From patchwork Tue Sep 5 14:52:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9939163 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 44DE260350 for ; Tue, 5 Sep 2017 14:52:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3713D2897B for ; Tue, 5 Sep 2017 14:52:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C25428995; Tue, 5 Sep 2017 14:52:41 +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 C91962897B for ; Tue, 5 Sep 2017 14:52:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751926AbdIEOwi (ORCPT ); Tue, 5 Sep 2017 10:52:38 -0400 Received: from mail-wm0-f42.google.com ([74.125.82.42]:36879 "EHLO mail-wm0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751857AbdIEOw1 (ORCPT ); Tue, 5 Sep 2017 10:52:27 -0400 Received: by mail-wm0-f42.google.com with SMTP id u26so20490290wma.0 for ; Tue, 05 Sep 2017 07:52:26 -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=HBgP2wfWBmepiY8xiz/Y18qD2OAoDyQzmuKKyzgvb7HYwYTNKMGoZXdclLf7X9C5+6 btyvGOdQNWq7nxMwlkeGGTxQtN6bgoWcef3JgrMNrhfair8iDl+eJ5ExO/UGhASQJbBE qslrdbyD+6hHiC1AiImQD8vznwmppqVxqjMnc= 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=DPunA++Rx+uiEx8C9roXdJYzH3KPbIOMtVfvWw3Bip5g5Zb1J/wqy0UQYSrySXMfKa AVQmt+NxQn612Q9+aBsbiRJtlpa+4SF+JTfQVLM0/WsJup7ykKVfai23/5Tv4L2F3MgE PeQ8uXNIfOGjikRpvqnJxjDdeXogZWfeRFicnJeUHezrw0HwVnZz7xuaSN/5Um2JB6YJ D2taLOoF9URlbXX4ljGqO8X1Z++BdaG45WUrzS8k0WzipW5ZQI50NVqrASZjDz1yATxh M+G+Fc7ZrBA0Rv+ZNKk9+2Fzt+5vAxt9hnxUDIIPqpfa00GFfdUUyxV31k+FZkVIzKwy gRXA== X-Gm-Message-State: AHPjjUhSw0wtxfB1YwlMHc86q5Lj37mCnbL+TA8Y32x3DHHOjhKXnzoe U097kjJGrLq+DDn/ X-Google-Smtp-Source: ADKCNb7rBRvJJXcObbc12at7bV07va28TtofBi6SD7baKdMxl2MjCKXMNdh4oXcEWIUwGBSIH7dRXg== X-Received: by 10.80.201.134 with SMTP id w6mr3491639edh.56.1504623145773; Tue, 05 Sep 2017 07:52:25 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id a28sm293809edc.14.2017.09.05.07.52.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 05 Sep 2017 07:52:24 -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 7/8] KVM: arm/arm64: Extract GICv3 max APRn index calculation Date: Tue, 5 Sep 2017 16:52:06 +0200 Message-Id: <20170905145207.18447-8-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170905145207.18447-1-cdall@linaro.org> References: <20170905145207.18447-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