From: Sean Christopherson <seanjc@google.com>
To: Ricardo Koller <ricarkol@google.com>
Cc: kvm@vger.kernel.org, maz@kernel.org, bgardon@google.com,
andrew.jones@linux.dev, kvmarm@lists.linux.dev,
pbonzini@redhat.com, axelrasmussen@google.com,
kvmarm@lists.cs.columbia.edu, dmatlack@google.com
Subject: Re: [PATCH v9 10/14] KVM: selftests: aarch64: Add aarch64/page_fault_test
Date: Fri, 14 Oct 2022 21:23:30 +0000 [thread overview]
Message-ID: <Y0nTUmsC7YGTQery@google.com> (raw)
In-Reply-To: <20221011010628.1734342-11-ricarkol@google.com>
On Tue, Oct 11, 2022, Ricardo Koller wrote:
> +/* Returns true to continue the test, and false if it should be skipped. */
> +static bool punch_hole_in_backing_store(struct kvm_vm *vm,
> + struct userspace_mem_region *region)
> +{
> + void *hva = (void *)region->region.userspace_addr;
> + uint64_t paging_size = region->region.memory_size;
> + int ret, fd = region->fd;
> +
> + if (fd != -1) {
> + ret = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
> + 0, paging_size);
> + TEST_ASSERT(ret == 0, "fallocate failed, errno: %d\n", errno);
> + } else {
> + ret = madvise(hva, paging_size, MADV_DONTNEED);
> + TEST_ASSERT(ret == 0, "madvise failed, errno: %d\n", errno);
> + }
Uber nit, no need to manually print the errno, TEST_ASSERT() does that automatically
and pretty prints the string too. I know this because I keep forgetting myself :-).
> +/* Returns true to continue the test, and false if it should be skipped. */
> +static bool handle_cmd(struct kvm_vm *vm, int cmd)
> +{
> + struct userspace_mem_region *data_region, *pt_region;
> + bool continue_test = true;
> +
> + data_region = vm_get_mem_region(vm, MEM_REGION_TEST_DATA);
> + pt_region = vm_get_mem_region(vm, MEM_REGION_PT);
> +
> + if (cmd == CMD_SKIP_TEST)
> + continue_test = false;
> +
> + if (cmd & CMD_HOLE_PT)
> + continue_test = punch_hole_in_backing_store(vm, pt_region);
> + if (cmd & CMD_HOLE_DATA)
> + continue_test = punch_hole_in_backing_store(vm, data_region);
> +
> + return continue_test;
> +}
...
> +static void setup_abort_handlers(struct kvm_vm *vm, struct kvm_vcpu *vcpu,
> + struct test_desc *test)
Align params.
static void setup_abort_handlers(struct kvm_vm *vm, struct kvm_vcpu *vcpu,
struct test_desc *test)
> +static void for_each_test_and_guest_mode(
> + void (*func)(enum vm_guest_mode m, void *a),
If you spin a new version, can you put together a patch or mini-series to add a
typedef for this function pointer? Then this function doesn't need a funky wrap.
Or alternatively, as follow-up to avoid delaying this series even longer.
E.g.
static void for_each_test_and_guest_mode(guest_mode_test_t func,
enum vm_mem_backing_src_type src_type)
diff --git a/tools/testing/selftests/kvm/include/guest_modes.h b/tools/testing/selftests/kvm/include/guest_modes.h
index b691df33e64e..ee7c5c271eb2 100644
--- a/tools/testing/selftests/kvm/include/guest_modes.h
+++ b/tools/testing/selftests/kvm/include/guest_modes.h
@@ -15,7 +15,9 @@ extern struct guest_mode guest_modes[NUM_VM_MODES];
guest_modes[mode] = (struct guest_mode){ supported, enabled }; \
})
+typedef void (*guest_mode_test_t)(enum vm_guest_mode, void *);
+
void guest_modes_append_default(void);
-void for_each_guest_mode(void (*func)(enum vm_guest_mode, void *), void *arg);
+void for_each_guest_mode(guest_mode_test_t func, void *arg);
void guest_modes_help(void);
void guest_modes_cmdline(const char *arg);
> + enum vm_mem_backing_src_type src_type)
> +{
> + 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);
> + }
> +}
> +
> +int main(int argc, char *argv[])
> +{
> + enum vm_mem_backing_src_type src_type;
> + int opt;
> +
> + setbuf(stdout, NULL);
> +
> + src_type = DEFAULT_VM_MEM_SRC;
> +
> + while ((opt = getopt(argc, argv, "hm:s:")) != -1) {
> + switch (opt) {
> + case 'm':
> + guest_modes_cmdline(optarg);
> + break;
> + case 's':
> + src_type = parse_backing_src_type(optarg);
> + break;
> + case 'h':
> + default:
> + help(argv[0]);
> + exit(0);
> + }
> + }
> +
> + for_each_test_and_guest_mode(run_test, src_type);
> + return 0;
> +}
> diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h
> index c1ddca8db225..5f977528e09c 100644
> --- a/tools/testing/selftests/kvm/include/aarch64/processor.h
> +++ b/tools/testing/selftests/kvm/include/aarch64/processor.h
> @@ -105,11 +105,19 @@ enum {
> #define ESR_EC_MASK (ESR_EC_NUM - 1)
>
> #define ESR_EC_SVC64 0x15
> +#define ESR_EC_IABT 0x21
> +#define ESR_EC_DABT 0x25
> #define ESR_EC_HW_BP_CURRENT 0x31
> #define ESR_EC_SSTEP_CURRENT 0x33
> #define ESR_EC_WP_CURRENT 0x35
> #define ESR_EC_BRK_INS 0x3c
>
> +/* Access flag */
> +#define PTE_AF (1ULL << 10)
> +
> +/* 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);
>
> --
> 2.38.0.rc1.362.ged0d419d3c-goog
>
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
WARNING: multiple messages have this Message-ID (diff)
From: Sean Christopherson <seanjc@google.com>
To: Ricardo Koller <ricarkol@google.com>
Cc: kvm@vger.kernel.org, kvmarm@lists.linux.dev,
kvmarm@lists.cs.columbia.edu, andrew.jones@linux.dev,
pbonzini@redhat.com, maz@kernel.org, alexandru.elisei@arm.com,
eric.auger@redhat.com, oupton@google.com, reijiw@google.com,
rananta@google.com, bgardon@google.com, dmatlack@google.com,
axelrasmussen@google.com
Subject: Re: [PATCH v9 10/14] KVM: selftests: aarch64: Add aarch64/page_fault_test
Date: Fri, 14 Oct 2022 21:23:30 +0000 [thread overview]
Message-ID: <Y0nTUmsC7YGTQery@google.com> (raw)
Message-ID: <20221014212330.YkUBblKWNFi1Om_YQcp6n51LKGcMi5BilqsawnDf8fw@z> (raw)
In-Reply-To: <20221011010628.1734342-11-ricarkol@google.com>
On Tue, Oct 11, 2022, Ricardo Koller wrote:
> +/* Returns true to continue the test, and false if it should be skipped. */
> +static bool punch_hole_in_backing_store(struct kvm_vm *vm,
> + struct userspace_mem_region *region)
> +{
> + void *hva = (void *)region->region.userspace_addr;
> + uint64_t paging_size = region->region.memory_size;
> + int ret, fd = region->fd;
> +
> + if (fd != -1) {
> + ret = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
> + 0, paging_size);
> + TEST_ASSERT(ret == 0, "fallocate failed, errno: %d\n", errno);
> + } else {
> + ret = madvise(hva, paging_size, MADV_DONTNEED);
> + TEST_ASSERT(ret == 0, "madvise failed, errno: %d\n", errno);
> + }
Uber nit, no need to manually print the errno, TEST_ASSERT() does that automatically
and pretty prints the string too. I know this because I keep forgetting myself :-).
> +/* Returns true to continue the test, and false if it should be skipped. */
> +static bool handle_cmd(struct kvm_vm *vm, int cmd)
> +{
> + struct userspace_mem_region *data_region, *pt_region;
> + bool continue_test = true;
> +
> + data_region = vm_get_mem_region(vm, MEM_REGION_TEST_DATA);
> + pt_region = vm_get_mem_region(vm, MEM_REGION_PT);
> +
> + if (cmd == CMD_SKIP_TEST)
> + continue_test = false;
> +
> + if (cmd & CMD_HOLE_PT)
> + continue_test = punch_hole_in_backing_store(vm, pt_region);
> + if (cmd & CMD_HOLE_DATA)
> + continue_test = punch_hole_in_backing_store(vm, data_region);
> +
> + return continue_test;
> +}
...
> +static void setup_abort_handlers(struct kvm_vm *vm, struct kvm_vcpu *vcpu,
> + struct test_desc *test)
Align params.
static void setup_abort_handlers(struct kvm_vm *vm, struct kvm_vcpu *vcpu,
struct test_desc *test)
> +static void for_each_test_and_guest_mode(
> + void (*func)(enum vm_guest_mode m, void *a),
If you spin a new version, can you put together a patch or mini-series to add a
typedef for this function pointer? Then this function doesn't need a funky wrap.
Or alternatively, as follow-up to avoid delaying this series even longer.
E.g.
static void for_each_test_and_guest_mode(guest_mode_test_t func,
enum vm_mem_backing_src_type src_type)
diff --git a/tools/testing/selftests/kvm/include/guest_modes.h b/tools/testing/selftests/kvm/include/guest_modes.h
index b691df33e64e..ee7c5c271eb2 100644
--- a/tools/testing/selftests/kvm/include/guest_modes.h
+++ b/tools/testing/selftests/kvm/include/guest_modes.h
@@ -15,7 +15,9 @@ extern struct guest_mode guest_modes[NUM_VM_MODES];
guest_modes[mode] = (struct guest_mode){ supported, enabled }; \
})
+typedef void (*guest_mode_test_t)(enum vm_guest_mode, void *);
+
void guest_modes_append_default(void);
-void for_each_guest_mode(void (*func)(enum vm_guest_mode, void *), void *arg);
+void for_each_guest_mode(guest_mode_test_t func, void *arg);
void guest_modes_help(void);
void guest_modes_cmdline(const char *arg);
> + enum vm_mem_backing_src_type src_type)
> +{
> + 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);
> + }
> +}
> +
> +int main(int argc, char *argv[])
> +{
> + enum vm_mem_backing_src_type src_type;
> + int opt;
> +
> + setbuf(stdout, NULL);
> +
> + src_type = DEFAULT_VM_MEM_SRC;
> +
> + while ((opt = getopt(argc, argv, "hm:s:")) != -1) {
> + switch (opt) {
> + case 'm':
> + guest_modes_cmdline(optarg);
> + break;
> + case 's':
> + src_type = parse_backing_src_type(optarg);
> + break;
> + case 'h':
> + default:
> + help(argv[0]);
> + exit(0);
> + }
> + }
> +
> + for_each_test_and_guest_mode(run_test, src_type);
> + return 0;
> +}
> diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h
> index c1ddca8db225..5f977528e09c 100644
> --- a/tools/testing/selftests/kvm/include/aarch64/processor.h
> +++ b/tools/testing/selftests/kvm/include/aarch64/processor.h
> @@ -105,11 +105,19 @@ enum {
> #define ESR_EC_MASK (ESR_EC_NUM - 1)
>
> #define ESR_EC_SVC64 0x15
> +#define ESR_EC_IABT 0x21
> +#define ESR_EC_DABT 0x25
> #define ESR_EC_HW_BP_CURRENT 0x31
> #define ESR_EC_SSTEP_CURRENT 0x33
> #define ESR_EC_WP_CURRENT 0x35
> #define ESR_EC_BRK_INS 0x3c
>
> +/* Access flag */
> +#define PTE_AF (1ULL << 10)
> +
> +/* 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);
>
> --
> 2.38.0.rc1.362.ged0d419d3c-goog
>
next prev parent reply other threads:[~2022-10-14 21:23 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-11 1:06 [PATCH v9 00/14] KVM: selftests: Add aarch64/page_fault_test Ricardo Koller
2022-10-11 1:06 ` Ricardo Koller
2022-10-11 1:06 ` [PATCH v9 01/14] KVM: selftests: Add a userfaultfd library Ricardo Koller
2022-10-11 1:06 ` Ricardo Koller
2022-10-14 21:15 ` Sean Christopherson
2022-10-14 21:15 ` Sean Christopherson
2022-10-11 1:06 ` [PATCH v9 02/14] KVM: selftests: aarch64: Add virt_get_pte_hva() library function Ricardo Koller
2022-10-11 1:06 ` Ricardo Koller
2022-10-11 1:06 ` [PATCH v9 03/14] KVM: selftests: Add missing close and munmap in __vm_mem_region_delete() Ricardo Koller
2022-10-11 1:06 ` Ricardo Koller
2022-10-11 1:06 ` [PATCH v9 04/14] KVM: selftests: aarch64: Construct DEFAULT_MAIR_EL1 using sysreg.h macros Ricardo Koller
2022-10-11 1:06 ` Ricardo Koller
2022-10-11 1:06 ` [PATCH v9 05/14] tools: Copy bitfield.h from the kernel sources Ricardo Koller
2022-10-11 1:06 ` Ricardo Koller
2022-10-11 1:06 ` [PATCH v9 06/14] KVM: selftests: Stash backing_src_type in struct userspace_mem_region Ricardo Koller
2022-10-11 1:06 ` Ricardo Koller
2022-10-11 1:06 ` [PATCH v9 07/14] KVM: selftests: Add vm->memslots[] and enum kvm_mem_region_type Ricardo Koller
2022-10-11 1:06 ` Ricardo Koller
2022-10-11 1:06 ` [PATCH v9 08/14] KVM: selftests: Fix alignment in virt_arch_pgd_alloc() and vm_vaddr_alloc() Ricardo Koller
2022-10-11 1:06 ` Ricardo Koller
2022-10-13 14:09 ` Andrew Jones
2022-10-13 14:09 ` Andrew Jones
2022-10-11 1:06 ` [PATCH v9 09/14] KVM: selftests: Use the right memslot for code, page-tables, and data allocations Ricardo Koller
2022-10-11 1:06 ` Ricardo Koller
2022-10-13 14:14 ` Andrew Jones
2022-10-13 14:14 ` Andrew Jones
2022-10-11 1:06 ` [PATCH v9 10/14] KVM: selftests: aarch64: Add aarch64/page_fault_test Ricardo Koller
2022-10-11 1:06 ` Ricardo Koller
2022-10-14 21:23 ` Sean Christopherson [this message]
2022-10-14 21:23 ` Sean Christopherson
2022-10-11 1:06 ` [PATCH v9 11/14] KVM: selftests: aarch64: Add userfaultfd tests into page_fault_test Ricardo Koller
2022-10-11 1:06 ` Ricardo Koller
2022-10-14 21:27 ` Sean Christopherson
2022-10-14 21:27 ` Sean Christopherson
2022-10-11 1:06 ` [PATCH v9 12/14] KVM: selftests: aarch64: Add dirty logging " Ricardo Koller
2022-10-11 1:06 ` Ricardo Koller
2022-10-14 21:28 ` Sean Christopherson
2022-10-14 21:28 ` Sean Christopherson
2022-10-11 1:06 ` [PATCH v9 13/14] KVM: selftests: aarch64: Add readonly memslot " Ricardo Koller
2022-10-11 1:06 ` Ricardo Koller
2022-10-11 1:06 ` [PATCH v9 14/14] KVM: selftests: aarch64: Add mix of " Ricardo Koller
2022-10-11 1:06 ` Ricardo Koller
2022-10-14 21:30 ` [PATCH v9 00/14] KVM: selftests: Add aarch64/page_fault_test Sean Christopherson
2022-10-14 21:30 ` Sean Christopherson
2022-10-14 21:37 ` Ricardo Koller
2022-10-14 21:37 ` 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=Y0nTUmsC7YGTQery@google.com \
--to=seanjc@google.com \
--cc=andrew.jones@linux.dev \
--cc=axelrasmussen@google.com \
--cc=bgardon@google.com \
--cc=dmatlack@google.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=pbonzini@redhat.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 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.