From patchwork Mon Nov 19 21:37:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabiano Rosas X-Patchwork-Id: 10689505 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 37B6E13AD for ; Mon, 19 Nov 2018 21:38:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2AFBE29786 for ; Mon, 19 Nov 2018 21:38:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1ECF6297A1; Mon, 19 Nov 2018 21:38:36 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9EDF629786 for ; Mon, 19 Nov 2018 21:38:35 +0000 (UTC) Received: from localhost ([::1]:59097 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gOrFa-0000Hs-P3 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 19 Nov 2018 16:38:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37323) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gOrEw-00089F-Mp for qemu-devel@nongnu.org; Mon, 19 Nov 2018 16:37:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gOrEt-0004RT-Iw for qemu-devel@nongnu.org; Mon, 19 Nov 2018 16:37:54 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:44310) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gOrEt-0004QW-Au for qemu-devel@nongnu.org; Mon, 19 Nov 2018 16:37:51 -0500 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wAJLXYf1042651 for ; Mon, 19 Nov 2018 16:37:49 -0500 Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) by mx0a-001b2d01.pphosted.com with ESMTP id 2nv4e0hwu7-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 19 Nov 2018 16:37:49 -0500 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 19 Nov 2018 21:37:48 -0000 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 19 Nov 2018 21:37:47 -0000 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wAJLbkx818284598 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 19 Nov 2018 21:37:46 GMT Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 28454BE051; Mon, 19 Nov 2018 21:37:46 +0000 (GMT) Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 04D44BE053; Mon, 19 Nov 2018 21:37:44 +0000 (GMT) Received: from farosas.linux.ibm.com.ibmmodules.com (unknown [9.85.157.103]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP; Mon, 19 Nov 2018 21:37:44 +0000 (GMT) From: Fabiano Rosas To: qemu-devel@nongnu.org Date: Mon, 19 Nov 2018 19:37:38 -0200 X-Mailer: git-send-email 2.17.1 X-TM-AS-GCONF: 00 x-cbid: 18111921-0020-0000-0000-00000E8C28EF X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010083; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000270; SDB=6.01119873; UDB=6.00581058; IPR=6.00899994; MB=3.00024237; MTD=3.00000008; XFM=3.00000015; UTC=2018-11-19 21:37:48 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18111921-0021-0000-0000-000063C4423E Message-Id: <20181119213739.773-1-farosas@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-11-19_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=31 spamscore=0 clxscore=1015 lowpriorityscore=31 mlxscore=0 impostorscore=0 mlxlogscore=496 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811190192 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [RFC PATCH 0/1] single step for KVM HV X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Single stepping via GDB/gdbstub is currently not working with KVM HV. When asking for a single step (stepi), KVM simply ignores the request and execution continues. This has the direct effect of breaking GDB's 'step', 'stepi', 'next', 'nexti' commands. The 'continue' command is also affected since continuing right after a breakpoint requires that GDB first perform a single step so that the breakpoint can be re-inserted before continuing - in this case the breakpoint is not re-inserted and it won't hit again. The issue here is that single stepping in POWER makes use of an interrupt (Trace Interrupt [1]) that does not reach the hypervisor, so while the single step would happen if properly triggered, it would not cause an exit to KVM so there would be no way of handing control back to GDB. Aside from that, the guest kernel is not prepared to deal with such an interrupt in kernel mode (when not using KGDB, or some other debugging facility) and it causes an Oops. This series implements a "software single step" approach that makes use of: i) the Trace Interrupt to perform the step inside the guest and ii) a breakpoint at the Trace Interrupt handler address to cause a vm exit (Emulation Assist) so that we can return control to QEMU. With (i), we basically get the single step for free, without having to discover what are the possible targets of instructions that divert execution. With (ii), we hide the single step from the guest and keep all of the step logic in QEMU. This was so far tested with single and multiple vcpus and with GDB scheduler locking on and off [2]. I have not fully explored yet the potential issues when using debuggers simultaneously inside and outside the guest, however I was able to single step the ptrace code while single stepping a userspace program inside the guest with GDB. I'm looking for feedback on the general approach before I develop this further. 1- PowerISA Section 6.5.15 - Trace Interrupt 2- https://sourceware.org/gdb/onlinedocs/gdb/All_002dStop-Mode.html Fabiano Rosas (1): target/ppc: support single stepping with KVM HV accel/kvm/kvm-all.c | 10 +++++++ exec.c | 1 + include/sysemu/kvm.h | 4 +++ target/arm/kvm.c | 4 +++ target/i386/kvm.c | 4 +++ target/ppc/kvm.c | 65 +++++++++++++++++++++++++++++++++++++++++++- target/s390x/kvm.c | 4 +++ 7 files changed, 91 insertions(+), 1 deletion(-) --- 2.17.1