All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Cc: Hans de Goede <hansg@kernel.org>,
	platform-driver-x86@vger.kernel.org,
	 LKML <linux-kernel@vger.kernel.org>,
	Stable@vger.kernel.org
Subject: Re: [PATCH 3/3] platform/x86/intel/tpmi/plr: Prevent fault during unbind
Date: Thu, 30 Apr 2026 13:24:03 +0300 (EEST)	[thread overview]
Message-ID: <ef77dd1d-57bf-073d-4ef6-54cf70ddd12f@linux.intel.com> (raw)
In-Reply-To: <20260429195214.1532711-4-srinivas.pandruvada@linux.intel.com>

On Wed, 29 Apr 2026, Srinivas Pandruvada wrote:

> This driver faults when intel vsec driver unbound from PCI driver
> interface. For example:
> 
> echo 0000:00:03.1 > /sys/bus/pci/drivers/intel_vsec/unbind
> 
> This is caused by accessing plr->dbgfs_dir after vsec_tpmi driver is
> removed. Here vsec_tpmi driver is the parent. On unbind, the parent
> device remove callback is called first which here will remove debugfs
> interface. Hence plr->dbgfs_dir is no longer valid.
> 
> Register notifier for TPMI_CORE_EXIT and make this pointer to NULL,
> so that debugfs_remove_recursive() is not called with bad plr->dbgfs_dir
> pointer.
> 
> After notifier is returned the vsec_tpmi driver will call remove debugfs
> by calling debugfs_remove_recursive().
> 
> Fixes: 811f67c51636 ("platform/x86/intel/tpmi: Add new auxiliary driver for performance limits")
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> Cc: <Stable@vger.kernel.org>
> ---
>  drivers/platform/x86/intel/plr_tpmi.c | 43 +++++++++++++++++++++++++--
>  1 file changed, 41 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/platform/x86/intel/plr_tpmi.c b/drivers/platform/x86/intel/plr_tpmi.c
> index 05727169f49c..644df673896b 100644
> --- a/drivers/platform/x86/intel/plr_tpmi.c
> +++ b/drivers/platform/x86/intel/plr_tpmi.c
> @@ -22,6 +22,7 @@
>  #include <linux/module.h>
>  #include <linux/mod_devicetable.h>
>  #include <linux/mutex.h>
> +#include <linux/notifier.h>
>  #include <linux/seq_file.h>
>  #include <linux/sprintf.h>
>  #include <linux/types.h>
> @@ -60,6 +61,8 @@ struct tpmi_plr {
>  	struct tpmi_plr_die *die_info;
>  	int num_dies;
>  	struct auxiliary_device *auxdev;
> +	struct notifier_block nb;
> +	struct mutex lock; /* Protect access to dbgfs_dir  */

Extra whitespace.

Move the comment slightly more right as there's place.

>  };
>  
>  static const char * const plr_coarse_reasons[] = {
> @@ -255,6 +258,30 @@ static ssize_t plr_status_write(struct file *filp, const char __user *ubuf,
>  }
>  DEFINE_SHOW_STORE_ATTRIBUTE(plr_status);
>  
> +static int intel_plr_notify(struct notifier_block *self, unsigned long action, void *data)
> +{
> +	struct tpmi_plr *plr = container_of(self, struct tpmi_plr, nb);
> +
> +	if (action == TPMI_CORE_EXIT) {
> +		guard(mutex)(&plr->lock);
> +		plr->dbgfs_dir = NULL;
> +	}
> +
> +	return NOTIFY_DONE;
> +}
> +
> +static int intel_plr_register_notifier(struct notifier_block *nb)
> +{
> +	nb->notifier_call = intel_plr_notify;
> +	nb->priority = 0;
> +	return tpmi_register_notifier(nb);
> +}
> +
> +static void intel_plr_unregister_notifier(struct notifier_block *nb)
> +{
> +	tpmi_unregister_notifier(nb);
> +}
> +
>  static int intel_plr_probe(struct auxiliary_device *auxdev, const struct auxiliary_device_id *id)
>  {
>  	struct oobmsm_plat_info *plat_info;
> @@ -282,10 +309,16 @@ static int intel_plr_probe(struct auxiliary_device *auxdev, const struct auxilia
>  	if (!plr)
>  		return -ENOMEM;
>  
> +	mutex_init(&plr->lock);

This lacks pairing destroy, but you can probably use devm_mutex_init() as 
there's devm_*() below.

> +
> +	intel_plr_register_notifier(&plr->nb);
> +
>  	plr->die_info = devm_kcalloc(&auxdev->dev, num_resources, sizeof(*plr->die_info),
>  				     GFP_KERNEL);
> -	if (!plr->die_info)
> -		return -ENOMEM;
> +	if (!plr->die_info) {
> +		err = -ENOMEM;
> +		goto err_notify;
> +	}
>  
>  	plr->num_dies = num_resources;
>  	plr->dbgfs_dir = debugfs_create_dir("plr", dentry);
> @@ -326,6 +359,9 @@ static int intel_plr_probe(struct auxiliary_device *auxdev, const struct auxilia
>  
>  err:
>  	debugfs_remove_recursive(plr->dbgfs_dir);
> +err_notify:
> +	intel_plr_unregister_notifier(&plr->nb);
> +
>  	return err;
>  }
>  
> @@ -333,6 +369,9 @@ static void intel_plr_remove(struct auxiliary_device *auxdev)
>  {
>  	struct tpmi_plr *plr = auxiliary_get_drvdata(auxdev);
>  
> +	intel_plr_unregister_notifier(&plr->nb);
> +
> +	guard(mutex)(&plr->lock);
>  	debugfs_remove_recursive(plr->dbgfs_dir);
>  }
>  
> 

-- 
 i.


      reply	other threads:[~2026-04-30 10:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-29 19:52 [PATCH 0/3] platform/x86: intel: TPMI/PLR PCI unbind issue Srinivas Pandruvada
2026-04-29 19:52 ` [PATCH 1/3] platform/x86: intel: Move debugfs register before creating devices Srinivas Pandruvada
2026-04-29 19:52 ` [PATCH 2/3] platform/x86: intel: Add notifiers support Srinivas Pandruvada
2026-04-29 19:52 ` [PATCH 3/3] platform/x86/intel/tpmi/plr: Prevent fault during unbind Srinivas Pandruvada
2026-04-30 10:24   ` Ilpo Järvinen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ef77dd1d-57bf-073d-4ef6-54cf70ddd12f@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=Stable@vger.kernel.org \
    --cc=hansg@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=srinivas.pandruvada@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.