Thread View: linux.kernel.netdev
1 messages
1 total messages
Started by zhaoguohan
Fri, 13 Nov 2026 01:29
Re: [PATCH RFC] vhost: set dirty log bits without pinning pages on x86
Author: zhaoguohan
Date: Fri, 13 Nov 2026 01:29
Date: Fri, 13 Nov 2026 01:29
90 lines
11243 bytes
11243 bytes
On Thu, Nov 12, 2026 at 05:53:47AM -0500, Michael S. Tsirkin wrote:
> vhost had a TODO to replace page pinning with a version
> of set_bit that works on userspace memory, since forever.
>
> It is really best to avoid GUP on fast path entirely.
> Implement set_user_bit and use it in vhost, to do just that.
[...]
> lightly tested. pls test and resubmit with your tool.
Thanks, this is much simpler than my version. Two comments on
set_bit_user() before I resubmit:
> + int __err = 0; \
> + __uaccess_begin(); \
> + asm volatile("\n" \
> + "1: " LOCK_PREFIX "orb %[mask], %[ptr]\n" \
> + "2:\n" \
> + _ASM_EXTABLE_TYPE_REG(1b, 2b, EX_TYPE_EFAULT_REG, \
> + %[errout]) \
> + : [errout] "=r" (__err), \
> + [ptr] "+m" (*(u8 __user *)(addr)) \
errout is only written on the fixup path, so it needs "+r", as in
__try_cmpxchg_user_asm(). With "=r" gcc drops the initialisation; here
(gcc 13.3, x86_64_defconfig) it even shares a register with mask:
1a3: lock or %dl,(%rax)
1a9: test %edx,%edx
1ab: jne 1bd <log_write+0x5d>
...
1bd: mov $0xfffffff2,%eax
so every call returns -EFAULT, and log_write() stops after the first
page.
> + __uaccess_begin(); \
No access_ok() here. vhost checks the log range when it is set up and
I couldn't find a way around that, but GUP used to reject kernel
addresses by itself. user_access_begin() would keep the check (and the
nospec barrier) local. Something like this, build-tested on x86_64 and
i386 only:
diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -597,19 +597,23 @@ _label: \
/* set_bit() on a byte of user memory; returns -EFAULT on fault. */
#define set_bit_user(nr, addr) \
({ \
- int __err = 0; \
- __uaccess_begin(); \
- asm volatile("\n" \
- "1: " LOCK_PREFIX "orb %[mask], %[ptr]\n" \
- "2:\n" \
- _ASM_EXTABLE_TYPE_REG(1b, 2b, EX_TYPE_EFAULT_REG, \
- %[errout]) \
- : [errout] "=r" (__err), \
- [ptr] "+m" (*(u8 __user *)(addr)) \
- : [mask] "q" ((unsigned char)BIT(nr)) \
- : "memory", "cc"); \
- __uaccess_end(); \
- __err ? -EFAULT : 0; \
+ u8 __user *__p = (addr); \
+ int __err = -EFAULT; \
+ if (user_access_begin(__p, sizeof(*__p))) { \
+ __err = 0; \
+ asm volatile("\n" \
+ "1: " LOCK_PREFIX "orb %[mask], %[ptr]\n" \
+ "2:\n" \
+ _ASM_EXTABLE_TYPE_REG(1b, 2b, \
+ EX_TYPE_EFAULT_REG, \
+ %[errout]) \
+ : [errout] "+r" (__err), \
+ [ptr] "+m" (*__p) \
+ : [mask] "q" ((unsigned char)BIT(nr)) \
+ : "memory", "cc"); \
+ user_access_end(); \
+ } \
+ __err; \
})
/*
If this looks right, I'll fold it in, run my test in a VM and resubmit
with the test as a second patch.
Thanks,
Khan
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads