From patchwork Tue Oct 4 13:01:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 612231 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp171736pvb; Tue, 4 Oct 2022 06:27:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5kUbbNHqsNz1YHBDDaKWlq6xAFQ2RVnguALphR2WVIG24eOklXqYI/X6jnJngaBeMftvML X-Received: by 2002:a05:620a:4046:b0:6e1:14b0:86fd with SMTP id i6-20020a05620a404600b006e114b086fdmr576604qko.536.1664890022291; Tue, 04 Oct 2022 06:27:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664890022; cv=none; d=google.com; s=arc-20160816; b=vX6zWiKqbJfWa91lSiYF8uPcJqVAxi/NpjrfSNdi1DJPLltfM65AFFPmKukcGY7UuF 1xfdJ1kUEFOahf+ao/3bK7XjOQqG1jEaohWZNri6lQQyygtJR8s3POZPYMIYLlDsXkjj p4ZhUCmSduUM2q7w3VjFdfu8LOlFtnccUjiHQ8Kc/D9glPXT1/qK3DYW4YkWI5HqXvg+ kxwbsNzCuSq/e2eSKHLt85yUjbfsFabDcMpPIRyR79G0QsM0jcsj72b2z1buedjy4Kgu fbaKt0HfoGhaPJOzo9R6srCbWL+w6dcv6EI+Ol7Z3FJCHZkTjz0QXBFTiUlMoglFmGlF IDgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=C1NyWOfmsPZQD10r7UbPdctd03es5mAxTm6eeJpepGU=; b=acUQu8ItfkTPxYeEId6kWYCRgvebWqDiMfxaFuaRMpkHImVOUUktqgs7oVLKieGwhh vBuCCUwrEJQCDk6lpjEXkwnw45zLFobvbB3gHKT+05avLMyIIaLnucZIgBZfGyL6OACZ Mhs7g5cwtGrprJX2yBwBy5XRvKGHgmfO9kH+jW89+O51DYOK90xmD700USeQAfrkSxjN NneQOs8hE+r2xYwEESeBI2gjJjoDwzUdWaSI8fV35jZ6lFxhAwxGITXlygC++c9AxJYx 2KNuVRLzAGS+fAkVh6X3UmgK/F8mbVBvMEqGi9Xi7DaO1Jk0GgByjh/JxGhLPxRyvzPr MiKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gPYP2Pph; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q8-20020a056214194800b004b181af6156si991154qvk.208.2022.10.04.06.27.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Oct 2022 06:27:02 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gPYP2Pph; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54216 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofhwr-0008Dx-QM for patch@linaro.org; Tue, 04 Oct 2022 09:27:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54794) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofhgN-0007NV-7X for qemu-devel@nongnu.org; Tue, 04 Oct 2022 09:09:59 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]:45989) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ofhgK-00008R-Op for qemu-devel@nongnu.org; Tue, 04 Oct 2022 09:09:58 -0400 Received: by mail-wr1-x436.google.com with SMTP id a10so8903151wrm.12 for ; Tue, 04 Oct 2022 06:09:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=C1NyWOfmsPZQD10r7UbPdctd03es5mAxTm6eeJpepGU=; b=gPYP2PphyxFCnruzFlPldrHhv49mwao1pKlrmzA4ShnYKCDnoGKF0kI1xvj6FxGc80 +5Cnu0OToTBkSLvLa3sqPA71ybvfAuAPekFostEJf9mnuklUYwBB6HbTap6FnjCCijb2 V97qAHtZXwfQZqy/Euf65bPN6dN2P1K/Mabx+UxTsat/1Fzo/BNQT2qzw6X+kn/hV7N8 vIwfyXCnjAkrzc37ZPNl1N+VXZUAxcCrO8Tz6yhSRk/FpU4EHCZc7xhomsLO/qc24L7d hjMArAAXTs5HOWfM6QojHvtfABWSPmH/rHogfmTRKvH0Hi8jq2b4A/0rtSaX/qVK5aTu st7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=C1NyWOfmsPZQD10r7UbPdctd03es5mAxTm6eeJpepGU=; b=H+pRMkeby5YNGb024VHhs67cpVvI8VPOt5S6q9oPkB4GZ3x6kynZfE67v42Ux5ZeyW 4LOhn35nM+iiUP6Y18Fv8oRb6I/3dInwefJ1PRevAYVQFmFrsyKBdrr4XqkAj0WQqO42 CN7y0hWyeSs5WEj41mh4qQa7h1bQuw6bCAqWjNqTSNPV082p/WONOj3xtnbjP35fMrmX p9VDvnkFD25fcsfvczSiO2UXKETK7wwLvJU81W+Y5tyDNujlP0p7FeXzS7ofTc+CdnuU DUcwvAK0J0IghZTxsjSkKt/mOuEpxoi6I+APT8z2Eqear33r3Ijln/5eAGrfWYuMlaBs 7Amg== X-Gm-Message-State: ACrzQf0atXTdEMGBtPuiutNrHbAWMiXZ7e8xV5VqEproRI40pchlR8SD 2VqUmnIzodLmIm2zmAOkVyWwUA== X-Received: by 2002:a5d:6d8e:0:b0:22a:4831:e0e with SMTP id l14-20020a5d6d8e000000b0022a48310e0emr15296668wrs.442.1664888993995; Tue, 04 Oct 2022 06:09:53 -0700 (PDT) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id l4-20020a7bc444000000b003b339438733sm14273999wmi.19.2022.10.04.06.09.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 06:09:51 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 958DF1FFE0; Tue, 4 Oct 2022 14:01:43 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Mads Ynddal , Paolo Bonzini , Richard Henderson , kvm@vger.kernel.org (open list:Overall KVM CPUs) Subject: [PULL 45/54] gdbstub: move guest debug support check to ops Date: Tue, 4 Oct 2022 14:01:29 +0100 Message-Id: <20221004130138.2299307-46-alex.bennee@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004130138.2299307-1-alex.bennee@linaro.org> References: <20221004130138.2299307-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x436.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This removes the final hard coding of kvm_enabled() in gdbstub and moves the check to an AccelOps. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Alex Bennée Reviewed-by: Mads Ynddal Message-Id: <20220929114231.583801-46-alex.bennee@linaro.org> diff --git a/accel/kvm/kvm-cpus.h b/accel/kvm/kvm-cpus.h index 33e435d62b..fd63fe6a59 100644 --- a/accel/kvm/kvm-cpus.h +++ b/accel/kvm/kvm-cpus.h @@ -18,6 +18,7 @@ void kvm_destroy_vcpu(CPUState *cpu); void kvm_cpu_synchronize_post_reset(CPUState *cpu); void kvm_cpu_synchronize_post_init(CPUState *cpu); void kvm_cpu_synchronize_pre_loadvm(CPUState *cpu); +bool kvm_supports_guest_debug(void); int kvm_insert_breakpoint(CPUState *cpu, int type, hwaddr addr, hwaddr len); int kvm_remove_breakpoint(CPUState *cpu, int type, hwaddr addr, hwaddr len); void kvm_remove_all_breakpoints(CPUState *cpu); diff --git a/gdbstub/internals.h b/gdbstub/internals.h index 41e2e72dbf..eabb0341d1 100644 --- a/gdbstub/internals.h +++ b/gdbstub/internals.h @@ -9,6 +9,7 @@ #ifndef _INTERNALS_H_ #define _INTERNALS_H_ +bool gdb_supports_guest_debug(void); int gdb_breakpoint_insert(CPUState *cs, int type, hwaddr addr, hwaddr len); int gdb_breakpoint_remove(CPUState *cs, int type, hwaddr addr, hwaddr len); void gdb_breakpoint_remove_all(CPUState *cs); diff --git a/include/sysemu/accel-ops.h b/include/sysemu/accel-ops.h index 86794ac273..8cc7996def 100644 --- a/include/sysemu/accel-ops.h +++ b/include/sysemu/accel-ops.h @@ -47,6 +47,7 @@ struct AccelOpsClass { int64_t (*get_elapsed_ticks)(void); /* gdbstub hooks */ + bool (*supports_guest_debug)(void); int (*insert_breakpoint)(CPUState *cpu, int type, hwaddr addr, hwaddr len); int (*remove_breakpoint)(CPUState *cpu, int type, hwaddr addr, hwaddr len); void (*remove_all_breakpoints)(CPUState *cpu); diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index 21d3f1d01e..6e1bd01725 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -46,7 +46,6 @@ 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; #define kvm_enabled() (kvm_allowed) /** @@ -168,11 +167,6 @@ extern bool kvm_has_guest_debug; */ #define kvm_msi_devid_required() (kvm_msi_use_devid) -/* - * Does KVM support guest debugging - */ -#define kvm_supports_guest_debug() (kvm_has_guest_debug) - #else #define kvm_enabled() (0) @@ -190,7 +184,6 @@ extern bool kvm_has_guest_debug; #define kvm_direct_msi_enabled() (false) #define kvm_ioeventfd_any_length_enabled() (false) #define kvm_msi_devid_required() (false) -#define kvm_supports_guest_debug() (false) #endif /* CONFIG_KVM_IS_POSSIBLE */ diff --git a/accel/kvm/kvm-accel-ops.c b/accel/kvm/kvm-accel-ops.c index 5c0e37514c..fbf4fe3497 100644 --- a/accel/kvm/kvm-accel-ops.c +++ b/accel/kvm/kvm-accel-ops.c @@ -99,6 +99,7 @@ static void kvm_accel_ops_class_init(ObjectClass *oc, void *data) ops->synchronize_pre_loadvm = kvm_cpu_synchronize_pre_loadvm; #ifdef KVM_CAP_SET_GUEST_DEBUG + ops->supports_guest_debug = kvm_supports_guest_debug; ops->insert_breakpoint = kvm_insert_breakpoint; ops->remove_breakpoint = kvm_remove_breakpoint; ops->remove_all_breakpoints = kvm_remove_all_breakpoints; diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index b8c734fe3a..6ebff6e5a6 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -3287,6 +3287,12 @@ int kvm_update_guest_debug(CPUState *cpu, unsigned long reinject_trap) return data.err; } +bool kvm_supports_guest_debug(void) +{ + /* probed during kvm_init() */ + return kvm_has_guest_debug; +} + int kvm_insert_breakpoint(CPUState *cpu, int type, hwaddr addr, hwaddr len) { struct kvm_sw_breakpoint *bp; diff --git a/accel/tcg/tcg-accel-ops.c b/accel/tcg/tcg-accel-ops.c index 965c2ad581..19cbf1db3a 100644 --- a/accel/tcg/tcg-accel-ops.c +++ b/accel/tcg/tcg-accel-ops.c @@ -93,6 +93,11 @@ void tcg_handle_interrupt(CPUState *cpu, int mask) } } +static bool tcg_supports_guest_debug(void) +{ + return true; +} + /* Translate GDB watchpoint type to a flags value for cpu_watchpoint_* */ static inline int xlat_gdb_type(CPUState *cpu, int gdbtype) { @@ -198,6 +203,7 @@ static void tcg_accel_ops_init(AccelOpsClass *ops) } } + ops->supports_guest_debug = tcg_supports_guest_debug; ops->insert_breakpoint = tcg_insert_breakpoint; ops->remove_breakpoint = tcg_remove_breakpoint; ops->remove_all_breakpoints = tcg_remove_all_breakpoints; diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index ff9f3f9586..be88ca0d71 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -45,7 +45,6 @@ #include "qemu/sockets.h" #include "sysemu/hw_accel.h" -#include "sysemu/kvm.h" #include "sysemu/runstate.h" #include "semihosting/semihost.h" #include "exec/exec-all.h" @@ -3447,8 +3446,8 @@ int gdbserver_start(const char *device) return -1; } - if (kvm_enabled() && !kvm_supports_guest_debug()) { - error_report("gdbstub: KVM doesn't support guest debugging"); + if (!gdb_supports_guest_debug()) { + error_report("gdbstub: current accelerator doesn't support guest debugging"); return -1; } diff --git a/gdbstub/softmmu.c b/gdbstub/softmmu.c index 4e73890379..f208c6cf15 100644 --- a/gdbstub/softmmu.c +++ b/gdbstub/softmmu.c @@ -15,6 +15,15 @@ #include "sysemu/cpus.h" #include "internals.h" +bool gdb_supports_guest_debug(void) +{ + const AccelOpsClass *ops = cpus_get_accel(); + if (ops->supports_guest_debug) { + return ops->supports_guest_debug(); + } + return false; +} + int gdb_breakpoint_insert(CPUState *cs, int type, hwaddr addr, hwaddr len) { const AccelOpsClass *ops = cpus_get_accel(); diff --git a/gdbstub/user.c b/gdbstub/user.c index 42652b28a7..033e5fdd71 100644 --- a/gdbstub/user.c +++ b/gdbstub/user.c @@ -14,6 +14,12 @@ #include "hw/core/cpu.h" #include "internals.h" +bool gdb_supports_guest_debug(void) +{ + /* user-mode == TCG == supported */ + return true; +} + int gdb_breakpoint_insert(CPUState *cs, int type, hwaddr addr, hwaddr len) { CPUState *cpu;