Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753959AbbDUHIh (ORCPT ); Tue, 21 Apr 2015 03:08:37 -0400 Received: from ozlabs.org ([103.22.144.67]:56150 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751538AbbDUHId (ORCPT ); Tue, 21 Apr 2015 03:08:33 -0400 Date: Tue, 21 Apr 2015 16:51:21 +1000 From: David Gibson To: Thomas Huth Cc: agraf@suse.de, michael@ellerman.id.au, benh@kernel.crashing.org, aik@ozlabs.ru, kvm-ppc@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCHv4] kvmppc: Implement H_LOGICAL_CI_{LOAD,STORE} in KVM Message-ID: <20150421065121.GE31815@voom.redhat.com> References: <1429576911-6076-1-git-send-email-david@gibson.dropbear.id.au> <20150421083702.23ab1462@thh440s> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="J4XPiPrVK1ev6Sgr" Content-Disposition: inline In-Reply-To: <20150421083702.23ab1462@thh440s> 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: 5625 Lines: 157 --J4XPiPrVK1ev6Sgr Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Apr 21, 2015 at 08:37:02AM +0200, Thomas Huth wrote: > Am Tue, 21 Apr 2015 10:41:51 +1000 > schrieb David Gibson : >=20 > > 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(+) > ... > > diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c > > index cfbcdc6..453a8a4 100644 > > --- a/arch/powerpc/kvm/book3s.c > > +++ b/arch/powerpc/kvm/book3s.c > > @@ -821,6 +821,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_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; > > + >=20 > Most of the code in book3s.c seems not to use a empty line after a > "break;", so may I suggest to remove these empty lines here, too, to > keep the coding style a little bit more consistent? I don't think it's worth respinning just for that. > > + case 2: > > + kvmppc_set_gpr(vcpu, 4, be16_to_cpu(*(__be16 *)&buf)); > > + break; > > + > > + case 4: > > + kvmppc_set_gpr(vcpu, 4, be32_to_cpu(*(__be32 *)&buf)); > > + break; > > + > > + case 8: > > + kvmppc_set_gpr(vcpu, 4, be64_to_cpu(*(__be64 *)&buf)); > > + break; > > + > > + default: > > + BUG(); >=20 > If I got the code right, a malicious guest could easily trigger this > BUG() statement, couldn't it? ... so a BUG() is maybe not the right > thing to do here. Would it be appropriate to return an error value to > the guest instead? Actually no - the test at the top of the function for is_power_of_2(size) etc. catches this safely before we get here. The BUG() is just paranoia. >=20 > > + } > > + > > + return H_SUCCESS; > > +} > > +EXPORT_SYMBOL_GPL(kvmppc_h_logical_ci_load); >=20 > Thomas >=20 --=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 --J4XPiPrVK1ev6Sgr Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJVNfNpAAoJEGw4ysog2bOS5pQQAKXp2GB2hjbpxiPv6yrMDMxO G0mjlK+1MwZJrAyvw1/wEoUVlcHUm2Hhk6G1dR2Z0xRmP0pdFb49fYZ4RPyUQCJQ a623fR5OY+8uGKJysC4DDNXVxBR5tXOOGjE0PdvvVPwqrepF9sB3RfC+2R+xOitD ev89DkyVhUc8i8ieNozTFVaFmIRm8JdSkpTS54oX51X057JeJjZ/Jw2CxSLKsXyJ nlwTkatQS9WQ0KTzTV7W3RzAwNQwjaeRoLNC2b6KZAyxmAsfvlHWIrqqGwDRX2A0 iy4gYF2Mvv8DT5elFAViTz8qAOCNtkx67hoCY9fj9D9T3va9lLqxgOd8OvVRYe+p r/ZWVKCuDAooY17X4NxcgfRrdLkpxMpdGslmMGWemH0ZYwIKZCDyAQCV/a4i29gZ gp/nc8Hh1yDLUzSSmG6Cv/hjBQn913iL5aGrpnNwdkxODEisZ+gLrgs6EgmWtogT W9TBOkaH8Ng1bcnccLpB0w5MdWXAmZ14O5hXDh1CyY+kUEw10iJl8099khadxfZb gVmgtAjWu2F1aImgezRByDUZawLlTe1XULtUqBS7Q5/8H1pOqHlmb0h+dCuEjDiP aifgnY3cobunge1PsPCygZJDjes96BYPgtKxj9e7ESxUbVwjtcIf30c6kXx+TrnQ bthiVAdKDmSdbtFwwIJL =tpry -----END PGP SIGNATURE----- --J4XPiPrVK1ev6Sgr-- -- 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/