Skip to contentSkip to conversation

cxl: Fix number of allocated pages in SPA

PATCH In review Christophe Lombard 3 participants 5 messages Oct 6, 2015 – Oct 7, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 cxl: Fix number of allocated pages in SPA

This moves the initialisation of the num_procs to before the SPA allocation.
The field 'num_procs' of the structure cxl_afu is not updated to the right value (maximum number of processes that can be supported by the AFU) when the pages are allocated (i.e. when cxl_alloc_spa() is called). The number of allocates pages depends on the max number of processes.

---
 drivers/misc/cxl/native.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/cxl/native.c +1 -1
index b37f2e8..d2e75c8 100644
@@ -457,6 +457,7 @@ static int activate_afu_directed(struct cxl_afu *afu)
 
 	dev_info(&afu->dev, "Activating AFU directed mode\n");
 
+	afu->num_procs = afu->max_procs_virtualised;
 	if (afu->spa == NULL) {
 		if (cxl_alloc_spa(afu))
 			return -ENOMEM;
@@ -468,7 +469,6 @@ static int activate_afu_directed(struct cxl_afu *afu)
 	cxl_p1n_write(afu, CXL_PSL_ID_An, CXL_PSL_ID_An_F | CXL_PSL_ID_An_L);
 
 	afu->current_mode = CXL_MODE_DIRECTED;
-	afu->num_procs = afu->max_procs_virtualised;
 
 	if ((rc = cxl_chardev_m_afu_add(afu)))
 		return rc;
Signature · 1 line
1.9.1
Acked-by on v2 1/1
#1 lore raw

The explanation probably still needs to be expanded more (e.g. this could cause a crash for an AFU that supports more than about a thousand processes) - see my other email in reply to v1 for more, but I'm happy for this to go in as is (but ultimately that's mpe's call).

It should also be CCd to stable, this bug was introduced before the driver was originally upstreamed, we just never hit it because all our AFUs are limited to less processes by their interrupt requirements.

Excerpts from Christophe Lombard's message of 2015-10-07 01:19:49 +1100:

Quoted 32 lines

This moves the initialisation of the num_procs to before the SPA allocation.
The field 'num_procs' of the structure cxl_afu is not updated to the right value (maximum number of processes that can be supported by the AFU) when the pages are allocated (i.e. when cxl_alloc_spa() is called). The number of allocates pages depends on the max number of processes.

---
 drivers/misc/cxl/native.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/cxl/native.c +1 -1
index b37f2e8..d2e75c8 100644
@@ -457,6 +457,7 @@ static int activate_afu_directed(struct cxl_afu *afu)
 
     dev_info(&afu->dev, "Activating AFU directed mode\n");
 
+    afu->num_procs = afu->max_procs_virtualised;
     if (afu->spa == NULL) {
         if (cxl_alloc_spa(afu))
             return -ENOMEM;
@@ -468,7 +469,6 @@ static int activate_afu_directed(struct cxl_afu *afu)
     cxl_p1n_write(afu, CXL_PSL_ID_An, CXL_PSL_ID_An_F | CXL_PSL_ID_An_L);
 
     afu->current_mode = CXL_MODE_DIRECTED;
-    afu->num_procs = afu->max_procs_virtualised;
 
     if ((rc = cxl_chardev_m_afu_add(afu)))
         return rc;
#2 lore raw
Quoted 10 lines · Ian Munsie

The explanation probably still needs to be expanded more (e.g. this could cause a crash for an AFU that supports more than about a thousand processes) - see my other email in reply to v1 for more, but I'm happy for this to go in as is (but ultimately that's mpe's call).

It should also be CCd to stable, this bug was introduced before the driver was originally upstreamed, we just never hit it because all our AFUs are limited to less processes by their interrupt requirements.

Cc stable <[email protected]>

So the driver went into 3.18, so this should be:

Cc stable <[email protected]> # 3.18+

One of you please resend with a coherent change log with all the details included.

cheers

#3 lore raw

PATCH 1/1 cxl: Fix number of allocated pages in SPA

From: Christophe Lombard <[email protected]>

The scheduled process area is currently allocated before assigning the correct maximum processes to the AFU, which will mean we only ever allocate a fixed number of pages for the scheduled process area. This will limit us to 958 processes with 2 x 64K pages. If we try to use more processes than that we'd probably overrun the buffer and corrupt memory or crash.

AFUs that require three or more interrupts per process will not be affected as they are already limited to less processes than that, but we could hit it on an AFU that requires 0, 1 or 2 interrupts per process, or when using 4K pages.

This patch moves the initialisation of the num_procs to before the SPA allocation so that enough pages will be allocated for the number of processes that the AFU supports.

---

Changes since v2:
- Expanded commit message
Changes since v1:
- Expanded commit message

 drivers/misc/cxl/native.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/cxl/native.c +1 -1
index b37f2e8..d2e75c8 100644
@@ -457,6 +457,7 @@ static int activate_afu_directed(struct cxl_afu *afu)
 
 	dev_info(&afu->dev, "Activating AFU directed mode\n");
 
+	afu->num_procs = afu->max_procs_virtualised;
 	if (afu->spa == NULL) {
 		if (cxl_alloc_spa(afu))
 			return -ENOMEM;
@@ -468,7 +469,6 @@ static int activate_afu_directed(struct cxl_afu *afu)
 	cxl_p1n_write(afu, CXL_PSL_ID_An, CXL_PSL_ID_An_F | CXL_PSL_ID_An_L);
 
 	afu->current_mode = CXL_MODE_DIRECTED;
-	afu->num_procs = afu->max_procs_virtualised;
 
 	if ((rc = cxl_chardev_m_afu_add(afu)))
 		return rc;
Signature · 1 line
2.1.4
#4 lore raw
Quoted 14 lines · Ian Munsie

From: Christophe Lombard <[email protected]>

The scheduled process area is currently allocated before assigning the correct maximum processes to the AFU, which will mean we only ever allocate a fixed number of pages for the scheduled process area. This will limit us to 958 processes with 2 x 64K pages. If we try to use more processes than that we'd probably overrun the buffer and corrupt memory or crash.

AFUs that require three or more interrupts per process will not be affected as they are already limited to less processes than that, but we could hit it on an AFU that requires 0, 1 or 2 interrupts per process, or when using 4K pages.

Quoted 7 lines

This patch moves the initialisation of the num_procs to before the SPA allocation so that enough pages will be allocated for the number of processes that the AFU supports.

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/4108efb02daa09cbb5db048a

cheers