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 90132C433EF for ; Sun, 24 Apr 2022 06:29:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C0D86B0074; Sun, 24 Apr 2022 02:29:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 070E56B0075; Sun, 24 Apr 2022 02:29:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ECA346B0078; Sun, 24 Apr 2022 02:29:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id DE2956B0074 for ; Sun, 24 Apr 2022 02:29:32 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BC2C1270EF for ; Sun, 24 Apr 2022 06:29:32 +0000 (UTC) X-FDA: 79390796184.10.EBAC584 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by imf19.hostedemail.com (Postfix) with ESMTP id 5073F1A0031 for ; Sun, 24 Apr 2022 06:29:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650781771; x=1682317771; h=message-id:subject:from:to:cc:date:in-reply-to: references:mime-version:content-transfer-encoding; bh=mEtVeQ8xCV3wRzfhM2vTLT+erRs7nKtFKJ5thWlpl3k=; b=ZsePlj9UEyNwg9T9o3scbEcAT37oJ9Mz6IW9jIorJw1VVAs5MSLEixCs GvzrdXrAH3uTLGI/VuMCTX8PT3str5f/cb+/ROf7KXW3h6p9PgGviSjce 9uqbSvEsgxGbeXtkSPkU5hgXV5VzGzAEo/+evPaoTB3x25N11uBfS1WtS ZmPi7Egb663hoD5HLx2tAhVNEyyOZRNd+etO1H6dtURGHyfoMjKtLf9aG Me6guy5Pvs4eyjsOjxs5hqx8it9j3OHMbMb8JZx8x87h8BNQDxK7zeYiN WHoSvO/NNIwNrCirmH0NfNaUjYii91fg7wM5hTuSXZAlk6UDlzBH8VeOg w==; X-IronPort-AV: E=McAfee;i="6400,9594,10326"; a="263850283" X-IronPort-AV: E=Sophos;i="5.90,285,1643702400"; d="scan'208";a="263850283" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Apr 2022 23:29:29 -0700 X-IronPort-AV: E=Sophos;i="5.90,285,1643702400"; d="scan'208";a="674991629" Received: from yilinhua-mobl1.ccr.corp.intel.com ([10.254.215.113]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Apr 2022 23:29:25 -0700 Message-ID: Subject: Re: [PATCH v3 3/7] drivers/base/node: Add support to write node_states[] via sysfs From: "ying.huang@intel.com" To: Jagdish Gediya , linux-mm@kvack.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org Cc: baolin.wang@linux.alibaba.com, dave.hansen@linux.intel.com, aneesh.kumar@linux.ibm.com, shy828301@gmail.com, weixugc@google.com, gthelen@google.com, dan.j.williams@intel.com Date: Sun, 24 Apr 2022 14:29:21 +0800 In-Reply-To: <20220422195516.10769-4-jvgediya@linux.ibm.com> References: <20220422195516.10769-1-jvgediya@linux.ibm.com> <20220422195516.10769-4-jvgediya@linux.ibm.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.3-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Stat-Signature: 7xanbbr69jah4wfebsemzefr5cazx4kc X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 5073F1A0031 X-Rspam-User: Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=ZsePlj9U; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf19.hostedemail.com: domain of ying.huang@intel.com has no SPF policy when checking 192.55.52.120) smtp.mailfrom=ying.huang@intel.com X-HE-Tag: 1650781768-912023 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: On Sat, 2022-04-23 at 01:25 +0530, Jagdish Gediya wrote: > Current /sys/devices/system/node/* interface doesn't support > to write node_states[], however write support is needed in case > users want to set them manually e.g. when user want to override > default N_DEMOTION_TARGETS found by the kernel. > > Rename existing _NODE_ATTR to _NODE_ATTR_RO and introduce new > _NODE_ATTR_RW which can be used for node_states[] which can > be written from sysfs. > > It may be necessary to validate written values and take action > based on them in a state specific way so a callback 'write' is > introduced in 'struct node_attr'. > > A new function demotion_targets_write() is added to validate > the input nodes for N_DEMOTION_TARGETS which should be subset > of N_MEMORY and to build new demotion list based on new nodes. > > Signed-off-by: Jagdish Gediya How about discussing the ABI design firstly? I started a discussion in the following thread. I think we can start with the requirements. https://lore.kernel.org/lkml/200e95cf36c1642512d99431014db8943fed715d.camel@intel.com/ Best Regards, Huang, Ying > --- >  drivers/base/node.c | 62 +++++++++++++++++++++++++++++++++++---------- >  1 file changed, 49 insertions(+), 13 deletions(-) > > diff --git a/drivers/base/node.c b/drivers/base/node.c > index 6eef22e6413e..e03eedbc421b 100644 > --- a/drivers/base/node.c > +++ b/drivers/base/node.c > @@ -20,6 +20,7 @@ >  #include >  #include >  #include > +#include >   > > > >  static struct bus_type node_subsys = { >   .name = "node", > @@ -1013,6 +1014,7 @@ void unregister_one_node(int nid) >  struct node_attr { >   struct device_attribute attr; >   enum node_states state; > + int (*write)(nodemask_t nodes); >  }; >   > > > >  static ssize_t show_node_state(struct device *dev, > @@ -1024,23 +1026,57 @@ static ssize_t show_node_state(struct device *dev, >   nodemask_pr_args(&node_states[na->state])); >  } >   > > > > -#define _NODE_ATTR(name, state) \ > - { __ATTR(name, 0444, show_node_state, NULL), state } > +static ssize_t store_node_state(struct device *s, > + struct device_attribute *attr, > + const char *buf, size_t count) > +{ > + nodemask_t nodes; > + struct node_attr *na = container_of(attr, struct node_attr, attr); > + > + if (nodelist_parse(buf, nodes)) > + return -EINVAL; > + > + if (na->write) { > + if (na->write(nodes)) > + return -EINVAL; > + } else { > + node_states[na->state] = nodes; > + } > + > + return count; > +} > + > +static int demotion_targets_write(nodemask_t nodes) > +{ > + if (nodes_subset(nodes, node_states[N_MEMORY])) { > + node_states[N_DEMOTION_TARGETS] = nodes; > + set_migration_target_nodes(); > + return 0; > + } > + > + return -EINVAL; > +} > + > +#define _NODE_ATTR_RO(name, state) \ > + { __ATTR(name, 0444, show_node_state, NULL), state, NULL } > + > +#define _NODE_ATTR_RW(name, state, write_fn) \ > + { __ATTR(name, 0644, show_node_state, store_node_state), state, write_fn } >   > > > >  static struct node_attr node_state_attr[] = { > - [N_POSSIBLE] = _NODE_ATTR(possible, N_POSSIBLE), > - [N_ONLINE] = _NODE_ATTR(online, N_ONLINE), > - [N_NORMAL_MEMORY] = _NODE_ATTR(has_normal_memory, N_NORMAL_MEMORY), > + [N_POSSIBLE] = _NODE_ATTR_RO(possible, N_POSSIBLE), > + [N_ONLINE] = _NODE_ATTR_RO(online, N_ONLINE), > + [N_NORMAL_MEMORY] = _NODE_ATTR_RO(has_normal_memory, N_NORMAL_MEMORY), >  #ifdef CONFIG_HIGHMEM > - [N_HIGH_MEMORY] = _NODE_ATTR(has_high_memory, N_HIGH_MEMORY), > + [N_HIGH_MEMORY] = _NODE_ATTR_RO(has_high_memory, N_HIGH_MEMORY), >  #endif > - [N_MEMORY] = _NODE_ATTR(has_memory, N_MEMORY), > - [N_CPU] = _NODE_ATTR(has_cpu, N_CPU), > - [N_GENERIC_INITIATOR] = _NODE_ATTR(has_generic_initiator, > - N_GENERIC_INITIATOR), > - [N_DEMOTION_TARGETS] = _NODE_ATTR(demotion_targets, > - N_DEMOTION_TARGETS), > - > + [N_MEMORY] = _NODE_ATTR_RO(has_memory, N_MEMORY), > + [N_CPU] = _NODE_ATTR_RO(has_cpu, N_CPU), > + [N_GENERIC_INITIATOR] = _NODE_ATTR_RO(has_generic_initiator, > + N_GENERIC_INITIATOR), > + [N_DEMOTION_TARGETS] = _NODE_ATTR_RW(demotion_targets, > + N_DEMOTION_TARGETS, > + demotion_targets_write), >  }; >   > > > >  static struct attribute *node_state_attrs[] = {