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: 58863 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp148865wrn; Fri, 17 Feb 2023 16:51:07 -0800 (PST) X-Google-Smtp-Source: AK7set+27s6POiuPwq5Z/71eeph2AguoO4+CM56f7SONH3b4QX8+2Yr+Dd+mWMDit8cK6fCmPK3X X-Received: by 2002:a17:903:2451:b0:194:5c63:364c with SMTP id l17-20020a170903245100b001945c63364cmr3580893pls.62.1676681467412; Fri, 17 Feb 2023 16:51:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676681467; cv=none; d=google.com; s=arc-20160816; b=XrXeAZjQb2Hq51XEMGkMXT5RZYMcKdxCnVYtC8+Fvb7N2cJjJqQllHSwrqqFnAd4rC WkZC4prBscqMoR4Wewwz9OmZkJRkM7WMfFK2Lgel9zJQp+wPQa52G5voFP5uYppGq6DJ MrTGJl67XikEFT8HOc1Y6RwA3rI9C2tFmCRxlrirTFcOIZ5182JWlSiacZ8Ef+6ifExf uuhuIRLmx9IMIVmEcQAPEIxsRpSIvanWYb3RLtxiOBQerci9v0f7rG6+S7LF4ZXTdIVd R+a+dENAJ8k9dDbi0TYFwqKBwBO3aVAi/aIAI7QtShpgGkhz6oNwEwIRYbLB0Yfl0284 SFQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=9mwmDPnm22mSNSwTn0VodViIvXaPz9XlM8QDWYhbyM8=; b=FF3ccX2VbxaIJ+oytFPSoVuVZEli8YeLCMtMM8NaNl6ShWdZmerd4GC98Al7efvoHm l6fnk5W0pgUEZ0VT9tYsq1+UYwvgcc8VCsklqKjdrFQkEZ3p7worpehmJV0Ko5BhFMaF F8iHnSA2Fs3gqsQ7Usg3ZEgcgtXewKBLPp2/AKFkNtxK1bKlzPXhRaHzzgBKIRMy0RoD /Hx+2R2zIe7G66g+FzdVM+ntD5dYuRMiM45jD2dDCOvCt3Tu1ds7vYR7Gp9S15gN2Leu MN0W472B3ADvvksv8veR97VRo6fxHYIKmnwbYpxSHgIY+qHp9HQ0k82XBYCZh0/NUY21 iMFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=eMm01hnu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b5-20020a170902e94500b001960922af15si1145287pll.239.2023.02.17.16.50.55; Fri, 17 Feb 2023 16:51:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=eMm01hnu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230255AbjBRApN (ORCPT + 99 others); Fri, 17 Feb 2023 19:45:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230145AbjBRApI (ORCPT ); Fri, 17 Feb 2023 19:45:08 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 034A068E50 for ; Fri, 17 Feb 2023 16:44:33 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id q8-20020a25f408000000b00944353b6a81so2529933ybd.7 for ; Fri, 17 Feb 2023 16:44:32 -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=3R3S0hct3/LwBoQv0Qo1C67Y6QLgHjixC7uT53i8Crhe74UuXCakNVvo405mcKy9H8 vm/MWMZBVQ9Hz69kRU9tshKhI0gugR63KbdeQ4KWJfnxSpU5obbsqTnNSlEUhpHYguBp IOTLxnBjFuNF3D5ytEqs+7F9I3ZMNPvVQ8yWF/rA7DLea6WO0pE025YMrKn8rC2naqiz kk5JD0mw5EaCxnzWY94/Sh5kiJDkuiGHxqu0+d1OtPTztPAD6lwTEyFf7a2GfT6xo1Rb wx90HThETUjxCNfGg1PEGUmdcghO8oGxKoJ9IO1u/f4JFHZ0dbnaQDcNFTS3SeUQQYKb kDhw== X-Gm-Message-State: AO0yUKVK4EeGQwGGZLtLSAo6rQ3e4N3fVnUPtM0uOjazqp7xombfex0J EOmKMidvXUj80NO47mEbIHgCMnUSE14PlLfIqQ== 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-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758127946311189540?= X-GMAIL-MSGID: =?utf-8?q?1758127946311189540?= 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);