From patchwork Mon Dec 4 14:03:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10090399 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 CDB1360329 for ; Mon, 4 Dec 2017 14:08:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B7A95291CE for ; Mon, 4 Dec 2017 14:08:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B647E291F1; Mon, 4 Dec 2017 14:08:38 +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 E447B291CE for ; Mon, 4 Dec 2017 14:08:37 +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=iGpbRGd5JQQCTfdnAgbv53dydIIJuwTLLjER9m38KSs=; b=SAPKzgUAwDnSQP 0Qrk+wybCmjCRe2jfTOUO+Pv1DaMBlzuTQn3BYcz6MmjD2CW2C9vDt0T5/iQuplo0HFCOmH8ABIgN LyLd8AzvD+yDVQ0QE3rRlwHqm6fg4McRhpzWk6hsCbVWEqJPV/GvSSfTKjSOWywj1zT7tOKV8F6nf Uni4c87BKZpqJlDmdXqImBYEy0HfcSK/75Yc1MHSLlBIdTwLq87JFlkxoRvBelWf7wxVKI4aqIVVD h5cTk0Sjb1L6PCz3JwBo1e8J7uGIaZe5Y6j8LR9ez7roFivLm5Z1shozL9SYOdRZJ/O1cUvWFNsiE fiQFhdVPeIPhqS8Oy9+A==; 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 1eLrQD-0007ht-AN; Mon, 04 Dec 2017 14:08:37 +0000 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eLrM7-0002PI-4j for linux-arm-kernel@lists.infradead.org; Mon, 04 Dec 2017 14:04:36 +0000 Received: by mail-wr0-x241.google.com with SMTP id h1so17377968wre.12 for ; Mon, 04 Dec 2017 06:04:04 -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=6oFHdsRBEi2ZKsyImyoKk9oj8yj+3hFnyemX8H9M3Ss=; b=rady7uM/8zjiRfiuGtDwjUOpiQllpbuS12SVFx0SuW9vQHpYE5nW00dtqga2iumeII wYhH0V/itJaMEKJ0BiWcsz7QwOtNL8GUfgpsbhcYCq6kZ++dlay/m6/6CxAnJ3hz29vt HHVsGkLZv9RKtTbealbZF3CMivGfdEef1AomsMXE3giUedheWFZ/OYwLXHn0o6A7YJIn 8QgYR0Zeyjf6gnyxgcTqhY/9YWtYYPwYscbLoBcCC5LSIHVX45RO5TfmDiA1WFb1FauQ MqhJYYoAxj8dHNWM35y2Vna7ega8+82tH57vnGgfamSxWDKnyHqQT/Ih/7X9nfqorX6P AWDw== 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=6oFHdsRBEi2ZKsyImyoKk9oj8yj+3hFnyemX8H9M3Ss=; b=O7scj9KK1Sl90bK44J9wxUxdm4+3ZsGmIq+3jAddfkbkGrt0JUJrI9xR2hWoMmknAH o4A8fS4qwfs5trNKNgv2C7pAThmDoMXXAnOl6yJ1v2ft4TY3me8uc93Yr9xlHPqrlYB4 gjVRXkrvyW1aB+w/TQb0BxBgUQ0ucQLAd3EgC4vBB2SHd5ELtx59ZFOqrJpemgLiV1eT 3olwXVhzBeUYxsMFRbQgwhHWKjewQsoLoLjXHqAyYdcCAnxPrMnnW5PnDDps0+qSZqB8 KNpoIhkDdxLgb5Ccst857BJqC58Dv6OSBXVjytvvZJWqYaE8Y0uJNLB6N/x5w5+QjmvT WQFQ== X-Gm-Message-State: AKGB3mI217FFTjQIpkO5IMiUZhQcdjxUTQO7FbbP7ZHPxJeJj4ZhDKtH UYzEz2uwI39NaGi6xJeB+io7gekyzj8= X-Google-Smtp-Source: AGs4zMbpQ7ceIR3zq8ZzLVjLLI3mqMQX3VNy1v5s2y5VQu47VrLiCMJ5CvYUKddcTbR3HL9XmWsw/w== X-Received: by 10.223.158.203 with SMTP id b11mr1795186wrf.82.1512396242727; Mon, 04 Dec 2017 06:04:02 -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.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Dec 2017 06:04:01 -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 11/19] kvm: arm64: handle single-stepping trapped instructions Date: Mon, 4 Dec 2017 15:03:40 +0100 Message-Id: <20171204140348.21965-9-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_060424_093762_73629772 X-CRM114-Status: GOOD ( 15.62 ) 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 If we are using guest debug to single-step the guest, we need to ensure that we exit after emulating the instruction. This only affects instructions completely emulated by the kernel. For instructions emulated in userspace, we need to exit and return to complete the emulation. The kvm_arm_handle_step_debug() helper sets up the necessary exit state if needed. Signed-off-by: Alex Bennée Reviewed-by: Julien Thierry Signed-off-by: Christoffer Dall --- arch/arm64/kvm/handle_exit.c | 49 +++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index b71247995469..029c28dd25e9 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -186,6 +186,40 @@ static exit_handle_fn kvm_get_exit_handler(struct kvm_vcpu *vcpu) return arm_exit_handlers[hsr_ec]; } +/* + * We may be single-stepping an emulated instruction. If the emulation + * has been completed in the kernel, we can return to userspace with a + * KVM_EXIT_DEBUG, otherwise userspace needs to complete its + * emulation first. + */ +static int handle_trap_exceptions(struct kvm_vcpu *vcpu, struct kvm_run *run) +{ + int handled; + + /* + * See ARM ARM B1.14.1: "Hyp traps on instructions + * that fail their condition code check" + */ + if (!kvm_condition_valid(vcpu)) { + kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); + handled = 1; + } else { + exit_handle_fn exit_handler; + + exit_handler = kvm_get_exit_handler(vcpu); + handled = exit_handler(vcpu, run); + } + + /* + * kvm_arm_handle_step_debug() sets the exit_reason on the kvm_run + * structure if we need to return to userspace. + */ + if (handled > 0 && kvm_arm_handle_step_debug(vcpu, run)) + handled = 0; + + return handled; +} + /* * Return > 0 to return to guest, < 0 on error, 0 (and set exit_reason) on * proper exit to userspace. @@ -193,8 +227,6 @@ static exit_handle_fn kvm_get_exit_handler(struct kvm_vcpu *vcpu) int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run, int exception_index) { - exit_handle_fn exit_handler; - if (ARM_SERROR_PENDING(exception_index)) { u8 hsr_ec = ESR_ELx_EC(kvm_vcpu_get_hsr(vcpu)); @@ -222,18 +254,7 @@ int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run, kvm_inject_vabt(vcpu); return 1; case ARM_EXCEPTION_TRAP: - /* - * See ARM ARM B1.14.1: "Hyp traps on instructions - * that fail their condition code check" - */ - if (!kvm_condition_valid(vcpu)) { - kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); - return 1; - } - - exit_handler = kvm_get_exit_handler(vcpu); - - return exit_handler(vcpu, run); + return handle_trap_exceptions(vcpu, run); case ARM_EXCEPTION_HYP_GONE: /* * EL2 has been reset to the hyp-stub. This happens when a guest