linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Rakie Kim <rakie.kim@sk.com>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Rakie Kim <rakie.kim@sk.com>, Gregory Price <gourry@gourry.net>,
	Andrew Morton <akpm@linux-foundation.org>,
	Honggyu Kim <honggyu.kim@sk.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Joshua Hahn <joshua.hahnjy@gmail.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org, kernel_team@skhynix.com
Subject: Re: [PATCH next] mm/mempolicy: Fix error code in sysfs_wi_node_add()
Date: Thu, 24 Apr 2025 14:49:36 +0900	[thread overview]
Message-ID: <20250424054942.120-1-rakie.kim@sk.com> (raw)
In-Reply-To: <aAkWbsmFW2dbRwhk@gourry-fedora-PF4VCD3F>

On Wed, 23 Apr 2025 12:33:50 -0400 Gregory Price <gourry@gourry.net> wrote:
> On Wed, Apr 23, 2025 at 11:24:58AM +0300, Dan Carpenter wrote:
> > Return -EEXIST if the node already exists.  Don't return success.
> > 
> > Fixes: 1bf270ac1b0a ("mm/mempolicy: support memory hotplug in weighted interleave")
> > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> > ---
> > Potentially returning success was intentional?  This is from static
> > analysis and I can't be totally sure.
> 
> I think this was intentional to allow hotplug callbacks to continue
> executing.  I will let the SK folks who wrote the patch confirm/deny.
> 
> If it is intentional, then we need to add a comment here to explain.
> 
> ~Gregory
> 
> > 
> >  mm/mempolicy.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> > index f43951668c41..0538a994440a 100644
> > --- a/mm/mempolicy.c
> > +++ b/mm/mempolicy.c
> > @@ -3539,7 +3539,7 @@ static const struct kobj_type wi_ktype = {
> >  
> >  static int sysfs_wi_node_add(int nid)
> >  {
> > -	int ret = 0;
> > +	int ret;
> >  	char *name;
> >  	struct iw_node_attr *new_attr;
> >  
> > @@ -3569,6 +3569,7 @@ static int sysfs_wi_node_add(int nid)
> >  	if (wi_group->nattrs[nid]) {
> >  		mutex_unlock(&wi_group->kobj_lock);
> >  		pr_info("node%d already exists\n", nid);
> > +		ret = -EEXIST;
> >  		goto out;
> >  	}
> >  
> > -- 
> > 2.47.2
> > 
> 

Hi Dan,

Thank you very much for analyzing the issue in this code and for
sharing a detailed patch to address it. Your review is greatly
appreciated.

However, the current behavior of returning success instead of an
-EEXIST or other error code was intentional. I would like to explain
the rationale for this choice and would appreciate your further
thoughts.

The condition:

	if (wi_group->nattrs[nid]) {
		mutex_unlock(&wi_group->kobj_lock);
		pr_info("node%d already exists\n", nid);
		goto out;
	}

is triggered in the following two cases:

1. If `sysfs_wi_node_delete()` fails:
   - This function only performs `sysfs_remove_file()` and frees
     memory, and these operations do not fail in a way that would leave
     the system in an inconsistent state.

2. If `sysfs_wi_node_add()` is invoked multiple times for the same node:
   - While repeated additions for the same node would indicate a
     potential issue in logic, simply skipping the redundant addition
     does not cause a functional problem. The original sysfs entry
     remains valid and continues to work as expected.

Therefore, I chose to return success in this case to avoid interrupting
the flow unnecessarily.

Also, as you pointed out, even if we returned -EEXIST here, it would not
change the runtime behavior. This is because `sysfs_wi_node_add()` is
called from the following memory notifier:

	static int wi_node_notifier(struct notifier_block *nb,
				     unsigned long action, void *data)
	{
		...
		switch (action) {
		case MEM_ONLINE:
			err = sysfs_wi_node_add(nid);
			if (err)
				pr_err("failed to add sysfs for node%d during hotplug: %d\n",
				       nid, err);
			break;
		...
		}
		return NOTIFY_OK;
	}

As discussed in prior reviews (including suggestions by David
Hildenbrand), returning NOTIFY_BAD on failure can interfere with other
notifier chains due to NOTIFY_STOP_MASK behavior. Hence, we always
return NOTIFY_OK to preserve consistent hotplug handling across
subsystems.
I would sincerely appreciate it if you could share any further thoughts
or concerns you may have regarding this decision.

Rakie



  reply	other threads:[~2025-04-24  5:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-23  8:24 Dan Carpenter
2025-04-23 15:27 ` Joshua Hahn
2025-04-23 16:33 ` Gregory Price
2025-04-24  5:49   ` Rakie Kim [this message]
2025-05-02  6:46 ` Honggyu Kim
2025-05-02  7:10   ` Dan Carpenter
2025-05-02  7:40     ` Rakie Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250424054942.120-1-rakie.kim@sk.com \
    --to=rakie.kim@sk.com \
    --cc=akpm@linux-foundation.org \
    --cc=dan.carpenter@linaro.org \
    --cc=dan.j.williams@intel.com \
    --cc=gourry@gourry.net \
    --cc=honggyu.kim@sk.com \
    --cc=joshua.hahnjy@gmail.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kernel_team@skhynix.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox