Skip to contentSkip to conversation

powerpc/pseries/vas: Pass hw_cpu_id to node associativity HCALL

PATCH Applied Haren Myneni 5 participants 5 messages Sep 29, 2022 – Oct 4, 2022 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/pseries/vas: Pass hw_cpu_id to node associativity HCALL

Generally the hypervisor decides to allocate a window on different VAS instances. But if the user space wishes to allocate on the current VAS instance where the process is executing, the kernel has to pass associativity domain IDs to allocate VAS window HCALL. To determine the associativity domain IDs for the current CPU, passing smp_processor_id() to node associativity HCALL which may return H_P2 (-55) error during DLPAR CPU event.

This patch fixes this issue by passing hard_smp_processor_id() with VPHN_FLAG_VCPU flag (PAPR 14.11.6.1 H_HOME_NODE_ASSOCIATIVITY).

---
 arch/powerpc/platforms/pseries/vas.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/platforms/pseries/vas.c +1 -1
index fe33bdb620d5..533026fd1f40 100644
@@ -348,7 +348,7 @@ static struct vas_window *vas_allocate_window(int vas_id, u64 flags,
 		 * So no unpacking needs to be done.
 		 */
 		rc = plpar_hcall9(H_HOME_NODE_ASSOCIATIVITY, domain,
-				  VPHN_FLAG_VCPU, smp_processor_id());
+				  VPHN_FLAG_VCPU, hard_smp_processor_id());
 		if (rc != H_SUCCESS) {
 			pr_err("H_HOME_NODE_ASSOCIATIVITY error: %d\n", rc);
 			goto out;
Signature · 1 line
2.26.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 21 lines · Haren Myneni

Generally the hypervisor decides to allocate a window on different VAS instances. But if the user space wishes to allocate on the current VAS instance where the process is executing, the kernel has to pass associativity domain IDs to allocate VAS window HCALL. To determine the associativity domain IDs for the current CPU, passing smp_processor_id() to node associativity HCALL which may return H_P2 (-55) error during DLPAR CPU event.

This patch fixes this issue by passing hard_smp_processor_id() with VPHN_FLAG_VCPU flag (PAPR 14.11.6.1 H_HOME_NODE_ASSOCIATIVITY).

---
 arch/powerpc/platforms/pseries/vas.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/platforms/pseries/vas.c +0 -0
index fe33bdb620d5..533026fd1f40 100644

arch/powerpc/platforms/pseries/vas.c static struct vas_window *vas_allocate_window(int vas_id, u64 flags, · line 354

Quoted 8 lines
arch/powerpc/platforms/pseries/vas.c +1 -1
@@ -348,7 +348,7 @@ static struct vas_window *vas_allocate_window(int vas_id, u64 flags,
 		 * So no unpacking needs to be done.
 		 */
 		rc = plpar_hcall9(H_HOME_NODE_ASSOCIATIVITY, domain,
-				  VPHN_FLAG_VCPU, smp_processor_id());
+				  VPHN_FLAG_VCPU, hard_smp_processor_id());
 		if (rc != H_SUCCESS) {
 			pr_err("H_HOME_NODE_ASSOCIATIVITY error: %d\n", rc);
 			goto out;

Yes, it is always wrong to pass Linux CPU numbers to the hypervisor, which has its own numbering for hardware threads. It usually coincides with Linux's numbering in practice, which tends to hide bugs like this.

#2 lore raw

Hello,

Quoted 35 lines · Nathan Lynch
Quoted 21 lines · Haren Myneni

Generally the hypervisor decides to allocate a window on different VAS instances. But if the user space wishes to allocate on the current VAS instance where the process is executing, the kernel has to pass associativity domain IDs to allocate VAS window HCALL. To determine the associativity domain IDs for the current CPU, passing smp_processor_id() to node associativity HCALL which may return H_P2 (-55) error during DLPAR CPU event.

This patch fixes this issue by passing hard_smp_processor_id() with VPHN_FLAG_VCPU flag (PAPR 14.11.6.1 H_HOME_NODE_ASSOCIATIVITY).

---
 arch/powerpc/platforms/pseries/vas.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/platforms/pseries/vas.c +0 -0
index fe33bdb620d5..533026fd1f40 100644

arch/powerpc/platforms/pseries/vas.c static struct vas_window *vas_allocate_window(int vas_id, u64 flags, · line 354

Quoted 8 lines
arch/powerpc/platforms/pseries/vas.c +1 -1
@@ -348,7 +348,7 @@ static struct vas_window *vas_allocate_window(int vas_id, u64 flags,
 		 * So no unpacking needs to be done.
 		 */
 		rc = plpar_hcall9(H_HOME_NODE_ASSOCIATIVITY, domain,
-				  VPHN_FLAG_VCPU, smp_processor_id());
+				  VPHN_FLAG_VCPU, hard_smp_processor_id());
 		if (rc != H_SUCCESS) {
 			pr_err("H_HOME_NODE_ASSOCIATIVITY error: %d\n", rc);
 			goto out;

Yes, it is always wrong to pass Linux CPU numbers to the hypervisor, which has its own numbering for hardware threads. It usually coincides with Linux's numbering in practice, which tends to hide bugs like this.

Quoted 1 line

This is the code that introduces the problem, right?

Fixes b22f2d88e435 ("powerpc/pseries/vas: Integrate API with open/close windows")

Thanks

Michal

#3 lore raw
Quoted 36 lines · Michal Suchánek
Quoted 35 lines · Nathan Lynch
Quoted 21 lines · Haren Myneni

Generally the hypervisor decides to allocate a window on different VAS instances. But if the user space wishes to allocate on the current VAS instance where the process is executing, the kernel has to pass associativity domain IDs to allocate VAS window HCALL. To determine the associativity domain IDs for the current CPU, passing smp_processor_id() to node associativity HCALL which may return H_P2 (-55) error during DLPAR CPU event.

This patch fixes this issue by passing hard_smp_processor_id() with VPHN_FLAG_VCPU flag (PAPR 14.11.6.1 H_HOME_NODE_ASSOCIATIVITY).

---
 arch/powerpc/platforms/pseries/vas.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/platforms/pseries/vas.c +0 -0
index fe33bdb620d5..533026fd1f40 100644

arch/powerpc/platforms/pseries/vas.c static struct vas_window *vas_allocate_window(int vas_id, u64 flags, · line 354

Quoted 8 lines
arch/powerpc/platforms/pseries/vas.c +1 -1
@@ -348,7 +348,7 @@ static struct vas_window *vas_allocate_window(int vas_id, u64 flags,
 		 * So no unpacking needs to be done.
 		 */
 		rc = plpar_hcall9(H_HOME_NODE_ASSOCIATIVITY, domain,
-				  VPHN_FLAG_VCPU, smp_processor_id());
+				  VPHN_FLAG_VCPU, hard_smp_processor_id());
 		if (rc != H_SUCCESS) {
 			pr_err("H_HOME_NODE_ASSOCIATIVITY error: %d\n", rc);
 			goto out;

Yes, it is always wrong to pass Linux CPU numbers to the hypervisor, which has its own numbering for hardware threads. It usually coincides with Linux's numbering in practice, which tends to hide bugs like this.

Quoted 5 lines
Quoted 1 line

This is the code that introduces the problem, right?

Fixes b22f2d88e435 ("powerpc/pseries/vas: Integrate API with open/close windows")

Yeah, I tagged it when applying. Thanks.

cheers

#4 lore raw
In reply to Haren Myneni
Quoted 9 lines · Haren Myneni

Generally the hypervisor decides to allocate a window on different VAS instances. But if the user space wishes to allocate on the current VAS instance where the process is executing, the kernel has to pass associativity domain IDs to allocate VAS window HCALL. To determine the associativity domain IDs for the current CPU, passing smp_processor_id() to node associativity HCALL which may return H_P2 (-55) error during DLPAR CPU event.

[...]

Applied to powerpc/next.

[1/1] powerpc/pseries/vas: Pass hw_cpu_id to node associativity HCALL

      https://git.kernel.org/powerpc/c/f3e5d9e53e74d77e711a2c90a91a8b0836a9e0b3

cheers