Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756215AbbBEAxE (ORCPT ); Wed, 4 Feb 2015 19:53:04 -0500 Received: from ozlabs.org ([103.22.144.67]:37066 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750806AbbBEAxA (ORCPT ); Wed, 4 Feb 2015 19:53:00 -0500 Date: Thu, 5 Feb 2015 11:48:46 +1100 From: David Gibson To: Alexander Graf Cc: paulus@samba.org, aik@ozlabs.ru, kvm-ppc@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCHv2] kvmppc: Implement H_LOGICAL_CI_{LOAD,STORE} in KVM Message-ID: <20150205004846.GE25675@voom.fritz.box> References: <1422942264-23886-1-git-send-email-david@gibson.dropbear.id.au> <54D239BE.2030605@suse.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="DqhR8hV3EnoxUkKN" Content-Disposition: inline In-Reply-To: <54D239BE.2030605@suse.de> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 6068 Lines: 168 --DqhR8hV3EnoxUkKN Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Feb 04, 2015 at 04:24:46PM +0100, Alexander Graf wrote: >=20 >=20 > On 03.02.15 06:44, David Gibson wrote: > > On POWER, storage caching is usually configured via the MMU - attributes > > such as cache-inhibited are stored in the TLB and the hashed page table. > >=20 > > This makes correctly performing cache inhibited IO accesses awkward when > > the MMU is turned off (real mode). Some CPU models provide special > > registers to control the cache attributes of real mode load and stores = but > > this is not at all consistent. This is a problem in particular for SLO= F, > > the firmware used on KVM guests, which runs entirely in real mode, but > > which needs to do IO to load the kernel. > >=20 > > To simplify this qemu implements two special hypercalls, H_LOGICAL_CI_L= OAD > > and H_LOGICAL_CI_STORE which simulate a cache-inhibited load or store to > > a logical address (aka guest physical address). SLOF uses these for IO. > >=20 > > However, because these are implemented within qemu, not the host kernel, > > these bypass any IO devices emulated within KVM itself. The simplest w= ay > > to see this problem is to attempt to boot a KVM guest from a virtio-blk > > device with iothread / dataplane enabled. The iothread code relies on = an > > in kernel implementation of the virtio queue notification, which is not > > triggered by the IO hcalls, and so the guest will stall in SLOF unable = to > > load the guest OS. > >=20 > > This patch addresses this by providing in-kernel implementations of the > > 2 hypercalls, which correctly scan the KVM IO bus. Any access to an > > address not handled by the KVM IO bus will cause a VM exit, hitting the > > qemu implementation as before. > >=20 > > Note that a userspace change is also required, in order to enable these > > new hcall implementations with KVM_CAP_PPC_ENABLE_HCALL. > >=20 > > Signed-off-by: David Gibson > > --- > > arch/powerpc/include/asm/kvm_book3s.h | 3 ++ > > arch/powerpc/kvm/book3s.c | 76 +++++++++++++++++++++++++++= ++++++++ > > arch/powerpc/kvm/book3s_hv.c | 12 ++++++ > > arch/powerpc/kvm/book3s_pr_papr.c | 28 +++++++++++++ > > 4 files changed, 119 insertions(+) > >=20 > > v2: > > - Removed some debugging printk()s that were accidentally left in > > - Fix endianness; like all PAPR hypercalls, these should always act > > big-endian, even if the guest is little-endian (in practice this > > makes no difference, since the only user is SLOF, which is always > > big-endian) > >=20 > > diff --git a/arch/powerpc/include/asm/kvm_book3s.h b/arch/powerpc/inclu= de/asm/kvm_book3s.h > > index 942c7b1..578e550 100644 > > --- a/arch/powerpc/include/asm/kvm_book3s.h > > +++ b/arch/powerpc/include/asm/kvm_book3s.h > > @@ -292,6 +292,9 @@ static inline bool kvmppc_supports_magic_page(struc= t kvm_vcpu *vcpu) > > return !is_kvmppc_hv_enabled(vcpu->kvm); > > } > > =20 > > +extern int kvmppc_h_logical_ci_load(struct kvm_vcpu *vcpu); > > +extern int kvmppc_h_logical_ci_store(struct kvm_vcpu *vcpu); > > + > > /* Magic register values loaded into r3 and r4 before the 'sc' assembly > > * instruction for the OSI hypercalls */ > > #define OSI_SC_MAGIC_R3 0x113724FA > > diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c > > index 888bf46..7b51492 100644 > > --- a/arch/powerpc/kvm/book3s.c > > +++ b/arch/powerpc/kvm/book3s.c > > @@ -820,6 +820,82 @@ void kvmppc_core_destroy_vm(struct kvm *kvm) > > #endif > > } > > =20 > > +int kvmppc_h_logical_ci_load(struct kvm_vcpu *vcpu) > > +{ > > + unsigned long size =3D kvmppc_get_gpr(vcpu, 4); > > + unsigned long addr =3D kvmppc_get_gpr(vcpu, 5); > > + u64 buf; > > + int ret; > > + > > + if (!is_power_of_2(size) || (size > sizeof(buf))) > > + return H_TOO_HARD; > > + > > + ret =3D kvm_io_bus_read(vcpu->kvm, KVM_MMIO_BUS, addr, size, &buf); > > + if (ret !=3D 0) > > + return H_TOO_HARD; > > + > > + switch (size) { > > + case 1: > > + kvmppc_set_gpr(vcpu, 4, *(u8 *)&buf); > > + break; > > + > > + case 2: > > + kvmppc_set_gpr(vcpu, 4, be16_to_cpu(*(u16 *)&buf)); > > + break; > > + > > + case 4: > > + kvmppc_set_gpr(vcpu, 4, be32_to_cpu(*(u32 *)&buf)); > > + break; > > + > > + case 8: > > + kvmppc_set_gpr(vcpu, 4, be64_to_cpu(*(u64 *)&buf)); >=20 > Shouldn't these casts be __be types? Ah, yes they should. > > + break; > > + > > + default: > > + BUG(); > > + } > > + > > + return H_SUCCESS; > > +} > > +EXPORT_SYMBOL_GPL(kvmppc_h_logical_ci_load); /* For use by the kvm-pr = module */ >=20 > No need for the comment. Ok. --=20 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 --DqhR8hV3EnoxUkKN Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJU0r3uAAoJEGw4ysog2bOSgxgQAOTFUP2+ob2/6PeYDB/Jp2kU eh6CFGejNueR93uakyaV+hKSGomz2MG6S7sIHsRi48PjHDNUu12fGPjsv5tPZfo0 kEpSbhasfdhE1IkW3t2TtFtkO/g1INwHYVUC1sqzI3GCkopd+s/lWFAPrZu/movf pGeTkGx3i7V5ir437xfE+cXJrIgDGsQpx7osHiogzqDQwRXbTn8fjLmk2e88Zu3v mxnmLl0Pw01/nYLxxYa3I2VCfV1Ei0ZWTemuvhJTLZgV1j9eYhHUZxqFkumrMb9Q C8b/G7YSD986ddbrtpGR8tlmh3IocHOQgTnIekyKC7FpQh9uXCGZ9NpCY4FE/sqg FJvrOvmRMLCqKoMtBeggOQ+RRYnxMjbPniRAvkPZKLyNOjLYW2BAsxygX4q2fvr5 SbmIa0LIY6/+KRKghgCT8kP2cGFQSBkop57w1IP4fsIM+oB3LxEyk5o38r4THAAh B8Mcddgr7pudMgvv9yYo60J28/UbCGXRwr01PL8OVFtXrazDziXhvexkRrNc0wyn hdxXKzP+X1wkw/1Wr8r2D6KsYUj0skhgh3t/hkjrJ6bDj3FLcidGL/Bdb7+q0Ljo 9FpvWcBbmA5the9v9FmqwKN35qihdRLod824R2Y7iWusFtWct1MronIvymIx3xKG cJAa/IpUfSFtrz0bx7hg =lypr -----END PGP SIGNATURE----- --DqhR8hV3EnoxUkKN-- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/