Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp3203433rdb; Tue, 26 Dec 2023 22:29:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IEbErIug6/Baj0Zhn/aJ6Xv606jKOW5adsOWQ50dysAUhhf9d1hcdMq93k9QV7XCziui7wJ X-Received: by 2002:a17:906:d0db:b0:a27:22:40a9 with SMTP id bq27-20020a170906d0db00b00a27002240a9mr890018ejb.68.1703658552806; Tue, 26 Dec 2023 22:29:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703658552; cv=none; d=google.com; s=arc-20160816; b=qTKQq5r2wYuS26ej3ejmvRlpn/TdkiZYO0S3Nr5PXmRUqvrCsGtQvShAkxVmcVN6qp FJJhf01TLu9qCYCPqkUB4CQBmfPTpRJ81lQ6HYF3cJlcPmlxcEhzh6Alo36OfHgX/Dzk 0qyuaTZ+KrhgJVN8PFCB217favPZeHyt3j0fo8HljRUR1CExcAnKCNWXjfZydDSPf/pA sOs6uAFxQd3qSQpdM6SBUpduzDnf1cgakGjzma8+D0ykLqC0esL1fmhfFmMtCjbl9iqZ Q8bOqa5yNeD+coFshcbPPUCSCc12qUgtSZGmGmdnriduoNjcfA331mfLHM5UJeB+OGGb hYIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=EBclTDLttnG2G2Kj3Vj75holeBp6JLT7I/1KtcOhhGI=; fh=+uoRuePerzEUtGMtUkxhzXG+DZX8dBsFnLC2Ry+GNNY=; b=MHQ31esoLTZsoBfroJWo2hV4o+qYeo8SUmQiKLIVFZkkl8W5spcRqBhVBDqzYRd+0A jFNs6PKDbb+jI22otpeFvFiNE46/N1R35cNwboh2KSr8NDS5X2a95rLYdPqE0w6Z999Y ST7LsY+QGyeY6ESi5bxupskXacTMZ4+Duw03KWjI3PHlboH4vbs8t7WQd9EyAjmU8KeU XkuEvtN1ViM4ozw5P1zLTU9QaHWdoARJv4kKPP4Yxj19iY3nybZCnT29w1Bf8/Kq+Y5A aOqz5Z9Nq1jgTEZXOtUcWdnbXzGFUypWt4RnedwlX38F/YqTyfuWVoD7Vl4WV7jN8EzO OcDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gUqWbrR7; spf=pass (google.com: domain of linux-kernel+bounces-11862-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11862-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id fc4-20020a1709073a4400b00a26ae76c104si4734711ejc.173.2023.12.26.22.29.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Dec 2023 22:29:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-11862-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gUqWbrR7; spf=pass (google.com: domain of linux-kernel+bounces-11862-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11862-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8E5931F22D6B for ; Wed, 27 Dec 2023 06:29:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4FF427491; Wed, 27 Dec 2023 06:28:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="gUqWbrR7" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) (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 6F9A75C9C; Wed, 27 Dec 2023 06:28:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703658485; x=1735194485; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=Opg1f7F6WAG9qwnC6IpMUubGNjOktSJX+l64W9VgPXc=; b=gUqWbrR7gnU2G+7RQjoklWd44Nrd6mn2wYPmwyEnpe8e60kH27FXLASk gN9bnKPkXRhsoEWBjScjwdJBiLb4w8RUcQD5xxlidU1YtfEe8bGxNWqe5 LtZm+uOZT09XNlc3n/+7fSWrOHHWKYVHBMaXbN6UFzbmlyJbH9AgVEF6w 71gSpo+0XwStEF+Oe95E4FNaSKPh5z1iHLn8/Miy9eORFpI6p5pu5Wr2m qrxB8uixe8lm1eL/ZqmIAhi2N8FIoUK5OUmWWqJ3aAW9vIhF6jx17Fody /Ds5IXde49p0NhZL7bNJtRhWFwipH36tf3bC8WH9usH8vP+0LZjZiGXnw w==; X-IronPort-AV: E=McAfee;i="6600,9927,10935"; a="427584075" X-IronPort-AV: E=Sophos;i="6.04,308,1695711600"; d="scan'208";a="427584075" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Dec 2023 22:28:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10935"; a="1025316091" X-IronPort-AV: E=Sophos;i="6.04,308,1695711600"; d="scan'208";a="1025316091" Received: from ranerica-svr.sc.intel.com ([172.25.110.23]) by fmsmga006.fm.intel.com with ESMTP; 26 Dec 2023 22:28:00 -0800 From: Ricardo Neri To: "Rafael J. Wysocki" Cc: Chen Yu , Len Brown , Srinivas Pandruvada , Stanislaw Gruszka , Zhang Rui , Zhao Liu , stable@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Neri , Zhao Liu Subject: [PATCH 4/4] thermal: intel: hfi: Add a suspend notifier Date: Tue, 26 Dec 2023 22:29:40 -0800 Message-Id: <20231227062940.10780-5-ricardo.neri-calderon@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231227062940.10780-1-ricardo.neri-calderon@linux.intel.com> References: <20231227062940.10780-1-ricardo.neri-calderon@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The kernel gives the HFI hardware a memory region that the latter uses to provide updates to the HFI table. The kernel allocates this memory region at boot. It remains constant throughout runtime time. When resuming from suspend or hibernation, the restore kernel allocates a second memory buffer and reprograms the HFI hardware with the new location as part of a normal boot. The location of the second memory buffer may differ from the one allocated by the image kernel. Subsequently, when the restore kernel transfers control to the image kernel, the second buffer becomes invalid, potentially leading to memory corruption if the hardware writes to it (hardware continues using the buffer from the restore kernel). Add a suspend notifier to disable all HFI instances before jumping to the image kernel and enable them once the image kernel has been restored. Use the memory buffer that the image kernel allocated. For non-boot CPUs, rely on the CPU hotplug callbacks as CPUs are disabled and enabled during suspend and resume, respectively. The CPU hotplug callbacks do not cover the boot CPU. Handle the HFI instance of the boot CPU from the suspend notifier callback. Cc: Chen Yu Cc: Len Brown Cc: Srinivas Pandruvada Cc: Stanislaw Gruszka Cc: Zhang Rui Cc: Zhao Liu Cc: linux-pm@vger.kernel.org Cc: stable@vger.kernel.org Signed-off-by: Ricardo Neri --- drivers/thermal/intel/intel_hfi.c | 53 +++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/drivers/thermal/intel/intel_hfi.c b/drivers/thermal/intel/intel_hfi.c index d2c874f43786..965c245e5e78 100644 --- a/drivers/thermal/intel/intel_hfi.c +++ b/drivers/thermal/intel/intel_hfi.c @@ -30,11 +30,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -569,11 +571,62 @@ static __init int hfi_parse_features(void) return 0; } +static void hfi_do_pm_enable(void *info) +{ + struct hfi_instance *hfi_instance = info; + + hfi_set_hw_table(hfi_instance); + hfi_enable(); +} + +static void hfi_do_pm_disable(void *info) +{ + hfi_disable(); +} + +static int hfi_pm_notify(struct notifier_block *nb, + unsigned long mode, void *unused) +{ + struct hfi_cpu_info *info = &per_cpu(hfi_cpu_info, 0); + struct hfi_instance *hfi_instance = info->hfi_instance; + + /* HFI may not be in use. */ + if (!hfi_instance) + return 0; + + /* + * Only handle the HFI instance of the package of the boot CPU. The + * instances of other packages are handled in the CPU hotplug callbacks. + */ + switch (mode) { + case PM_HIBERNATION_PREPARE: + case PM_SUSPEND_PREPARE: + case PM_RESTORE_PREPARE: + return smp_call_function_single(0, hfi_do_pm_disable, + NULL, true); + + case PM_POST_RESTORE: + case PM_POST_HIBERNATION: + case PM_POST_SUSPEND: + return smp_call_function_single(0, hfi_do_pm_enable, + hfi_instance, true); + default: + return -EINVAL; + } +} + +static struct notifier_block hfi_pm_nb = { + .notifier_call = hfi_pm_notify, +}; + void __init intel_hfi_init(void) { struct hfi_instance *hfi_instance; int i, j; + if (register_pm_notifier(&hfi_pm_nb)) + return; + if (hfi_parse_features()) return; -- 2.25.1