All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jinyu Tang" <tjytimi@163.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v2 2/2] KVM: selftests: Add a hugetlb memslot alignment test mode
Date: Thu, 04 Jun 2026 14:42:33 +0000	[thread overview]
Message-ID: <20260604144233.857031F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260604142602.3582602-3-tjytimi@163.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Moving the memslot GPA by `guest_page_size` breaks KVM's host page size alignment requirement when `guest_page_size < host_page_size`.
--

commit 6f87612dbda5d8765dabde103b78b45366d2e3b8
Author: Jinyu Tang <tjytimi@163.com>

KVM: selftests: Add a hugetlb memslot alignment test mode

This commit adds a -u option to kvm_page_table_test to intentionally
misalign the test memslot GPA by one guest page. It creates the memslot
aligned and then moves it to create a deliberate HVA/GPA offset mismatch.

> diff --git a/tools/testing/selftests/kvm/kvm_page_table_test.c b/tools/testing/selftests/kvm/kvm_page_table_test.c
> index fc5242fb956fc..a910e3abb8c71 100644
> --- a/tools/testing/selftests/kvm/kvm_page_table_test.c
> +++ b/tools/testing/selftests/kvm/kvm_page_table_test.c
[ ... ]
> @@ -276,13 +278,22 @@ static struct kvm_vm *pre_init_before_test(enum vm_guest_mode mode, void *arg)
>  	/* Add an extra memory slot with specified backing src type */
>  	vm_userspace_mem_region_add(vm, src_type, guest_test_phys_mem,
>  				    TEST_MEM_SLOT_INDEX, guest_num_pages, 0);
> +	region = memslot2region(vm, TEST_MEM_SLOT_INDEX);
> +	host_test_mem = region->host_mem;
> +
> +	if (p->misalign_slot_gpa) {
> +		TEST_ASSERT(is_backing_src_hugetlb(src_type),
> +			    "Memslot GPA misalignment requires hugetlb backing");
> +		TEST_ASSERT(guest_num_pages > 1,
> +			    "Need at least two guest pages to misalign memslot GPA");
> +
> +		guest_test_phys_mem += guest_page_size;
> +		vm_mem_region_move(vm, TEST_MEM_SLOT_INDEX, guest_test_phys_mem);

[Severity: Medium]
Will this move operation fail on hosts where the guest page size is smaller
than the host page size?

The KVM_SET_USER_MEMORY_REGION ioctl requires the guest physical address to
be aligned to the host's page size. 

Because for_each_guest_mode() iterates through configurations that can have a
smaller guest page size (like a 4K guest on a 64K ARM64 host), adding
guest_page_size to the aligned GPA will produce a misaligned address for KVM.

Could vm_mem_region_move() fail with -EINVAL from KVM in these cases, causing
the test assertion to fail? Would it be safer to shift by the maximum of the
guest page size and the host page size?

> +	}
>  
>  	/* Do mapping(GVA->GPA) for the testing memory slot */
>  	virt_map(vm, guest_test_virt_mem, guest_test_phys_mem, guest_num_pages);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260604142602.3582602-1-tjytimi@163.com?part=2

      reply	other threads:[~2026-06-04 14:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-04 14:26 [PATCH v2 0/2] KVM: riscv: Fix hugetlb G-stage block mapping eligibility Jinyu Tang
2026-06-04 14:26 ` Jinyu Tang
2026-06-04 14:26 ` Jinyu Tang
2026-06-04 14:26 ` [PATCH v2 1/2] KVM: riscv: Check hugetlb block mappings against memslot bounds Jinyu Tang
2026-06-04 14:26   ` Jinyu Tang
2026-06-04 14:26   ` Jinyu Tang
2026-06-04 14:52   ` sashiko-bot
2026-06-04 14:26 ` [PATCH v2 2/2] KVM: selftests: Add a hugetlb memslot alignment test mode Jinyu Tang
2026-06-04 14:26   ` Jinyu Tang
2026-06-04 14:26   ` Jinyu Tang
2026-06-04 14:42   ` sashiko-bot [this message]

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=20260604144233.857031F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tjytimi@163.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.