From patchwork Sat Feb 18 00:43: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: 13145419 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 B398FC05027 for ; Sat, 18 Feb 2023 00:43:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5880A6B0098; Fri, 17 Feb 2023 19:43:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 55EEA6B009A; Fri, 17 Feb 2023 19:43:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 42CB66B009B; Fri, 17 Feb 2023 19:43:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 3430E6B0098 for ; Fri, 17 Feb 2023 19:43:18 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 12C971209EF for ; Sat, 18 Feb 2023 00:43:18 +0000 (UTC) X-FDA: 80478563676.06.09763BC Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf21.hostedemail.com (Postfix) with ESMTP id 516AE1C0004 for ; Sat, 18 Feb 2023 00:43:16 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=p4J50SCY; spf=pass (imf21.hostedemail.com: domain of 3Ix_wYwsKCEgkmuo1vo83xqqyyqvo.mywvsx47-wwu5kmu.y1q@flex--ackerleytng.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3Ix_wYwsKCEgkmuo1vo83xqqyyqvo.mywvsx47-wwu5kmu.y1q@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=1676680996; 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=a9HoC/OaMmMmyFwGFTweDzsomxpTI5zBveAVKH/mxUs=; b=Msy0BVcBnCyF0e8/JVLovJSWYH7Dfyz5RdW5qWji73CswgCYMV7Tyb6jhgKHDJCtGlQAFg agVFp4zWWXbAi+UCeNmahTU2ZiH3vNUgXmu5XcCIyAvZIOzSdHzUlNiwnLdDEZYym+ym/N q6LWpAJYG7VBte07OlAKxqgupfi/ppo= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=p4J50SCY; spf=pass (imf21.hostedemail.com: domain of 3Ix_wYwsKCEgkmuo1vo83xqqyyqvo.mywvsx47-wwu5kmu.y1q@flex--ackerleytng.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3Ix_wYwsKCEgkmuo1vo83xqqyyqvo.mywvsx47-wwu5kmu.y1q@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676680996; a=rsa-sha256; cv=none; b=ZLk4UPXoFiDi8sXG+mzjvYgR/9pS2uEXLQEh5lYnEZhyB9CMKRovHZQS0ZLGTY2u5XkpRc l0mIMU4ByiVPKQh2QI1+P3vA5qDg6Kd4pUWmjKINhTAw7l/LTVYS5X9mUF/p3Kev43JJ7Z S1PkNDb6HmG9oNfC90Rf4mM2ggAZPQM= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-5365741ec51so24651587b3.1 for ; Fri, 17 Feb 2023 16:43:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=a9HoC/OaMmMmyFwGFTweDzsomxpTI5zBveAVKH/mxUs=; b=p4J50SCYcCeG3qGRpHChFsOtrnkHXhTK4OUQeA7csD+WhBd4bepBHtG/cyOfbbTSC+ lCFAqzmMUFKlMigeUVQiWbej8Gu0AWjDX2DuN4h3rP0oUlDEosc+NJ4U87QAa5/PzCNE CCI6mGg0jUZFutFG4yOh79Uont3On7YTn2CT4elMJDE1FfadxmUYwEME2piTlq5az1Mq 9aZyrgkj9RfvKY2E3TqhjPL810vpjoE3FXu/K+4aGPj7XXrOfXVxw+yab5AlL0F/7lnv mwMmGTIisoVBNs8uCuNHuCp5dmw5ILOZjOHaFdx58TbpMJJ+4truEcCA49DA7ssvncOM ZPVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=a9HoC/OaMmMmyFwGFTweDzsomxpTI5zBveAVKH/mxUs=; b=2UT1FMsgR8/akoo9aqvoJvwB3iGlvMZZsyE5n5/3HSP0HxlwGAXss6Mw8fGF+cYXV7 0tFot+0OY3K14D1rIde/Wo8aLzclcqIHLp48lJUkSyQ4VxoDSGhVpQbQ5ySkugfSo3o4 keyXVvOsUd7Rsr/yCuA7zGRCpO8kkBM7/iKTJpX7qiCZKinMfPGOJJMYCm16yVZeS3ZE 4L/GyihXcDAK96qLC1HHhE8zr6nyo1F8DUt5MxZZZhFlC/04I+SqlP0iA8SJ5uhHejaa KRysSBfyPxbig/1MpHjIhN3FirS/i/qnXPk5BYL2699Zits5jpB16m1GothUdzT2EDgB aw6w== X-Gm-Message-State: AO0yUKXi+8+oB+S2sS4dV4GKhTiOQEwh568cSp1hPKUGFg957vVVaQsm cacnkw31Q3vsMzz9vlx6FFRY/+YW8/BI6orIgg== X-Google-Smtp-Source: AK7set/gCiyNU2zsSUQcnpfweO59d4+LMWomYJ6sq6DKFLDhVfbtMpiT7MZoq2d4nExGworQhG3UEyTFbFT8aAYUHA== X-Received: from ackerleytng-cloudtop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1f5f]) (user=ackerleytng job=sendgmr) by 2002:a05:6902:1024:b0:8fc:686c:cf87 with SMTP id x4-20020a056902102400b008fc686ccf87mr57267ybt.4.1676680995496; Fri, 17 Feb 2023 16:43:15 -0800 (PST) Date: Sat, 18 Feb 2023 00:43:01 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <4ea08e03d57152d505b747a6a570752dd698e315.1676680548.git.ackerleytng@google.com> Subject: [RFC PATCH 1/2] mm: restrictedmem: Add flag as THP allocation hint for memfd_restricted() syscall 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-Rspamd-Queue-Id: 516AE1C0004 X-Stat-Signature: fmhxc4kkynmidf4c8trp5ut55gf864yt X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1676680996-105350 X-HE-Meta: U2FsdGVkX1+E4xTnMlBMcXfTCgksNE0aRY9tajucFxXxlkqplpIQ3q9d3qrmnt9KQxJeMTx5giRP1Cazo5grcW9NOeFaIrXy4f6UMPYtcFjZrrl1XfjUyFKJ2X/CBGLNHV71PRZX8VeNhilBeFTqJOB/sn0ibmpGkN9jRhxZEuWTbxamRtHDc1XL3xk45u4KUBnr9V1O8ct6XrT2jd4vLduRx9G+2TtzuPCrnwlhGxW4r/+fvR7RUJ45rqqm9TZjEMF2B5dmJqBrRo5LgaFpZyh5CkOxSgUITc6xgrtfoYoPXwU5TODcx81cuUMfx+3hugXD8g18AR+tQWVJMe0yXZAnjIDX7Mt5lQlawTXAo3zzPmeWdQnEfiSly+8tCphGfbg6v2WkFsTWytL2Udjy2XzowiN7aPihxr/ReBH070dPmkz+hlFFefBdmac8ynLgxH7vvILrt/gUM3/0j/hmObyR0C0uupNqmVmdHGGZvxvlJ7mVmN/owsFqhdwpmmuiNWF9koz9ZYlAd9RTi/GAKxt6yOZD9ELG7JSSatTZ04fPVjZuQNJ7kB6pYF59/V2CunbYDItHAcjvakzUUSKpBn3dWXh7+Csw+Jz/B5c6tJfdm6NBGUJ1ofnUaPdncLqVXmDu5bmasiv7nWG2G/tXpC9ITp4uvLecIFEvIG43pFg2YviFKzwe4FXyBl4nogFmYZzfcghBnBo7rTzllCbvovhBoOVYRv88WY6hyAp1DIHc93KNDgDG1QIq0/cdHhVN4+6EzlB3hdltql6zQyrB3mMYYOLy4LwiENAtOXR9/WE//0VakFoq590HD+wlF9Yv9QiLDyajfyo/9yszwf5Kr58XgllGx/ptTaLP/51NiVIxBRcVx+388WZTgSDSxEs/YVePCBUzZaa7wreen1iBzAKX0dOK5Z4zAOoH3ggsIzHIzMfU4C1g2Ofb125VtnkSsPyE7DrwwosRDDvvijV 7vGNkgR7 eC4sgGyLBFbXkpI1AWyqximgrernojtalzeTNFEtcmbAlxkE9P9ItZwc5v0CskONqfKMhD4uY5MP/4gSsraC0vwH0cab7Bci/ORCDOW/5qbul97wYIUi/q4b7xXdV35hu7C6e6DBy/pDe3tSCbnsUT8DUk0YnLWPm9WgW+F/RfZQzFcwPZQIuieW9sh3G2OAk6UfLumLlQtARn6qDUY8np0dbrLmKNKRAoGLhTZ2oMXu+wIbMYcTSwtuLbeyrYG1gKpVK/4JvrbpRD77E+s/1q24zk178n0KZwQc8wiCRv7lUW2a/KkXLJ+Ao1XZXVnbLjvJd2zr3wJhqiTA1mOTVJCShyXva1z9iBXPBFC17ms8yhjj5lXv4xEn6zHPGuf2vvxzg6nocCJjO84AEjUfLbBGvUvAWdRvtOjav1eYLOPEy5WIXFh/S0KnOOEc7C2yMeqOE4GVF2gNiKLrsNHtuWlmDbgqbVwV9zktSYwMJ6uEdNy1wGcB0Ar30AcYNYEulEZvZDeo/W6x+4mDjOGivUOvM1Nis77xETFc24IUQ86DsNk2i5X14/4J3kKa2RqcoIB3kTOOUFuusL3/cKQ3HmmdWSHvw+fIAE1+q9K0yv5F363FiYGhUB2gieQF0EN2qRhWD6iLJRI2peHogkQugCteNk+yJha5wgyQQ0QkzvUcPKjbDqAVb0lOsCow7IeadgT0j7WCtspiaVvE= 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: Allow userspace to hint the kernel to use Transparent HugePages to back restricted memory on a per-file basis. Signed-off-by: Ackerley Tng --- include/uapi/linux/restrictedmem.h | 1 + mm/restrictedmem.c | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/include/uapi/linux/restrictedmem.h b/include/uapi/linux/restrictedmem.h index 9f108dd1ac4c..f671ccbb43bc 100644 --- a/include/uapi/linux/restrictedmem.h +++ b/include/uapi/linux/restrictedmem.h @@ -4,5 +4,6 @@ /* flags for memfd_restricted */ #define RMFD_TMPFILE 0x0001U +#define RMFD_HUGEPAGE 0x0002U #endif /* _UAPI_LINUX_RESTRICTEDMEM_H */ diff --git a/mm/restrictedmem.c b/mm/restrictedmem.c index 97f3e2159e8b..87c829960b31 100644 --- a/mm/restrictedmem.c +++ b/mm/restrictedmem.c @@ -190,19 +190,25 @@ static struct file *restrictedmem_file_create(struct file *memfd) return file; } -static int restrictedmem_create(struct vfsmount *mount) +static int restrictedmem_create(unsigned int flags, struct vfsmount *mount) { struct file *file, *restricted_file; int fd, err; + unsigned long shmem_setup_flags = VM_NORESERVE; fd = get_unused_fd_flags(0); if (fd < 0) return fd; - if (mount) - file = shmem_file_setup_with_mnt(mount, "memfd:restrictedmem", 0, VM_NORESERVE); - else - file = shmem_file_setup("memfd:restrictedmem", 0, VM_NORESERVE); + if (flags & RMFD_HUGEPAGE) + shmem_setup_flags |= VM_HUGEPAGE; + + if (mount) { + file = shmem_file_setup_with_mnt(mount, "memfd:restrictedmem", + 0, shmem_setup_flags); + } else { + file = shmem_file_setup("memfd:restrictedmem", 0, shmem_setup_flags); + } if (IS_ERR(file)) { err = PTR_ERR(file); @@ -230,7 +236,8 @@ static bool is_shmem_mount(struct vfsmount *mnt) return mnt->mnt_sb->s_magic == TMPFS_MAGIC; } -static int restrictedmem_create_from_path(const char __user *mount_path) +static int restrictedmem_create_from_path(unsigned int flags, + const char __user *mount_path) { int ret; struct path path; @@ -250,7 +257,7 @@ static int restrictedmem_create_from_path(const char __user *mount_path) if (unlikely(ret)) goto out; - ret = restrictedmem_create(path.mnt); + ret = restrictedmem_create(flags, path.mnt); mnt_drop_write(path.mnt); out: @@ -261,16 +268,16 @@ static int restrictedmem_create_from_path(const char __user *mount_path) SYSCALL_DEFINE2(memfd_restricted, unsigned int, flags, const char __user *, mount_path) { - if (flags & ~RMFD_TMPFILE) + if (flags & ~(RMFD_TMPFILE | RMFD_HUGEPAGE)) return -EINVAL; if (flags == RMFD_TMPFILE) { if (!mount_path) return -EINVAL; - return restrictedmem_create_from_path(mount_path); + return restrictedmem_create_from_path(flags, mount_path); } else { - return restrictedmem_create(NULL); + return restrictedmem_create(flags, NULL); } } From patchwork Sat Feb 18 00:43:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 13145420 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 D6779C05027 for ; Sat, 18 Feb 2023 00:43:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 783716B0099; Fri, 17 Feb 2023 19:43:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 734426B009A; Fri, 17 Feb 2023 19:43:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D4C86B009B; Fri, 17 Feb 2023 19:43:24 -0500 (EST) 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 4E8516B0099 for ; Fri, 17 Feb 2023 19:43:24 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 291A3808A7 for ; Sat, 18 Feb 2023 00:43:24 +0000 (UTC) X-FDA: 80478563928.28.B397449 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf21.hostedemail.com (Postfix) with ESMTP id 6AF231C000C for ; Sat, 18 Feb 2023 00:43:22 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=eMm01hnu; spf=pass (imf21.hostedemail.com: domain of 3KR_wYwsKCE4qs0u71uE93ww44w1u.s421y3AD-220Bqs0.47w@flex--ackerleytng.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3KR_wYwsKCE4qs0u71uE93ww44w1u.s421y3AD-220Bqs0.47w@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=1676681002; 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=9mwmDPnm22mSNSwTn0VodViIvXaPz9XlM8QDWYhbyM8=; b=vrOGNmbxcfiAvneTAdqQLAQMJwn3XfDeV1dSSpMWBbsC3s4w/uWUNHUgqfWgAi5keRem2S W3NANlD2E5lhFQfvozMbcgKwLRcRKaSh3DR3r4iDzuqlkkqiAw3yyh9ERYOMZAk0USSAdU g9XSSkVDgO7hkHc1ByWZ4ARGB3kTdk8= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=eMm01hnu; spf=pass (imf21.hostedemail.com: domain of 3KR_wYwsKCE4qs0u71uE93ww44w1u.s421y3AD-220Bqs0.47w@flex--ackerleytng.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3KR_wYwsKCE4qs0u71uE93ww44w1u.s421y3AD-220Bqs0.47w@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676681002; a=rsa-sha256; cv=none; b=QIg4nF098FfGiUlNj+D/HfBTxGS2p0k10B8WoTWSD1nuOeRfsWIb7fYrUbeXYuK3DhAOf6 TG2blQHWpRys4zr3DeACu3z4KL2pCmzz3FfVrKtPkDI4pcBGkrg5r1aazrlz7eZph6c/e9 e0unikQdKtb07j+SUvGdjt8TkV7B75Y= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5365742524fso24999127b3.13 for ; Fri, 17 Feb 2023 16:43:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=9mwmDPnm22mSNSwTn0VodViIvXaPz9XlM8QDWYhbyM8=; b=eMm01hnumElMl3UotGf8lJtLmKUjjLEmp4ZHK0o1H0LRyNA5w7x33BZeE7ifCfM7pg Cd3CBejXIUZT0dDASkiYet2Q11r1oqaxT2jWL7729gQTvNyIV+Z3A265SCXl8KKZFvM6 J2aSWma9rqTSDwyH7vONqfORZObAwWA+6hRLW5QjldLuMtFrDr6CiZLUw313wtVBTkEY Uql860ZaIf2fzbiPBXmxv8De94uhU4jaykP5woFVxM5M2xVs65vFvbC27a8oelqLROik ucodFnqa/c0QR5Ark7refIrmAYAsOKE19K26vuVEVEq0bwodrw1HGi4stiNrcoXlrrSh sdyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=9mwmDPnm22mSNSwTn0VodViIvXaPz9XlM8QDWYhbyM8=; b=dYSHj49VbgFgOVmzBuShQh76oTJ6rrgGznFneNNTqsX3nFwyZDM+jX2/1e/AGdxg4T KfB8Xbe/6piAKVCN3YO8C3zmBhePfQlxk/mCSqmuTDIlX9UQRwcQfAv8ay/GMs9W1wLH v7asDgr3zm6xoMf28nv7L3458/0c2zxib3Ror0zZSfmzXZw4PheZWpWbjbj6rpYe5up2 hV1Z6mKTFERbJbIIv5h1z3o1L2lOvX3rv7P659RpE3f6jcUCdq6XgfqZAjSAzeSvPcvn bvqBNrl5HCpyx1r2ZaOxXwfjx3oYFG5L1EDgt1kmySiL2PO36TeqFX7FxkI4YmzkyIMr 5xWQ== X-Gm-Message-State: AO0yUKU3d8tMh5mzLqiCx6l+wEDsek42DpaUWvknKhsuvkNf8LS+4E23 btxBJjVciGlgG96NPsRW87+E/1UQCkUt+ozH9Q== X-Google-Smtp-Source: AK7set8GCw+l6Q5gppx0SI7xgHF70UCy3j05OUIa+XJfbCoB3vIVoiRjffivwnfUze8k0uHuDZvSsWzxIhc/w0Mo2w== X-Received: from ackerleytng-cloudtop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1f5f]) (user=ackerleytng job=sendgmr) by 2002:a05:6902:10e:b0:95d:6b4f:a73a with SMTP id o14-20020a056902010e00b0095d6b4fa73amr5895ybh.8.1676681001601; Fri, 17 Feb 2023 16:43:21 -0800 (PST) Date: Sat, 18 Feb 2023 00:43:02 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <67956539824ea9dd66a94d67b046b2f4bb0aa6f2.1676680548.git.ackerleytng@google.com> Subject: [RFC PATCH 2/2] selftests: restrictedmem: Add selftest for RMFD_HUGEPAGE 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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6AF231C000C X-Rspam-User: X-Stat-Signature: 88oqzwfan63xhkio1hx6t19xf4fc4bf3 X-HE-Tag: 1676681002-970068 X-HE-Meta: U2FsdGVkX1/9QRwT22O+mtqTDwbcfSt3oxjrUJL6ejcqNeg0T+xMy87d24pr5iJivy6nQFQC/NG/6zv/4c3Gd16yEfFHmB8NByue5rTmklgYD0xlkPjJtQu/65TTIuFx1uY4i+StJVZ04M4tpWAMwMGojwZ0LYf0C6MylXm+RFX/vPeHNPxqffVQgr+GiBcuBi2Qz1YiMc0+jqWOlTKTB563BbjGvc6FV1k/PHOE2PybQEzKcHw3iWpThWRSw9oYCodV5nBD9fDcFCHVLUfBC6FLa/E0y8YDUeTBKbD9jeowRyyPEigunutie1sh1OmY8+uLz2poWW6nefnq7XW5S4Ja+4lMPEQC9Gtf7yMfJ4uFHK5YJAo82nb3dZHPiWlolCBBJXZ2GOJ8h88WWCm/HboQqaroNULc8VegJwKg++u8us3WSL9OiPpW+vfzv99oqW+bhCWsd2zxMbAmD0yzm7OVNeIwIiOCPnE7blNagDQgm/+2FFrY2z1+GWXrsNN0U2kKMUyYTI/5WTZ2x9u6fvlS2dktvVUsaZKYw0jsnjjERMJVS46MMGko1GvZje9wC2JTq5THfed/Zcb1pQsUjRPVVfeZkqVqgh6QXm3Rp8MLemVMd8X36i4H3u0aumbXoSQwBPg/c4jQoPtFPa5kJSHYm6LdAGZOE04jpw789SmUf/soTwbQMmykdtNiXtNU01lIuK3CTjzGPhLDHpFAlviZvsOsZ56TkIpIWCv4Eo4isA6tYoBNRnIX4+MlyryDuAxJUnH6AZOpg03KxxkoVM2IWDqpffJ1f1ixwYZ6YHLAeQQIcHbV5F2vqkfleU9HJYGXBMIYB6sgqYGZ5vovo2lR9Tnl6+q0IPZ33o4kIuBzYh+YT5nJXdqsNj5/Ul5AtrUI4vjBEhz7fPkzAiofoO5EyxY89OLqgZTrSXu7O0sURKUDRzReJeM+T6bKAhSXJL+sEjkfXkymRGPa0qI qYhD/mgD oNbhTU3XoWsGvMzLSL1O4nM4mouh3F2HBFv8XCN0f49AKuchF02l58fCqZT3b6ZffHgHZ5z9o5n5FaZa6sJVVfkvocm8jFdH7aNzF34Kid7vKWZH2ni6XTFJNSjopqzHWpqg6o3pehoVCKts72lGkItHz+Bal5Gh9rQ1k0jQ4uw5F99XI3lfQYPfeMJOeXaE6N7R1MHXotFI6BXlLdQtAuzV8s4i2Nhxmgnehunt7gS5f7aX4f5ctPsgYm+CeA5BCab9ihzDfmqdQkFrBdfKS8bspAGYZ/X6YvU5BMP5Y1eXDO0wRvSdtx3BOCZsrGF/r+EGiAWBCV8C/MEzHeUnWuS8jNG4kFq8hNOth0nIaLFq4MJ6PuAHw65TfeUhoP6YcNoBPH2++Rh310+etbryh6BVx9U5rWok4TwMESgnKFH+soF0SlOzVT3XdEvkYDoZXOFpNJOwXkUe+ax0e6BAKfW0pRSAmZt0jA1Ac7InD1sftCQB9eXUPeqCRTGIDC2HuK7mZzR65ZTKFnKY/IIl4q2YbD/CxgjZBVHCmEZNx+qs58JEehaDM+zUCyiT456ESMm0hy4eXWtjIh6JtUz/9FVkIRur0AXocv6RlqDesXKmZz/kz0uxqc+h8+334iHeeUqSQPuXvngVYd6aDUaoHNoDV+KUwW2OahHGb9+TnBK5Pwh58OTZP+IoKlTDM/Wpz+eHCQxkbyyQRJX4= 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: Tests that when RMFD_HUGEPAGE is specified, restrictedmem will be backed by Transparent HugePages. Signed-off-by: Ackerley Tng --- .../restrictedmem_hugepage_test.c | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tools/testing/selftests/restrictedmem/restrictedmem_hugepage_test.c b/tools/testing/selftests/restrictedmem/restrictedmem_hugepage_test.c index 0d9cf2ced754..75283d68696f 100644 --- a/tools/testing/selftests/restrictedmem/restrictedmem_hugepage_test.c +++ b/tools/testing/selftests/restrictedmem/restrictedmem_hugepage_test.c @@ -180,6 +180,31 @@ TEST_F(reset_shmem_enabled, restrictedmem_fstat_shmem_enabled_always) close(mfd); } +TEST(restrictedmem_invalid_flags) +{ + int mfd = memfd_restricted(99, NULL); + + ASSERT_EQ(-1, mfd); + ASSERT_EQ(EINVAL, errno); +} + +TEST_F(reset_shmem_enabled, restrictedmem_rmfd_hugepage) +{ + int mfd = -1; + struct stat stat; + + ASSERT_EQ(0, set_shmem_thp_policy("never")); + + mfd = memfd_restricted(RMFD_HUGEPAGE, NULL); + ASSERT_NE(-1, mfd); + + ASSERT_EQ(0, fstat(mfd, &stat)); + + ASSERT_EQ(stat.st_blksize, get_hpage_pmd_size()); + + close(mfd); +} + TEST(restrictedmem_tmpfile_no_mount_path) { int mfd = memfd_restricted(RMFD_TMPFILE, NULL);