linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: jsmart2021@gmail.com (James Smart)
Subject: [REPOST][PATCH] nvme_fc: add 'nvme_discovery' sysfs attribute to fc transport device
Date: Tue, 11 Sep 2018 11:02:13 -0700	[thread overview]
Message-ID: <c806be1b-f86f-de84-3669-d9bb89aaaf65@gmail.com> (raw)
In-Reply-To: <20180911085843.GA17520@infradead.org>

On 9/11/2018 1:58 AM, Christoph Hellwig wrote:
>> +	unsigned long flags;
>> +	struct nvme_fc_lport *lport;
>> +	struct nvme_fc_rport *rport, *tmp_rport;
>> +
>> +	list_for_each_entry_safe(rport, tmp_rport,
>> +				 lheadp, disc_list) {
>> +		spin_lock_irqsave(&nvme_fc_lock, flags);
>> +		list_del_init(&rport->disc_list);
>> +		spin_unlock_irqrestore(&nvme_fc_lock, flags);
>> +		lport = rport->lport;
>> +		/* signal discovery. Won't hurt if it repeats */
>> +		nvme_fc_signal_discovery_scan(lport, rport);
>> +		nvme_fc_rport_put(rport);
>> +		nvme_fc_lport_put(lport);
>> +	}
> 
> This list iteration is not safe.  It should probably be something like:
> 
> 	spin_lock_irqsave(&nvme_fc_lock, flags);
> 	while (!list_empty(disc_list)) {
> 		struct nvme_fc_rport *rport = list_entry(disc_list->next,
> 				struct nvme_fc_lport, disct_list);
> 
> 		list_del_init(&rport->disc_list);
> 		spin_unlock_irqrestore(&nvme_fc_lock, flags);
> 
> 		lport = rport->lport;
> 		/* signal discovery. Won't hurt if it repeats */
> 		nvme_fc_signal_discovery_scan(lport, rport);
> 		nvme_fc_rport_put(rport);
> 		nvme_fc_lport_put(lport);
> 
> 		spin_lock_irqsave(&nvme_fc_lock, flags);
> 	}
> 	spin_unlock_irqrestore(&nvme_fc_lock, flags);

Well, I don't think I agree with you on the safeness of the locking, but 
moving it to the other style isn't different and looks more normal. I'll 
rework it.


> 
> 
>> +			if (!nvme_fc_lport_get(lport))
>> +				continue;
>> +			if (!nvme_fc_rport_get(rport)) {
>> +				/*
>> +				 * This is a temporary condition, so upon
>> +				 * restart this node will be gone from the
>> +				 * list.
>> +				 */
>> +				spin_unlock_irqrestore(&nvme_fc_lock, flags);
>> +				nvme_fc_lport_put(lport);
>> +				nvme_fc_discovery_unwind(&nvme_fc_disc_list);
>> +				if (failcnt++ < DISCOVERY_MAX_FAIL)
>> +					goto restart;
>> +				pr_err("nvme_discovery: too many reference "
>> +				       "failures\n");
>> +				return 0;
>> +			}
> 
> Maybe use a goto for this condition to move it out of the loop?

May not be necessary. I think I want to change this loop a little.

> 
>> +	list_for_each_entry_safe(rport, tmp_rport,
>> +				 &nvme_fc_disc_list, disc_list) {
>> +		spin_lock_irqsave(&nvme_fc_lock, flags);
>> +		list_del_init(&rport->disc_list);
>> +		spin_unlock_irqrestore(&nvme_fc_lock, flags);
>> +		lport = rport->lport;
>> +		nvme_fc_signal_discovery_scan(lport, rport);
>> +		nvme_fc_rport_put(rport);
>> +		nvme_fc_lport_put(lport);
>> +	}
> 
> Same locking issue as above.  And in fact exactly the same code, so
> it should probably call nvme_fc_discovery_unwind.

ok

-- james

  reply	other threads:[~2018-09-11 18:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-20 22:06 [REPOST][PATCH] nvme_fc: add 'nvme_discovery' sysfs attribute to fc transport device James Smart
2018-09-05 20:14 ` James Smart
2018-09-11  8:58 ` Christoph Hellwig
2018-09-11 18:02   ` James Smart [this message]
2018-09-17 13:41     ` Christoph Hellwig
2018-09-17 16:07       ` James Smart

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=c806be1b-f86f-de84-3669-d9bb89aaaf65@gmail.com \
    --to=jsmart2021@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).