From patchwork Fri Dec 7 03:43:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suraj Jitindar Singh X-Patchwork-Id: 10717407 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 9F3B415A6 for ; Fri, 7 Dec 2018 03:44:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 908512EDEC for ; Fri, 7 Dec 2018 03:44:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 84E8B2EDF2; Fri, 7 Dec 2018 03:44:05 +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,FREEMAIL_FROM,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 14B0D2EDEC for ; Fri, 7 Dec 2018 03:44:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726114AbeLGDoE (ORCPT ); Thu, 6 Dec 2018 22:44:04 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:45359 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726087AbeLGDoE (ORCPT ); Thu, 6 Dec 2018 22:44:04 -0500 Received: by mail-pg1-f193.google.com with SMTP id y4so1077336pgc.12; Thu, 06 Dec 2018 19:44:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=v/8AAl8q/xQgZCOCCKR0EHdYpuAx8C+FNvDhIEvGom4=; b=HINwW3BNw5+WJjwf5Ig5s4PQLnfDvFapWZmWWo/nwyc4uen1+FwcTi7+HXOKz5O1Ip wFayGtBavJyL+xyWM5cPl2N0ZjoJDwGou3B/yKD1Kr//GIsjGH+kwi8Lwg6BnPXIl+6a 48I1jjCx3kQuoZhamArTVvTvQSbABM5QVPHAXbl4OSGEuxRNcw3ZHDemod2Pv1jxkdKl YwRH56HvOE+GhnTdkEXaKdk1UkMRBrY2/oZHTjWYQGCEDt192TN7v1qAg520hI9EpMPi FrNx/a2aM1XJM9V95OShdsGO9zHisH4q1J9RraJFnnzWtFyOqNFdy/rmszZEhjLoGXFr 4utA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=v/8AAl8q/xQgZCOCCKR0EHdYpuAx8C+FNvDhIEvGom4=; b=XI6b8hISP1opJxCK+nZxhRL+ydnMjcE3s8lMLDv63MW5CN9iLZ1wFMo5MH67marTlE xdgOE07r5h6YYaKLcHTolVmHFhaoR6syVkX1b45ioagpNPpYl1gBgenZVEY0Z+GY6UfU QqRv/jphtPo+7w6Hu+LslFrUmIu40Aogrcj7ET8WBDdbycFZnsKW3dwRp36vIJW84enm j/9HtErpxOBa6zSPQACeuIFxnfWvjniPEEe1Tyk+FvTHFJYG1th5Qz19BqzEhXbuQFr7 cd2flz9OBfIATA6a+HtV4Tbf57td70h5NPCJEMYK6xYoBcbuYZ3o/b9ExicTbGGTRQGg +3Vw== X-Gm-Message-State: AA+aEWaNBhi+i7aov5TN21Ct4e++NF4rWseIaG3EDNq4SgU1ZeTZsoRj Qp7aKDLa7lCE1Zl825DMooQ8M8WD X-Google-Smtp-Source: AFSGD/WbkNQwlncT4LBqzbKiUeTq4dt0q5zhF3qWFqgppf4nvDvTFAvVW8d3oksV1gtJI1wv6A3D1w== X-Received: by 2002:a62:e201:: with SMTP id a1mr652119pfi.75.1544154242080; Thu, 06 Dec 2018 19:44:02 -0800 (PST) Received: from localhost.localdomain ([1.129.152.198]) by smtp.gmail.com with ESMTPSA id e23sm2262646pfh.68.2018.12.06.19.43.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Dec 2018 19:44:01 -0800 (PST) From: Suraj Jitindar Singh To: kvm-ppc@vger.kernel.org Cc: sjitindarsingh@gmail.com, kvm@vger.kernel.org, paulus@ozlabs.org, linuxppc-dev@lists.ozlabs.org, aik@ozlabs.ru Subject: [PATCH 5/8] KVM: PPC: Update kvmppc_st and kvmppc_ld to use quadrants Date: Fri, 7 Dec 2018 14:43:23 +1100 Message-Id: <20181207034326.3564-7-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20181207034326.3564-1-sjitindarsingh@gmail.com> References: <20181207034326.3564-1-sjitindarsingh@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The functions kvmppc_st and kvmppc_ld are used to access guest memory from the host using a guest effective address. They do so by translating through the process table to obtain a guest real address and then using kvm_read_guest or kvm_write_guest to make the access with the guest real address. This method of access however only works for L1 guests and will give the incorrect results for a nested guest. We can however use the store_to_eaddr and load_from_eaddr kvmppc_ops to perform the access for a nested guesti (and a L1 guest). So attempt this method first and fall back to the old method if this fails and we aren't running a nested guest. At this stage there is no fall back method to perform the access for a nested guest and this is left as a future improvement. For now we will return to the nested guest and rely on the fact that a translation should be faulted in before retrying the access. Signed-off-by: Suraj Jitindar Singh --- arch/powerpc/kvm/powerpc.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c index 95859c53a5cd..cb029fcab404 100644 --- a/arch/powerpc/kvm/powerpc.c +++ b/arch/powerpc/kvm/powerpc.c @@ -331,10 +331,17 @@ int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, { ulong mp_pa = vcpu->arch.magic_page_pa & KVM_PAM & PAGE_MASK; struct kvmppc_pte pte; - int r; + int r = -EINVAL; vcpu->stat.st++; + if (vcpu->kvm->arch.kvm_ops && vcpu->kvm->arch.kvm_ops->store_to_eaddr) + r = vcpu->kvm->arch.kvm_ops->store_to_eaddr(vcpu, eaddr, ptr, + size); + + if ((!r) || (r == -EAGAIN)) + return r; + r = kvmppc_xlate(vcpu, *eaddr, data ? XLATE_DATA : XLATE_INST, XLATE_WRITE, &pte); if (r < 0) @@ -367,10 +374,17 @@ int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, { ulong mp_pa = vcpu->arch.magic_page_pa & KVM_PAM & PAGE_MASK; struct kvmppc_pte pte; - int rc; + int rc = -EINVAL; vcpu->stat.ld++; + if (vcpu->kvm->arch.kvm_ops && vcpu->kvm->arch.kvm_ops->load_from_eaddr) + rc = vcpu->kvm->arch.kvm_ops->load_from_eaddr(vcpu, eaddr, ptr, + size); + + if ((!rc) || (rc == -EAGAIN)) + return rc; + rc = kvmppc_xlate(vcpu, *eaddr, data ? XLATE_DATA : XLATE_INST, XLATE_READ, &pte); if (rc)