Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp4676802rdb; Fri, 29 Dec 2023 09:27:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IEW/hWeMxLT1wZNqhOZtH/3ONFzH50SVDf+o8AjTLdDnu66OYG01yPkNT07igVHumBD7pxP X-Received: by 2002:a17:907:718d:b0:9e3:fbab:e091 with SMTP id zv13-20020a170907718d00b009e3fbabe091mr3602478ejb.15.1703870873020; Fri, 29 Dec 2023 09:27:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703870873; cv=none; d=google.com; s=arc-20160816; b=X20JF47BG+vN8wfqSkhgO3eKg+Zwip5Rj3FYwrzGhD+pPdidoVOmeLmmPKapV5YJw+ Cfb0SF49eBVbEoSQXOfmudLsypSBhs1anZWlZbKbN3/1yAvejM43/KBpRC1I5/SjGTQT 2YE0nI3x2Z8sQCYZLX5CJ7OSszT1PSi6adYj3oqZF/2LqI3y/K5f01Oyu6IpMwxIe1q8 Lghec8uc2T7TpMLTPUNiKJaodz2aZ8kJ8cmCS1CL9ho4sIQUj/rI2omU/kivQE2wQPRT TbUfZb3bA0fm4agS2GFG5JrdC7sby3MjNkdU/85HiUyIVpWVebsqUsNPWodmNGQBiD2r VXVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence; bh=qJAYsDTmYmyvQGFSeJtiB4aaPRQYv97IAZCo7KpDKGo=; fh=wjR6OO7JN4L0SmhSLzSHPpkiuz4pXAj+KoQOzF6st2E=; b=PXQbfUQV3pPr1A/15IAyDi8C7rWkkqMCfHHt+kE/k+Wtc80POizvZR9g0m5xIMyz/x UYdaXrLgFTmohn7iNq33b1mg5APmaju64LLZOybvoplJLeXbPuWMs6hun2qBZuP6oo1U MYK6pLX8K7NkspVJNWMgngD1r6UKelvp0noWmeRAylE0nxr52AisB+kY6qLZJIdCZAKN HVb9/um3qex/P4+VLBD8PssROSUo44q/cdZcuejSEltZayDsL4z0oesDTsSC5ay05qUs I5/qusAZnM7oGkrYbWgUVm3ruO7zOoOhew/UFSELarpZ/gXaZkZUlFX+ncnjim6CNfpm jyjA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-13182-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13182-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 11-20020a170906004b00b00a26db9496d5si5151878ejg.545.2023.12.29.09.27.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Dec 2023 09:27:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-13182-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; spf=pass (google.com: domain of linux-kernel+bounces-13182-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13182-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 BE5751F2116B for ; Fri, 29 Dec 2023 17:27:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F0DE012B8A; Fri, 29 Dec 2023 17:27:43 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11FB112B72; Fri, 29 Dec 2023 17:27:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ot1-f44.google.com with SMTP id 46e09a7af769-6dbca8c6eeeso1488846a34.1; Fri, 29 Dec 2023 09:27:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703870861; x=1704475661; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qJAYsDTmYmyvQGFSeJtiB4aaPRQYv97IAZCo7KpDKGo=; b=NxHycAn6keiJCyvJOx9CNRoB5861vX1e9fQ3bM8gIou8W1AKSJpY8tgd47bJ2LPm2A 2Px5PkNPHtfexKu2RJguPMdzrjXVglXhgrso2LMTqsyE3vbNZum9lcG9Ojqo35wDeJjo dqmKxM8s0GeNrueVJkgzNp/PNpcEjmJJEvyBB/V3uWWTLGycwuAcCr2sr/mPFfS9CeaI ziWFrm4tnsheEOOQu7lTiGzRcZTyrqy7FcpgBGpEELDY/+mhpAkydJZvbi7N7BPxbAmR SRV/9q9WAJJ8rrQ+QXn9HBoEryNolfTKTOlsfi29sG5VCEhx7SvtX48+wcEyXmM2csU2 lc6g== X-Gm-Message-State: AOJu0YxJCDpP5QfcLtY0Iq0BFYAGEWC/SvH3A1ZXS3LPnwTChADzpPKj JQf+iqv+yMfvinKopFh3bRLeVn4oYK2wZF4aKA8= X-Received: by 2002:a05:6820:358:b0:593:fbd5:10aa with SMTP id m24-20020a056820035800b00593fbd510aamr17655974ooe.1.1703870861144; Fri, 29 Dec 2023 09:27:41 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231227062940.10780-1-ricardo.neri-calderon@linux.intel.com> <20231227062940.10780-5-ricardo.neri-calderon@linux.intel.com> In-Reply-To: <20231227062940.10780-5-ricardo.neri-calderon@linux.intel.com> From: "Rafael J. Wysocki" Date: Fri, 29 Dec 2023 18:27:30 +0100 Message-ID: Subject: Re: [PATCH 4/4] thermal: intel: hfi: Add a suspend notifier To: Ricardo Neri Cc: "Rafael J. Wysocki" , 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, Zhao Liu Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Dec 27, 2023 at 7:28=E2=80=AFAM Ricardo Neri wrote: > > 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 locatio= n > 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/in= tel_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 =3D info; > + > + hfi_set_hw_table(hfi_instance); > + hfi_enable(); The above do RMW, so should locking be used here? > +} > + > +static void hfi_do_pm_disable(void *info) > +{ > + hfi_disable(); > +} And here? > + > +static int hfi_pm_notify(struct notifier_block *nb, > + unsigned long mode, void *unused) > +{ > + struct hfi_cpu_info *info =3D &per_cpu(hfi_cpu_info, 0); > + struct hfi_instance *hfi_instance =3D 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. T= he > + * instances of other packages are handled in the CPU hotplug cal= lbacks. > + */ > + 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 =3D { > + .notifier_call =3D 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; > > --