From patchwork Fri Mar 2 04:49:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Mackerras X-Patchwork-Id: 10253391 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 11119603ED for ; Fri, 2 Mar 2018 04:49:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F3B72287FD for ; Fri, 2 Mar 2018 04:49:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E86BF28800; Fri, 2 Mar 2018 04:49:58 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, 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 8CF2B287FE for ; Fri, 2 Mar 2018 04:49:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1164961AbeCBEtv (ORCPT ); Thu, 1 Mar 2018 23:49:51 -0500 Received: from ozlabs.org ([103.22.144.67]:32885 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1164925AbeCBEtu (ORCPT ); Thu, 1 Mar 2018 23:49:50 -0500 Received: by ozlabs.org (Postfix, from userid 1003) id 3zsxg055yyz9sWB; Fri, 2 Mar 2018 15:49:48 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1519966188; bh=WPxoILcbm5aSKsgdy22eyXbw9V8zZahiMH9sXAwU9q8=; h=Date:From:To:Subject:From; b=GAp4+hjNjNogaytICXCUX21vwJoV2koMFaWBJ729J+n+qW3nLkFiNW0RrVMDLLoiL /rdhcr6lPSTW+J2NPAyJynQFDBZcwXWLOUsSrsl0iG5THXRjWHwd0p/KRcNChSS9m9 pvsUHdFWjRGCp5zt9Av/60q7nlPowgcvoEk2viYNKZnYIWcwrqag2B2vpabPCJyvip mzLx10RlYbiQy7MCqZlB+K4sSrqCXRwT9Uka+CXwLWgXbx+WMz1If5x9Y5I+kd34W/ CI610VRVR2ff5PW77yJ0mMYDwY3eTeRuLBLR1ZHuj8IQNCXQNZ74Ed9/4lNXVfcMNT D08Iur7oTRKfQ== Date: Fri, 2 Mar 2018 15:49:43 +1100 From: Paul Mackerras To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Subject: [PATCH] KVM: PPC: Book3S HV: Fix VRMA initialization with 2MB or 1GB memory backing Message-ID: <20180302044943.lnpc3uzijjxu7zax@oak.ozlabs.ibm.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The current code for initializing the VRMA (virtual real memory area) for HPT guests requires the page size of the backing memory to be one of 4kB, 64kB or 16MB. With a radix host we have the possibility that the backing memory page size can be 2MB or 1GB. In these cases, if the guest switches to HPT mode, KVM will not initialize the VRMA and the guest will fail to run. In fact it is not necessary that the VRMA page size is the same as the backing memory page size; any VRMA page size less than or equal to the backing memory page size is acceptable. Therefore we now choose the largest page size out of the set {4k, 64k, 16M} which is not larger than the backing memory page size. Signed-off-by: Paul Mackerras --- arch/powerpc/kvm/book3s_hv.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index 89707354c2ef..b4a538b29da5 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -3656,15 +3656,17 @@ static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu) goto up_out; psize = vma_kernel_pagesize(vma); - porder = __ilog2(psize); up_read(¤t->mm->mmap_sem); /* We can handle 4k, 64k or 16M pages in the VRMA */ - err = -EINVAL; - if (!(psize == 0x1000 || psize == 0x10000 || - psize == 0x1000000)) - goto out_srcu; + if (psize >= 0x1000000) + psize = 0x1000000; + else if (psize >= 0x10000) + psize = 0x10000; + else + psize = 0x1000; + porder = __ilog2(psize); senc = slb_pgsize_encoding(psize); kvm->arch.vrma_slb_v = senc | SLB_VSID_B_1T |