From patchwork Fri Apr 14 00:11:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 83143 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp26668vqo; Thu, 13 Apr 2023 17:13:10 -0700 (PDT) X-Google-Smtp-Source: AKy350Zw5kTVF1iVDCcxvigf6FZebuGw+lPqCI0K5uApNoXPicGFcKt+/67p010IB7Vktib7arQZ X-Received: by 2002:a17:903:40c1:b0:19f:36ae:c29f with SMTP id t1-20020a17090340c100b0019f36aec29fmr715169pld.46.1681431190350; Thu, 13 Apr 2023 17:13:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681431190; cv=none; d=google.com; s=arc-20160816; b=yXPozpJbYI8COK5ut3sKd5wUxiRltlkZpccngJ2T+4XktueJWTSpj/QOmOMJ6389Pa BsONoua6Q+j5y+zoro4mAtVi0Fl6uqlH1q2Y+oyYUdtBi/FLlQIjOvCyWIna4B9bO1EC IUbWgEM4kuadqoBrmn4qObwhZEWdYzZ2lYcWJRGmn71IjxR+rJ9/iq9aID79ZFgn4Vk2 UaJz57zMbaXWdMX0hGtBAYEUDbpcxTlKNTtOA13nB9703T1pXZ1YnhDPDl9Se9URo+7K GyCQcwlRnNC8v2QN1qUIm3IsyC0M9U3d4GJdgxSc10PDEWaq/U4fa6oHXqxuxOzoVyj6 hRHQ== 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=BkEj6q2IVKaYOP6wiiRLnj5ts2mBBZa+OIxL/GSTf98=; b=bFDokIrVJwyEQnbf4VWMZT+QSvrA+fDgJVtpZsstnSUkepB20YC9hFu0llEh3YGDhp H68JRsYuDx0m0ruVIPsZr5xIcJC/5jBQvdV84eAIu6uigBhurF86J0e8alGUWgoxkWAy BUuf8ZiJvLX+wFp2yy1F2KCQ4hgPNMs54+Znzkc4NBQgnw/BFUBHxZ0LQkaDoZTzfLps /of+04DVfmcmlAbl/R0OOu6kJTF8iF0OOjFcERlxI+ViGbncheFiQmMN+DLiDOXel1gB Ho0aXM26R6WKl5IDnbStA9niJnD0Okl/iY8LfZZ4KRxxWL1pHUEPTWcZDa1oJTpEWii7 /KhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=hEKe7KJh; 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 x62-20020a638641000000b0051460f7d4e0si3330142pgd.29.2023.04.13.17.12.58; Thu, 13 Apr 2023 17:13:10 -0700 (PDT) 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=20221208 header.b=hEKe7KJh; 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 S229493AbjDNAMJ (ORCPT + 99 others); Thu, 13 Apr 2023 20:12:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230324AbjDNAMD (ORCPT ); Thu, 13 Apr 2023 20:12:03 -0400 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 CD63335A1 for ; Thu, 13 Apr 2023 17:12:02 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id p2-20020a170902e74200b001a64b5976a5so5975594plf.0 for ; Thu, 13 Apr 2023 17:12:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681431122; x=1684023122; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=BkEj6q2IVKaYOP6wiiRLnj5ts2mBBZa+OIxL/GSTf98=; b=hEKe7KJhnbtB7HOx0Et2GGRR4tPoUqzTdWnfUxGGsyi9EoTWrZhVqGnrZvvHuOndFb TZMGSQ8vslsUBzDoxn9iNYO9LNL12Zs3VwW97btbxF/u5m0XCRPh93bGl4sbvEzqxT6/ vZR2E4QR8bsqooC9JFGEbUD4GNGVdkQWEnhHWe0gty7hNJfMUG+x6qUJrqOv1s31GKD5 /0uqMrvUHdk6drQi8pnb3EXthHB7+IGInrY92tJ9ElhNKYIt+IMYZonjXRQ9OCvmz8n+ DadYc4CMCAJvwcgOviymbXY411dscM1zCutEA5OdbSJuHP8nTNCFxIaU7gllAACoSnWm TMoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681431122; x=1684023122; 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=BkEj6q2IVKaYOP6wiiRLnj5ts2mBBZa+OIxL/GSTf98=; b=gLPNk7PszY5tfkK8JvTH8mqzHhmLm/xcXmQKTHSLlI7focxV+gwVfbvhW4GUX1SPPk 4UVoxRaLrWqfMR1femdLulyi8kQWCIJo6mWqLueKcACdLERZsYtFttiNDrhXUdkHlFA+ ag6FUWq5NbXsMxi+/FvLZFVnbTQlxMkhm8EnBImZQdKflhrk9UNXJNs/UnOGBIFtXCid 69CJiEnGtERtjn3iQ+dzT1oA8tUyLdsNANVY7ANJmhJRhG65SURtCcAKMvIsgisp5euu MyaZSNVCwa/O88L1+QUKcXiYwFfBXfdP7UztO02v8acAU//Ev/4k+d2nbm3WVhAd233L S0BQ== X-Gm-Message-State: AAQBX9fSaIv2wFOR5hIiWO6bdtkw6z7jFOF5Vkra7rpAGdby88Lp8LJ1 rwjsx/FteOYsRxQ75cBCFx3mQUs8sB3j0c0lMw== X-Received: from ackerleytng-cloudtop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1f5f]) (user=ackerleytng job=sendgmr) by 2002:a63:1c09:0:b0:507:3e33:43e3 with SMTP id c9-20020a631c09000000b005073e3343e3mr240709pgc.7.1681431122125; Thu, 13 Apr 2023 17:12:02 -0700 (PDT) Date: Fri, 14 Apr 2023 00:11:51 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: Subject: [RFC PATCH 2/6] mm: mempolicy: Refactor out mpol_init_from_nodemask 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, muchun.song@linux.dev, feng.tang@intel.com, brgerst@gmail.com, rdunlap@infradead.org, masahiroy@kernel.org, mailhol.vincent@wanadoo.fr, 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?1763108391779515127?= X-GMAIL-MSGID: =?utf-8?q?1763108391779515127?= Refactor out mpol_init_from_nodemask() to simplify logic in do_mbind(). mpol_init_from_nodemask() will be used to perform similar functionality in do_memfd_restricted_bind() in a later patch. Signed-off-by: Ackerley Tng --- mm/mempolicy.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index a256a241fd1d..a2655b626731 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1254,6 +1254,25 @@ static struct page *new_page(struct page *page, unsigned long start) } #endif +static long mpol_init_from_nodemask(struct mempolicy *mpol, const nodemask_t *nmask, + bool always_unlock) +{ + long err; + NODEMASK_SCRATCH(scratch); + + if (!scratch) + return -ENOMEM; + + /* Cannot take lock before allocating in NODEMASK_SCRATCH */ + mmap_write_lock(current->mm); + err = mpol_set_nodemask(mpol, nmask, scratch); + if (always_unlock || err) + mmap_write_unlock(current->mm); + + NODEMASK_SCRATCH_FREE(scratch); + return err; +} + static long do_mbind(unsigned long start, unsigned long len, unsigned short mode, unsigned short mode_flags, nodemask_t *nmask, unsigned long flags) @@ -1306,17 +1325,8 @@ static long do_mbind(unsigned long start, unsigned long len, lru_cache_disable(); } - { - NODEMASK_SCRATCH(scratch); - if (scratch) { - mmap_write_lock(mm); - err = mpol_set_nodemask(new, nmask, scratch); - if (err) - mmap_write_unlock(mm); - } else - err = -ENOMEM; - NODEMASK_SCRATCH_FREE(scratch); - } + + err = mpol_init_from_nodemask(new, nmask, false); if (err) goto mpol_out;