All of lore.kernel.org
 help / color / mirror / Atom feed
From: Allison Henderson <allison.henderson@oracle.com>
To: "ruansy.fnst@fujitsu.com" <ruansy.fnst@fujitsu.com>,
	"nvdimm@lists.linux.dev" <nvdimm@lists.linux.dev>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-xfs@vger.kernel.org" <linux-xfs@vger.kernel.org>,
	"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>
Cc: "dan.j.williams@intel.com" <dan.j.williams@intel.com>,
	"djwong@kernel.org" <djwong@kernel.org>,
	"david@fromorbit.com" <david@fromorbit.com>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>
Subject: Re: [PATCH v2.1 3/8] fsdax: zero the edges if source is HOLE or UNWRITTEN
Date: Sat, 3 Dec 2022 00:19:48 +0000	[thread overview]
Message-ID: <cbf2d999d0bd7ad86c0533bd76d7adab0492c4bc.camel@oracle.com> (raw)
In-Reply-To: <1669973145-318-1-git-send-email-ruansy.fnst@fujitsu.com>

On Fri, 2022-12-02 at 09:25 +0000, Shiyang Ruan wrote:
> If srcmap contains invalid data, such as HOLE and UNWRITTEN, the dest
> page should be zeroed.  Otherwise, since it's a pmem, old data may
> remains on the dest page, the result of CoW will be incorrect.
> 
> The function name is also not easy to understand, rename it to
> "dax_iomap_copy_around()", which means it copys data around the
> range.
> 
> Signed-off-by: Shiyang Ruan <ruansy.fnst@fujitsu.com>
> Reviewed-by: Darrick J. Wong <djwong@kernel.org>
> 
I think the new changes look good
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>

