]> git.itanic.dy.fi Git - linux-stable/commitdiff
cxl/hdm: Fail upon detecting 0-sized decoders
authorDan Williams <dan.j.williams@intel.com>
Fri, 14 Apr 2023 18:53:55 +0000 (11:53 -0700)
committerDan Williams <dan.j.williams@intel.com>
Tue, 18 Apr 2023 17:32:46 +0000 (10:32 -0700)
Decoders committed with 0-size lead to later crashes on shutdown as
__cxl_dpa_release() assumes a 'struct resource' has been established in
the in 'cxlds->dpa_res'. Just fail the driver load in this instance
since there are deeper problems with the enumeration or the setup when
this happens.

Fixes: 9c57cde0dcbd ("cxl/hdm: Enumerate allocated DPA")
Cc: <stable@vger.kernel.org>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Alison Schofield <alison.schofield@intel.com>
Link: https://lore.kernel.org/r/168149843516.792294.11872242648319572632.stgit@dwillia2-xfh.jf.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
drivers/cxl/core/hdm.c

index 02cc2c38b44baf8ef37c3dd9c4b4d7806181e3bb..35b338b716fed12caa931590f1c8f2621e89f414 100644 (file)
@@ -269,8 +269,11 @@ static int __cxl_dpa_reserve(struct cxl_endpoint_decoder *cxled,
 
        lockdep_assert_held_write(&cxl_dpa_rwsem);
 
-       if (!len)
-               goto success;
+       if (!len) {
+               dev_warn(dev, "decoder%d.%d: empty reservation attempted\n",
+                        port->id, cxled->cxld.id);
+               return -EINVAL;
+       }
 
        if (cxled->dpa_res) {
                dev_dbg(dev, "decoder%d.%d: existing allocation %pr assigned\n",
@@ -323,7 +326,6 @@ static int __cxl_dpa_reserve(struct cxl_endpoint_decoder *cxled,
                cxled->mode = CXL_DECODER_MIXED;
        }
 
-success:
        port->hdm_end++;
        get_device(&cxled->cxld.dev);
        return 0;
@@ -833,6 +835,13 @@ static int init_hdm_decoder(struct cxl_port *port, struct cxl_decoder *cxld,
                                 port->id, cxld->id);
                        return -ENXIO;
                }
+
+               if (size == 0) {
+                       dev_warn(&port->dev,
+                                "decoder%d.%d: Committed with zero size\n",
+                                port->id, cxld->id);
+                       return -ENXIO;
+               }
                port->commit_end = cxld->id;
        } else {
                /* unless / until type-2 drivers arrive, assume type-3 */