mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Suzuki K Poulose <suzuki.poulose@arm.com>
To: Steven Price <steven.price@arm.com>,
	kvm@vger.kernel.org, kvmarm@lists.linux.dev
Cc: Catalin Marinas <catalin.marinas@arm.com>,
	Marc Zyngier <maz@kernel.org>, Will Deacon <will@kernel.org>,
	James Morse <james.morse@arm.com>,
	Oliver Upton <oliver.upton@linux.dev>,
	Zenghui Yu <yuzenghui@huawei.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, Joey Gouly <joey.gouly@arm.com>,
	Alexandru Elisei <alexandru.elisei@arm.com>,
	Christoffer Dall <christoffer.dall@arm.com>,
	Fuad Tabba <tabba@google.com>,
	linux-coco@lists.linux.dev,
	Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>,
	Gavin Shan <gshan@redhat.com>,
	Shanker Donthineni <sdonthineni@nvidia.com>,
	Alper Gun <alpergun@google.com>,
	"Aneesh Kumar K . V" <aneesh.kumar@kernel.org>,
	Emi Kisanuki <fj0570is@fujitsu.com>,
	Vishal Annapurve <vannapurve@google.com>,
	WeiLin.Chang@arm.com, Lorenzo Pieralisi <lpieralisi@kernel.org>,
	Kohei Enju <enju.kohei@fujitsu.com>
Subject: Re: [PATCH v4 07/11] KVM: arm64: CCA: Add Realm RTT mapping and invalidation helpers
Date: Tue, 24 Nov 2026 00:20:24 +0000	[thread overview]
Message-ID: <bc90af1d-068e-4e79-8d5f-f8205beb0a69@arm.com> (raw)
In-Reply-To: <20261123104233.95710-8-steven.price@arm.com>

On 23/11/2026 10:42, Steven Price wrote:
> Add the RMI RTT creation and unmap helpers needed by CCA Realm stage-2
> memory operations. REC exit handling and guest requested RIPAS changes
> follow in the vCPU series.
> 
> Signed-off-by: Steven Price <steven.price@arm.com>
> 
> ---
> Changes since v3:
> - Use the VTCR-derived Realm start level for RTT operations.
> 
> Changes since v2:
> - Use a local MMU cache during notifier invalidation, handle
>    failed RTT splits, and validate RMI levels and cache state.
> 
> Changes since v1:
> - Rework RTT creation and folding around missing or existing RTTs.
>    Use a shared RMI block-size helper and handle alignment, partial
>    progress and errors in range operations.
> ---
>   arch/arm64/include/asm/kvm_rmi.h |   8 +
>   arch/arm64/kvm/rmi.c             | 421 +++++++++++++++++++++++++++++++
>   drivers/firmware/arm_rmm/rmi.c   |  10 -
>   include/linux/arm-rmi-cmds.h     |   8 +
>   4 files changed, 437 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/kvm_rmi.h b/arch/arm64/include/asm/kvm_rmi.h

...

