Skip to contentSkip to conversation

vdpa/ifc: check lm_cfg is not NULL before use lm_cfg

PATCH Superseded Andy Pei 2 participants 2 messages Dec 13, 2021 virtio core

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Andy Pei

author
#0 lore raw

PATCH 2/3 vdpa/ifc: check lm_cfg is not NULL before use lm_cfg

check lm_cfg is not NULL before use lm_cfg.
when init hardware, if lm_cfg is NULL, output some debug information.

---
 drivers/vdpa/ifc/base/ifcvf.c | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)
drivers/vdpa/ifc/base/ifcvf.c +24 -8
index d10c1fd..b9b061f 100644
@@ -87,6 +87,8 @@
 	}
 
 	hw->lm_cfg = hw->mem_resource[4].addr;
+	if (!hw->lm_cfg)
+		DEBUGOUT("HW mem_resource[4] is NULL, so lm_cfg is NULL.\n");
 
 	if (hw->common_cfg == NULL || hw->notify_base == NULL ||
 			hw->isr == NULL || hw->dev_cfg == NULL) {
@@ -218,10 +220,13 @@
 				&cfg->queue_used_hi);
 		IFCVF_WRITE_REG16(hw->vring[i].size, &cfg->queue_size);
 
-		*(u32 *)(lm_cfg + IFCVF_LM_RING_STATE_OFFSET +
-				(i / 2) * IFCVF_LM_CFG_SIZE + (i % 2) * 4) =
-			(u32)hw->vring[i].last_avail_idx |
-			((u32)hw->vring[i].last_used_idx << 16);
+		if (lm_cfg != NULL) {
+			*(u32 *)(lm_cfg + IFCVF_LM_RING_STATE_OFFSET +
+					(i / 2) * IFCVF_LM_CFG_SIZE +
+					(i % 2) * 4) =
+				(u32)hw->vring[i].last_avail_idx |
+				((u32)hw->vring[i].last_used_idx << 16);
+		}
 
 		IFCVF_WRITE_REG16(i + 1, &cfg->queue_msix_vector);
 		if (IFCVF_READ_REG16(&cfg->queue_msix_vector) ==
@@ -254,10 +259,14 @@
 		IFCVF_WRITE_REG16(i, &cfg->queue_select);
 		IFCVF_WRITE_REG16(0, &cfg->queue_enable);
 		IFCVF_WRITE_REG16(IFCVF_MSI_NO_VECTOR, &cfg->queue_msix_vector);
-		ring_state = *(u32 *)(hw->lm_cfg + IFCVF_LM_RING_STATE_OFFSET +
-				(i / 2) * IFCVF_LM_CFG_SIZE + (i % 2) * 4);
-		hw->vring[i].last_avail_idx = (u16)(ring_state >> 16);
-		hw->vring[i].last_used_idx = (u16)(ring_state >> 16);
+		if (hw->lm_cfg != NULL) {
+			ring_state = *(u32 *)(hw->lm_cfg +
+					IFCVF_LM_RING_STATE_OFFSET +
+					(i / 2) * IFCVF_LM_CFG_SIZE +
+					(i % 2) * 4);
+			hw->vring[i].last_avail_idx = (u16)(ring_state >> 16);
+			hw->vring[i].last_used_idx = (u16)(ring_state >> 16);
+		}
 	}
 }
 
@@ -292,6 +301,9 @@
 
 	lm_cfg = hw->lm_cfg;
 
+	if (lm_cfg == NULL)
+		return;
+
 	*(u32 *)(lm_cfg + IFCVF_LM_BASE_ADDR_LOW) =
 		log_base & IFCVF_32_BIT_MASK;
 
@@ -313,6 +325,10 @@
 	u8 *lm_cfg;
 
 	lm_cfg = hw->lm_cfg;
+
+	if (lm_cfg == NULL)
+		return;
+
 	*(u32 *)(lm_cfg + IFCVF_LM_LOGGING_CTRL) = IFCVF_LM_DISABLE;
 }
 
Signature · 1 line
1.8.3.1
#1 lore raw

Hi,

Comments inline.

BRs,
Xiao

Quoted 10 lines

-----Original Message-----
From: Pei, Andy <[email protected]>
Sent: Monday, December 13, 2021 12:29 PM
To: [email protected]
Cc: Pei, Andy <[email protected]>; Xia, Chenbo <[email protected]>; Wang, Xiao W <[email protected]>
Subject: [PATCH 2/3] vdpa/ifc: check lm_cfg is not NULL before use lm_cfg

