Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1342532rdb; Wed, 6 Dec 2023 16:28:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IEdzKGkGOId07TDUq/+dqa/SmevwI1JSap5bi6FGEndqmcxJiRuKGNHt1ylQjQabE2YzGHO X-Received: by 2002:a17:902:db09:b0:1d0:b1f0:1006 with SMTP id m9-20020a170902db0900b001d0b1f01006mr2096107plx.101.1701908922190; Wed, 06 Dec 2023 16:28:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701908922; cv=none; d=google.com; s=arc-20160816; b=jPni4b7UFxPyN4XJQgciwKEvo6ZOBgze7BqU+m3jH3jAov+K4VMMYg75293kQaAP4L zBTysFAZi/XLK84mc1yTI+zbSGXFsVoTa3pzGUKnnsNjBYA78uFCpon07UTkV2vpXfcV 10stYeLzZhODGqFWCik+99yGhPc7nKEW/YZXdhLCe/6ePgDaLLq1o7/tvc9nS3DeoiWN 1BbBGEvFIWVUeJvDbCsQXBDZSa4hn/zW8mo6mJetMWvESmZlCI0xc5e7moFDiMYI5AMK 9SymuOKhnqMBGoKa3nlnJAuin+5vAFh48JlUocswqcItTkA6W46+xsM/tETlS8QHlbVM pGsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Flml1UNmBLLzB1/s7Z9Ivu1nW91eSQVCRu4FPg3vOUU=; fh=OPZt+TfCasQcFfjtcVitIxrj3KymWieGBJWA0LtZmYU=; b=AcQ7r3U1Y++5SBmdKwFJdHsKxe7z5wJgTxnO+So65nfigIjRpJ/JtNiZd5wvkyxUL1 ODs4l1hXMjqfPTcdXzn+PuME3bzg7jL6YE232SagZ0sfmOAFw6sjPISbu1VMrHtFD9sE a+PXBCZUiZadxyxj00HG+DQ09ymqW25mU/VOnnxIsdOV+otuLUV57ixlLwuToQ6hrobT lGZGQlVuhIfEOKjRRdfS6Gumn7MOJoJ3RbuWUfr025CbZ27a3t0eAhvEgmauSYouqTCi Nwj9e/hJcEeJMzqz44MdL5SqNP5slvG7jpGfduUmYvWjqSicv3Li3KeVbQsOXUNPx/xu 5q5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=aaagYva7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id b16-20020a170902b61000b001cc23d2bb92si70926pls.650.2023.12.06.16.28.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 16:28:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=aaagYva7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id E58EC80D44FB; Wed, 6 Dec 2023 16:28:40 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441906AbjLGA2X (ORCPT + 99 others); Wed, 6 Dec 2023 19:28:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1441867AbjLGA2K (ORCPT ); Wed, 6 Dec 2023 19:28:10 -0500 Received: from mail-yw1-x1143.google.com (mail-yw1-x1143.google.com [IPv6:2607:f8b0:4864:20::1143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78D6218D; Wed, 6 Dec 2023 16:28:16 -0800 (PST) Received: by mail-yw1-x1143.google.com with SMTP id 00721157ae682-5d3efc071e2so1014707b3.0; Wed, 06 Dec 2023 16:28:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701908895; x=1702513695; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Flml1UNmBLLzB1/s7Z9Ivu1nW91eSQVCRu4FPg3vOUU=; b=aaagYva7WvXvsbKwPcvWHVGHH97ACRu2dViRmx1tzqPuLq/mY+A7UQx5N7Usinn14B 3NeyMlOHJq5xFph0EDzD1oe0uC4qYEFTIsdQOS5nhDgLRXJJgwUy9d/5b1/kGRmfHqg/ 1N5nWVVlxo6dj9esIHLuCCWyo0t6aHrgHC9g048/jDY6IVKaILhlKpIlbky5Zvq90iY5 687QYQtdnHI46dmwi57y13TsoAxeion80wy5WwjAqmFyXVBj891TujYEJdRt9n3SDPC0 n2TjYW4io2ES9ga8BAbmykU7/Ck3whlRF1h5foVBK/y8/5NqGihfqZUaOmXKcs5Yc1d6 iHhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701908895; x=1702513695; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Flml1UNmBLLzB1/s7Z9Ivu1nW91eSQVCRu4FPg3vOUU=; b=M1umy21Z0Zq4Wf6KFsrbpwSs49gjD4FVeypIKjxZg+v4Jv+/JffxB/Wr5k25SLfMPc xABuyeKotoa/DASBSvEO98lZtnhADLn9I9nKD4qXlMja/wWIas6Z1foLCxLIYw6aVJl3 q2d5Gh2fxG1cBI/m1zMjMECriF629i9USceU3Pqec4/A838Wuc3RRo28DpaTN3Di9WgY uXIEfrZOSPRLPJn+cqk+XO8asg+7ou3bMvLRnNa/S7CrQtXJjvkEDwRHWzPEfVUJ2i7y 9CyaoWxgKmcKjzBDp3faYmnGdz4BP4khd/yrUvdhqcilfsz9uKj1wl+n4bRQlsc8xna6 PlhQ== X-Gm-Message-State: AOJu0YxJkFSxyPKoSmSszdg6fTmuCU54bWOb+nE8P004mhjKSs99epMk WGZ+7JJ0BjeF++6P69tj2Q== X-Received: by 2002:a05:690c:fc3:b0:5d3:9f2d:658c with SMTP id dg3-20020a05690c0fc300b005d39f2d658cmr1911791ywb.24.1701908895635; Wed, 06 Dec 2023 16:28:15 -0800 (PST) Received: from fedora.mshome.net (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id x145-20020a81a097000000b005d82fc8cc92sm19539ywg.105.2023.12.06.16.28.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 16:28:15 -0800 (PST) From: Gregory Price X-Google-Original-From: Gregory Price To: linux-mm@kvack.org, jgroves@micron.com, ravis.opensrc@micron.com, sthanneeru@micron.com, emirakhur@micron.com, Hasan.Maruf@amd.com Cc: linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, arnd@arndb.de, tglx@linutronix.de, luto@kernel.org, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, mhocko@kernel.org, tj@kernel.org, ying.huang@intel.com, gregory.price@memverge.com, corbet@lwn.net, rakie.kim@sk.com, hyeongtak.ji@sk.com, honggyu.kim@sk.com, vtavarespetr@micron.com, peterz@infradead.org Subject: [RFC PATCH 03/11] mm/mempolicy: refactor sanitize_mpol_flags for reuse Date: Wed, 6 Dec 2023 19:27:51 -0500 Message-Id: <20231207002759.51418-4-gregory.price@memverge.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20231207002759.51418-1-gregory.price@memverge.com> References: <20231207002759.51418-1-gregory.price@memverge.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 06 Dec 2023 16:28:41 -0800 (PST) split sanitize_mpol_flags into sanitize and validate. Sanitize is used by set_mempolicy to split (int mode) into mode and mode_flags, and then validates them. Validate validates already split flags. Validate will be reused for new syscalls that accept already split mode and mode_flags. Signed-off-by: Gregory Price --- mm/mempolicy.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 65e0334a1a18..eec807d0c6a1 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1466,24 +1466,39 @@ static int copy_nodes_to_user(unsigned long __user *mask, unsigned long maxnode, return copy_to_user(mask, nodes_addr(*nodes), copy) ? -EFAULT : 0; } -/* Basic parameter sanity check used by both mbind() and set_mempolicy() */ -static inline int sanitize_mpol_flags(int *mode, unsigned short *flags) +/* + * Basic parameter sanity check used by mbind/set_mempolicy + * May modify flags to include internal flags (e.g. MPOL_F_MOF/F_MORON) + */ +static inline int validate_mpol_flags(unsigned short mode, unsigned short *flags) { - *flags = *mode & MPOL_MODE_FLAGS; - *mode &= ~MPOL_MODE_FLAGS; - - if ((unsigned int)(*mode) >= MPOL_MAX) + if ((unsigned int)(mode) >= MPOL_MAX) return -EINVAL; if ((*flags & MPOL_F_STATIC_NODES) && (*flags & MPOL_F_RELATIVE_NODES)) return -EINVAL; if (*flags & MPOL_F_NUMA_BALANCING) { - if (*mode != MPOL_BIND) + if (mode != MPOL_BIND) return -EINVAL; *flags |= (MPOL_F_MOF | MPOL_F_MORON); } return 0; } +/* + * Used by mbind/set_memplicy to split and validate mode/flags + * set_mempolicy combines (mode | flags), split them out into separate + * fields and return just the mode in mode_arg and flags in flags. + */ +static inline int sanitize_mpol_flags(int *mode_arg, unsigned short *flags) +{ + unsigned short mode = (*mode_arg & ~MPOL_MODE_FLAGS); + + *flags = *mode_arg & MPOL_MODE_FLAGS; + *mode_arg = mode; + + return validate_mpol_flags(mode, flags); +} + static long kernel_mbind(unsigned long start, unsigned long len, unsigned long mode, const unsigned long __user *nmask, unsigned long maxnode, unsigned int flags) -- 2.39.1