Linux KVM/arm64 development list
 help / color / mirror / Atom feed
From: Ryan Roberts <ryan.roberts@arm.com>
To: Marc Zyngier <maz@kernel.org>
Cc: Oliver Upton <oliver.upton@linux.dev>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	James Morse <james.morse@arm.com>,
	Zenghui Yu <yuzenghui@huawei.com>,
	Ard Biesheuvel <ardb@kernel.org>,
	Anshuman Khandual <anshuman.khandual@arm.com>,
	linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev
Subject: Re: [PATCH v5 07/12] KVM: arm64: Use LPA2 page-tables for stage2 and hyp stage1
Date: Fri, 24 Nov 2023 11:49:57 +0000	[thread overview]
Message-ID: <1ead7fa6-7085-4b95-a568-ece094721d34@arm.com> (raw)
In-Reply-To: <86fs0xzue7.wl-maz@kernel.org>

On 22/11/2023 15:21, Marc Zyngier wrote:
> On Wed, 22 Nov 2023 13:41:33 +0000,
> Ryan Roberts <ryan.roberts@arm.com> wrote:
>>
>> On 21/11/2023 20:34, Oliver Upton wrote:
>>> On Thu, Nov 16, 2023 at 02:29:26PM +0000, Ryan Roberts wrote:
>>>> Implement a simple policy whereby if the HW supports FEAT_LPA2 for the
>>>> page size we are using, always use LPA2-style page-tables for stage 2
>>>> and hyp stage 1 (assuming an nvhe hyp), regardless of the VMM-requested
>>>> IPA size or HW-implemented PA size. When in use we can now support up to
>>>> 52-bit IPA and PA sizes.
>>>>
>>>> We use the previously created cpu feature to track whether LPA2 is
>>>> supported for deciding whether to use the LPA2 or classic pte format.
>>>>
>>>> Note that FEAT_LPA2 brings support for bigger block mappings (512GB with
>>>> 4KB, 64GB with 16KB). We explicitly don't enable these in the library
>>>> because stage2_apply_range() works on batch sizes of the largest used
>>>> block mapping, and increasing the size of the batch would lead to soft
>>>> lockups. See commit 5994bc9e05c2 ("KVM: arm64: Limit
>>>> stage2_apply_range() batch size to largest block").
>>>>
>>>> With the addition of LPA2 support in the hypervisor, the PA size
>>>> supported by the HW must be capped with a runtime decision, rather than
>>>> simply using a compile-time decision based on PA_BITS. For example, on a
>>>> system that advertises 52 bit PA but does not support FEAT_LPA2, A 4KB
>>>> or 16KB kernel compiled with LPA2 support must still limit the PA size
>>>> to 48 bits.
>>>>
>>>> Therefore, move the insertion of the PS field into TCR_EL2 out of
>>>> __kvm_hyp_init assembly code and instead do it in cpu_prepare_hyp_mode()
>>>> where the rest of TCR_EL2 is prepared. This allows us to figure out PS
>>>> with kvm_get_parange(), which has the appropriate logic to ensure the
>>>> above requirement. (and the PS field of VTCR_EL2 is already populated
>>>> this way).
>>>>
>>>> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
>>>> ---
>>>>  arch/arm64/include/asm/kvm_mmu.h     |  2 +-
>>>>  arch/arm64/include/asm/kvm_pgtable.h | 47 +++++++++++++++++++++-------
>>>>  arch/arm64/kvm/arm.c                 |  5 +++
>>>>  arch/arm64/kvm/hyp/nvhe/hyp-init.S   |  4 ---
>>>>  arch/arm64/kvm/hyp/pgtable.c         | 15 +++++++--
>>>>  5 files changed, 54 insertions(+), 19 deletions(-)
>>>>
>>>> diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h
>>>> index 31e8d7faed65..f4e4fcb35afc 100644
>>>> --- a/arch/arm64/include/asm/kvm_mmu.h
>>>> +++ b/arch/arm64/include/asm/kvm_mmu.h
>>>> @@ -340,7 +340,7 @@ static inline struct kvm *kvm_s2_mmu_to_kvm(struct kvm_s2_mmu *mmu)
>>>>  	return container_of(mmu->arch, struct kvm, arch);
>>>>  }
>>>>  
>>>> -#define kvm_lpa2_is_enabled()		false
>>>> +#define kvm_lpa2_is_enabled()		system_supports_lpa2()
>>>
>>> Can we use this predicate consistently throughout the KVM code? Looks
>>> like the rest of this diff is using system_supports_lpa2() directly.
>>
>> My thinking was that system_supports_lpa2() is an input to KVM's policy to
>> decide if it is going to use LPA2 (currently that policy is very simple - if the
>> system supports it, then KVM uses it - but it doesn't have to be that way), and
>> kvm_lpa2_is_enabled() is how KVM exports its policy decision, so one is an input
>> and the other is an output.
>>
>> It's a lightly held opinion though - I'll make the change if you insist? :)
> 
> <bikeshed>
> I personally don't find this dichotomy very useful. It could make
> sense if we used the page table walker for S1 outside of KVM, but
> that's not the case at the moment.
> 
> If there is no plan for such a use case, I'd rather see a single
> predicate, making the code a bit more readable.
> </bikeshed>

