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>
Subject: Re: [PATCH 4/4] cxl/mbox: Add KUnit tests for cxl_internal_send_cmd()
Date: Mon, 19 Oct 2026 14:22:05 -0700 [thread overview]
Message-ID: <ataJ_b397PDR6YwP@aschofie-mobl2.lan> (raw)
In-Reply-To: <4e79ef12-5873-43ef-a763-47fb062dc77a@zohomail.com>
On Thu, Oct 15, 2026 at 05:37:26PM +0800, Li Ming wrote:
>
> 在 2026/10/14 12:17, Alison Schofield 写道:
> > cxl_internal_send_cmd() validates mailbox payload sizes, translates device
> > return codes to errnos, and checks returned output sizes. Existing cxl_test
> > coverage does not exercise many of its error paths.
> >
> > Add a KUnit suite that replaces mbox_send() with a stub transport, allowing
> > tests to control transport errors, device return codes, and output sizes.
> >
> > The suite covers command forwarding, payload size limits, transport errors,
> > defined and unknown device return codes, background commands, and fixed
> > versus variable output sizes.
> >
> > The unknown return code cases provide regression coverage for "cxl/mbox:
> > Treat unknown device return codes as errors". Without that change, the
> > tests fail and KASAN reports a global out-of-bounds read.
> >
> > The suite uses the existing CONFIG_CXL_KUNIT_TEST option, allowing it to
> > run without additional configuration.
> >
> > Signed-off-by: Alison Schofield <alison.schofield@intel.com>
> > ---
> > Documentation/driver-api/cxl/testing.rst | 3 +
> > drivers/cxl/core/Makefile | 1 +
> > drivers/cxl/core/tests/Makefile | 5 +
> > drivers/cxl/core/tests/mbox_kunit.c | 249 +++++++++++++++++++++++
> > 4 files changed, 258 insertions(+)
> > create mode 100644 drivers/cxl/core/tests/Makefile
> > create mode 100644 drivers/cxl/core/tests/mbox_kunit.c
> >
snip
> > +static int cxl_mbox_test_init(struct kunit *test)
> > +{
> > + struct mock_mbox *mock;
> > +
> > + mock = kunit_kzalloc(test, sizeof(*mock), GFP_KERNEL);
> > + KUNIT_ASSERT_NOT_NULL(test, mock);
> > +
> > + mock->cxl_mbox.payload_size = TEST_PAYLOAD_SIZE;
> > + mock->cxl_mbox.mbox_send = mock_mbox_send;
mock->return_code = CXL_MBOX_CMD_RC_SUCCESS;
> > + test->priv = mock;
>
> How about adding a line "mock->return_code = CXL_MBOX_CMD_RC_SUCCESS" here
> to explicitly initialize mock->return_code? It makes easier for readers to
> see the default return_code is SUCCESS.
>
Thanks and agree. Done like above in v2.
snip more below...
> > +
> > +static void send_unknown_return_code(struct kunit *test)
> > +{
> > + static const u16 codes[] = { ARRAY_SIZE(cxl_mbox_cmd_rctable), 0x100,
> > + 0xffff };
> > + struct mock_mbox *mock = test->priv;
> > +
> > + /* Codes the driver does not know are still device errors */
> > + for (int i = 0; i < ARRAY_SIZE(codes); i++) {
> > + struct cxl_mbox_cmd cmd = {};
> > + int rc;
> > +
> > + mock->return_code = codes[i];
> > + rc = cxl_internal_send_cmd(&mock->cxl_mbox, &cmd);
> > + KUNIT_EXPECT_EQ_MSG(test, rc, -ENXIO, "return_code=%#x",
> > + codes[i]);
> > + KUNIT_EXPECT_STREQ_MSG(test, cxl_mbox_cmd_rc2str(&cmd),
> > + "unknown return code", "return_code=%#x",
> > + codes[i]);
> > + }
> > +}
> Since we already have cxl_mbox_cmd_rctable here, should we also cover the
> existing return_codes that we know?
The known return codes are covered by send_device_error(). That iterates
thru the rc table and checks the expected errno for each entry. SUCCESS
and BACKGROUND are covered by their own tests.
The unknown return code test exercises the new out-of-range handling, so
I think we have the coverage we need here.
-- Alison
next prev parent reply other threads:[~2026-10-19 21:22 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
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 [this message]
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=ataJ_b397PDR6YwP@aschofie-mobl2.lan \
--to=alison.schofield@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=icheng@nvidia.com \
--cc=iweiny@kernel.org \
--cc=jic23@kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=ming.li@zohomail.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 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.