From patchwork Thu Feb 16 00:41:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 13142344 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 6B780C636D6 for ; Thu, 16 Feb 2023 00:41:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 76B8C6B0071; Wed, 15 Feb 2023 19:41:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 71C076B0072; Wed, 15 Feb 2023 19:41:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5BBFA6B0073; Wed, 15 Feb 2023 19:41:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 46E606B0071 for ; Wed, 15 Feb 2023 19:41:33 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 14C101A1082 for ; Thu, 16 Feb 2023 00:41:33 +0000 (UTC) X-FDA: 80471301666.21.FB4F283 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf06.hostedemail.com (Postfix) with ESMTP id 49E7F180009 for ; Thu, 16 Feb 2023 00:41:31 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=UlyGz18R; spf=pass (imf06.hostedemail.com: domain of 3uXvtYwsKCIwqs0u71uE93ww44w1u.s421y3AD-220Bqs0.47w@flex--ackerleytng.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3uXvtYwsKCIwqs0u71uE93ww44w1u.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=1676508091; 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=KyDL7aG5vadqxs1ZDVMtNmlMp6h+pTwRitO0Vsd+xXA=; b=cYN5AUhju9ftZSiXGp+HD28nEF2gEbdCJGFMgpbDovUgSklvLLhUok0bTimajyodPXoiAF vZTaV4PBiZGGWW8qViFd3Ino/Jj9m/q/EZzGqspplmAEhO605J8unqtSuqObADSFJaCxGg 6OdTC2PbbMPhImLKSR3wybnShy6dbEE= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=UlyGz18R; spf=pass (imf06.hostedemail.com: domain of 3uXvtYwsKCIwqs0u71uE93ww44w1u.s421y3AD-220Bqs0.47w@flex--ackerleytng.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3uXvtYwsKCIwqs0u71uE93ww44w1u.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=1676508091; a=rsa-sha256; cv=none; b=A502AOSWnevrkdLY0PLZxuisgAuTM1Cab5o/+7JQ5hMuL/bttsp90b4QlFNtZKpk8lQa9e zeHww9nmw2PhLcYShCYDww4B/yHyAovQ76LAP2m+RXtQgzBul2H7YRKicgo+ZQjIL1JCgs d7rwuyDHZ2snBE8Hty1TiKuOODA7PUs= Received: by mail-pl1-f202.google.com with SMTP id m12-20020a1709026bcc00b001963da9cc71so205830plt.11 for ; Wed, 15 Feb 2023 16:41:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:from:to:cc:subject:date:message-id:reply-to; bh=KyDL7aG5vadqxs1ZDVMtNmlMp6h+pTwRitO0Vsd+xXA=; b=UlyGz18Rq6eKdsAzT90nvKAGzObDlWojIa+4RUu1raCFtQqRUYcy3SspX0jxdJ9rb0 Nw7weHMdrBLZ31wvo1gRWxGi06bUObPJDZmDnyE3qo/jMx6/HDaZTvkl6TQazEiCG569 utifp/LkZIaUBLsxN8fp/8hujvgldojhDyaXNaI8MeFAbY3JeVjvD0NkW2/MUJ28e42V ZMWfGCIgfQWx7Q2YfH7HNWCie5aE+GUgO/fc5leiKryY6MB/sRZht4uh4VjIQkc1sgzj o5tcKSvOUm3vBr0kx5kdnMHT1xneMoUIuFwr5LQO2CkBOhtS2iifTcqrX4jc6sGsYjIC IkyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=KyDL7aG5vadqxs1ZDVMtNmlMp6h+pTwRitO0Vsd+xXA=; b=KsyXTKOyeaqJvegeA7EIktSnpO2V+cG5vmK1ChXKukWj/wlI34LQZ8hOD4h4095G+o jxOLRHCM8yh5yGM7XtOrdPDzAcIlRbQe82DmCJ0f0v8zWASzG6FNqcRroTaYJWl13c8p YzXRz8l7Cb/nekRERniIg86AN7Sl4qNb7Cdw1/6D/L5ws/pGR4VpTOMCRK1hvE2/w/6K p8X46m/DigSw6GoqvsyMF/jjj9JJwoQcoGT4XBjax6h7WZI/o8+PU86F0oDobh9RdENi KQj6HLDgDE2FLxsOpWuH6dLca+fRKncf6xU0iNW7YzbYUAYOHRvOZ7R+Lpc+jnPavyRM 17tQ== X-Gm-Message-State: AO0yUKUINDwIKi6WVooVq9zJARtJGkzeEid/iE8jYpg85XCBLoZ703TG j2iSlfRDPO+iTw0hDDpEXZcfRc6VlIuWJboS+g== X-Google-Smtp-Source: AK7set9ULYqZvTPKnXy7w+XwzeOZWCcMQ4uqZfm4qVlxGYvM8N3GKtC4fbQQyb++BnxdRdIQAt0St6aX14Ha/b9zJw== X-Received: from ackerleytng-cloudtop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1f5f]) (user=ackerleytng job=sendgmr) by 2002:a63:7a1c:0:b0:4fb:ab27:fa7 with SMTP id v28-20020a637a1c000000b004fbab270fa7mr637750pgc.0.1676508089776; Wed, 15 Feb 2023 16:41:29 -0800 (PST) Date: Thu, 16 Feb 2023 00:41:15 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.1.637.g21b0678d19-goog Message-ID: Subject: [RFC PATCH 0/2] Providing mount 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: chao.p.peng@linux.intel.com, aarcange@redhat.com, ak@linux.intel.com, akpm@linux-foundation.org, arnd@arndb.de, bfields@fieldses.org, bp@alien8.de, 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: rspam05 X-Rspamd-Queue-Id: 49E7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zZpTgVVwSViVMSrvfuSmEUuI8NwWe/13WeHJxgFmRE349eH0tvVrrD1tH1vR6TSACR62YBa/doO8OHvprHl5nWjZNLi12fehU3quRfFoe54LEstaB4YgX82eWUSDZKaYyV8csb/6jzYMNjdjg7UfLT1H3TaMkH5m5hflWaYQs2/iZrir5Kh+0jeL7f/OefsunIGftidQJT5bm/5nGERjv009Bcqq1C/mgM4tQxfQiOYW9DgK6yfUSvY97umZ4BX/GndsrMLCDtsHIlY/VrxW/hkMWPtxMFGkXKxrovzLhROeKDkQL8ngYpWzG2b+k8LwgJLEkSQlG0Tdi6pxf+uK3b6VFGWfr199CldX5CGinE8TC+tLNXIjOoOjPtUu2ArBUmCopNQ3mvdmDUG1YvkD0CMcsRl6x8HyTHfyPQNhJnx8OKsTIGGRolkEai9rh9wzTT6GFjc0/j8AdHnS1cb4qs1ZO6r75TwAD4N6hOCez9PH/kkJ5HDjPKzBMgAal9XSVPp6cdjaNoFzGlMgVRgBBHXTTxA4Q71g3tNywSX0qxwUCPJ6FHQOqrykkDCEFzKj8GTyFhptkyS98PtIh7BIUwWW9SbXFk0Br6QrqIi14vGvQVTpue+G03hPSFnZmjJA79VlQP6FGTsg1NkOWQIu9e6JQ83cnsDYr1XC2OOFVjzUGOf7gw5G/Y/mcyVMRnHmzkPsM2abOQruVw2uME9+JCYbT0L1Bfhy6O4UKFGrS+dYa+bvbkIP+/WekIq2XWs5q9UkHqpWrwZseFDkOMkPjz7hcTgMHJwD4B8uFaLtlFcNdlKZYSJt+NESXXlBqlwKh84Bn7gu4RpWtFx0tXyLDpPC 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 has been 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/#m7e944d7892afdd1d62a03a287bd488c56e377b0c The tree can be found at: https://github.com/googleprodkernel/linux-cc/tree/restrictedmem-provide-mount-path In this patchset, a modification to the memfd_restricted() syscall is proposed, which allows userspace to provide a mount, on which the 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:*’. Dependencies: + Sean’s iteration of the ‘KVM: mm: fd-based approach for supporting KVM’ patch series at https://github.com/sean-jc/linux/tree/x86/upm_base_support + Proposed fixes for these issues mentioned on the mailing list: + https://lore.kernel.org/lkml/diqzzga0fv96.fsf@ackerleytng-cloudtop-sg.c.googlers.com/ Future work/TODOs: + man page for the memfd_restricted() syscall + Support for per file Transparent HugePage allocation hints + Support for per file NUMA binding hints Ackerley Tng (2): mm: restrictedmem: Allow userspace to specify mount_path for memfd_restricted selftests: restrictedmem: Check hugepage-ness of shmem file backing restrictedmem fd include/linux/syscalls.h | 2 +- include/uapi/linux/restrictedmem.h | 8 + mm/restrictedmem.c | 63 +++- tools/testing/selftests/Makefile | 1 + .../selftests/restrictedmem/.gitignore | 3 + .../testing/selftests/restrictedmem/Makefile | 14 + .../testing/selftests/restrictedmem/common.c | 9 + .../testing/selftests/restrictedmem/common.h | 8 + .../restrictedmem_hugepage_test.c | 344 ++++++++++++++++++ 9 files changed, 445 insertions(+), 7 deletions(-) create mode 100644 include/uapi/linux/restrictedmem.h create mode 100644 tools/testing/selftests/restrictedmem/.gitignore create mode 100644 tools/testing/selftests/restrictedmem/Makefile create mode 100644 tools/testing/selftests/restrictedmem/common.c create mode 100644 tools/testing/selftests/restrictedmem/common.h create mode 100644 tools/testing/selftests/restrictedmem/restrictedmem_hugepage_test.c --- 2.39.1.637.g21b0678d19-goog