From patchwork Tue Sep 10 23:44:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 13799511 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DE02EE01F4 for ; Tue, 10 Sep 2024 23:46:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 643978D00F1; Tue, 10 Sep 2024 19:45:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A7028D00E2; Tue, 10 Sep 2024 19:45:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3AAAA8D00F1; Tue, 10 Sep 2024 19:45:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 11EE88D00E2 for ; Tue, 10 Sep 2024 19:45:42 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id B6457A09AA for ; Tue, 10 Sep 2024 23:45:41 +0000 (UTC) X-FDA: 82550463282.21.B9340B1 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf05.hostedemail.com (Postfix) with ESMTP id E25B210000D for ; Tue, 10 Sep 2024 23:45:39 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=C3FGK0Dw; spf=pass (imf05.hostedemail.com: domain of 3I9rgZgsKCJg24C6JD6QLF88GG8D6.4GEDAFMP-EECN24C.GJ8@flex--ackerleytng.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3I9rgZgsKCJg24C6JD6QLF88GG8D6.4GEDAFMP-EECN24C.GJ8@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726011836; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TlIOiJjV6U0PI3iCsuHTa2oFdtPEU4Vo6B5xI+1eOyo=; b=pnzfOygupZrMl7RfPQdEEDk4Y0rIqy65soTCQDYlycl1A7g/V09b3x3YFKpDgUKgb+oB7i X5y0POjf9YPVxgfmE/aEROeB6pe7EwLTBr0ADAbABlFPLk/kijNwuJ6JClYQRk6Nbj8qNQ Ro2xuh/FWXuf5NB6CEA1kQEMVrMWLGI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726011836; a=rsa-sha256; cv=none; b=aO0FALfLOjKhoiIDtfWD81THTgoK5DnU1/Pe2WMlu5dnupQyim9S0c43w4aDxybdqbYkDA O1t8JpU7iQJS0dxuMpMUZ78TgO8SXAuS/hXmjqENNG6p7RdCaq79jJ/WevWgw1TRnBx1y0 INQG7MQQ9Tr3Ts+PuNN++Vy7NcdYkB0= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=C3FGK0Dw; spf=pass (imf05.hostedemail.com: domain of 3I9rgZgsKCJg24C6JD6QLF88GG8D6.4GEDAFMP-EECN24C.GJ8@flex--ackerleytng.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3I9rgZgsKCJg24C6JD6QLF88GG8D6.4GEDAFMP-EECN24C.GJ8@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6db7a8c6910so87037337b3.0 for ; Tue, 10 Sep 2024 16:45:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726011939; x=1726616739; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=TlIOiJjV6U0PI3iCsuHTa2oFdtPEU4Vo6B5xI+1eOyo=; b=C3FGK0DwIe/R+zwABPGLI+gNQwC+ghKN+hQ5g+BWdSwI7ZGsMQVJ66RH1nj8owHu+8 TMBphGV6KKbCTC8fo6CRO+11QbJhcOFWCriRH+HZArDFo7kJQhY6q3rCrgqbTCH7Fia8 YIvBvo7uSdBUWX1c9N2xPmmXKYkNxTOu4HqdJQUjOi62nVRDxO0hNMooUUpRqlm3SmT+ 5ubTGsuovSdOyhYaPL1MkW8oE8s4nPh9C7VdGo4YKwUmtvvc1L9qRHOgUDG1sHxNBIL3 7mkOfunC/uDQT1xeEADHqLCyyEM/o5sl8p74SGz9KUqH6Uda9pB8o2AnkNFw9tWQPu84 1kWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726011939; x=1726616739; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TlIOiJjV6U0PI3iCsuHTa2oFdtPEU4Vo6B5xI+1eOyo=; b=IbpnRHiJQFA8oDATGippQIC3gE9c94ptaDH32jXHsDOTN7Ks1W8mB3aU3YBbGn4nGE IRkHh2tvBNTvN54tQnLjX2UytQJhcuKNnA2WkC6bCTbfIoD2EAgJSxgOGTAy/ploP/Qm Z4+lLlrgXoG3zLVuOpMZhTrBdYMy6kehqK5HLsXtUlsN4CkdUTeQJFXGR/8WwKsd3JWr jLq5ufVwH8D1lOuarR90y+gb/KrcdN1TYvltLL73Jn6wgALA7Bw1Itvox5B7X3tQLnr5 LGq3FFD3/IQ6/sydHKM/56rz5lYdf5wUDuyGOUxRV+ineUN7/eR7KxCRuwoIfDnnfzw3 01rg== X-Forwarded-Encrypted: i=1; AJvYcCXgevIinvpgBsBsW5AOcNjlHEgCr/sg4pJJ3ThIGOyL69Hg+xpKcdyfTZWAZXFSG0M9CzV3KJKYiA==@kvack.org X-Gm-Message-State: AOJu0Yxsm8cBsMnjvAPK/JwZlq8HpxDAfiy2MK8q8m8/P3eJbkRpLfo3 dnix+Pu6UWtOsCSHwau36CPiXOShfskik6UGzFNHU1TYTvpRs/SPzgF1drTbv9brSlDPyxwm/56 Og3xO6TRuVGsN16/7g2JPGw== X-Google-Smtp-Source: AGHT+IH3N5qL0TDHwb+ahMnzs9ETG7Svm+A6F+qfQL1tieuJZR8fE0gET637CAqDRn32FQw0mJ0L0E81ldHixRjnIw== X-Received: from ackerleytng-ctop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:13f8]) (user=ackerleytng job=sendgmr) by 2002:a05:690c:c93:b0:6b0:57ec:c5f9 with SMTP id 00721157ae682-6db44a59f17mr6527007b3.0.1726011939045; Tue, 10 Sep 2024 16:45:39 -0700 (PDT) Date: Tue, 10 Sep 2024 23:44:09 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog Message-ID: <3ef4b32d32dca6e1b506e967c950dc2d4c3bc7ae.1726009989.git.ackerleytng@google.com> Subject: [RFC PATCH 38/39] KVM: selftests: Update private_mem_conversions_test for mmap()able guest_memfd From: Ackerley Tng To: tabba@google.com, quic_eberman@quicinc.com, roypat@amazon.co.uk, jgg@nvidia.com, peterx@redhat.com, david@redhat.com, rientjes@google.com, fvdl@google.com, jthoughton@google.com, seanjc@google.com, pbonzini@redhat.com, zhiquan1.li@intel.com, fan.du@intel.com, jun.miao@intel.com, isaku.yamahata@intel.com, muchun.song@linux.dev, mike.kravetz@oracle.com Cc: erdemaktas@google.com, vannapurve@google.com, ackerleytng@google.com, qperret@google.com, jhubbard@nvidia.com, willy@infradead.org, shuah@kernel.org, brauner@kernel.org, bfoster@redhat.com, kent.overstreet@linux.dev, pvorel@suse.cz, rppt@kernel.org, richard.weiyang@gmail.com, anup@brainfault.org, haibo1.xu@intel.com, ajones@ventanamicro.com, vkuznets@redhat.com, maciej.wieczor-retman@intel.com, pgonda@google.com, oliver.upton@linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-fsdevel@kvack.org X-Stat-Signature: 61wkafpbeghaamkxic7izfmm7ryq3wsw X-Rspamd-Queue-Id: E25B210000D X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1726011939-164545 X-HE-Meta: U2FsdGVkX1+/S0CFvUNzIQegHlVipW0b3vRAFBnL7MtZR/c4Ux/TBFfckB0K6dSupsL8gAGjroTVyR/dHC4OJiYRzm5/F34BLK3j6U1cHksufV8Gu14eXk0XixCQXozsSmQgbJYpp5FRONsyXvbmMU7wjjw9kdT90/qKs+jTJakWJu85AoHQ2JW6ip9kSNfaErWD4I45tfYgw4QbWGlrIAuIBay/VauQ9fHhPEaQiv6mlLxl+CUpoW9uWyzKc9p8YmL3BjIVBjQTqKr2bXeSVE/GRpl2fV1pr62MKCb6f4l4rujdhbNAYPuIHaEw0AS2Cx2nPelXYUOeMBViDpungMERcg6ltEdO0rqvm+FnRuW4u9SnrraQzetD2iN3pqePoEltxyqHoTyO2qEgUw+2XmPMSwqzUJFsi1VWYG9nsieAIQ3r+m+zTnazQKhIJTxMmlM8gyfzfIpNq++LqX5hrPJ1fahdr2zI7kE8qBjFSSEQ2GMhl5xhucQX/4LG7hYODWYIXhTdMy/OhwXGXKkF4S0D76QheiyfaYDiZs+mbBWNd21w+PeLyFtFAAjyZUEI23h/N5Y7tU46sRkvJDeTOea5AJsQJNvQgrzUvrKPfSLjJxfQMTROHLKEeiUveL8gmns+0inpIR67JqsFL4hdIxECT7ci/wqaOXRyVeRX7REjnJI/Rb6ErIofstIxWdii5UucyftwpAeHkfuZybupnbisI/KyVMMBt5yAdBgqu6VsfpoFRJMSc+hOjLo++RxUpO+i6A8sGiuxwjfnJJleXQZGY5rB7D5ZZx575de1g+XqQS57WzH665ayluEvOpnV5ZS7txqNllFgOSanicWoAl08bqjyMKXOqhs5ZsLLyXXHuwLVflVAG3c+MEg4OJD7fqxt9gvvo2tAJOTLyyS/aLdZD0bVBvB/msXCjufwPRzMiEISNjFALvnJxJv45MI12L+YlUJ24i6/X94CH9g KsLlpSna Zq4EGM8pELfHJkTVhtCa8gAWKn0GEgqgXmYHNaZizyOjYFEcuz/LltL2mE0tnKKHHqQZpYndFyIKXMtFHBWPyBQqH8M/c61ARORDhSmlMu+nRKQgHs/oqnqTpefykfTRGpgvrQx9TerB0UqFYi2ZSzKV2Yo7tTtjN3Jl6s+/zMUixgQZUug0rmwzP2laVLlwnoNmcbWmfaAhbsHTeSp1xek99D7NFrE8ADosBXk4aPOanibLg27UpAJtNtvjYC5kE0NzHNGKhqy8aKOC7/YcuckMwKSuyuxJVQsrozfp3kCRQ3w9/LMghkzs0QzkgCTPh3bogc2/i8En9lQedJIIJ/NXxfjtwYw5RlsHOMSGTk3A9bm8qswmKYQntwJvtW50yAoKLZQalzjGZbInZrakiEPXLaTPC3sQ3bHMKUH344PDqQvZRb+ZydUJDz4Ex/9vx5OSqjcPUu50qhc9h5aVbuwgMxbCx8ah1cy9bfY/PU412ar/ZdVODKhdvjKm/NZ6iNYjFez7hrzsV45jWe7iwzncZ3aUpEAircnjCdq6Ez8Y6Pyz28YpvTvZB93eRETG26td/jguL5dP+KGT1CdqlEQlDECbksSWlEySGGOODP+vb6hXlto+OG3UDgWI7+dv6ig+mnj3QS4s1CJbv3+DTAQds82oMw9J0GgYZlncqoqg6Zz62Y0bkAWP/Rb/gSU6TtdZzh2MKzryOsxM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Signed-off-by: Ackerley Tng --- .../kvm/x86_64/private_mem_conversions_test.c | 146 +++++++++++++++--- .../x86_64/private_mem_conversions_test.sh | 3 + 2 files changed, 124 insertions(+), 25 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c b/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c index 71f480c19f92..6524ef398584 100644 --- a/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c +++ b/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include #include @@ -202,15 +204,19 @@ static void guest_test_explicit_conversion(uint64_t base_gpa, bool do_fallocate) guest_sync_shared(gpa, size, p3, p4); memcmp_g(gpa, p4, size); - /* Reset the shared memory back to the initial pattern. */ - memset((void *)gpa, init_p, size); - /* * Free (via PUNCH_HOLE) *all* private memory so that the next * iteration starts from a clean slate, e.g. with respect to * whether or not there are pages/folios in guest_mem. */ guest_map_shared(base_gpa, PER_CPU_DATA_SIZE, true); + + /* + * Reset the entire block back to the initial pattern. Do this + * after fallocate(PUNCH_HOLE) because hole-punching zeroes + * memory. + */ + memset((void *)base_gpa, init_p, PER_CPU_DATA_SIZE); } } @@ -286,7 +292,8 @@ static void guest_code(uint64_t base_gpa) GUEST_DONE(); } -static void handle_exit_hypercall(struct kvm_vcpu *vcpu) +static void handle_exit_hypercall(struct kvm_vcpu *vcpu, + bool back_shared_memory_with_guest_memfd) { struct kvm_run *run = vcpu->run; uint64_t gpa = run->hypercall.args[0]; @@ -303,17 +310,46 @@ static void handle_exit_hypercall(struct kvm_vcpu *vcpu) if (do_fallocate) vm_guest_mem_fallocate(vm, gpa, size, map_shared); - if (set_attributes) + if (set_attributes) { + if (back_shared_memory_with_guest_memfd && !map_shared) + vm_guest_mem_madvise(vm, gpa, size, MADV_DONTNEED); vm_set_memory_attributes(vm, gpa, size, map_shared ? 0 : KVM_MEMORY_ATTRIBUTE_PRIVATE); + } run->hypercall.ret = 0; } +static void assert_not_faultable(uint8_t *address) +{ + pid_t child_pid; + + child_pid = fork(); + TEST_ASSERT(child_pid != -1, "fork failed"); + + if (child_pid == 0) { + *address = 'A'; + } else { + int status; + waitpid(child_pid, &status, 0); + + TEST_ASSERT(WIFSIGNALED(status), + "Child should have exited with a signal"); + TEST_ASSERT_EQ(WTERMSIG(status), SIGBUS); + } +} + static bool run_vcpus; -static void *__test_mem_conversions(void *__vcpu) +struct test_thread_args { - struct kvm_vcpu *vcpu = __vcpu; + struct kvm_vcpu *vcpu; + bool back_shared_memory_with_guest_memfd; +}; + +static void *__test_mem_conversions(void *params) +{ + struct test_thread_args *args = params; + struct kvm_vcpu *vcpu = args->vcpu; struct kvm_run *run = vcpu->run; struct kvm_vm *vm = vcpu->vm; struct ucall uc; @@ -325,7 +361,8 @@ static void *__test_mem_conversions(void *__vcpu) vcpu_run(vcpu); if (run->exit_reason == KVM_EXIT_HYPERCALL) { - handle_exit_hypercall(vcpu); + handle_exit_hypercall(vcpu, + args->back_shared_memory_with_guest_memfd); continue; } @@ -349,8 +386,18 @@ static void *__test_mem_conversions(void *__vcpu) size_t nr_bytes = min_t(size_t, vm->page_size, size - i); uint8_t *hva = addr_gpa2hva(vm, gpa + i); - /* In all cases, the host should observe the shared data. */ - memcmp_h(hva, gpa + i, uc.args[3], nr_bytes); + /* Check contents of memory */ + if (args->back_shared_memory_with_guest_memfd && + uc.args[0] == SYNC_PRIVATE) { + assert_not_faultable(hva); + } else { + /* + * If shared and private memory use + * separate backing memory, the host + * should always observe shared data. + */ + memcmp_h(hva, gpa + i, uc.args[3], nr_bytes); + } /* For shared, write the new pattern to guest memory. */ if (uc.args[0] == SYNC_SHARED) @@ -366,11 +413,41 @@ static void *__test_mem_conversions(void *__vcpu) } } -static void -test_mem_conversions(enum vm_mem_backing_src_type src_type, - enum vm_private_mem_backing_src_type private_mem_src_type, - uint32_t nr_vcpus, - uint32_t nr_memslots) +static void add_memslot(struct kvm_vm *vm, uint64_t gpa, uint32_t slot, + uint64_t size, int guest_memfd, + uint64_t guest_memfd_offset, + enum vm_mem_backing_src_type src_type, + bool back_shared_memory_with_guest_memfd) +{ + struct userspace_mem_region *region; + + if (!back_shared_memory_with_guest_memfd) { + vm_mem_add(vm, src_type, gpa, slot, size / vm->page_size, + KVM_MEM_GUEST_MEMFD, guest_memfd, + guest_memfd_offset); + return; + } + + region = vm_mem_region_alloc(vm); + + guest_memfd = vm_mem_region_install_guest_memfd(region, guest_memfd); + + vm_mem_region_mmap(region, size, MAP_SHARED, guest_memfd, guest_memfd_offset); + vm_mem_region_install_memory(region, size, getpagesize()); + + region->region.slot = slot; + region->region.flags = KVM_MEM_GUEST_MEMFD; + region->region.guest_phys_addr = gpa; + region->region.guest_memfd_offset = guest_memfd_offset; + + vm_mem_region_add(vm, region); +} + +static void test_mem_conversions(enum vm_mem_backing_src_type src_type, + enum vm_private_mem_backing_src_type private_mem_src_type, + uint32_t nr_vcpus, + uint32_t nr_memslots, + bool back_shared_memory_with_guest_memfd) { /* * Allocate enough memory so that each vCPU's chunk of memory can be @@ -381,6 +458,7 @@ test_mem_conversions(enum vm_mem_backing_src_type src_type, get_private_mem_backing_src_pagesz(private_mem_src_type), get_backing_src_pagesz(src_type))); const size_t per_cpu_size = align_up(PER_CPU_DATA_SIZE, alignment); + struct test_thread_args *thread_args[KVM_MAX_VCPUS]; const size_t memfd_size = per_cpu_size * nr_vcpus; const size_t slot_size = memfd_size / nr_memslots; struct kvm_vcpu *vcpus[KVM_MAX_VCPUS]; @@ -404,13 +482,14 @@ test_mem_conversions(enum vm_mem_backing_src_type src_type, vm, memfd_size, vm_private_mem_backing_src_alias(private_mem_src_type)->flag); - for (i = 0; i < nr_memslots; i++) - vm_mem_add(vm, src_type, BASE_DATA_GPA + slot_size * i, - BASE_DATA_SLOT + i, slot_size / vm->page_size, - KVM_MEM_GUEST_MEMFD, memfd, slot_size * i); + for (i = 0; i < nr_memslots; i++) { + add_memslot(vm, BASE_DATA_GPA + slot_size * i, + BASE_DATA_SLOT + i, slot_size, memfd, slot_size * i, + src_type, back_shared_memory_with_guest_memfd); + } for (i = 0; i < nr_vcpus; i++) { - uint64_t gpa = BASE_DATA_GPA + i * per_cpu_size; + uint64_t gpa = BASE_DATA_GPA + i * per_cpu_size; vcpu_args_set(vcpus[i], 1, gpa); @@ -420,13 +499,23 @@ test_mem_conversions(enum vm_mem_backing_src_type src_type, */ virt_map(vm, gpa, gpa, PER_CPU_DATA_SIZE / vm->page_size); - pthread_create(&threads[i], NULL, __test_mem_conversions, vcpus[i]); + thread_args[i] = malloc(sizeof(struct test_thread_args)); + TEST_ASSERT(thread_args[i] != NULL, + "Could not allocate memory for thread parameters"); + thread_args[i]->vcpu = vcpus[i]; + thread_args[i]->back_shared_memory_with_guest_memfd = + back_shared_memory_with_guest_memfd; + + pthread_create(&threads[i], NULL, __test_mem_conversions, + (void *)thread_args[i]); } WRITE_ONCE(run_vcpus, true); - for (i = 0; i < nr_vcpus; i++) + for (i = 0; i < nr_vcpus; i++) { pthread_join(threads[i], NULL); + free(thread_args[i]); + } kvm_vm_free(vm); @@ -448,7 +537,7 @@ test_mem_conversions(enum vm_mem_backing_src_type src_type, static void usage(const char *cmd) { puts(""); - printf("usage: %s [-h] [-m nr_memslots] [-s mem_type] [-p private_mem_type] [-n nr_vcpus]\n", cmd); + printf("usage: %s [-h] [-m nr_memslots] [-s mem_type] [-p private_mem_type] [-n nr_vcpus] [-g]\n", cmd); puts(""); backing_src_help("-s"); puts(""); @@ -458,19 +547,22 @@ static void usage(const char *cmd) puts(""); puts(" -m: specify the number of memslots (default: 1)"); puts(""); + puts(" -g: back shared memory with guest_memfd (default: false)"); + puts(""); } int main(int argc, char *argv[]) { enum vm_mem_backing_src_type src_type = DEFAULT_VM_MEM_SRC; enum vm_private_mem_backing_src_type private_mem_src_type = DEFAULT_VM_PRIVATE_MEM_SRC; + bool back_shared_memory_with_guest_memfd = false; uint32_t nr_memslots = 1; uint32_t nr_vcpus = 1; int opt; TEST_REQUIRE(kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_SW_PROTECTED_VM)); - while ((opt = getopt(argc, argv, "hm:s:p:n:")) != -1) { + while ((opt = getopt(argc, argv, "hgm:s:p:n:")) != -1) { switch (opt) { case 's': src_type = parse_backing_src_type(optarg); @@ -484,6 +576,9 @@ int main(int argc, char *argv[]) case 'm': nr_memslots = atoi_positive("nr_memslots", optarg); break; + case 'g': + back_shared_memory_with_guest_memfd = true; + break; case 'h': default: usage(argv[0]); @@ -491,7 +586,8 @@ int main(int argc, char *argv[]) } } - test_mem_conversions(src_type, private_mem_src_type, nr_vcpus, nr_memslots); + test_mem_conversions(src_type, private_mem_src_type, nr_vcpus, nr_memslots, + back_shared_memory_with_guest_memfd); return 0; } diff --git a/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.sh b/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.sh index fb6705fef466..c7f3dfee0336 100755 --- a/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.sh +++ b/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.sh @@ -75,6 +75,9 @@ TEST_EXECUTABLE="$(dirname "$0")/private_mem_conversions_test" $TEST_EXECUTABLE -s "$src_type" -p "$private_mem_src_type" -n $num_vcpus_to_test $TEST_EXECUTABLE -s "$src_type" -p "$private_mem_src_type" -n $num_vcpus_to_test -m $num_memslots_to_test + $TEST_EXECUTABLE -s "$src_type" -p "$private_mem_src_type" -n $num_vcpus_to_test -g + $TEST_EXECUTABLE -s "$src_type" -p "$private_mem_src_type" -n $num_vcpus_to_test -m $num_memslots_to_test -g + { set +x; } 2>/dev/null echo