Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp3246152rdb; Wed, 27 Dec 2023 00:41:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IHRM0J2IBb70ZjTXnvoMGpjeXZlVJktZ9d9KFt39CdtMEmdvDURMNBP13JtocJo/bs+2flL X-Received: by 2002:a05:6808:319a:b0:3bb:acd2:9d6f with SMTP id cd26-20020a056808319a00b003bbacd29d6fmr4974889oib.109.1703666517068; Wed, 27 Dec 2023 00:41:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703666517; cv=none; d=google.com; s=arc-20160816; b=yVI8Nq55yU+Zh4eHR7GSNmpbopJgKgopeUTkOykBWN/na8UTtE0Is4iq5KPBtd5I09 BgCp3KaThfRG99EOhtiAOKqYWh9d56hm9na2gSVKNlgDVk2LWwV60MDD9EzxdRIpjBGw /cCtzJU4A94OSjU4qMqdF2dLjZHAF4dOT+lgJ4bt+SwHG+uGZDEKfgcAClwPp2J2yGf0 mK6QsvqWu6oNWrTaQisrojnd77Zg2sCOwoJ+OwAp/FZbdCyJHcd0CUUznYi4+QdgO3fE qF9V9l3VB1HSmt2Lv6XZoL8NgJdxxxd9TwW3VFnkI7JXdkF+IelqQrFGU/Il7ijTHHwO 8JJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:message-id:date:references:in-reply-to:subject:cc:to :from:dkim-signature; bh=glPndTNnJJuLpNfGyz67y0Df/ZaMneiaeAtlcWaPglM=; fh=Jz2Ll0x7kpkro9T+tG6p9PVJz7jeBja5vEy2q93TjHM=; b=HebhyAh8IrhGUXdpzBaOsWktsyFmAr8otGAIjRQZqbiPx8U76L33DxLxus9UH8bDyt 5DyTGEVHgN+QhhyZphmGeaZxtG8Z5nuH9WeMH9gCqGbD02+LNJUKLH7QWIAS67tnwGrf bIFQxL8dBJ1+XtWL1y/7nkSvmx8zKNlbItvQbbwbnzO1YAoIvaPUWZPtpkqVbhi+uz9w ztTbP5ugvsasjxmrTe3jyZX7auwuGO9cny7FxptMzSt5ob7xc9rbVaD/kv1qWqLfzHjt MFFR276o06MJSuB7hY7ovz98hBpsoJM+SyZZXlQ8BT5VtJMMcDP0vJBN87UMEIy52L5F D8aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=V6NyIrAF; spf=pass (google.com: domain of linux-kernel+bounces-11907-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11907-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 25-20020aa79259000000b006d9fac3a70fsi1036756pfp.370.2023.12.27.00.41.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 00:41:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-11907-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=V6NyIrAF; spf=pass (google.com: domain of linux-kernel+bounces-11907-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11907-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 99230B21A79 for ; Wed, 27 Dec 2023 08:41:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A82A763C6; Wed, 27 Dec 2023 08:41:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="V6NyIrAF" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2876D63A8; Wed, 27 Dec 2023 08:41:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703666495; x=1735202495; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=58fSFBLJBQoRVtYJ67nH8yMUOjWPticG1ojkRLi14ak=; b=V6NyIrAFgCzUf3NSMF5ez+MlOcLlmmPwMVpTIHwf/6kFkHebaR7gig0x q0+OkyM+7mJ3FRmvqi14+sREF1Ku/XM1jevplhXrJkadA/T4Dmeo0dbkq dUbfjcLL/1zw8TpQQ4lH+MqmNe1+wsasNPidhK4m9Ap5kkenoQzYon/H0 m5kikL3ii3gjfiJ2jE5zzEpbmHQgJZ2SCXNoXbLLikY6r6vh4WY1N5a0d Jw+wQzlTFVPjaLeAB8KR/v/0pxF+nNrC+lDglzk2h6K6cAi0ax7u8HjP7 UUQScKyd8gRu/ThHq0joZAGpjdn2BhBbeXFN4/rU8GdGl0LlyQURHlNHx A==; X-IronPort-AV: E=McAfee;i="6600,9927,10935"; a="3261999" X-IronPort-AV: E=Sophos;i="6.04,308,1695711600"; d="scan'208";a="3261999" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Dec 2023 00:41:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10935"; a="896828128" X-IronPort-AV: E=Sophos;i="6.04,308,1695711600"; d="scan'208";a="896828128" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Dec 2023 00:41:27 -0800 From: "Huang, Ying" To: Gregory Price Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, x86@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, hpa@zytor.com, mhocko@kernel.org, tj@kernel.org, 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, jgroves@micron.com, ravis.opensrc@micron.com, sthanneeru@micron.com, emirakhur@micron.com, Hasan.Maruf@amd.com, seungjun.ha@samsung.com Subject: Re: [PATCH v5 03/11] mm/mempolicy: refactor sanitize_mpol_flags for reuse In-Reply-To: <20231223181101.1954-4-gregory.price@memverge.com> (Gregory Price's message of "Sat, 23 Dec 2023 13:10:53 -0500") References: <20231223181101.1954-1-gregory.price@memverge.com> <20231223181101.1954-4-gregory.price@memverge.com> Date: Wed, 27 Dec 2023 16:39:29 +0800 Message-ID: <87y1dgdoou.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Gregory Price writes: > 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 0a180c670f0c..59ac0da24f56 100644 > --- a/mm/mempolicy.c > +++ b/mm/mempolicy.c > @@ -1463,24 +1463,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 mbind() uses mode flags too. > + * 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; It appears that it's unnecessary to introduce a local variable to split mode/flags. Just reuse the original code? > + > + 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) -- Best Regards, Huang, Ying