From patchwork Mon Aug 20 06:06:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Mackerras X-Patchwork-Id: 10569945 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B2EE2139B for ; Mon, 20 Aug 2018 06:07:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B59328D7E for ; Mon, 20 Aug 2018 06:07:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D25429180; Mon, 20 Aug 2018 06:07:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1DADD28D7E for ; Mon, 20 Aug 2018 06:07:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726137AbeHTJVV (ORCPT ); Mon, 20 Aug 2018 05:21:21 -0400 Received: from ozlabs.org ([203.11.71.1]:41273 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725948AbeHTJVV (ORCPT ); Mon, 20 Aug 2018 05:21:21 -0400 Received: by ozlabs.org (Postfix, from userid 1003) id 41v3HB4jH7z9s5c; Mon, 20 Aug 2018 16:07:02 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1534745222; bh=NgmmIjXzBX429adfdVFEigXMg5dXFbR2cyAYL3C3/0g=; h=Date:From:To:Cc:Subject:From; b=JpZh4ptsViKVRvdhfFMRqhsgK5GNe8SnIcAD5ene9NvMpd/UMTEwMqrdX5HYUJ5ox qcl+JcyatEMtPSBlm3AQBE1WSewW2vtQh4bwkH5fsRUMNW5gOOfdPl14qfHB5qiBVM 2xTU8VsAB7BO63Bbo+JEBHKND52bMOFqqXeWjJZm/sxbSL5VDUYQ/NCZC1oxl/5oOh cyX6PTMnSe8FSPyN3SCyW8SU9QU/HLITePXdq8DVSWy8z8vUqUi6g/kMaWR4V3nVbi JwOY0JWF5IPKCuwNFehqFuxY4z1lghOs6pH7ugdDQIS958PNdeiiuUyZ86U450P9Nq yV3ytQ2aDZ6vQ== Date: Mon, 20 Aug 2018 16:06:59 +1000 From: Paul Mackerras To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Cc: David Gibson Subject: [PATCH] KVM: PPC: Book3S HV: Don't truncate HPTE index in xlate function Message-ID: <20180820060659.GA19336@fergus> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This fixes a bug which causes guest virtual addresses to get translated to guest real addresses incorrectly when the guest is using the HPT MMU and has more than 256GB of RAM, or more specifically has a HPT larger than 2GB. This has showed up in testing as a failure of the host to emulate doorbell instructions correctly on POWER9 for HPT guests with more than 256GB of RAM. The bug is that the HPTE index in kvmppc_mmu_book3s_64_hv_xlate() is stored as an int, and in forming the HPTE address, the index gets shifted left 4 bits as an int before being signed-extended to 64 bits. The simple fix is to make the variable a long int, matching the return type of kvmppc_hv_find_lock_hpte(), which is what calculates the index. Fixes: 697d3899dcb4 ("KVM: PPC: Implement MMIO emulation support for Book3S HV guests") Signed-off-by: Paul Mackerras Reviewed-by: David Gibson --- arch/powerpc/kvm/book3s_64_mmu_hv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c index 7f3a8cf..4c08f42 100644 --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c @@ -359,7 +359,7 @@ static int kvmppc_mmu_book3s_64_hv_xlate(struct kvm_vcpu *vcpu, gva_t eaddr, unsigned long pp, key; unsigned long v, orig_v, gr; __be64 *hptep; - int index; + long int index; int virtmode = vcpu->arch.shregs.msr & (data ? MSR_DR : MSR_IR); if (kvm_is_radix(vcpu->kvm))