2021-02-07 17:12:43

by Ruan Shiyang

[permalink] [raw]
Subject: [PATCH 1/7] fsdax: Output address in dax_iomap_pfn() and rename it

Add address output in dax_iomap_pfn() in order to perform a memcpy() in
CoW case. Since this function both output address and pfn, rename it to
dax_iomap_direct_access().

Signed-off-by: Shiyang Ruan <[email protected]>
---
fs/dax.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/fs/dax.c b/fs/dax.c
index 5b47834f2e1b..b012b2db7ba2 100644
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -998,8 +998,8 @@ static sector_t dax_iomap_sector(struct iomap *iomap, loff_t pos)
return (iomap->addr + (pos & PAGE_MASK) - iomap->offset) >> 9;
}

-static int dax_iomap_pfn(struct iomap *iomap, loff_t pos, size_t size,
- pfn_t *pfnp)
+static int dax_iomap_direct_access(struct iomap *iomap, loff_t pos, size_t size,
+ void **kaddr, pfn_t *pfnp)
{
const sector_t sector = dax_iomap_sector(iomap, pos);
pgoff_t pgoff;
@@ -1011,11 +1011,13 @@ 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),
- NULL, pfnp);
+ kaddr, pfnp);
if (length < 0) {
rc = length;
goto out;
}
+ if (!pfnp)
+ goto out_check_addr;
rc = -EINVAL;
if (PFN_PHYS(length) < size)
goto out;
@@ -1025,6 +1027,12 @@ static int dax_iomap_pfn(struct iomap *iomap, loff_t pos, size_t size,
if (length > 1 && !pfn_t_devmap(*pfnp))
goto out;
rc = 0;
+
+out_check_addr:
+ if (!kaddr)
+ goto out;
+ if (!*kaddr)
+ rc = -EFAULT;
out:
dax_read_unlock(id);
return rc;
@@ -1348,7 +1356,8 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp,
count_memcg_event_mm(vma->vm_mm, PGMAJFAULT);
major = VM_FAULT_MAJOR;
}
- error = dax_iomap_pfn(&iomap, pos, PAGE_SIZE, &pfn);
+ error = dax_iomap_direct_access(&iomap, pos, PAGE_SIZE,
+ NULL, &pfn);
if (error < 0)
goto error_finish_iomap;

@@ -1566,7 +1575,8 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp,

switch (iomap.type) {
case IOMAP_MAPPED:
- error = dax_iomap_pfn(&iomap, pos, PMD_SIZE, &pfn);
+ error = dax_iomap_direct_access(&iomap, pos, PMD_SIZE,
+ NULL, &pfn);
if (error < 0)
goto finish_iomap;

--
2.30.0




2021-02-22 07:49:02

by Xiaoguang Wang

[permalink] [raw]
Subject: Re: [PATCH 1/7] fsdax: Output address in dax_iomap_pfn() and rename it

hi,

> Add address output in dax_iomap_pfn() in order to perform a memcpy() in
> CoW case. Since this function both output address and pfn, rename it to
> dax_iomap_direct_access().
>
> Signed-off-by: Shiyang Ruan <[email protected]>
> ---
> fs/dax.c | 20 +++++++++++++++-----
> 1 file changed, 15 insertions(+), 5 deletions(-)
>
> diff --git a/fs/dax.c b/fs/dax.c
> index 5b47834f2e1b..b012b2db7ba2 100644
> --- a/fs/dax.c
> +++ b/fs/dax.c
> @@ -998,8 +998,8 @@ static sector_t dax_iomap_sector(struct iomap *iomap, loff_t pos)
> return (iomap->addr + (pos & PAGE_MASK) - iomap->offset) >> 9;
> }
>
> -static int dax_iomap_pfn(struct iomap *iomap, loff_t pos, size_t size,
> - pfn_t *pfnp)
> +static int dax_iomap_direct_access(struct iomap *iomap, loff_t pos, size_t size,
> + void **kaddr, pfn_t *pfnp)
> {
> const sector_t sector = dax_iomap_sector(iomap, pos);
> pgoff_t pgoff;
> @@ -1011,11 +1011,13 @@ 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),
> - NULL, pfnp);
> + kaddr, pfnp);
> if (length < 0) {
> rc = length;
> goto out;
> }
> + if (!pfnp)
Should this be "if (!*pfnp)"?

