From patchwork Fri Jul 24 14:35:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 11683445 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7379C138A for ; Fri, 24 Jul 2020 14:37:07 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4C5DB2065C for ; Fri, 24 Jul 2020 14:37:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ewbOQhBB"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="qTwSG62o" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4C5DB2065C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version: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=5OhbQfPrG2FH6g2arANm0h0RHflD1Mjy7qBMLmWGj6Y=; b=ewbOQhBBPAjLDACSxdqB5O8X9 bOYepC/wcbg1MBqbagiRR5C6X6cwkJqDfDL1hjMVbjIkbt5mpYGRmbyi6fHQTGsXCDFJGwqjOcQQV iYH7g3cTMfvGEmoUih6jAWWGkR+PfBsZJeXvKsZLa2DaCu1khRLHP2cuR6uEAFTloLqbVemSnPEIM UIiVbfvvelRU+hpXa87on1sDYhzUkP0gDnXONlgHQuZY7kGPnKRro0lWMK51fiWw5d6o6xd0HDQwa rMzZPpXGU9eL4iYmi9T87MdZQl4OpRS21znrwlkv3OVx8GdE8UuwtIxVTAH3/E7hoWyQrCDZDx80u TWgUOmNbQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jyynB-0003Dl-En; Fri, 24 Jul 2020 14:35:21 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jyyn5-0003Be-8J for linux-arm-kernel@lists.infradead.org; Fri, 24 Jul 2020 14:35:16 +0000 Received: from localhost.localdomain (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5157D20714; Fri, 24 Jul 2020 14:35:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595601314; bh=4LRg3VE6PVsumxNfed/x5MvUvbAKTRm7x3AQ3dM6Qg4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qTwSG62oN3ulpiaV7VULoi7GrB5vYx5E5xCY7JiMyiyzb30N5XwIu7vTD8ZMuAH0d 366XqaLlIoadq6EhNgruHzbVUEdQ6YdC7fD2gWZrXXlZKOixKxhumcND6ubHwOE+N1 srXcPf6RyLdsYDOgQKoPnGZ0L62tPtAjHt+vDjQs= From: Will Deacon To: kvmarm@lists.cs.columbia.edu Subject: [PATCH 1/7] KVM: arm64: Update comment when skipping guest MMIO access instruction Date: Fri, 24 Jul 2020 15:35:00 +0100 Message-Id: <20200724143506.17772-2-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200724143506.17772-1-will@kernel.org> References: <20200724143506.17772-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200724_103515_395827_DA4FC14A X-CRM114-Status: GOOD ( 12.03 ) X-Spam-Score: -5.2 (-----) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-5.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [198.145.29.99 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Quentin Perret , kernel-team@android.com, Suzuki Poulose , James Morse , Marc Zyngier , Will Deacon , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org If a 32-bit guest accesses MMIO using a 16-bit Thumb-2 instruction that is reported to the hypervisor without a valid syndrom (for example, because of the addressing mode), then we may hand off the fault to userspace. When resuming the guest, we unconditionally advance the PC by 4 bytes, since ESR_EL2.IL is always 1 for data aborts generated without a valid syndrome. This is a bit rubbish, but it's also difficult to see how we can fix it without potentially introducing regressions in userspace MMIO fault handling. Update the comment when skipping a guest MMIO access instruction so that this corner case is at least written down. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/mmio.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/arm64/kvm/mmio.c b/arch/arm64/kvm/mmio.c index 4e0366759726..b54ea5aa6c06 100644 --- a/arch/arm64/kvm/mmio.c +++ b/arch/arm64/kvm/mmio.c @@ -113,6 +113,13 @@ int kvm_handle_mmio_return(struct kvm_vcpu *vcpu, struct kvm_run *run) /* * The MMIO instruction is emulated and should not be re-executed * in the guest. + * + * Note: If user space handled the emulation because the abort + * symdrome information was not valid (ISV set in the ESR), then + * this will assume that the faulting instruction was 32-bit. + * If the faulting instruction was a 16-bit Thumb instruction, + * then userspace would need to rewind the PC by 2 bytes prior to + * resuming the vCPU (yuck!). */ kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); From patchwork Fri Jul 24 14:35:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 11683441 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7F28E618 for ; Fri, 24 Jul 2020 14:37:02 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 521E7206D8 for ; Fri, 24 Jul 2020 14:37:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GeRm7aOX"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="Vau5MMte" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 521E7206D8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version: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=uApOqhXDLAnyDViu0A/t2NiKfhuONHzchjsJpKQ+qTs=; b=GeRm7aOXGed5lpZwIgBnRYqGJ pgBnJXjeD5ABsxL7A4dwt87thu5QNf1hHyjpTWqbh6KEHDHzQk7UuVUJbQVGQ4WDpJH+M9wi7EQuK AxQSpENS4zLqBqKDOip8o0eLy5ICKz65WaeitJw4e4W4c4eNPAmIldikk2Ig2dwpqzFrCdpr+MhST mr+Td4dzlMl19S0SKXFKFM/49YJ49hbu9ehlM/aAfLXyPlNeiR3k9qoA7ZVX7VAcgaor63vbj7vQO 0jaCaECXITPAmCUFTm/E3dCMhekhKLKHRQqOoJPLlrWc3rWdiXAxc4LKevFt0nojXfKKjsaEMYgNY +mKFCMyTg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jyynD-0003EE-BU; Fri, 24 Jul 2020 14:35:23 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jyyn7-0003CC-2b for linux-arm-kernel@lists.infradead.org; Fri, 24 Jul 2020 14:35:18 +0000 Received: from localhost.localdomain (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 24AC020767; Fri, 24 Jul 2020 14:35:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595601316; bh=wLGUvE19PgAr3GL6UxA3dDSQK472ZS7rSLycjtaK/zs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vau5MMtecjApgGX+mjp+pl6FBNgvBTe7zT9C83jhNc8GqKOdhM7XeHrr5HULBZc8h MmQ1FWBUU8kr6yvcgFBDbFkmHjv6c2CenE028cheDD9zgFeaweNP0Z0so1wuO7xNPe ODHdpmhbCJTzTLI3PPCEYwmS9oqzZVK5We3SU83w= From: Will Deacon To: kvmarm@lists.cs.columbia.edu Subject: [PATCH 2/7] KVM: arm64: Rename kvm_vcpu_dabt_isextabt() Date: Fri, 24 Jul 2020 15:35:01 +0100 Message-Id: <20200724143506.17772-3-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200724143506.17772-1-will@kernel.org> References: <20200724143506.17772-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200724_103517_206732_95BA2A58 X-CRM114-Status: GOOD ( 13.08 ) X-Spam-Score: -5.2 (-----) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-5.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [198.145.29.99 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Quentin Perret , kernel-team@android.com, Suzuki Poulose , James Morse , Marc Zyngier , Will Deacon , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org kvm_vcpu_dabt_isextabt() is not specific to data aborts and has nothing to do with sign extension. Rename it. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_emulate.h | 2 +- arch/arm64/kvm/hyp/switch.c | 2 +- arch/arm64/kvm/mmu.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h index 4d0f8ea600ba..9d6beb532536 100644 --- a/arch/arm64/include/asm/kvm_emulate.h +++ b/arch/arm64/include/asm/kvm_emulate.h @@ -366,7 +366,7 @@ static __always_inline u8 kvm_vcpu_trap_get_fault_type(const struct kvm_vcpu *vc return kvm_vcpu_get_hsr(vcpu) & ESR_ELx_FSC_TYPE; } -static __always_inline bool kvm_vcpu_dabt_isextabt(const struct kvm_vcpu *vcpu) +static __always_inline bool kvm_vcpu_abt_is_extabt(const struct kvm_vcpu *vcpu) { switch (kvm_vcpu_trap_get_fault(vcpu)) { case FSC_SEA: diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index db1c4487d95d..9aa1092bbafd 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -594,7 +594,7 @@ static bool __hyp_text fixup_guest_exit(struct kvm_vcpu *vcpu, u64 *exit_code) valid = kvm_vcpu_trap_get_class(vcpu) == ESR_ELx_EC_DABT_LOW && kvm_vcpu_trap_get_fault_type(vcpu) == FSC_FAULT && kvm_vcpu_dabt_isvalid(vcpu) && - !kvm_vcpu_dabt_isextabt(vcpu) && + !kvm_vcpu_abt_is_extabt(vcpu) && !kvm_vcpu_dabt_iss1tw(vcpu); if (valid) { diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index df2a8025ec8a..660a83a172e4 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -2074,7 +2074,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run) is_iabt = kvm_vcpu_trap_is_iabt(vcpu); /* Synchronous External Abort? */ - if (kvm_vcpu_dabt_isextabt(vcpu)) { + if (kvm_vcpu_abt_is_extabt(vcpu)) { /* * For RAS the host kernel may handle this abort. * There is no need to pass the error into the guest. From patchwork Fri Jul 24 14:35:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 11683439 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 627FB138A for ; Fri, 24 Jul 2020 14:37:02 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3822820674 for ; Fri, 24 Jul 2020 14:37:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="FkkGI8q2"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="r1uRDTfX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3822820674 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version: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=LoWzpZNtd7RVLDPpDQSXhL9s5CQ8Ke09ZzY6pekSwyc=; b=FkkGI8q2RETeOzkbow7ELWvkd TdaFf1Q1LZDEKK5ndjIRAJ1iUHJ3ISrbgQCGm94uq9uQxFWVlsqX3vs/cEnuZEuDHxx4dFE7X/ZGW 6un49ErYvmjSSvDiFkSmvmzR5MWYRxir7hQgYgj+pg1NC2JV3K4dl4Cp5x42/pKLPWcPD1bykaOId /r0yYRzSiJRhEMzir8vA/Zp4gG9APRpLxMVU24c2+iIs7rbQdJn0J7ZinlWaTKkE4HytQR7aRPKT+ p/fBsOPCDvj6ISn5F8cs+IEePYlgeo2W//kedhaviyMqu7W1cm1jJyPzXkdILzWFLxBMZXlqXNHc7 DAqHCnDmA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jyynF-0003F8-OE; Fri, 24 Jul 2020 14:35:25 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jyyn9-0003Cy-0N for linux-arm-kernel@lists.infradead.org; Fri, 24 Jul 2020 14:35:19 +0000 Received: from localhost.localdomain (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id ECCED2078D; Fri, 24 Jul 2020 14:35:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595601318; bh=1bIUieX2HmjuBqC9V0MncwzHE+Mu6QjPYz3OPP1AvzQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r1uRDTfX6y7a7Bu27IHDDtliTwi9q17DC0oH/zu8/vm4b6qbG2iKwVFPun2irduAM 2J5YLekWU7/CBiHXctu0+sYiYm3UqBT5yZPWPGCKOHqFKsXT2qjkAoAVbrMsiBJHns nu3P14AIsSE/spmB2mJbOxBXebmxAVMPA/ddndcc= From: Will Deacon To: kvmarm@lists.cs.columbia.edu Subject: [PATCH 3/7] KVM: arm64: Handle data and instruction external aborts the same way Date: Fri, 24 Jul 2020 15:35:02 +0100 Message-Id: <20200724143506.17772-4-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200724143506.17772-1-will@kernel.org> References: <20200724143506.17772-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200724_103519_126364_217193B9 X-CRM114-Status: GOOD ( 12.92 ) X-Spam-Score: -5.2 (-----) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-5.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [198.145.29.99 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Quentin Perret , kernel-team@android.com, Suzuki Poulose , James Morse , Marc Zyngier , Will Deacon , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org If the guest generates a synchronous external abort which is not handled by the host, we inject it back into the guest as a virtual SError, but only if the original fault was reported on the data side. Instruction faults are reported as "Unsupported FSC", causing the vCPU run loop to bail with -EFAULT. Although synchronous external aborts from a guest are pretty unusual, treat them the same regardless of whether they are taken as data or instruction aborts by EL2. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/mmu.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 660a83a172e4..ae17a99243e2 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -2079,13 +2079,10 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run) * For RAS the host kernel may handle this abort. * There is no need to pass the error into the guest. */ - if (!kvm_handle_guest_sea(fault_ipa, kvm_vcpu_get_hsr(vcpu))) - return 1; - - if (unlikely(!is_iabt)) { + if (kvm_handle_guest_sea(fault_ipa, kvm_vcpu_get_hsr(vcpu))) kvm_inject_vabt(vcpu); - return 1; - } + + return 1; } trace_kvm_guest_fault(*vcpu_pc(vcpu), kvm_vcpu_get_hsr(vcpu), From patchwork Fri Jul 24 14:35:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 11683443 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 70313138A for ; Fri, 24 Jul 2020 14:37:04 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 496BC2065C for ; Fri, 24 Jul 2020 14:37:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="pIY3C6mO"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="yiXEFGt7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 496BC2065C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version: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=JULMjK6JgZLJcQMMMsseg92U0I5gHdpW9M7eI8ihixM=; b=pIY3C6mO+hxtd50wvppSYGsK2 GP9WJcomwMhpY0/aNf5/iN30BTzWgZvVz7tHE8FIyv6dbXS7UMIUoRvEzRndZbJoW92jsTDMnDOeJ 4np6CV6OsdD8DCmxfhdq18XAq5tbGPG5mD9P28vXWoZxpVziFfZFzDuXOP/Meo1i+NM3pex7Z/7e3 1i1Vdf6G7NLJmd7LUlxzNvwbx4LByY3bzRk90OmENcNnXG712mwVYnUYjqYsVLm29EO0jLMKjMrm0 LR0Pp6XejxjiGuVtONw1WSl6KIq/pfxMlkxMtplOrfbaEtoN6DnDKz8T3ydG41XG7397buYddyiPh ALL0S8IAw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jyynR-0003Hj-2I; Fri, 24 Jul 2020 14:35:37 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jyynA-0003DV-Oy for linux-arm-kernel@lists.infradead.org; Fri, 24 Jul 2020 14:35:21 +0000 Received: from localhost.localdomain (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D071C20674; Fri, 24 Jul 2020 14:35:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595601320; bh=ijOhZAWxzLhleVKNPuhFyU6KwAfe6z3uD2+snheMDy0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yiXEFGt7N8Cojz24AFxW3Ck5sT84Iy0+U4Uh5quzcZp6eNEg35lqlyEfDLc+j2I7k IKFr5SitXOPBrxiF7SE9OD5pD9eqNk+b8NuLTyHpuExHtqDEYnECiSOw/2G12ZIfdC 5H7DwJzFFyXVRQz2z8+VjsC13MS/P+EN04c1SaFc= From: Will Deacon To: kvmarm@lists.cs.columbia.edu Subject: [PATCH 4/7] KVM: arm64: Remove useless local variable Date: Fri, 24 Jul 2020 15:35:03 +0100 Message-Id: <20200724143506.17772-5-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200724143506.17772-1-will@kernel.org> References: <20200724143506.17772-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200724_103520_925846_6A621B89 X-CRM114-Status: GOOD ( 11.31 ) X-Spam-Score: -5.2 (-----) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-5.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [198.145.29.99 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Quentin Perret , kernel-team@android.com, Suzuki Poulose , James Morse , Marc Zyngier , Will Deacon , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 'is_iabt' is used exactly once in kvm_handle_guest_abort(). Remove it, and inlined its definition instead. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/mmu.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index ae17a99243e2..73e62d360a36 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -2064,14 +2064,13 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run) phys_addr_t fault_ipa; struct kvm_memory_slot *memslot; unsigned long hva; - bool is_iabt, write_fault, writable; + bool write_fault, writable; gfn_t gfn; int ret, idx; fault_status = kvm_vcpu_trap_get_fault_type(vcpu); fault_ipa = kvm_vcpu_get_fault_ipa(vcpu); - is_iabt = kvm_vcpu_trap_is_iabt(vcpu); /* Synchronous External Abort? */ if (kvm_vcpu_abt_is_extabt(vcpu)) { @@ -2105,7 +2104,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run) hva = gfn_to_hva_memslot_prot(memslot, gfn, &writable); write_fault = kvm_is_write_fault(vcpu); if (kvm_is_error_hva(hva) || (write_fault && !writable)) { - if (is_iabt) { + if (kvm_vcpu_trap_is_iabt(vcpu)) { /* Prefetch Abort on I/O address */ ret = -ENOEXEC; goto out; From patchwork Fri Jul 24 14:35:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 11683447 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 30607618 for ; Fri, 24 Jul 2020 14:37:09 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 08B8F2065C for ; Fri, 24 Jul 2020 14:37:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="z0VxXO27"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="KCelo5hc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 08B8F2065C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version: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=JVQ/THOZSOt6LRBhRWBAwnvu1VnfrDlMvRW+aPaWxFM=; b=z0VxXO27BBPEh41Yf5Yi+vYIB BdLziIVffLY0gdPjn2o20E+R4FMqGSBbUaj/yx4Zjvs/24/Z5XUMeTILYrWO76jvZlzLpUalyRVPF jt2cRZzyWTBjiwUDW+uQ4RSjoavg8T1NPKXnbY9YLj37dGc8eM5pxx29E8iFOu6qwN7BC67w5Qyc+ /nFWgmYnYmtGOsdI5iEs6s0EMcB9PWPNjqZjSKms+cjh95KmQQQJtsymyISGdIPuHMYKLxYafKwTD Ta/+mxrqCQxkVCBNELSjINIKsN006l5w3c0p2Rfq5UryouMU7x5lNla93jHa03Yq7lhFguGqOI9K6 flXa6vOtw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jyynU-0003IP-Ms; Fri, 24 Jul 2020 14:35:40 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jyynC-0003E3-Lj for linux-arm-kernel@lists.infradead.org; Fri, 24 Jul 2020 14:35:23 +0000 Received: from localhost.localdomain (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A56B420714; Fri, 24 Jul 2020 14:35:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595601322; bh=nRSup5oIqQmb2RxIWwmKIgwnUNAyLD5LZ4z565QIuW4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KCelo5hchAth+oQZaQ/g7s+9X9saqctfN4NO81m3gcJa4w01EYmMebeQ5kwJTZbVb 71w3pC5VFYzpYtLGbE5fIeEu4dM3CMv9h+458DpnGy3jZ1OZlxAvBLRMv2IoOzmFXq rqgxnA9BRTCWMsqhD94w96nTKoEOyl09P6RcsLX4= From: Will Deacon To: kvmarm@lists.cs.columbia.edu Subject: [PATCH 5/7] KVM: arm64: Move 'invalid syndrome' logic out of io_mem_abort() Date: Fri, 24 Jul 2020 15:35:04 +0100 Message-Id: <20200724143506.17772-6-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200724143506.17772-1-will@kernel.org> References: <20200724143506.17772-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200724_103522_895787_94901F31 X-CRM114-Status: GOOD ( 16.01 ) X-Spam-Score: -5.2 (-----) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-5.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [198.145.29.99 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Quentin Perret , kernel-team@android.com, Suzuki Poulose , James Morse , Marc Zyngier , Will Deacon , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org In preparation for handling stage-2 faults on stage-1 page-table walks earlier, move the 'invalid syndrome' logic out of io_mem_abort() and into its own function, which can be called from kvm_handle_guest_abort() directly. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/mmio.c | 22 ---------------------- arch/arm64/kvm/mmu.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/arch/arm64/kvm/mmio.c b/arch/arm64/kvm/mmio.c index b54ea5aa6c06..45a630e480e1 100644 --- a/arch/arm64/kvm/mmio.c +++ b/arch/arm64/kvm/mmio.c @@ -136,28 +136,6 @@ int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run, int len; u8 data_buf[8]; - /* - * No valid syndrome? Ask userspace for help if it has - * volunteered to do so, and bail out otherwise. - */ - if (!kvm_vcpu_dabt_isvalid(vcpu)) { - if (vcpu->kvm->arch.return_nisv_io_abort_to_user) { - run->exit_reason = KVM_EXIT_ARM_NISV; - run->arm_nisv.esr_iss = kvm_vcpu_dabt_iss_nisv_sanitized(vcpu); - run->arm_nisv.fault_ipa = fault_ipa; - return 0; - } - - kvm_pr_unimpl("Data abort outside memslots with no valid syndrome info\n"); - return -ENOSYS; - } - - /* Page table accesses IO mem: tell guest to fix its TTBR */ - if (kvm_vcpu_dabt_iss1tw(vcpu)) { - kvm_inject_dabt(vcpu, kvm_vcpu_get_hfar(vcpu)); - return 1; - } - /* * Prepare MMIO operation. First decode the syndrome data we get * from the CPU. Then try if some in-kernel emulation feels diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 73e62d360a36..adb933ecd177 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -2046,6 +2046,20 @@ static void handle_access_fault(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa) kvm_set_pfn_accessed(pfn); } +static int handle_error_invalid_dabt(struct kvm_vcpu *vcpu, struct kvm_run *run, + phys_addr_t fault_ipa) +{ + if (!vcpu->kvm->arch.return_nisv_io_abort_to_user) { + kvm_pr_unimpl("Data abort outside memslots with no valid syndrome info\n"); + return -ENOSYS; + } + + run->exit_reason = KVM_EXIT_ARM_NISV; + run->arm_nisv.esr_iss = kvm_vcpu_dabt_iss_nisv_sanitized(vcpu); + run->arm_nisv.fault_ipa = fault_ipa; + return 0; +} + /** * kvm_handle_guest_abort - handles all 2nd stage aborts * @vcpu: the VCPU pointer @@ -2133,6 +2147,21 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run) * of the page size. */ fault_ipa |= kvm_vcpu_get_hfar(vcpu) & ((1 << 12) - 1); + + /* + * No valid syndrome? Ask userspace for help if it has + * volunteered to do so, and bail out otherwise. + */ + if (!kvm_vcpu_dabt_isvalid(vcpu)) { + ret = handle_error_invalid_dabt(vcpu, run, fault_ipa); + goto out_unlock; + } + + if (kvm_vcpu_dabt_iss1tw(vcpu)) { + ret = -ENXIO; + goto out; + } + ret = io_mem_abort(vcpu, run, fault_ipa); goto out_unlock; } @@ -2153,6 +2182,9 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run) if (ret == -ENOEXEC) { kvm_inject_pabt(vcpu, kvm_vcpu_get_hfar(vcpu)); ret = 1; + } else if (ret == -ENXIO) { + kvm_inject_dabt(vcpu, kvm_vcpu_get_hfar(vcpu)); + ret = 1; } out_unlock: srcu_read_unlock(&vcpu->kvm->srcu, idx); From patchwork Fri Jul 24 14:35:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 11683449 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EB6B9618 for ; Fri, 24 Jul 2020 14:37:09 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C368D2065C for ; Fri, 24 Jul 2020 14:37:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ET09I6M2"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="pH6pshNX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C368D2065C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version: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=hIfmX4zqrj0UEIw15nhSa0yUM1SW40PLY3gCOzho3Ec=; b=ET09I6M2S12Z5otsCcwRfv4pf Zi6AZxhotMUIUUKn1c9g20GZVZucfEIF1k1iuDW3nHfm6sIAy1HwII/FDDtvRiniZ32RF6aZ/jUxW PLAtDpeqxD6zR+ozFFjo97go0LX+Au3JWPk76cDLi31XxRhO+G6ptmjJGyROKnKk2WuOU/hg5QqPS fF5qC1+/BHvPiNKmjEPwWi2ZIxI3r1MUVylmOqijRg5Ay+8Tc66Vg0jO84nKhngQfGHqyME+ZLKLz RYqe9kxqLjgI+SmEaVMAV5u7mkOYS37qu1CoatGVHhPoQ53rs2nvHZXQfbOwlT3QgnVPISMVZ4Mvb Zp/78qP6w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jyyna-0003K2-QE; Fri, 24 Jul 2020 14:35:46 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jyynE-0003Ef-Iv for linux-arm-kernel@lists.infradead.org; Fri, 24 Jul 2020 14:35:25 +0000 Received: from localhost.localdomain (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7A08A206F0; Fri, 24 Jul 2020 14:35:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595601323; bh=RIsZfSCZmrp/wPqTZvZHGiqd/TR+61Y5jeApU2sToMo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pH6pshNXOl66q6bN+6OAOkNvX7CEbYgEkUEf79c08LvqRTWh0ZuYyk16AxIUnHETF 2BktErnFvndXfPgMsWYW8y+QSVmikB0qTMfCvpjUkhlj70lPGgjX+uBQ/2yTl+byMF yTQogZqmhbRMLVPz/ryZ16m6ZXiDaksmJzSK+XEU= From: Will Deacon To: kvmarm@lists.cs.columbia.edu Subject: [PATCH 6/7] KVM: arm64: Handle stage-2 faults on stage-1 page-table walks earlier Date: Fri, 24 Jul 2020 15:35:05 +0100 Message-Id: <20200724143506.17772-7-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200724143506.17772-1-will@kernel.org> References: <20200724143506.17772-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200724_103524_776664_9E2CFDD2 X-CRM114-Status: GOOD ( 14.21 ) X-Spam-Score: -5.2 (-----) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-5.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [198.145.29.99 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Quentin Perret , kernel-team@android.com, Suzuki Poulose , James Morse , Marc Zyngier , Will Deacon , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Stage-2 faults on stage-1 page-table walks can occur on both the I-side and the D-side. It is IMPLEMENTATATION DEFINED whether they are reported as reads or writes and, in the case that they are generated by an AT instruction, they are reported with the CM bit set. All of this deeply confuses the logic in kvm_handle_guest_abort(); userspace may or may not see the fault, depending on whether it occurs on the data or the instruction side, and an AT instruction may be skipped if the translation tables are held in a read-only memslot. Move the handling of stage-2 faults on stage-1 page-table walks earlier so that they consistently result in either a data or an instruction abort being re-injected back to the guest. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/mmu.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index adb933ecd177..9e72e7f4a2c2 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -2124,6 +2124,11 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run) goto out; } + if (kvm_vcpu_dabt_iss1tw(vcpu)) { + ret = -ENXIO; + goto out; + } + /* * Check for a cache maintenance operation. Since we * ended-up here, we know it is outside of any memory @@ -2157,11 +2162,6 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run) goto out_unlock; } - if (kvm_vcpu_dabt_iss1tw(vcpu)) { - ret = -ENXIO; - goto out; - } - ret = io_mem_abort(vcpu, run, fault_ipa); goto out_unlock; } From patchwork Fri Jul 24 14:35:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 11683451 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 00A4A618 for ; Fri, 24 Jul 2020 14:37:28 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CBC81206D8 for ; Fri, 24 Jul 2020 14:37:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="V9ryF2iD"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="qh8oWoBa" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CBC81206D8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version: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=8F1tx56HGsKJczkIulw0ZusWS7T8YgHKIgnedu8ErbE=; b=V9ryF2iDgPO5t/jfz6gnSzgav /WhJaoUO1UY0Uubkrwl38Pu0GDVyGuSwrJBflIBHiewyhIjoCOe/d64CC0MLzLOBfeZe2iqP1m9jK Qw0tL41Vom/3uT9cfwTHB2ol9DlGxiEMCP1vItHI0PCGnIOyAUoRmNm3Ea+AdVIV9NrD85wTiIeSX 728k2sqwrodp383oCpVn3iWPOhnpeU7tAMmtBXhXKPxa6mlIPJkW7bY+aew7mDYAp1qjFlTY3d0nn nzMzFhcG0mZS0hX8ZGXZFWTBV19idiAQ1DWHPz82u2mBRh6Ge6O3ztFhwJFnPVn6wPBCvdiBQU4sx G/Lq4QPCg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jyynj-0003MT-R8; Fri, 24 Jul 2020 14:35:56 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jyynG-0003FK-8o for linux-arm-kernel@lists.infradead.org; Fri, 24 Jul 2020 14:35:28 +0000 Received: from localhost.localdomain (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4ECBB2065C; Fri, 24 Jul 2020 14:35:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595601325; bh=aH6+b9S0bxa9/SN+80CrqBVkxawU3zO7lLnHFqJKx/Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qh8oWoBa5d97kv/5Ec1xVKnU0c7jbVGRWvECJktcuh03XdNewjxMcBYP3kJZeQap5 ze1Ac6uT4dw0xZJk4hqEQvVSlsoVcdUlBCG1E99K3NqUPXc8Umc+42BEThUIAKNZCd ewtLa8hzzMldYszFp+8yn/9Fcf8wbqkfer26IgrA= From: Will Deacon To: kvmarm@lists.cs.columbia.edu Subject: [PATCH 7/7] KVM: arm64: Separate write faults on read-only memslots from MMIO Date: Fri, 24 Jul 2020 15:35:06 +0100 Message-Id: <20200724143506.17772-8-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200724143506.17772-1-will@kernel.org> References: <20200724143506.17772-1-will@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200724_103526_524280_FCC4AF01 X-CRM114-Status: GOOD ( 19.68 ) X-Spam-Score: -5.2 (-----) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-5.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [198.145.29.99 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Quentin Perret , kernel-team@android.com, Suzuki Poulose , James Morse , Marc Zyngier , Will Deacon , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Although taking a write-fault on a read-only memslot triggers an MMIO exit back to userspace, lumping the handling together in kvm_handle_guest_abort() causes some of the early triage to have weird effects on userspace. For example, if a guest generates a stage-2 fault on a stage-1 translation fault when trying to fetch an instruction from a read-only memslot, it will be mistakenly treated as an attempt to execute from MMIO and a prefetch abort will be re-injected into the guest. Separate the MMIO handling from the read-only memslot handling, so that the latter is left entirely up to userspace. Note that this _will_ result in more exits than before for read-only memslots, since userspace will now see some cache maintenance and instruction-side aborts. Cc: Marc Zyngier Cc: Quentin Perret Signed-off-by: Will Deacon --- arch/arm64/kvm/mmu.c | 45 ++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 9e72e7f4a2c2..2edc6f2412dc 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -2117,9 +2117,30 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run) memslot = gfn_to_memslot(vcpu->kvm, gfn); hva = gfn_to_hva_memslot_prot(memslot, gfn, &writable); write_fault = kvm_is_write_fault(vcpu); - if (kvm_is_error_hva(hva) || (write_fault && !writable)) { + + /* + * The IPA is reported as [MAX:12], so we need to complement it with + * the bottom 12 bits from the faulting VA. This is always 12 bits, + * irrespective of the page size. + */ + fault_ipa |= kvm_vcpu_get_hfar(vcpu) & ((1 << 12) - 1); + + /* + * We can perform some early fault triage based purely on the memslot + * information: + * + * Faults on IPAs falling outside of any memslot are re-injected + * into the guest as external aborts if they were either signalled as + * instruction aborts or as a stage-2 fault on a translation table walk. + * If the instruction was a cache maintenance instruction then it is + * quietly skipped, otherwise we exit to userspace for MMIO emulation. + * + * Write faults on IPAs falling within a read-only memslot are reported + * to userspace as MMIO exits. This includes cache maintenance and + * stage-2 faults on translation table walks, + */ + if (kvm_is_error_hva(hva)) { if (kvm_vcpu_trap_is_iabt(vcpu)) { - /* Prefetch Abort on I/O address */ ret = -ENOEXEC; goto out; } @@ -2129,30 +2150,12 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run) goto out; } - /* - * Check for a cache maintenance operation. Since we - * ended-up here, we know it is outside of any memory - * slot. But we can't find out if that is for a device, - * or if the guest is just being stupid. The only thing - * we know for sure is that this range cannot be cached. - * - * So let's assume that the guest is just being - * cautious, and skip the instruction. - */ if (kvm_vcpu_dabt_is_cm(vcpu)) { kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); ret = 1; goto out_unlock; } - /* - * The IPA is reported as [MAX:12], so we need to - * complement it with the bottom 12 bits from the - * faulting VA. This is always 12 bits, irrespective - * of the page size. - */ - fault_ipa |= kvm_vcpu_get_hfar(vcpu) & ((1 << 12) - 1); - /* * No valid syndrome? Ask userspace for help if it has * volunteered to do so, and bail out otherwise. @@ -2161,7 +2164,9 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run) ret = handle_error_invalid_dabt(vcpu, run, fault_ipa); goto out_unlock; } + } + if (kvm_is_error_hva(hva) || (write_fault && !writable)) { ret = io_mem_abort(vcpu, run, fault_ipa); goto out_unlock; }