Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5629123rdb; Wed, 13 Dec 2023 14:42:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IGilKjtskpIFi7amnDKdLVi6r2RxR9ffQUPHhyLSnGzEBjzsQA8n8V2B5ESQ4KZrwnlusbe X-Received: by 2002:a05:6808:159d:b0:3b8:5c24:80da with SMTP id t29-20020a056808159d00b003b85c2480damr11101411oiw.58.1702507336888; Wed, 13 Dec 2023 14:42:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702507336; cv=none; d=google.com; s=arc-20160816; b=Y63dHz6kGbNg9N5vfNYaUOLxtPRYXXqCiyP2GDCBgpYS1zdxS9aXYDjgUhORK6LO1N Febzt4ehQZrEszQC5flyAdx9GAGFh7Xq14kAR4l45Gn5wmeofH50GCCy66qmR9jhhsZC oJzHullpV/J/6TNMISodLLqK2oDXF6/7KXXrF+kQpggj/9uTPdGyZoNS5GwA3krwTQvA jEqdQfk3L3vTQm9zEQ/23CfWtalTPMFLG67kx42SqsvLmvjMCGcL5sVt948f38xAi/Vh 0xGU0JYdW9L7EQ7GZ2DIpSJcOcKAZAPJICn4f07kzemXzQH9fSTrQqVCJj+NRAlgsFu9 jUkQ== 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=oR/U/lAWuhs3jEMZC4KyA26ezpCk8+tc9jcFDZQx9cU=; fh=tBzJ0NKB+DWbP/kk9rYMQt7EghJKLCiF1I+bTxOTDlg=; b=htNu2AfNtZ5IXonixzmRWiVIomMg9OQXHgyeJhKcg/LUm5nMD0UzdGMqdSGdMXZXgF N+NbuH/FUbaK0Ii2yoXMlkBi9eh/wKu+o0prvmjPirK1aygiksB4SpxBFWbTlVn1aFHa 91PDtJIgDtVhz8wvQRLwAnbIna/E7nZiVREWo3R6Dpw7iqMU3ZJcnKT08OEui4qXaLXO aC1XIwAM/cdM7ETUvojwiZJN0chdLhS5qPn5AA8NTimZScJ6dPkgu9l9XLh40p5GWxvG xS9d5I2qOlN0+o/zUk4/T5eBSXzqi8nYgvXHsbdT7AbDqk6FzoTAADLGjtfGQJgXnl+w UauA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=HfqVKAsm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id a21-20020a056a001d1500b006d095146a77si5284763pfx.380.2023.12.13.14.42.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 14:42:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=HfqVKAsm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 812FE826F7F3; Wed, 13 Dec 2023 14:42:07 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442849AbjLMWla (ORCPT + 99 others); Wed, 13 Dec 2023 17:41:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235416AbjLMWlW (ORCPT ); Wed, 13 Dec 2023 17:41:22 -0500 Received: from mail-yw1-x1144.google.com (mail-yw1-x1144.google.com [IPv6:2607:f8b0:4864:20::1144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DA1DEA; Wed, 13 Dec 2023 14:41:28 -0800 (PST) Received: by mail-yw1-x1144.google.com with SMTP id 00721157ae682-5c85e8fdd2dso73245737b3.2; Wed, 13 Dec 2023 14:41:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702507287; x=1703112087; 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=oR/U/lAWuhs3jEMZC4KyA26ezpCk8+tc9jcFDZQx9cU=; b=HfqVKAsmfmk5otoU0fhpOLdxeL9mc9vHjHTLJwk6xWNKgcp+1rkeJcnF8Xa5+Zbdcx Bo0zfUs+GCa1yXH07QNI3rdUFdS4n8ZWG3pIBXUYEbzoogM1G1ueC3MmccD1OfbnVnF4 tTZjHosZ28GnqrKS7/E0Oz4Pa5MCBwq/0tEz5QH8L+FPoOZdibqNyWHwqCjhqNLngBHd 0BPo+6vAOko9Li28AKH5FAtc6/7nb/TqIV+3HfdSo319HSqmG++DnIKOoy6bXjiZlWuk ZrT5qfZBoJKOFoIS2UzHx3RwWl3rk6OWgTaWbJ5/I2qWeq4nWq0RNvOcdPDVVxR5IaSh SVbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702507287; x=1703112087; 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=oR/U/lAWuhs3jEMZC4KyA26ezpCk8+tc9jcFDZQx9cU=; b=vU1EyDFwDpIKQn6S/WroZr1wH2tuSN0DyP/9vxsiCy5NVYAQ064xwB3Adh/VmTqi0B GKrz2gkThh+YzuyDrsheG672IeolssAD3jEoEonkhJg+fdHNFoeuWQ2UNJI+u5scLLyn MZBjOR9M0D38itRWIrpLsl3rMbRq1tibvwwvCHnJIVFHc99dm+a+cPYsbUbjuC1ynHY0 K8FRjS8CarclnhzkZL/CI5MSz3eKqIlFj5okmSY3z3YuBPGSb9asuQM6VfEuh5upHF2g /cJee3aRx4BOP87TiEqGOwL60jaIBGblxYvKUeJxOovPmZrTOKKig+oGJUYA81oP65vT NWJQ== X-Gm-Message-State: AOJu0YwTYMPxBGU2LHjTK9PHp8BCPOVudgziGDvZpBCxl4yzOEmqw9Bk BnlVLhuFXJQOeE2GRqT5yw== X-Received: by 2002:a0d:d383:0:b0:5d7:1940:dd68 with SMTP id v125-20020a0dd383000000b005d71940dd68mr6889260ywd.62.1702507287649; Wed, 13 Dec 2023 14:41:27 -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 v4-20020a818504000000b005d9729068f5sm5050583ywf.42.2023.12.13.14.41.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 14:41:27 -0800 (PST) From: Gregory Price X-Google-Original-From: Gregory Price To: linux-mm@kvack.org Cc: 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, 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, jgroves@micron.com, ravis.opensrc@micron.com, sthanneeru@micron.com, emirakhur@micron.com, Hasan.Maruf@amd.com, seungjun.ha@samsung.com Subject: [PATCH v3 03/11] mm/mempolicy: refactor sanitize_mpol_flags for reuse Date: Wed, 13 Dec 2023 17:41:10 -0500 Message-Id: <20231213224118.1949-4-gregory.price@memverge.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20231213224118.1949-1-gregory.price@memverge.com> References: <20231213224118.1949-1-gregory.price@memverge.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email 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 (morse.vger.email [0.0.0.0]); Wed, 13 Dec 2023 14:42:07 -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 bd233aed103c..e55a8fa13e45 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 + * 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