Regards,
Xiaoguang Wang
> + goto out_check_addr;
> rc = -EINVAL;
> if (PFN_PHYS(length) < size)
> goto out;
> @@ -1025,6 +1027,12 @@ static int dax_iomap_pfn(struct iomap *iomap, loff_t pos, size_t size,
> if (length > 1 && !pfn_t_devmap(*pfnp))
> goto out;
> rc = 0;
> +
> +out_check_addr:
> + if (!kaddr)
> + goto out;
> + if (!*kaddr)
> + rc = -EFAULT;
> out:
> dax_read_unlock(id);
> return rc;
> @@ -1348,7 +1356,8 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp,
> count_memcg_event_mm(vma->vm_mm, PGMAJFAULT);
> major = VM_FAULT_MAJOR;
> }
> - error = dax_iomap_pfn(&iomap, pos, PAGE_SIZE, &pfn);
> + error = dax_iomap_direct_access(&iomap, pos, PAGE_SIZE,
> + NULL, &pfn);
> if (error < 0)
> goto error_finish_iomap;
>
> @@ -1566,7 +1575,8 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp,
>
> switch (iomap.type) {
> case IOMAP_MAPPED:
> - error = dax_iomap_pfn(&iomap, pos, PMD_SIZE, &pfn);
> + error = dax_iomap_direct_access(&iomap, pos, PMD_SIZE,
> + NULL, &pfn);
> if (error < 0)
> goto finish_iomap;
>
>

2021-02-23 02:22:42

by Shiyang Ruan

[permalink] [raw]
Subject: 回复: [PATCH 1/7] fsdax: Output address in da x_iomap_pfn() and rename it

> hi,
>
> > Add address output in dax_iomap_pfn() in order to perform a memcpy() in
> > CoW case. Since this function both output address and pfn, rename it to
> > dax_iomap_direct_access().
> >
> > Signed-off-by: Shiyang Ruan <[email protected]>
> > ---
> > fs/dax.c | 20 +++++++++++++++-----
> > 1 file changed, 15 insertions(+), 5 deletions(-)
> >
> > diff --git a/fs/dax.c b/fs/dax.c
> > index 5b47834f2e1b..b012b2db7ba2 100644
> > --- a/fs/dax.c
> > +++ b/fs/dax.c
> > @@ -998,8 +998,8 @@ static sector_t dax_iomap_sector(struct iomap *iomap, loff_t pos)
> > return (iomap->addr + (pos & PAGE_MASK) - iomap->offset) >> 9;
> > }
> >
> > -static int dax_iomap_pfn(struct iomap *iomap, loff_t pos, size_t size,
> > - pfn_t *pfnp)
> > +static int dax_iomap_direct_access(struct iomap *iomap, loff_t pos, size_t size,
> > + void **kaddr, pfn_t *pfnp)
> > {
> > const sector_t sector = dax_iomap_sector(iomap, pos);
> > pgoff_t pgoff;
> > @@ -1011,11 +1011,13 @@ 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),
> > - NULL, pfnp);
> > + kaddr, pfnp);
> > if (length < 0) {
> > rc = length;
> > goto out;
> > }
> > + if (!pfnp)
> Should this be "if (!*pfnp)"?

pfnp may be NULL if we only need a kaddr output.
`dax_iomap_direct_access(iomap, pos, size, &kaddr, NULL);`

So, it's a NULL pointer check here.


--
Thanks,
Ruan Shiyang.

>
> Regards,
> Xiaoguang Wang
> > + goto out_check_addr;
> > rc = -EINVAL;
> > if (PFN_PHYS(length) < size)
> > goto out;
> > @@ -1025,6 +1027,12 @@ static int dax_iomap_pfn(struct iomap *iomap, loff_t pos, size_t size,
> > if (length > 1 && !pfn_t_devmap(*pfnp))
> > goto out;
> > rc = 0;
> > +
> > +out_check_addr:
> > + if (!kaddr)
> > + goto out;
> > + if (!*kaddr)
> > + rc = -EFAULT;
> > out:
> > dax_read_unlock(id);
> > return rc;
>