All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alison Schofield <alison.schofield@intel.com>
To: Li Ming <ming.li@zohomail.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>,
	Jonathan Cameron <jic23@kernel.org>,
	Dave Jiang <dave.jiang@intel.com>,
	Vishal Verma <vishal.l.verma@intel.com>,
	Ira Weiny <iweiny@kernel.org>, Richard Cheng <icheng@nvidia.com>,
	<linux-cxl@vger.kernel.org>,
	Gaobin Huang <huanggaobin23@semi.ac.cn>, <stable@vger.kernel.org>
Subject: Re: [PATCH 3/4] cxl/mbox: Treat unknown device return codes as errors
Date: Mon, 19 Oct 2026 14:01:40 -0700	[thread overview]
Message-ID: <ataFNPeoHJjiHj3V@aschofie-mobl2.lan> (raw)
In-Reply-To: <4bcc00ea-1586-471e-a51e-01a0d3f762df@zohomail.com>

On Thu, Oct 15, 2026 at 05:22:02PM +0800, Li Ming wrote:
> 
> 在 2026/10/14 12:17, Alison Schofield 写道:
> > From: Gaobin Huang <huanggaobin23@semi.ac.cn>
> > 
> > cxl_mbox_cmd_rc2errno() and cxl_mbox_cmd_rc2str() use the device's 16-bit
> > return code to index cxl_mbox_cmd_rctable[]. A return code outside the
> > table's range causes an out-of-bounds read, potentially allowing a failed
> > command to be reported as successful.
> > 
> > Check the return code against the table size. Report unknown codes as
> > -ENXIO, the errno used for most device-reported errors, and describe them
> > as "unknown return code".
> > 
> > Found with a QEMU Type-3 device returning codes 001Fh and 0020h, which are defined in CXL 4.0 but not yet recognized by Linux [1].
> > 
> > [1] https://lore.kernel.org/linux-cxl/20260929060747.3550005-1-huanggaobin23@semi.ac.cn/
> > 
> > Fixes: 92fcc1abab09 ("cxl/mbox: Improve handling of mbox_cmd hw return codes")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Gaobin Huang <huanggaobin23@semi.ac.cn>
> > Co-developed-by: Alison Schofield <alison.schofield@intel.com>
> > Signed-off-by: Alison Schofield <alison.schofield@intel.com>
> Reviewed-by: Li Ming <ming.li@zohomail.com>
> 
> 
> The issue is not related this patch, but I found it during reviewing this
> patchset.
> 
> I noticed that the default errno of CXL_MBOX_CMD_RC_BACKGROUND is -ENXIO,
> but description is "background cmd started successfully", I checked no any
> driver code checks/uses this CXL_MBOX_CMD_RC_BACKGROUND's errno, maybe we
> should set to 0 like CXL_MBOX_CMD_RC_SUCCESS?
> 

Hi Ming,

Agree. Fixing it to 0 seems like a separate cleanup, not for this
series. Can you send a separate patch for that?

-- Alison


 > ---
> > 
> > This patch is independently applicable and backportable. It is
> > intentionally introduced here as a lead in to the kunit patch
> > that backstops this fix.
> > 
> > 
> >   drivers/cxl/cxlmem.h | 6 ++++++
> >   1 file changed, 6 insertions(+)
> > 
> > diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h
> > index c401e3a1af06..357d0d873e87 100644
> > --- a/drivers/cxl/cxlmem.h
> > +++ b/drivers/cxl/cxlmem.h
> > @@ -6,6 +6,7 @@
> >   #include <linux/pci.h>
> >   #include <linux/cdev.h>
> >   #include <linux/uuid.h>
> > +#include <linux/array_size.h>
> >   #include <linux/node.h>
> >   #include <cxl/event.h>
> >   #include <cxl/mailbox.h>
> > @@ -205,13 +206,18 @@ static const
> >   struct cxl_mbox_cmd_rc cxl_mbox_cmd_rctable[] ={ CMD_CMD_RC_TABLE };
> >   #undef C
> > +/* The return code comes from the device and may be one this table lacks */
> >   static inline const char *cxl_mbox_cmd_rc2str(struct cxl_mbox_cmd *mbox_cmd)
> >   {
> > +	if (mbox_cmd->return_code >= ARRAY_SIZE(cxl_mbox_cmd_rctable))
> > +		return "unknown return code";
> >   	return cxl_mbox_cmd_rctable[mbox_cmd->return_code].desc;
> >   }
> >   static inline int cxl_mbox_cmd_rc2errno(struct cxl_mbox_cmd *mbox_cmd)
> >   {
> > +	if (mbox_cmd->return_code >= ARRAY_SIZE(cxl_mbox_cmd_rctable))
> > +		return -ENXIO;
> >   	return cxl_mbox_cmd_rctable[mbox_cmd->return_code].err;
> >   }

  reply	other threads:[~2026-10-19 21:01 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14  4:17 [PATCH 0/4] cxl: Add KUnit tests and documentation Alison Schofield
2026-10-14  4:17 ` [PATCH 1/4] Documentation/driver-api/cxl: Add a testing page Alison Schofield
2026-10-14 21:34   ` Alison Schofield
2026-10-16 19:02     ` Jonathan Cameron
2026-10-16 19:01   ` Jonathan Cameron
2026-10-19 20:44     ` Alison Schofield
2026-10-16 22:52   ` Anisa Su
2026-10-19 20:39     ` Alison Schofield
2026-10-14  4:17 ` [PATCH 2/4] cxl: Add KUnit tests for HDM decoder encoding helpers Alison Schofield
2026-10-15  9:16   ` Li Ming
2026-10-16 20:01   ` Jonathan Cameron
2026-10-19 21:09     ` Alison Schofield
2026-10-14  4:17 ` [PATCH 3/4] cxl/mbox: Treat unknown device return codes as errors Alison Schofield
2026-10-14 15:06   ` 黄高彬
2026-10-15  9:22   ` Li Ming
2026-10-19 21:01     ` Alison Schofield [this message]
2026-10-20  2:35       ` Li Ming
2026-10-16 20:03   ` Jonathan Cameron
2026-10-14  4:17 ` [PATCH 4/4] cxl/mbox: Add KUnit tests for cxl_internal_send_cmd() Alison Schofield
2026-10-15  9:37   ` Li Ming
2026-10-19 21:22     ` Alison Schofield
2026-10-20  2:34       ` Li Ming
2026-10-14 20:52 ` [PATCH 0/4] cxl: Add KUnit tests and documentation Dave Jiang

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=ataFNPeoHJjiHj3V@aschofie-mobl2.lan \
    --to=alison.schofield@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --cc=huanggaobin23@semi.ac.cn \
    --cc=icheng@nvidia.com \
    --cc=iweiny@kernel.org \
    --cc=jic23@kernel.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=ming.li@zohomail.com \
    --cc=stable@vger.kernel.org \
    --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.