From patchwork Tue Sep 10 23:43:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 13799490 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 6EC75EE01F2 for ; Tue, 10 Sep 2024 23:45:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7DF368D0002; Tue, 10 Sep 2024 19:45:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 61A7B8D00DC; 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 3CF2F8D0002; Tue, 10 Sep 2024 19:45:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 187008D00DB for ; Tue, 10 Sep 2024 19:45:06 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 07DEC160E8D for ; Tue, 10 Sep 2024 23:45:04 +0000 (UTC) X-FDA: 82550461728.19.52929DE Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf16.hostedemail.com (Postfix) with ESMTP id 436FC180004 for ; Tue, 10 Sep 2024 23:45:02 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="tk7/vugD"; spf=pass (imf16.hostedemail.com: domain of 3_dngZgsKCHIQSaUhbUojdWWeeWbU.SecbYdkn-ccalQSa.ehW@flex--ackerleytng.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3_dngZgsKCHIQSaUhbUojdWWeeWbU.SecbYdkn-ccalQSa.ehW@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=1726011799; 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=o/HXd5Kdj9SBXB3jabZ8LV/kfZeRyP8D+V3Q9EiJjcU=; b=XVQkzVierPpdievBi3boZlMNtwHGOxBDk4XzP7/Zeps34AN4iwysGf02fQcfUI+r2qrWPg i9a94nJvrem0sXWDz0rKqzhRKKzeGWi2Ioixg6tYVHCU8D3LTmi6pa7i60w+LxwIUyY56A 7IvsDXc8OeAf2sw9corzOWlz+KlD6JM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726011799; a=rsa-sha256; cv=none; b=3exJKBTgCS41cqVt2HPvXGJ9cHTpoCpDNT5OKp0ac1SjGpJ2+0tLopi+Gn4CcidIUyNp0C N0ZU/zQjqJCpSdNODMl6TL1N5WC/SnlYdP2eLn6Dd8bFuZHrF56Pc1sktrB2FjADKhzdUA OOt4rj2kRqfVeB6km9WhHxOR97xL9fk= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="tk7/vugD"; spf=pass (imf16.hostedemail.com: domain of 3_dngZgsKCHIQSaUhbUojdWWeeWbU.SecbYdkn-ccalQSa.ehW@flex--ackerleytng.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3_dngZgsKCHIQSaUhbUojdWWeeWbU.SecbYdkn-ccalQSa.ehW@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6d6b2b9a534so37702307b3.2 for ; Tue, 10 Sep 2024 16:45:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726011901; x=1726616701; 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=o/HXd5Kdj9SBXB3jabZ8LV/kfZeRyP8D+V3Q9EiJjcU=; b=tk7/vugDJXJXFEiCNK+9OD3+NEGFOStfxAtRusFmlR2r5uONSQOR3SBeuIM/OSjYpv V/dECh2AY6mYhCe2IrzOi2XZGYklTikKkaWC3100vzsiTFE3QW8zWhSqPbtCCG2Y2wc7 qz3G8oPZ8NF72PQUNR3Ws5VxtavXoOFH1Ojc+F8NYMTTvGd3glmm9jV18cyrmbapHJEK Drs4LzpnQDjtNGNrt9B4bhzH0Z6SqtxhVRUtvG4qzVbljCuCLxYg8msoXsDlIjyquuZn FeidfkK72GnfbLvXEUkQeJ3K7dl0CGXt4+cwwyydFhw0Aodv/SVeSA/vIyccjHVrPdd8 vG+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726011901; x=1726616701; 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=o/HXd5Kdj9SBXB3jabZ8LV/kfZeRyP8D+V3Q9EiJjcU=; b=LhCyP6RgIunLBGf5rXNr7LrAP87ceO1Sml7jUo2kKbzIhChIMk6p+ee0YWHuLWO593 u+sqCG4ETvHzLdaKSbX6EJZaCJLX9+u7pEIr3Baqnn1v3HToeVGvLrzUmdr3HqtMcmqp 0HHmETzcECwDqjSY7tXkjWXgl13v+FO3wrecW0rbuKhH+3W5kK2gF8S/NSlaBtq3xGIw nRiTnXL0BlAlEiwPwn0vix6LWZcphCsG3XmW8bN74vI+0vH0wguVzcN3Kjs3+lKNHFaO eU3Q+bjqKbIfCz8XBdZA4DaTx1u9pSfa9GqYs3Z/6It4sUpgReUm5Ki42uqaMf7KuxWv M1nQ== X-Forwarded-Encrypted: i=1; AJvYcCViErk/zrJ1Jf4jsASG4S76gLWIQtRZmSXuNTiwmxjyYqYPoz+bzi9u2zqIdK1H4F0oS/xG7UXNIg==@kvack.org X-Gm-Message-State: AOJu0Yx0SU/2YcTWbQePBp4er10rzSBYj71i4cRknzjfyHwaq9XK3EX2 ALtLaUN8dK1tL2MgDqbv10mE7Q2DMpNBlZeyEsRCcg07+hk/mANHPtf3tNfI/KGmh84uKifMXL0 z36J2ky15qVbjCzxXf6J7aA== X-Google-Smtp-Source: AGHT+IHO3Hz+XYA+Vm8ou+yVR+TLwcjnNq/stukVuZHNAMFeSdnEW4ysXQTgCnqywX2CHH+Ew1hV18uk9npr6EUJ3A== X-Received: from ackerleytng-ctop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:13f8]) (user=ackerleytng job=sendgmr) by 2002:a05:690c:6e0a:b0:6ae:34f0:8832 with SMTP id 00721157ae682-6dba6d5d3e6mr543327b3.2.1726011901348; Tue, 10 Sep 2024 16:45:01 -0700 (PDT) Date: Tue, 10 Sep 2024 23:43:48 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog Message-ID: <2f0572464beebbcd2166fe9d709d0ce33a0cee78.1726009989.git.ackerleytng@google.com> Subject: [RFC PATCH 17/39] KVM: selftests: Add basic selftests for hugetlb-backed 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-Rspamd-Queue-Id: 436FC180004 X-Stat-Signature: yqpuk45711sdnx5g9ca8zkiobm65ank4 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1726011902-30303 X-HE-Meta: U2FsdGVkX19BxDoudh//Gyuxtq8p7hWHxoKuUi7e5CRaR8W0vTetvdBCN5vNs1SPYxShvkW+J7sjyzANMJK8OLXms+5XIlMZFGRS29W3oupe0Sie1a91Xb5Or6Y6zPa4//g7i6wtnp9QVUEtD40SdODycO+ZuvTGoedEpby/r2sv/l8fBqCaQqpBwLyN+hJUtxzKpYfz1VE5/Y+3NcFPVtUtv5YCzxUlOHYatzFM1AyxMSCJUzTaiejtUrQJudFg1vXRE5oNzNOiY2kPxNBJVs/pwI+zjeizWF/hokt7yoHUpdNUChiUc2KvUKsiQi15gboRIkfkpJZbpuR1/jKTudVrSsZ7vaYYdhKvfb1k9NzwHxzOCjt6fozKHuCWG70eS8nh6LpCgdCyMkB/XbDuI2ZwABNWL9OGcZ4ilu+/6LBSA/nIVx8n+lzbsWZKF8IFyhTs3KRKWm1lyCf4HcHFUVpNoeaY5EAmiSco8TO4OATNW7NShiew0FXNriizjTDlpEVT/mp9cQDB+YZdGDynPNFeie29kwhHgdpeT3czHq94MLORzmy8zqodEPqRd85wk8BEWcs6TycdLWJnCygOVqjPTq8X0/wGspgKKkMIyFw8aWdJzesKU6OogMHsdB9Tgeli4v7RXpEczxaxvn1rqL1Af6j7G2sYMJUM8hvkuZwwKBZ1gS2dUM6pC5yqJZGMS0AOTAXXei3xTUW9+oc2lxv+lzlc4Znh/BRyEEi7/P9Az/EETlyuOQCRXK9FQV8Y6wY4fCX/TpvdxkkWAq9agQ/AM7WoFm559I0vxR5yU3LyvGe3BK58PdrAMGSJA0ANRfiQBBMH6G6RBr5iY8+BV9ZPCBEQXiXaHibnpH7CIcF4C4+4b0Y1afiPDSrdrsKAjzbg4YRzuqDPjYtapdvcKSId7ZfUhQXc9vqjbYhR3XlCAHn/45Xb7Wng1d451NpdWbz5luYLfW51cL20dWN 69HcSjH5 nogN621wN9g3bqN3BM4RsghbdXc4zlasIjncoZwmYB7VIGf4mHFAZxYpfxvHTV6jSmrJFij1Ttj8DZ+DUxncfUALyMA4T/kjDvD8Akn6/FauZq5u17hyXhIhl6/7TiQJHRUGo1pMiDAysiCerSL1fa6Z19MK/IYA7SJ4cIBRqVTLSAt1rvR4jsNM/5Ipg/rYaiYAtOrG3rgBQ+ueNA4mkjVaxmAJlVmLwvvhQud0+3ZPl8+OTOqICpviA226YTcQE6eDfM6oj2BY+QUwJDxVpAy1tqMO8DC3CVvRWVzLkLeyJnz9aHP7Qm7jNTYFxV8l+eCJVr0FDHaYXfjNrfTJyXy9DeVolyRxM1tankVNJHLm62rfLBSsxc5U+8WJWwJSyRSRnoyMNbcx13h4hJXjnGgGyJnYJpzreI9xvAPXyowv3l4nKKTWN8kJfV33G4TfPS98WTl5ESwVqrhTHuL/nzlRiywNwetCZnUoFqa/kVpi9bvbKpW9q0DJYuqOI6yO+zjO9BN3heMD63+c+BWRmaFHoA9TXDkMRfLDnTfMBqJ2+XZHyvENgkujSmLWYuX9QEtxcufSfYFAjfN1jlyAmWboZtsGU8jDuBbsWgPRqccgESiNE3xin+kLURfs02eQspeeK+N0orCUgqMseR0L8VYL+iQZiPv7xhb7Z 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: List-Subscribe: List-Unsubscribe: Add tests for 2MB and 1GB page sizes, and update the invalid flags test for the new KVM_GUEST_MEMFD_HUGETLB flag. Signed-off-by: Ackerley Tng --- .../testing/selftests/kvm/guest_memfd_test.c | 45 ++++++++++++++----- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/kvm/guest_memfd_test.c b/tools/testing/selftests/kvm/guest_memfd_test.c index ba0c8e996035..3618ce06663e 100644 --- a/tools/testing/selftests/kvm/guest_memfd_test.c +++ b/tools/testing/selftests/kvm/guest_memfd_test.c @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -122,6 +123,7 @@ static void test_invalid_punch_hole(int fd, size_t page_size, size_t total_size) static void test_create_guest_memfd_invalid(struct kvm_vm *vm) { + uint64_t valid_flags = KVM_GUEST_MEMFD_HUGETLB; size_t page_size = getpagesize(); uint64_t flag; size_t size; @@ -135,6 +137,9 @@ static void test_create_guest_memfd_invalid(struct kvm_vm *vm) } for (flag = 0; flag; flag <<= 1) { + if (flag & valid_flags) + continue; + fd = __vm_create_guest_memfd(vm, page_size, flag); TEST_ASSERT(fd == -1 && errno == EINVAL, "guest_memfd() with flag '0x%lx' should fail with EINVAL", @@ -170,24 +175,16 @@ static void test_create_guest_memfd_multiple(struct kvm_vm *vm) close(fd1); } -int main(int argc, char *argv[]) +static void test_guest_memfd(struct kvm_vm *vm, uint32_t flags, size_t page_size) { - size_t page_size; size_t total_size; int fd; - struct kvm_vm *vm; TEST_REQUIRE(kvm_has_cap(KVM_CAP_GUEST_MEMFD)); - page_size = getpagesize(); total_size = page_size * 4; - vm = vm_create_barebones(); - - test_create_guest_memfd_invalid(vm); - test_create_guest_memfd_multiple(vm); - - fd = vm_create_guest_memfd(vm, total_size, 0); + fd = vm_create_guest_memfd(vm, total_size, flags); test_file_read_write(fd); test_mmap(fd, page_size); @@ -197,3 +194,31 @@ int main(int argc, char *argv[]) close(fd); } + +int main(int argc, char *argv[]) +{ + struct kvm_vm *vm; + + TEST_REQUIRE(kvm_has_cap(KVM_CAP_GUEST_MEMFD)); + + vm = vm_create_barebones(); + + test_create_guest_memfd_invalid(vm); + test_create_guest_memfd_multiple(vm); + + printf("Test guest_memfd with 4K pages\n"); + test_guest_memfd(vm, 0, getpagesize()); + printf("\tPASSED\n"); + + printf("Test guest_memfd with 2M pages\n"); + test_guest_memfd(vm, KVM_GUEST_MEMFD_HUGETLB | KVM_GUEST_MEMFD_HUGE_2MB, + 2UL << 20); + printf("\tPASSED\n"); + + printf("Test guest_memfd with 1G pages\n"); + test_guest_memfd(vm, KVM_GUEST_MEMFD_HUGETLB | KVM_GUEST_MEMFD_HUGE_1GB, + 1UL << 30); + printf("\tPASSED\n"); + + return 0; +}