linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Oliver Upton <oliver.upton@linux.dev>
To: Ryan Roberts <ryan.roberts@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>, Marc Zyngier <maz@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 11/12] KVM: selftests: arm64: Determine max ipa size per-page size
Date: Tue, 21 Nov 2023 23:27:57 +0000	[thread overview]
Message-ID: <ZV08_eU9vV1SUmmd@linux.dev> (raw)
In-Reply-To: <20231116142931.1675485-12-ryan.roberts@arm.com>

On Thu, Nov 16, 2023 at 02:29:30PM +0000, Ryan Roberts wrote:
> We are about to add 52 bit PA guest modes for 4K and 16K pages when the
> system supports LPA2. In preparation beef up the logic that parses mmfr0
> to also tell us what the maximum supported PA size is for each page
> size. Max PA size = 0 implies the page size is not supported at all.
> 
> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
> ---
>  .../selftests/kvm/include/aarch64/processor.h |  4 +-
>  .../selftests/kvm/lib/aarch64/processor.c     | 27 ++++++++++---
>  tools/testing/selftests/kvm/lib/guest_modes.c | 40 ++++++++-----------
>  3 files changed, 41 insertions(+), 30 deletions(-)
> 
> diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h
> index c42d683102c7..cf20e44e86f2 100644
> --- a/tools/testing/selftests/kvm/include/aarch64/processor.h
> +++ b/tools/testing/selftests/kvm/include/aarch64/processor.h
> @@ -119,8 +119,8 @@ enum {
>  /* Access flag update enable/disable */
>  #define TCR_EL1_HA		(1ULL << 39)
>  
> -void aarch64_get_supported_page_sizes(uint32_t ipa,
> -				      bool *ps4k, bool *ps16k, bool *ps64k);
> +void aarch64_get_supported_page_sizes(uint32_t ipa, uint32_t *ipa4k,
> +					uint32_t *ipa16k, uint32_t *ipa64k);
>  
>  void vm_init_descriptor_tables(struct kvm_vm *vm);
>  void vcpu_init_descriptor_tables(struct kvm_vcpu *vcpu);
> diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c
> index 6fe12e985ba5..917cfeddb6b4 100644
> --- a/tools/testing/selftests/kvm/lib/aarch64/processor.c
> +++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c
> @@ -492,12 +492,24 @@ uint32_t guest_get_vcpuid(void)
>  	return read_sysreg(tpidr_el1);
>  }
>  
> -void aarch64_get_supported_page_sizes(uint32_t ipa,
> -				      bool *ps4k, bool *ps16k, bool *ps64k)
> +static uint32_t max_ipa_for_page_size(uint32_t vm_ipa, uint32_t gran,
> +				uint32_t not_sup_val, uint32_t ipa52_min_val)
> +{
> +	if (gran == not_sup_val)
> +		return 0;
> +	else if (gran >= ipa52_min_val && vm_ipa >= 52)
> +		return 52;
> +	else
> +		return min(vm_ipa, 48U);
> +}
> +
> +void aarch64_get_supported_page_sizes(uint32_t ipa, uint32_t *ipa4k,
> +					uint32_t *ipa16k, uint32_t *ipa64k)
>  {
>  	struct kvm_vcpu_init preferred_init;
>  	int kvm_fd, vm_fd, vcpu_fd, err;
>  	uint64_t val;
> +	uint32_t gran;
>  	struct kvm_one_reg reg = {
>  		.id	= KVM_ARM64_SYS_REG(SYS_ID_AA64MMFR0_EL1),
>  		.addr	= (uint64_t)&val,
> @@ -518,9 +530,14 @@ void aarch64_get_supported_page_sizes(uint32_t ipa,
>  	err = ioctl(vcpu_fd, KVM_GET_ONE_REG, &reg);
>  	TEST_ASSERT(err == 0, KVM_IOCTL_ERROR(KVM_GET_ONE_REG, vcpu_fd));
>  
> -	*ps4k = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR0_EL1_TGRAN4), val) != 0xf;
> -	*ps64k = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR0_EL1_TGRAN64), val) == 0;
> -	*ps16k = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR0_EL1_TGRAN16), val) != 0;
> +	gran = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR0_EL1_TGRAN4), val);
> +	*ipa4k = max_ipa_for_page_size(ipa, gran, 0xf, 1);
> +
> +	gran = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR0_EL1_TGRAN64), val);
> +	*ipa64k = max_ipa_for_page_size(ipa, gran, 0xf, 0);
> +
> +	gran = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR0_EL1_TGRAN16), val);
> +	*ipa16k = max_ipa_for_page_size(ipa, gran, 0, 2);
>  
>  	close(vcpu_fd);
>  	close(vm_fd);
> diff --git a/tools/testing/selftests/kvm/lib/guest_modes.c b/tools/testing/selftests/kvm/lib/guest_modes.c
> index 1df3ce4b16fd..c64c5cf49942 100644
> --- a/tools/testing/selftests/kvm/lib/guest_modes.c
> +++ b/tools/testing/selftests/kvm/lib/guest_modes.c
> @@ -18,33 +18,27 @@ void guest_modes_append_default(void)
>  #else
>  	{
>  		unsigned int limit = kvm_check_cap(KVM_CAP_ARM_VM_IPA_SIZE);
> -		bool ps4k, ps16k, ps64k;
> +		uint32_t ipa4k, ipa16k, ipa64k;
>  		int i;
>  
> -		aarch64_get_supported_page_sizes(limit, &ps4k, &ps16k, &ps64k);
> +		aarch64_get_supported_page_sizes(limit, &ipa4k, &ipa16k, &ipa64k);
>  
> -		vm_mode_default = NUM_VM_MODES;
> +		guest_mode_append(VM_MODE_P52V48_64K, ipa64k >= 52, ipa64k >= 52);

Can we just change guest_mode_append() to take a single bool argument and
initialize both ::supported and ::enabled to its value?

-- 
Thanks,
Oliver

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2023-11-21 23:28 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
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 [this message]
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=ZV08_eU9vV1SUmmd@linux.dev \
    --to=oliver.upton@linux.dev \
    --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=ryan.roberts@arm.com \
    --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;
as well as URLs for NNTP newsgroup(s).