Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.9 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795981497; b=KJVmymUk/5RFfXWcsF1E8cNLjl+leALYY9E0fAYetzc8ZbDyZaYo2cs93Nb5u4njlv1M xZhVe1voLZqV+iVN8l88APcAVDCmvrN+evSr5l2NlDx5x1lgxKrorcqqdAilKupqfKSy/ HiAXx/pnc4WBTkm7TTH96lVDqe6v89hjuZrJsjjuE7Up40GNsoZpNGxX0lAUSpL+K7HgB D8Ilddt/EukE8YA7MKep7Tj+LnbP4XjSClDZe62WRcyH3qACw7fV1LGQXl056QMJXufxw o+LBA6HHLRuktIg3LqxQf3I1SEPBoIe6aHJiKny6Dlrd26lnwTTXN3AEWWlzRMYa5wA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795981497; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=/QNFOwuH9JhjnFtm23kqEJYA3qzXyu+4Ijbb7MOg9PA=; b=dKhxwRvS9DPfTWTbeuDhISJTTZ24aGvYp/P/80SC3ix9YpHzGqfsJsDybGlJMuYFAKUj wWiJKDNhOcUM3MlDsvIPgS6GwKaNUOADtm9iiz/gq6DcgscA1Ns93WXrH+ldwqCibWpxR rYmajcbQXEsku3w1h2VxHUCAEuEU3Xt8+zGBnYmceXKNyEOjE1zodW6usoHK3dmFjSeLT FrthlRNF4P+Cv/dKbZg04iysFlG46+mEnXUhRdYA1nc5Ow3YXTCyO6gU6hydKXRnyfiR2 juDiU3at2ZMXhe+kvWamgXqgYcPdsTTync/U1WAAofbjdm1ffgg9r5RL2XG3L/nWuJA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=IYitybGC; arc=none smtp.remote-ip=198.175.65.9 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29753606A337; Sun, 29 Nov 2026 19:44:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 29753606A337 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=IYitybGC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1795981498; x=1827517498; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ihB9VqnxbD5wQK7AbLj7QOyPJmJrjwF+K/r1GH0j+2I=; b=IYitybGCWOp3Ili404KtJSgohnpSQD7BoLuyTox52f66cpTLCqbadNVd QUsnsoXpZmaC5j29V3kMp/VzstjkAK/CxtWGVdcDE5lrVbpVOoqJSIMdw d2Fm/AgvnFzIfOJI3syxuYWuD6WsoXPAn3Rlh5sReTJ/EYRs9Q9Pq46X1 SwGDZ/SbBsnIIjtfYvmB1MV3fAxMr8PabJyUDf0ww+RhvQ1AxYbb4zZfF atYHQSxkb0wX9Xz8Xwd4vx5uO7XXaPT0PYIJkthNpc6ddB7ksGStrKbjn d2fbqbcB7EGWTtxDiQk+0EoQFsGtOYsGgxTb8HgxFR4w3QGxKHXlUjgHT A==; X-CSE-ConnectionGUID: KkfcpKukRsGuheBA2AW4mg== X-CSE-MsgGUID: wceKSuNgTIiMryukFP1rLA== X-IronPort-AV: E=McAfee;i="6800,10657,11981"; a="4720134" X-IronPort-AV: E=Sophos;i="6.27,241,1787036400"; d="scan'208";a="4720134" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2026 11:44:56 -0800 X-CSE-ConnectionGUID: mUzOcJQBRhS5mccsdhKsKw== X-CSE-MsgGUID: /AshS5yqTmS7xWutaNULjQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,241,1787036400"; d="scan'208";a="12896569" Received: from spandruv-desk.jf.intel.com ([10.54.55.20]) by fmviesa005.fm.intel.com with ESMTP; 29 Nov 2026 11:44:56 -0800 From: Srinivas Pandruvada To: hansg@kernel.org, ilpo.jarvinen@linux.intel.com Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, kapoorarnav43@gmail.com, Srinivas Pandruvada Subject: [PATCH v2 2/2] platform/x86/intel-uncore-freq: Fix deadlock when removing attributes Date: Sun, 29 Nov 2026 11:44:45 -0800 Message-ID: <20261129194445.2805447-3-srinivas.pandruvada@linux.intel.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261129194445.2805447-1-srinivas.pandruvada@linux.intel.com> References: <20261129194445.2805447-1-srinivas.pandruvada@linux.intel.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit uncore_freq_remove_die_entry() holds uncore_lock while removing the attribute group of an entry. Removing attributes waits for active sysfs callbacks of these attributes to finish. But the show and store callbacks take uncore_lock, which results in an ABBA deadlock: CPU0 CPU1 ---- ---- kernfs_fop_read_iter() show_attr() uncore_freq_remove_die_entry() mutex_lock(&uncore_lock) mutex_lock(&uncore_lock) delete_attr_group() sysfs_remove_group() waits for CPU0 Mark the entry as not valid with an invalid control CPU under uncore_lock, and remove the attribute group after releasing it. Free the seqnum_id after the attribute group is removed, so that the name can't be used by a new entry while the old attributes still exist. Adding and removing the same entry is serialized by the callers: CPU hotplug callbacks in the MSR based driver, and device probe and remove in the TPMI driver. Callbacks running before the attributes are removed are safe: the MSR based driver returns -ENXIO for an invalid control CPU, and the TPMI driver MMIO is unmapped only after the device is removed. Fixes: ae7b2ce57851 ("platform/x86/intel/uncore-freq: Use sysfs API to create attributes") Signed-off-by: Srinivas Pandruvada --- v2: Use scoped_guard as suggested by Ilpo .../uncore-frequency-common.c | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c index 6051aa040abf..57e5941ae43e 100644 --- a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c +++ b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c @@ -5,6 +5,7 @@ * All rights reserved. * */ +#include #include #include #include "uncore-frequency-common.h" @@ -311,19 +312,24 @@ EXPORT_SYMBOL_NS_GPL(uncore_freq_add_entry, "INTEL_UNCORE_FREQUENCY"); void uncore_freq_remove_die_entry(struct uncore_data *data) { - mutex_lock(&uncore_lock); - /* Nothing to remove, if the entry was not added or already removed */ - if (!data->valid) - goto uncore_unlock; + scoped_guard(mutex, &uncore_lock) { + /* Nothing to remove, if the entry was not added or already removed */ + if (!data->valid) + return; + + data->control_cpu = -1; + data->valid = false; + } + /* + * Removing the attributes waits for active sysfs callbacks, which take + * uncore_lock. So this can't be done while holding uncore_lock. + */ delete_attr_group(data, data->name); - data->control_cpu = -1; - data->valid = false; + + /* Free the ID after the attributes with the name using it are removed */ if (data->domain_id != UNCORE_DOMAIN_ID_INVALID) ida_free(&intel_uncore_ida, data->seqnum_id); - -uncore_unlock: - mutex_unlock(&uncore_lock); } EXPORT_SYMBOL_NS_GPL(uncore_freq_remove_die_entry, "INTEL_UNCORE_FREQUENCY"); -- 2.56.0