Linux-Fsdevel Archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: "Fabio M. De Francesco" <fmdefrancesco@gmail.com>
Cc: Ira Weiny <ira.weiny@intel.com>,
	Viacheslav Dubeyko <slava@dubeyko.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Bart Van Assche <bvanassche@acm.org>,
	Kees Cook <keescook@chromium.org>,
	linux-fsdevel@vger.kernel.org
Subject: Re: kmap + memmove
Date: Fri, 24 May 2024 20:35:42 +0100	[thread overview]
Message-ID: <ZlDsDifoQJM5RDy_@casper.infradead.org> (raw)
In-Reply-To: <ZjhZHQShGq_LDyDe@casper.infradead.org>

On Mon, May 06, 2024 at 05:14:21AM +0100, Matthew Wilcox wrote:
> On Sun, May 05, 2024 at 01:25:58PM +0100, Matthew Wilcox wrote:
> > Here's a fun bug that's not obvious:
> > 
> > hfs_bnode_move:
> >                                 dst_ptr = kmap_local_page(*dst_page);
> >                                 src_ptr = kmap_local_page(*src_page);
> >                                 memmove(dst_ptr, src_ptr, src);
> 
> OK, so now we know this is the only place with this problem, how are we
> going to fix it?

Fabio?

> I think the obvious thing to do is to revert the kmap -> kmap_local
> conversion in this function.  The other functions look fine.
> 
> Longer term, hfs_bnode_move() makes my eyes bleed.  I really think we
> need to do something stupider.  Something like ...
> 
> void hfs_bnode_move(struct hfs_bnode *node, int dst, int src, int len)
> {
> 	void *data;
> 	int first, last;
> 
> 	if (!len || src == dst)
> 		return;
> 	if (src < dst && src + len < dst)
> 		return hfs_bnode_copy(node, dst, node, src, len);
> 	if (dst < src && dst + len < src)
> 		return hfs_bnode_copy(node, dst, node, src, len);
> 
> 	src += node->page_offset;
> 	dst += node->page_offset;
> 	first = min(dst, src) / PAGE_SIZE;
> 	last = max(dst + len, src + len) / PAGE_SIZE;
> 	data = vmap_folios(bnode->folios + first, last - first + 1);
> 	src -= first * PAGE_SIZE;
> 	dst -= first * PAGE_SIZE;
> // maybe an off-by-one in above calculations; check it
> 	memmove(data + dst, data + src, len);
> 	vunmap(data);
> }
> 

      reply	other threads:[~2024-05-24 19:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-05 12:25 kmap + memmove Matthew Wilcox
2024-05-05 13:01 ` Julia Lawall
2024-05-06  3:40   ` Ira Weiny
2024-05-06  5:15     ` Julia Lawall
2024-05-06  5:48     ` Julia Lawall
2024-05-06  5:50       ` Julia Lawall
2024-05-06  3:47   ` Matthew Wilcox
2024-05-06  4:14 ` Matthew Wilcox
2024-05-24 19:35   ` Matthew Wilcox [this message]

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=ZlDsDifoQJM5RDy_@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=bvanassche@acm.org \
    --cc=fmdefrancesco@gmail.com \
    --cc=ira.weiny@intel.com \
    --cc=keescook@chromium.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=slava@dubeyko.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).