mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Richard Cheng <icheng@nvidia.com>
To: John Groves <john@jagalactic.com>
Cc: John Groves <John@groves.net>, Dan Williams <djbw@kernel.org>,
	 John Groves <jgroves@micron.com>,
	Vishal Verma <vishal.l.verma@intel.com>,
	 Dave Jiang <dave.jiang@intel.com>,
	Matthew Wilcox <willy@infradead.org>, Jan Kara <jack@suse.cz>,
	 Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>,
	 Miklos Szeredi <miklos@szeredi.hu>,
	Alison Schofield <alison.schofield@intel.com>,
	 Ira Weiny <iweiny@kernel.org>,
	Jonathan Cameron <jic23@kernel.org>,
	 "nvdimm@lists.linux.dev" <nvdimm@lists.linux.dev>,
	"linux-cxl@vger.kernel.org" <linux-cxl@vger.kernel.org>,
	 "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>
Subject: Re: [PATCH V6 05/10] dax/fsdev: clear pgmap ops and owner on unbind
Date: Mon, 22 Jun 2026 18:31:52 +0800	[thread overview]
Message-ID: <ajkO7yiGplFl4MIa@MWDK4CY14F> (raw)
In-Reply-To: <0100019ecc094b6e-fc163bde-0396-4a33-909f-fb88e740be27-000000@email.amazonses.com>

