aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Donnellan <andrew.donnellan@au1.ibm.com>2016-07-28 01:39:41 -0400
committerMichael Ellerman <mpe@ellerman.id.au>2016-08-09 02:52:02 -0400
commit164793379ad3b7ef5fc5a28260c111358892dff3 (patch)
tree007c1bc56c5541efe87ee836f86ec58423bc4bef
parentcbd74e1bc8129efb9908f130a8a6e60fd95d2106 (diff)
cxl: Fix NULL dereference in cxl_context_init() on PowerVM guests
Commit f67a6722d650 ("cxl: Workaround PE=0 hardware limitation in Mellanox CX4") added a "min_pe" field to struct cxl_service_layer_ops, to allow us to work around a Mellanox CX-4 hardware limitation. When allocating the PE number in cxl_context_init(), we read from ctx->afu->adapter->native->sl_ops->min_pe to get the minimum PE number. Unsurprisingly, in a PowerVM guest ctx->afu->adapter->native is NULL, and guests don't have a cxl_service_layer_ops struct anywhere. Move min_pe from struct cxl_service_layer_ops to struct cxl so it's accessible in both native and PowerVM environments. For the Mellanox CX-4, set the min_pe value in set_sl_ops(). Fixes: f67a6722d650 ("cxl: Workaround PE=0 hardware limitation in Mellanox CX4") Reported-by: Frederic Barrat <fbarrat@linux.vnet.ibm.com> Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com> Acked-by: Ian Munsie <imunsie@au1.ibm.com> Reviewed-by: Frederic Barrat <fbarrat@linux.vnet.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
-rw-r--r--drivers/misc/cxl/context.c3
-rw-r--r--drivers/misc/cxl/cxl.h2
-rw-r--r--drivers/misc/cxl/pci.c3
3 files changed, 4 insertions, 4 deletions
diff --git a/drivers/misc/cxl/context.c b/drivers/misc/cxl/context.c
index bdee9a01ef35..c466ee2b0c97 100644
--- a/drivers/misc/cxl/context.c
+++ b/drivers/misc/cxl/context.c
@@ -90,8 +90,7 @@ int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master,
90 */ 90 */
91 mutex_lock(&afu->contexts_lock); 91 mutex_lock(&afu->contexts_lock);
92 idr_preload(GFP_KERNEL); 92 idr_preload(GFP_KERNEL);
93 i = idr_alloc(&ctx->afu->contexts_idr, ctx, 93 i = idr_alloc(&ctx->afu->contexts_idr, ctx, ctx->afu->adapter->min_pe,
94 ctx->afu->adapter->native->sl_ops->min_pe,
95 ctx->afu->num_procs, GFP_NOWAIT); 94 ctx->afu->num_procs, GFP_NOWAIT);
96 idr_preload_end(); 95 idr_preload_end();
97 mutex_unlock(&afu->contexts_lock); 96 mutex_unlock(&afu->contexts_lock);
diff --git a/drivers/misc/cxl/cxl.h b/drivers/misc/cxl/cxl.h
index de090533f18c..344a0ff8f8c7 100644
--- a/drivers/misc/cxl/cxl.h
+++ b/drivers/misc/cxl/cxl.h
@@ -561,7 +561,6 @@ struct cxl_service_layer_ops {
561 u64 (*timebase_read)(struct cxl *adapter); 561 u64 (*timebase_read)(struct cxl *adapter);
562 int capi_mode; 562 int capi_mode;
563 bool needs_reset_before_disable; 563 bool needs_reset_before_disable;
564 int min_pe;
565}; 564};
566 565
567struct cxl_native { 566struct cxl_native {
@@ -603,6 +602,7 @@ struct cxl {
603 struct bin_attribute cxl_attr; 602 struct bin_attribute cxl_attr;
604 int adapter_num; 603 int adapter_num;
605 int user_irqs; 604 int user_irqs;
605 int min_pe;
606 u64 ps_size; 606 u64 ps_size;
607 u16 psl_rev; 607 u16 psl_rev;
608 u16 base_image; 608 u16 base_image;
diff --git a/drivers/misc/cxl/pci.c b/drivers/misc/cxl/pci.c
index d152e2de8c93..1d0347c36e6d 100644
--- a/drivers/misc/cxl/pci.c
+++ b/drivers/misc/cxl/pci.c
@@ -1521,14 +1521,15 @@ static const struct cxl_service_layer_ops xsl_ops = {
1521 .write_timebase_ctrl = write_timebase_ctrl_xsl, 1521 .write_timebase_ctrl = write_timebase_ctrl_xsl,
1522 .timebase_read = timebase_read_xsl, 1522 .timebase_read = timebase_read_xsl,
1523 .capi_mode = OPAL_PHB_CAPI_MODE_DMA, 1523 .capi_mode = OPAL_PHB_CAPI_MODE_DMA,
1524 .min_pe = 1, /* Workaround for Mellanox CX4 HW bug */
1525}; 1524};
1526 1525
1527static void set_sl_ops(struct cxl *adapter, struct pci_dev *dev) 1526static void set_sl_ops(struct cxl *adapter, struct pci_dev *dev)
1528{ 1527{
1529 if (dev->vendor == PCI_VENDOR_ID_MELLANOX && dev->device == 0x1013) { 1528 if (dev->vendor == PCI_VENDOR_ID_MELLANOX && dev->device == 0x1013) {
1529 /* Mellanox CX-4 */
1530 dev_info(&adapter->dev, "Device uses an XSL\n"); 1530 dev_info(&adapter->dev, "Device uses an XSL\n");
1531 adapter->native->sl_ops = &xsl_ops; 1531 adapter->native->sl_ops = &xsl_ops;
1532 adapter->min_pe = 1; /* Workaround for CX-4 hardware bug */
1532 } else { 1533 } else {
1533 dev_info(&adapter->dev, "Device uses a PSL\n"); 1534 dev_info(&adapter->dev, "Device uses a PSL\n");
1534 adapter->native->sl_ops = &psl_ops; 1535 adapter->native->sl_ops = &psl_ops;