From patchwork Thu Feb 7 04:56:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suraj Jitindar Singh X-Patchwork-Id: 10800363 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 17C4213A4 for ; Thu, 7 Feb 2019 04:57:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05A5B2D460 for ; Thu, 7 Feb 2019 04:57:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED9902D468; Thu, 7 Feb 2019 04:57:11 +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 752032D460 for ; Thu, 7 Feb 2019 04:57:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726855AbfBGE5K (ORCPT ); Wed, 6 Feb 2019 23:57:10 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:40472 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726716AbfBGE5J (ORCPT ); Wed, 6 Feb 2019 23:57:09 -0500 Received: by mail-pf1-f194.google.com with SMTP id i12so4233180pfo.7; Wed, 06 Feb 2019 20:57:08 -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; bh=pD6Sd4tXhUU1w7g3BhLgkNrC7p2Crz6vdbFgbo4L8xQ=; b=sP693IOJT1vy9y4K8ltwk4eo4Kt656odYTBfL7JbfxJLpRDrXA7sd5V5FAplRo0ZN/ 9bs5IkvOCysLUq3dtW6hpgRANKveYOxFuodXwK8NhW5HYURzamYnGPjZ2/8GNBSZBcdF bvUs2FT84nzjKzKmveJjcog3h0mhrSxM5QUnnZCO3xOElVadLLhS0Xn59sVqn5ZbbbKr lHlW6NWIQ2Dw+jGiBltlXJjpgea7oMl88xnpyHlmXPI8HrHwUDO773c2l9ObYwEgOTxo CD+JRpEGKVyFUtKyF6DmM0t11lZZlDY+mRfna4L4D10UB6zvTqb1V8exJIOzAJtzLbpH 8CQA== 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; bh=pD6Sd4tXhUU1w7g3BhLgkNrC7p2Crz6vdbFgbo4L8xQ=; b=l4cS0IcTkh8I7AALCv/dyB1p1p2jO0PelF0IIEpX37CTlC1ksU1eaFzX8jJgYbY4L7 82MVwoalM/P8vPnbb/oCqpWip0goADwf/XifZ6ktm/rB/BlPV6sAQMdz0QkX4kWrAgoJ +us+cIM7tMY40QGHjERbnnxTYXR20xB/A+EJtJIVnWJ89tOj/Xtem9592ZSA2GEJwCy7 hLtOqfO0+V5vt13WY2SDnD02GSmt4q6UhvhC6ULwXfRppca1OV+IOaMIEa/PaYvdM2IV k1agQVIMut7r3csy9wFRPbqLODMVLlr4vwK67Tz1I0cGVR4jNTzyJptCVa5IWiqn9ZIN QgyQ== X-Gm-Message-State: AHQUAuaf5U1UGv/F/G2nUm5eQXUv4cONEZONSKSAD2i72uwkD1U4tdqn e2R+XMYc945fSD+5ujVr7RMHuKA/ X-Google-Smtp-Source: AHgI3IZe6jbuvbD9VWe/0snFG3vpNh711t9Ibb/PzAZJYJDrUKyRPiQnQdDs4Q3XEaqgIwYtwa9nwA== X-Received: by 2002:a63:9d0f:: with SMTP id i15mr12962551pgd.77.1549515428187; Wed, 06 Feb 2019 20:57:08 -0800 (PST) Received: from surajjs2.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id d88sm14586840pfe.19.2019.02.06.20.57.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Feb 2019 20:57:07 -0800 (PST) From: Suraj Jitindar Singh To: kvm-ppc@vger.kernel.org Cc: kvm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, paulus@ozlabs.org, Suraj Jitindar Singh Subject: [PATCH] KVM: PPC: Book3S HV: Optimise mmio emulation for devices on FAST_MMIO_BUS Date: Thu, 7 Feb 2019 15:56:50 +1100 Message-Id: <20190207045650.18322-1-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.13.6 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Devices on the KVM_FAST_MMIO_BUS by definition have length zero and are thus used for notification purposes rather than data transfer. For example eventfd for virtio devices. This means that when emulating mmio instructions which target devices on this bus we can immediately handle them and return without needing to load the instruction from guest memory. For now we restrict this to stores as this is the only use case at present. For a normal guest the effect is negligible, however for a nested guest we save on the order of 5us per access. Signed-off-by: Suraj Jitindar Singh --- arch/powerpc/kvm/book3s_64_mmu_hv.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c index bd2dcfbf00cd..be7bc070eae5 100644 --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c @@ -442,6 +442,24 @@ int kvmppc_hv_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu, u32 last_inst; /* + * Fast path - check if the guest physical address corresponds to a + * device on the FAST_MMIO_BUS, if so we can avoid loading the + * instruction all together, then we can just handle it and return. + */ + if (is_store) { + int idx, ret; + + idx = srcu_read_lock(&vcpu->kvm->srcu); + ret = kvm_io_bus_write(vcpu, KVM_FAST_MMIO_BUS, (gpa_t) gpa, 0, + NULL); + srcu_read_unlock(&vcpu->kvm->srcu, idx); + if (!ret) { + kvmppc_set_pc(vcpu, kvmppc_get_pc(vcpu) + 4); + return RESUME_GUEST; + } + } + + /* * If we fail, we just return to the guest and try executing it again. */ if (kvmppc_get_last_inst(vcpu, INST_GENERIC, &last_inst) !=