From patchwork Thu Mar 16 00:31:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 13176859 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 4970FC7618B for ; Thu, 16 Mar 2023 00:31:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C9DFD6B008C; Wed, 15 Mar 2023 20:31:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C501E6B0092; Wed, 15 Mar 2023 20:31:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A04B26B0093; Wed, 15 Mar 2023 20:31:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 90AAC6B008C for ; Wed, 15 Mar 2023 20:31:31 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 7069316125F for ; Thu, 16 Mar 2023 00:31:31 +0000 (UTC) X-FDA: 80572882782.14.96F4540 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf01.hostedemail.com (Postfix) with ESMTP id B016740013 for ; Thu, 16 Mar 2023 00:31:29 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=d8uc3IAp; spf=pass (imf01.hostedemail.com: domain of 3YGMSZAsKCJc13B5IC5PKE77FF7C5.3FDC9ELO-DDBM13B.FI7@flex--ackerleytng.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3YGMSZAsKCJc13B5IC5PKE77FF7C5.3FDC9ELO-DDBM13B.FI7@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=1678926689; 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=K90xoVX+0RlzLAw3SfN8qTyLgxMNh2Rq4fRe4RbG85I=; b=37HJEOVux0TDY5zZDyWd63vPMxMcpq60WWjpyTTqiavYFOKWsJOQ6gsPIbvxF22GbIkrRn 5EyfQGgIW1kwvPePqHBXY/t2C/HTWBNS+6h3q/KgURqHN1GMMRPSw1gUt3O+jYPtzcahHj N1H8eL3fT0RkGrkAeZfcJH+ZNAht7WE= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=d8uc3IAp; spf=pass (imf01.hostedemail.com: domain of 3YGMSZAsKCJc13B5IC5PKE77FF7C5.3FDC9ELO-DDBM13B.FI7@flex--ackerleytng.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3YGMSZAsKCJc13B5IC5PKE77FF7C5.3FDC9ELO-DDBM13B.FI7@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678926689; a=rsa-sha256; cv=none; b=wj0RlCGybbI/04vrU1toxcNlYVvvAtTdwDOihgHtImf2gtUMzSRIg5N5NhucuvA8AX69iE QfQpEcGsW3xiHs3uwwPfPb7hAIckFrHy9DS8XbazDKBZNOWkAivQBjt8HbvXees0XxkFvD JWZ31JNwIbUyotGU4crC0SljBI4WIls= Received: by mail-pj1-f73.google.com with SMTP id nm11-20020a17090b19cb00b0023d0c90d851so71665pjb.1 for ; Wed, 15 Mar 2023 17:31:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678926688; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=K90xoVX+0RlzLAw3SfN8qTyLgxMNh2Rq4fRe4RbG85I=; b=d8uc3IApbYmz26P2pZurWd/mdMnPn+5Qfc7rz6kuRm/Rdx7nODA9CSqEzNbHzvos3x RveM5uzlBa4alqsey/A+ZQ+F9FkBIhKp+vzmydZ7x8yVdpJ1dFg58aZJtFtCTBrdqTeM jtglH5cHaz9xRzfcMN6bC6InRMKXNsMGC/lp63mFpBGrilMy6mUNN3C7pjzFUdepgkuU +cgfLXerxqml3OAS1MvZtFFYDjNKV6KkSDelOKwW/Ftb9Njw0KqVRUjV1fgWAjc/PHx5 vlmTiVMmyjWJKxE37zalK36nTXI7Daq2qNoskHBh/u2Z2VdJEZ3uNpydLhqA1aIDw3qB CSMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678926688; 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=K90xoVX+0RlzLAw3SfN8qTyLgxMNh2Rq4fRe4RbG85I=; b=sdT1SAx6bxN2bno4+Bvkc0UP2MWRsRNEq5YaRlk6e0m1GeMzF0Aey8ZCfE9lKArjvB nLZ3AJLMEILkj/zSzTRUfdMLWEJDhafiWIYnpORasy+6yH4XrY9ndDUTZBGCcXuoIXmM BQDyYGend5VjqrtPwZUd+IhUlwlF9fNT4H/kYqDUJZ1rc/pP+mes3Zm07hBPsywFga8A 3sKtriPst9tXz062pshbD34GK9LvA3Fiv9XCmKnuwRRhtw1Bt7IvSwpVYLAjt/JNEd/c lZAsHbi7/XrlA5BJMcFLfOSrmkSGaTWcnV6Wo4/aZnLjRSprEbe9YOWcnoC6RhAfteuw KvaQ== X-Gm-Message-State: AO0yUKVERXiz1eM2agUgX97D8x6kJHyjuusY8LbuIQZhr/Z9NQ5xeFqe jyKV03ktwzQN+fyFSu8Rv5qVJyzC1qfaX+9DbQ== X-Google-Smtp-Source: AK7set81FNM6aZ2KKc0RpczFG5Lx+WgCWICz/KzlEJw1NjziYveSgQLqdoN474MmozxZF5HPAo3b3AmF9lnSjz983g== X-Received: from ackerleytng-cloudtop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1f5f]) (user=ackerleytng job=sendgmr) by 2002:a05:6a00:198d:b0:5a9:9713:1dc with SMTP id d13-20020a056a00198d00b005a9971301dcmr677531pfl.6.1678926688561; Wed, 15 Mar 2023 17:31:28 -0700 (PDT) Date: Thu, 16 Mar 2023 00:31:01 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.40.0.rc2.332.ga46443480c-goog Message-ID: <287d6e84dc788d84599392ca5d65864201f9a6a4.1678926164.git.ackerleytng@google.com> Subject: [RFC PATCH 08/10] KVM: selftests: Default private_mem_conversions_test to use 1 restrictedmem file for test data From: Ackerley Tng To: kvm@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, qemu-devel@nongnu.org Cc: aarcange@redhat.com, ak@linux.intel.com, akpm@linux-foundation.org, arnd@arndb.de, bfields@fieldses.org, bp@alien8.de, chao.p.peng@linux.intel.com, corbet@lwn.net, dave.hansen@intel.com, david@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, hpa@zytor.com, hughd@google.com, jlayton@kernel.org, jmattson@google.com, joro@8bytes.org, jun.nakajima@intel.com, kirill.shutemov@linux.intel.com, linmiaohe@huawei.com, luto@kernel.org, mail@maciej.szmigiero.name, mhocko@suse.com, michael.roth@amd.com, mingo@redhat.com, naoya.horiguchi@nec.com, pbonzini@redhat.com, qperret@google.com, rppt@kernel.org, seanjc@google.com, shuah@kernel.org, steven.price@arm.com, tabba@google.com, tglx@linutronix.de, vannapurve@google.com, vbabka@suse.cz, vkuznets@redhat.com, wanpengli@tencent.com, wei.w.wang@intel.com, x86@kernel.org, yu.c.zhang@linux.intel.com, Ackerley Tng X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 1cxqqmxerm941fnhxf55m9ca4ki1e7m3 X-Rspamd-Queue-Id: B016740013 X-HE-Tag: 1678926689-57432 X-HE-Meta: U2FsdGVkX1/J+FMm4lzB+90p5c0ymeUgYprf3U3idJkkq8lroZ7wBAQt3kS+qj56U3LLbLT4pllVeDuNi+V4T5JsDdvBo6QauDd3vzjq6gAlR084I8FeXr248q6NuaVLKBeZ3pQU92eeRtIQvFTm/U/vS6hkToib6lPZ1HNRaFN4scsSqMXaH/rjTfBIS89FPOFv/0wobpVuXIEmRCFhENSkqspLUlOC0lOl6l2ng8uTeDBUjQNTi144U6WPXWhR5IE8nuJC+br11mjNFk1l2bH6S8y3bCbNPj/fn6do3sPAMeWOzwb7b/uR7MKUN3368hnyuvIC1UX6JAdw7Is7khC4CYXvsGbZunwdTnNxiGzZuIc6y5hBr7IwjxiqxqsIpuxbCyuT4GqhyNFvdyeD5OTFiZsRR8XnYWMUE0cnEwAl0ZynHElWJ2MzcYlCA7VbPpFPgjyUNLkIR4RZC3wTWt7mAR68jQhadzakUk0TB+YCJ6ZEHO6BShVfSxHIZzb7mrcB+R44n0NeJ2JCTnSgheE8mFIPJmXEr51UwLvFUCkVNRjViwCGtlfErC3sZS5dKYCbzX9NlTt1H388dJ0HOjUu23Ap9BTi0LkTMmuF64M4g7FEbuePJiD0p6zYmx8sYIiKrLnqTSs6v40+VSWMLRb3VWqdwogG9XYakeCaBEKsNX3mwCfDtGhGAyESt3PE/RneQ1wFoJVnr+iiQspMENsWRAHT0p7czDOa9yRDd2yoSxeLkOea9snfC+8AC6ly6z3+1jLB8NMO3UHuE0qL+YSzukAWt7Dr82LAaeJ721A9yqhOPtgYcxbeqJMqT9a2WJxu1hcEbY84lxnwQrHF5nH1xgkViSAUWk8UwyqYXuM2ZLHJfuVj+SSx2DDVbE76QDjpSvMiPP7gJhAqm0nFscKXvpqi+hSTmWT8+RYm2/IvSeutZiiWT8q/tnTdQQPcQQdTifRTt/WQ5bL/QPA 2BBv/ohG b8efJh3/fpz5Q3KSiidVCdFNiHZ0UXEB479bxWpoWWbNP/Rcmed0MHZc5FowZhW1V7BNUTsXau3tkx44IFGGXoCqxp/qpyUZq5j7bySk4KEQaJyrCO8Q/uHPWH2tlmKeVv2zTA3iw7GhHY7/L97kZHEZGFW88GPaDE6ojYT9JAJW02lylocsfXOL6jWMQi0p/xTeDiqcJKjfPtJxDpdHdwV9sHzDI+RPmvkE4Kfl2YQIIKmtj98k3EsV+b6J/oEeTngVuSaLShm9RMIE2wFTyhopYcYIWq31eGnrlPi9xStCbxSj7Q3H8yvGT6voyQIX69Oi9yPu8qlHIsoWKaueoocIZdm+C7yzIi4eOlEvg0l7UnHyC5x9CHkU80W1wmOKOVoXm9wtbG96P2vzrTIy/IEmc/0l9gb5ZBY+/DLO0thTA79/GQgR/73lNNVbD252Hl710O3vMvuEAAy2DUYp3HiqdxVHtIONxBRyZlKXUs5o4fDsLVAYoKxoHkZ+buqj+9XNRfA6NwDDhi1Ci+tQ7FSfLfyi45cGrGQgla1zh8m9NeP+evL02M9yTw1gn1BqEKNex+qYCjj79EYQduvqoyD3gys+TDzgHLTL7C2eTf30m0TAWM5gY1uUJlNaiqqhG07e0sKhNj2wI7fUr6cCDuIV8d2nYO7ymqH3h2zlIgMsYj2qliGPWl/MVi5d6wtcHvao+4XkPMg6n980= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Default the private/shared memory conversion tests to use a single file (when multiple memslots are requested), while executing on multiple vCPUs in parallel, to stress-test the restrictedmem subsystem. Also add a flag to allow multiple files to be used. Signed-off-by: Ackerley Tng --- .../kvm/x86_64/private_mem_conversions_test.c | 52 ++++++++++++++----- 1 file changed, 38 insertions(+), 14 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 afaf8d0e52e6..ca30f0f05c39 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 @@ -324,7 +324,8 @@ void *thread_function(void *input) } static void add_memslot_for_vcpu( - struct kvm_vm *vm, enum vm_mem_backing_src_type src_type, uint8_t vcpu_id) + struct kvm_vm *vm, enum vm_mem_backing_src_type src_type, uint8_t vcpu_id, + int restrictedmem_fd, uint64_t restrictedmem_offset) { uint64_t gpa = data_gpa_base_for_vcpu_id(vcpu_id); uint32_t slot = DATA_SLOT_BASE + vcpu_id; @@ -336,7 +337,8 @@ static void add_memslot_for_vcpu( static void test_mem_conversions(enum vm_mem_backing_src_type src_type, uint8_t nr_vcpus, uint32_t iterations, - bool use_multiple_memslots) + bool use_multiple_memslots, + bool use_different_restrictedmem_files) { struct kvm_vcpu *vcpus[KVM_MAX_VCPUS]; pthread_t threads[KVM_MAX_VCPUS]; @@ -356,21 +358,28 @@ static void test_mem_conversions(enum vm_mem_backing_src_type src_type, vm_enable_cap(vm, KVM_CAP_EXIT_HYPERCALL, (1 << KVM_HC_MAP_GPA_RANGE)); npages_for_all_vcpus = DATA_SIZE / vm->page_size * nr_vcpus; + virt_map(vm, DATA_GPA_BASE, DATA_GPA_BASE, npages_for_all_vcpus); if (use_multiple_memslots) { - for (i = 0; i < nr_vcpus; i++) - add_memslot_for_vcpu(vm, src_type, i); + int fd = memfd_restricted(0); + int offset = 0; + + for (i = 0; i < nr_vcpus; i++) { + if (use_different_restrictedmem_files) { + if (i > 0) + fd = memfd_restricted(0); + } else { + offset = i * DATA_GPA_SPACING; + } + + add_memslot_for_vcpu(vm, src_type, i, fd, offset); + } } else { vm_userspace_mem_region_add( vm, src_type, DATA_GPA_BASE, DATA_SLOT_BASE, npages_for_all_vcpus, KVM_MEM_PRIVATE); } - virt_map(vm, DATA_GPA_BASE, DATA_GPA_BASE, npages_for_all_vcpus); - - for (i = 0; i < nr_vcpus; i++) - add_memslot_for_vcpu(vm, src_type, i); - for (i = 0; i < nr_vcpus; i++) { args[i].vm = vm; args[i].vcpu = vcpus[i]; @@ -382,7 +391,7 @@ static void test_mem_conversions(enum vm_mem_backing_src_type src_type, for (i = 0; i < nr_vcpus; i++) pthread_join(threads[i], NULL); - if (!use_multiple_memslots) + if (!use_multiple_memslots || !use_different_restrictedmem_files) test_invalidation_code_unbound(vm, 1, DATA_SIZE * nr_vcpus); else test_invalidation_code_unbound(vm, nr_vcpus, DATA_SIZE); @@ -391,8 +400,9 @@ static void test_mem_conversions(enum vm_mem_backing_src_type src_type, static void usage(const char *command) { puts(""); - printf("usage: %s [-h] [-m] [-s mem-type] [-n number-of-vcpus] [-i number-of-iterations]\n", - command); + printf("usage: %s\n", command); + printf(" [-h] [-m] [-f] [-s mem-type]\n"); + printf(" [-n number-of-vcpus] [-i number-of-iterations]\n"); puts(""); backing_src_help("-s"); puts(""); @@ -404,6 +414,9 @@ static void usage(const char *command) puts(""); puts(" -m: use multiple memslots (default: use 1 memslot)"); puts(""); + puts(" -f: use different restrictedmem files for each memslot"); + puts(" (default: use 1 restrictedmem file for all memslots)"); + puts(""); } int main(int argc, char *argv[]) @@ -412,12 +425,13 @@ int main(int argc, char *argv[]) uint8_t nr_vcpus = 2; uint32_t iterations = 10; bool use_multiple_memslots = false; + bool use_different_restrictedmem_files = false; int opt; TEST_REQUIRE(kvm_has_cap(KVM_CAP_EXIT_HYPERCALL)); TEST_REQUIRE(kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_PROTECTED_VM)); - while ((opt = getopt(argc, argv, "mhs:n:i:")) != -1) { + while ((opt = getopt(argc, argv, "fmhs:n:i:")) != -1) { switch (opt) { case 'n': nr_vcpus = atoi_positive("nr_vcpus", optarg); @@ -431,6 +445,9 @@ int main(int argc, char *argv[]) case 'm': use_multiple_memslots = true; break; + case 'f': + use_different_restrictedmem_files = true; + break; case 'h': default: usage(argv[0]); @@ -438,6 +455,13 @@ int main(int argc, char *argv[]) } } - test_mem_conversions(src_type, nr_vcpus, iterations, use_multiple_memslots); + if (!use_multiple_memslots && use_different_restrictedmem_files) { + printf("Overriding -f flag: "); + puts("Using just 1 restrictedmem file since only 1 memslot is to be used."); + use_different_restrictedmem_files = false; + } + + test_mem_conversions(src_type, nr_vcpus, iterations, use_multiple_memslots, + use_different_restrictedmem_files); return 0; }