From patchwork Sun Apr 23 17:08:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9695207 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 9191D602A7 for ; Sun, 23 Apr 2017 17:43:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9175625EF7 for ; Sun, 23 Apr 2017 17:43:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8398426530; Sun, 23 Apr 2017 17:43:58 +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=ham 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 31BB425EF7 for ; Sun, 23 Apr 2017 17:43:58 +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=XFqvYgP1sxV41ID0kb8yc5w03x3y8TEcNCsF4vTifPI=; b=AkBBG5X6dtwvUj2OBHZiAEolI+ qAjQuM0HxyURNVXDiTc55GVfgw8MakZR4OCaEUJuLsVtQLuwDNXFJYcRyUipWnfK94aghfpbMyc8H NR8SJdqeWd3W2yRjMaSfXoSqzxAcbCEDQfmyJfarlPtLebBf6ZjhzKFzebIrJkiynO2+XkP4E93pb 26C9rEeyQ5j3w5L1xXDO/kIG5MQ7eT44DZ6aiJKka/0VSlAe85pw3Mw+BbK5J/YtDujJsnsDXMf1w bOwGdBFSM31jcU3AftPz///r89MFfmQV9ETRuyhEsrgnUvjuILAeETCOPUoyminnIWnwML8eRSlR1 ccVHpxWw==; 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 1d2LYD-0006c7-OB; Sun, 23 Apr 2017 17:43:57 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d2LMg-0002ZO-7d for linux-arm-kernel@bombadil.infradead.org; Sun, 23 Apr 2017 17:32:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=2v8D5SZgsywFtYwDGTyYMTYr5BbD9ddFUww0FoaZAhs=; b=kKI9JDYfsbVgAvThmoUlknqLX BA/pSixCbwToMx+gYxbjyD4KWdMRUWMBNA/Zxz8JTIMmIX7msWgNN++E357krQcQbuYOlpvpF7Tjj 6D4CZ2AfZcwPZpHR+tOfQhP9dKdESbYw6do5Dg7q4339+RwvIwUP8NIednWoaQSLkpQTUxtpHx/ku pyrxkFQ3cHmZ8QL/rILzbHP4uYw6h78Ah3jko1GSOvHxVZKtRJuoWDBq3FyaDs7xb5QDZStL4hlLM 3NbzDB9yZERJS9tQFLlqFGluCimHvskN/ueZyIEh9ZxkF1QDVv9FFu1KDUoDzyEAM8iH0fMu2edRT dU6wJuYPA==; Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d2L1o-0005BV-8Z for linux-arm-kernel@lists.infradead.org; Sun, 23 Apr 2017 17:10:29 +0000 Received: by mail-wm0-x22f.google.com with SMTP id i137so1939095wmf.0 for ; Sun, 23 Apr 2017 10:10:07 -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=2v8D5SZgsywFtYwDGTyYMTYr5BbD9ddFUww0FoaZAhs=; b=AiL2vScWNs741BY92DXjDQcFakKUEOlEgWmc16qWR8HK+1UpY1V1UbnmQhkRIu4Xzl HoCDBfaRu51lEwAXyQd3PhC478/WaIDi9t0IlpVZIlYKH+qDbyK5YfCphkFVhr1nBkEq WFQF+q0OjDkRSsoES77dAn4679NA76iM0iCC0= 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=2v8D5SZgsywFtYwDGTyYMTYr5BbD9ddFUww0FoaZAhs=; b=WUnZA6/26pdNRvBdELavQosmuyEY9/SoJJFTI4riCJsIAWSni31POj1M2M6arnCu2r K3SbEjGFF0GKC5YfAldozTsT08w5IBa9fheYgccHusHwlmABRD/ot73zXAL88aLJXDnp iqwPNri8Du19sqbmJMdKkg1rtExxHsplJed1AHguKCoU0jhg71jL24tCrwYtAdl+LZ8M Fw8/7/5T/731jYDWIfj4G1FY479087/ctLqAgi8pwAjAHBBDvTkmF3jcR+NDt9zv7XsS QFFCvJk0gIndZ4IgK3ffXE4nni+JArToOIqfs8gIadDEx0HhXFDeO0K3zHeUUuLU6/nI e3kQ== X-Gm-Message-State: AN3rC/5oaw/y/J0H8j1WIUYDZTk4QdQ9i1KNxVEBQLHDJKpXp5+FSv4t M+S8RKuxa7Xi34YR X-Received: by 10.80.153.11 with SMTP id k11mr138840edb.63.1492967405805; Sun, 23 Apr 2017 10:10:05 -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.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 23 Apr 2017 10:10:05 -0700 (PDT) From: Christoffer Dall To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PULL 33/79] arm64: KVM: Do not corrupt registers on failed 64bit CP read Date: Sun, 23 Apr 2017 19:08:43 +0200 Message-Id: <20170423170929.27334-34-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_131028_417049_F39D2B86 X-CRM114-Status: GOOD ( 12.72 ) 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 If we fail to emulate a mrrc instruction, we: 1) deliver an exception, 2) spit a nastygram on the console, 3) write back some garbage to Rt/Rt2 While 1) and 2) are perfectly acceptable, 3) is out of the scope of the architecture... Let's mimick the code in kvm_handle_cp_32 and be more cautious. Reviewed-by: Christoffer Dall Signed-off-by: Marc Zyngier Signed-off-by: Christoffer Dall --- arch/arm64/kvm/sys_regs.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 2f4418e..582d68e 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1678,20 +1678,25 @@ static int kvm_handle_cp_64(struct kvm_vcpu *vcpu, params.regval |= vcpu_get_reg(vcpu, Rt2) << 32; } - if (!emulate_cp(vcpu, ¶ms, target_specific, nr_specific)) - goto out; - if (!emulate_cp(vcpu, ¶ms, global, nr_global)) - goto out; - - unhandled_cp_access(vcpu, ¶ms); + /* + * Try to emulate the coprocessor access using the target + * specific table first, and using the global table afterwards. + * If either of the tables contains a handler, handle the + * potential register operation in the case of a read and return + * with success. + */ + if (!emulate_cp(vcpu, ¶ms, target_specific, nr_specific) || + !emulate_cp(vcpu, ¶ms, global, nr_global)) { + /* Split up the value between registers for the read side */ + if (!params.is_write) { + vcpu_set_reg(vcpu, Rt, lower_32_bits(params.regval)); + vcpu_set_reg(vcpu, Rt2, upper_32_bits(params.regval)); + } -out: - /* Split up the value between registers for the read side */ - if (!params.is_write) { - vcpu_set_reg(vcpu, Rt, lower_32_bits(params.regval)); - vcpu_set_reg(vcpu, Rt2, upper_32_bits(params.regval)); + return 1; } + unhandled_cp_access(vcpu, ¶ms); return 1; }