From patchwork Tue Sep 5 15:41:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9939235 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 72BA860350 for ; Tue, 5 Sep 2017 15:41:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 65E562897C for ; Tue, 5 Sep 2017 15:41:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5AB9F289AF; Tue, 5 Sep 2017 15:41:27 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 EB1A22897C for ; Tue, 5 Sep 2017 15:41:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752034AbdIEPlZ (ORCPT ); Tue, 5 Sep 2017 11:41:25 -0400 Received: from mail-wm0-f51.google.com ([74.125.82.51]:37498 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751980AbdIEPlW (ORCPT ); Tue, 5 Sep 2017 11:41:22 -0400 Received: by mail-wm0-f51.google.com with SMTP id u26so21052775wma.0 for ; Tue, 05 Sep 2017 08:41:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kvF0jyxPC1D0yDoCsQLv72O+HDBxzTeLI2MGHMuNRgA=; b=MPdjFXZpgmAQ3wzOHSA3DdxIfbJhpd0T7uBChERTLEuLDgntjIu7slM0hrdTVKqD4K sJj3RKWB0mngdz7m62wf9sjsrF1H5Yc0p0E2CTf+aLbk8I45UNn32bC1b7FIvJF6KmuT Euf1BJtzbbB7Kmg3uzrREDWJSqrPgTGmg0nBk= 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=kvF0jyxPC1D0yDoCsQLv72O+HDBxzTeLI2MGHMuNRgA=; b=X53gYz6ZGeM+Tre+/ut77BVeW+6/MTESPHB2DbB3PQxoK8oUMdehPFfgM971xXWCHV Yhgv1i7csSlYb3z6rexuccX8ikMrFTtgU2Amx8kyjr0IbhpUrs2lBH2oUXXESh+LJGGS PVS2P7TNS6FzKr6akV+AyrFliKiSXzjsIxN7364BFbM18BgLFdOREwyDxKiho9Q8WnnU n0aAnajyvxeZHrlktKu9ADNgtqzznteKQUt3oipKaF1GA5L3ftFwqgY39RnIY1tRUSuU +OBP9npm7DOwESUtrhGClEaW9wXOLX0U3vGKUNUws3gAc2iKM9cggBOFMNAQHsr7mLh8 vKTw== X-Gm-Message-State: AHPjjUjs4JT5MiWeDC29ERddBCIgJTd13h7V1eBnQ0FCC3xOiVwTYuWa IzPgdbPHtZM7mP/5 X-Google-Smtp-Source: ADKCNb5AxqcD7scdKOvKtX5E2KrL1QyLRddp/AkC+CnmBUyNf8Op8GgJbxark4vCOnKni/S2bnqrKg== X-Received: by 10.80.138.129 with SMTP id j1mr3550550edj.111.1504626081280; Tue, 05 Sep 2017 08:41:21 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id k19sm336273eda.73.2017.09.05.08.41.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 05 Sep 2017 08:41:20 -0700 (PDT) From: Christoffer Dall To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Cc: Marc Zyngier , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Christoffer Dall Subject: [PULL v2 4/5] KVM: arm/arm64: Extract GICv3 max APRn index calculation Date: Tue, 5 Sep 2017 17:41:05 +0200 Message-Id: <20170905154106.2945-5-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170905154106.2945-1-cdall@linaro.org> References: <20170905154106.2945-1-cdall@linaro.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As we are about to access the APRs from the GICv2 uaccess interface, make this logic generally available. Reviewed-by: Marc Zyngier Signed-off-by: Christoffer Dall --- arch/arm64/kvm/vgic-sys-reg-v3.c | 23 +++-------------------- virt/kvm/arm/vgic/vgic.h | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/arch/arm64/kvm/vgic-sys-reg-v3.c b/arch/arm64/kvm/vgic-sys-reg-v3.c index 116786d..c77d508 100644 --- a/arch/arm64/kvm/vgic-sys-reg-v3.c +++ b/arch/arm64/kvm/vgic-sys-reg-v3.c @@ -208,29 +208,12 @@ static void vgic_v3_access_apr_reg(struct kvm_vcpu *vcpu, static bool access_gic_aprn(struct kvm_vcpu *vcpu, struct sys_reg_params *p, const struct sys_reg_desc *r, u8 apr) { - struct vgic_cpu *vgic_v3_cpu = &vcpu->arch.vgic_cpu; u8 idx = r->Op2 & 3; - /* - * num_pri_bits are initialized with HW supported values. - * We can rely safely on num_pri_bits even if VM has not - * restored ICC_CTLR_EL1 before restoring APnR registers. - */ - switch (vgic_v3_cpu->num_pri_bits) { - case 7: - vgic_v3_access_apr_reg(vcpu, p, apr, idx); - break; - case 6: - if (idx > 1) - goto err; - vgic_v3_access_apr_reg(vcpu, p, apr, idx); - break; - default: - if (idx > 0) - goto err; - vgic_v3_access_apr_reg(vcpu, p, apr, idx); - } + if (idx > vgic_v3_max_apr_idx(vcpu)) + goto err; + vgic_v3_access_apr_reg(vcpu, p, apr, idx); return true; err: if (!p->is_write) diff --git a/virt/kvm/arm/vgic/vgic.h b/virt/kvm/arm/vgic/vgic.h index bba7fa2..bf9ceab 100644 --- a/virt/kvm/arm/vgic/vgic.h +++ b/virt/kvm/arm/vgic/vgic.h @@ -220,4 +220,20 @@ int vgic_debug_destroy(struct kvm *kvm); bool lock_all_vcpus(struct kvm *kvm); void unlock_all_vcpus(struct kvm *kvm); +static inline int vgic_v3_max_apr_idx(struct kvm_vcpu *vcpu) +{ + struct vgic_cpu *cpu_if = &vcpu->arch.vgic_cpu; + + /* + * num_pri_bits are initialized with HW supported values. + * We can rely safely on num_pri_bits even if VM has not + * restored ICC_CTLR_EL1 before restoring APnR registers. + */ + switch (cpu_if->num_pri_bits) { + case 7: return 3; + case 6: return 1; + default: return 0; + } +} + #endif