Skip to contentSkip to conversation

PPC: KVM: Fix BAT put

PATCH In review Alexander Graf 3 participants 4 messages Oct 5, 2012 – Oct 6, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PPC: KVM: Fix BAT put

In the sregs API, upper and lower 32bit segments of the BAT registers are swapped when doing a set. Since we need to support old kernels out there, don't bother to fix it in the kernel, but instead work around the problem in QEMU by swapping on put.

---
 target-ppc/kvm.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
target-ppc/kvm.c +5 -4
index 1975323..93c5bb7 100644
@@ -493,10 +493,11 @@ int kvm_arch_put_registers(CPUPPCState *env, int level)
 
         /* Sync BATs */
         for (i = 0; i < 8; i++) {
-            sregs.u.s.ppc32.dbat[i] = ((uint64_t)env->DBAT[1][i] << 32)
-                | env->DBAT[0][i];
-            sregs.u.s.ppc32.ibat[i] = ((uint64_t)env->IBAT[1][i] << 32)
-                | env->IBAT[0][i];
+            /* Beware. We have to swap upper and lower bits here */
+            sregs.u.s.ppc32.dbat[i] = ((uint64_t)env->DBAT[0][i] << 32)
+                | env->DBAT[1][i];
+            sregs.u.s.ppc32.ibat[i] = ((uint64_t)env->IBAT[0][i] << 32)
+                | env->IBAT[1][i];
         }
 
         ret = kvm_vcpu_ioctl(env, KVM_SET_SREGS, &sregs);
Signature · 1 line
1.6.0.2
#1 lore raw
Quoted 6 lines · Alexander Graf

In the sregs API, upper and lower 32bit segments of the BAT registers are swapped when doing a set. Since we need to support old kernels out there, don't bother to fix it in the kernel, but instead work around the problem in QEMU by swapping on put.

We should probably at least add warning comments to the kernel headers.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#2 lore raw
Quoted 10 lines · David Gibson
Quoted 6 lines · Alexander Graf

In the sregs API, upper and lower 32bit segments of the BAT registers are swapped when doing a set. Since we need to support old kernels out there, don't bother to fix it in the kernel, but instead work around the problem in QEMU by swapping on put.

We should probably at least add warning comments to the kernel headers.

I would prefer to switch all of the sregs mess to one_reg and declare it deprecated then :).

Alex

Quoted 6 lines
Signature · 5 lines
-- 
David Gibson            | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au    | minimalist, thank you.  NOT _the_ _other_
               | _way_ _around_!
http://www.ozlabs.org/~dgibson
#3 lore raw
In reply to Alexander Graf
Quoted 20 lines · Alexander Graf

In the sregs API, upper and lower 32bit segments of the BAT registers are swapped when doing a set. Since we need to support old kernels out there, don't bother to fix it in the kernel, but instead work around the problem in QEMU by swapping on put.

---
 target-ppc/kvm.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
target-ppc/kvm.c +0 -2
index 1975323..93c5bb7 100644
@@ -493,10 +493,11 @@ int kvm_arch_put_registers(CPUPPCState *env, int level)
 
         /* Sync BATs */
         for (i = 0; i < 8; i++) {
-            sregs.u.s.ppc32.dbat[i] = ((uint64_t)env->DBAT[1][i] << 32)
-                | env->DBAT[0][i];

target-ppc/kvm.c int kvm_arch_put_registers(CPUPPCState *env, int level) · line 503

Quoted 10 lines
target-ppc/kvm.c +5 -2
-            sregs.u.s.ppc32.ibat[i] = ((uint64_t)env->IBAT[1][i] << 32)
-                | env->IBAT[0][i];
+            /* Beware. We have to swap upper and lower bits here */
+            sregs.u.s.ppc32.dbat[i] = ((uint64_t)env->DBAT[0][i] << 32)
+                | env->DBAT[1][i];
+            sregs.u.s.ppc32.ibat[i] = ((uint64_t)env->IBAT[0][i] << 32)
+                | env->IBAT[1][i];
         }
 
         ret = kvm_vcpu_ioctl(env, KVM_SET_SREGS, &sregs);

Applied (actually as part of the PPC pull).

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net