From patchwork Sun Apr 23 17:08:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9694963 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 3888360245 for ; Sun, 23 Apr 2017 17:11:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20EC626530 for ; Sun, 23 Apr 2017 17:11:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 14994265B9; Sun, 23 Apr 2017 17:11:30 +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 B213426530 for ; Sun, 23 Apr 2017 17:11:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1163121AbdDWRL1 (ORCPT ); Sun, 23 Apr 2017 13:11:27 -0400 Received: from mail-wm0-f51.google.com ([74.125.82.51]:38616 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1162376AbdDWRKI (ORCPT ); Sun, 23 Apr 2017 13:10:08 -0400 Received: by mail-wm0-f51.google.com with SMTP id r190so50449396wme.1 for ; Sun, 23 Apr 2017 10:10:02 -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=GdQEQXsnHmVUfAO97sDwqy00o+OVDaj0t2W1l371ss8=; b=CuuYVilqdg+vG3KIcwqixXXPC5tyBDWWJAq0UMUj7ABLn52R/RA3Wi/4BkAeN1Q+ig S5Yj7aIvvZzRm7Sll1q+w4yZKUj5Gd4wRyd01tjlmu9BAu+Vb4Ea0d3n5CAsiWvCt8rE Kf2/Aqz7qBCRJvmiwLUTTyI0/ojiquJIV9SjU= 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=GdQEQXsnHmVUfAO97sDwqy00o+OVDaj0t2W1l371ss8=; b=aMmQ8M5mrzCYbDqYEDeOqo0PUn1eBaMh2ns91rzIsRX62ja3xm8mQ/NgKoM1K42d8f 0FXxn6kVjb3QWgHTZeOUcxa3U6o9+V2NlWKVeD07q9u7rjTJf0eyX1XXGsneuXNLSoPT X9KxJq6CP09UuckwQYG0eUy8+ZlnCz2UmUqGjFsUkM/85jhEU2GKtkZouBZshXjVK2Gi QGteDr3J+bCZ8XpnhKiCWAZ7IhTdnsR1MPNRyQ6XxGVOs7pALYVwmsdxj6Elq3wIZrmL DszzYUdZO/8IYLpf+9p+ZPhhS8nyE1mbVe4HinHo36PLjWPBstRGmhn8ioqw0OmUF2CM v/Kg== X-Gm-Message-State: AN3rC/5NOSbxSBpiVtl98pRp3IDXUxJwDVe2oM2nCpNCQxkHaxnIxloR tI6b/B8g3ysXwf6M X-Received: by 10.80.184.129 with SMTP id l1mr121733ede.88.1492967401756; Sun, 23 Apr 2017 10:10:01 -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.10.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 23 Apr 2017 10:10:01 -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 Subject: [PULL 29/79] arm64: KVM: PMU: Inject UNDEF on non-privileged accesses Date: Sun, 23 Apr 2017 19:08:39 +0200 Message-Id: <20170423170929.27334-30-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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Marc Zyngier access_pminten() and access_pmuserenr() can only be accessed when the CPU is in a priviledged mode. If it is not, let's inject an UNDEF exception. Reviewed-by: Christoffer Dall Signed-off-by: Marc Zyngier --- arch/arm64/kvm/sys_regs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 750c129..d343c0f 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -709,8 +709,10 @@ static bool access_pminten(struct kvm_vcpu *vcpu, struct sys_reg_params *p, if (!kvm_arm_pmu_v3_ready(vcpu)) return trap_raz_wi(vcpu, p, r); - if (!vcpu_mode_priv(vcpu)) + if (!vcpu_mode_priv(vcpu)) { + kvm_inject_undefined(vcpu); return false; + } if (p->is_write) { u64 val = p->regval & mask; @@ -780,8 +782,10 @@ static bool access_pmuserenr(struct kvm_vcpu *vcpu, struct sys_reg_params *p, return trap_raz_wi(vcpu, p, r); if (p->is_write) { - if (!vcpu_mode_priv(vcpu)) + if (!vcpu_mode_priv(vcpu)) { + kvm_inject_undefined(vcpu); return false; + } vcpu_sys_reg(vcpu, PMUSERENR_EL0) = p->regval & ARMV8_PMU_USERENR_MASK;