From nobody Sat May 18 03:46:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1704964139; cv=none; d=zohomail.com; s=zohoarc; b=XCffHI+R5GiMoyCwY5a7fzQ+x+ervKtQMXyuctlHd3B2BfqXsHfOjAqmKwUIqewhNzuNO+7bKgdVIeE6E2KDbyE7IZJElQB1kwOQLKE44UnyRKeyYhLLMAhrmukwpiLi5V04sIWXV/ZZLToA26iwQ4jwHQytibA2pcdApUDOH3M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704964139; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xL3761ssSlB++YwBh6IrPXss1xwoWjvn8Ap3bhK0DfA=; b=ipVnaK7PhVYtFNk8+5kbgkBto8IlGHzKPoUdfr/GQNmpkzsOjmDpyOmbTNl6XXZhi3+7GFqnCMzlYkjpvVdEnRlpdHEswQCEXA1ZCsnCXBPqDzyVfCLu3ejshOsM/V0ZCrB+0HkBz0vdgv99YH1yPAcj9q4vCWUNDix8nVgkWtM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1704964139204600.5565234584935; Thu, 11 Jan 2024 01:08:59 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.666067.1036492 (Exim 4.92) (envelope-from ) id 1rNr3H-00025u-UN; Thu, 11 Jan 2024 09:08:39 +0000 Received: by outflank-mailman (output) from mailman id 666067.1036492; Thu, 11 Jan 2024 09:08:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rNr3H-00025n-Rr; Thu, 11 Jan 2024 09:08:39 +0000 Received: by outflank-mailman (input) for mailman id 666067; Thu, 11 Jan 2024 09:08:38 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rNr3G-00025h-5y for xen-devel@lists.xenproject.org; Thu, 11 Jan 2024 09:08:38 +0000 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [2a00:1450:4864:20::333]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 01141f5c-b061-11ee-98f0-6d05b1d4d9a1; Thu, 11 Jan 2024 10:08:37 +0100 (CET) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-40e60e1373bso2309075e9.1 for ; Thu, 11 Jan 2024 01:08:37 -0800 (PST) Received: from localhost ([213.195.127.70]) by smtp.gmail.com with ESMTPSA id s27-20020adfa29b000000b003366cf8bda4sm664221wra.41.2024.01.11.01.08.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 01:08:35 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 01141f5c-b061-11ee-98f0-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1704964116; x=1705568916; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=xL3761ssSlB++YwBh6IrPXss1xwoWjvn8Ap3bhK0DfA=; b=ZNw819/T2t+BxSyaNogtE28gJK31onjx3cGHFO4qSvPEAWouVnYc2hsE3QnVhJCd48 drK7ADQtcqOPGBoawTEvCOYIz83QJH9+yhrdsiN1WFehFW0JHc8uoDmEy64peROOwcRa vGKDDprnpM8i3d7Bv/vWIq/YifiFf29rBB8bw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704964116; x=1705568916; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xL3761ssSlB++YwBh6IrPXss1xwoWjvn8Ap3bhK0DfA=; b=HDRrMGJvQ+Z26lR+f5hbtZMUnVe5fb9ifDTGkFuoeltd+Pcrw4j3gc68R6tAqAAEo6 YRsdQKyQ78/mZbpTPkvhnEipoYtuxKYRLLNjb2+m+uYOTNESz2LyoaKZC9PRcBa00Be5 cmy7SpAuQCQ1fpSw3GukGO3UyL37OAM0eKkiqJ0i0JVFvs/hNnSET+ipo17KvUNkJGE1 MGlM8THRXxTWK8vbgjTsxwFNalUGb2uB7OIhx7HVy5u6K/QeVGXGFhShST7d8NwtUsI2 /V4BPM2bBV7qZNTO/BUpqtKxZrTyQ8T1cei3IlFNFKbyLAYqgJnbCav3f1s/tF+/86dy tb8Q== X-Gm-Message-State: AOJu0Yzo8QqmwR0qNaWzibIUS0HSouhmwPwh5KWdj/lw3wN7yeazKGKe tXzUlMRp5dKxc2W65wG1TtBjyDpAWbjmwDm2FmD6PhwgIS4= X-Google-Smtp-Source: AGHT+IGJaC/xb9CScX0wTmbsCyOacS78Kzlsy3BkCDDFX/1bAspQNvnAES0xfrc1G/TK45XOSM6enw== X-Received: by 2002:a05:600c:12d1:b0:40d:2b60:b6cf with SMTP id v17-20020a05600c12d100b0040d2b60b6cfmr219480wmd.78.1704964115888; Thu, 11 Jan 2024 01:08:35 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper , Wei Liu Subject: [PATCH v2] x86/intel: ensure Global Performance Counter Control is setup correctly Date: Thu, 11 Jan 2024 10:08:21 +0100 Message-ID: <20240111090821.67594-1-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1704964140370100001 When Architectural Performance Monitoring is available, the PERF_GLOBAL_CTRL MSR contains per-counter enable bits that is ANDed with the enable bit in t= he counter EVNTSEL MSR in order for a PMC counter to be enabled. So far the watchdog code seems to have relied on the PERF_GLOBAL_CTRL enable bits being set by default, but at least on some Intel Sapphire and Emerald Rapids this is no longer the case, and Xen reports: Testing NMI watchdog on all CPUs: 0 40 stuck The first CPU on each package is started with PERF_GLOBAL_CTRL zeroed, so P= MC0 doesn't start counting when the enable bit in EVNTSEL0 is set, due to the relevant enable bit in PERF_GLOBAL_CTRL not being set. Check and adjust PERF_GLOBAL_CTRL during CPU initialization so that all the general-purpose PMCs are enabled. Doing so brings the state of the package= -BSP PERF_GLOBAL_CTRL in line with the rest of the CPUs on the system. Signed-off-by: Roger Pau Monn=C3=A9 --- Changes since v1: - Do the adjustment of PERF_GLOBAL_CTRL even if the watchdog is not used, = and enable all counters. --- Unsure whether printing a warning if the value of PERF_GLOBAL_CTRL is not correct is of any value, hence I haven't added it. --- xen/arch/x86/cpu/intel.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/cpu/intel.c b/xen/arch/x86/cpu/intel.c index dfee64689ffe..40d3eb0e18a7 100644 --- a/xen/arch/x86/cpu/intel.c +++ b/xen/arch/x86/cpu/intel.c @@ -533,9 +533,25 @@ static void cf_check init_intel(struct cpuinfo_x86 *c) init_intel_cacheinfo(c); if (c->cpuid_level > 9) { unsigned eax =3D cpuid_eax(10); + unsigned int cnt =3D (uint8_t)(eax >> 8); + /* Check for version and the number of counters */ - if ((eax & 0xff) && (((eax>>8) & 0xff) > 1)) + if ((eax & 0xff) && (cnt > 1) && (cnt <=3D 32)) { + uint64_t global_ctrl; + unsigned int cnt_mask =3D (1UL << cnt) - 1; + + /* + * On (some?) Sapphire/Emerald Rapids platforms each + * package-BSP starts with all the enable bits for the + * general-purpose PMCs cleared. Adjust so counters + * can be enabled from EVNTSEL. + */ + rdmsrl(MSR_CORE_PERF_GLOBAL_CTRL, global_ctrl); + if ((global_ctrl & cnt_mask) !=3D cnt_mask) + wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, + global_ctrl | cnt_mask); __set_bit(X86_FEATURE_ARCH_PERFMON, c->x86_capability); + } } =20 if ( !cpu_has(c, X86_FEATURE_XTOPOLOGY) ) --=20 2.43.0