On Mon, Jun 15, 2026 at 04:07:01PM +0800, John Groves wrote:
> From: John Groves <John@Groves.net>
> 
> fsdev_dax_probe() sets pgmap->ops = &fsdev_pagemap_ops and
> pgmap->owner = dev_dax, but nothing ever clears them. For a dynamic
> device the pgmap is devm-allocated and freed on unbind, so this is
> harmless. For a static device the pgmap is the shared, long-lived one
> owned by the dax bus (kill_dev_dax() only NULLs dev_dax->pgmap for the
> non-static case), and device.c's probe sets only pgmap->type, never
> clearing ops/owner.
> 
> So after fsdev unbinds a static device the stale fsdev_pagemap_ops
> survives on the shared pgmap. If the device is then rebound to
> device_dax (MEMORY_DEVICE_GENERIC, which installs no ->memory_failure),
> or the fsdev_dax module is unloaded, a subsequent memory_failure on that
> pgmap dispatches through the stale -- and possibly freed -- handler.
> 
> Register a devm action that clears pgmap->ops and pgmap->owner on unbind,
> symmetric with setting them at probe, so the pgmap carries no fsdev state
> once fsdev is detached.
> 
> Suggested-by: Richard Cheng <icheng@nvidia.com>
> Fixes: d5406bd458b0a ("dax: add fsdev.c driver for fs-dax on character dax")
> Signed-off-by: John Groves <john@groves.net>
> ---
>  drivers/dax/fsdev.c | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/drivers/dax/fsdev.c b/drivers/dax/fsdev.c
> index 0fd5e1293d725..68a4369562f70 100644
> --- a/drivers/dax/fsdev.c
> +++ b/drivers/dax/fsdev.c
> @@ -127,6 +127,23 @@ static void fsdev_clear_ops(void *data)
>  	dax_set_ops(dev_dax->dax_dev, NULL);
>  }
>  
> +static void fsdev_clear_pgmap_ops(void *data)
> +{
> +	struct dev_pagemap *pgmap = data;
> +
> +	/*
> +	 * fsdev installs pgmap->ops and ->owner at probe. For a static device
> +	 * the pgmap is shared and long-lived (owned by the dax bus), so
> +	 * leaving fsdev's ops behind on unbind would let a later
> +	 * memory_failure -- after rebind to another driver, or after this
> +	 * module is unloaded -- dispatch through a stale or freed
> +	 * ->memory_failure handler. Clear them so the pgmap carries no fsdev
> +	 * state once we are unbound.
> +	 */
> +	pgmap->ops = NULL;
> +	pgmap->owner = NULL;
> +}
> +
>  /*
>   * Page map operations for FS-DAX mode
>   * Similar to fsdax_pagemap_ops in drivers/nvdimm/pmem.c
> @@ -306,6 +323,11 @@ static int fsdev_dax_probe(struct dev_dax *dev_dax)
>  	if (IS_ERR(addr))
>  		return PTR_ERR(addr);
>  
> +	/* Drop fsdev's pgmap->ops/owner on unbind so no stale ops survive. */
> +	rc = devm_add_action_or_reset(dev, fsdev_clear_pgmap_ops, pgmap);
> +	if (rc)
> +		return rc;
> +
>  	/*
>  	 * Clear any stale compound folio state left over from a previous
>  	 * driver (e.g., device_dax with vmemmap_shift). Also register this
> -- 
> 2.53.0
>

Thanks for this, LGTM.

Reviewed-by: Richard Cheng <icheng@nvidia.com>

Best regards,
Richard Cheng. 

  reply	other threads:[~2026-06-22 10:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260615160531.17432-1-john@jagalactic.com>
2026-06-15 16:05 ` [PATCH V6 0/10] Fixes to the previously-merged drivers/dax/fsdev series John Groves
     [not found]   ` <20260615160616.17456-1-john@jagalactic.com>
2026-06-15 16:06     ` [PATCH V6 01/10] dax: fix misleading comment about share/index union in dax_folio_reset_order() John Groves
     [not found]   ` <20260615160626.17473-1-john@jagalactic.com>
2026-06-15 16:06     ` [PATCH V6 02/10] dax/fsdev: fix multi-range offset in memory_failure handler John Groves
2026-06-23  6:55       ` Richard Cheng
     [not found]   ` <20260615160634.17496-1-john@jagalactic.com>
2026-06-15 16:06     ` [PATCH V6 03/10] dax/fsdev: clear vmemmap_shift when binding static pgmap John Groves
     [not found]   ` <20260615160648.17513-1-john@jagalactic.com>
2026-06-15 16:06     ` [PATCH V6 04/10] dax/fsdev: don't leave a dangling dev_dax->pgmap on probe failure John Groves
     [not found]   ` <20260615160656.17533-1-john@jagalactic.com>
2026-06-15 16:07     ` [PATCH V6 05/10] dax/fsdev: clear pgmap ops and owner on unbind John Groves
2026-06-22 10:31       ` Richard Cheng [this message]
     [not found]   ` <20260615160704.17550-1-john@jagalactic.com>
2026-06-15 16:07     ` [PATCH V6 06/10] dax/fsdev: use __va(phys) for kaddr in direct_access John Groves
     [not found]   ` <20260615160713.17567-1-john@jagalactic.com>
2026-06-15 16:07     ` [PATCH V6 07/10] dax/fsdev: fail probe on invalid pgmap offset John Groves
     [not found]   ` <20260615160724.17584-1-john@jagalactic.com>
2026-06-15 16:07     ` [PATCH V6 08/10] dax: read holder_ops once in dax_holder_notify_failure() John Groves
     [not found]   ` <20260615160733.17601-1-john@jagalactic.com>
2026-06-15 16:07     ` [PATCH V6 09/10] dax: fix holder_ops race in fs_put_dax() John Groves
     [not found]   ` <20260615160741.17618-1-john@jagalactic.com>
2026-06-15 16:07     ` [PATCH V6 10/10] dax: fsdev.c minor formatting cleanup John Groves
2026-07-15  0:06   ` [PATCH V6 0/10] Fixes to the previously-merged drivers/dax/fsdev series Alison Schofield

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=ajkO7yiGplFl4MIa@MWDK4CY14F \
    --to=icheng@nvidia.com \
    --cc=John@groves.net \
    --cc=alison.schofield@intel.com \
    --cc=brauner@kernel.org \
    --cc=dave.jiang@intel.com \
    --cc=djbw@kernel.org \
    --cc=iweiny@kernel.org \
    --cc=jack@suse.cz \
    --cc=jgroves@micron.com \
    --cc=jic23@kernel.org \
    --cc=john@jagalactic.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=nvdimm@lists.linux.dev \
    --cc=viro@zeniv.linux.org.uk \
    --cc=vishal.l.verma@intel.com \
    --cc=willy@infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome