From: Dave Jiang <dave.jiang@intel.com>
To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev
Cc: djbw@kernel.org, iweiny@kernel.org, pasha.tatashin@soleen.com,
mclapinski@google.com, rppt@kernel.org,
joao.m.martins@oracle.com, jic23@kernel.org, gourry@gourry.net,
john@groves.net, rick.p.edgecombe@intel.com
Subject: [RFC PATCH 02/12] dax: Save the kva from memremap
Date: Thu, 23 Apr 2026 10:02:09 -0700 [thread overview]
Message-ID: <20260423170219.281618-3-dave.jiang@intel.com> (raw)
In-Reply-To: <20260423170219.281618-1-dave.jiang@intel.com>
This patch is partially taken from John Grove's famfs dax series.
Save the kva for memremap because we need direct_access() support.
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
drivers/dax/dax-private.h | 4 ++++
drivers/dax/device.c | 19 +++++++++++++++++++
2 files changed, 23 insertions(+)
diff --git a/drivers/dax/dax-private.h b/drivers/dax/dax-private.h
index c6ae27c982f4..425a515905e5 100644
--- a/drivers/dax/dax-private.h
+++ b/drivers/dax/dax-private.h
@@ -69,6 +69,8 @@ struct dev_dax_range {
* data while the device is activated in the driver.
* @region: parent region
* @dax_dev: core dax functionality
+ * @virt_addr: kva from memremap; used by fsdev_dax
+ * @cached_size: cached size of the memory range for quick access; used by fsdev_dax
* @align: alignment of this instance
* @target_node: effective numa node if dev_dax memory range is onlined
* @dyn_id: is this a dynamic or statically created instance
@@ -83,6 +85,8 @@ struct dev_dax_range {
struct dev_dax {
struct dax_region *region;
struct dax_device *dax_dev;
+ void *virt_addr;
+ u64 cached_size;
unsigned int align;
int target_node;
bool dyn_id;
diff --git a/drivers/dax/device.c b/drivers/dax/device.c
index 62206bcb63a6..4ffa3ef60a57 100644
--- a/drivers/dax/device.c
+++ b/drivers/dax/device.c
@@ -370,6 +370,7 @@ static int dax_open(struct inode *inode, struct file *filp)
filp->f_sb_err = file_sample_sb_err(filp);
filp->private_data = dev_dax;
inode->i_flags = S_DAX;
+ inode->i_size = dev_dax->cached_size;
return 0;
}
@@ -408,7 +409,9 @@ static int dev_dax_probe(struct dev_dax *dev_dax)
struct device *dev = &dev_dax->dev;
struct dev_pagemap *pgmap;
struct inode *inode;
+ u64 data_offset = 0;
struct cdev *cdev;
+ u64 len = 0;
void *addr;
int rc, i;
@@ -451,6 +454,7 @@ static int dev_dax_probe(struct dev_dax *dev_dax)
i, range->start, range->end);
return -EBUSY;
}
+ len += range_len(range);
}
pgmap->type = MEMORY_DEVICE_GENERIC;
@@ -461,6 +465,21 @@ static int dev_dax_probe(struct dev_dax *dev_dax)
if (IS_ERR(addr))
return PTR_ERR(addr);
+ /* Detect whether the data is at a non-zero offset into the memory */
+ if (pgmap->range.start != dev_dax->ranges[0].range.start) {
+ u64 phys = dev_dax->ranges[0].range.start;
+ u64 pgmap_phys = dev_dax->pgmap[0].range.start;
+
+ if (!WARN_ON(pgmap_phys > phys))
+ data_offset = phys - pgmap_phys;
+
+ pr_debug("%s: offset detected phys=%llx pgmap_phys=%llx offset=%llx\n",
+ __func__, phys, pgmap_phys, data_offset);
+ }
+
+ dev_dax->virt_addr = addr + data_offset;
+ dev_dax->cached_size = len;
+
inode = dax_inode(dax_dev);
cdev = inode->i_cdev;
cdev_init(cdev, &dax_fops);
--
2.53.0
next prev parent reply other threads:[~2026-04-23 17:02 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-23 17:02 [RFC PATCH 00/12] dax: Add DAX to guest memfd support for KVM Dave Jiang
2026-04-23 17:02 ` [RFC PATCH 01/12] dax: rate limit dev_dax_huge_fault() output Dave Jiang
2026-04-23 17:02 ` Dave Jiang [this message]
2026-04-23 17:02 ` [RFC PATCH 03/12] dax: Add fallocate support to device dax Dave Jiang
2026-04-23 17:02 ` [RFC PATCH 04/12] dax: Move dax_pgoff_to_phys() to dax bus to be used by dev dax Dave Jiang
2026-04-23 17:02 ` [RFC PATCH 05/12] dax: Add dax_operations and supporting functions to device dax Dave Jiang
2026-04-23 17:02 ` [RFC PATCH 06/12] dax: Add helper to determine if a 'struct file' supports dax Dave Jiang
2026-04-23 17:02 ` [RFC PATCH 07/12] KVM: guest_memfd: Add setup of daxfd when binding gmem Dave Jiang
2026-04-23 17:02 ` [RFC PATCH 08/12] fs: allow char dev to go through fallocate Dave Jiang
2026-04-23 17:02 ` [RFC PATCH 09/12] dax: Add dax_get_dev_dax() helper function Dave Jiang
2026-04-23 17:02 ` [RFC PATCH 10/12] kvm: Implement dax support for KVM faulting Dave Jiang
2026-04-23 17:02 ` [RFC PATCH 11/12] kvm: Add daxfd support for supported flags Dave Jiang
2026-04-23 17:02 ` [RFC PATCH 12/12] selftest/kvm: Add daxfd support for gmem selftest Dave Jiang
2026-04-23 17:27 ` [RFC PATCH 00/12] dax: Add DAX to guest memfd support for KVM Pasha Tatashin
2026-04-23 18:08 ` Dave Jiang
2026-04-23 18:21 ` Dave Jiang
2026-04-24 3:43 ` Gregory Price
2026-04-24 17:38 ` Frank van der Linden
2026-04-29 13:21 ` Ira Weiny
2026-04-29 23:58 ` Gregory Price
2026-04-24 17:13 ` Frank van der Linden
2026-04-24 18:23 ` Dave Jiang
2026-04-24 20:01 ` Frank van der Linden
2026-04-24 20:59 ` Dave Jiang
2026-05-06 20:23 ` Ackerley Tng
2026-05-06 20:37 ` Dave Jiang
2026-05-08 1:09 ` Ira Weiny
2026-05-10 14:40 ` Gregory Price
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=20260423170219.281618-3-dave.jiang@intel.com \
--to=dave.jiang@intel.com \
--cc=djbw@kernel.org \
--cc=gourry@gourry.net \
--cc=iweiny@kernel.org \
--cc=jic23@kernel.org \
--cc=joao.m.martins@oracle.com \
--cc=john@groves.net \
--cc=linux-cxl@vger.kernel.org \
--cc=mclapinski@google.com \
--cc=nvdimm@lists.linux.dev \
--cc=pasha.tatashin@soleen.com \
--cc=rick.p.edgecombe@intel.com \
--cc=rppt@kernel.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