From patchwork Tue Apr 11 01:29:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 13206944 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 7827AC76196 for ; Tue, 11 Apr 2023 01:29:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B063B280040; Mon, 10 Apr 2023 21:29:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AB68528003C; Mon, 10 Apr 2023 21:29:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 97DF6280040; Mon, 10 Apr 2023 21:29:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 87F9628003C for ; Mon, 10 Apr 2023 21:29:39 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5F1758029A for ; Tue, 11 Apr 2023 01:29:39 +0000 (UTC) X-FDA: 80667378078.15.BB87D18 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf12.hostedemail.com (Postfix) with ESMTP id 811E34000C for ; Tue, 11 Apr 2023 01:29:37 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=o2tU5lXa; spf=pass (imf12.hostedemail.com: domain of 3ALg0ZAsKCGsJLTNaUNhcWPPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--ackerleytng.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3ALg0ZAsKCGsJLTNaUNhcWPPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681176577; a=rsa-sha256; cv=none; b=h29kZj9DgULNEop224+XYVI6S7ZCkU3YadreX58Y88HgLH7g+IkWoo6sfSBTXHtGMwqhZg BiIjYV41MYJIc2aSxhkn0T7Mpxdlw3BVee/MJkuyl4X/0Q5aRKUsaYXC5BL0kEXX+vzwny Z6NNorvaoaFVPM814Foz2A210EqHWBU= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=o2tU5lXa; spf=pass (imf12.hostedemail.com: domain of 3ALg0ZAsKCGsJLTNaUNhcWPPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--ackerleytng.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3ALg0ZAsKCGsJLTNaUNhcWPPXXPUN.LXVURWdg-VVTeJLT.XaP@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=1681176577; 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:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=u35FXb24rxXsoG0aCEe4m7ddoHISWHWt5V4ebjSzsz4=; b=ntO4p80OzsynU5CFvdwoAc56el1GFGPY/rVDWzn94M+QBwQnljNyPV2blQkTv8pjh50tod 7BSIA/pOF89wVapnC1zXwuNrs6USLitAvbC7lN8k8Eahr2QfyMwo5tJvA+jblNsbhBE7Y0 5K+kRggBAriDVMy5GWazo01IV5TbPIU= Received: by mail-yb1-f201.google.com with SMTP id j6-20020a255506000000b00b8ef3da4acfso4435450ybb.8 for ; Mon, 10 Apr 2023 18:29:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1681176576; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:from:to:cc:subject:date:message-id:reply-to; bh=u35FXb24rxXsoG0aCEe4m7ddoHISWHWt5V4ebjSzsz4=; b=o2tU5lXa5GgaaWuGTbd5bbvKtG3z3RSme5Cet24inDTS7nOrViJmL/iq51gozQkU0w fSc14g51lyAN7EZ2W2YdqFHXsQ6fhtJt3Ww8txhLuuaqZ7otipQp1kY2GirbtpvPd8tz qOFtr4vKJdNigycQsXduABdE6Mx/1K8btlYWEfUtLHRYy5H01FBzkck2ffnGkGbDsNsT ZbsMLLNEojFf+Yy7PynOmDitIMxxEZiFMr4qBeOETiKphih3BdTfUf4XHIT8Qtk4z1z+ d9h/ldEYXKqGvPbthLo+j90zJo0SUaeonPgvSapyQgn4pLlBWcLiJxpQI3QivbmMF29i 8afA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681176576; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=u35FXb24rxXsoG0aCEe4m7ddoHISWHWt5V4ebjSzsz4=; b=MjHG6e1CRNTNhNpbKKf75s1QGuTyUUxkz32EdaKOwJhIBrmllUxjtbKg3ANySzuiLz P1bXVh6QV0Iwh4HwLL8j7ky++MKegk7ZjgaHFa8oYduA8+TxnoIrmMso9q6KhOPFIg6i MCGzk8mxygIr7ph1BHekG97d58XUUKMX89I+YThKXIXnNNza3XOmtRslYvqM6NO1xvrB nqwlyM56OxwH+wwFACMdoAy/dMLo4OT9n1zr9ZdVh3mKe1zSmKjmyZveGK0m0DOoeJTn i6WAkCDpSuOIJ9Ntx4xs2ThEsMha0M//DnPm/hECSDi4qsSpfPoteq+aDqSan23RwN0G uYBw== X-Gm-Message-State: AAQBX9c2dIot73veuxIlNrFMh4BenEe/mDh5maNhkKLdldgQU264nv6g JrhCIn2Rc1/Ij+8QzNHxyyWz71N0G4uPtkTAGg== X-Google-Smtp-Source: AKy350avHjLsg9mTzZAWYFqY+XYZP5h/AOkdol2OZ6k0pfwzqyIYSmwhwrM4doSRB7oAHOnKfLu7oA90tp2KCOA+fw== X-Received: from ackerleytng-cloudtop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1f5f]) (user=ackerleytng job=sendgmr) by 2002:a05:690c:1:b0:544:bbd2:74be with SMTP id bc1-20020a05690c000100b00544bbd274bemr8286702ywb.4.1681176576562; Mon, 10 Apr 2023 18:29:36 -0700 (PDT) Date: Tue, 11 Apr 2023 01:29:31 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog Message-ID: Subject: [RFC PATCH v4 0/2] Providing mount in 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-Rspam-User: X-Rspamd-Queue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JUzko rJreOhRgVeFsyMVUGI2xiWLg0/+BTHLMH7E4rYZfnEjEROO+dh6aYH3UF3OpxD0gQh5KVw3qilPB6dXTCQWYVapCu7pwsBeWmI7peBvm8bwYDs0jDxAhkL72CYNG0JrOTBgk0aDQE0J4/Aie/01W1ih4Nf2qYaSv/yO9OCnF9e3butH5RGMnS152CIdTR2Yg9JMsi8KS3O7nMJ13xYLRoZnP6Z3LvWtE7VTocw4fUVouwwKhuAHaTXnW4aGybMT0RlbrliILXXdfKW9P8ihS77fL1QzL1Rrv4okr/MNprjsfaEj/dv/nhLum9mpw4BJFfoNz/Lr8kBjM0roJUrw2EOUlMCKZcMctne2prsDxbcYkqMQeH0hoXRfNih/F/iBNm/7f7Lw1LlxmcC2IWGgwF3z8X2rgoYbMc2FVP2zg0j1IpIwY9Mb7HyJwrqUpzI9VhIpnd3noe+k1JfWkPBRuaEnfp5kaVUx8RYgkSlNb1ohl74K9TBl2tTBngT2FrFFC6chQ9WcPjfElsfyzb+L5DUawrJJUl03ydMiW6HYNYq8JxgRH/Bl4mZvQKwwi2tW6YAfiXvP2sg2Hn3FhtVqlTLMwBnc20i8RIGvcteoLmbTkG4u4K9ZbXcKIyZjmmuFXcoDfa19yFwkmxgP4mCORZvY96pWNepee1JO+qgylLoDFtKeHXNHAj6mU4V/nFSdzF4s/MNsZOmACR5PrduzC4Kk20/YivDQ1J5Q2nc3uVkw3LeDWc1nyxmHIRuFKo46W6HBraR3IJRCg7mV9dN3XSGW0RbRc+0qy1r3V/OifAN/sj0cCby7F+wJmLzA== 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: Hello, This patchset builds upon the memfd_restricted() system call that was discussed in the 'KVM: mm: fd-based approach for supporting KVM' patch series, at https://lore.kernel.org/lkml/20221202061347.1070246-1-chao.p.peng@linux.intel.com/T/ The tree can be found at: https://github.com/googleprodkernel/linux-cc/tree/restrictedmem-provide-mount-fd-rfc-v4 In this patchset, a modification to the memfd_restricted() syscall is proposed, which allows userspace to provide a mount, on which the restrictedmem file will be created and returned from the memfd_restricted(). Allowing userspace to provide a mount allows userspace to control various memory binding policies via tmpfs mount options, such as Transparent HugePage memory allocation policy through 'huge=always/never' and NUMA memory allocation policy through 'mpol=local/bind:*'. Changes since RFCv3: + Added check to ensure that bind mounts must be bind mounts of the whole filesystem + Removed inappropriate check on fd’s permissions as Christian suggested + Renamed RMFD_USERMNT to MEMFD_RSTD_USERMNT as David suggested + Added selftest to check that bind mounts must be bind mounts of the whole filesystem Changes since RFCv2: + Tightened semantics to accept only fds of the root of a tmpfs mount, as Christian suggested + Added permissions check on the inode represented by the fd to guard against creation of restrictedmem files on read-only tmpfs filesystems or mounts + Renamed RMFD_TMPFILE to RMFD_USERMNT to better represent providing a userspace mount to create a restrictedmem file on + Updated selftests for tighter semantics and added selftests to check for permissions Changes since RFCv1: + Use fd to represent mount instead of path string, as Kirill suggested. I believe using fds makes this syscall interface more aligned with the other syscalls like fsopen(), fsconfig(), and fsmount() in terms of using and passing around fds + Remove unused variable char *orig_shmem_enabled from selftests Dependencies: + Chao’s work on UPM, at https://github.com/chao-p/linux/commits/privmem-v11.5 Links to earlier patch series: + RFC v3: https://lore.kernel.org/lkml/cover.1680306489.git.ackerleytng@google.com/T/ + RFC v2: https://lore.kernel.org/lkml/cover.1679428901.git.ackerleytng@google.com/T/ + RFC v1: https://lore.kernel.org/lkml/cover.1676507663.git.ackerleytng@google.com/T/ Ackerley Tng (2): mm: restrictedmem: Allow userspace to specify mount for memfd_restricted selftests: restrictedmem: Check memfd_restricted()'s handling of provided userspace mount include/linux/syscalls.h | 2 +- include/uapi/linux/restrictedmem.h | 8 + mm/restrictedmem.c | 73 ++- tools/testing/selftests/mm/.gitignore | 1 + tools/testing/selftests/mm/Makefile | 1 + .../selftests/mm/memfd_restricted_usermnt.c | 529 ++++++++++++++++++ tools/testing/selftests/mm/run_vmtests.sh | 3 + 7 files changed, 611 insertions(+), 6 deletions(-) create mode 100644 include/uapi/linux/restrictedmem.h create mode 100644 tools/testing/selftests/mm/memfd_restricted_usermnt.c --- 2.40.0.577.gac1e443424-goog