From patchwork Tue Feb 27 11:34:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10244915 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 BCFA760208 for ; Tue, 27 Feb 2018 11:39:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFE8723B24 for ; Tue, 27 Feb 2018 11:39:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4E92262AE; Tue, 27 Feb 2018 11:39:10 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2777B23B24 for ; Tue, 27 Feb 2018 11:39:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=TrHMZFrNsB4Pz+JxJjZ4QGYKJqtBQYiRzf2GbYiFqaI=; b=noT1GqXG/l5jXSTOpO8qHhQiaM lfqFpfK7hY4j4c26OdT0OzxLkpdC9+f+hD7HHYCEmD5VDw/xZD+xLqXmYMkdt7Cpr8UOKlWpcAWhb L4PLAyZ21bP5pIX4XzM1Fq0AzGK5vUPtZBgzKNG9EVVhyEkh9iGvouhyf/ZBHPKoM9XwqokPpryn1 WfM7qH6Snp8GIblOe3WiP7VFa9vPyn/ijDe1uRaRk5mw1kXGu4TM76nLsFJlXWnqHZoVwaSnz1TXY gvTLqe9QBKyrSeuDvkdL9aIbnlQlNOHPmeQZZVJreY7DRnPr+jKUMd168504+Se3duWV9JwqyMHQG JyP8yWpw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eqdb4-0001IM-Pw; Tue, 27 Feb 2018 11:39:02 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqdXS-0006xw-Vi for linux-arm-kernel@lists.infradead.org; Tue, 27 Feb 2018 11:35:42 +0000 Received: by mail-wm0-x243.google.com with SMTP id z81so23373961wmb.4 for ; Tue, 27 Feb 2018 03:35:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=christofferdall-dk.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=m1GpXHYEz2XwOM9k3ixmDsSaOuEt57A4eGi5MOSpS2o=; b=Lr0Q2laVyUI2eAJCaYoYI0+OUKNdHLN5u+DmdpfBIuqOnf5inbfEgX5Ic+7XgbXy4L 4NlB721RQj3ZeV52HsU3nPiEqSj+9wGd9MM0ZbHtzkZkSkkqWUBtsDAK+nfOt7NilaCU OtyKOxlis6yjM7raobZOQupUNi5b6sU9s65Qi3Hj17U9a15fO7Eo2CPajO9N74/4Yf6H gPqZkuJCSIy0eo8gDyf3DdWFo2m6E03Cebpi/lxG78rAP1p0+8LxuNKzQ59fwbtTl6jt hFF3zWjgcFrGQfgZrzxinUw6MmQz85Bjvu4X3S81vn46lQ2UG4jpI5du1nhcSpf+/ZSs j10g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=m1GpXHYEz2XwOM9k3ixmDsSaOuEt57A4eGi5MOSpS2o=; b=kBTDBaF+TJe7m1dnBrWdLnxK1LugNzo6yeDPoof3SnMb0GW14ck4/nTVTJ3hAlWLp9 2sOgL9eo/eIYg6Ci8MQpbablkOGKdoP8g7vjV0Y6YizhtLC7cDyB2PrUz0mSiyk6YOsl A/gZq9hJmkAlClr5EtSiDV2fEnasx1HTvBPfEuAXC6t1wHCIvhO305KYYY+SvQw5qu7b Y7R16dSUMzVNY6cE4jX3nl0Rq6AD0EUs0YCzilvVNGmaQfnrT1Q8uGChGH4lCrw11IyK 4MaPfspPv+ITaWPJPaYm6DvSDBnYJKydb8GeflI+moq78EnbR0ErcIhKcYrWwqAKg+Mw LBKQ== X-Gm-Message-State: APf1xPD34aZF3z404Ay46PD7xgqqsssm5v2DqjL2pPtfNwABvhdGjLfZ 9mPOtIxUxtqqZn30n2TYv5PjFA== X-Google-Smtp-Source: AH8x226hqqVv7trRH4///Wd2gLqTjSOU7c9Z83V87ZDQSsSv4lVVOADP9xBs/so6aOXUHogQAxpnwg== X-Received: by 10.80.184.58 with SMTP id j55mr18736133ede.45.1519731307480; Tue, 27 Feb 2018 03:35:07 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id m1sm9176786ede.39.2018.02.27.03.35.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Feb 2018 03:35:06 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 25/40] KVM: arm64: Introduce framework for accessing deferred sysregs Date: Tue, 27 Feb 2018 12:34:14 +0100 Message-Id: <20180227113429.637-26-cdall@kernel.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180227113429.637-1-cdall@kernel.org> References: <20180227113429.637-1-cdall@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180227_033519_943838_ABCD03FE X-CRM114-Status: GOOD ( 19.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jones , kvm@vger.kernel.org, Marc Zyngier , Tomasz Nowicki , Julien Grall , Yury Norov , Dave Martin , Shih-Wei Li MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Christoffer Dall We are about to defer saving and restoring some groups of system registers to vcpu_put and vcpu_load on supported systems. This means that we need some infrastructure to access system registes which supports either accessing the memory backing of the register or directly accessing the system registers, depending on the state of the system when we access the register. We do this by defining read/write accessor functions, which can handle both "immediate" and "deferrable" system registers. Immediate registers are always saved/restored in the world-switch path, but deferrable registers are only saved/restored in vcpu_put/vcpu_load when supported and sysregs_loaded_on_cpu will be set in that case. Note that we don't use the deferred mechanism yet in this patch, but only introduce infrastructure. This is to improve convenience of review in the subsequent patches where it is clear which registers become deferred. Reviewed-by: Marc Zyngier Reviewed-by: Andrew Jones Signed-off-by: Christoffer Dall --- Notes: Changes since v4: - Slightly reworded commentary based on Drew's feedback Changes since v3: - Changed to a switch-statement based approach to improve readability. Changes since v2: - New patch (deferred register handling has been reworked) arch/arm64/include/asm/kvm_host.h | 8 ++++++-- arch/arm64/kvm/sys_regs.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 179bb9d5760b..ab46bc70add6 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -284,6 +284,10 @@ struct kvm_vcpu_arch { /* Virtual SError ESR to restore when HCR_EL2.VSE is set */ u64 vsesr_el2; + + /* True when deferrable sysregs are loaded on the physical CPU, + * see kvm_vcpu_load_sysregs and kvm_vcpu_put_sysregs. */ + bool sysregs_loaded_on_cpu; }; #define vcpu_gp_regs(v) (&(v)->arch.ctxt.gp_regs) @@ -296,8 +300,8 @@ struct kvm_vcpu_arch { */ #define __vcpu_sys_reg(v,r) ((v)->arch.ctxt.sys_regs[(r)]) -#define vcpu_read_sys_reg(v,r) __vcpu_sys_reg(v,r) -#define vcpu_write_sys_reg(v,n,r) do { __vcpu_sys_reg(v,r) = n; } while (0) +u64 vcpu_read_sys_reg(struct kvm_vcpu *vcpu, int reg); +void vcpu_write_sys_reg(struct kvm_vcpu *vcpu, u64 val, int reg); /* * CP14 and CP15 live in the same array, as they are backed by the diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 7514db002430..c809f0d1a059 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -76,6 +77,38 @@ static bool write_to_read_only(struct kvm_vcpu *vcpu, return false; } +u64 vcpu_read_sys_reg(struct kvm_vcpu *vcpu, int reg) +{ + if (!vcpu->arch.sysregs_loaded_on_cpu) + goto immediate_read; + + /* + * System registers listed in the switch are not saved on every + * exit from the guest but are only saved on vcpu_put. + */ + switch (reg) { + } + +immediate_read: + return __vcpu_sys_reg(vcpu, reg); +} + +void vcpu_write_sys_reg(struct kvm_vcpu *vcpu, u64 val, int reg) +{ + if (!vcpu->arch.sysregs_loaded_on_cpu) + goto immediate_write; + + /* + * System registers listed in the switch are not restored on every + * entry to the guest but are only restored on vcpu_load. + */ + switch (reg) { + } + +immediate_write: + __vcpu_sys_reg(vcpu, reg) = val; +} + /* 3 bits per cache level, as per CLIDR, but non-existent caches always 0 */ static u32 cache_levels;