From patchwork Sun Apr 23 17:08:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9695083 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 0D53E60245 for ; Sun, 23 Apr 2017 17:15:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC40326530 for ; Sun, 23 Apr 2017 17:15:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DFA4D267EC; Sun, 23 Apr 2017 17:15:57 +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.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_SORBS_SPAM autolearn=no 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 98B4626530 for ; Sun, 23 Apr 2017 17:15:57 +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=UW5z0jbrihcG1Hxrw6MrM8NMPyG76ytgjhGDbFC0jWs=; b=MnBl1/afB6BBjEZpSmGAtyF9QQ JCujTAMPFfqp5lsbKF7QPXy7VuIymJEAR14v+nCwHYAoMu1fPI6FEs/UmI9w/FFC/jghLlHAxnkgk upb+SDFFPZEq8/aBXpIS9ig/hXSI1w2RKZuu55NWjTG3psyIhUFzawnoToWdnGXb9Bi1iX26X76qo 3AW4v6vTaxxcDqCPitk8qylyk8uXOSRC+5DTsc2bR96YR1zafymzG78H085lHY0SeDdbk/be5z7i7 k5a2OE+euTy7qMsLMcMO1WJDyk8kTBCcVV7F88x2PztfbnWArU8z+ip/9cWkaj8Iu3hh3siEfyuJA VnMJsepw==; 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 1d2L76-0004Th-06; Sun, 23 Apr 2017 17:15:56 +0000 Received: from mail-wm0-f51.google.com ([74.125.82.51]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d2L1m-0004zH-1T for linux-arm-kernel@lists.infradead.org; Sun, 23 Apr 2017 17:10:29 +0000 Received: by mail-wm0-f51.google.com with SMTP id w64so46375491wma.0 for ; Sun, 23 Apr 2017 10:10:06 -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=12XXYMXVqNm+hV4yDU9bzcD45eP43DalqkcTL1WPFoo=; b=dkstsFSVZWMelfjxiXadNDS/KDfblmP9aj2vXRAQ4geDezkLCN+FvVHOzYpgU+dgzu Xgt6mK3civmIwbYn5SzbbVCXSNhKAXd6rK2aSeYNZkFyTYQzrjGFB4BalPUkyxX5XeMp ncbpXrdoSCxU394Oiied76H2ZrLYbrg7yYmYc= 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=12XXYMXVqNm+hV4yDU9bzcD45eP43DalqkcTL1WPFoo=; b=fSRMJLOKyG2O7dylZsJzhoKMyQM56Ctua7KT1/Zpo+E+t8b0SYHFpqD+mAr5tZLsXg dKXlh0tGnceYq7WXDLthvGXJ/idCGtcAbgn2zbBtAg8cJLW9y3ECGClCA1XKQ9MWTcx/ U7HhG4yWtj0VChxJWz3eet/c0eLXGKqXNv8t/JbDOd4qpk0367eZpbKvAv8Nh6KOZfTa i0oovY2rXYkwZktF21Wf0tkeS4E/lhOhKVqRt3z9iAvp8TGXgHzIZxF9wTRYup4TkpIX qtSDkXKQ9OgjIea74YeAUHH6t0IYFuVDAdkvWsHQuhA6xS9AqiIdhy743DPglqmCh5it 5HYw== X-Gm-Message-State: AN3rC/4N5yICYbAgPCzhGi0eunPF1A8w0IJ8VFy56j7uF32LH01PngpV auF2keaSmwukzYK/ X-Received: by 10.80.152.69 with SMTP id h5mr121260edb.66.1492967404839; Sun, 23 Apr 2017 10:10:04 -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.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 23 Apr 2017 10:10:04 -0700 (PDT) From: Christoffer Dall To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PULL 32/79] arm64: KVM: Treat sysreg accessors returning false as successful Date: Sun, 23 Apr 2017 19:08:42 +0200 Message-Id: <20170423170929.27334-33-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_101026_615213_3843EA97 X-CRM114-Status: GOOD ( 13.91 ) 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 , 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 Instead of considering that a sysreg accessor has failed when returning false, let's consider that it is *always* successful (after all, we won't stand for an incomplete emulation). The return value now simply indicates whether we should skip the instruction (because it has now been emulated), or if we should leave the PC alone if the emulation has injected an exception. Reviewed-by: Christoffer Dall Signed-off-by: Marc Zyngier --- arch/arm64/kvm/sys_regs.c | 49 +++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 3fef01d..2f4418e 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1571,6 +1571,22 @@ int kvm_handle_cp14_load_store(struct kvm_vcpu *vcpu, struct kvm_run *run) return 1; } +static void perform_access(struct kvm_vcpu *vcpu, + struct sys_reg_params *params, + const struct sys_reg_desc *r) +{ + /* + * Not having an accessor means that we have configured a trap + * that we don't know how to handle. This certainly qualifies + * as a gross bug that should be fixed right away. + */ + BUG_ON(!r->access); + + /* Skip instruction if instructed so */ + if (likely(r->access(vcpu, params, r))) + kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); +} + /* * emulate_cp -- tries to match a sys_reg access in a handling table, and * call the corresponding trap handler. @@ -1594,20 +1610,8 @@ static int emulate_cp(struct kvm_vcpu *vcpu, r = find_reg(params, table, num); if (r) { - /* - * Not having an accessor means that we have - * configured a trap that we don't know how to - * handle. This certainly qualifies as a gross bug - * that should be fixed right away. - */ - BUG_ON(!r->access); - - if (likely(r->access(vcpu, params, r))) { - /* Skip instruction, since it was emulated */ - kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); - /* Handled */ - return 0; - } + perform_access(vcpu, params, r); + return 0; } /* Not handled */ @@ -1777,26 +1781,13 @@ static int emulate_sys_reg(struct kvm_vcpu *vcpu, r = find_reg(params, sys_reg_descs, ARRAY_SIZE(sys_reg_descs)); if (likely(r)) { - /* - * Not having an accessor means that we have - * configured a trap that we don't know how to - * handle. This certainly qualifies as a gross bug - * that should be fixed right away. - */ - BUG_ON(!r->access); - - if (likely(r->access(vcpu, params, r))) { - /* Skip instruction, since it was emulated */ - kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); - return 1; - } - /* If access function fails, it should complain. */ + perform_access(vcpu, params, r); } else { kvm_err("Unsupported guest sys_reg access at: %lx\n", *vcpu_pc(vcpu)); print_sys_reg_instr(params); + kvm_inject_undefined(vcpu); } - kvm_inject_undefined(vcpu); return 1; }