mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 20:06:24 +00:00
KVM: arm64: Handle endianness in read helper for emulated PTW
Implementing FEAT_HAFDBS means adding another descriptor accessor that needs to deal with the guest-configured endianness. Prepare by moving the endianness handling into the read accessor and out of the main body of the S1/S2 PTWs. Reviewed-by: Marc Zyngier <maz@kernel.org> Tested-by: Marc Zyngier <maz@kernel.org> Link: https://msgid.link/20251124190158.177318-9-oupton@kernel.org Signed-off-by: Oliver Upton <oupton@kernel.org>
This commit is contained in:
@@ -362,6 +362,24 @@ transfault:
|
|||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int kvm_read_s1_desc(struct kvm_vcpu *vcpu, u64 pa, u64 *desc,
|
||||||
|
struct s1_walk_info *wi)
|
||||||
|
{
|
||||||
|
u64 val;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
r = kvm_read_guest(vcpu->kvm, pa, &val, sizeof(val));
|
||||||
|
if (r)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
if (wi->be)
|
||||||
|
*desc = be64_to_cpu((__force __be64)val);
|
||||||
|
else
|
||||||
|
*desc = le64_to_cpu((__force __le64)val);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int walk_s1(struct kvm_vcpu *vcpu, struct s1_walk_info *wi,
|
static int walk_s1(struct kvm_vcpu *vcpu, struct s1_walk_info *wi,
|
||||||
struct s1_walk_result *wr, u64 va)
|
struct s1_walk_result *wr, u64 va)
|
||||||
{
|
{
|
||||||
@@ -414,17 +432,12 @@ static int walk_s1(struct kvm_vcpu *vcpu, struct s1_walk_info *wi,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = kvm_read_guest(vcpu->kvm, ipa, &desc, sizeof(desc));
|
ret = kvm_read_s1_desc(vcpu, ipa, &desc, wi);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fail_s1_walk(wr, ESR_ELx_FSC_SEA_TTW(level), false);
|
fail_s1_walk(wr, ESR_ELx_FSC_SEA_TTW(level), false);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wi->be)
|
|
||||||
desc = be64_to_cpu((__force __be64)desc);
|
|
||||||
else
|
|
||||||
desc = le64_to_cpu((__force __le64)desc);
|
|
||||||
|
|
||||||
/* Invalid descriptor */
|
/* Invalid descriptor */
|
||||||
if (!(desc & BIT(0)))
|
if (!(desc & BIT(0)))
|
||||||
goto transfault;
|
goto transfault;
|
||||||
|
|||||||
@@ -197,9 +197,26 @@ static int check_output_size(struct s2_walk_info *wi, phys_addr_t output)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int read_guest_s2_desc(struct kvm_vcpu *vcpu, phys_addr_t pa, u64 *desc)
|
static int read_guest_s2_desc(struct kvm_vcpu *vcpu, phys_addr_t pa, u64 *desc,
|
||||||
|
struct s2_walk_info *wi)
|
||||||
{
|
{
|
||||||
return kvm_read_guest(vcpu->kvm, pa, desc, sizeof(*desc));
|
u64 val;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
r = kvm_read_guest(vcpu->kvm, pa, &val, sizeof(val));
|
||||||
|
if (r)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Handle reversedescriptors if endianness differs between the
|
||||||
|
* host and the guest hypervisor.
|
||||||
|
*/
|
||||||
|
if (wi->be)
|
||||||
|
*desc = be64_to_cpu((__force __be64)val);
|
||||||
|
else
|
||||||
|
*desc = le64_to_cpu((__force __le64)val);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -260,19 +277,10 @@ static int walk_nested_s2_pgd(struct kvm_vcpu *vcpu, phys_addr_t ipa,
|
|||||||
>> (addr_bottom - 3);
|
>> (addr_bottom - 3);
|
||||||
|
|
||||||
paddr = base_addr | index;
|
paddr = base_addr | index;
|
||||||
ret = read_guest_s2_desc(vcpu, paddr, &desc);
|
ret = read_guest_s2_desc(vcpu, paddr, &desc, wi);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/*
|
|
||||||
* Handle reversedescriptors if endianness differs between the
|
|
||||||
* host and the guest hypervisor.
|
|
||||||
*/
|
|
||||||
if (wi->be)
|
|
||||||
desc = be64_to_cpu((__force __be64)desc);
|
|
||||||
else
|
|
||||||
desc = le64_to_cpu((__force __le64)desc);
|
|
||||||
|
|
||||||
/* Check for valid descriptor at this point */
|
/* Check for valid descriptor at this point */
|
||||||
if (!(desc & 1) || ((desc & 3) == 1 && level == 3)) {
|
if (!(desc & 1) || ((desc & 3) == 1 && level == 3)) {
|
||||||
out->esr = compute_fsc(level, ESR_ELx_FSC_FAULT);
|
out->esr = compute_fsc(level, ESR_ELx_FSC_FAULT);
|
||||||
|
|||||||
Reference in New Issue
Block a user