Dave Jiang's patch [1] adds feat_mutex to serialize kernel-managed Get
and Set Feature operations. However, the RAW command path calls
mbox_send() directly and bypasses cxl_get_feature() and
cxl_set_feature().
Take feat_mutex around each RAW Get and Set Feature mailbox send. This
prevents individual RAW Feature commands from interleaving with
kernel-managed Feature helper loops. Other RAW commands are unchanged.
[1]:
https://lore.kernel.org/linux-cxl/20260709155841.1895915-1-dave.jiang@intel.com/
Signed-off-by: Richard Cheng <icheng@nvidia.com>
---
drivers/cxl/core/mbox.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
index 0370ac39ec4a..55b0c3ac1ede 100644
--- a/drivers/cxl/core/mbox.c
+++ b/drivers/cxl/core/mbox.c
@@ -599,6 +599,8 @@ static int handle_mailbox_cmd_from_user(struct cxl_mailbox *cxl_mbox,
u32 *retval)
{
struct device *dev = cxl_mbox->host;
+ bool is_feature_cmd = mbox_cmd->opcode == CXL_MBOX_OP_GET_FEATURE ||
+ mbox_cmd->opcode == CXL_MBOX_OP_SET_FEATURE;
int rc;
dev_dbg(dev,
@@ -608,7 +610,11 @@ static int handle_mailbox_cmd_from_user(struct cxl_mailbox *cxl_mbox,
cxl_mem_opcode_to_name(mbox_cmd->opcode),
mbox_cmd->opcode, mbox_cmd->size_in);
+ if (is_feature_cmd)
+ mutex_lock(&cxl_mbox->feat_mutex);
rc = cxl_mbox->mbox_send(cxl_mbox, mbox_cmd);
+ if (is_feature_cmd)
+ mutex_unlock(&cxl_mbox->feat_mutex);
if (rc)
goto out;
--
2.43.0