From patchwork Mon Jan 9 06:24:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9504023 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 5F9D160757 for ; Mon, 9 Jan 2017 06:38:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50556280DE for ; Mon, 9 Jan 2017 06:38:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 44B2D2811C; Mon, 9 Jan 2017 06:38:16 +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.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable 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 E31B5280DE for ; Mon, 9 Jan 2017 06:38:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1163775AbdAIGgk (ORCPT ); Mon, 9 Jan 2017 01:36:40 -0500 Received: from outprodmail01.cc.columbia.edu ([128.59.72.39]:38151 "EHLO outprodmail01.cc.columbia.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S939539AbdAIGZ4 (ORCPT ); Mon, 9 Jan 2017 01:25:56 -0500 Received: from hazelnut (hazelnut.cc.columbia.edu [128.59.213.250]) by outprodmail01.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096PWY9017300 for ; Mon, 9 Jan 2017 01:25:55 -0500 Received: from hazelnut (localhost.localdomain [127.0.0.1]) by hazelnut (Postfix) with ESMTP id 4A3636D for ; Mon, 9 Jan 2017 01:25:55 -0500 (EST) Received: from sendprodmail03.cc.columbia.edu (sendprodmail03.cc.columbia.edu [128.59.72.15]) by hazelnut (Postfix) with ESMTP id 27B8D6D for ; Mon, 9 Jan 2017 01:25:55 -0500 (EST) Received: from mail-qk0-f197.google.com (mail-qk0-f197.google.com [209.85.220.197]) by sendprodmail03.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096PsWh056888 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 9 Jan 2017 01:25:55 -0500 Received: by mail-qk0-f197.google.com with SMTP id 11so31129449qkl.4 for ; Sun, 08 Jan 2017 22:25:55 -0800 (PST) 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=2E4GpkyoxfAJ/9scF91MfuuwbolILaTJuc8VWQIYErg=; b=k5juljH4w+tZtp8eyJpwbO9vJmsjIx2ZYA1DndBNKTN+90GhU12ArXQn2urGLj31HW 6FTqSuX9wqdbaMhfbN0VKCaCR6D4lg62i2ho7qozQNXlvJCdlJWcYZ1Cust2+Nr5vLVl HgSuQTCXe2bi3jk1EoXwkJqH2jMVWHpJxUoXm6GRuL+XWBBS+I+oRTZAXJ+7zXMzuobP oW2F6H84pX+yn560gAvojOXHpOuJtZIY5GRx8YH07qezYinJ6Crvdl/FO5YknDyUbuN3 qNjyE/E5U6TKqTn0HDOwSxGgR7HFjlBskHKJtdQDVZBoFafquB+MboknmsOkME0d8Zwm KGrQ== X-Gm-Message-State: AIkVDXIiB0n8FG3wdBAHloJ6Ujz6Alfi3pQlJmVFDTfnDwsP5uY3uzW5awWfqm9lPU+rnaM6Ymgt3W7L0+cNkudV8AyEGMA4n62z20K1vs0zvZQMbGsNOx0TW1pR6yCh6Shj51HMNn8NQe0= X-Received: by 10.55.45.129 with SMTP id t123mr74654675qkh.311.1483943154801; Sun, 08 Jan 2017 22:25:54 -0800 (PST) X-Received: by 10.55.45.129 with SMTP id t123mr74654648qkh.311.1483943154642; Sun, 08 Jan 2017 22:25:54 -0800 (PST) Received: from jintack.cs.columbia.edu ([2001:18d8:ffff:16:21a:4aff:feaa:f900]) by smtp.gmail.com with ESMTPSA id h3sm8623257qtc.6.2017.01.08.22.25.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Jan 2017 22:25:53 -0800 (PST) From: Jintack Lim To: christoffer.dall@linaro.org, marc.zyngier@arm.com, pbonzini@redhat.com, rkrcmar@redhat.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, vladimir.murzin@arm.com, suzuki.poulose@arm.com, mark.rutland@arm.com, james.morse@arm.com, lorenzo.pieralisi@arm.com, kevin.brodsky@arm.com, wcohen@redhat.com, shankerd@codeaurora.org, geoff@infradead.org, andre.przywara@arm.com, eric.auger@redhat.com, anna-maria@linutronix.de, shihwei@cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jintack@cs.columbia.edu Subject: [RFC 17/55] KVM: arm64: Trap SPSR_EL1, ELR_EL1 and VBAR_EL1 in virtual EL2 Date: Mon, 9 Jan 2017 01:24:13 -0500 Message-Id: <1483943091-1364-18-git-send-email-jintack@cs.columbia.edu> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1483943091-1364-1-git-send-email-jintack@cs.columbia.edu> References: <1483943091-1364-1-git-send-email-jintack@cs.columbia.edu> X-No-Spam-Score: Local X-Scanned-By: MIMEDefang 2.78 on 128.59.72.15 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For the same reason we trap virtual memory register accesses in virtual EL2, we need to trap SPSR_EL1, ELR_EL1 and VBAR_EL1 accesses. ARM v8.3 introduces the HCR_EL2.NV1 bit to be able to trap on those register accesses in EL1. Do not set this bit until the whole nesting support is complete. Signed-off-by: Jintack Lim --- arch/arm64/kvm/sys_regs.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 0f5d21b..19d6a6e 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -898,6 +898,38 @@ static bool access_cntp_cval(struct kvm_vcpu *vcpu, return true; } +static inline void access_rw(struct sys_reg_params *p, u64 *sysreg) +{ + if (!p->is_write) + p->regval = *sysreg; + else + *sysreg = p->regval; +} + +static bool access_elr(struct kvm_vcpu *vcpu, + struct sys_reg_params *p, + const struct sys_reg_desc *r) +{ + access_rw(p, &vcpu->arch.ctxt.gp_regs.elr_el1); + return true; +} + +static bool access_spsr(struct kvm_vcpu *vcpu, + struct sys_reg_params *p, + const struct sys_reg_desc *r) +{ + access_rw(p, &vcpu->arch.ctxt.gp_regs.spsr[KVM_SPSR_EL1]); + return true; +} + +static bool access_vbar(struct kvm_vcpu *vcpu, + struct sys_reg_params *p, + const struct sys_reg_desc *r) +{ + access_rw(p, &vcpu_sys_reg(vcpu, r->reg)); + return true; +} + static bool trap_el2_reg(struct kvm_vcpu *vcpu, struct sys_reg_params *p, const struct sys_reg_desc *r) @@ -1013,6 +1045,13 @@ static bool trap_el2_reg(struct kvm_vcpu *vcpu, { Op0(0b11), Op1(0b000), CRn(0b0010), CRm(0b0000), Op2(0b010), access_vm_reg, reset_val, TCR_EL1, 0 }, + /* SPSR_EL1 */ + { Op0(0b11), Op1(0b000), CRn(0b0100), CRm(0b0000), Op2(0b000), + access_spsr}, + /* ELR_EL1 */ + { Op0(0b11), Op1(0b000), CRn(0b0100), CRm(0b0000), Op2(0b001), + access_elr}, + /* AFSR0_EL1 */ { Op0(0b11), Op1(0b000), CRn(0b0101), CRm(0b0001), Op2(0b000), access_vm_reg, reset_unknown, AFSR0_EL1 }, @@ -1045,7 +1084,7 @@ static bool trap_el2_reg(struct kvm_vcpu *vcpu, /* VBAR_EL1 */ { Op0(0b11), Op1(0b000), CRn(0b1100), CRm(0b0000), Op2(0b000), - NULL, reset_val, VBAR_EL1, 0 }, + access_vbar, reset_val, VBAR_EL1, 0 }, /* ICC_SGI1R_EL1 */ { Op0(0b11), Op1(0b000), CRn(0b1100), CRm(0b1011), Op2(0b101),