Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp723439rdd; Tue, 9 Jan 2024 19:05:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IF1heQRzihM3EGltFYPtRZfZ4hU5FK7C9bFGtoH3+Q3KkFH+yuX9v5HHfzOSTl5pg9g2uk+ X-Received: by 2002:a17:906:a24f:b0:a2b:1d51:a0a3 with SMTP id bi15-20020a170906a24f00b00a2b1d51a0a3mr231387ejb.92.1704855943961; Tue, 09 Jan 2024 19:05:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704855943; cv=none; d=google.com; s=arc-20160816; b=Hk5Q5ogooQaUXiMX4nvH/qyMQqk4wlfZuaVLUzfPivY1MJ8MW3blTfC1CXFwQtoH8K hFsafYcW0hTl2NTQCAdgh2BwU3EQs6hjgM8K/oTwgCgtVFeM+b064MJfvrMlhw2mfILO lLjf8G+ChX/uHKKiI7eZTKeo7EbG22sypTG2r6Q33bYdHRuNv6Ogzh3V7ewE/f3YlLk7 EG+18R0kfl4Uo+ln9cGsTr6ACTsu0xWmOXnJdzenElW1J7ON5ntDkyE8NlvQAKQOIJnE aekqPA53c3Li9FEMa/2CtmtNir6QdxjfosIXmBb7Lzgzhcov0JGvZN5a0G8rRhAOlC9q PfxQ== 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:message-id:date :subject:cc:to:from:dkim-signature; bh=3hpFKyc1rbB7+ZiL/nQux/IDUPloIWpBipxKtuuP8Iw=; fh=6JuzWURnijERx562KBcGG1aOrqYcDpLtDbmQyDGFfSA=; b=blbF1g54d45+JsRD6ExM3EzspfMtPm/ixOL+rzyDFEMTqqDTebXrxjnFvGuud58gln QdngZc78yYaONyKlkmkY9tPhDW5xiuiXAdmMogG+HaZrtK/W/PpEYn8AdLWq0Ilp7zgl Nzxduczyq2wM/5gve3jgE7vRjl0mHq1rQQodPOGECsYAsZkr+gN9V1uoh+9oQwzHgrnl U6B7SKy+xg09KlFVdXNTn9tJpfjplFUfUHvppIaoVAZ+a1haHu/HTki1SRdicu6NsDJX gcp4a0dXLLHL0p9vGTnyfPrGFlf1MjxPnN4byA5dCiYmGb05KLRFvbpJt0sNjQ3epcg5 f/zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ko93EGdJ; spf=pass (google.com: domain of linux-kernel+bounces-21671-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21671-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a8-20020a170906190800b00a27c4870128si1320913eje.877.2024.01.09.19.05.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 19:05:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21671-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ko93EGdJ; spf=pass (google.com: domain of linux-kernel+bounces-21671-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21671-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 98AF91F2622D for ; Wed, 10 Jan 2024 03:05:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 664A33234; Wed, 10 Jan 2024 03:05:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ko93EGdJ" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) (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 B727A1871; Wed, 10 Jan 2024 03:05:30 +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=1704855930; x=1736391930; h=from:to:cc:subject:date:message-id; bh=pHu+JjwxmcBrvbDLReMh07daUmBXGKOvaUBLbr2Vdns=; b=ko93EGdJE30AdGTe4KRDlnSCg0qfxOc/skxgkFlPUReIVbkrx7JkPGNF KB1nFsGPLpLutYryBBNTnOHOon997mzwqTpZlDUJEhMPd9n+2t95dtWn2 lNnF2cIn3JAbbVCA3LWQEe+5OvSPG4bHy9lVPzVbhMQ6JxvFl7sVmWn2V XlBJuFFNxfrrxyvTSeOXJMqlWzw1vAfBBU3SNo9qHESum9UxmKHl4JXgp dv3iy0iWTVRBue95KYaAJ5j2qKZgUH1dY33zLydxC22L09Ze3SAX5CMcd eA3r0vjsoIaaeTWwD5T88b4yrPMEumceaECtkDJc0zILRAA+eOuph6kC1 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10947"; a="397244704" X-IronPort-AV: E=Sophos;i="6.04,184,1695711600"; d="scan'208";a="397244704" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jan 2024 19:05:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10947"; a="1029002690" X-IronPort-AV: E=Sophos;i="6.04,184,1695711600"; d="scan'208";a="1029002690" Received: from ranerica-svr.sc.intel.com ([172.25.110.23]) by fmsmga006.fm.intel.com with ESMTP; 09 Jan 2024 19:05:29 -0800 From: Ricardo Neri To: "Rafael J. Wysocki" Cc: Chen Yu , Len Brown , Srinivas Pandruvada , Stanislaw Gruszka , Zhang Rui , Zhao Liu , Ricardo Neri , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] thermal: intel: hfi: Add syscore callbacks Date: Tue, 9 Jan 2024 19:07:04 -0800 Message-Id: <20240110030704.11305-1-ricardo.neri-calderon@linux.intel.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The kernel allocates a memory buffer and provides its location to the hardware, which uses it to update the HFI table. This allocation occurs during boot and remains constant throughout runtime. When resuming from 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. 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 (the hardware continues using the buffer from the restore kernel). It is also possible that the hardware forgets the address of the memory buffer when resuming from "deep" suspend. Memory corruption may also occur in such a scenario. To prevent the described memory corruption, disable HFI when preparing to suspend or hibernate. Enable it when resuming. Add syscore callbacks to handle the package of the boot CPU (packages of non-boot CPUs are handled via CPU offline). Syscore ops always run on the boot CPU. Additionally, HFI only needs to be disabled during "deep" suspend and hibernation. Syscore ops only run in these cases. 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 # 6.1 Signed-off-by: Ricardo Neri --- This is v3 of the patch [4/4] of [1]. Rafael has already accepted the first three patches. Thanks! I tested this patch on the testing branch of Rafael on Jan 9th. 2024. I tested it on a Meteor Lake system. It completed 1000 hibernation-resume cycles. [1]. https://lore.kernel.org/all/20240103041459.11113-1-ricardo.neri-calderon@linux.intel.com/ --- Changes since v2: * Switched to syscore ops instead of a suspend notifier as it is a better fit: we only need to handle the boot CPU, disabling HFI is only needed for "deep" suspend and hibernation. (Rafael) * Removed incorrect statement about the suspend flow in the commit message. (Rafael) Changes since v1: * Moved registration of the suspend notifier towards the end of intel_hfi_init(). (Stan) * Renamed hfi_do_pm_[enable|disable]() to hfi_do_[enable|disable](). Stan will use these functions outside the suspend notifier. (Stan) * Added locking to calls to hfi_[enable|disable]() from the suspend notifier. (Rafael) --- drivers/thermal/intel/intel_hfi.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/thermal/intel/intel_hfi.c b/drivers/thermal/intel/intel_hfi.c index 22445403b520..768cd5f9eb32 100644 --- a/drivers/thermal/intel/intel_hfi.c +++ b/drivers/thermal/intel/intel_hfi.c @@ -35,7 +35,9 @@ #include #include #include +#include #include +#include #include #include @@ -571,6 +573,30 @@ static __init int hfi_parse_features(void) return 0; } +static void hfi_do_enable(void) +{ + /* If we are here, we are on the boot CPU */ + struct hfi_cpu_info *info = &per_cpu(hfi_cpu_info, 0); + struct hfi_instance *hfi_instance = info->hfi_instance; + + /* No locking needed. There is no concurrency with CPU online. */ + hfi_set_hw_table(hfi_instance); + hfi_enable(); +} + +static int hfi_do_disable(void) +{ + /* No locking needed. There is no concurrency with CPU offline. */ + hfi_disable(); + + return 0; +} + +static struct syscore_ops hfi_pm_ops = { + .resume = hfi_do_enable, + .suspend = hfi_do_disable, +}; + void __init intel_hfi_init(void) { struct hfi_instance *hfi_instance; @@ -602,6 +628,8 @@ void __init intel_hfi_init(void) if (!hfi_updates_wq) goto err_nomem; + register_syscore_ops(&hfi_pm_ops); + return; err_nomem: -- 2.25.1