From mboxrd@z Thu Jan 1 00:00:00 1970 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 8B239C46CD2 for ; Tue, 30 Jan 2024 04:02:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D3E98D0008; Mon, 29 Jan 2024 23:02:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 183ED8D0001; Mon, 29 Jan 2024 23:02:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 04C078D0008; Mon, 29 Jan 2024 23:02:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E97768D0001 for ; Mon, 29 Jan 2024 23:02:33 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id BC9C24021E for ; Tue, 30 Jan 2024 04:02:33 +0000 (UTC) X-FDA: 81734630586.27.D699130 Received: from mail-m6012.netease.com (mail-m6012.netease.com [210.79.60.12]) by imf15.hostedemail.com (Postfix) with ESMTP id 1096AA0008 for ; Tue, 30 Jan 2024 04:02:30 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=ustc.edu; spf=pass (imf15.hostedemail.com: domain of luochunsheng@ustc.edu designates 210.79.60.12 as permitted sender) smtp.mailfrom=luochunsheng@ustc.edu ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706587352; 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; bh=eY6HuWLNDLB9UPRUvIXfr6Zat04tkGffsC0AY9mJ5ro=; b=jbamaLV9+rUfNPEWUGfWK6cQFJwbO8l5T39P9QSslkxznQSK0CIiHHVxkt9Oh5roCpBgJ5 WnXFOVyecBvNIuwauz1p090moWLeexB64zP5/5fqHkTZ6dA/Tc8sdS9pcKUdZNnztGFWsu pIKedDmckW5roJNXPsNLzurll6+K7ys= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=ustc.edu; spf=pass (imf15.hostedemail.com: domain of luochunsheng@ustc.edu designates 210.79.60.12 as permitted sender) smtp.mailfrom=luochunsheng@ustc.edu ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706587352; a=rsa-sha256; cv=none; b=6Bdc1m9blkoNqZuxiG51KqiFbvuEG2AtblfoAa10r1MdRkI7Gcfs1svATlCQvKHk1GvBGb V5olUJH95U54EJA1xNiWhhdVRymXY++BRB7CSM/OkeP0wkJ3wJs1DQGyTN+8qtlj+5NjlC Ov6aDMcfsmwurQgBl7PRLak+pG+p7bs= Received: from [192.168.255.10] (unknown [101.226.143.243]) by smtp.qiye.163.com (Hmail) with ESMTPA id CF3837E0123; Tue, 30 Jan 2024 12:02:21 +0800 (CST) Content-Type: multipart/alternative; boundary="------------Wi7Mk80Gx0f1i43BERfX4Ynj" Message-ID: Date: Tue, 30 Jan 2024 12:02:20 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mempolicy: check home_node is in the nodes of policy From: Chunsheng Luo To: Gregory Price Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20240126132240.24518-1-luochunsheng@ustc.edu> <1bd6caec-f799-48df-8523-22ea0013beb4@ustc.edu> In-Reply-To: <1bd6caec-f799-48df-8523-22ea0013beb4@ustc.edu> X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVlCGUJJVkgYGkpLHxlMHh8YSFUTARMWGhIXJBQOD1 lXWRgSC1lBWUpLSlVJSU1VSk9IVUlPSFlXWRYaDxIVHRRZQVlPS0hVSk1PSUxOVUpLS1VKQktLWQ Y+ X-HM-Tid: 0a8d588844bc03a2kunmcf3837e0123 X-HM-MType: 10 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6NxA6Pyo5CjMIGEseEwMUA0sp NhlPCTVVSlVKTEtNTkNMSE9JSE5IVTMWGhIXVRcOFBgTDhUIEx4VHDsOCA8YVR4fDkVZV1kSC1lB WUpLSlVJSU1VSk9IVUlPSFlXWQgBWUFMQ01PNwY+ X-Rspamd-Queue-Id: 1096AA0008 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: hhsg96pk8zf3nmbaj9c4p8986y99qxp8 X-HE-Tag: 1706587350-299326 X-HE-Meta: U2FsdGVkX19K/LuexaU/Q2B4ZUR0el+bNVZWRX2d3QWyC7F7TizrVq3EmhBkCe85JyBMlDVAKXd15zROzDI4vy7ToUsceFDIr6KVkpUkuUZxIKggkIkRP5+NlI43t/Hl8jKTif8rGv2ULCC6YWSUKalpqVR7BatGrEjWb5Ykudw7Itzh79clDGZNF4Qf1snDuAabK3964GCheHgRvniNpQ5FJQ3INjGMWW5W1WvvRgdV6cWm4w2hzxusnKKyYDyzp2QPXMWApAtBq+P7tO/dZrsCyNr1zOZVyWOwyX4GGdRCCQ/ZLTQaW6heicKRnemNXAfvoK2SOsFpGS8hxS1i78O6yty6ONHkc+NRVYy+yvQJrb1pOGeF3kfIrXzgL/5E8kgKMgM0XknALJjSuSg6fO4GcLJQiviZ58/W559u9qBdW/EQI8iZopJC74qCPJx8qt5l7ADh7AALCic9XQ7vXS9tipd6b36gSmcmUJkZHzho524qE87ym7j8RDNqL8zui3uNeQPWn15fraxD4OIBTDiqtwcisDskK3KPwQIbbLm8zvo+9OFHlVBdSvsQYXU8XZJcC3Kur3zC8FLN/ZKayVbcFWVDo8KwB2/ayEpikkBFyKLjUeCwvzmDnQWBBwBUGKsLR3QiY5y8vYMS06RFIeJdIc0tgxEsufBqNep3CfdSxnYq124wctEoVIRBBE7QYKUg30cuJiafsHHjwhQmGTeQafxAAcZngatSLYw3/jv3Jl3GMGLO3Rprt02TS3Jr1FfdNztV1fBfWuA4tayfsB3LDqmcUs8sgmcY1KTKPqlE2ckg5XNY1Kr32zz2hi9ss/wIIQlmWRUeBnCwHlOrbebRHnl+zq4vnCbmdskE5xWepun7y+zJnNpFBfZdFSr9BIoDInh5D5KN652yuxFohKXLwwPVTYzFCgAyeVLVHx8OOcuEvy2sHMaReB+d6haxM9o5ewaqnauOlSMzphi GEpORxGL F61OIm5G9Me+DSuA/2F9qeW/17HM84sFPIYBxFqGKtXsFTEqsnxW24Y3KuDCk6nqUA9PnnahBYH2Ij2g9/19YCB02iw0jFkbmUSlG1Of9y+9okm5IKtp92/6IaLwgagvxW/nK30+LzxWH1vtgeFF+Q5u+l8rUOGpXbCXFlTR68orjuw5i+zc+PREhfkst6aJg1cg3Ad5i0mD36ijBW8hG+Pr8QwGLClOuO60ASWRYXiwwbOEyKtP7/V9JBO/4UpOpM/d+8j+Hr5GAXrbNopCKBxPdSrJrla7bBE2hj49xBm92GbY5RrtZ27ZI33SrG9FNhFESxmh5EXcntx+25dpAVK6BvV+xE8VZxm+7s4UK7qO3dpbSVCeFitIaSHc0MYmI88t0U4CSbt2uA0G9+SRbnR7mgHJE89UJDXSsP5J6oaOBQre3lGgisY9WiwCkD9ByhijFQ/Lbei3tzvkzaEQXroChce06Z5/ssPU6 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: List-Subscribe: List-Unsubscribe: This is a multi-part message in MIME format. --------------Wi7Mk80Gx0f1i43BERfX4Ynj Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2024/1/30 10:29, Chunsheng Luo wrote: > > > On 2024/1/29 23:12, Gregory Price wrote: >> On Fri, Jan 26, 2024 at 08:22:40AM -0500, Chunsheng Luo wrote: >>> set_mempolicy_home_node should be used after setting the memory >>> policy. If the home_node isn't in the nodes of policy, we should >>> return failure to avoid misunderstanding. >>> >>> Signed-off-by: Chunsheng Luo >>> --- >>> mm/mempolicy.c | 6 ++++++ >>> 1 file changed, 6 insertions(+) >>> >> Since it's not possible to add/remove a node to a mask without also >> erasing the home node, this seems reasonable. >> >> e.g. this is what happens presently >> mbind(0-2) : mask(0,1,2), home_node(NUMA_NO_NODE) >> home_node(3) : mask(0,1,2), home_node(3) >> mbind(0-3) : mask(0,1,2,3), home_node(NUMA_NO_NODE) >> >> However, it is possible for a cgroup migration or a change to >> cpusets.mems_allowed to change a nodemask without somping the home_node. >> >> e.g.: >> mbind(2-3) : mask(2-3), home_node(NUMA_NO_NODE) >> home_node(3) : mask(2-3), home_node(3) >> cpusets(0-1) : mask(0-1), home_node(3) >> >> Should the rebind code also shift the home-node or un-set it accordingly >> to keep the mask/home_node behavior consistent with the syscalls? >> >> (see mpol_rebind_nodemask) > Thank you for your reply. > First, home_node can only be set for VMA policy. > second, the result of cgroup migration is consistent with the result of the first e.g. > when process mem_allowed updates, vma policy will alse be updated. > Function call: > update_tasks_nodemask >      ->mpol_rebind_mm >          -> for_each_vma: mpol_rebind_policy >              -> mpol_rebind_nodemask Sorry, I make a mistake. The mpol_rebind_nodemask() only modifies the nodemask of the vma policy, but doesn't modify the home_node, so the behavior is different from do_mbind(), so you are right. >>> diff --git a/mm/mempolicy.c b/mm/mempolicy.c >>> index 10a590ee1c89..9282be2ae18e 100644 >>> --- a/mm/mempolicy.c >>> +++ b/mm/mempolicy.c >>> @@ -1536,6 +1536,12 @@ SYSCALL_DEFINE4(set_mempolicy_home_node, unsigned long, start, unsigned long, le >>> err = -EOPNOTSUPP; >>> break; >>> } >>> + >>> + if (!node_isset(home_node, old->nodes)) { >>> + err = -EINVAL; >>> + break; >>> + } >>> + >>> new = mpol_dup(old); >>> if (IS_ERR(new)) { >>> err = PTR_ERR(new); >>> -- >>> 2.43.0 >>> >>> --------------Wi7Mk80Gx0f1i43BERfX4Ynj Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit


