Patchwork [v5,2/6] KVM: PPC: Book3S: add helper routines to detect endian

login
register
mail settings
Submitter Cédric Le Goater
Date Nov. 5, 2013, 5:22 p.m.
Message ID <1383672128-26795-3-git-send-email-clg@fr.ibm.com>
Download mbox | patch
Permalink /patch/288591/
State New
Headers show

Comments

Cédric Le Goater - Nov. 5, 2013, 5:22 p.m.
They will be used to decide whether to byte-swap or not. When Little
Endian host kernels come, these routines will need to be changed
accordingly.

Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
---
 arch/powerpc/include/asm/kvm_book3s.h |   10 ++++++++++
 1 file changed, 10 insertions(+)
Alexander Graf - Jan. 2, 2014, 8:05 p.m.
On 05.11.2013, at 18:22, Cédric Le Goater <clg@fr.ibm.com> wrote:

> They will be used to decide whether to byte-swap or not. When Little
> Endian host kernels come, these routines will need to be changed
> accordingly.
> 
> Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
> ---
> arch/powerpc/include/asm/kvm_book3s.h |   10 ++++++++++
> 1 file changed, 10 insertions(+)
> 
> diff --git a/arch/powerpc/include/asm/kvm_book3s.h b/arch/powerpc/include/asm/kvm_book3s.h
> index d11c089..22ec875 100644
> --- a/arch/powerpc/include/asm/kvm_book3s.h
> +++ b/arch/powerpc/include/asm/kvm_book3s.h
> @@ -270,6 +270,16 @@ static inline ulong kvmppc_get_pc(struct kvm_vcpu *vcpu)
> 	return vcpu->arch.pc;
> }
> 
> +static inline bool kvmppc_need_byteswap(struct kvm_vcpu *vcpu)
> +{
> +	return vcpu->arch.shared->msr & MSR_LE;
> +}
> +
> +static inline bool kvmppc_is_bigendian(struct kvm_vcpu *vcpu)
> +{
> +	return !kvmppc_need_byteswap(vcpu);

This is logically reversed. kvmppc_need_byteswap should check kvmppc_is_bigendian(), not the other way around.


Alex

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Cédric Le Goater - Jan. 8, 2014, 5:22 p.m.
Hi Alex,

On 01/02/2014 09:05 PM, Alexander Graf wrote:
> 
> On 05.11.2013, at 18:22, Cédric Le Goater <clg@fr.ibm.com> wrote:
> 
>> They will be used to decide whether to byte-swap or not. When Little
>> Endian host kernels come, these routines will need to be changed
>> accordingly.
>>
>> Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
>> ---
>> arch/powerpc/include/asm/kvm_book3s.h |   10 ++++++++++
>> 1 file changed, 10 insertions(+)
>>
>> diff --git a/arch/powerpc/include/asm/kvm_book3s.h b/arch/powerpc/include/asm/kvm_book3s.h
>> index d11c089..22ec875 100644
>> --- a/arch/powerpc/include/asm/kvm_book3s.h
>> +++ b/arch/powerpc/include/asm/kvm_book3s.h
>> @@ -270,6 +270,16 @@ static inline ulong kvmppc_get_pc(struct kvm_vcpu *vcpu)
>> 	return vcpu->arch.pc;
>> }
>>
>> +static inline bool kvmppc_need_byteswap(struct kvm_vcpu *vcpu)
>> +{
>> +	return vcpu->arch.shared->msr & MSR_LE;
>> +}
>> +
>> +static inline bool kvmppc_is_bigendian(struct kvm_vcpu *vcpu)
>> +{
>> +	return !kvmppc_need_byteswap(vcpu);
> 
> This is logically reversed. kvmppc_need_byteswap should check kvmppc_is_bigendian(), 
> not the other way around.
> 
 
I think we should get rid of kvmppc_is_bigendian(). 

As you noted in a subsequent email, it ends up returning true when run 
for "little endian guests on little endian hosts", which is awkward and 
the way it is used in kvmppc_handle_load() and kvmppc_handle_store()
can be improved.

I will give it a try taking into account the other comments you made. 

C.

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/arch/powerpc/include/asm/kvm_book3s.h b/arch/powerpc/include/asm/kvm_book3s.h
index d11c089..22ec875 100644
--- a/arch/powerpc/include/asm/kvm_book3s.h
+++ b/arch/powerpc/include/asm/kvm_book3s.h
@@ -270,6 +270,16 @@  static inline ulong kvmppc_get_pc(struct kvm_vcpu *vcpu)
 	return vcpu->arch.pc;
 }
 
+static inline bool kvmppc_need_byteswap(struct kvm_vcpu *vcpu)
+{
+	return vcpu->arch.shared->msr & MSR_LE;
+}
+
+static inline bool kvmppc_is_bigendian(struct kvm_vcpu *vcpu)
+{
+	return !kvmppc_need_byteswap(vcpu);
+}
+
 static inline int kvmppc_ld32(struct kvm_vcpu *vcpu, ulong *eaddr,
 			      u32 *ptr, bool data)
 {