From: hch@infradead.org (Christoph Hellwig)
Subject: [REPOST][PATCH] nvme_fc: add 'nvme_discovery' sysfs attribute to fc transport device
Date: Tue, 11 Sep 2018 01:58:43 -0700 [thread overview]
Message-ID: <20180911085843.GA17520@infradead.org> (raw)
In-Reply-To: <20180820220611.8769-1-jsmart2021@gmail.com>
> + 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);
> + 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?
> + 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.
next prev parent reply other threads:[~2018-09-11 8:58 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 [this message]
2018-09-11 18:02 ` James Smart
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=20180911085843.GA17520@infradead.org \
--to=hch@infradead.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;
as well as URLs for NNTP newsgroup(s).