From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-m49219.qiye.163.com (mail-m49219.qiye.163.com [45.254.49.219]) (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 E73CB31F9A2 for ; Wed, 29 Apr 2026 07:35:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.254.49.219 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777448124; cv=none; b=fZck3elr0uE8hrOdoBaWXWWK1bjroiJ2QkiwbG4vpSJRWwF6ofsbL+33HvkDe+WXL2fJfjvB5qNay1j/Cf/Ac9DiAwcuAeF9/+NQjY2oHg/UZ4avQZr+F6LAYHO360ygKoZJO63WlfDyKGXrFSrxuOHJElRmHxZi+dbHECcaLrg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777448124; c=relaxed/simple; bh=PzvlSfO6YX+PIww2HCm3oN6MXSFmg1oGbXTWjG+7JEk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=g2sILQZOKboHyIiR2caHeo0XpZPa2ykOMxC/bvh2BnBbG60xU6cz8ILHNfutl64F047Nxz7ktJfmmne0BzksBnI6+ElTzjBBPNj248EW3OFolcYCHVl/vc+hM6SKzOOG0cMwSo6t5br95uARlAOu75GFOAtfe1SC9+DY2pzQV3o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=easystack.cn; spf=pass smtp.mailfrom=easystack.cn; arc=none smtp.client-ip=45.254.49.219 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=easystack.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=easystack.cn Received: from [192.168.0.18] (unknown [218.94.118.90]) by smtp.qiye.163.com (Hmail) with ESMTP id 19888ca78; Wed, 29 Apr 2026 15:30:07 +0800 (GMT+08:00) Message-ID: <7cd85225-6377-4062-840a-88358273c3a1@easystack.cn> Date: Wed, 29 Apr 2026 15:30:06 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 3/4] mm/page_owner: add NUMA node filter with nodelist support To: Andrew Morton Cc: vbabka@kernel.org, surenb@google.com, mhocko@suse.com, jackmanb@google.com, hannes@cmpxchg.org, ziy@nvidia.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20260428071112.1420380-1-zhen.ni@easystack.cn> <20260428071112.1420380-4-zhen.ni@easystack.cn> <20260428071640.53b6f37e3a0b2d0ce520622e@linux-foundation.org> From: "zhen.ni" In-Reply-To: <20260428071640.53b6f37e3a0b2d0ce520622e@linux-foundation.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-HM-Tid: 0a9dd825295c0229kunm463d27401a9e26 X-HM-MType: 1 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFJQjdXWRgWCB1ZQUpXWS1ZQUlXWQ8JGhUIEh9ZQVlCHx1PVhpOQk1LTB5ITkgeT1YVFA kWGhdVGRETFhoSFyQUDg9ZV1kYEgtZQVlJSkNVQk9VSkpDVUJLWVdZFhoPEhUdFFlBWU9LSFVKS0 lPT09IVUpLS1VKQktLWQY+ 在 2026/4/28 22:16, Andrew Morton 写道: > On Tue, 28 Apr 2026 15:11:11 +0800 Zhen Ni wrote: > >> Add NUMA node filtering functionality to page_owner to allow >> filtering pages by specific NUMA node(s) using nodelist format. >> >> The filter allows users to focus on pages from specific NUMA nodes, >> which is useful for NUMA-aware memory allocation analysis and debugging. >> >> Supported input formats: >> - Single node: echo "2" > nid >> - Multiple nodes: echo "0,2,3" > nid >> - Node range: echo "0-3" > nid >> - Mixed format: echo "0,2-4,7" > nid >> - Disable filter: echo "-1" > nid >> >> ... >> >> +static ssize_t nid_filter_write(struct file *file, >> + const char __user *buf, >> + size_t count, loff_t *ppos) >> +{ >> + char *kbuf; >> + nodemask_t mask; >> + int ret; >> + int val; >> + >> + /* >> + * Limit input size to handle worst-case nodelist (all nodes). >> + * Worst case per node: ",NNNNN" (comma + 5-digit node number) = 6 bytes. >> + * Formula: 100 bytes overhead + 6 * MAX_NUMNODES >> + */ >> + if (count > (100 + 6 * MAX_NUMNODES)) >> + return -EINVAL; >> + >> + kbuf = kmalloc(count + 1, GFP_KERNEL); >> + if (!kbuf) >> + return -ENOMEM; >> + >> + if (copy_from_user(kbuf, buf, count)) { >> + ret = -EFAULT; >> + goto out_free; >> + } >> + kbuf[count] = '\0'; > > strncpy_from_user() was not useful here? > After checking similar usage in mm/ (e.g., mm/kmemleak.c), I'll switch to strncpy_from_user(). The change is straightforward: long len; len = strncpy_from_user(kbuf, buf, count + 1); if (len < 0) { ret = -EFAULT; goto out_free; } kbuf[count] = '\0'; I'll make this change in the next version. >> + /* Support: "-1" to clear, or nodelist format like "0", "0,2", "0-3" */ >> + if (kstrtoint(kbuf, 10, &val) == 0 && val == -1) >> + nodes_clear(mask); >> + else if (nodelist_parse(kbuf, mask)) { >> + ret = -EINVAL; >> + goto out_free; >> + } >> + >> + owner_filter.nid_mask = mask; >> + ret = count; >> + >> +out_free: >> + kfree(kbuf); >> + return ret; >> +} > > > Best regards, Zhen Ni