Re: [PATCH RFC] vhost: don't use kmap() to log dirty pages

From: Christoph Hellwig
Date: Tue May 07 2019 - 11:48:49 EST


On Mon, May 06, 2019 at 10:23:29PM -0400, Jason Wang wrote:
> Note: there're archs (few non popular ones) that don't implement
> futex helper, we can't log dirty pages. We can fix them on top or
> simply disable LOG_ALL features of vhost.

That means vhost now has to depend on HAVE_FUTEX_CMPXCHG to make
sure we have a working implementation.


> #include <linux/sched/signal.h>
> #include <linux/interval_tree_generic.h>
> #include <linux/nospec.h>
> +#include <asm/futex.h>

Also please include the futex maintainers to make sure they are fine
with this first usage of <asm/futex.h> outside of kernel/futex.c.


> +static int set_bit_to_user(int nr, u32 __user *addr)
> {
> unsigned long log = (unsigned long)addr;
> struct page *page;
> + u32 old_log;
> int r;
>
> r = get_user_pages_fast(log, 1, 1, &page);
> if (r < 0)
> return r;
> BUG_ON(r != 1);
> +
> + r = futex_atomic_cmpxchg_inatomic(&old_log, addr, 0, 0);
> + if (r < 0)
> + return r;
> +
> + old_log |= 1 << nr;
> + r = put_user(old_log, addr);
> + if (r < 0)
> + return r;

And this just looks odd to me. Why do we need the futex call to
replace a 0 value with 0? Why does it still duplicate the
put_user? This doesn't look like actually working code to me.

Also don't we need a pagefault_disable() around
futex_atomic_cmpxchg_inatomic?