From: Ira Weiny <ira.weiny@intel.com>
To: Hillf Danton <hdanton@sina.com>
Cc: Dan Williams <dan.j.williams@intel.com>,
Bjorn Helgaas <bhelgaas@google.com>, Li Ming <ming4.li@intel.com>,
Vishal Verma <vishal.l.verma@intel.com>,
Lukas Wunner <lukas@wunner.de>,
Alison Schofield <alison.schofield@intel.com>,
<linux-kernel@vger.kernel.org>, <linux-pci@vger.kernel.org>
Subject: Re: [PATCH] PCI/DOE: Remove asynchronous task support
Date: Sun, 20 Nov 2022 05:57:22 -0800 [thread overview]
Message-ID: <Y3oyQhHUbYZGA80M@iweiny-mobl> (raw)
In-Reply-To: <20221120022735.4671-1-hdanton@sina.com>
On Sun, Nov 20, 2022 at 10:27:35AM +0800, Hillf Danton wrote:
> On Sat, 19 Nov 2022 14:25:27 -0800 Ira Weiny <ira.weiny@intel.com>
> > @@ -529,8 +492,18 @@ int pci_doe_submit_task(struct pci_doe_mb *doe_mb, struct pci_doe_task *task)
> > return -EIO;
> >
> > task->doe_mb = doe_mb;
> > - INIT_WORK(&task->work, doe_statemachine_work);
> > - queue_work(doe_mb->work_queue, &task->work);
> > +
> > +again:
> > + if (!mutex_trylock(&doe_mb->exec_lock)) {
> > + if (wait_event_timeout(task->doe_mb->wq,
> > + test_bit(PCI_DOE_FLAG_CANCEL, &doe_mb->flags),
> > + PCI_DOE_POLL_INTERVAL))
> > + return -EIO;
>
> Is EIO worth a line of pr_warn()?
Maybe but I'm not sure it is worth it. This was paralleling the original code
which called pci_doe_flush_mb() to shut down the mailbox. So this is likely to
never happen. The callers could print something if needed.
>
> > + goto again;
> > + }
> > + exec_task(task);
> > + mutex_unlock(&doe_mb->exec_lock);
> > +
>
> If it is likely to take two minutes to acquire the exec_lock after
> rounds of trying again, trylock + wait timeout barely make sense given EIO.
I'm not sure where 2 minutes come from?
#define PCI_DOE_TIMEOUT HZ
#define PCI_DOE_POLL_INTERVAL (PCI_DOE_TIMEOUT / 128)
It is also not anticipated that more than 1 task is being given to the mailbox
but the protection needs to be there because exec_task() will get confused if
more than 1 thread submits at the same time.
All this said I've now convinced myself that there is a race in the use of
PCI_DOE_FLAG_CANCEL even with the existing code.
I believe that if the pci device goes away the doe_mb structure may get free'ed
prior to other threads having a chance to check doe_mb->flags. Worse yet the
work queue itself (doe_mb->wq) may become invalid...
I don't believe this can currently happen because anyone using the doe_mb
structure has a reference to the pci device.
With this patch I think all the doe_mb->flags and the wait queue can go away.
pci_doe_wait() can be replaced with a simple msleep_interruptible().
Let me work through that a bit.
Ira
>
> Hillf
>
> /**
> * wait_event_timeout - sleep until a condition gets true or a timeout elapses
> * @wq_head: the waitqueue to wait on
> * @condition: a C expression for the event to wait for
> * @timeout: timeout, in jiffies
> *
> * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
> * @condition evaluates to true. The @condition is checked each time
> * the waitqueue @wq_head is woken up.
> *
> * wake_up() has to be called after changing any variable that could
> * change the result of the wait condition.
> *
> * Returns:
> * 0 if the @condition evaluated to %false after the @timeout elapsed,
> * 1 if the @condition evaluated to %true after the @timeout elapsed,
> * or the remaining jiffies (at least 1) if the @condition evaluated
> * to %true before the @timeout elapsed.
> */
next prev parent reply other threads:[~2022-11-20 13:57 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-19 22:25 [PATCH] PCI/DOE: Remove asynchronous task support ira.weiny
[not found] ` <20221120022735.4671-1-hdanton@sina.com>
2022-11-20 13:57 ` Ira Weiny [this message]
2022-11-21 17:52 ` Jonathan Cameron
2022-11-21 1:39 ` Li, Ming
2022-11-21 2:07 ` Li, Ming
2022-11-21 22:59 ` Ira Weiny
2022-11-22 9:46 ` Jonathan Cameron
2022-11-22 15:55 ` Ira Weiny
2022-11-21 2:01 ` Zhuo, Qiuxu
2022-11-21 11:07 ` Jonathan Cameron
2022-11-21 14:17 ` Zhuo, Qiuxu
2022-11-21 17:41 ` Jonathan Cameron
2022-11-22 19:48 ` Lukas Wunner
2022-11-21 11:19 ` Jonathan Cameron
2022-11-22 19:28 ` Lukas Wunner
2022-11-22 20:12 ` Dan Williams
2022-11-21 15:24 ` Dan Williams
2022-11-21 17:19 ` Davidlohr Bueso
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=Y3oyQhHUbYZGA80M@iweiny-mobl \
--to=ira.weiny@intel.com \
--cc=alison.schofield@intel.com \
--cc=bhelgaas@google.com \
--cc=dan.j.williams@intel.com \
--cc=hdanton@sina.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=ming4.li@intel.com \
--cc=vishal.l.verma@intel.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