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: 5481 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp20201wrn; Wed, 15 Feb 2023 16:43:16 -0800 (PST) X-Google-Smtp-Source: AK7set8tAZIq29hl+N768ytgitr2eF/A4Eqd1EhVi0KU6HIIFncsDVE6wxxM8BpymYLlwqhpxOR/ X-Received: by 2002:a17:902:f693:b0:19a:a647:1879 with SMTP id l19-20020a170902f69300b0019aa6471879mr658032plg.33.1676508196146; Wed, 15 Feb 2023 16:43:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676508196; cv=none; d=google.com; s=arc-20160816; b=MjfRWMx+KuW0ijyEN2qfUi8oNalYEaGraI+rS52B/MqerdTMyNS+W+RhiAZB4UdDP2 cvTB7gq1Hqb1d3WWk24JueMJXiAST27cd6cgDgiYtz4z6U7YeWY+2hhSCRru/XXCBJRS SPcSQCCS1uSMilzqNH1liiL3F3lViEyboQ8durzy1aSAmLTnO0O86Dw6V4sHCYlCHC84 m1dzjStcnAmooZhdthtfX1qEjXiYoAaK8j7ANJbgvMmWVB2h4Wao9c3yVXh81cZh6HiY eEy9gQissfX6AVHOAtRY08Tfyyy2Cv27luC/ZWQQ0MfV3yvzwtnHnrFmlMMGuQBzv7bc U4iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:from:subject :message-id:mime-version:date:dkim-signature; bh=KyDL7aG5vadqxs1ZDVMtNmlMp6h+pTwRitO0Vsd+xXA=; b=uVyt7UhQs5MgebfbLkRX+BLWTy6SOazOMbeTeeB7IfxUuQtwhz026QT4LQNZjnLXzJ EZ38L/qzgLlL/aph6t5AwFTqYyayE1VGbOAS9LLcNlR+mBVkkcC9Si3Yf39DTivZwQmg eriD5Va+0DJLTcOpvj7y+yqtqWUqnTMXxokilm3qK0WicZx+0O0g57ZrG3w3xLsNQuyc OYkmwolwOFLk2/QDvrKYa/8/7vncHsShgzzgY7CcVoDrq0toES4EVZXtv3N1fGTffuIp /QGwnpSGxDSCgLcP/+HsvQNK9IZSMtt4myW2hZPpuWVAWE2UOwOUsqg6Hb9jhhmBnnQr i/8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=UlyGz18R; 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 j3-20020a170903028300b0019a97c3bccfsi13489430plr.617.2023.02.15.16.43.03; Wed, 15 Feb 2023 16:43:16 -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=UlyGz18R; 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 S229595AbjBPAle (ORCPT + 99 others); Wed, 15 Feb 2023 19:41:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229489AbjBPAlb (ORCPT ); Wed, 15 Feb 2023 19:41:31 -0500 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7161D42DED for ; Wed, 15 Feb 2023 16:41:30 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id q7-20020a170902eb8700b0019ace17fa33so209441plg.7 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=YBNs9C8Hd+q6Qcl9utReZHgU01rtVRigncP/iF3566QyDJdsixwh3uxrWaukOhU11G I4jcYATyL9DEHXz7dh3hqLBgnzDW+VCqVQUu9kU7wkghtz7OyW+z41d0phiXfnDPlYs8 hQMNzBlIfdYNEhYb1U1a0RC/Ar+r6JHg/0hhWp+SHYBj/RZrrul+rc8x+6vpRCCee5oi 27rKFevofPtGKdSfRlv74MaMMcMtRVcxMbfd/pfUTVd6bRDaA8xDENNUC8fuJcRgR0Sd TXYpn+KlY+9YSHJ5sh5+mGysl/WFlHUK3Ybd7CKA4aR79jw0zSbDBz481SQRlAI5kyO/ ijdQ== X-Gm-Message-State: AO0yUKUhfsB2ty8KILpMU1CKK+QtW9PrMwRfzDykZZQU8lA0wx+qa3xr O3JQxTot2xU9mxSpYVyNMSh/6+bU3NlP+FEktw== 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-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=ham 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?1757946258359003890?= X-GMAIL-MSGID: =?utf-8?q?1757946258359003890?= 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