[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <kivowzryb3mbntaoud4kmhxjbix3usqjiy7phwihjc7p4rp4gk@ppilefrxpu35>
Date: Thu, 8 Jan 2026 20:26:07 +0000
From: Yosry Ahmed <yosry.ahmed@...ux.dev>
To: Sean Christopherson <seanjc@...gle.com>
Cc: Paolo Bonzini <pbonzini@...hat.com>, Marc Zyngier <maz@...nel.org>,
Oliver Upton <oupton@...nel.org>, Tianrui Zhao <zhaotianrui@...ngson.cn>,
Bibo Mao <maobibo@...ngson.cn>, Huacai Chen <chenhuacai@...nel.org>,
Anup Patel <anup@...infault.org>, Paul Walmsley <pjw@...nel.org>,
Palmer Dabbelt <palmer@...belt.com>, Albert Ou <aou@...s.berkeley.edu>,
Christian Borntraeger <borntraeger@...ux.ibm.com>, Janosch Frank <frankja@...ux.ibm.com>,
Claudio Imbrenda <imbrenda@...ux.ibm.com>, kvm@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
kvmarm@...ts.linux.dev, loongarch@...ts.linux.dev, kvm-riscv@...ts.infradead.org,
linux-riscv@...ts.infradead.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v4 21/21] KVM: selftests: Test READ=>WRITE dirty logging
behavior for shadow MMU
On Thu, Jan 08, 2026 at 08:32:44AM -0800, Sean Christopherson wrote:
[..]
> @@ -106,12 +139,66 @@ static void l1_guest_code(void *data)
> l1_svm_code(data);
> }
>
> +static void test_handle_ucall_sync(struct kvm_vm *vm, u64 arg,
> + unsigned long *bmap)
> +{
> + vm_vaddr_t gva = arg & ~(PAGE_SIZE - 1);
> + int page_nr, i;
> +
> + /*
> + * Extract the page number of underlying physical page, which is also
> + * the _L1_ page number. The dirty bitmap _must_ be updated based on
> + * the L1 GPA, not L2 GPA, i.e. whether or not L2 used an aliased GPA
> + * (i.e. if TDP enabled for L2) is irrelevant with respect to the dirty
> + * bitmap and which underlying physical page is accessed.
> + *
> + * Note, gva will be '0' if there was no access, i.e. if the purpose of
> + * the sync is to verify all pages are clean.
> + */
> + if (!gva)
> + page_nr = 0;
> + else if (gva >= TEST_MEM_ALIAS_BASE)
> + page_nr = (gva - TEST_MEM_ALIAS_BASE) >> PAGE_SHIFT;
> + else
> + page_nr = (gva - TEST_MEM_BASE) >> PAGE_SHIFT;
> + TEST_ASSERT(page_nr == 0 || page_nr == 1,
> + "Test bug, unexpected frame number '%u' for arg = %lx", page_nr, arg);
> + TEST_ASSERT(gva || (arg & TEST_SYNC_NO_FAULT),
> + "Test bug, gva must be valid if a fault is expected");
> +
> + kvm_vm_get_dirty_log(vm, TEST_MEM_SLOT_INDEX, bmap);
> +
> + /*
> + * Check all pages to verify the correct physical page was modified (or
> + * not), and that all pages are clean/dirty as expected.
> + *
> + * If a fault of any kind is expected, the target page should be dirty
> + * as the Dirty bit is set in the gPTE. KVM should create a writable
> + * SPTE even on a read fault, *and* KVM must mark the GFN as dirty
> + * when doing so.
> + */
> + for (i = 0; i < TEST_MEM_PAGES; i++) {
> + if (i == page_nr && arg & TEST_SYNC_WRITE_FAULT)
Micro nit: I think this is slightly clearer:
if (i == page_nr && (arg & TEST_SYNC_WRITE_FAULT))
Powered by blists - more mailing lists