From: Jonathan Cameron <jonathan.cameron@huawei.com>
To: Davidlohr Bueso <dave@stgolabs.net>
Cc: <qemu-devel@nongnu.org>, <linux-cxl@vger.kernel.org>
Subject: Re: [PATCH 1/2] hw/cxl: Respect Media Operation max ops discovery semantics
Date: Thu, 19 Mar 2026 14:50:50 +0000 [thread overview]
Message-ID: <20260319145050.00002acf@huawei.com> (raw)
In-Reply-To: <20260318185508.3683044-2-dave@stgolabs.net>
On Wed, 18 Mar 2026 11:55:07 -0700
Davidlohr Bueso <dave@stgolabs.net> wrote:
> The Discovery handler rejects requests where start_index + num_ops
> exceeds the total number of supported operations. Per CXL 4.0
> Table 8-332, num_ops is the "Maximum number of Media Operation to
> return" - a maximum, not an exact count. The device should return
> up to that many entries, not reject the request.
>
> Cap num_ops to the available entries from start_index instead of
> erroring the command.
>
> Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
One trivial thing inline.
> ---
> hw/cxl/cxl-mailbox-utils.c | 25 +++++++++++--------------
> 1 file changed, 11 insertions(+), 14 deletions(-)
>
> diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
> index a3143f3faa23..71a012121c87 100644
> --- a/hw/cxl/cxl-mailbox-utils.c
> +++ b/hw/cxl/cxl-mailbox-utils.c
> @@ -2593,6 +2593,7 @@ static CXLRetCode media_operations_discovery(uint8_t *payload_in,
> } QEMU_PACKED *media_op_in_disc_pl = (void *)payload_in;
> struct media_op_discovery_out_pl *media_out_pl =
> (struct media_op_discovery_out_pl *)payload_out;
> + int total = ARRAY_SIZE(media_op_matrix);
> int num_ops, start_index, i;
> int count = 0;
>
> @@ -2609,24 +2610,20 @@ static CXLRetCode media_operations_discovery(uint8_t *payload_in,
> * sub class command.
> */
> if (media_op_in_disc_pl->dpa_range_count ||
> - start_index + num_ops > ARRAY_SIZE(media_op_matrix)) {
> + start_index >= total) {
> return CXL_MBOX_INVALID_INPUT;
> }
>
> media_out_pl->dpa_range_granularity = CXL_CACHE_LINE_SIZE;
> - media_out_pl->total_supported_operations =
> - ARRAY_SIZE(media_op_matrix);
> - if (num_ops > 0) {
> - for (i = start_index; i < start_index + num_ops; i++) {
> - media_out_pl->entry[count].media_op_class =
> - media_op_matrix[i].media_op_class;
> - media_out_pl->entry[count].media_op_subclass =
> - media_op_matrix[i].media_op_subclass;
> - count++;
> - if (count == num_ops) {
> - break;
> - }
> - }
> + media_out_pl->total_supported_operations = total;
> +
> + num_ops = MIN(num_ops, total - start_index);
> + for (i = 0; i < num_ops; i++) {
> + media_out_pl->entry[count].media_op_class =
> + media_op_matrix[start_index + i].media_op_class;
> + media_out_pl->entry[count].media_op_subclass =
> + media_op_matrix[start_index + i].media_op_subclass;
Patch in general looks good, but the indenting here is a bit too creative
/ inconsistent.
media_out_pl->entry[count].media_op_class =
media_op_matrix[start_index + i].media_op_class;
media_out_pl->entry[count].media_op_subclass =
media_op_matrix[start_index + i].media_op_subclass;
or something along those lines.
> + count++;
> }
>
> media_out_pl->num_of_supported_operations = count;
WARNING: multiple messages have this Message-ID (diff)
From: Jonathan Cameron via qemu development <qemu-devel@nongnu.org>
To: Davidlohr Bueso <dave@stgolabs.net>
Cc: <qemu-devel@nongnu.org>, <linux-cxl@vger.kernel.org>
Subject: Re: [PATCH 1/2] hw/cxl: Respect Media Operation max ops discovery semantics
Date: Thu, 19 Mar 2026 14:50:50 +0000 [thread overview]
Message-ID: <20260319145050.00002acf@huawei.com> (raw)
In-Reply-To: <20260318185508.3683044-2-dave@stgolabs.net>
On Wed, 18 Mar 2026 11:55:07 -0700
Davidlohr Bueso <dave@stgolabs.net> wrote:
> The Discovery handler rejects requests where start_index + num_ops
> exceeds the total number of supported operations. Per CXL 4.0
> Table 8-332, num_ops is the "Maximum number of Media Operation to
> return" - a maximum, not an exact count. The device should return
> up to that many entries, not reject the request.
>
> Cap num_ops to the available entries from start_index instead of
> erroring the command.
>
> Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
One trivial thing inline.
> ---
> hw/cxl/cxl-mailbox-utils.c | 25 +++++++++++--------------
> 1 file changed, 11 insertions(+), 14 deletions(-)
>
> diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
> index a3143f3faa23..71a012121c87 100644
> --- a/hw/cxl/cxl-mailbox-utils.c
> +++ b/hw/cxl/cxl-mailbox-utils.c
> @@ -2593,6 +2593,7 @@ static CXLRetCode media_operations_discovery(uint8_t *payload_in,
> } QEMU_PACKED *media_op_in_disc_pl = (void *)payload_in;
> struct media_op_discovery_out_pl *media_out_pl =
> (struct media_op_discovery_out_pl *)payload_out;
> + int total = ARRAY_SIZE(media_op_matrix);
> int num_ops, start_index, i;
> int count = 0;
>
> @@ -2609,24 +2610,20 @@ static CXLRetCode media_operations_discovery(uint8_t *payload_in,
> * sub class command.
> */
> if (media_op_in_disc_pl->dpa_range_count ||
> - start_index + num_ops > ARRAY_SIZE(media_op_matrix)) {
> + start_index >= total) {
> return CXL_MBOX_INVALID_INPUT;
> }
>
> media_out_pl->dpa_range_granularity = CXL_CACHE_LINE_SIZE;
> - media_out_pl->total_supported_operations =
> - ARRAY_SIZE(media_op_matrix);
> - if (num_ops > 0) {
> - for (i = start_index; i < start_index + num_ops; i++) {
> - media_out_pl->entry[count].media_op_class =
> - media_op_matrix[i].media_op_class;
> - media_out_pl->entry[count].media_op_subclass =
> - media_op_matrix[i].media_op_subclass;
> - count++;
> - if (count == num_ops) {
> - break;
> - }
> - }
> + media_out_pl->total_supported_operations = total;
> +
> + num_ops = MIN(num_ops, total - start_index);
> + for (i = 0; i < num_ops; i++) {
> + media_out_pl->entry[count].media_op_class =
> + media_op_matrix[start_index + i].media_op_class;
> + media_out_pl->entry[count].media_op_subclass =
> + media_op_matrix[start_index + i].media_op_subclass;
Patch in general looks good, but the indenting here is a bit too creative
/ inconsistent.
media_out_pl->entry[count].media_op_class =
media_op_matrix[start_index + i].media_op_class;
media_out_pl->entry[count].media_op_subclass =
media_op_matrix[start_index + i].media_op_subclass;
or something along those lines.
> + count++;
> }
>
> media_out_pl->num_of_supported_operations = count;
next prev parent reply other threads:[~2026-03-19 14:50 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-18 18:55 [PATCH v2 -qemu 0/2] hw/cxl: Media Operation Discovery fixlets Davidlohr Bueso
2026-03-18 18:55 ` [PATCH 1/2] hw/cxl: Respect Media Operation max ops discovery semantics Davidlohr Bueso
2026-03-19 14:50 ` Jonathan Cameron [this message]
2026-03-19 14:50 ` Jonathan Cameron via qemu development
2026-03-18 18:55 ` [PATCH 2/2] hw/cxl: Exclude Discovery from Media Operation Discovery output Davidlohr Bueso
2026-03-19 14:54 ` Jonathan Cameron
2026-03-19 14:54 ` Jonathan Cameron via qemu development
-- strict thread matches above, loose matches on Subject: below --
2026-03-19 18:42 [PATCH v3 -qemu 0/2] hw/cxl: Media Operation Discovery fixlets Davidlohr Bueso
2026-03-19 18:42 ` [PATCH 1/2] hw/cxl: Respect Media Operation max ops discovery semantics Davidlohr Bueso
2026-03-18 18:42 [PATCH -qemu 0/2] hw/cxl: Media Operation Discovery fixles Davidlohr Bueso
2026-03-18 18:42 ` [PATCH 1/2] hw/cxl: Respect Media Operation max ops discovery semantics Davidlohr Bueso
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=20260319145050.00002acf@huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=dave@stgolabs.net \
--cc=linux-cxl@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
/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.