From nobody Thu May 2 08:59:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617288251; cv=none; d=zohomail.com; s=zohoarc; b=fiarN/oRhv7vq6mpiBatngVB6L6uGTAGcNvpSttwynygW+6QVLzSOTcVbQMZ+r4DxxI1+scfWI+3j2trveQjLNy8CEar439MUb0edYhlq7t5HDMojSDg1fGmaEQXIj1aif86+RrgadPOuGujyqF5tP0aspTIogBWW3UbfDlfDL8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617288251; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rU3RIc7ZbPs0ZRexkYqTMuHou64+ARL6X0Qz2sJLr4c=; b=hJ+ObXotsWpUmCkqan8Lv95YyvBVyYz07LxdkrYsaYJYhs9IEin9eZ6rSsZJOx44a3qQ2rq3b1SKiQ1A+X6AieabyJHVRcVnZdh0/L/TcioM1Bo2KOgZdY/C8hP5a2B7WF9GWJnDcFir8Jc5mGEkYk10RpJwbHV1oEdQnnShDqM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617288251001139.16581262277884; Thu, 1 Apr 2021 07:44:11 -0700 (PDT) Received: from localhost ([::1]:33318 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lRyYL-0000wK-Le for importer@patchew.org; Thu, 01 Apr 2021 10:44:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33862) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRyWS-00005C-CH for qemu-devel@nongnu.org; Thu, 01 Apr 2021 10:42:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:22364) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRyWM-00078N-QL for qemu-devel@nongnu.org; Thu, 01 Apr 2021 10:42:11 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-198-CuC3XtW2Mw2ABQ37Qga5OQ-1; Thu, 01 Apr 2021 10:42:02 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CEE24817473; Thu, 1 Apr 2021 14:41:57 +0000 (UTC) Received: from localhost.localdomain (unknown [10.35.206.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD7245D6B1; Thu, 1 Apr 2021 14:41:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617288125; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rU3RIc7ZbPs0ZRexkYqTMuHou64+ARL6X0Qz2sJLr4c=; b=BcW6lUDy8Xk59OPcqCLTarLcExGVnRSMg+4906qAapsQYOA8sk0YP2m+YDR3BKXxzcBsL7 scAN3q+3fbT4etHzd/mSTE1gJsbJbae7aTTk66zNoie9syuTpjuiD0qM4lHwTTBF7/33+Z 8GEh7CXiA18IxpfZ4YxGM9TY7elHbqw= X-MC-Unique: CuC3XtW2Mw2ABQ37Qga5OQ-1 From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH 1/2] kvm: update kernel headers for KVM_GUESTDBG_BLOCKEVENTS Date: Thu, 1 Apr 2021 17:41:51 +0300 Message-Id: <20210401144152.1031282-2-mlevitsk@redhat.com> In-Reply-To: <20210401144152.1031282-1-mlevitsk@redhat.com> References: <20210401144152.1031282-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=mlevitsk@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Cornelia Huck , Maxim Levitsky , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Maxim Levitsky --- linux-headers/asm-x86/kvm.h | 2 ++ linux-headers/linux/kvm.h | 1 + 2 files changed, 3 insertions(+) diff --git a/linux-headers/asm-x86/kvm.h b/linux-headers/asm-x86/kvm.h index 8e76d3701d..33878cdc34 100644 --- a/linux-headers/asm-x86/kvm.h +++ b/linux-headers/asm-x86/kvm.h @@ -281,6 +281,8 @@ struct kvm_debug_exit_arch { #define KVM_GUESTDBG_USE_HW_BP 0x00020000 #define KVM_GUESTDBG_INJECT_DB 0x00040000 #define KVM_GUESTDBG_INJECT_BP 0x00080000 +#define KVM_GUESTDBG_BLOCKIRQ 0x00100000 + =20 /* for KVM_SET_GUEST_DEBUG */ struct kvm_guest_debug_arch { diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h index 020b62a619..2ded7a0630 100644 --- a/linux-headers/linux/kvm.h +++ b/linux-headers/linux/kvm.h @@ -1056,6 +1056,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_ENFORCE_PV_FEATURE_CPUID 190 #define KVM_CAP_SYS_HYPERV_CPUID 191 #define KVM_CAP_DIRTY_LOG_RING 192 +#define KVM_CAP_SET_GUEST_DEBUG2 195 =20 #ifdef KVM_CAP_IRQ_ROUTING =20 --=20 2.26.2 From nobody Thu May 2 08:59:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617288257; cv=none; d=zohomail.com; s=zohoarc; b=aTZ1/wRBV2PAlGQHIqRIXSe2nWQvMFqpbjkmcUpSsIZ1e1akOqJ99D6//lHdeUfcLs1hN95Q9D81rDRWFybMQcmWSZkWyT8+CT9cdGRjvL6BSziIlgWDyweoFo8ZBDIrub4xlv3ZXfQV55lH5XGpL9kJNVEHVGDKeileqY4PWBI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617288257; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8e4Bei7nicGbpDHe18wJ0ubAsMrHPj23eP+6cLOjdQU=; b=UjKTCl5jWMw8DN4kGa/WwtB1HHaEfWwUrT14/JsMzyywzZSvwNXlreGJQ7mmUK4an1jfVVOuB2fnaDpJT+FfBShIfhzktOvVfujFSDvsHeUvguC8/u1minzf54/tb1idEQHhQR4z96hostoVGDbWG5AsPdRz83cqM4U2+IK8q+A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161728825775751.159736389900445; Thu, 1 Apr 2021 07:44:17 -0700 (PDT) Received: from localhost ([::1]:33456 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lRyYS-0000ze-GX for importer@patchew.org; Thu, 01 Apr 2021 10:44:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33896) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRyWS-00005I-Ts for qemu-devel@nongnu.org; Thu, 01 Apr 2021 10:42:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26776) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRyWM-000786-Vy for qemu-devel@nongnu.org; Thu, 01 Apr 2021 10:42:12 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-529-6E2G0mzBPKilfDw9EZDSIg-1; Thu, 01 Apr 2021 10:42:03 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4C51B1072420; Thu, 1 Apr 2021 14:42:00 +0000 (UTC) Received: from localhost.localdomain (unknown [10.35.206.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A49D5D6B1; Thu, 1 Apr 2021 14:41:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617288125; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8e4Bei7nicGbpDHe18wJ0ubAsMrHPj23eP+6cLOjdQU=; b=C/eZ1MtD7Lb3CVzEOI16zlLHsxmrxL5OztAy2SJM5vq4tOGfnzH6euiZP/iLqoZQrvvm8U BxSpFE0B+a0EXIFbHxF5r/VP5eKIf7BNJ0noGGYI+T+48EG4MbRs7e1YTUKw+y8Sy0pzGQ UdthcAPf8TQkNoJUGLG5aRmMZKuMEFs= X-MC-Unique: 6E2G0mzBPKilfDw9EZDSIg-1 From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH 2/2] gdbstub: implement NOIRQ support for single step on KVM, when kvm's KVM_GUESTDBG_BLOCKIRQ debug flag is supported. Date: Thu, 1 Apr 2021 17:41:52 +0300 Message-Id: <20210401144152.1031282-3-mlevitsk@redhat.com> In-Reply-To: <20210401144152.1031282-1-mlevitsk@redhat.com> References: <20210401144152.1031282-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=mlevitsk@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Cornelia Huck , Maxim Levitsky , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Maxim Levitsky --- accel/kvm/kvm-all.c | 25 +++++++++++++++++++ gdbstub.c | 59 ++++++++++++++++++++++++++++++++++++-------- include/sysemu/kvm.h | 13 ++++++++++ 3 files changed, 87 insertions(+), 10 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index b6d9f92f15..bc7955fb19 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -147,6 +147,8 @@ bool kvm_vm_attributes_allowed; bool kvm_direct_msi_allowed; bool kvm_ioeventfd_any_length_allowed; bool kvm_msi_use_devid; +bool kvm_has_guest_debug; +int kvm_sstep_flags; static bool kvm_immediate_exit; static hwaddr kvm_max_slot_size =3D ~0; =20 @@ -2186,6 +2188,25 @@ static int kvm_init(MachineState *ms) kvm_ioeventfd_any_length_allowed =3D (kvm_check_extension(s, KVM_CAP_IOEVENTFD_ANY_LENGTH) > 0); =20 + kvm_has_guest_debug =3D + (kvm_check_extension(s, KVM_CAP_SET_GUEST_DEBUG) > 0); + + kvm_sstep_flags =3D 0; + + if (kvm_has_guest_debug) { + /* Assume that single stepping is supported */ + kvm_sstep_flags =3D SSTEP_ENABLE; + + int guest_debug_flags =3D + kvm_check_extension(s, KVM_CAP_SET_GUEST_DEBUG2); + + if (guest_debug_flags > 0) { + if (guest_debug_flags & KVM_GUESTDBG_BLOCKIRQ) { + kvm_sstep_flags |=3D SSTEP_NOIRQ; + } + } + } + kvm_state =3D s; =20 ret =3D kvm_arch_init(ms, s); @@ -2796,6 +2817,10 @@ int kvm_update_guest_debug(CPUState *cpu, unsigned l= ong reinject_trap) =20 if (cpu->singlestep_enabled) { data.dbg.control |=3D KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_SINGLESTE= P; + + if (cpu->singlestep_enabled & SSTEP_NOIRQ) { + data.dbg.control |=3D KVM_GUESTDBG_BLOCKIRQ; + } } kvm_arch_update_guest_debug(cpu, &data.dbg); =20 diff --git a/gdbstub.c b/gdbstub.c index 054665e93e..f789ded99d 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -369,12 +369,11 @@ typedef struct GDBState { gdb_syscall_complete_cb current_syscall_cb; GString *str_buf; GByteArray *mem_buf; + int sstep_flags; + int supported_sstep_flags; } GDBState; =20 -/* By default use no IRQs and no timers while single stepping so as to - * make single stepping like an ICE HW step. - */ -static int sstep_flags =3D SSTEP_ENABLE|SSTEP_NOIRQ|SSTEP_NOTIMER; +static GDBState gdbserver_state; =20 /* Retrieves flags for single step mode. */ static int get_sstep_flags(void) @@ -386,11 +385,10 @@ static int get_sstep_flags(void) if (replay_mode !=3D REPLAY_MODE_NONE) { return SSTEP_ENABLE; } else { - return sstep_flags; + return gdbserver_state.sstep_flags; } } =20 -static GDBState gdbserver_state; =20 static void init_gdbserver_state(void) { @@ -400,6 +398,23 @@ static void init_gdbserver_state(void) gdbserver_state.str_buf =3D g_string_new(NULL); gdbserver_state.mem_buf =3D g_byte_array_sized_new(MAX_PACKET_LENGTH); gdbserver_state.last_packet =3D g_byte_array_sized_new(MAX_PACKET_LENG= TH + 4); + + + if (kvm_enabled()) { + gdbserver_state.supported_sstep_flags =3D kvm_get_supported_sstep_= flags(); + } else { + gdbserver_state.supported_sstep_flags =3D + SSTEP_ENABLE | SSTEP_NOIRQ | SSTEP_NOTIMER; + } + + /* + * By default use no IRQs and no timers while single stepping so as to + * make single stepping like an ICE HW step. + */ + + gdbserver_state.sstep_flags =3D SSTEP_ENABLE | SSTEP_NOIRQ | SSTEP_NOT= IMER; + gdbserver_state.sstep_flags &=3D gdbserver_state.supported_sstep_flags; + } =20 #ifndef CONFIG_USER_ONLY @@ -2023,24 +2038,43 @@ static void handle_v_commands(GdbCmdContext *gdb_ct= x, void *user_ctx) =20 static void handle_query_qemu_sstepbits(GdbCmdContext *gdb_ctx, void *user= _ctx) { - g_string_printf(gdbserver_state.str_buf, "ENABLE=3D%x,NOIRQ=3D%x,NOTIM= ER=3D%x", - SSTEP_ENABLE, SSTEP_NOIRQ, SSTEP_NOTIMER); + g_string_printf(gdbserver_state.str_buf, "ENABLE=3D%x", SSTEP_ENABLE); + + if (gdbserver_state.supported_sstep_flags & SSTEP_NOIRQ) { + g_string_append_printf(gdbserver_state.str_buf, ",NOIRQ=3D%x", + SSTEP_NOIRQ); + } + + if (gdbserver_state.supported_sstep_flags & SSTEP_NOTIMER) { + g_string_append_printf(gdbserver_state.str_buf, ",NOTIMER=3D%x", + SSTEP_NOTIMER); + } + put_strbuf(); } =20 static void handle_set_qemu_sstep(GdbCmdContext *gdb_ctx, void *user_ctx) { + int new_sstep_flags; if (!gdb_ctx->num_params) { return; } =20 - sstep_flags =3D gdb_ctx->params[0].val_ul; + new_sstep_flags =3D gdb_ctx->params[0].val_ul; + + if (new_sstep_flags & ~gdbserver_state.supported_sstep_flags) { + put_packet("E22"); + return; + } + + gdbserver_state.sstep_flags =3D new_sstep_flags; put_packet("OK"); } =20 static void handle_query_qemu_sstep(GdbCmdContext *gdb_ctx, void *user_ctx) { - g_string_printf(gdbserver_state.str_buf, "0x%x", sstep_flags); + g_string_printf(gdbserver_state.str_buf, "0x%x", + gdbserver_state.sstep_flags); put_strbuf(); } =20 @@ -3499,6 +3533,11 @@ int gdbserver_start(const char *device) return -1; } =20 + if (kvm_enabled() && !kvm_supports_guest_debug()) { + error_report("gdbstub: KVM doesn't support guest debugging"); + return -1; + } + if (!device) return -1; if (strcmp(device, "none") !=3D 0) { diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index a1ab1ee12d..42f9ce6344 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -46,6 +46,8 @@ extern bool kvm_readonly_mem_allowed; extern bool kvm_direct_msi_allowed; extern bool kvm_ioeventfd_any_length_allowed; extern bool kvm_msi_use_devid; +extern bool kvm_has_guest_debug; +extern int kvm_sstep_flags; =20 #define kvm_enabled() (kvm_allowed) /** @@ -167,6 +169,17 @@ extern bool kvm_msi_use_devid; */ #define kvm_msi_devid_required() (kvm_msi_use_devid) =20 +/* + * Does KVM support guest debugging + */ +#define kvm_supports_guest_debug() (kvm_has_guest_debug) + +/* + * kvm_supported_sstep_flags + * Returns: SSTEP_* flags that KVM supports for guest debug + */ +#define kvm_get_supported_sstep_flags() (kvm_sstep_flags) + #else =20 #define kvm_enabled() (0) --=20 2.26.2