From patchwork Mon Dec 4 14:03:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10090405 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 75AD260329 for ; Mon, 4 Dec 2017 14:09:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F9372842D for ; Mon, 4 Dec 2017 14:09:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5396428E3E; Mon, 4 Dec 2017 14:09:44 +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=-2.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_MED, URIBL_DBL_ABUSE_SPAM 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 C3FCD2842D for ; Mon, 4 Dec 2017 14:09:43 +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: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=3dsjvINVq5m4ZSg1eaQFqjiPivK6H1wE6wGiy72uzbM=; b=W4IbrkBsIIXwEc 3XpdfyYZs3O169FI+RRcvv3bq8vNP3yGsnk0InVBcWdDQFMJI7IEzF0YrwFYN+Rj5ynbkl344ttfU 1z30TAmIIy667CikjMqblFGXsNc3ZCZY+8IEV94AYFR/PkeAVsCBvX1oL9pFHmGR+Mb6AtwBGgUs+ gExI1CZ/JJz/CxJ8vbe8pbf+hNhRmcl2/cy6yOgGTGUTW87pcfEffxZ2AjW5rKR1+HaBOw1PHu3+A YJkpSwvmF3tTdTFyYs0xJ3mRPtdej/PYxjdWQP5d6IOGWHutZp6ZVYmU/6F3t/48+tzBVtsar91Jw k+tvQtDrYFmesi93OQDQ==; 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 1eLrR9-0008N6-KF; Mon, 04 Dec 2017 14:09:35 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eLrM8-0002PZ-I9 for linux-arm-kernel@lists.infradead.org; Mon, 04 Dec 2017 14:04:38 +0000 Received: by mail-wm0-x244.google.com with SMTP id r78so6020509wme.5 for ; Mon, 04 Dec 2017 06:04:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=christofferdall-dk.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JDUQfrY9hGrcsaLNtVfO3OaTJhgjUQDn3QeoprfDhgc=; b=Ynq/bgcogwJ/bXEUk8hW5tQZTZxJY0gV9t++XOndT5rKrIis/5HVVBy4arBS8VFMTX T9LXEfcK1m4geDC2+XiwNDkXziG0+honQ9pWbiklGCKZTogoew1PEV9CFSUnMBiatBvU LcHi84rUsda3GhrN639rF+0XmXfj+6Bm2SbP0+/ComdmVHkEzkrIYttBABWs7Tnetkot A/2gXzGuHzGEjSLwa10Txo7Xp4xNeYNr8a+NeO/2nGejP49py4/zpYGdYgYeFxNKusJs Ff5b11Wi+4mkeHrC59US+cRAVQ9wS4miSAmTNFXfgjseeaz4+SWzyHJtS5fds8EFa30L 4w1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=JDUQfrY9hGrcsaLNtVfO3OaTJhgjUQDn3QeoprfDhgc=; b=MLLkBqVSJWSp8ios6S46Oo04KyWl/oE+8bK0twicI998P3dBP/n1KxdMuQq47ZgjzQ 5Duj8J0SwLlKhiu+VPJsobbePHtSyLXJ9dvSpbcjnPFvGgrrItN0MMBoS5fTz5+sbJ85 aMMmYEPsWA5gLpxJpS8AlsmHjgU0f4BKlhO67BLCZcsr7CGSNGJBiCxnBwoFYvp05MwB 7Bo+wi3gi3JU9SChwvAxxDT4bDm/pRZB1qCU3kQqsnr3mfrnifs9OtA4bWEbNQA1vcJJ 4MNlS8ZlWKlQr7wKm2cQre4SJ+YNNi8vVb/PDVwX6sz+4zz3AKRh8bxkAb8kFy5t7bWZ 53Ug== X-Gm-Message-State: AKGB3mIytimm3ZWXxu/SfcquMWj9Hl4R6Uea3Ar6MVV0e+xBalx7nlGF Bx7dDRqD9Q1oyGkc1AThsttvHg== X-Google-Smtp-Source: AGs4zMa70c2mgc4efjUnLzAUiAOtkbdxi4BzQd6Q++x+/sASsnO0We8HTJmm30N4aybzN2dox3Tsqw== X-Received: by 10.28.165.130 with SMTP id o124mr3036931wme.124.1512396246855; Mon, 04 Dec 2017 06:04:06 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id g7sm22794279wra.38.2017.12.04.06.04.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Dec 2017 06:04:06 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PULL 14/19] kvm: arm64: handle single-step of hyp emulated mmio instructions Date: Mon, 4 Dec 2017 15:03:43 +0100 Message-Id: <20171204140348.21965-12-cdall@kernel.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171204135637.21620-1-cdall@kernel.org> References: <20171204135637.21620-1-cdall@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171204_060425_352503_C98C80AD X-CRM114-Status: GOOD ( 15.57 ) 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 , =?UTF-8?q?Alex=20Benn=C3=A9e?= , kvm@vger.kernel.org, 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 X-Virus-Scanned: ClamAV using ClamSMTP From: Alex Bennée There is a fast-path of MMIO emulation inside hyp mode. The handling of single-step is broadly the same as kvm_arm_handle_step_debug() except we just setup ESR/HSR so handle_exit() does the correct thing as we exit. For the case of an emulated illegal access causing an SError we will exit via the ARM_EXCEPTION_EL1_SERROR path in handle_exit(). We behave as we would during a real SError and clear the DBG_SPSR_SS bit for the emulated instruction. Acked-by: Marc Zyngier Reviewed-by: Christoffer Dall Signed-off-by: Alex Bennée Signed-off-by: Christoffer Dall --- arch/arm64/kvm/hyp/switch.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index 525c01f48867..f7c651f3a8c0 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -22,6 +22,7 @@ #include #include #include +#include static bool __hyp_text __fpsimd_enabled_nvhe(void) { @@ -269,7 +270,11 @@ static bool __hyp_text __populate_fault_info(struct kvm_vcpu *vcpu) return true; } -static void __hyp_text __skip_instr(struct kvm_vcpu *vcpu) +/* Skip an instruction which has been emulated. Returns true if + * execution can continue or false if we need to exit hyp mode because + * single-step was in effect. + */ +static bool __hyp_text __skip_instr(struct kvm_vcpu *vcpu) { *vcpu_pc(vcpu) = read_sysreg_el2(elr); @@ -282,6 +287,14 @@ static void __hyp_text __skip_instr(struct kvm_vcpu *vcpu) } write_sysreg_el2(*vcpu_pc(vcpu), elr); + + if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) { + vcpu->arch.fault.esr_el2 = + (ESR_ELx_EC_SOFTSTP_LOW << ESR_ELx_EC_SHIFT) | 0x22; + return false; + } else { + return true; + } } int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu) @@ -342,13 +355,21 @@ int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu) int ret = __vgic_v2_perform_cpuif_access(vcpu); if (ret == 1) { - __skip_instr(vcpu); - goto again; + if (__skip_instr(vcpu)) + goto again; + else + exit_code = ARM_EXCEPTION_TRAP; } if (ret == -1) { - /* Promote an illegal access to an SError */ - __skip_instr(vcpu); + /* Promote an illegal access to an + * SError. If we would be returning + * due to single-step clear the SS + * bit so handle_exit knows what to + * do after dealing with the error. + */ + if (!__skip_instr(vcpu)) + *vcpu_cpsr(vcpu) &= ~DBG_SPSR_SS; exit_code = ARM_EXCEPTION_EL1_SERROR; } @@ -363,8 +384,10 @@ int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu) int ret = __vgic_v3_perform_cpuif_access(vcpu); if (ret == 1) { - __skip_instr(vcpu); - goto again; + if (__skip_instr(vcpu)) + goto again; + else + exit_code = ARM_EXCEPTION_TRAP; } /* 0 falls through to be handled out of EL2 */