[QEMU PATCH] cxl/cxl-mailbox-utils: Fix size check for cmd_firmware_update_get_info

nifan.cxl@gmail.com posted 1 patch 1 month, 2 weeks ago
hw/cxl/cxl-mailbox-utils.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[QEMU PATCH] cxl/cxl-mailbox-utils: Fix size check for cmd_firmware_update_get_info
Posted by nifan.cxl@gmail.com 1 month, 2 weeks ago
From: Fan Ni <fan.ni@samsung.com>

In the function cmd_firmware_update_get_info for handling Get FW info
command (0x0200h), the vmem, pmem and DC capacity size check were
incorrect. The size should be aligned to 256MiB, not smaller than
256MiB.

Signed-off-by: Fan Ni <fan.ni@samsung.com>
---
 hw/cxl/cxl-mailbox-utils.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
index 9258e48f95..c82ad50ac8 100644
--- a/hw/cxl/cxl-mailbox-utils.c
+++ b/hw/cxl/cxl-mailbox-utils.c
@@ -649,9 +649,9 @@ static CXLRetCode cmd_firmware_update_get_info(const struct cxl_cmd *cmd,
     } QEMU_PACKED *fw_info;
     QEMU_BUILD_BUG_ON(sizeof(*fw_info) != 0x50);
 
