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: 9939195 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 89BB9604D3 for ; Tue, 5 Sep 2017 15:06:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A6FA28987 for ; Tue, 5 Sep 2017 15:06:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F6F1289A5; Tue, 5 Sep 2017 15:06:40 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 043ED28987 for ; Tue, 5 Sep 2017 15:06:40 +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=7aZgZyImS0D7k7d29F3Z9nxBAQ/wYscPW7osBcbGXjw=; b=AhMqwPlRZMD8wy5kfClz1DKM/V /ig6WwRR81zvK/zQOm83faCwBq2/69dXV2G0AAS+jIdDME/Bf4UdMUmQVfFa2g58gy5Q1kCKoalaB 7iSPAD1T5+Jy06vQ0nDM5uJfIbwOYLnv/I4kAlLd8YtNsfXH+RHCOHtqEpOJfz5jZUFZds/6XOD7J +dmy7xQQtguvnkBs6VJEsnu5ByEDUsj3LcgXBXrToLzQqPxE9O+MAFyHDcRKBRdV1poAQrVPG6e3G pLsV9lwm3PfSeaIg808nOdL9a2HpxGi8tGcZGKuZTuyYXs/NjbJHaEnJ9lR6A1KJMDpCtV1bGJ0Ym o/LqeA5Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dpFR1-000855-3b; Tue, 05 Sep 2017 15:06:39 +0000 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dpFDZ-0007ak-V3 for linux-arm-kernel@lists.infradead.org; Tue, 05 Sep 2017 14:52:59 +0000 Received: by mail-wm0-x234.google.com with SMTP id 187so20373589wmn.1 for ; Tue, 05 Sep 2017 07:52:27 -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=NFjh9nR3Ahx01YFkWjefp1ZEagNzFyS4ppKyCND5z8lVLv1CSYH6aQUmmGlNh9vXxC xQFRq2lGlt1V6R9MTgrgwNGebPEgiEcRxtke0wZuClRnjOpbSmzTllOmD+JZUR4B/44H dFpjxRJdOytkaWrcaSsO5nwcD2+VZjDEdnpT+zoQm9DeMSmvH+oDdRoxyeRMi5ZAVt5h MU/jFFTeZ+klibI3fAo5oP8Y8lXNcsijnu5AzNwfQLlT/Afur9D7YaU417YHLdxvbAni 8G9+RlbuAv9WgAf4VpHdB2gAtpEw7xM1BnuY/m6dzOuq1ca38vfwZ0Ixd38nyDYekSw9 9AFw== X-Gm-Message-State: AHPjjUiXsYknK105XKm6hXazQ01oA2gvoVDVh6L1znFCU2A+43gJj1Sl RZ80oLJ0QSMGxvsI 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?= 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170905_075246_753214_6B6AB228 X-CRM114-Status: GOOD ( 13.29 ) 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: Marc Zyngier , Christoffer Dall , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org 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 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