From patchwork Tue Oct 3 03:10:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9981467 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 6475C60384 for ; Tue, 3 Oct 2017 03:12:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5600D2881D for ; Tue, 3 Oct 2017 03:12:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A8A528822; Tue, 3 Oct 2017 03:12:53 +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=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 EF66E2881D for ; Tue, 3 Oct 2017 03:12:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752041AbdJCDMO (ORCPT ); Mon, 2 Oct 2017 23:12:14 -0400 Received: from mail-it0-f53.google.com ([209.85.214.53]:51573 "EHLO mail-it0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751515AbdJCDL6 (ORCPT ); Mon, 2 Oct 2017 23:11:58 -0400 Received: by mail-it0-f53.google.com with SMTP id w1so283379itd.0 for ; Mon, 02 Oct 2017 20:11:57 -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=mKZ0Lca7TJ2FD0gz3H0+ghUW0cqtKIfknE/bkoSwv5M=; b=Qr0VCxcdZtWtVcIW+O6QfYnbWfO2Th+qQEWrjjalP1HoNlHdqEpbpgUC01Tkz2j1GD zcyReWPwoCriJ7HE0TdMbzUBzo8Nn24cjf1Da9vrK07RMt/VwAjqgPsGXAEpytqc2FzQ bGiteI0DKTyb+BecxzOO+UkyRZ0oqrPZMTRKk= 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=mKZ0Lca7TJ2FD0gz3H0+ghUW0cqtKIfknE/bkoSwv5M=; b=H2r14y7xf668D43AK2f4E9+a5QQhcTz20YJIsqOZ7BSwjG0xGW3Ltf5dDUXL7dfuKA jopywhLwiII7LpYxi94SbbFWED4986J4ltvX5N9LpWhJsvlA6RBnGqPdHNAwTXA24uKH XCMc9FZxQUmPryFEPbLFkFejxE0BlOKxjk5gxd0DKxy9jDS3+OLh0agJ/WNI9iy0NkZJ 1guDJWEWj/HAwFz3BLK1alJFFK+qV03UdtmITKLIqdDTNjsFsNjBZ09lm2RGapEBeasF 0wkSbrUJnyJA8NiLZ5AVPQYsLFXUnu6ZKe9VQuOB1mb9C4BJiG7uEd3aKcmL0zFHUAJ5 sUSQ== X-Gm-Message-State: AMCzsaXXURX6466LQeUxqSRJAs4cB84J1QBx6O7Dt4G7l3yiMnA5hVGq 1UQlN6rd4lOsr2H7wnME97GB7Q== X-Google-Smtp-Source: AOwi7QDHr/hYfBDgbswMCRPoXRXnRW2FOUPxi/RcPWgT2OyuVVWhpry5J4s+iVMRF51viWdLKiix1Q== X-Received: by 10.36.217.201 with SMTP id p192mr24148198itg.28.1507000317460; Mon, 02 Oct 2017 20:11:57 -0700 (PDT) Received: from node.jintackl-qv28633.kvmarm-pg0.wisc.cloudlab.us (c220g1-031126.wisc.cloudlab.us. [128.104.222.76]) by smtp.gmail.com with ESMTPSA id h84sm5367193iod.72.2017.10.02.20.11.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Oct 2017 20:11:56 -0700 (PDT) From: Jintack Lim To: christoffer.dall@linaro.org, marc.zyngier@arm.com, kvmarm@lists.cs.columbia.edu Cc: jintack@cs.columbia.edu, pbonzini@redhat.com, rkrcmar@redhat.com, catalin.marinas@arm.com, will.deacon@arm.com, linux@armlinux.org.uk, mark.rutland@arm.com, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Jintack Lim Subject: [RFC PATCH v2 17/31] KVM: arm64: Rework the system instruction emulation framework Date: Mon, 2 Oct 2017 22:10:59 -0500 Message-Id: <1507000273-3735-15-git-send-email-jintack.lim@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1507000273-3735-1-git-send-email-jintack.lim@linaro.org> References: <1507000273-3735-1-git-send-email-jintack.lim@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 Rework the system instruction emulation framework to handle potentially all system instruction traps other than MSR/MRS instructions. Those system instructions would be AT and TLBI instructions controlled by HCR_EL2.NV, AT, and TTLB bits. Signed-off-by: Jintack Lim --- arch/arm64/kvm/sys_regs.c | 66 ++++++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 41 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 88ce172..481bea64 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1621,6 +1621,11 @@ static bool access_id_aa64mmfr0_el1(struct kvm_vcpu *v, { SYS_DESC(SYS_SP_EL2), NULL, reset_special, SP_EL2, 0}, }; +#define SYS_INSN_TO_DESC(insn, access_fn, forward_fn) \ + { SYS_DESC((insn)), (access_fn), NULL, 0, 0, NULL, NULL, (forward_fn) } +static struct sys_reg_desc sys_insn_descs[] = { +}; + #define reg_to_match_value(x) \ ({ \ unsigned long val; \ @@ -1674,6 +1679,25 @@ static void perform_access(struct kvm_vcpu *vcpu, kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); } +static int emulate_sys_instr(struct kvm_vcpu *vcpu, struct sys_reg_params *p) +{ + + const struct sys_reg_desc *r; + + /* Search from the system instruction table. */ + r = find_reg(p, sys_insn_descs, ARRAY_SIZE(sys_insn_descs)); + + if (likely(r)) { + perform_access(vcpu, p, r); + } else { + kvm_err("Unsupported guest sys instruction at: %lx\n", + *vcpu_pc(vcpu)); + print_sys_reg_instr(p); + kvm_inject_undefined(vcpu); + } + return 1; +} + static bool trap_dbgidr(struct kvm_vcpu *vcpu, struct sys_reg_params *p, const struct sys_reg_desc *r) @@ -2236,47 +2260,6 @@ static int emulate_sys_reg(struct kvm_vcpu *vcpu, return 1; } -static int emulate_tlbi(struct kvm_vcpu *vcpu, - struct sys_reg_params *params) -{ - /* TODO: support tlbi instruction emulation*/ - kvm_inject_undefined(vcpu); - return 1; -} - -static int emulate_at(struct kvm_vcpu *vcpu, - struct sys_reg_params *params) -{ - /* TODO: support address translation instruction emulation */ - kvm_inject_undefined(vcpu); - return 1; -} - -static int emulate_sys_instr(struct kvm_vcpu *vcpu, - struct sys_reg_params *params) -{ - int ret = 0; - - /* - * Forward this trap to the virtual EL2 if the virtual HCR_EL2.NV - * bit is set. - */ - if (forward_nv_traps(vcpu)) - return kvm_inject_nested_sync(vcpu, kvm_vcpu_get_hsr(vcpu)); - - /* TLB maintenance instructions*/ - if (params->CRn == 0b1000) - ret = emulate_tlbi(vcpu, params); - /* Address Translation instructions */ - else if (params->CRn == 0b0111 && params->CRm == 0b1000) - ret = emulate_at(vcpu, params); - - if (ret) - kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); - - return ret; -} - static void reset_sys_reg_descs(struct kvm_vcpu *vcpu, const struct sys_reg_desc *table, size_t num) { @@ -2754,6 +2737,7 @@ void kvm_sys_reg_table_init(void) BUG_ON(check_sysreg_table(cp15_regs, ARRAY_SIZE(cp15_regs))); BUG_ON(check_sysreg_table(cp15_64_regs, ARRAY_SIZE(cp15_64_regs))); BUG_ON(check_sysreg_table(invariant_sys_regs, ARRAY_SIZE(invariant_sys_regs))); + BUG_ON(check_sysreg_table(sys_insn_descs, ARRAY_SIZE(sys_insn_descs))); /* We abuse the reset function to overwrite the table itself. */ for (i = 0; i < ARRAY_SIZE(invariant_sys_regs); i++)