Skip to content

Commit b59d9d2

Browse files
committed
KVM: PPC: Book3S PR: PAPR: Access RTAS in big endian
When the guest does an RTAS hypercall it keeps all RTAS variables inside a big endian data structure. To make sure we don't have to bother about endianness inside the actual RTAS handlers, let's just convert the whole structure to host endian before we call our RTAS handlers and back to big endian when we return to the guest. Signed-off-by: Alexander Graf <[email protected]>
1 parent 1692aa3 commit b59d9d2

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

arch/powerpc/kvm/book3s_rtas.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,32 @@ int kvm_vm_ioctl_rtas_define_token(struct kvm *kvm, void __user *argp)
205205
return rc;
206206
}
207207

208+
static void kvmppc_rtas_swap_endian_in(struct rtas_args *args)
209+
{
210+
#ifdef __LITTLE_ENDIAN__
211+
int i;
212+
213+
args->token = be32_to_cpu(args->token);
214+
args->nargs = be32_to_cpu(args->nargs);
215+
args->nret = be32_to_cpu(args->nret);
216+
for (i = 0; i < args->nargs; i++)
217+
args->args[i] = be32_to_cpu(args->args[i]);
218+
#endif
219+
}
220+
221+
static void kvmppc_rtas_swap_endian_out(struct rtas_args *args)
222+
{
223+
#ifdef __LITTLE_ENDIAN__
224+
int i;
225+
226+
for (i = 0; i < args->nret; i++)
227+
args->args[i] = cpu_to_be32(args->args[i]);
228+
args->token = cpu_to_be32(args->token);
229+
args->nargs = cpu_to_be32(args->nargs);
230+
args->nret = cpu_to_be32(args->nret);
231+
#endif
232+
}
233+
208234
int kvmppc_rtas_hcall(struct kvm_vcpu *vcpu)
209235
{
210236
struct rtas_token_definition *d;
@@ -223,6 +249,8 @@ int kvmppc_rtas_hcall(struct kvm_vcpu *vcpu)
223249
if (rc)
224250
goto fail;
225251

252+
kvmppc_rtas_swap_endian_in(&args);
253+
226254
/*
227255
* args->rets is a pointer into args->args. Now that we've
228256
* copied args we need to fix it up to point into our copy,
@@ -247,6 +275,7 @@ int kvmppc_rtas_hcall(struct kvm_vcpu *vcpu)
247275

248276
if (rc == 0) {
249277
args.rets = orig_rets;
278+
kvmppc_rtas_swap_endian_out(&args);
250279
rc = kvm_write_guest(vcpu->kvm, args_phys, &args, sizeof(args));
251280
if (rc)
252281
goto fail;

0 commit comments

Comments
 (0)