* [PATCH RFC] vhost: set dirty log bits without pinning pages on x86
@ 2026-11-12 10:53 Michael S. Tsirkin
0 siblings, 0 replies; only message in thread
From: Michael S. Tsirkin @ 2026-11-12 10:53 UTC (permalink / raw)
To: linux-kernel
Cc: Khan Zhao, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, x86, H. Peter Anvin, Jason Wang, Eugenio Pérez,
kvm, virtualization, netdev
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.
Should not be too hard for non-x86 too.
Reported-by: Khan Zhao <zhaoguohan@kylinos.cn>
Link: https://lore.kernel.org/all/20261112085631.128819-1-zhaoguohan@kylinos.cn/
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
lightly tested. pls test and resubmit with your tool.
arch/x86/include/asm/uaccess.h | 18 ++++++++++++++++++
drivers/vhost/vhost.c | 7 +++++++
2 files changed, 25 insertions(+)
diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
index 3a0dd3c2b233e..ba1e7c3f83c8e 100644
--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -594,6 +594,24 @@ _label: \
__ret; \
})
+/* 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; \
+})
+
/*
* We want the unsafe accessors to always be inlined and use
* the error labels - thus the macro games.
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 2f2c45d208832..9ba16cbd788cc 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -2405,6 +2405,12 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
}
EXPORT_SYMBOL_GPL(vhost_dev_ioctl);
+#ifdef CONFIG_X86
+static int set_bit_to_user(int nr, void __user *addr)
+{
+ return set_bit_user(nr, addr);
+}
+#else
/* TODO: This is really inefficient. We need something like get_user()
* (instruction directly accesses the data, with an exception table entry
* returning -EFAULT). See Documentation/arch/x86/exception-tables.rst.
@@ -2427,6 +2433,7 @@ static int set_bit_to_user(int nr, void __user *addr)
unpin_user_pages_dirty_lock(&page, 1, true);
return 0;
}
+#endif /* CONFIG_X86 */
static int log_write(void __user *log_base,
u64 write_address, u64 write_length)
--
MST
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-12 10:53 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-12 10:53 [PATCH RFC] vhost: set dirty log bits without pinning pages on x86 Michael S. Tsirkin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®