From: Dan Williams <dan.j.williams@intel.com>
To: David Laight <David.Laight@aculab.com>,
"'ira.weiny@intel.com'" <ira.weiny@intel.com>,
Bjorn Helgaas <bhelgaas@google.com>,
Dan Williams <dan.j.williams@intel.com>
Cc: Bjorn Helgaas <helgaas@kernel.org>,
Gregory Price <gregory.price@memverge.com>,
Jonathan Cameron <Jonathan.Cameron@huawei.com>,
Lukas Wunner <lukas@wunner.de>,
Vishal Verma <vishal.l.verma@intel.com>,
"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-cxl@vger.kernel.org" <linux-cxl@vger.kernel.org>
Subject: RE: [PATCH V2] PCI/DOE: Detect on stack work items automatically
Date: Fri, 18 Nov 2022 10:14:37 -0800 [thread overview]
Message-ID: <6377cb8d32422_12cdff294e7@dwillia2-xfh.jf.intel.com.notmuch> (raw)
In-Reply-To: <e59f83f3ca4149d098efe43b48fecd1b@AcuMS.aculab.com>
David Laight wrote:
> From: ira.weiny@intel.com
> > Sent: 18 November 2022 00:05
> >
> > Work item initialization needs to be done with either
> > INIT_WORK_ONSTACK() or INIT_WORK() depending on how the work item is
> > allocated.
> >
> > The callers of pci_doe_submit_task() allocate struct pci_doe_task on the
> > stack and pci_doe_submit_task() incorrectly used INIT_WORK().
> >
> > Jonathan suggested creating doe task allocation macros such as
> > DECLARE_CDAT_DOE_TASK_ONSTACK().[1] The issue with this is the work
> > function is not known to the callers and must be initialized correctly.
> >
> > A follow up suggestion was to have an internal 'pci_doe_work' item
> > allocated by pci_doe_submit_task().[2] This requires an allocation which
> > could restrict the context where tasks are used.
> >
> > Another idea was to have an intermediate step to initialize the task
> > struct with a new call.[3] This added a lot of complexity.
> >
> > Lukas pointed out that object_is_on_stack() is available to detect this
> > automatically.
> >
> > Use object_is_on_stack() to determine the correct init work function to
> > call.
>
> This is all a bit strange.
> The 'onstack' flag is needed for the diagnostic check:
> is_on_stack = object_is_on_stack(addr);
> if (is_on_stack == onstack)
> return;
> pr_warn(...);
> WARN_ON(1);
>
> So setting the flag to the location of the buffer just subverts the check.
> It that is sane there ought to be a proper way to do it.
>
> OTOH using an on-stack structure for INIT_WORK seems rather strange.
> Since the kernel thread must sleep waiting for the 'work' to complete
> why not just perform the required code there.
To have the option to support both async and sync flows through this
driver interface. It is similar to the internal distinction between:
submit_bio_wait()
...and:
submit_bio()
Where the former just layers an on on-stack completion over the
asynchronous submit_bio().
> Also you really don't want to OOPS with anything from the stack
> linked into global kernel data structures.
> While wait queues are pretty limited in scope and probably ok,
> this looks like a big accident waiting to happen.
I do not see the cause for alarm, this sync-wait design pattern is not
new.
next prev parent reply other threads:[~2022-11-18 18:14 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-18 0:05 [PATCH V2] PCI/DOE: Detect on stack work items automatically ira.weiny
2022-11-18 0:07 ` Ira Weiny
2022-11-18 0:50 ` Bjorn Helgaas
2022-11-18 9:20 ` David Laight
2022-11-18 18:14 ` Dan Williams [this message]
2022-11-18 18:43 ` Ira Weiny
2022-11-18 19:46 ` Dan Williams
2022-11-19 2:24 ` Li, Ming
2022-11-19 5:11 ` Dan Williams
2022-11-19 17:27 ` Ira Weiny
2022-11-22 17:13 ` Lukas Wunner
2022-11-22 17:14 ` Lukas Wunner
2022-11-22 20:22 ` Dan Williams
2022-11-22 22:06 ` David Laight
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=6377cb8d32422_12cdff294e7@dwillia2-xfh.jf.intel.com.notmuch \
--to=dan.j.williams@intel.com \
--cc=David.Laight@aculab.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=bhelgaas@google.com \
--cc=gregory.price@memverge.com \
--cc=helgaas@kernel.org \
--cc=ira.weiny@intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lukas@wunner.de \
--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