Re: splicing pages to the same file

From: Linus Torvalds
Date: Sat Mar 29 2014 - 13:17:53 EST


On Tue, Mar 25, 2014 at 8:00 AM, Miklos Szeredi <miklos@xxxxxxxxxx> wrote:
> In pipe_to_file() I noticed the "if (buf->page != page)" and started thinking
> about this. What should be the correct behavior?

I don't think we can have "correct" behavior, because no such behavior exists.

It's very much like memcpy() with the destination and source
overlapping. And as you noticed, doing it as a "memmove()" in
pipe_to_file() wouldn't help, because since we block this up by pages,
there will still be a potential overlap across subsequent page
fragments.

So I think the only reasonable option is to document the fact that
splicing from a file to itself falls under the "you're insane, it may
or may not do what you want". And since it depends on page size and on
which order we move pages around in etc, the rule should simply be
that you cannot sanely expect a splice from a file to itself to work.
Regardless of any actual byte range overlap details. "Don't do it".

Now, we *could* make it work when there isn't any overlap. Right now,
if you splice from a file to itself within the same page, we'll always
just say "screw you", but we could look at the offset too. That
wouldn't make a true overlap work (you could still have overlap that
we'd miss because within one part of a page it wouldn't look like
overlap to us since we only see this one page fragment at a time), but
we could try to make the case where there is no true overlap always
work reliably.

But would that be it worth it, since older kernels would still not
give those guarantees? Why did you even notice?

Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/