From: Paul Mackerras Subject: Re: [PATCH v2 3/3] KVM: PPC: Book3S: MMIO emulation support for little endian guests Date: Wed, 9 Oct 2013 10:31:23 +1100 Message-ID: <20131008233123.GB17420@iris.ozlabs.ibm.com> References: <1381241531-27940-1-git-send-email-clg@fr.ibm.com> <1381241531-27940-4-git-send-email-clg@fr.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: =?iso-8859-1?Q?C=E9dric?= Le Goater , kvm-ppc@vger.kernel.org, "kvm@vger.kernel.org mailing list" To: Alexander Graf Return-path: Content-Disposition: inline In-Reply-To: Sender: kvm-ppc-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On Tue, Oct 08, 2013 at 04:25:31PM +0200, Alexander Graf wrote: >=20 > On 08.10.2013, at 16:12, C=E9dric Le Goater wrote: >=20 > > MMIO emulation reads the last instruction executed by the guest > > and then emulates. If the guest is running in Little Endian mode, > > the instruction needs to be byte-swapped before being emulated. > >=20 > > This patch stores the last instruction in the endian order of the > > host, primarily doing a byte-swap if needed. The common code > > which fetches 'last_inst' uses a helper routine kvmppc_need_byteswa= p(). > > and the exit paths for the Book3S PV and HR guests use their own > > version in assembly. > >=20 > > Finally, the meaning of the 'is_bigendian' argument of the > > routines kvmppc_handle_load() of kvmppc_handle_store() is > > slightly changed to represent an eventual reverse operation. This > > is used in conjunction with kvmppc_is_bigendian() to determine if > > the instruction being emulated should be byte-swapped. > >=20 > > Signed-off-by: C=E9dric Le Goater > > --- > >=20 > > Changes in v2: > >=20 > > - replaced rldicl. by andi. to test the MSR_LE bit in the guest > > exit paths. (Paul Mackerras) > >=20 > > - moved the byte swapping logic to kvmppc_handle_load() and=20 > > kvmppc_handle_load() by changing the is_bigendian parameter > > meaning. (Paul Mackerras) > >=20 > > arch/powerpc/include/asm/kvm_book3s.h | 9 ++++++++- > > arch/powerpc/include/asm/kvm_ppc.h | 10 +++++----- > > arch/powerpc/kvm/book3s_hv_rmhandlers.S | 11 +++++++++++ > > arch/powerpc/kvm/book3s_segment.S | 10 ++++++++++ > > arch/powerpc/kvm/emulate.c | 1 - > > arch/powerpc/kvm/powerpc.c | 16 ++++++++++++---- > > 6 files changed, 46 insertions(+), 11 deletions(-) > >=20 > > diff --git a/arch/powerpc/include/asm/kvm_book3s.h b/arch/powerpc/i= nclude/asm/kvm_book3s.h > > index 4ee6c66..f043e62 100644 > > --- a/arch/powerpc/include/asm/kvm_book3s.h > > +++ b/arch/powerpc/include/asm/kvm_book3s.h > > @@ -289,7 +289,14 @@ static inline int kvmppc_ld32(struct kvm_vcpu = *vcpu, ulong *eaddr, > > static inline int kvmppc_ld_inst(struct kvm_vcpu *vcpu, ulong *eadd= r, > > u32 *inst) > > { > > - return kvmppc_ld32(vcpu, eaddr, inst, false); > > + int ret; > > + > > + ret =3D kvmppc_ld32(vcpu, eaddr, inst, false); > > + > > + if (kvmppc_need_byteswap(vcpu)) > > + *inst =3D swab32(*inst); >=20 > This logic wants to live in kvmppc_ld32(), no? Every 32bit access is = going to need a byteswap, regardless of whether it's an instruction or = not. True, until we get to POWER8 with its split little-endian support, where instructions and data can have different endianness... Paul.