On 2024/1/30 10:29, Chunsheng Luo wrote:


On 2024/1/29 23:12, Gregory Price wrote:
On Fri, Jan 26, 2024 at 08:22:40AM -0500, Chunsheng Luo wrote:
set_mempolicy_home_node should be used after setting the memory
policy. If the home_node isn't in the nodes of policy, we should
return failure to avoid misunderstanding.

Signed-off-by: Chunsheng Luo <luochunsheng@ustc.edu>
---
 mm/mempolicy.c | 6 ++++++
 1 file changed, 6 insertions(+)

Since it's not possible to add/remove a node to a mask without also
erasing the home node, this seems reasonable.

e.g. this is what happens presently
mbind(0-2)    :   mask(0,1,2),   home_node(NUMA_NO_NODE)
home_node(3)  :   mask(0,1,2),   home_node(3)
mbind(0-3)    :   mask(0,1,2,3), home_node(NUMA_NO_NODE)

However, it is possible for a cgroup migration or a change to
cpusets.mems_allowed to change a nodemask without somping the home_node.

e.g.:
mbind(2-3)    :   mask(2-3),  home_node(NUMA_NO_NODE)
home_node(3)  :   mask(2-3),  home_node(3)
cpusets(0-1)  :   mask(0-1),  home_node(3)

