From patchwork Tue Sep 10 23:43:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 13799491 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 57073EE01F1 for ; Tue, 10 Sep 2024 23:45:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0768F8D00DC; Tue, 10 Sep 2024 19:45:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0003A8D00DB; Tue, 10 Sep 2024 19:45:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6D368D00DC; Tue, 10 Sep 2024 19:45:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B28CB8D00DB for ; Tue, 10 Sep 2024 19:45:06 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 39ABC4071A for ; Tue, 10 Sep 2024 23:45:06 +0000 (UTC) X-FDA: 82550461812.29.9C9D960 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf14.hostedemail.com (Postfix) with ESMTP id 63636100006 for ; Tue, 10 Sep 2024 23:45:04 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=1RGVZ84y; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of 3_tngZgsKCHMRTbVicVpkeXXffXcV.TfdcZelo-ddbmRTb.fiX@flex--ackerleytng.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3_tngZgsKCHMRTbVicVpkeXXffXcV.TfdcZelo-ddbmRTb.fiX@flex--ackerleytng.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726011876; a=rsa-sha256; cv=none; b=X6UykBBOklnDqPeECWlvYC2NsFA74QotoxMTzsEvquRKhAFQTti4R6H46SuLWNv7/SP6Yr G5PvU4esjNSm/BJHmNj11N1qcySNrOA8G26pP/sHgo751kgf3ysIO/mv+dv5Dgclt/TuTA Ao5blPiCLtLmoovns9afeU3PogxpQ3o= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=1RGVZ84y; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of 3_tngZgsKCHMRTbVicVpkeXXffXcV.TfdcZelo-ddbmRTb.fiX@flex--ackerleytng.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3_tngZgsKCHMRTbVicVpkeXXffXcV.TfdcZelo-ddbmRTb.fiX@flex--ackerleytng.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726011876; 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=YRCNcbi6F+8e/+W6bDlSdC9DBYtBZ6HMw9eZxHX0xEQ=; b=yDUBsZG+Ok4W2SCFPzzghhGlKs5FTTurKFx4/jXaza1a5zOFfuzaIDOk6G0ucyuu3mMqqK wJBBLmJ8+9y1zwfI71tuA1lZF4qhq4vTdnZDm5ym0rtOJRn97qJL2ON/+q1IPf0k6CIfjT HUJtH6EqgAuNmx3Wm+crWYV3RBZ5PcE= Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2d88116d768so6348779a91.0 for ; Tue, 10 Sep 2024 16:45:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726011903; x=1726616703; 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=YRCNcbi6F+8e/+W6bDlSdC9DBYtBZ6HMw9eZxHX0xEQ=; b=1RGVZ84ybTrPdRb1WoFPTNzYjR59L3bDM9iiO05RiCuFE6AC24uXr8Vp0Dc/c2Z7VK IhogV9Cfdw46qVzIVPUe2ZQfrY63sqydze1T97WvmnF1OF5OKbbxP29U2FVf2+FZw/Y5 BKryZabliuYBOZwLjIRFQMlyHEIrzISjLcj+u72rb5UgF1JXF0KHkesmHhk6HwbOrGWL 0mFVUIWQLGGeIutwkce7hQSNlbR95CsGDJC1Ovenw38WHQpIGfFFdTX1I6u96FcjwBTk aVuWnJ5A2FpvKaLSGEVCTpuyUJav8z61V1mHV452rftG7TTGWgbHMJCcchpq/CEjr/tH OkQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726011903; x=1726616703; 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=YRCNcbi6F+8e/+W6bDlSdC9DBYtBZ6HMw9eZxHX0xEQ=; b=LQxd4nSnNoMvnC2ME48vE1o82UG0BlzDTZF/yzB4jwBBBxExJSctZ+uYaa+3OX5Qfm NEML+DBM/Jvy2psnzmZ7K4h7Bjy9iHykFbtNbfzjO9ts8AMsKhxjip8hYQx3CYmap3+7 upig4QBotZ0+WrzNKUmgcrojhs3klTHJyuDEive9TURu81e3gPTKNnOZ6BY/2lT+xTIP 1IDkZz1w3qK1bTeaDhkEsb1FP+fS31q+K+DxrUzqfYCnwlL9vE91aQjlW/NcgX4P50Za uOM7BxnAUbLS1Q5XvxHhbAX781WYipzGy/KAm+uC0I+LZJlJAOEPRlopBSZXkT5Zp8o/ /PCA== X-Forwarded-Encrypted: i=1; AJvYcCUZcvysBoD796NRMyAo7XgK5JTWX3KVUxRZGi/8yt4mDe7z4ne6/pxc00IZZ5Rx6WFq6CkRpqtGIg==@kvack.org X-Gm-Message-State: AOJu0YwlhgGPQi08KC6tK//XgebU5J+ExZSvjqLL2INoNcuDitVZTvRU cqwXmd2NGak34QbJuX3WCbh2K1TpGHyGOI/WAbRS1HWbRYaMWzNcyzMVXo1CKlotaECzEGLiPy0 EgUHkOPB2od1vYCYarEYkQQ== X-Google-Smtp-Source: AGHT+IHtETmvMtzECuoQj0TF7p/fCvI8MzpUYVVeKR6wp9ZmcH42X+aBOrBQUronIKH1gIl+RV35B4SpP9LwziE8Sg== X-Received: from ackerleytng-ctop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:13f8]) (user=ackerleytng job=sendgmr) by 2002:a17:90a:b38d:b0:2d8:a37d:b762 with SMTP id 98e67ed59e1d1-2dad517ea05mr68668a91.4.1726011902955; Tue, 10 Sep 2024 16:45:02 -0700 (PDT) Date: Tue, 10 Sep 2024 23:43:49 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog Message-ID: <327dadf390b5e397074e5bcc9f85468b1467f9a6.1726009989.git.ackerleytng@google.com> Subject: [RFC PATCH 18/39] KVM: selftests: Support various types of backing sources for private memory 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-Rspam-User: X-Rspamd-Queue-Id: 63636100006 X-Rspamd-Server: rspam01 X-Stat-Signature: nettr3ntouxe6569n6e5jexgsdwhctqu X-HE-Tag: 1726011904-309353 X-HE-Meta: U2FsdGVkX199SdXw4SAY8kgGaBMMDvI1IK2VRA/IwSMsg/tsTBXCgDGGy6D9cJXuiiGPNbVEt+XhpLZcLhHPC4d+L4PPeyBxwDJR+hsfshR2l1EXsPZdlMFu5hTGnwG+pRGbd+gWx1brjcRMFG9Nb/5s1gfS9nL1Vee9qzx0z5/m0MU2l+tblxZIsgbSM8YpZZVLnjSZcB96z+HM+zRYzV/umEdXX+QwEromZWXm7t5WjE7WMN3zaELGzrEvaELjWqK4WAAu6qnc5jpq793z1fTU4PlwWs1MDn3F4iiP+LZIBtC+lYjXpf2u8+mzYJHOFQzo5CpOT6EwCMLyz1jAhBYso4JGU73Vae2yHvf2V+GdwOyCsbg1o+V0cjQX0OP/s0ABsNH1BwPMbX2/g6XeGpPOPR3t/Rm6GOzErDbM16sbxmzFl9hHhDhA+zAnkugOxH7E80IEqIfW6I1YsEmRll2cZGFYpC3/Rt0coTDChcRLi0b+9DZW6x8A/W8gfy7YdhKUQYY6dHTJz1rY0ZFoGSF4uZjDyaToRzXzvrk3Mttp/IP9HctnVNnpqbXTWkUd/BG+hRN6fdhuYW9UavcP6iSOON8zAaYGJcrcB4nClJ1afO7LhD+sGVMX3fIl/SzgnztmEBWxES6xssZwEfv/3TeGzw2WdP4hqVT50GrcJADtK488lHAWnI0lQyEJ/LfC9/8NZeQX3qI0RYyO1UeDjUnOwOX2Xt+nmp3JGZGztF15mEcTlqGRIDMinGct6Qlhap5bBDdh6CwCNs+Zh6EEcnGByW5YXni1XXPzuhQBAZ9LQHBohtxBt+3pXr8ZdDKh0G3kKvgGEg7vaSfasLXSA9wMHdc6c+rJp9VBxvgTVPQbOBGs80AVdm6eQN4LnnsDY21GDk6sDXIUE9tr5PSA7k3bBZzNoqbK3/5e7L3h6ICh5Vng0DdVNb3kbuz3DoKfm1dycUvEKTCcuHpSKh/ H/YXzRmO VYiWTrPACsKLHgq1MZydf3MDhtKYDwICFuPfoFwT2fiFp6UYH1mGl9oUfnnmiF/HbgnwvtnSxXsNsoVOx96fgmqnByfaquFdVcf9iK5Gt0urC2H33BBhr/bTzYUDfNGF89y9IfjNKwrtHN3/92oJyqBPbpjgmugyzAo9QFwL+YLTLsDtjN7R3Ehn+JM3PWHh+8tS2kGmqAJRJrNet+c2EagvNtHJgj73Q0jC+5TKzMZT5LggTYZ3ipsT6l/oyuKBTnUhC+AnPXhyR/G7K7Yfau/MUmQFUJnIGZDK4NTdjORvu65x4gJvlnyFx3alL80mP0mjjlE3ztpDJpQzkQtWqhJHMvDFga/NHhrJs7RupFhqsG97pbGAeHoGTVuDLtquQu+ovU1kVwfLmyvTPBGSauGe9lB3y2jJ7LShO7w9kCm8fbK2BjwCpsGOdcz0g9rbwYrekfMX6Y5yN6ZHT7x7n16EWXS2NFI2jt89lqF1H4jonvM1ktgrnmhExVDQiMis4uAm4p9sn7sBTEfWBb2m82wXRxiAUthvoQ1sDL7Ww9T0WMnpZFAcBEN0l/TaqsSNEFP2CCHt0VGOiLOj0V++NHs1D1Rd+eAMaWKJWbBrldivwCo6E88N0PCKWGcNtdWu1XZR1LvOHQtg7qdC12RzmzRhfjw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000005, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Adds support for various type of backing sources for private memory (in the sense of confidential computing), similar to the backing sources available for shared memory. Signed-off-by: Ackerley Tng --- .../testing/selftests/kvm/include/test_util.h | 16 ++++ tools/testing/selftests/kvm/lib/test_util.c | 74 +++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h index 3e473058849f..011e757d4e2c 100644 --- a/tools/testing/selftests/kvm/include/test_util.h +++ b/tools/testing/selftests/kvm/include/test_util.h @@ -142,6 +142,16 @@ struct vm_mem_backing_src_alias { uint32_t flag; }; +enum vm_private_mem_backing_src_type { + VM_PRIVATE_MEM_SRC_GUEST_MEM, /* Use default page size */ + VM_PRIVATE_MEM_SRC_HUGETLB, /* Use kernel default page size for hugetlb pages */ + VM_PRIVATE_MEM_SRC_HUGETLB_2MB, + VM_PRIVATE_MEM_SRC_HUGETLB_1GB, + NUM_PRIVATE_MEM_SRC_TYPES, +}; + +#define DEFAULT_VM_PRIVATE_MEM_SRC VM_PRIVATE_MEM_SRC_GUEST_MEM + #define MIN_RUN_DELAY_NS 200000UL bool thp_configured(void); @@ -152,6 +162,12 @@ size_t get_backing_src_pagesz(uint32_t i); bool is_backing_src_hugetlb(uint32_t i); void backing_src_help(const char *flag); enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name); + +void private_mem_backing_src_help(const char *flag); +enum vm_private_mem_backing_src_type parse_private_mem_backing_src_type(const char *type_name); +const struct vm_mem_backing_src_alias *vm_private_mem_backing_src_alias(uint32_t i); +size_t get_private_mem_backing_src_pagesz(uint32_t i); + long get_run_delay(void); /* diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c index 8ed0b74ae837..d0a9b5ee0c01 100644 --- a/tools/testing/selftests/kvm/lib/test_util.c +++ b/tools/testing/selftests/kvm/lib/test_util.c @@ -15,6 +15,7 @@ #include #include #include "linux/kernel.h" +#include #include "test_util.h" @@ -288,6 +289,34 @@ const struct vm_mem_backing_src_alias *vm_mem_backing_src_alias(uint32_t i) return &aliases[i]; } +const struct vm_mem_backing_src_alias *vm_private_mem_backing_src_alias(uint32_t i) +{ + static const struct vm_mem_backing_src_alias aliases[] = { + [VM_PRIVATE_MEM_SRC_GUEST_MEM] = { + .name = "private_mem_guest_mem", + .flag = 0, + }, + [VM_PRIVATE_MEM_SRC_HUGETLB] = { + .name = "private_mem_hugetlb", + .flag = KVM_GUEST_MEMFD_HUGETLB, + }, + [VM_PRIVATE_MEM_SRC_HUGETLB_2MB] = { + .name = "private_mem_hugetlb_2mb", + .flag = KVM_GUEST_MEMFD_HUGETLB | KVM_GUEST_MEMFD_HUGE_2MB, + }, + [VM_PRIVATE_MEM_SRC_HUGETLB_1GB] = { + .name = "private_mem_hugetlb_1gb", + .flag = KVM_GUEST_MEMFD_HUGETLB | KVM_GUEST_MEMFD_HUGE_1GB, + }, + }; + _Static_assert(ARRAY_SIZE(aliases) == NUM_PRIVATE_MEM_SRC_TYPES, + "Missing new backing private mem src types?"); + + TEST_ASSERT(i < NUM_PRIVATE_MEM_SRC_TYPES, "Private mem backing src type ID %d too big", i); + + return &aliases[i]; +} + #define MAP_HUGE_PAGE_SIZE(x) (1ULL << ((x >> MAP_HUGE_SHIFT) & MAP_HUGE_MASK)) size_t get_backing_src_pagesz(uint32_t i) @@ -308,6 +337,20 @@ size_t get_backing_src_pagesz(uint32_t i) } } +size_t get_private_mem_backing_src_pagesz(uint32_t i) +{ + uint32_t flag = vm_private_mem_backing_src_alias(i)->flag; + + switch (i) { + case VM_PRIVATE_MEM_SRC_GUEST_MEM: + return getpagesize(); + case VM_PRIVATE_MEM_SRC_HUGETLB: + return get_def_hugetlb_pagesz(); + default: + return MAP_HUGE_PAGE_SIZE(flag); + } +} + bool is_backing_src_hugetlb(uint32_t i) { return !!(vm_mem_backing_src_alias(i)->flag & MAP_HUGETLB); @@ -344,6 +387,37 @@ enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name) return -1; } +static void print_available_private_mem_backing_src_types(const char *prefix) +{ + int i; + + printf("%sAvailable private mem backing src types:\n", prefix); + + for (i = 0; i < NUM_PRIVATE_MEM_SRC_TYPES; i++) + printf("%s %s\n", prefix, vm_private_mem_backing_src_alias(i)->name); +} + +void private_mem_backing_src_help(const char *flag) +{ + printf(" %s: specify the type of memory that should be used to\n" + " back guest private memory. (default: %s)\n", + flag, vm_private_mem_backing_src_alias(DEFAULT_VM_PRIVATE_MEM_SRC)->name); + print_available_private_mem_backing_src_types(" "); +} + +enum vm_private_mem_backing_src_type parse_private_mem_backing_src_type(const char *type_name) +{ + int i; + + for (i = 0; i < NUM_PRIVATE_MEM_SRC_TYPES; i++) + if (!strcmp(type_name, vm_private_mem_backing_src_alias(i)->name)) + return i; + + print_available_private_mem_backing_src_types(""); + TEST_FAIL("Unknown private mem backing src type: %s", type_name); + return -1; +} + long get_run_delay(void) { char path[64];