From patchwork Sun Apr 23 17:08:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9695081 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 233AC6037F for ; Sun, 23 Apr 2017 17:15:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FCFE26530 for ; Sun, 23 Apr 2017 17:15:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 049E8267EC; Sun, 23 Apr 2017 17:15:45 +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 7552026538 for ; Sun, 23 Apr 2017 17:15:44 +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=nILCzt/b9BH83/Ql0PNHYrANTL4FV9xWdeTl/i0zlKo=; b=GUe+wakD0aIdU+5xKGgahr6fjI z0LwnK2Deg+2i29K085ytilvp3ec4F0li9n/7csC66l5tY95GtVtADC9d+ZS3e581D7NJ0xKDHTHh opFvDisjOECCds5ISeXP1nNXXXy/vlGFCyqQlVB9Prw0Zar8a3oAyYd78cTwRWqApD1iUcwHo1mVX srtJYeO3RlYbDqzPuI8yQFZO0YSUJrcLvMYlJKcOV0a7PYTlhtFG5h+dl/4LmPFmLhCDsF4xhOjGH +pIWjwg4Bri7qkTtRrP1mL6m1Cp9mNOIlYikPReD73P90Q/wrL8Swq0NcuT+wu5db9w31oG9DDMPC xACUnKWw==; 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 1d2L6t-0004Cx-CQ; Sun, 23 Apr 2017 17:15:43 +0000 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d2L1h-0004bz-6N for linux-arm-kernel@lists.infradead.org; Sun, 23 Apr 2017 17:10:28 +0000 Received: by mail-wm0-x22b.google.com with SMTP id m123so50336052wma.0 for ; Sun, 23 Apr 2017 10:10:01 -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=hKDRVeywHqrqB/UxK2nzrZxSVvnkbFxbPShEyM8BZFI=; b=DrT1ElQ7iluiLWY6G5ji8eZahwqkWT6Vv9bDh492Yr4rRFwwrVGf2+YQTJtzdcV2jC WGqYCx4i4+d9+YoIFVmzD/Updx/yeOMzc9NphED+Jet+hBB9pgDiJbjAPzJ0v7X6j/DB qoGecBgtyqL6LQ2YxttZp/hEIf+U1NMgv+sPI= 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=hKDRVeywHqrqB/UxK2nzrZxSVvnkbFxbPShEyM8BZFI=; b=psJppRxJk9udXKCNhHrxx9kbuji9GKqp7nhpG8pRZUq4tGg60q0nqIFVWJjzbohQDh JGUKP3DxUKOHUBDQTBJxVCyqAqYlESEvB1MKmBC7w8iyFU4lu+J7k8sH4h5sB7NhAu9j F3awydMYSwnGyCgUcFLj2oTXDh4RmY+cYL7CGQPjg2iK2YBV8p+M0ih7vnSxw5zH86Hd 1mcBTT4oNo41GG+MjNB1gm+EFz0EMs1sxwU9EbT5UQy4PI/YPkqpFE3G7KkVtBQVlLs2 7vQC5403/5UB0LDC8b+I75/flr9mOhBpEA/4Gbvu9hC0GcEEYdH1M7sD2WByBKico8YW AeMg== X-Gm-Message-State: AN3rC/5sSq6IRgVVZM5m1kJ1i8j4bbj1sgpOH/gJVfFN5scBPFSSRJFM 0bBhvogncGZI5ooV X-Received: by 10.80.184.2 with SMTP id j2mr120147ede.176.1492967399736; Sun, 23 Apr 2017 10:09:59 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id 58sm2803521edz.2.2017.04.23.10.09.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 23 Apr 2017 10:09:59 -0700 (PDT) From: Christoffer Dall To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PULL 27/79] arm64: KVM: PMU: Refactor pmu_*_el0_disabled Date: Sun, 23 Apr 2017 19:08:37 +0200 Message-Id: <20170423170929.27334-28-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170423170929.27334-1-cdall@linaro.org> References: <20170423170929.27334-1-cdall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170423_101021_674201_D97E879E X-CRM114-Status: GOOD ( 10.63 ) 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 From: Marc Zyngier There is a lot of duplication in the pmu_*_el0_disabled helpers, and as we're going to modify them shortly, let's move all the common stuff in a single function. No functional change. Reviewed-by: Christoffer Dall Signed-off-by: Marc Zyngier Signed-off-by: Christoffer Dall --- arch/arm64/kvm/sys_regs.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 0e26f8c..036efc97 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -460,35 +460,32 @@ static void reset_pmcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) vcpu_sys_reg(vcpu, PMCR_EL0) = val; } -static bool pmu_access_el0_disabled(struct kvm_vcpu *vcpu) +static bool check_pmu_access_disabled(struct kvm_vcpu *vcpu, u64 flags) { u64 reg = vcpu_sys_reg(vcpu, PMUSERENR_EL0); + bool enabled = (reg & flags) || vcpu_mode_priv(vcpu); - return !((reg & ARMV8_PMU_USERENR_EN) || vcpu_mode_priv(vcpu)); + return !enabled; } -static bool pmu_write_swinc_el0_disabled(struct kvm_vcpu *vcpu) +static bool pmu_access_el0_disabled(struct kvm_vcpu *vcpu) { - u64 reg = vcpu_sys_reg(vcpu, PMUSERENR_EL0); + return check_pmu_access_disabled(vcpu, ARMV8_PMU_USERENR_EN); +} - return !((reg & (ARMV8_PMU_USERENR_SW | ARMV8_PMU_USERENR_EN)) - || vcpu_mode_priv(vcpu)); +static bool pmu_write_swinc_el0_disabled(struct kvm_vcpu *vcpu) +{ + return check_pmu_access_disabled(vcpu, ARMV8_PMU_USERENR_SW | ARMV8_PMU_USERENR_EN); } static bool pmu_access_cycle_counter_el0_disabled(struct kvm_vcpu *vcpu) { - u64 reg = vcpu_sys_reg(vcpu, PMUSERENR_EL0); - - return !((reg & (ARMV8_PMU_USERENR_CR | ARMV8_PMU_USERENR_EN)) - || vcpu_mode_priv(vcpu)); + return check_pmu_access_disabled(vcpu, ARMV8_PMU_USERENR_CR | ARMV8_PMU_USERENR_EN); } static bool pmu_access_event_counter_el0_disabled(struct kvm_vcpu *vcpu) { - u64 reg = vcpu_sys_reg(vcpu, PMUSERENR_EL0); - - return !((reg & (ARMV8_PMU_USERENR_ER | ARMV8_PMU_USERENR_EN)) - || vcpu_mode_priv(vcpu)); + return check_pmu_access_disabled(vcpu, ARMV8_PMU_USERENR_ER | ARMV8_PMU_USERENR_EN); } static bool access_pmcr(struct kvm_vcpu *vcpu, struct sys_reg_params *p,