From nobody Wed Apr 16 03:28:51 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1681985336; cv=none; d=zohomail.com; s=zohoarc; b=V8bi3Dv9D9lach42pw61LjiJcqqCNx8mHp6y4TNFriwGe/hYD6qiuSE4rYOIIkquPMJK27sQO4InQW6uQdTEmTZsX5sAOJHQ/0a2DT1kZebTHPMJEDgIa2QIY+VC9FlNoqDjGOI0pq6z9Pc2lqeeQcaHwv5Li4Q/iP+BdGiccZc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681985336; h=Content-Type:Content-Transfer-Encoding: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=UBHmKP2QWvbgSGiIjbO0DHXHxUNpy1cA3E2msdtGyEU=; b=iyh5iIFAGSs1E8N+rKmISgNZImKKwOzIyGO93ZoopSjanYoLx3QYqR0BKuyQ66lWrpDMZoGGK6ntVkafb/+a3W0C1x3kENsfHsyV2lKDGSC4lyzCYNAjXFXA3dj2/aFu1n9wD2N4rnOnfoTz3Pg125p0OIfD+hhk2nSjlJjTnO0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1681985336854572.9432146271714; Thu, 20 Apr 2023 03:08:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppRAD-0000cP-JN; Thu, 20 Apr 2023 06:05:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppRAA-0000Zi-Ed for qemu-devel@nongnu.org; Thu, 20 Apr 2023 06:05:15 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ppRA4-0003rV-Dk for qemu-devel@nongnu.org; Thu, 20 Apr 2023 06:05:13 -0400 Received: by mail-wm1-x330.google.com with SMTP id he13so964577wmb.2 for ; Thu, 20 Apr 2023 03:05:06 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id o2-20020a5d58c2000000b002fe522117fdsm1556388wrf.36.2023.04.20.03.05.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 03:05:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681985105; x=1684577105; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=UBHmKP2QWvbgSGiIjbO0DHXHxUNpy1cA3E2msdtGyEU=; b=IMHdiBul6mXvafDGTwo+tkps089yVSk8ABzbTn/IIh7NZA4m/6AAH3LqubRZ3O+Uzi MHjf4w7AB3DjOpJH2McdbQwuZ4HrKMzXmmDfpgxnU5GbftHR1BkGTGZQE+01qqW4QDTA etPY6oLMDJbuOrWvB9vbh3WuYfEUZIRHg4MlXnFumLo4Y4rTHnUnPT5+c4qMbck677jh CRnUf9xztZdQQ7lsUu4aCJw2ToWhZvphj37xi6dnNkGmxAkxqtfS5Qt1uDMRv83zSh96 Gu0wyDeUtnVBF+QgNUg95pml6pFl1nXuzxQbSwuCY1tr7Fx24eW+kmHiuAzyIDUIxy7s fRpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681985105; x=1684577105; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UBHmKP2QWvbgSGiIjbO0DHXHxUNpy1cA3E2msdtGyEU=; b=cJ5O4WbG+W7ey0QybC/hGpez/q6D39Pdw4sIzOfxpY5EYTK+lM4CUz3G2YtrjhQIjU YHVnEijTZjxkvTmgGTxEyqogVnyZEdODTxW4oHANs1Fc1UQwNPLeA3PUTvDGlW2A+wQM 2pAyeTyY37qUAxJXS4EM3yaydKA43LENwh+6RGjL5fz6ktN2PyS4FusLrA64G0qdtvel 3KPOy9qNwJ0vA1PNYZqzpqTpVHe5W7B7VRav/NuWiXcqVcR2mNiPdnXEghJFCPS+rTIS Ixp5AOGVDXzKuzBGtxJkCmQ0Jq4Og9wnkkvThIarwxOogg8RVxeKDWqKoGqPpqSY2ItP 8MNg== X-Gm-Message-State: AAQBX9fyF/8dY1U8E7XT14J+uq6PrTnVFmbE13SwEBXz9vznecBKEtL6 kIDEZOwxH2EYMQncoJ1ckA9pDua5rnwQSbi49vw= X-Google-Smtp-Source: AKy350bbbPVu7Y2MEyPCChzvRNCKLzigX6Tzf9Y8gYOulKq4BvnekfuHwWPirdPcTuKmCF7cgdIq1A== X-Received: by 2002:a1c:cc02:0:b0:3ef:df3:1693 with SMTP id h2-20020a1ccc02000000b003ef0df31693mr840105wmb.32.1681985105712; Thu, 20 Apr 2023 03:05:05 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 11/21] target/arm: Initialize debug capabilities only once Date: Thu, 20 Apr 2023 11:04:46 +0100 Message-Id: <20230420100456.944969-12-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230420100456.944969-1-peter.maydell@linaro.org> References: <20230420100456.944969-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::330; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x330.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, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1681985338922100003 From: Akihiko Odaki kvm_arm_init_debug() used to be called several times on a SMP system as kvm_arch_init_vcpu() calls it. Move the call to kvm_arch_init() to make sure it will be called only once; otherwise it will overwrite pointers to memory allocated with the previous call and leak it. Fixes: e4482ab7e3 ("target-arm: kvm - add support for HW assisted debug") Suggested-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Akihiko Odaki Message-id: 20230405153644.25300-1-akihiko.odaki@daynix.com Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- target/arm/kvm_arm.h | 8 ++++++++ target/arm/kvm.c | 2 ++ target/arm/kvm64.c | 18 ++++-------------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h index 99017b635ce..330fbe5c722 100644 --- a/target/arm/kvm_arm.h +++ b/target/arm/kvm_arm.h @@ -18,6 +18,14 @@ #define KVM_ARM_VGIC_V2 (1 << 0) #define KVM_ARM_VGIC_V3 (1 << 1) =20 +/** + * kvm_arm_init_debug() - initialize guest debug capabilities + * @s: KVMState + * + * Should be called only once before using guest debug capabilities. + */ +void kvm_arm_init_debug(KVMState *s); + /** * kvm_arm_vcpu_init: * @cs: CPUState diff --git a/target/arm/kvm.c b/target/arm/kvm.c index f022c644d2f..84da49332c4 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -280,6 +280,8 @@ int kvm_arch_init(MachineState *ms, KVMState *s) } } =20 + kvm_arm_init_debug(s); + return ret; } =20 diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c index 1197253d12f..810db33ccbd 100644 --- a/target/arm/kvm64.c +++ b/target/arm/kvm64.c @@ -74,24 +74,16 @@ GArray *hw_breakpoints, *hw_watchpoints; #define get_hw_bp(i) (&g_array_index(hw_breakpoints, HWBreakpoint, i)) #define get_hw_wp(i) (&g_array_index(hw_watchpoints, HWWatchpoint, i)) =20 -/** - * kvm_arm_init_debug() - check for guest debug capabilities - * @cs: CPUState - * - * kvm_check_extension returns the number of debug registers we have - * or 0 if we have none. - * - */ -static void kvm_arm_init_debug(CPUState *cs) +void kvm_arm_init_debug(KVMState *s) { - have_guest_debug =3D kvm_check_extension(cs->kvm_state, + have_guest_debug =3D kvm_check_extension(s, KVM_CAP_SET_GUEST_DEBUG); =20 - max_hw_wps =3D kvm_check_extension(cs->kvm_state, KVM_CAP_GUEST_DEBUG_= HW_WPS); + max_hw_wps =3D kvm_check_extension(s, KVM_CAP_GUEST_DEBUG_HW_WPS); hw_watchpoints =3D g_array_sized_new(true, true, sizeof(HWWatchpoint), max_hw_wps); =20 - max_hw_bps =3D kvm_check_extension(cs->kvm_state, KVM_CAP_GUEST_DEBUG_= HW_BPS); + max_hw_bps =3D kvm_check_extension(s, KVM_CAP_GUEST_DEBUG_HW_BPS); hw_breakpoints =3D g_array_sized_new(true, true, sizeof(HWBreakpoint), max_hw_bps); return; @@ -920,8 +912,6 @@ int kvm_arch_init_vcpu(CPUState *cs) } cpu->mp_affinity =3D mpidr & ARM64_AFFINITY_MASK; =20 - kvm_arm_init_debug(cs); - /* Check whether user space can specify guest syndrome value */ kvm_arm_init_serror_injection(cs); =20 --=20 2.34.1