From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795625252; b=IPVEUfcUTfOVFgZaomGZ96eq2lpYdv9Cjpj/oXKPMqtboLrpTnLUeI8TPogX24ZQ+0DX yavOYqMYFg09v6Ny1T+KgVFbcnI7KxIiCdKYwSYS1HPYTNKuhHES8xOumk0sBvhqlY7D6 8K0o3Kyr1FrUuBivwzi+TIyRd7sYERhWksckicefV2OWSSWtVitu5Pe+YQNrKLYK7pT4N WIDInqCx26SVIlCen6gPMWJvt61T4Gobed1abGs2kp/KGp13HlVYcNH2UZVEz65V8bP2F H1dEewKLygF0xEqqvNLDwhTMYi4wwf4qxHEM7SDmWoh+sCY9MGpsjq18+sos0ckJB1g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795625252; h=DMARC-Filter:Received:Received:DKIM-Signature:Message-ID:Date: MIME-Version:User-Agent:Subject:To:Cc:References:From: Content-Language:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=u74A0Q4um7qV8/WDW/DpSpOB1wN/qS5tUTp8OCX2aSQ=; b=Jk7SK6aKJ0VapmRxGW+o3+xZCEt+ay1Us68K+Ks7fCvzLCmXNdBrFMm78T66i/N/jLWx 4ZLOrD/NYjYlbMAtLOqIXVuhwCmEBy3IOkZqlWYCL3dlFtldOu67ZiFmBo1fSU4Anpd6g MaR1OXlt8ChJvDIBfGfpF7wU2wpS9n8SL6mz4dAYOwhevVwsKuzx58/zGfPMNkNN3Hnd5 DHl6dOXGAsr/EVVkxSIOOze+RbeL6LsO5duBkPnNtEaP8O+emaRfPZZxLjBQgzVUSU1fR TA8/CV2vLDJXvC2/luJLLm6JBvybfNdPUcUQeHJVSEFzhAn40cAhf/44RB+9BEfqHxQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=PPcHEM+F; arc=none smtp.remote-ip=217.140.110.172 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 93603606A327; Wed, 25 Nov 2026 16:47:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 93603606A327 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=PPcHEM+F Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 928232F; Wed, 25 Nov 2026 08:47:27 -0800 (PST) Received: from [10.57.32.107] (unknown [10.57.32.107]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 62CE23F632; Wed, 25 Nov 2026 08:47:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1795625250; bh=2eqARM5zetumptsIOUsll4fMIks93bDujuzqoyMavgw=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=PPcHEM+FJASRgoa04KgHq2/l2CDs0QOxGySNx7u9SCuF1kp6pNFlZ7lgZOs3j47MH HCfcsVevE2w3sAPyXltY1uD8GnIBSWH7PIWuEZ6+ocCHneO4YCVHSjB2/+VqU0XaCO lgLzNt+x7UEcGbcd3uHJEx012FNtAa4MPhF1n5Mc= Message-ID: <483ee877-3953-46b1-b4a2-e3b084ee3b64@arm.com> Date: Wed, 25 Nov 2026 16:47:22 +0000 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 07/11] KVM: arm64: CCA: Add Realm RTT mapping and invalidation helpers To: Suzuki K Poulose , kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Catalin Marinas , Marc Zyngier , Will Deacon , James Morse , Oliver Upton , Zenghui Yu , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly , Alexandru Elisei , Christoffer Dall , Fuad Tabba , linux-coco@lists.linux.dev, Ganapatrao Kulkarni , Gavin Shan , Shanker Donthineni , Alper Gun , "Aneesh Kumar K . V" , Emi Kisanuki , Vishal Annapurve , WeiLin.Chang@arm.com, Lorenzo Pieralisi , Kohei Enju References: <20261123104233.95710-1-steven.price@arm.com> <20261123104233.95710-8-steven.price@arm.com> <70c50c45-c8b9-4096-84b2-ba4b6ecb63ed@arm.com> From: Steven Price Content-Language: en-GB In-Reply-To: <70c50c45-c8b9-4096-84b2-ba4b6ecb63ed@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 25/11/2026 09:51, Suzuki K Poulose wrote: > > > On 24/11/2026 00:20, Suzuki K Poulose wrote: >> 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 >>> >>> --- >>> 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. > > Having a think about it, I don't think the folding of RTTs in the unmap > case is a good idea. We could leave them as they are, because: > > 1) As mentioned above, we are holding the write_lock() and doing this > within the lock is bad for contention > 2) We do not check if there was any mapping at all that was actually > invalidated. i.e., the tables were already folded and for a big range > we go over it unnecessarily. > 3) For fixing up permission faults on shared range, we end up unmapping > the range and then trying to map it. Folding here means, we could end > up in the dance of reclaiming the RTT and then creating it back for > each L3. (This is a rare case though). > > Overall, I don't see the benefit of folding outweighing the impact of > it. So, could we please drop this ? Agreed. I don't think we have a good view (yet) on when folding makes sense. I think it ended up in here mostly so that we could exercise those paths in the RMM. But that's a terrible reason to keep it ;) Eventually I think we'll need to figure out how to cause folding in those (probably fairly rare) situations where it will help. But for now I'll just drop this. Thanks, Steve