Re: [PATCH RFC 16/19] mm/frame-vector: remove FOLL_FORCE usage

From: Linus Torvalds
Date: Tue Nov 22 2022 - 12:34:10 EST


On Tue, Nov 22, 2022 at 4:25 AM Hans Verkuil <hverkuil@xxxxxxxxx> wrote:
>
> I tracked the use of 'force' all the way back to the first git commit
> (2.6.12-rc1) in the very old video-buf.c. So it is very, very old and the
> reason is lost in the mists of time.

Well, not entirely.

For archaeology reasons, I went back to the old BK history, which
exists as a git conversion in

https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/

and there you can actually find it.

Not with a lot of explanations, though - it's commit b7649ef789
("[PATCH] videobuf update"):

This updates the video-buf.c module (helper module for video buffer
management). Some memory management fixes, also some adaptions to the
final v4l2 api.

but it went from

err = get_user_pages(current,current->mm,
- data, dma->nr_pages,
- rw == READ, 0, /* don't force */
+ data & PAGE_MASK, dma->nr_pages,
+ rw == READ, 1, /* force */
dma->pages, NULL);

in that commit.

So it goes back to October 2002.

> Looking at this old LWN article https://lwn.net/Articles/28548/ suggests
> that it might be related to calling get_user_pages for write buffers

The timing roughly matches.

> I assume that removing FOLL_FORCE from 'FOLL_FORCE|FOLL_WRITE' will still
> allow drivers to read from the buffer?

The issue with some of the driver hacks has been that

- they only want to read, and the buffer may be read-only

- they then used FOLL_WRITE despite that, because they want to break
COW (due to the issue that David is now fixing with his series)

- but that means that the VM layer says "nope, you can't write to
this read-only user mapping"

- ... and then they use FOLL_FORCE to say "yes, I can".

iOW, the FOLL_FORCE may be entirely due to an (incorrect, but
historically needed) FOLL_WRITE.

Linus