From patchwork Tue Mar 21 11:05:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9636403 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 740DE602D6 for ; Tue, 21 Mar 2017 11:06:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 721FF26E4F for ; Tue, 21 Mar 2017 11:06:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 63D5327F07; Tue, 21 Mar 2017 11:06: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=-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 [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 D2A2D26E4F for ; Tue, 21 Mar 2017 11:06:26 +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=lX+CL1oWq3t44qQVK4pOSGNQmOHtbYICHb3UK9c8ETg=; b=Rk/q/oS/YnhKrOIQMMD0sOfIbm zP/raa6JWuh/KfCk6WoyfZWdXl/wPchTNSIAnK2KmHL1f1iHXKTTlpp/noz1fMnX3/DpmrHUTR0w5 20FTX+LMYCtxJyjuL37W2M9r3r0SdBsnW5g5mljDcV6rDXqDC+UzmZpHdA7suJrR0AYYKrQgK5w1R DO16VAQ2EYa4ZKdrSunTrx6L4ae+cG+NaKPavj+M4X+DAskLbyM+Sy5OJhigad6qL+eFfsEFLC/DY bKKyQJsHyRKiJofM5RIQI3zvmumU1orvRJR6VFNdAIpFRzEYjwNv8BntJE1HGsf9T56kvczL+So9S PeJ0TfeA==; 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 1cqHcQ-00055g-Bi; Tue, 21 Mar 2017 11:06:26 +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 1cqHbx-0004V6-Sf for linux-arm-kernel@lists.infradead.org; Tue, 21 Mar 2017 11:06:00 +0000 Received: by mail-wm0-x234.google.com with SMTP id u132so9293738wmg.0 for ; Tue, 21 Mar 2017 04:05:37 -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=JwdKMTlijbrYgQ9xvrBmlIgmbZGj6cVz2Zk93nXfzwM=; b=hGJCFW7XpZmL4+5WnJGUHEGF4XRbivJaWxeHmRTKCVsuzk4bd+uErBWQG4oP03l2E2 yCfpvYogQNGADxENCUGnxNlXmjZE2TpuuRXmUASzp9mUzQF9nluuVCvw3b2EuA9pH8Wj XXSZHQz1Px/DK0joVF47KU7sQ6C0KUuhQb2Xg= 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=JwdKMTlijbrYgQ9xvrBmlIgmbZGj6cVz2Zk93nXfzwM=; b=cnOF94pzdbKhWso5cl/zE9sHpnM+edUEznyEzw9lySj1H4NA6SQE8eiXw3c9sGLa2P OKQBCGnbVJ4qsIIo6zIGe87w8dzG4LGpzIryHDV+9LW1ZC5RujGR6XVgczJCRct2Q0ov fUgPxtfWHuhIa7uulYv4D/hNsrkpwsIBN/6LPmMGN7KMe6+9NF9T9f6I3KXX1GR+md1n fCaVkibCUVNUAeDVTNuiPacB46q0fsD5ut61Au9QlrIZw4PBcewxofkICmBK1AxI09Tk agCFXzDy735gf4lXULk9pocdABlPJEHkJTCAB8k31FiZS7XQzl0QN2cX/rQlz7zLp31o UOEQ== X-Gm-Message-State: AFeK/H33w1kXa86A9EX/TRDyePwSiDGeRJZmXSyhn0LpBa6tuXpmu+WbL2JXP206iDsk6iuk X-Received: by 10.28.57.84 with SMTP id g81mr2131034wma.41.1490094335939; Tue, 21 Mar 2017 04:05:35 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id f48sm24358252wrf.17.2017.03.21.04.05.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 21 Mar 2017 04:05:35 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/5] KVM: arm64: vgic: Factor out access_gic_ctlr into separate r/w functions Date: Tue, 21 Mar 2017 12:05:27 +0100 Message-Id: <20170321110530.15857-3-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170321110530.15857-1-cdall@linaro.org> References: <20170321110530.15857-1-cdall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170321_040558_170656_4369E974 X-CRM114-Status: GOOD ( 15.84 ) 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: Christoffer Dall , kvm@vger.kernel.org, Marc Zyngier , Andre Przywara , Vijaya.Kumar@cavium.com, Eric Auger 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 We currently have one large function to deal with accesses to the virtual ICC_CTLR_EL1 from userspace. But the read and write paths don't share much logic, and as we're about to mess with this implementaiton, factor the two paths out into separate functions. No functional change. Signed-off-by: Christoffer Dall --- arch/arm64/kvm/vgic-sys-reg-v3.c | 134 ++++++++++++++++++++++----------------- 1 file changed, 75 insertions(+), 59 deletions(-) diff --git a/arch/arm64/kvm/vgic-sys-reg-v3.c b/arch/arm64/kvm/vgic-sys-reg-v3.c index 79f37e3..48848db 100644 --- a/arch/arm64/kvm/vgic-sys-reg-v3.c +++ b/arch/arm64/kvm/vgic-sys-reg-v3.c @@ -18,80 +18,96 @@ #include "vgic.h" #include "sys_regs.h" -static bool access_gic_ctlr(struct kvm_vcpu *vcpu, struct sys_reg_params *p, - const struct sys_reg_desc *r) +static bool write_gic_ctlr(struct kvm_vcpu *vcpu, u32 val) { - u32 host_pri_bits, host_id_bits, host_seis, host_a3v, seis, a3v; struct vgic_cpu *vgic_v3_cpu = &vcpu->arch.vgic_cpu; + u32 host_pri_bits, host_id_bits, host_seis, host_a3v, seis, a3v; struct vgic_vmcr vmcr; - u64 val; vgic_get_vmcr(vcpu, &vmcr); - if (p->is_write) { - val = p->regval; - - /* - * Disallow restoring VM state if not supported by this - * hardware. - */ - host_pri_bits = ((val & ICC_CTLR_EL1_PRI_BITS_MASK) >> - ICC_CTLR_EL1_PRI_BITS_SHIFT) + 1; - if (host_pri_bits > vgic_v3_cpu->num_pri_bits) - return false; - vgic_v3_cpu->num_pri_bits = host_pri_bits; + /* + * Disallow restoring VM state if not supported by this + * hardware. + */ + host_pri_bits = ((val & ICC_CTLR_EL1_PRI_BITS_MASK) >> + ICC_CTLR_EL1_PRI_BITS_SHIFT) + 1; + if (host_pri_bits > vgic_v3_cpu->num_pri_bits) + return false; - host_id_bits = (val & ICC_CTLR_EL1_ID_BITS_MASK) >> - ICC_CTLR_EL1_ID_BITS_SHIFT; - if (host_id_bits > vgic_v3_cpu->num_id_bits) - return false; + vgic_v3_cpu->num_pri_bits = host_pri_bits; - vgic_v3_cpu->num_id_bits = host_id_bits; + host_id_bits = (val & ICC_CTLR_EL1_ID_BITS_MASK) >> + ICC_CTLR_EL1_ID_BITS_SHIFT; + if (host_id_bits > vgic_v3_cpu->num_id_bits) + return false; - host_seis = ((kvm_vgic_global_state.ich_vtr_el2 & - ICH_VTR_SEIS_MASK) >> ICH_VTR_SEIS_SHIFT); - seis = (val & ICC_CTLR_EL1_SEIS_MASK) >> - ICC_CTLR_EL1_SEIS_SHIFT; - if (host_seis != seis) - return false; + vgic_v3_cpu->num_id_bits = host_id_bits; - host_a3v = ((kvm_vgic_global_state.ich_vtr_el2 & - ICH_VTR_A3V_MASK) >> ICH_VTR_A3V_SHIFT); - a3v = (val & ICC_CTLR_EL1_A3V_MASK) >> ICC_CTLR_EL1_A3V_SHIFT; - if (host_a3v != a3v) - return false; + host_seis = ((kvm_vgic_global_state.ich_vtr_el2 & + ICH_VTR_SEIS_MASK) >> ICH_VTR_SEIS_SHIFT); + seis = (val & ICC_CTLR_EL1_SEIS_MASK) >> + ICC_CTLR_EL1_SEIS_SHIFT; + if (host_seis != seis) + return false; - /* - * Here set VMCR.CTLR in ICC_CTLR_EL1 layout. - * The vgic_set_vmcr() will convert to ICH_VMCR layout. - */ - vmcr.ctlr = val & ICC_CTLR_EL1_CBPR_MASK; - vmcr.ctlr |= val & ICC_CTLR_EL1_EOImode_MASK; - vgic_set_vmcr(vcpu, &vmcr); - } else { - val = 0; - val |= (vgic_v3_cpu->num_pri_bits - 1) << - ICC_CTLR_EL1_PRI_BITS_SHIFT; - val |= vgic_v3_cpu->num_id_bits << ICC_CTLR_EL1_ID_BITS_SHIFT; - val |= ((kvm_vgic_global_state.ich_vtr_el2 & - ICH_VTR_SEIS_MASK) >> ICH_VTR_SEIS_SHIFT) << - ICC_CTLR_EL1_SEIS_SHIFT; - val |= ((kvm_vgic_global_state.ich_vtr_el2 & - ICH_VTR_A3V_MASK) >> ICH_VTR_A3V_SHIFT) << - ICC_CTLR_EL1_A3V_SHIFT; - /* - * The VMCR.CTLR value is in ICC_CTLR_EL1 layout. - * Extract it directly using ICC_CTLR_EL1 reg definitions. - */ - val |= vmcr.ctlr & ICC_CTLR_EL1_CBPR_MASK; - val |= vmcr.ctlr & ICC_CTLR_EL1_EOImode_MASK; - - p->regval = val; - } + host_a3v = ((kvm_vgic_global_state.ich_vtr_el2 & + ICH_VTR_A3V_MASK) >> ICH_VTR_A3V_SHIFT); + a3v = (val & ICC_CTLR_EL1_A3V_MASK) >> ICC_CTLR_EL1_A3V_SHIFT; + if (host_a3v != a3v) + return false; + /* + * Here set VMCR.CTLR in ICC_CTLR_EL1 layout. + * The vgic_set_vmcr() will convert to ICH_VMCR layout. + */ + vmcr.ctlr = val & ICC_CTLR_EL1_CBPR_MASK; + vmcr.ctlr |= val & ICC_CTLR_EL1_EOImode_MASK; + + vgic_set_vmcr(vcpu, &vmcr); return true; } +static u32 read_gic_ctlr(struct kvm_vcpu *vcpu) +{ + struct vgic_cpu *vgic_v3_cpu = &vcpu->arch.vgic_cpu; + u32 val = 0; + struct vgic_vmcr vmcr; + + vgic_get_vmcr(vcpu, &vmcr); + + val |= (vgic_v3_cpu->num_pri_bits - 1) << + ICC_CTLR_EL1_PRI_BITS_SHIFT; + val |= vgic_v3_cpu->num_id_bits << ICC_CTLR_EL1_ID_BITS_SHIFT; + val |= ((kvm_vgic_global_state.ich_vtr_el2 & + ICH_VTR_SEIS_MASK) >> ICH_VTR_SEIS_SHIFT) << + ICC_CTLR_EL1_SEIS_SHIFT; + val |= ((kvm_vgic_global_state.ich_vtr_el2 & + ICH_VTR_A3V_MASK) >> ICH_VTR_A3V_SHIFT) << + ICC_CTLR_EL1_A3V_SHIFT; + /* + * The VMCR.CTLR value is in ICC_CTLR_EL1 layout. + * Extract it directly using ICC_CTLR_EL1 reg definitions. + */ + val |= vmcr.ctlr & ICC_CTLR_EL1_CBPR_MASK; + val |= vmcr.ctlr & ICC_CTLR_EL1_EOImode_MASK; + + return val; +} + +static bool access_gic_ctlr(struct kvm_vcpu *vcpu, struct sys_reg_params *p, + const struct sys_reg_desc *r) +{ + bool ret = true; + + if (p->is_write) + ret = write_gic_ctlr(vcpu, p->regval); + else + p->regval = read_gic_ctlr(vcpu); + + return ret; +} + static bool access_gic_pmr(struct kvm_vcpu *vcpu, struct sys_reg_params *p, const struct sys_reg_desc *r) {