From patchwork Fri Jan 18 14:07:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabiano Rosas X-Patchwork-Id: 10770333 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 3E8FF6C5 for ; Fri, 18 Jan 2019 14:09:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C9842E5FC for ; Fri, 18 Jan 2019 14:09:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 211582E617; Fri, 18 Jan 2019 14:09:49 +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.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 064602E5FC for ; Fri, 18 Jan 2019 14:09:47 +0000 (UTC) Received: from localhost ([127.0.0.1]:40095 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkUqA-0008S8-67 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 18 Jan 2019 09:09:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57409) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkUog-00074u-Lh for qemu-devel@nongnu.org; Fri, 18 Jan 2019 09:08:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gkUoe-0002R2-OZ for qemu-devel@nongnu.org; Fri, 18 Jan 2019 09:08:14 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:43934 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gkUoc-0002Kq-EB for qemu-devel@nongnu.org; Fri, 18 Jan 2019 09:08:11 -0500 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x0IDx2eG070042 for ; Fri, 18 Jan 2019 09:08:07 -0500 Received: from e12.ny.us.ibm.com (e12.ny.us.ibm.com [129.33.205.202]) by mx0a-001b2d01.pphosted.com with ESMTP id 2q3fn21tjw-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 18 Jan 2019 09:08:06 -0500 Received: from localhost by e12.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 18 Jan 2019 14:08:06 -0000 Received: from b01cxnp22034.gho.pok.ibm.com (9.57.198.24) by e12.ny.us.ibm.com (146.89.104.199) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 18 Jan 2019 14:08:02 -0000 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x0IE81RR8519768 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 18 Jan 2019 14:08:01 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A18D4112069; Fri, 18 Jan 2019 14:08:01 +0000 (GMT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B222A112061; Fri, 18 Jan 2019 14:07:59 +0000 (GMT) Received: from farosas.linux.ibm.com.br.ibm.com (unknown [9.86.26.66]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP; Fri, 18 Jan 2019 14:07:59 +0000 (GMT) From: Fabiano Rosas To: qemu-devel@nongnu.org Date: Fri, 18 Jan 2019 12:07:51 -0200 X-Mailer: git-send-email 2.17.1 X-TM-AS-GCONF: 00 x-cbid: 19011814-0060-0000-0000-000002FBD413 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010430; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000275; SDB=6.01148269; UDB=6.00598209; IPR=6.00928572; MB=3.00025187; MTD=3.00000008; XFM=3.00000015; UTC=2019-01-18 14:08:05 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19011814-0061-0000-0000-000047F8747B Message-Id: <20190118140758.829-1-farosas@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-01-18_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=799 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901180101 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [RFC PATCH v3 0/7] target/ppc: 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: crosthwaite.peter@gmail.com, aik@ozlabs.ru, cohuck@redhat.com, qemu-ppc@nongnu.org, pbonzini@redhat.com, david@gibson.dropbear.id.au, philmd@redhat.com, rth@twiddle.net 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. Supported scenarios: - Stepping of multiple vcpus; - GDB scheduler locking on and off [2]; - single stepping of kernel code with QEMU while stepping with GDB inside the guest (user space, KGDB). 1- PowerISA Section 6.5.15 - Trace Interrupt 2- https://sourceware.org/gdb/onlinedocs/gdb/All_002dStop-Mode.html v1 -> v2: - split in more patches to facilitate review - use extract32 for decoding instruction instead of open-coding - add more people to CC https://lists.gnu.org/archive/html/qemu-devel/2018-11/msg03738.html v2 -> v3: - take Alternate Interrupt Location (AIL) into consideration when calculating the Trace Interrupt handler address (this allows single stepping in SLOF code); - check for a new KVM_GUEST_DEBUG_SSTEP capability (still to be submitted to kernel ml); - handle other vcpus (not currently stepping) hitting the single step breakpoint - by ignoring the breakpoint; - handle simultaneous single step by GDB inside guest - by first performing our step into the trace interrupt handler itself and returning to the guest afterwards; - handle single stepping when at the first trace interrupt handler instruction - by displacing the breakpoint to the next instruction; - restore MSR, SRR0, SRR1 after the step, taking into consideration possible mtspr, mtmsr instructions; - use stubs for arch-specific code that will not be implemented by other architectures at this point; https://lists.gnu.org/archive/html/qemu-devel/2018-11/msg03738.html Fabiano Rosas (7): target/ppc: Move exception vector offset computation into a function target/ppc: Add ppc_get_trace_int_handler_addr kvm: support checking for single step capability kvm-all: Introduce kvm_set_singlestep target/ppc: Move handling of hardware breakpoints to a separate function target/ppc: Refactor kvm_handle_debug target/ppc: support single stepping with KVM HV accel/kvm/kvm-all.c | 16 ++ accel/stubs/kvm-stub.c | 4 + exec.c | 2 +- include/sysemu/kvm.h | 3 + stubs/Makefile.objs | 1 + stubs/kvm-arch-set-singlestep.c | 8 + target/ppc/cpu.h | 6 + target/ppc/excp_helper.c | 43 +++-- target/ppc/kvm.c | 297 ++++++++++++++++++++++++++------ 9 files changed, 314 insertions(+), 66 deletions(-) create mode 100644 stubs/kvm-arch-set-singlestep.c --- 2.17.1