-    if ((cxl_dstate->vmem_size < CXL_CAPACITY_MULTIPLIER) ||
-        (cxl_dstate->pmem_size < CXL_CAPACITY_MULTIPLIER) ||
-        (ct3d->dc.total_capacity < CXL_CAPACITY_MULTIPLIER)) {
+    if ((!QEMU_IS_ALIGNED(cxl_dstate->vmem_size, CXL_CAPACITY_MULTIPLIER)) ||
+        (!QEMU_IS_ALIGNED(cxl_dstate->pmem_size, CXL_CAPACITY_MULTIPLIER)) ||
+        (!QEMU_IS_ALIGNED(ct3d->dc.total_capacity, CXL_CAPACITY_MULTIPLIER))) {
         return CXL_MBOX_INTERNAL_ERROR;
     }
 
-- 
2.43.0
Re: [QEMU PATCH] cxl/cxl-mailbox-utils: Fix size check for cmd_firmware_update_get_info
Posted by Davidlohr Bueso 1 month, 2 weeks ago
On Tue, 08 Oct 2024, nifan.cxl@gmail.com wrote:\n
>From: Fan Ni <fan.ni@samsung.com>
>
>In the function cmd_firmware_update_get_info for handling Get FW info
>command (0x0200h), the vmem, pmem and DC capacity size check were
>incorrect. The size should be aligned to 256MiB, not smaller than
>256MiB.

Can get rid of a level of parenthesis (other cmds as well), otherwise:

Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>

>
>Signed-off-by: Fan Ni <fan.ni@samsung.com>
>---
> hw/cxl/cxl-mailbox-utils.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
>diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
>index 9258e48f95..c82ad50ac8 100644
>--- a/hw/cxl/cxl-mailbox-utils.c
>+++ b/hw/cxl/cxl-mailbox-utils.c
>@@ -649,9 +649,9 @@ static CXLRetCode cmd_firmware_update_get_info(const struct cxl_cmd *cmd,
>     } QEMU_PACKED *fw_info;
>     QEMU_BUILD_BUG_ON(sizeof(*fw_info) != 0x50);
>
>-    if ((cxl_dstate->vmem_size < CXL_CAPACITY_MULTIPLIER) ||
>-        (cxl_dstate->pmem_size < CXL_CAPACITY_MULTIPLIER) ||
>-        (ct3d->dc.total_capacity < CXL_CAPACITY_MULTIPLIER)) {
>+    if ((!QEMU_IS_ALIGNED(cxl_dstate->vmem_size, CXL_CAPACITY_MULTIPLIER)) ||
>+        (!QEMU_IS_ALIGNED(cxl_dstate->pmem_size, CXL_CAPACITY_MULTIPLIER)) ||
>+        (!QEMU_IS_ALIGNED(ct3d->dc.total_capacity, CXL_CAPACITY_MULTIPLIER))) {
>         return CXL_MBOX_INTERNAL_ERROR;
>     }
>
>--
>2.43.0
>
Re: [QEMU PATCH] cxl/cxl-mailbox-utils: Fix size check for cmd_firmware_update_get_info
Posted by Jonathan Cameron via 1 month, 1 week ago
On Tue, 8 Oct 2024 20:01:07 -0700
Davidlohr Bueso <dave@stgolabs.net> wrote:

> On Tue, 08 Oct 2024, nifan.cxl@gmail.com wrote:\n
> >From: Fan Ni <fan.ni@samsung.com>
> >
> >In the function cmd_firmware_update_get_info for handling Get FW info
> >command (0x0200h), the vmem, pmem and DC capacity size check were
> >incorrect. The size should be aligned to 256MiB, not smaller than
> >256MiB.  
> 
> Can get rid of a level of parenthesis (other cmds as well), otherwise:
> 
> Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
I missed this one when gathering up fixes the other day.
I'll queue it up now with the excess brackets dropped.

Jonathan

> 
> >
> >Signed-off-by: Fan Ni <fan.ni@samsung.com>
> >---
> > hw/cxl/cxl-mailbox-utils.c | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
> >
> >diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
> >index 9258e48f95..c82ad50ac8 100644
> >--- a/hw/cxl/cxl-mailbox-utils.c
> >+++ b/hw/cxl/cxl-mailbox-utils.c
> >@@ -649,9 +649,9 @@ static CXLRetCode cmd_firmware_update_get_info(const struct cxl_cmd *cmd,
> >     } QEMU_PACKED *fw_info;
> >     QEMU_BUILD_BUG_ON(sizeof(*fw_info) != 0x50);
> >
> >-    if ((cxl_dstate->vmem_size < CXL_CAPACITY_MULTIPLIER) ||
> >-        (cxl_dstate->pmem_size < CXL_CAPACITY_MULTIPLIER) ||
> >-        (ct3d->dc.total_capacity < CXL_CAPACITY_MULTIPLIER)) {
> >+    if ((!QEMU_IS_ALIGNED(cxl_dstate->vmem_size, CXL_CAPACITY_MULTIPLIER)) ||
> >+        (!QEMU_IS_ALIGNED(cxl_dstate->pmem_size, CXL_CAPACITY_MULTIPLIER)) ||
> >+        (!QEMU_IS_ALIGNED(ct3d->dc.total_capacity, CXL_CAPACITY_MULTIPLIER))) {
> >         return CXL_MBOX_INTERNAL_ERROR;
> >     }
> >
> >--
> >2.43.0
> >
Re: [QEMU PATCH] cxl/cxl-mailbox-utils: Fix size check for cmd_firmware_update_get_info
Posted by Fan Ni 1 month, 1 week ago
On Wed, Oct 16, 2024 at 05:01:38PM +0100, Jonathan Cameron wrote:
> On Tue, 8 Oct 2024 20:01:07 -0700
> Davidlohr Bueso <dave@stgolabs.net> wrote:
> 
> > On Tue, 08 Oct 2024, nifan.cxl@gmail.com wrote:\n
> > >From: Fan Ni <fan.ni@samsung.com>
> > >
> > >In the function cmd_firmware_update_get_info for handling Get FW info
> > >command (0x0200h), the vmem, pmem and DC capacity size check were
> > >incorrect. The size should be aligned to 256MiB, not smaller than
> > >256MiB.  
> > 
> > Can get rid of a level of parenthesis (other cmds as well), otherwise:
> > 
> > Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
> I missed this one when gathering up fixes the other day.
> I'll queue it up now with the excess brackets dropped.
> 
> Jonathan
Thanks Jonathan,
Please also take a look the following patch, it is a fix for dcd.

https://lore.kernel.org/linux-cxl/20241015190224.251293-1-nifan.cxl@gmail.com/T/#u

Fan

> 
> > 
> > >
> > >Signed-off-by: Fan Ni <fan.ni@samsung.com>
> > >---
> > > hw/cxl/cxl-mailbox-utils.c | 6 +++---
> > > 1 file changed, 3 insertions(+), 3 deletions(-)
> > >
> > >diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
> > >index 9258e48f95..c82ad50ac8 100644
> > >--- a/hw/cxl/cxl-mailbox-utils.c
> > >+++ b/hw/cxl/cxl-mailbox-utils.c
> > >@@ -649,9 +649,9 @@ static CXLRetCode cmd_firmware_update_get_info(const struct cxl_cmd *cmd,
> > >     } QEMU_PACKED *fw_info;
> > >     QEMU_BUILD_BUG_ON(sizeof(*fw_info) != 0x50);
> > >
> > >-    if ((cxl_dstate->vmem_size < CXL_CAPACITY_MULTIPLIER) ||
> > >-        (cxl_dstate->pmem_size < CXL_CAPACITY_MULTIPLIER) ||
> > >-        (ct3d->dc.total_capacity < CXL_CAPACITY_MULTIPLIER)) {
> > >+    if ((!QEMU_IS_ALIGNED(cxl_dstate->vmem_size, CXL_CAPACITY_MULTIPLIER)) ||
> > >+        (!QEMU_IS_ALIGNED(cxl_dstate->pmem_size, CXL_CAPACITY_MULTIPLIER)) ||
> > >+        (!QEMU_IS_ALIGNED(ct3d->dc.total_capacity, CXL_CAPACITY_MULTIPLIER))) {
> > >         return CXL_MBOX_INTERNAL_ERROR;
> > >     }
> > >
> > >--
> > >2.43.0
> > >  
> 

-- 
Fan Ni