From: ira.weiny@intel.com
To: Bjorn Helgaas <bhelgaas@google.com>,
Dan Williams <dan.j.williams@intel.com>
Cc: Ira Weiny <ira.weiny@intel.com>,
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-kernel@vger.kernel.org,
linux-cxl@vger.kernel.org
Subject: [PATCH V2] PCI/DOE: Detect on stack work items automatically
Date: Thu, 17 Nov 2022 16:05:24 -0800 [thread overview]
Message-ID: <20221118000524.1477383-1-ira.weiny@intel.com> (raw)
From: Ira Weiny <ira.weiny@intel.com>
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.
[1] https://lore.kernel.org/linux-cxl/20221014151045.24781-1-Jonathan.Cameron@huawei.com/T/#m88a7f50dcce52f30c8bf5c3dcc06fa9843b54a2d
[2] https://lore.kernel.org/linux-cxl/20221014151045.24781-1-Jonathan.Cameron@huawei.com/T/#m63c636c5135f304480370924f4d03c00357be667
[3] https://lore.kernel.org/all/20221115011943.1051039-1-ira.weiny@intel.com/
Cc: Bjorn Helgaas <helgaas@kernel.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Reported-by: Gregory Price <gregory.price@memverge.com>
Reported-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Suggested-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
---
Changes from V1
Update oneliner
Use object_is_on_stack() to make this a simple fix
---
drivers/pci/doe.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/doe.c b/drivers/pci/doe.c
index e402f05068a5..42de517022d9 100644
--- a/drivers/pci/doe.c
+++ b/drivers/pci/doe.c
@@ -19,6 +19,7 @@
#include <linux/pci.h>
#include <linux/pci-doe.h>
#include <linux/workqueue.h>
+#include <linux/sched/task_stack.h>
#define PCI_DOE_PROTOCOL_DISCOVERY 0
@@ -529,7 +530,10 @@ 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);
+ if (object_is_on_stack(&task->work))
+ INIT_WORK_ONSTACK(&task->work, doe_statemachine_work);
+ else
+ INIT_WORK(&task->work, doe_statemachine_work);
queue_work(doe_mb->work_queue, &task->work);
return 0;
}
base-commit: 30a0b95b1335e12efef89dd78518ed3e4a71a763
prerequisite-patch-id: dfea657e07f37aa9d7c3d477d68b07f64fe78721
prerequisite-patch-id: e27264e76e637214ee50cdab0e5854b223d44b4e
--
2.37.2
next reply other threads:[~2022-11-18 0:05 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-18 0:05 ira.weiny [this message]
2022-11-18 0:07 ` [PATCH V2] PCI/DOE: Detect on stack work items automatically Ira Weiny
2022-11-18 0:50 ` Bjorn Helgaas
2022-11-18 9:20 ` David Laight
2022-11-18 18:14 ` Dan Williams
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=20221118000524.1477383-1-ira.weiny@intel.com \
--to=ira.weiny@intel.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=bhelgaas@google.com \
--cc=dan.j.williams@intel.com \
--cc=gregory.price@memverge.com \
--cc=helgaas@kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.