check lm_cfg is not NULL before use lm_cfg.
when init hardware, if lm_cfg is NULL, output some debug information.

1. We need to capitalize the first letter in a sentence.
2. If lm_cfg is null, then I assume device doesn't support HW LM feature. But in below code change, many places just return silently, is it an issue?

Quoted 11 lines
---
 drivers/vdpa/ifc/base/ifcvf.c | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)
drivers/vdpa/ifc/base/ifcvf.c +0 -0
index d10c1fd..b9b061f 100644

drivers/vdpa/ifc/base/ifcvf.c line 92

Quoted 6 lines
drivers/vdpa/ifc/base/ifcvf.c +2 -0
@@ -87,6 +87,8 @@
 	}
 
 	hw->lm_cfg = hw->mem_resource[4].addr;
+	if (!hw->lm_cfg)
+		DEBUGOUT("HW mem_resource[4] is NULL, so lm_cfg is
 NULL.\n");

We need to make the debug message more human readable.

Quoted 65 lines
drivers/vdpa/ifc/base/ifcvf.c +7 -5
 	if (hw->common_cfg == NULL || hw->notify_base == NULL ||
 			hw->isr == NULL || hw->dev_cfg == NULL) {
@@ -218,10 +220,13 @@
 				&cfg->queue_used_hi);
 		IFCVF_WRITE_REG16(hw->vring[i].size, &cfg->queue_size);
 
-		*(u32 *)(lm_cfg + IFCVF_LM_RING_STATE_OFFSET +
-				(i / 2) * IFCVF_LM_CFG_SIZE + (i % 2) * 4) =
-			(u32)hw->vring[i].last_avail_idx |
-			((u32)hw->vring[i].last_used_idx << 16);
+		if (lm_cfg != NULL) {
+			*(u32 *)(lm_cfg + IFCVF_LM_RING_STATE_OFFSET +
+					(i / 2) * IFCVF_LM_CFG_SIZE +
+					(i % 2) * 4) =
+				(u32)hw->vring[i].last_avail_idx |
+				((u32)hw->vring[i].last_used_idx << 16);
+		}
 
 		IFCVF_WRITE_REG16(i + 1, &cfg->queue_msix_vector);
 		if (IFCVF_READ_REG16(&cfg->queue_msix_vector) ==
@@ -254,10 +259,14 @@
 		IFCVF_WRITE_REG16(i, &cfg->queue_select);
 		IFCVF_WRITE_REG16(0, &cfg->queue_enable);
 		IFCVF_WRITE_REG16(IFCVF_MSI_NO_VECTOR, &cfg-
 >queue_msix_vector);
-		ring_state = *(u32 *)(hw->lm_cfg +

IFCVF_LM_RING_STATE_OFFSET +

drivers/vdpa/ifc/base/ifcvf.c +15 -4
-				(i / 2) * IFCVF_LM_CFG_SIZE + (i % 2) * 4);
-		hw->vring[i].last_avail_idx = (u16)(ring_state >> 16);
-		hw->vring[i].last_used_idx = (u16)(ring_state >> 16);
+		if (hw->lm_cfg != NULL) {
+			ring_state = *(u32 *)(hw->lm_cfg +
+					IFCVF_LM_RING_STATE_OFFSET +
+					(i / 2) * IFCVF_LM_CFG_SIZE +
+					(i % 2) * 4);
+			hw->vring[i].last_avail_idx = (u16)(ring_state >> 16);
+			hw->vring[i].last_used_idx = (u16)(ring_state >> 16);
+		}
 	}
 }
@@ -292,6 +301,9 @@
 
 	lm_cfg = hw->lm_cfg;
 
+	if (lm_cfg == NULL)
+		return;
+
 	*(u32 *)(lm_cfg + IFCVF_LM_BASE_ADDR_LOW) =
 		log_base & IFCVF_32_BIT_MASK;
 
@@ -313,6 +325,10 @@
 	u8 *lm_cfg;
 
 	lm_cfg = hw->lm_cfg;
+
+	if (lm_cfg == NULL)
+		return;
+
 	*(u32 *)(lm_cfg + IFCVF_LM_LOGGING_CTRL) = IFCVF_LM_DISABLE;
 }
 
--

1.8.3.1