kaddr and pfn can be NULL to ->direct_access()
Subsystems (7)
v3 cover kaddr and pfn can be NULL to ->direct_access()
From: Huaisheng Ye <[email protected]>
Changes since v2 [2]:
* Collect Martin and Mike's acks for dcssblk and dm-writecache;
* Rebase the series of patch to v4.18-rc7.
Changes since v1 [1]:
* Involve the previous patches for pfn can be NULL.
* Reword the patch descriptions according to Christian's comment.
* According to Ross's suggestion, replace local pointer dummy_addr with NULL within md/dm-writecache for direct_access.
[1]: https://lkml.org/lkml/2018/7/24/199
[2]: https://lkml.org/lkml/2018/7/25/581
Some functions within fs/dax, dax/super and md/dm-writecache don't need to get local pointer kaddr or variable pfn from direct_access. Assigning NULL to kaddr or pfn with ->direct_access() is more straightforward and simple than offering a useless local pointer or variable.
So all ->direct_access() need to check the validity of pointer kaddr and pfn for NULL assignment. If either of them is equal to NULL, that is to say callers may have no need for kaddr or pfn, so this series of patch are prepared for allowing them to pass in NULL instead of having to pass in a local pointer or variable that they then just throw away.
Huaisheng Ye (6):
libnvdimm, pmem: kaddr and pfn can be NULL to ->direct_access() s390, dcssblk: kaddr and pfn can be NULL to ->direct_access() tools/testing/nvdimm: kaddr and pfn can be NULL to ->direct_access() dax/super: Do not request a pointer kaddr when not required md/dm-writecache: Don't request pointer dummy_addr when not required
filesystem-dax: Do not request kaddr and pfn when not required
drivers/dax/super.c | 3 +-- drivers/md/dm-writecache.c | 3 +-- drivers/nvdimm/pmem.c | 7 +++++-- drivers/s390/block/dcssblk.c | 8 +++++--- fs/dax.c | 13 ++++--------- tools/testing/nvdimm/pmem-dax.c | 12 ++++++++---- 6 files changed, 24 insertions(+), 22 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v3 1/6 libnvdimm, pmem: kaddr and pfn can be NULL to ->direct_access()
From: Huaisheng Ye <[email protected]>
pmem_direct_access() needs to check the validity of pointers kaddr and pfn for NULL assignment. If anyone equals to NULL, it doesn't need to calculate the value.
If pointer equals to NULL, that is to say callers may have no need for kaddr or pfn, so this patch is prepared for allowing them to pass in NULL instead of having to pass in a pointer or local variable that they then just throw away.
--- drivers/nvdimm/pmem.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/nvdimm/pmem.c +5 -2
@@ -227,8 +227,11 @@ __weak long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff,if (unlikely (is_bad_pmem (&pmem->bb,PFN_PHYS (pgoff) /512 ,PFN_PHYS (nr_pages))))return -EIO ; - *kaddr = pmem->virt_addr + offset; - *pfn =phys_to_pfn_t (pmem->phys_addr + offset, pmem->pfn_flags); + +if (kaddr) + *kaddr = pmem->virt_addr + offset; +if (pfn) + *pfn =phys_to_pfn_t (pmem->phys_addr + offset, pmem->pfn_flags);/* * If badblocks are present, limit known good range to the
Signature · 1 line
1.8.3.1
PATCH v3 2/6 s390, dcssblk: kaddr and pfn can be NULL to ->direct_access()
In reply to Huaisheng YeFrom: Huaisheng Ye <[email protected]>
dcssblk_direct_access() needs to check the validity of pointers kaddr and pfn for NULL assignment. If anyone equals to NULL, it doesn't need to calculate the value.
If either of them is equal to NULL, that is to say callers may have no need for kaddr or pfn, so this patch is prepared for allowing them to pass in NULL instead of having to pass in a pointer or local variable that they then just throw away.
--- drivers/s390/block/dcssblk.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/s390/block/dcssblk.c +5 -3
@@ -922,9 +922,11 @@ static DEVICE_ATTR(save, S_IWUSR | S_IRUSR, dcssblk_save_show,unsigned long dev_sz; dev_sz = dev_info->end - dev_info->start +1 ; - *kaddr = (void *) dev_info->start + offset; - *pfn =__pfn_to_pfn_t (PFN_DOWN (dev_info->start + offset), -PFN_DEV |PFN_SPECIAL ); +if (kaddr) + *kaddr = (void *) dev_info->start + offset; +if (pfn) + *pfn =__pfn_to_pfn_t (PFN_DOWN (dev_info->start + offset), +PFN_DEV |PFN_SPECIAL );return (dev_sz - offset) /PAGE_SIZE ; }
Signature · 1 line
1.8.3.1
PATCH v3 3/6 tools/testing/nvdimm: kaddr and pfn can be NULL to ->direct_access()
In reply to Huaisheng YeFrom: Huaisheng Ye <[email protected]>
The mock / test version of pmem_direct_access() needs to check the validity of pointers kaddr and pfn for NULL assignment. If anyone equals to NULL, it doesn't need to calculate the value.
If pointer equals to NULL, that is to say callers may have no need for kaddr or pfn, so this patch is prepared for allowing them to pass in NULL instead of having to pass in a local pointer or variable that they then just throw away.
--- tools/testing/nvdimm/pmem-dax.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
tools/testing/nvdimm/pmem-dax.c +8 -4
@@ -31,17 +31,21 @@ long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff,if (get_nfit_res (pmem->phys_addr + offset)) {struct page *page; - *kaddr = pmem->virt_addr + offset; +if (kaddr) + *kaddr = pmem->virt_addr + offset; page =vmalloc_to_page (pmem->virt_addr + offset); - *pfn =page_to_pfn_t (page); +if (pfn) + *pfn =page_to_pfn_t (page);pr_debug_ratelimited ("%s: pmem: %p pgoff: %#lx pfn: %#lx\n" , __func__, pmem, pgoff,page_to_pfn (page));return 1 ; } - *kaddr = pmem->virt_addr + offset; - *pfn =phys_to_pfn_t (pmem->phys_addr + offset, pmem->pfn_flags); +if (kaddr) + *kaddr = pmem->virt_addr + offset; +if (pfn) + *pfn =phys_to_pfn_t (pmem->phys_addr + offset, pmem->pfn_flags);/* * If badblocks are present, limit known good range to the
Signature · 1 line
1.8.3.1
PATCH v3 4/6 dax/super: Do not request a pointer kaddr when not required
In reply to Huaisheng YeFrom: Huaisheng Ye <[email protected]>
Function __bdev_dax_supported doesn't need to get local pointer kaddr from direct_access. Using NULL instead of having to pass in a useless local pointer that caller then just throw away.
--- drivers/dax/super.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/dax/super.c +1 -2
@@ -89,7 +89,6 @@ bool __bdev_dax_supported(struct block_device *bdev, int blocksize)struct request_queue *q;pgoff_t pgoff;int err, id; -void *kaddr;pfn_t pfn;long len;char buf[BDEVNAME_SIZE ];
@@ -122,7 +121,7 @@ bool __bdev_dax_supported(struct block_device *bdev, int blocksize) } id =dax_read_lock (); - len =dax_direct_access (dax_dev, pgoff,1 , &kaddr, &pfn); + len =dax_direct_access (dax_dev, pgoff,1 ,NULL , &pfn);dax_read_unlock (id);put_dax (dax_dev);
Signature · 1 line
1.8.3.1
PATCH v3 5/6 md/dm-writecache: Don't request pointer dummy_addr when not required
In reply to Huaisheng YeFrom: Huaisheng Ye <[email protected]>
Function persistent_memory_claim doesn't need to get local pointer dummy_addr from direct_access. Using NULL instead of having to pass in a useless local pointer that caller then just throw away.
--- drivers/md/dm-writecache.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/md/dm-writecache.c +1 -2
@@ -268,9 +268,8 @@ static int persistent_memory_claim(struct dm_writecache *wc) i =0 ; do { long daa; - void *dummy_addr; daa = dax_direct_access(wc->ssd_dev->dax_dev, i, p - i, - &dummy_addr, &pfn); + NULL, &pfn); if (daa <= 0) { r = daa ? daa : -EINVAL; goto err3;
Signature · 1 line
1.8.3.1
PATCH v3 6/6 filesystem-dax: Do not request kaddr and pfn when not required
In reply to Huaisheng YeFrom: Huaisheng Ye <[email protected]>
Some functions within fs/dax don't need to get local pointer kaddr or variable pfn from direct_access. Using NULL instead of having to pass in useless pointer or variable that caller then just throw away.
--- fs/dax.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
fs/dax.c +4 -9
@@ -647,7 +647,6 @@ static int copy_user_dax(struct block_device *bdev, struct dax_device *dax_dev, {void *vto, *kaddr;pgoff_t pgoff; -pfn_t pfn;long rc;int id;
@@ -656,7 +655,7 @@ static int copy_user_dax(struct block_device *bdev, struct dax_device *dax_dev,return rc; id =dax_read_lock (); - rc =dax_direct_access (dax_dev, pgoff,PHYS_PFN (size), &kaddr, &pfn); + rc =dax_direct_access (dax_dev, pgoff,PHYS_PFN (size), &kaddr,NULL );if (rc <0 ) {dax_read_unlock (id);return rc;
@@ -967,7 +966,6 @@ static int dax_iomap_pfn(struct iomap *iomap, loff_t pos, size_t size, {const sector_t sector =dax_iomap_sector (iomap, pos);pgoff_t pgoff; -void *kaddr;int id, rc;long length;
@@ -976,7 +974,7 @@ static int dax_iomap_pfn(struct iomap *iomap, loff_t pos, size_t size,return rc; id =dax_read_lock (); length =dax_direct_access (iomap->dax_dev, pgoff,PHYS_PFN (size), - &kaddr, pfnp); +NULL , pfnp);if (length <0 ) { rc = length; goto out;
@@ -1052,15 +1050,13 @@ int __dax_zero_page_range(struct block_device *bdev,pgoff_t pgoff;long rc, id;void *kaddr; -pfn_t pfn; rc =bdev_dax_pgoff (bdev, sector,PAGE_SIZE , &pgoff);if (rc)return rc; id =dax_read_lock (); - rc =dax_direct_access (dax_dev, pgoff,1 , &kaddr, - &pfn); + rc =dax_direct_access (dax_dev, pgoff,1 , &kaddr,NULL );if (rc <0 ) {dax_read_unlock (id);return rc;
@@ -1116,7 +1112,6 @@ int __dax_zero_page_range(struct block_device *bdev,ssize_t map_len;pgoff_t pgoff;void *kaddr; -pfn_t pfn;if (fatal_signal_pending (current)) { ret = -EINTR ;
@@ -1128,7 +1123,7 @@ int __dax_zero_page_range(struct block_device *bdev,break ; map_len =dax_direct_access (dax_dev, pgoff,PHYS_PFN (size), - &kaddr, &pfn); + &kaddr,NULL );if (map_len <0 ) { ret = map_len;break ;
Signature · 1 line
1.8.3.1
Missing one in changes log.
Quoted 8 lines
From: Huaisheng Ye <[email protected]>
Sent: Monday, July 30, 2018 3:16 PMFrom: Huaisheng Ye <[email protected]>
Changes since v2 [2]:
* Collect Martin and Mike's acks for dcssblk and dm-writecache;
* Rebase the series of patch to v4.18-rc7.
* Collect Ross's reviewed-by for series.
Quoted 41 lines
Changes since v1 [1]:
* Involve the previous patches for pfn can be NULL.
* Reword the patch descriptions according to Christian's comment.
* According to Ross's suggestion, replace local pointerdummy_addrwith NULL within md/dm-writecache fordirect_access.[1]: https://lkml.org/lkml/2018/7/24/199
[2]: https://lkml.org/lkml/2018/7/25/581Some functions within fs/dax, dax/super and md/dm-writecache don't need to get local pointer kaddr or variable pfn from
direct_access. Assigning NULL to kaddr or pfn with ->direct_access() is more straightforward and simple than offering a useless local pointer or variable.So all ->direct_access() need to check the validity of pointer kaddr and pfn for NULL assignment. If either of them is equal to NULL, that is to say callers may have no need for kaddr or pfn, so this series of patch are prepared for allowing them to pass in NULL instead of having to pass in a local pointer or variable that they then just throw away.
Huaisheng Ye (6):
libnvdimm, pmem: kaddr and pfn can be NULL to ->direct_access() s390, dcssblk: kaddr and pfn can be NULL to ->direct_access()tools/testing/nvdimm: kaddr and pfn can be NULL to ->direct_access() dax/super: Do not request a pointer kaddr when not required md/dm-writecache: Don't request pointerdummy_addrwhen not required
filesystem-dax: Do not request kaddr and pfn when not requireddrivers/dax/super.c | 3 +-- drivers/md/dm-writecache.c | 3 +-- drivers/nvdimm/pmem.c | 7 +++++-- drivers/s390/block/dcssblk.c | 8 +++++--- fs/dax.c | 13 ++++--------- tools/testing/nvdimm/pmem-dax.c | 12 ++++++++---- 6 files changed, 24 insertions(+), 22 deletions(-)--
1.8.3.1
On 7/30/2018 12:15 AM, Huaisheng Ye wrote:
Applied
Quoted 43 lines
From: Huaisheng Ye <[email protected]>
Changes since v2 [2]:
* Collect Martin and Mike's acks for dcssblk and dm-writecache;
* Rebase the series of patch to v4.18-rc7.Changes since v1 [1]:
* Involve the previous patches for pfn can be NULL.
* Reword the patch descriptions according to Christian's comment.
* According to Ross's suggestion, replace local pointerdummy_addrwith NULL within md/dm-writecache fordirect_access.[1]: https://lkml.org/lkml/2018/7/24/199
[2]: https://lkml.org/lkml/2018/7/25/581Some functions within fs/dax, dax/super and md/dm-writecache don't need to get local pointer kaddr or variable pfn from
direct_access. Assigning NULL to kaddr or pfn with ->direct_access() is more straightforward and simple than offering a useless local pointer or variable.So all ->direct_access() need to check the validity of pointer kaddr and pfn for NULL assignment. If either of them is equal to NULL, that is to say callers may have no need for kaddr or pfn, so this series of patch are prepared for allowing them to pass in NULL instead of having to pass in a local pointer or variable that they then just throw away.
Huaisheng Ye (6):
libnvdimm, pmem: kaddr and pfn can be NULL to ->direct_access() s390, dcssblk: kaddr and pfn can be NULL to ->direct_access()tools/testing/nvdimm: kaddr and pfn can be NULL to ->direct_access() dax/super: Do not request a pointer kaddr when not required md/dm-writecache: Don't request pointerdummy_addrwhen not required
filesystem-dax: Do not request kaddr and pfn when not requireddrivers/dax/super.c | 3 +-- drivers/md/dm-writecache.c | 3 +-- drivers/nvdimm/pmem.c | 7 +++++-- drivers/s390/block/dcssblk.c | 8 +++++--- fs/dax.c | 13 ++++--------- tools/testing/nvdimm/pmem-dax.c | 12 ++++++++---- 6 files changed, 24 insertions(+), 22 deletions(-)