From patchwork Wed Jan 31 11:37:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Rui X-Patchwork-Id: 13539340 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0929D6D1D2; Wed, 31 Jan 2024 11:37:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706701050; cv=none; b=K5XPhY5RrIEolWrGIExgV1U+O5MKd1X8eBPWLBq6Kfz6eD7cLF/2S/V+Y36WD5EBNKsLy/0AEtpa+DfXQKUE2DfIYOeuS1wpqkP4ZrfWJvXNv767A548zXgJ7bC4ji+HxcCkhrjZIBOCvtgKvBCBx8iMyLrIT3ebokVeMZY2uqc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706701050; c=relaxed/simple; bh=GvAqwQ4KOZBh0mXfOdAbuk8oUfo2FkUF0mPuB57A4+4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HAS3gtaaSCo5bfUJNiw/Mb2ZeY6KrUNaYdxL/vP4EEBXxIK/ByeOAdO40dZ0GScMvfW2EJj2OXiaPgkngrSRDn3hHjx+uxj9UbtaTwPUVBn2Odlp84pVuHItdroRmxTo654iFw2uru6XpD/y58AuzCHAUgszLEu+KCABt4zLxFo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=gHWjYalG; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="gHWjYalG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706701048; x=1738237048; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GvAqwQ4KOZBh0mXfOdAbuk8oUfo2FkUF0mPuB57A4+4=; b=gHWjYalGxYdoeFDEzjBJyiRO2S3fDrmTNbr9PoYEogwCfTR21QUZe23H pQ/Oorsi+Xgaj9TAjZJYwCIN8+CcP51CZlqLoj0vDPLRVf4NZcXq93TL5 y+XrNusNotfgKq2MKdAd9GVCpNvNS/HpDBeddzlsOYqmg6PY05Cl6g08L lnXQPT2fdGUDbqecj/GkU+eIg73TBlLpLWqdTs4Ji2HMRnMzBd+dKgeIq 87RLWT2gh4QEyHcAKiJeIjwNfl7+RCmFS/I1h1Xg7sXEG/8+MUqg4bi2n IXlKffMmwFw8qBDIZU7jh4L/WeKri7nblnsiFZBwiszBbgQcX1z+iYN3h w==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="3441622" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="3441622" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 03:37:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="788542472" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="788542472" Received: from puhongt-mobl2.ccr.corp.intel.com (HELO rzhang1-mobl7.ccr.corp.intel.com) ([10.255.29.147]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 03:37:24 -0800 From: Zhang Rui To: rafael.j.wysocki@intel.com Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH 1/6] powercap: intel_rapl: Fix a NULL pointer dereference bug Date: Wed, 31 Jan 2024 19:37:08 +0800 Message-Id: <20240131113713.74779-2-rui.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240131113713.74779-1-rui.zhang@intel.com> References: <20240131113713.74779-1-rui.zhang@intel.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A NULL pointer dereference bug is triggered when probing MMIO RAPL driver on platforms with CPU ID not listed in intel_rapl_common CPU model list. This is because the intel_rapl_common module still probes on such platforms even if 'defaults_msr' is not set after commit 1488ac990ac8 ("powercap: intel_rapl: Allow probing without CPUID match"). Thus the MMIO RAPL rp->priv->defaults is NULL when registering to RAPL framework. Fix the problem by adding sanity check to ensure rp->priv->rapl_defaults is always valid. Fixes: 1488ac990ac8 ("powercap: intel_rapl: Allow probing without CPUID match") Signed-off-by: Zhang Rui Cc: --- drivers/powercap/intel_rapl_common.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/powercap/intel_rapl_common.c b/drivers/powercap/intel_rapl_common.c index 2feed036c1cd..1a739afd47d9 100644 --- a/drivers/powercap/intel_rapl_common.c +++ b/drivers/powercap/intel_rapl_common.c @@ -759,6 +759,11 @@ static int rapl_config(struct rapl_package *rp) default: return -EINVAL; } + + /* defaults_msr can be NULL on unsupported platforms */ + if (!rp->priv->defaults || !rp->priv->rpi) + return -ENODEV; + return 0; } From patchwork Wed Jan 31 11:37:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Rui X-Patchwork-Id: 13539341 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 255B47AE6E; Wed, 31 Jan 2024 11:37:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706701050; cv=none; b=sr240/zfkLHC7A6pW/A0oJlwBiS8FwI88d7FmcjpjywPuBcRNKCj7iVj2lmtFMZIQT3rn1XYSBNuTxMdxmyoC9EWvjTB+R63ai+uXWIBE9EH+eVokzRLofDk/a8sOiByJ6qt65LpoG5093mFYVKrl1I1knopGVliA/CoWEeNbSI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706701050; c=relaxed/simple; bh=HZHQQsIcvY0GIFCdIWOohL5EGPt1hOYTvfZ+z3doboM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uGFQzgGiUGmJ9gcynjgfLa/B68m5F1IvWi5sblSj9cTZSGGO0ONA3hfzkffm2TWeSrFw7xm3+uNOrMUvgex34hd74wBno8qZDdScFFv8z9+K2RQZhYz9SEV7e+XlMaqbB2DZ4LpdPBDABOfRe3XfUc7EPjsuSyRrNoZ4OS1lm3A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=G5Hy3ull; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="G5Hy3ull" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706701049; x=1738237049; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HZHQQsIcvY0GIFCdIWOohL5EGPt1hOYTvfZ+z3doboM=; b=G5Hy3ullwjvLVHqkn1ZIEL62Oxay+osJNpS0ontYmun/JxSQ1pNjG1K6 Tsy7zlkOBLM7VV3vclssHyQlNsp1LchuLAAdgJaFnz6NaimNzbdZiBrmN 2+mVUj4fPxyVvzwf9LoyrX8wkNuP6ldCQgqOfI0c866Cy0iXIm5Kc8gnO 0H+N1pdYzkSg+7YiMp0aHM1UcVUN9EAmgbYzmrVEnqSIZz9JzEOz6OpHD 6B/OFB/OoNu3CIlZaq4X0K0hD/KX6vPnBD+cx9IXpdpfpEPboOdpZyXI9 vwLaZutcID0V7KwVjkdYTTE192CXu+z/nnVAWusT9KE4hyQnsxQ4jdJ76 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="3441625" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="3441625" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 03:37:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="788542479" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="788542479" Received: from puhongt-mobl2.ccr.corp.intel.com (HELO rzhang1-mobl7.ccr.corp.intel.com) ([10.255.29.147]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 03:37:25 -0800 From: Zhang Rui To: rafael.j.wysocki@intel.com Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH 2/6] powercap: intel_rapl: Fix locking for TPMI RAPL Date: Wed, 31 Jan 2024 19:37:09 +0800 Message-Id: <20240131113713.74779-3-rui.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240131113713.74779-1-rui.zhang@intel.com> References: <20240131113713.74779-1-rui.zhang@intel.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 RAPL framework uses CPU hotplug lock to protect rapl_packages list and rp->lead_cpu to guarantee that 1. the RAPL package device is not unprobed and freed 2. the cached rp->lead_cpu is always valid for operations like powercap sysfs accesses. Current RAPL APIs assume they are called from CPU hotplug callbacks which hold the CPU hotplug lock. But TPMI RAPL driver invokes the APIs in the driver' .probe() function without CPU hotplug lock held. Fix the problem by providing both locked and lockless version RAPL APIs. Fixes: 9eef7f9da928 ("powercap: intel_rapl: Introduce RAPL TPMI interface driver") Signed-off-by: Zhang Rui --- drivers/powercap/intel_rapl_common.c | 29 +++++++++++++++++-- drivers/powercap/intel_rapl_msr.c | 8 ++--- .../int340x_thermal/processor_thermal_rapl.c | 8 ++--- include/linux/intel_rapl.h | 6 ++++ 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/drivers/powercap/intel_rapl_common.c b/drivers/powercap/intel_rapl_common.c index 1a739afd47d9..9d3e102f1a76 100644 --- a/drivers/powercap/intel_rapl_common.c +++ b/drivers/powercap/intel_rapl_common.c @@ -5,6 +5,7 @@ */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include #include #include #include @@ -1504,7 +1505,7 @@ static int rapl_detect_domains(struct rapl_package *rp) } /* called from CPU hotplug notifier, hotplug lock held */ -void rapl_remove_package(struct rapl_package *rp) +void rapl_remove_package_cpuslocked(struct rapl_package *rp) { struct rapl_domain *rd, *rd_package = NULL; @@ -1533,10 +1534,18 @@ void rapl_remove_package(struct rapl_package *rp) list_del(&rp->plist); kfree(rp); } +EXPORT_SYMBOL_GPL(rapl_remove_package_cpuslocked); + +void rapl_remove_package(struct rapl_package *rp) +{ + guard(cpus_read_lock)(); + rapl_remove_package_cpuslocked(rp); +} EXPORT_SYMBOL_GPL(rapl_remove_package); /* caller to ensure CPU hotplug lock is held */ -struct rapl_package *rapl_find_package_domain(int id, struct rapl_if_priv *priv, bool id_is_cpu) +struct rapl_package *rapl_find_package_domain_cpuslocked(int id, struct rapl_if_priv *priv, + bool id_is_cpu) { struct rapl_package *rp; int uid; @@ -1554,10 +1563,17 @@ struct rapl_package *rapl_find_package_domain(int id, struct rapl_if_priv *priv, return NULL; } +EXPORT_SYMBOL_GPL(rapl_find_package_domain_cpuslocked); + +struct rapl_package *rapl_find_package_domain(int id, struct rapl_if_priv *priv, bool id_is_cpu) +{ + guard(cpus_read_lock)(); + return rapl_find_package_domain_cpuslocked(id, priv, id_is_cpu); +} EXPORT_SYMBOL_GPL(rapl_find_package_domain); /* called from CPU hotplug notifier, hotplug lock held */ -struct rapl_package *rapl_add_package(int id, struct rapl_if_priv *priv, bool id_is_cpu) +struct rapl_package *rapl_add_package_cpuslocked(int id, struct rapl_if_priv *priv, bool id_is_cpu) { struct rapl_package *rp; int ret; @@ -1603,6 +1619,13 @@ struct rapl_package *rapl_add_package(int id, struct rapl_if_priv *priv, bool id kfree(rp); return ERR_PTR(ret); } +EXPORT_SYMBOL_GPL(rapl_add_package_cpuslocked); + +struct rapl_package *rapl_add_package(int id, struct rapl_if_priv *priv, bool id_is_cpu) +{ + guard(cpus_read_lock)(); + return rapl_add_package_cpuslocked(id, priv, id_is_cpu); +} EXPORT_SYMBOL_GPL(rapl_add_package); static void power_limit_state_save(void) diff --git a/drivers/powercap/intel_rapl_msr.c b/drivers/powercap/intel_rapl_msr.c index 250bd41a588c..b4b6930cacb0 100644 --- a/drivers/powercap/intel_rapl_msr.c +++ b/drivers/powercap/intel_rapl_msr.c @@ -73,9 +73,9 @@ static int rapl_cpu_online(unsigned int cpu) { struct rapl_package *rp; - rp = rapl_find_package_domain(cpu, rapl_msr_priv, true); + rp = rapl_find_package_domain_cpuslocked(cpu, rapl_msr_priv, true); if (!rp) { - rp = rapl_add_package(cpu, rapl_msr_priv, true); + rp = rapl_add_package_cpuslocked(cpu, rapl_msr_priv, true); if (IS_ERR(rp)) return PTR_ERR(rp); } @@ -88,14 +88,14 @@ static int rapl_cpu_down_prep(unsigned int cpu) struct rapl_package *rp; int lead_cpu; - rp = rapl_find_package_domain(cpu, rapl_msr_priv, true); + rp = rapl_find_package_domain_cpuslocked(cpu, rapl_msr_priv, true); if (!rp) return 0; cpumask_clear_cpu(cpu, &rp->cpumask); lead_cpu = cpumask_first(&rp->cpumask); if (lead_cpu >= nr_cpu_ids) - rapl_remove_package(rp); + rapl_remove_package_cpuslocked(rp); else if (rp->lead_cpu == cpu) rp->lead_cpu = lead_cpu; return 0; diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_rapl.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_rapl.c index 2f00fc3bf274..e964a9375722 100644 --- a/drivers/thermal/intel/int340x_thermal/processor_thermal_rapl.c +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_rapl.c @@ -27,9 +27,9 @@ static int rapl_mmio_cpu_online(unsigned int cpu) if (topology_physical_package_id(cpu)) return 0; - rp = rapl_find_package_domain(cpu, &rapl_mmio_priv, true); + rp = rapl_find_package_domain_cpuslocked(cpu, &rapl_mmio_priv, true); if (!rp) { - rp = rapl_add_package(cpu, &rapl_mmio_priv, true); + rp = rapl_add_package_cpuslocked(cpu, &rapl_mmio_priv, true); if (IS_ERR(rp)) return PTR_ERR(rp); } @@ -42,14 +42,14 @@ static int rapl_mmio_cpu_down_prep(unsigned int cpu) struct rapl_package *rp; int lead_cpu; - rp = rapl_find_package_domain(cpu, &rapl_mmio_priv, true); + rp = rapl_find_package_domain_cpuslocked(cpu, &rapl_mmio_priv, true); if (!rp) return 0; cpumask_clear_cpu(cpu, &rp->cpumask); lead_cpu = cpumask_first(&rp->cpumask); if (lead_cpu >= nr_cpu_ids) - rapl_remove_package(rp); + rapl_remove_package_cpuslocked(rp); else if (rp->lead_cpu == cpu) rp->lead_cpu = lead_cpu; return 0; diff --git a/include/linux/intel_rapl.h b/include/linux/intel_rapl.h index 33f21bd85dbf..f3196f82fd8a 100644 --- a/include/linux/intel_rapl.h +++ b/include/linux/intel_rapl.h @@ -178,6 +178,12 @@ struct rapl_package { struct rapl_if_priv *priv; }; +struct rapl_package *rapl_find_package_domain_cpuslocked(int id, struct rapl_if_priv *priv, + bool id_is_cpu); +struct rapl_package *rapl_add_package_cpuslocked(int id, struct rapl_if_priv *priv, + bool id_is_cpu); +void rapl_remove_package_cpuslocked(struct rapl_package *rp); + struct rapl_package *rapl_find_package_domain(int id, struct rapl_if_priv *priv, bool id_is_cpu); struct rapl_package *rapl_add_package(int id, struct rapl_if_priv *priv, bool id_is_cpu); void rapl_remove_package(struct rapl_package *rp); From patchwork Wed Jan 31 11:37:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Rui X-Patchwork-Id: 13539342 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68FF07B3D1; Wed, 31 Jan 2024 11:37:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706701053; cv=none; b=nyot7oZDQHgpp4KkYKH7y33uoh3HsMFwTjTTA98rVrpNqDrQPJqsMLYyyaMlozYs+MVtAnWTxtvkca/4Ji9l0gYyhvXDEswW71s01e3QjhnTNj/USzon3DAZlrfGjHc3bB0ahE3cmnn0HC+a4bHy7ANemiAhtMXnB1urSp6e6+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706701053; c=relaxed/simple; bh=VbGVsMvlR6qLCq5piw4v45/5b+9I9zsshnAjLePRsqA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OYV8vcANEIixbthTTIdXXWw4B2VoLhTyUeonq06031wL4XLahv/WZwKuu+/QaGPNbOuT203ckDWNTVtcbMob2vg7Cz5hQO0FQ29HlT7Yu35fhyYXq8r1ng6AlmrmDxxdJvkOro3myqvvnYxiz01y38nmiDAMi3IER8OZ/8oizps= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=IkpR5TKt; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="IkpR5TKt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706701050; x=1738237050; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VbGVsMvlR6qLCq5piw4v45/5b+9I9zsshnAjLePRsqA=; b=IkpR5TKtYFISiqvNHGBdb8CfScpggzwA1JrXKV5e83AofD9N/+Enn76m Izd7jxwpUNnQBn+sYkRhhvXvMiqDmyWkUUiqOgFIWuc/Mpr6IeIwwjjbk vCV5/j8SPl9gf/ocNx1zbuscRBSZEi42wSFbFmngZ5xilnvP3IIgjVq9i bmwB3jKEQEbaP2DxBOFqDY8o90CXSLLYLWdOaajUVQi7mCyxqIwOu5AKc j2NR0kqooHGW8djN7IvLJITkuXcFSh24pKhG0kbhsyxpIcrFllSnMysTy fS4QVsLRFNm/Zes9PklF28qainUlVIhf9O8Q/gKZDgOLAWXUOyVH5MPD5 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="3441637" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="3441637" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 03:37:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="788542488" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="788542488" Received: from puhongt-mobl2.ccr.corp.intel.com (HELO rzhang1-mobl7.ccr.corp.intel.com) ([10.255.29.147]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 03:37:28 -0800 From: Zhang Rui To: rafael.j.wysocki@intel.com Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH 3/6] powercap: intel_rapl_tpmi: Fix a register bug Date: Wed, 31 Jan 2024 19:37:10 +0800 Message-Id: <20240131113713.74779-4-rui.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240131113713.74779-1-rui.zhang@intel.com> References: <20240131113713.74779-1-rui.zhang@intel.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add the missing Domain Info register. This also fixes the bogus definition of the Interrupt register. Neither of these two registers was used previously. Fixes: 9eef7f9da928 ("powercap: intel_rapl: Introduce RAPL TPMI interface driver") Signed-off-by: Zhang Rui --- drivers/powercap/intel_rapl_tpmi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/powercap/intel_rapl_tpmi.c b/drivers/powercap/intel_rapl_tpmi.c index 891c90fefd8b..f1c734ac3c34 100644 --- a/drivers/powercap/intel_rapl_tpmi.c +++ b/drivers/powercap/intel_rapl_tpmi.c @@ -40,6 +40,7 @@ enum tpmi_rapl_register { TPMI_RAPL_REG_ENERGY_STATUS, TPMI_RAPL_REG_PERF_STATUS, TPMI_RAPL_REG_POWER_INFO, + TPMI_RAPL_REG_DOMAIN_INFO, TPMI_RAPL_REG_INTERRUPT, TPMI_RAPL_REG_MAX = 15, }; From patchwork Wed Jan 31 11:37:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Rui X-Patchwork-Id: 13539343 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 876A47D3F5; Wed, 31 Jan 2024 11:37:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706701054; cv=none; b=oLvF6Hnrsb4RXWJgtgTAY+jjf7DrPquUa/F1W7DkxIpcr2jQ22VAbo3uP/hyl4hGEW56h1QvXbF8jNXuAPxVXeoJ7yyhEMZSJRnWpBUjFG8WEfTali0dkxm/7u2G0Pw+mrSU8iK0yIUsLy7/uhFpavAUSK9RQ5jwnpwFmFPJL9Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706701054; c=relaxed/simple; bh=qqS366ENXAObLZelQMQdQKQUmZl5yUdXm3AHKjxtXp8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pKXo3mT1OmHRrtzGw8iuh8L1W0x7azL/TdU++9d6+ZeDtE+BhjkVkXKb3vNSSdL9fx1hFp0Kv27nScrLjL+AepewBV8N7C7LZ6IisB5grxDvv65Zyd0yAtqOeYzV4Npu2mqsHatsqm9jtiyRpa6fyD0iTuvS/VJJ3/rTErv5iNI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=NHR3II2i; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="NHR3II2i" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706701052; x=1738237052; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qqS366ENXAObLZelQMQdQKQUmZl5yUdXm3AHKjxtXp8=; b=NHR3II2ioMEs+bVqqettnbQe1SUBQs1ykmOX3+/25PrHVgi4uX7eKwEB Myj5ylSeOXCbM7YmYyvKU9nZowHWniNPjZj9h3KLipgVSjl0LxNnLtdus rH3A3RGIIsPv4+84ZwIoMYH/7o54Z9+LQNS+ewjBHPOXIoJZXuW7K+ySs uMXW9kcUcWH+AakuNb/YV8lqyF5B+fgWQNCSuD3azTjTLEYerUc/om3tG 5r41Ryq9ahxN/EDcc3pS8nuJnmavOaN8EPCTtsjwVrfX70Hp23DWiWLYd j2dcfDvXW/Ko9U3knbBStfy8i9zbJAQ8rHt62aAC8/SRs/KsYFijyq3Vj Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="3441644" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="3441644" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 03:37:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="788542498" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="788542498" Received: from puhongt-mobl2.ccr.corp.intel.com (HELO rzhang1-mobl7.ccr.corp.intel.com) ([10.255.29.147]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 03:37:30 -0800 From: Zhang Rui To: rafael.j.wysocki@intel.com Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH 4/6] powercap: intel_rapl_tpmi: Fix System Domain probing Date: Wed, 31 Jan 2024 19:37:11 +0800 Message-Id: <20240131113713.74779-5-rui.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240131113713.74779-1-rui.zhang@intel.com> References: <20240131113713.74779-1-rui.zhang@intel.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Only domain root packages can enumerate System (Psys) domain. Whether a package is domain root or not is described in the Bit 0 of the Domain Info register. Add support for Domain Info register and fix the System domain probing accordingly. Fixes: 9eef7f9da928 ("powercap: intel_rapl: Introduce RAPL TPMI interface driver") Signed-off-by: Zhang Rui --- drivers/powercap/intel_rapl_tpmi.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/powercap/intel_rapl_tpmi.c b/drivers/powercap/intel_rapl_tpmi.c index f1c734ac3c34..f6b7f085977c 100644 --- a/drivers/powercap/intel_rapl_tpmi.c +++ b/drivers/powercap/intel_rapl_tpmi.c @@ -131,6 +131,12 @@ static void trp_release(struct tpmi_rapl_package *trp) mutex_unlock(&tpmi_rapl_lock); } +/* + * Bit 0 of TPMI_RAPL_REG_DOMAIN_INFO indicates if the current package is a domain + * root or not. Only domain root packages can enumerate System (Psys) Domain. + */ +#define TPMI_RAPL_DOMAIN_ROOT BIT(0) + static int parse_one_domain(struct tpmi_rapl_package *trp, u32 offset) { u8 tpmi_domain_version; @@ -140,6 +146,7 @@ static int parse_one_domain(struct tpmi_rapl_package *trp, u32 offset) enum rapl_domain_reg_id reg_id; int tpmi_domain_size, tpmi_domain_flags; u64 tpmi_domain_header = readq(trp->base + offset); + u64 tpmi_domain_info; /* Domain Parent bits are ignored for now */ tpmi_domain_version = tpmi_domain_header & 0xff; @@ -170,6 +177,13 @@ static int parse_one_domain(struct tpmi_rapl_package *trp, u32 offset) domain_type = RAPL_DOMAIN_PACKAGE; break; case TPMI_RAPL_DOMAIN_SYSTEM: + if (!(tpmi_domain_flags & BIT(TPMI_RAPL_REG_DOMAIN_INFO))) { + pr_warn(FW_BUG "System domain must support Domain Info register\n"); + return -ENODEV; + } + tpmi_domain_info = readq(trp->base + offset + TPMI_RAPL_REG_DOMAIN_INFO); + if (!(tpmi_domain_info & TPMI_RAPL_DOMAIN_ROOT)) + return 0; domain_type = RAPL_DOMAIN_PLATFORM; break; case TPMI_RAPL_DOMAIN_MEMORY: From patchwork Wed Jan 31 11:37:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Rui X-Patchwork-Id: 13539344 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 283B57F464; Wed, 31 Jan 2024 11:37:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706701055; cv=none; b=gxAH70iaxXVGjmdgl+yiygK/ZpKarFj9PT3kIP40UvFdfSMoCRYwYzKdtM7RVB35L6FP8rYr0O75HA+JatIB3L4oJFpVuKtpIcKBsYshlatI0zNQamg7LoJiB6aMTdPWI3g6UpZVDRALIvV7I4i0aCkzfkuPcXLsMavooD8oQEI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706701055; c=relaxed/simple; bh=+7P8ooaYXamG1JjYcGUuE0lFs56ZdtWnnIGwXoN49QA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Dkzeb/y/iIcv7uWtvF5AoIYlaFq0PlFAk6ehnKLoJx0FNgFexrdJXBdbQioBOt0XVX8TunIEw8195v6LpFX9SotaeBO2EziE24H/SCbNzdBF5QBuybi9rf4FvdcsSVnq8sF/mtNqPYFeqbFgeN17M9M20XFBqVOXXFTU3ETz3I8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=BqKh7eAg; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="BqKh7eAg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706701054; x=1738237054; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+7P8ooaYXamG1JjYcGUuE0lFs56ZdtWnnIGwXoN49QA=; b=BqKh7eAgCgZr7AvFXy2F0bLxMXltNFq/VlgKaSNQB8q28FP9AanHvufJ EdNDmn0FBrjPKJHxMk+7XySGDLM2x2cgVho6SKrvoDauu2jk5PLCfDb2P 9pzfYtP6CDf79a1mQR/dNIhitLamdtmRxmnsx/qwZhICg6i5JYWJheU6W VFQpXwUcV/bpmgH+V9Nth6jEMD5m4Lao/NqHRWi+yx73+6CmkyNUYNDww OeBJDLRxJOKCl4SDRB0If6i5NfxTqNpwVGr5k8ClOZnfSLwSyjnXtu/kc 5DIFtcwFjE1suPi+GyupzufSWoAVYqpSJBFndsq1WHaAZYX4d8bgTFLfV A==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="3441658" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="3441658" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 03:37:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="788542507" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="788542507" Received: from puhongt-mobl2.ccr.corp.intel.com (HELO rzhang1-mobl7.ccr.corp.intel.com) ([10.255.29.147]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 03:37:32 -0800 From: Zhang Rui To: rafael.j.wysocki@intel.com Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH 5/6] powercap: intel_rapl: Add support for LNL-M paltform Date: Wed, 31 Jan 2024 19:37:12 +0800 Message-Id: <20240131113713.74779-6-rui.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240131113713.74779-1-rui.zhang@intel.com> References: <20240131113713.74779-1-rui.zhang@intel.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add support for LNL-M platform. Signed-off-by: Zhang Rui --- drivers/powercap/intel_rapl_common.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/powercap/intel_rapl_common.c b/drivers/powercap/intel_rapl_common.c index 9d3e102f1a76..a3094cb9f296 100644 --- a/drivers/powercap/intel_rapl_common.c +++ b/drivers/powercap/intel_rapl_common.c @@ -1262,6 +1262,7 @@ static const struct x86_cpu_id rapl_ids[] __initconst = { X86_MATCH_INTEL_FAM6_MODEL(METEORLAKE_L, &rapl_defaults_core), X86_MATCH_INTEL_FAM6_MODEL(SAPPHIRERAPIDS_X, &rapl_defaults_spr_server), X86_MATCH_INTEL_FAM6_MODEL(EMERALDRAPIDS_X, &rapl_defaults_spr_server), + X86_MATCH_INTEL_FAM6_MODEL(LUNARLAKE_M, &rapl_defaults_core), X86_MATCH_INTEL_FAM6_MODEL(LAKEFIELD, &rapl_defaults_core), X86_MATCH_INTEL_FAM6_MODEL(ATOM_SILVERMONT, &rapl_defaults_byt), From patchwork Wed Jan 31 11:37:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Rui X-Patchwork-Id: 13539345 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 417887F7F4; Wed, 31 Jan 2024 11:37:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706701057; cv=none; b=YDr8efGtvyAzhdUwv41nyZLFb2Xig41tbWXNUsCkBJ1zwxq04P/HHSkoOvX0ALJpUCdFOZ6tKN0r6E8WygmrfWJEW7V0Cj2zYxi0hq/2j9G89m08TR4Vi5hIJnLOc6xndxd7C38ARG0z5fNCDrdMhDYTTSDCI2z6l8ihRn3Okps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706701057; c=relaxed/simple; bh=3wEv6gpWu5XkRdhubo8bpcen3Ln1BI1Vmy7qOX9Tb8Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=blvgaMhaNLdJgYKyK9nZr/PZ/oXcN0TJbday+RGxNU8aiH2QoWHu+1ZfbnSN34kgJjuQQtu6VXs1OH/n7l20Wx+7C8h7JMUOpp4q9K4eMsOs1GF01hF5j7cgJKlxCaaA4HAYpZEG83NJTUcvHxiTKxCsEMEmSfTIgk8t0uzP9Z4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=PWoGmA+u; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="PWoGmA+u" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706701056; x=1738237056; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3wEv6gpWu5XkRdhubo8bpcen3Ln1BI1Vmy7qOX9Tb8Q=; b=PWoGmA+uYHsazKEu4TwaRCI+xJ3HS5Y/eAs/3UF3uayNScJRzp2jTy9f Il+IkcpG+ZXSjS1SDM5x0BZDk8SdysfHkhx9kNXL3lO3RAqbQsVth5ET+ wzrOtZCWBiIK9kX8BnTEjHL59dnGKzQjTddUFREKRKUgOhnSza3KYN9H+ L9a3rxo2KZEpNc0/WgKRBB+ATdOI8Vhi/vcF3X0sLvuw+HPiTltGfKJXQ bQUNCR4rfYSpEDXU3o14jgpDnHct/o/7Fdy4vUa4JcMW9DRy9DNAqJsHJ IzTzZf++X55bwzWv5hzEDMLYDYE7O13v/2Z7FMs2JYfoI+VnV4FNwhor/ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="3441668" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="3441668" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 03:37:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="788542511" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="788542511" Received: from puhongt-mobl2.ccr.corp.intel.com (HELO rzhang1-mobl7.ccr.corp.intel.com) ([10.255.29.147]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 03:37:34 -0800 From: Zhang Rui To: rafael.j.wysocki@intel.com Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH 6/6] powercap: intel_rapl: add support for Arrow Lake Date: Wed, 31 Jan 2024 19:37:13 +0800 Message-Id: <20240131113713.74779-7-rui.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240131113713.74779-1-rui.zhang@intel.com> References: <20240131113713.74779-1-rui.zhang@intel.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Sumeet Pawnikar Add support for LNL-M platform. Signed-off-by: Sumeet Pawnikar --- drivers/powercap/intel_rapl_common.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/powercap/intel_rapl_common.c b/drivers/powercap/intel_rapl_common.c index a3094cb9f296..aa627a6b12a4 100644 --- a/drivers/powercap/intel_rapl_common.c +++ b/drivers/powercap/intel_rapl_common.c @@ -1263,6 +1263,7 @@ static const struct x86_cpu_id rapl_ids[] __initconst = { X86_MATCH_INTEL_FAM6_MODEL(SAPPHIRERAPIDS_X, &rapl_defaults_spr_server), X86_MATCH_INTEL_FAM6_MODEL(EMERALDRAPIDS_X, &rapl_defaults_spr_server), X86_MATCH_INTEL_FAM6_MODEL(LUNARLAKE_M, &rapl_defaults_core), + X86_MATCH_INTEL_FAM6_MODEL(ARROWLAKE, &rapl_defaults_core), X86_MATCH_INTEL_FAM6_MODEL(LAKEFIELD, &rapl_defaults_core), X86_MATCH_INTEL_FAM6_MODEL(ATOM_SILVERMONT, &rapl_defaults_byt),