> ---
>  fs/dax.c | 79 +++++++++++++++++++++++++++++++++++-------------------
> --
>  1 file changed, 49 insertions(+), 30 deletions(-)
> 
> diff --git a/fs/dax.c b/fs/dax.c
> index a77739f2abe7..f12645d6f3c8 100644
> --- a/fs/dax.c
> +++ b/fs/dax.c
> @@ -1092,7 +1092,8 @@ static int dax_iomap_direct_access(const struct
> iomap *iomap, loff_t pos,
>  }
>  
>  /**
> - * dax_iomap_cow_copy - Copy the data from source to destination
> before write
> + * dax_iomap_copy_around - Prepare for an unaligned write to a
> shared/cow page
> + * by copying the data before and after the range to be written.
>   * @pos:       address to do copy from.
>   * @length:    size of copy operation.
>   * @align_size:        aligned w.r.t align_size (either PMD_SIZE or
> PAGE_SIZE)
> @@ -1101,35 +1102,50 @@ static int dax_iomap_direct_access(const
> struct iomap *iomap, loff_t pos,
>   *
>   * This can be called from two places. Either during DAX write fault
> (page
>   * aligned), to copy the length size data to daddr. Or, while doing
> normal DAX
> - * write operation, dax_iomap_actor() might call this to do the copy
> of either
> + * write operation, dax_iomap_iter() might call this to do the copy
> of either
>   * start or end unaligned address. In the latter case the rest of
> the copy of
> - * aligned ranges is taken care by dax_iomap_actor() itself.
> + * aligned ranges is taken care by dax_iomap_iter() itself.
> + * If the srcmap contains invalid data, such as HOLE and UNWRITTEN,
> zero the
> + * area to make sure no old data remains.
>   */
> -static int dax_iomap_cow_copy(loff_t pos, uint64_t length, size_t
> align_size,
> +static int dax_iomap_copy_around(loff_t pos, uint64_t length, size_t
> align_size,
>                 const struct iomap *srcmap, void *daddr)
>  {
>         loff_t head_off = pos & (align_size - 1);
>         size_t size = ALIGN(head_off + length, align_size);
>         loff_t end = pos + length;
>         loff_t pg_end = round_up(end, align_size);
> +       /* copy_all is usually in page fault case */
>         bool copy_all = head_off == 0 && end == pg_end;
> +       /* zero the edges if srcmap is a HOLE or IOMAP_UNWRITTEN */
> +       bool zero_edge = srcmap->flags & IOMAP_F_SHARED ||
> +                        srcmap->type == IOMAP_UNWRITTEN;
>         void *saddr = 0;
>         int ret = 0;
>  
> -       ret = dax_iomap_direct_access(srcmap, pos, size, &saddr,
> NULL);
> -       if (ret)
> -               return ret;
> +       if (!zero_edge) {
> +               ret = dax_iomap_direct_access(srcmap, pos, size,
> &saddr, NULL);
> +               if (ret)
> +                       return ret;
> +       }
>  
>         if (copy_all) {
> -               ret = copy_mc_to_kernel(daddr, saddr, length);
> -               return ret ? -EIO : 0;
> +               if (zero_edge)
> +                       memset(daddr, 0, size);
> +               else
> +                       ret = copy_mc_to_kernel(daddr, saddr,
> length);
> +               goto out;
>         }
>  
>         /* Copy the head part of the range */
>         if (head_off) {
> -               ret = copy_mc_to_kernel(daddr, saddr, head_off);
> -               if (ret)
> -                       return -EIO;
> +               if (zero_edge)
> +                       memset(daddr, 0, head_off);
> +               else {
> +                       ret = copy_mc_to_kernel(daddr, saddr,
> head_off);
> +                       if (ret)
> +                               return -EIO;
> +               }
>         }
>  
>         /* Copy the tail part of the range */
> @@ -1137,12 +1153,19 @@ static int dax_iomap_cow_copy(loff_t pos,
> uint64_t length, size_t align_size,
>                 loff_t tail_off = head_off + length;
>                 loff_t tail_len = pg_end - end;
>  
> -               ret = copy_mc_to_kernel(daddr + tail_off, saddr +
> tail_off,
> -                                       tail_len);
> -               if (ret)
> -                       return -EIO;
> +               if (zero_edge)
> +                       memset(daddr + tail_off, 0, tail_len);
> +               else {
> +                       ret = copy_mc_to_kernel(daddr + tail_off,
> +                                               saddr + tail_off,
> tail_len);
> +                       if (ret)
> +                               return -EIO;
> +               }
>         }
> -       return 0;
> +out:
> +       if (zero_edge)
> +               dax_flush(srcmap->dax_dev, daddr, size);
> +       return ret ? -EIO : 0;
>  }
>  
>  /*
> @@ -1241,13 +1264,10 @@ static int dax_memzero(struct iomap_iter
> *iter, loff_t pos, size_t size)
>         if (ret < 0)
>                 return ret;
>         memset(kaddr + offset, 0, size);
> -       if (srcmap->addr != iomap->addr) {
> -               ret = dax_iomap_cow_copy(pos, size, PAGE_SIZE,
> srcmap,
> -                                        kaddr);
> -               if (ret < 0)
> -                       return ret;
> -               dax_flush(iomap->dax_dev, kaddr, PAGE_SIZE);
> -       } else
> +       if (iomap->flags & IOMAP_F_SHARED)
> +               ret = dax_iomap_copy_around(pos, size, PAGE_SIZE,
> srcmap,
> +                                           kaddr);
> +       else
>                 dax_flush(iomap->dax_dev, kaddr + offset, size);
>         return ret;
>  }
> @@ -1401,8 +1421,8 @@ static loff_t dax_iomap_iter(const struct
> iomap_iter *iomi,
>                 }
>  
>                 if (cow) {
> -                       ret = dax_iomap_cow_copy(pos, length,
> PAGE_SIZE, srcmap,
> -                                                kaddr);
> +                       ret = dax_iomap_copy_around(pos, length,
> PAGE_SIZE,
> +                                                   srcmap, kaddr);
>                         if (ret)
>                                 break;
>                 }
> @@ -1547,7 +1567,7 @@ static vm_fault_t dax_fault_iter(struct
> vm_fault *vmf,
>                 struct xa_state *xas, void **entry, bool pmd)
>  {
>         const struct iomap *iomap = &iter->iomap;
> -       const struct iomap *srcmap = &iter->srcmap;
> +       const struct iomap *srcmap = iomap_iter_srcmap(iter);
>         size_t size = pmd ? PMD_SIZE : PAGE_SIZE;
>         loff_t pos = (loff_t)xas->xa_index << PAGE_SHIFT;
>         bool write = iter->flags & IOMAP_WRITE;
> @@ -1578,9 +1598,8 @@ static vm_fault_t dax_fault_iter(struct
> vm_fault *vmf,
>  
>         *entry = dax_insert_entry(xas, vmf, iter, *entry, pfn,
> entry_flags);
>  
> -       if (write &&
> -           srcmap->type != IOMAP_HOLE && srcmap->addr != iomap-
> >addr) {
> -               err = dax_iomap_cow_copy(pos, size, size, srcmap,
> kaddr);
> +       if (write && iomap->flags & IOMAP_F_SHARED) {
> +               err = dax_iomap_copy_around(pos, size, size, srcmap,
> kaddr);
>                 if (err)
>                         return dax_fault_return(err);
>         }


  reply	other threads:[~2022-12-03  0:20 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-01 15:28 [PATCH v2 0/8] fsdax,xfs: fix warning messages Shiyang Ruan
2022-12-01 15:28 ` [PATCH v2 1/8] fsdax: introduce page->share for fsdax in reflink mode Shiyang Ruan
2022-12-01 16:14   ` Darrick J. Wong
2022-12-02  9:23   ` [PATCH v2.1 " Shiyang Ruan
2022-12-02 20:18     ` Andrew Morton
2022-12-03  0:19     ` Allison Henderson
2022-12-03  2:07     ` Dan Williams
2022-12-05  5:56       ` Shiyang Ruan
2022-12-05  7:01         ` Darrick J. Wong
2022-12-07  2:49   ` [PATCH v2.2 " Shiyang Ruan
2022-12-08  1:26     ` Darrick J. Wong
2022-12-01 15:28 ` [PATCH v2 2/8] fsdax: invalidate pages when CoW Shiyang Ruan
2022-12-01 16:17   ` Darrick J. Wong
2022-12-01 15:28 ` [PATCH v2 3/8] fsdax: zero the edges if source is HOLE or UNWRITTEN Shiyang Ruan
2022-12-01 23:58   ` Darrick J. Wong
2022-12-02  0:39     ` Andrew Morton
2022-12-02  9:25   ` [PATCH v2.1 " Shiyang Ruan
2022-12-03  0:19     ` Allison Henderson [this message]
2022-12-01 15:28 ` [PATCH v2 4/8] fsdax,xfs: set the shared flag when file extent is shared Shiyang Ruan
2022-12-02  0:05   ` Darrick J. Wong
2022-12-01 15:31 ` [PATCH v2 5/8] fsdax: dedupe: iter two files at the same time Shiyang Ruan
2022-12-02  0:05   ` Darrick J. Wong
2022-12-01 15:32 ` [PATCH v2 6/8] xfs: use dax ops for zero and truncate in fsdax mode Shiyang Ruan
2022-12-02  0:05   ` Darrick J. Wong
2022-12-01 15:32 ` [PATCH v2 7/8] fsdax,xfs: port unshare to fsdax Shiyang Ruan
2022-12-01 15:32 ` [PATCH v2 8/8] xfs: remove restrictions for fsdax and reflink Shiyang Ruan
2022-12-02  0:06   ` Darrick J. Wong
2022-12-03  1:21 ` [PATCH v2 0/8] fsdax,xfs: fix warning messages Dan Williams
2022-12-29  8:23   ` Shiyang Ruan

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=cbf2d999d0bd7ad86c0533bd76d7adab0492c4bc.camel@oracle.com \
    --to=allison.henderson@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=dan.j.williams@intel.com \
    --cc=david@fromorbit.com \
    --cc=djwong@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --cc=ruansy.fnst@fujitsu.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.