Should the rebind code also shift the home-node or un-set it accordingly
to keep the mask/home_node behavior consistent with the syscalls?

(see mpol_rebind_nodemask)
Thank you for your reply.
First, home_node can only be set for VMA policy.
second, the result of cgroup migration is consistent with the result of the first e.g.
when process mem_allowed updates, vma policy will alse be updated.
Function call:
update_tasks_nodemask
     ->mpol_rebind_mm
         -> for_each_vma: mpol_rebind_policy
             -> mpol_rebind_nodemask
Sorry, I make a mistake. The mpol_rebind_nodemask() only modifies the nodemask of the vma policy,
but doesn't modify the home_node, so the behavior is different from do_mbind(), so you are right.

diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 10a590ee1c89..9282be2ae18e 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -1536,6 +1536,12 @@ SYSCALL_DEFINE4(set_mempolicy_home_node, unsigned long, start, unsigned long, le
 			err = -EOPNOTSUPP;
 			break;
 		}
+
+		if (!node_isset(home_node, old->nodes)) {
+			err = -EINVAL;
+			break;
+		}
+
 		new = mpol_dup(old);
 		if (IS_ERR(new)) {
 			err = PTR_ERR(new);
-- 
2.43.0


--------------Wi7Mk80Gx0f1i43BERfX4Ynj--