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: 13210784 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 CA270C77B78 for ; Fri, 14 Apr 2023 00:12:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 656076B0078; Thu, 13 Apr 2023 20:12:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5E0BB6B007B; Thu, 13 Apr 2023 20:12:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E338900002; Thu, 13 Apr 2023 20:12:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 2BBD06B0078 for ; Thu, 13 Apr 2023 20:12:05 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id EDC441404EF for ; Fri, 14 Apr 2023 00:12:04 +0000 (UTC) X-FDA: 80678068968.19.2BE0436 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf16.hostedemail.com (Postfix) with ESMTP id 2D52E180010 for ; Fri, 14 Apr 2023 00:12:02 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=hEKe7KJh; spf=pass (imf16.hostedemail.com: domain of 3Upo4ZAsKCJEvx5zC6zJE8119916z.x97638FI-775Gvx5.9C1@flex--ackerleytng.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3Upo4ZAsKCJEvx5zC6zJE8119916z.x97638FI-775Gvx5.9C1@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=1681431123; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BkEj6q2IVKaYOP6wiiRLnj5ts2mBBZa+OIxL/GSTf98=; b=1Fojur9VC4V/UcWBsrPhvygo60IUQq3G8mU6TYLbAXIqkRA59l+P6cS1p0esmGPb7+hXWk C1kLo790KmjcfSMSgs3U3xme0EnZxBexC5FwNIyHpUxpE86pCHjg4dh/O9MM0eE0ZiY3E8 OtItGRdX1gVRFopQA4xFE/IJCp2hb8Q= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=hEKe7KJh; spf=pass (imf16.hostedemail.com: domain of 3Upo4ZAsKCJEvx5zC6zJE8119916z.x97638FI-775Gvx5.9C1@flex--ackerleytng.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3Upo4ZAsKCJEvx5zC6zJE8119916z.x97638FI-775Gvx5.9C1@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681431123; a=rsa-sha256; cv=none; b=ALAbtx4BjMifRaa7yidVog+m00t3Cttww4MxTIK71so1TixL/Gb6BX39iC4pg3hayL4Ybs tdNy7iPl6dqg3PoxTv+SEXrpQ3iX5lLSt5oLwGNWJMv1Sm0LCwAX7FHyPPO7FVYSGH8hg5 0gAyFZRWTUAaubGVu46+xFrlr+nTwow= Received: by mail-pg1-f201.google.com with SMTP id k191-20020a6384c8000000b0051b6cf91f74so199505pgd.2 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=QUUP3feN6fJblU7zZD1RWQvH2yFblYs9MzvvI+8bOXMND94I0D+3RPw5oK4kyxZp8s lFTwbBpCaXe5cD52jtDOi+/Hu9in9x7gGRW+1hEJZpTeunuq2d0Hz6rUe8v2S2ItzAdQ M7u5bqFZzdYRr2IP3pafGaCRje9JFLHKVxtRZSbIXUYFU2/6wmD0gA+qo2pjXqJ8IgJr MzwHPkOF9WulnTb2EV++RFG4ej65cyKvAhHn1tddL331cMti1d5FO9cvFN1pV1w1RUnJ AASLx08pAPRmec7X6PNwDK/P0vXMhPxm4MNRljWBhMP46W96wkIFC7zhRHkakh0I/xju dDHw== X-Gm-Message-State: AAQBX9cWs9Y9KsPNBidqwn0w4nzkSbvEKTuVAE8RgXnUSOTvbzLK3HXg ma0eLPP7vRt9+J5jCvvs3HvAI+STjt/PYbtjjg== X-Google-Smtp-Source: AKy350avtllPlWwvIfTF15qlG1lqqPqwu/NAHA4tctgmwlguwviMhGUhrJ6084VLBRdQnA8mKuN5Lp3jk9IuHlWLyQ== 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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 2D52E180010 X-Rspam-User: X-Stat-Signature: g5c63ig3eg719cmgy6wwf8w51c1df5dp X-HE-Tag: 1681431122-938880 X-HE-Meta: U2FsdGVkX18IiDhzPCK30EQaZfLt73Y9BgUtAUsvHQhrvSaJ2z9D3FupdPTwvVze9nDjk8zxyywDrYkDqeGBNZyMIMbmLQWNyb3q83Y3VuWYx5yDuXUqwuwusIzAI/Zs+I2JWhGDa4UHzsb5bVPiCAzG3F44oUtZH78s8KyHbOywcwSIWf2LLRdMu+5g8471IXJnlFuZZua0g9rvPGWplErFXFC1yFhZnwly45VaafWq7Yj7+fxHaUcVSFyHt9nkHSE6+RdM4Vgew180h2/RZJRs+XQgs1nSYxNOTbUx459FrvKzsJcdqu8P/ZkCnYD6UaSJlShYmOP4blHu0fc1NFxwpn9vPvSKFO+z/HqusZ+qk71sj0z4nRyoSZcsKtSFvhT0jilHp1P8Rwb2vFguZjruiA5ObbgwRrYtZdaJaijcRxDMGNZDZGb2qnzqWfzfIt04H6Huyj9hxCA2ZThGBVZI8CV2r7gQAg4NL6lt4GuBE4WPonrbXjGkbjf9J64OwdbRJaQRTc91r1bsbNepXnBLyQh8nrOybbzOxtOChDRneMLoQMEUl9Y6SMy7JKsnaxDHhyki0JlHQAdIP94BJ8CZloPan8ZX6gy2wW/zN5Dah8FCcDOZgClVMlRpf28fUs6PntqS9S67d8hJLkiDZRDBmAXB+eopAAIP382c8AZocvDGlEKFaElhVbXN9nnCmKG6AGEJpbuLfYQ6RTpc30giPlEOsIhWvMMxMgFz6yeMFRO34esPaa/NZI1rQqdjlYBbsQ8pOv5Jf42HTb/nQraarUXF7To9//UP45zQYYo5pS0bzq6lAnLz/vW68dWh8xgTZv37K2F7qbxE1tLKcBvmk47S9Nuaw+xEAF2m0xiF4ZMIBuFFGLo+Fl2now8IUAWXJMPuUBFFpf0HdWaOi3RVsUkCTvgPerDnwKd7DY7dXKeoeGsgChXqwAWmNJKTfYHdIJ4TomaICq1s1Wl 2dJmLuXN TyP1/gyT3478TTOqJ/zf6FHekVj8gsT9issg4ayqCBKINmxuUu7wocxEm/DFVtmsgMGzYVwGU6NCz9X23MIrKHBSRWadaHkpFOuxFS5yYoBCI0rQ3g5jvSGS072KhP7xIZfNP4SzY5UNLwzUB2mA1eJqgyPnvuElJnOx8VdUlhSwK0Eyat/mLeCzRTkIhOzxRNqmh8UE+cOzA6mBxKWNsvSLKPxoqjyqmUihHDBBGqhM5fDaOcHTDEzaS1GnujAqcHREkWEb0PxndehJConhXn8AddC8HcInrXo6T1+543+Nnz/63ubnEytk+WY6w9x1ipxdMOVM+fJCQneNIH93bBRUvxuzFsjxsRRhqLqWz707K+7pc8CrDONrfBNRZsYw3hPpLkeHGmszJHmipEHzULrnlUsWuAaGCgJRdlW6w2c3gOHDOyvYM9pYOYRIeLsEKCTHvIoQXnz/ShpTkXBgTio04A/gE0Xx+P2k7LhaGG3LKuYeZ+drApBATKcQ1Z5iphB3iTUwg9jZCTTQDKkapn/i0b+8afCPuzH2/ZjyeQHEC9rfio83oqNoMCzIVk4wfSRylzAS/QOdSGF32a7oRpA5LvU2v49B178GqpsPH8MZ6+yjhxu5gkSLhsGeafOEKinqGPQAMraX5ab579MFvsdVFE9zUGfR0AGVivBfBM0xkT0pascCysgTnMAYkTC8T0PrKzf9+yT/PTk4= 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: 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;