> +
> +static void realm_unmap_shared_range(struct kvm *kvm,
> +				     unsigned long start,
> +				     unsigned long end,
> +				     bool may_block,
> +				     struct kvm_mmu_memory_cache *mc)
> +{
> +	struct realm *realm = &kvm->arch.realm;
> +	unsigned long rd = realm->rd_phys;
> +	unsigned long next_addr, addr;
> +	unsigned long shared_bit = BIT(realm->ia_bits - 1);
> +
> +	if (start >= end)
> +		return;
> +
> +	/*
> +	 * Callers may pass either an IPA range or its shared alias. Add the
> +	 * shared bit only for the former. Use addition so an exclusive end at
> +	 * shared_bit advances to the end of the IPA space.
> +	 */
> +	if (start < shared_bit) {
> +		start += shared_bit;
> +		end += shared_bit;
> +	}
> +
> +	for (addr = start; addr < end; addr = next_addr) {
> +		long ret;
> +
> +		ret = rmi_rtt_unprot_unmap(rd, addr, end, RMI_ADDR_TYPE_NONE,

...

> +		}
> +
> +		if (may_block)
> +			cond_resched_rwlock_write(&kvm->mmu_lock);
> +	}
> +
> +	realm_fold_rtt_level(realm, realm->start_level + 1,
> +			     start, end);

See below.

> +}
> +
> +static void realm_unmap_private_range(struct kvm *kvm,
> +				      unsigned long start,
> +				      unsigned long end,
> +				      bool may_block,
> +				      struct kvm_mmu_memory_cache *mc)
> +{
> +	struct realm *realm = &kvm->arch.realm;
> +	unsigned long rd = realm->rd_phys;
> +	unsigned long next_addr, addr;
> +	long ret;
> +
> +	for (addr = start; addr < end; addr = next_addr) {
> +		unsigned long out_range;
> +		unsigned long flags = RMI_ADDR_TYPE_SINGLE;
> +		/* TODO: Optimise using RMI_ADDR_TYPE_LIST */
> +
> +		ret = rmi_rtt_data_unmap(rd, addr, end, flags, 0,

...

> +		}
> +
> +		if (may_block)
> +			cond_resched_rwlock_write(&kvm->mmu_lock);
> +	}
> +
> +	realm_fold_rtt_level(realm, realm->start_level + 1,
> +			     start, end);


If "may_block", we don't take that into account while folding the RTTs ?
On a bigger range, we might spend too much time, starving the other
threads.

Also, there is no point in folding the RTTs if the Realm is dying. So, I
would rather skip this if the Realm is not ACTIVE.

Suzuki

  parent reply	other threads:[~2026-11-24  0:20 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 10:42 [PATCH v4 00/11] KVM: arm64: CCA: Prepare Realm memory management Steven Price
2026-11-23 10:42 ` [PATCH v4 01/11] KVM: arm64: guest_memfd: Check mmap support when preparing memslot Steven Price
2026-11-23 10:42 ` [PATCH v4 02/11] KVM: arm64: CCA: Introduce Realms Steven Price
2026-11-23 10:42 ` [PATCH v4 03/11] KVM: arm64: Pass range filter to stage2_unmap_range Steven Price
2026-11-23 10:42 ` [PATCH v4 04/11] KVM: arm64: Dispatch stage-2 destruction by VM flavor Steven Price
2026-11-23 11:23   ` Suzuki K Poulose
2026-11-23 10:42 ` [PATCH v4 05/11] KVM: arm64: CCA: Add basic infrastructure for creating a realm Steven Price
2026-11-23 11:35   ` Suzuki K Poulose
2026-11-23 10:42 ` [PATCH v4 06/11] KVM: arm64: CCA: Destroy RTTs Steven Price
2026-11-23 11:57   ` Suzuki K Poulose
2026-11-24  0:01     ` Suzuki K Poulose
2026-11-23 10:42 ` [PATCH v4 07/11] KVM: arm64: CCA: Add Realm RTT mapping and invalidation helpers Steven Price
2026-11-23 13:32   ` Suzuki K Poulose
2026-11-24  0:20   ` Suzuki K Poulose [this message]
2026-11-23 10:42 ` [PATCH v4 08/11] KVM: Allow architectures to reject memslot changes before invalidation Steven Price
2026-11-23 10:42 ` [PATCH v4 09/11] KVM: arm64: CCA: Prevent memslot modifications after Realm creation Steven Price
2026-11-23 10:42 ` [PATCH v4 10/11] KVM: arm64: CCA: Support runtime faulting of memory Steven Price
2026-11-23 10:42 ` [PATCH v4 11/11] KVM: arm64: CCA: Add Realm stage-2 MMU operations Steven Price

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bc90af1d-068e-4e79-8d5f-f8205beb0a69@arm.com \
    --to=suzuki.poulose@arm.com \
    --cc=WeiLin.Chang@arm.com \
    --cc=alexandru.elisei@arm.com \
    --cc=alpergun@google.com \
    --cc=aneesh.kumar@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=christoffer.dall@arm.com \
    --cc=enju.kohei@fujitsu.com \
    --cc=fj0570is@fujitsu.com \
    --cc=gankulkarni@os.amperecomputing.com \
    --cc=gshan@redhat.com \
    --cc=james.morse@arm.com \
    --cc=joey.gouly@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=maz@kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=sdonthineni@nvidia.com \
    --cc=steven.price@arm.com \
    --cc=tabba@google.com \
    --cc=vannapurve@google.com \
    --cc=will@kernel.org \
    --cc=yuzenghui@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®