From: Oliver Upton <oupton@google.com>
To: Ricardo Koller <ricarkol@google.com>
Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu,
drjones@redhat.com, pbonzini@redhat.com, maz@kernel.org,
alexandru.elisei@arm.com, eric.auger@redhat.com,
reijiw@google.com, rananta@google.com, bgardon@google.com,
axelrasmussen@google.com
Subject: Re: [PATCH v3 09/13] KVM: selftests: aarch64: Add aarch64/page_fault_test
Date: Wed, 25 May 2022 19:43:11 +0000 [thread overview]
Message-ID: <Yo6Gz6o1csFCqN9x@google.com> (raw)
In-Reply-To: <20220408004120.1969099-10-ricarkol@google.com>
Hi Ricardo,
On Thu, Apr 07, 2022 at 05:41:16PM -0700, Ricardo Koller wrote:
> diff --git a/tools/testing/selftests/kvm/aarch64/page_fault_test.c b/tools/testing/selftests/kvm/aarch64/page_fault_test.c
> new file mode 100644
> index 000000000000..04fc6007f630
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/aarch64/page_fault_test.c
[...]
> +/* Guest virtual addresses that point to the test page and its PTE. */
> +#define TEST_GVA 0xc0000000
> +#define TEST_EXEC_GVA 0xc0000008
> +#define TEST_PTE_GVA 0xd0000000
> +#define TEST_DATA 0x0123456789ABCDEF
> +
> +#define CMD_NONE (0)
> +#define CMD_SKIP_TEST (1ULL << 1)
> +#define CMD_HOLE_PT (1ULL << 2)
> +#define CMD_HOLE_TEST (1ULL << 3)
> +
> +#define PREPARE_FN_NR 10
> +#define CHECK_FN_NR 10
> +
> +uint64_t pte_gpa;
> +
> +enum { PT, TEST, NR_MEMSLOTS};
nit: fix formatting (just use newlines for each value).
> +struct memslot_desc {
> + void *hva;
> + uint64_t gpa;
> + uint64_t size;
> + uint64_t guest_pages;
> + uint64_t backing_pages;
> + enum vm_mem_backing_src_type src_type;
> + uint32_t idx;
> +} memslot[NR_MEMSLOTS] = {
> + {
> + .idx = TEST_PT_SLOT_INDEX,
> + .backing_pages = PT_MEMSLOT_BACKING_SRC_NPAGES,
> + },
> + {
> + .idx = TEST_MEM_SLOT_INDEX,
> + .backing_pages = TEST_MEMSLOT_BACKING_SRC_NPAGES,
nit: initialize fields in the order they appear in the struct.
[...]
> +static void guest_write64(void)
> +{
> + uint64_t val;
> +
> + WRITE_ONCE(*((uint64_t *)TEST_GVA), TEST_DATA);
> + val = READ_ONCE(*(uint64_t *)TEST_GVA);
nit: you could proabably avoid casting with a global pointer.
static uint64_t *guest_test_memory = (uint64_t *)TEST_GVA;
[...]
> +static void guest_test_check(struct test_desc *test)
> +{
> + void (*check_fn)(void);
> + int i;
> +
> + for (i = 0; i < CHECK_FN_NR; i++) {
> + check_fn = test->guest_test_check[i];
> + if (!check_fn)
> + continue;
> + check_fn();
nit:
if (check_fn)
check_fn();
One less line :)
> + }
> +}
> +
> +static void guest_code(struct test_desc *test)
> +{
> + if (!test->guest_test)
> + test->guest_test = guest_nop;
In other cases you've chosen to skip function calls if NULL. Is there a
need to call something here that I've missed or could you just do:
if (test->guest_test)
test->guest_test();
below?
> + if (!guest_prepare(test))
> + GUEST_SYNC(CMD_SKIP_TEST);
> +
> + GUEST_SYNC(test->mem_mark_cmd);
> + test->guest_test();
> +
> + guest_test_check(test);
> + GUEST_DONE();
> +}
[...]
> +
> +#define SNAME(s) #s
> +#define SCAT2(a, b) SNAME(a ## _ ## b)
> +#define SCAT3(a, b, c) SCAT2(a, SCAT2(b, c))
> +
> +#define _CHECK(_test) _CHECK_##_test
> +#define _PREPARE(_test) _PREPARE_##_test
> +#define _PREPARE_guest_read64 guest_prepare_nop
> +#define _PREPARE_guest_ld_preidx guest_prepare_nop
> +#define _PREPARE_guest_write64 guest_prepare_nop
> +#define _PREPARE_guest_st_preidx guest_prepare_nop
> +#define _PREPARE_guest_exec guest_prepare_nop
> +#define _PREPARE_guest_at guest_prepare_nop
Since you check for NULL in guest_prepare(), could you just use NULL for
these and drop guest_prepare_nop()?
> +#define _PREPARE_guest_dc_zva guest_check_dc_zva
> +#define _PREPARE_guest_cas guest_check_lse
> +
> +/* With or without access flag checks */
> +#define _PREPARE_with_af guest_set_ha, guest_clear_pte_af
> +#define _PREPARE_no_af guest_prepare_nop
> +#define _CHECK_with_af guest_check_pte_af
> +#define _CHECK_no_af guest_check_nop
> +
> +/* Performs an access and checks that no faults (no events) were triggered. */
> +#define TEST_ACCESS(_access, _with_af, _mark_cmd) \
> +{ \
> + .name = SCAT3(_access, _with_af, #_mark_cmd), \
> + .guest_prepare = { _PREPARE(_with_af), \
> + _PREPARE(_access) }, \
> + .mem_mark_cmd = _mark_cmd, \
> + .guest_test = _access, \
> + .guest_test_check = { _CHECK(_with_af) }, \
> + .expected_events = { 0 }, \
> +}
> +
> +static struct test_desc tests[] = {
> + /* Check that HW is setting the Access Flag (AF) (sanity checks). */
> + TEST_ACCESS(guest_read64, with_af, CMD_NONE),
> + TEST_ACCESS(guest_ld_preidx, with_af, CMD_NONE),
> + TEST_ACCESS(guest_cas, with_af, CMD_NONE),
> + TEST_ACCESS(guest_write64, with_af, CMD_NONE),
> + TEST_ACCESS(guest_st_preidx, with_af, CMD_NONE),
> + TEST_ACCESS(guest_dc_zva, with_af, CMD_NONE),
> + TEST_ACCESS(guest_exec, with_af, CMD_NONE),
> +
> + /*
> + * Accessing a hole in the test memslot (punched with fallocate or
> + * madvise) shouldn't fault (more sanity checks).
> + */
> + TEST_ACCESS(guest_read64, no_af, CMD_HOLE_TEST),
> + TEST_ACCESS(guest_cas, no_af, CMD_HOLE_TEST),
> + TEST_ACCESS(guest_ld_preidx, no_af, CMD_HOLE_TEST),
> + TEST_ACCESS(guest_write64, no_af, CMD_HOLE_TEST),
> + TEST_ACCESS(guest_st_preidx, no_af, CMD_HOLE_TEST),
> + TEST_ACCESS(guest_at, no_af, CMD_HOLE_TEST),
> + TEST_ACCESS(guest_dc_zva, no_af, CMD_HOLE_TEST),
> +
> + { 0 },
nit: no comma, we don't want to ever add anything after the sentinel I
presume.
> +};
> +
> +static void for_each_test_and_guest_mode(
> + void (*func)(enum vm_guest_mode m, void *a),
> + enum vm_mem_backing_src_type src_type)
> +{
Could you avoid the forward declaration and instead move definitions
around to satisfy the compiler?
> + struct test_desc *t;
> +
> + for (t = &tests[0]; t->name; t++) {
> + if (t->skip)
> + continue;
> +
> + struct test_params p = {
> + .src_type = src_type,
> + .test_desc = t,
> + };
> +
> + for_each_guest_mode(run_test, &p);
> + }
> +}
> diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h
> index 16753a1f28e3..cb5849fd8fd1 100644
> --- a/tools/testing/selftests/kvm/include/aarch64/processor.h
> +++ b/tools/testing/selftests/kvm/include/aarch64/processor.h
> @@ -125,6 +125,12 @@ enum {
> #define ESR_EC_WP_CURRENT 0x35
> #define ESR_EC_BRK_INS 0x3c
>
> +/* Access flag */
> +#define PTE_AF (1ULL << 10)
> +
> +/* Acces flag update enable/disable */
typo: Access
--
Thanks,
Oliver
next prev parent reply other threads:[~2022-05-25 19:43 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-08 0:41 [PATCH v3 00/13] KVM: selftests: Add aarch64/page_fault_test Ricardo Koller
2022-04-08 0:41 ` [PATCH v3 01/13] KVM: selftests: Add a userfaultfd library Ricardo Koller
2022-04-08 0:41 ` [PATCH v3 02/13] KVM: selftests: aarch64: Add vm_get_pte_gpa library function Ricardo Koller
2022-05-19 3:48 ` Oliver Upton
2022-04-08 0:41 ` [PATCH v3 03/13] KVM: selftests: Add vm_alloc_page_table_in_memslot " Ricardo Koller
2022-05-19 3:53 ` Oliver Upton
2022-04-08 0:41 ` [PATCH v3 04/13] KVM: selftests: aarch64: Export _virt_pg_map with a pt_memslot arg Ricardo Koller
2022-05-19 4:05 ` Oliver Upton
2022-04-08 0:41 ` [PATCH v3 05/13] KVM: selftests: Add missing close and munmap in __vm_mem_region_delete Ricardo Koller
2022-05-19 4:06 ` Oliver Upton
2022-04-08 0:41 ` [PATCH v3 06/13] KVM: selftests: Add vm_mem_region_get_src_fd library function Ricardo Koller
2022-05-19 4:08 ` Oliver Upton
2022-04-08 0:41 ` [PATCH v3 07/13] KVM: selftests: aarch64: Construct DEFAULT_MAIR_EL1 using sysreg.h macros Ricardo Koller
2022-05-19 4:17 ` Oliver Upton
2022-04-08 0:41 ` [PATCH v3 08/13] tools: Copy bitfield.h from the kernel sources Ricardo Koller
2022-05-19 4:25 ` Oliver Upton
2022-04-08 0:41 ` [PATCH v3 09/13] KVM: selftests: aarch64: Add aarch64/page_fault_test Ricardo Koller
2022-05-25 19:43 ` Oliver Upton [this message]
2022-04-08 0:41 ` [PATCH v3 10/13] KVM: selftests: aarch64: Add userfaultfd tests into page_fault_test Ricardo Koller
2022-04-08 0:41 ` [PATCH v3 11/13] KVM: selftests: aarch64: Add dirty logging " Ricardo Koller
2022-04-08 0:41 ` [PATCH v3 12/13] KVM: selftests: aarch64: Add readonly memslot " Ricardo Koller
2022-04-08 0:41 ` [PATCH v3 13/13] KVM: selftests: aarch64: Add mix of " Ricardo Koller
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=Yo6Gz6o1csFCqN9x@google.com \
--to=oupton@google.com \
--cc=alexandru.elisei@arm.com \
--cc=axelrasmussen@google.com \
--cc=bgardon@google.com \
--cc=drjones@redhat.com \
--cc=eric.auger@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=maz@kernel.org \
--cc=pbonzini@redhat.com \
--cc=rananta@google.com \
--cc=reijiw@google.com \
--cc=ricarkol@google.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).