OK fair enough. I've made this change for the next rev.

> 
> 	M.
> 


  reply	other threads:[~2023-11-24 11:50 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-16 14:29 [PATCH v5 00/12] KVM: arm64: Support FEAT_LPA2 at hyp s1 and vm s2 Ryan Roberts
2023-11-16 14:29 ` [PATCH v5 01/12] arm64/mm: Modify range-based tlbi to decrement scale Ryan Roberts
2023-11-16 14:29 ` [PATCH v5 02/12] arm64/mm: Add lpa2_is_enabled() kvm_lpa2_is_enabled() stubs Ryan Roberts
2023-11-16 14:29 ` [PATCH v5 03/12] arm64/mm: Update tlb invalidation routines for FEAT_LPA2 Ryan Roberts
2023-11-16 14:29 ` [PATCH v5 04/12] arm64: Add ARM64_HAS_LPA2 CPU capability Ryan Roberts
2023-11-22 15:14   ` Marc Zyngier
2023-11-16 14:29 ` [PATCH v5 05/12] arm64/mm: Add FEAT_LPA2 specific ID_AA64MMFR0.TGRAN[2] Ryan Roberts
2023-11-16 14:29 ` [PATCH v5 06/12] KVM: arm64: Add new (V)TCR_EL2 field definitions for FEAT_LPA2 Ryan Roberts
2023-11-16 14:29 ` [PATCH v5 07/12] KVM: arm64: Use LPA2 page-tables for stage2 and hyp stage1 Ryan Roberts
2023-11-21 20:34   ` Oliver Upton
2023-11-22 13:41     ` Ryan Roberts
2023-11-22 15:21       ` Marc Zyngier
2023-11-24 11:49         ` Ryan Roberts [this message]
2023-11-27  9:32           ` Marc Zyngier
2023-11-27  9:43             ` Ryan Roberts
2023-11-16 14:29 ` [PATCH v5 08/12] KVM: arm64: Convert translation level parameter to s8 Ryan Roberts
2023-11-16 14:29 ` [PATCH v5 09/12] KVM: arm64: Support up to 5 levels of translation in kvm_pgtable Ryan Roberts
2023-11-16 14:29 ` [PATCH v5 10/12] KVM: arm64: Allow guests with >48-bit IPA size on FEAT_LPA2 systems Ryan Roberts
2023-11-16 14:29 ` [PATCH v5 11/12] KVM: selftests: arm64: Determine max ipa size per-page size Ryan Roberts
2023-11-21 23:27   ` Oliver Upton
2023-11-22 13:47     ` Ryan Roberts
2023-11-21 23:34   ` Oliver Upton
2023-11-22 13:47     ` Ryan Roberts
2023-11-16 14:29 ` [PATCH v5 12/12] KVM: selftests: arm64: Support P52V48 4K and 16K guest_modes Ryan Roberts
2023-11-21 23:38 ` [PATCH v5 00/12] KVM: arm64: Support FEAT_LPA2 at hyp s1 and vm s2 Oliver Upton
2023-11-22 13:37   ` Ryan Roberts

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=1ead7fa6-7085-4b95-a568-ece094721d34@arm.com \
    --to=ryan.roberts@arm.com \
    --cc=anshuman.khandual@arm.com \
    --cc=ardb@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=james.morse@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=maz@kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=suzuki.poulose@arm.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