Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jia He" <justin.he@arm.com>
Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org,
	"Oliver Upton" <oupton@kernel.org>,
	"Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH v2 2/3] KVM: arm64: selftests: Add a test for VNCR_EL2 translation faults
Date: Wed, 25 Nov 2026 03:02:40 +0000	[thread overview]
Message-ID: <sashiko-outbox-232440@kernel.org> (raw)
In-Reply-To: <20261125024426.3464050-3-justin.he@arm.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] KVM: arm64: selftests: nv_vncr_abort fails on 16K and 64K
  host page sizes
--

commit 771173f048bfbff4d1afde9bc6d9374d48302af1
Author: Jia He <justin.he@arm.com>

KVM: arm64: selftests: Add a test for VNCR_EL2 translation faults

This commit adds an arm64 KVM selftest for VNCR_EL2 stage-1 translation
faults and hardware access flag updates when the last-level page table is in
a read-only or writable memslot.

> diff --git a/tools/testing/selftests/kvm/arm64/nv_vncr_abort.c b/tools/testing/selftests/kvm/arm64/nv_vncr_abort.c
> new file mode 100644
> index 0000000000000..d2052b1526111
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/arm64/nv_vncr_abort.c
[ ... ]
> +static void setup_vncr_page(struct kvm_vm *vm, enum test_mode mode)
> +{
> +	u64 oa_mask = GENMASK_ULL(47, 12);
> +	gpa_t data_gpa, table_gpa;
> +	u64 *l2e, *table;
> +	int idx = (VNCR_VA >> 12) & 511;
> +
> +	data_gpa = vm_phy_page_alloc(vm, MEM_REGION_DATA);
> +	virt_pg_map(vm, VNCR_VA, data_gpa);
> +	*(u64 *)(addr_gpa2hva(vm, data_gpa) + VNCR_VTTBR_EL2) = VNCR_MAGIC;
> +
> +	l2e = virt_get_pte_hva_at_level(vm, VNCR_VA, 2);
> +	TEST_ASSERT((*l2e & 3) == 3, "level 2 entry is not a table: %lx", *l2e);
> +	table_gpa = *l2e & oa_mask;
> +	table = addr_gpa2hva(vm, table_gpa);
> +
> +	if (mode == RW_PT_AF_CLEAR) {
> +		table[idx] &= ~PTE_AF;
> +		return;
> +	}
> +
> +	vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, RO_PT_GPA,
> +				    RO_PT_SLOT, 1, KVM_MEM_READONLY);
> +	memcpy(addr_gpa2hva(vm, RO_PT_GPA), table, vm->page_size);
> +	if (mode == RO_PT_AF_CLEAR)
> +		((u64 *)addr_gpa2hva(vm, RO_PT_GPA))[idx] &= ~PTE_AF;
> +
> +	*l2e = (*l2e & ~oa_mask) | RO_PT_GPA;
> +}
> +
> +static void sigalrm_handler(int sig)
> +{
> +}
> +
> +static void run_test(enum test_mode mode)
> +{
> +	struct kvm_vcpu_init init;
> +	struct kvm_vcpu *vcpu;
> +	struct kvm_vm *vm;
> +	struct ucall uc;
> +	u64 mmfr1;
> +	int ret;
> +
> +	vm = vm_create(1);
> +	kvm_get_default_vcpu_target(vm, &init);
> +	init.features[0] |= BIT(KVM_ARM_VCPU_HAS_EL2);
> +	vcpu = aarch64_vcpu_add(vm, 0, &init, guest_code);
> +	kvm_arch_vm_finalize_vcpus(vm);
> +
> +	mmfr1 = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64MMFR1_EL1));
> +	__TEST_REQUIRE(SYS_FIELD_GET(ID_AA64MMFR1_EL1, HAFDBS, mmfr1),
> +		       "Hardware AF management not supported");
> +	TEST_REQUIRE(vm->page_size == 4096);

[Severity: Medium]
Will this test fail on 16K and 64K host kernels when the CPU supports a 4K
stage-1 translation granule?

guest_modes_append_default() selects VM_MODE_P40V48_4K whenever the CPU
supports a 4K granule regardless of the host page size, so vm->page_size is
4096 and TEST_REQUIRE(vm->page_size == 4096) does not skip on 16K or 64K
hosts.

Passing npages = 1 to vm_userspace_mem_region_add() in setup_vncr_page() then
hits the assertion in vm_mem_add() requiring npages to cover at least one
host page:

tools/testing/selftests/kvm/lib/kvm_util.c:vm_mem_add() {
    ...
	TEST_ASSERT(vm_adjust_num_guest_pages(vm->mode, npages) == npages,
		"Number of guest pages is not compatible with the host. "
		"Try npages=%d", vm_adjust_num_guest_pages(vm->mode, npages));
    ...
}

Also, in RW_PT_AF_CLEAR mode, vm_phy_page_alloc() returns a 4K-aligned
data_gpa that is not aligned to a 16K or 64K host page, while KVM maps the
containing host pfn at the VNCR fixmap and takes the page offset from
VNCR_VA & (PAGE_SIZE - 1) (which is 0), reading from the start of the host
page instead of data_gpa.

Should run_test() check TEST_REQUIRE(getpagesize() == 4096), or size
RO_PT_SLOT with vm_adjust_num_guest_pages() and align data_gpa to the host
page size?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125024426.3464050-1-justin.he@arm.com?part=2

  reply	other threads:[~2026-11-25  3:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  2:44 [PATCH v2 0/3] KVM: arm64: nv: VNCR page in read-only and cacheable PFNMAP memory Jia He
2026-11-25  2:44 ` [PATCH v2 1/3] KVM: arm64: nv: Inject an SEA when the VNCR walk cannot set the AF Jia He
2026-11-25  2:44 ` [PATCH v2 2/3] KVM: arm64: selftests: Add a test for VNCR_EL2 translation faults Jia He
2026-11-25  3:02   ` sashiko-bot [this message]
2026-11-25  2:44 ` [PATCH v2 3/3] KVM: arm64: nv: Allow the L1 VNCR page in cacheable PFNMAP memory Jia He

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=sashiko-outbox-232440@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=justin.he@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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