[PATCH v2] x86/vm86: Remove deprecated VM86 support

Ashwin Gundarapu posted 1 patch 1 week, 5 days ago
arch/x86/Kconfig                       |  30 -
arch/x86/include/asm/processor-flags.h |   6 +-
arch/x86/include/asm/processor.h       |   5 +-
arch/x86/include/asm/thread_info.h     |   6 +-
arch/x86/include/asm/vm86.h            |  91 ---
arch/x86/kernel/Makefile               |   1 -
arch/x86/kernel/process.c              |   5 -
arch/x86/kernel/vm86_32.c              | 831 -------------------------
8 files changed, 3 insertions(+), 972 deletions(-)
delete mode 100644 arch/x86/include/asm/vm86.h
delete mode 100644 arch/x86/kernel/vm86_32.c
[PATCH v2] x86/vm86: Remove deprecated VM86 support
Posted by Ashwin Gundarapu 1 week, 5 days ago
VM86 support allows 16-bit DOS programs to run in virtual 8086 mode
on 32-bit x86 kernels. This feature has been deprecated and the Kconfig
help text itself states that any recent software works without it.

Remove the vm86 subsystem entirely including the main driver source,
Kconfig options, header file, and all references in thread_info,
processor, and processor-flags headers.

Signed-off-by: Ashwin Gundarapu <linuxuser509@zohomail.in>
---
v2: Also remove arch/x86/include/asm/vm86.h and arch/x86/kernel/vm86_32.c
    as pointed out by Christophe JAILLET.
---
 arch/x86/Kconfig                       |  30 -
 arch/x86/include/asm/processor-flags.h |   6 +-
 arch/x86/include/asm/processor.h       |   5 +-
 arch/x86/include/asm/thread_info.h     |   6 +-
 arch/x86/include/asm/vm86.h            |  91 ---
 arch/x86/kernel/Makefile               |   1 -
 arch/x86/kernel/process.c              |   5 -
 arch/x86/kernel/vm86_32.c              | 831 -------------------------
 8 files changed, 3 insertions(+), 972 deletions(-)
 delete mode 100644 arch/x86/include/asm/vm86.h
 delete mode 100644 arch/x86/kernel/vm86_32.c

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index f3f7cb01d69d..de00975e0f11 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -1206,36 +1206,6 @@ config X86_MCE_INJECT
 
 source "arch/x86/events/Kconfig"

-config X86_LEGACY_VM86
-	bool "Legacy VM86 support"
-	depends on X86_32
-	help
-	  This option allows user programs to put the CPU into V8086
-	  mode, which is an 80286-era approximation of 16-bit real mode.
-
-	  Some very old versions of X and/or vbetool require this option
-	  for user mode setting.  Similarly, DOSEMU will use it if
-	  available to accelerate real mode DOS programs.  However, any
-	  recent version of DOSEMU, X, or vbetool should be fully
-	  functional even without kernel VM86 support, as they will all
-	  fall back to software emulation. Nevertheless, if you are using
-	  a 16-bit DOS program where 16-bit performance matters, vm86
-	  mode might be faster than emulation and you might want to
-	  enable this option.
-
-	  Note that any app that works on a 64-bit kernel is unlikely to
-	  need this option, as 64-bit kernels don't, and can't, support
-	  V8086 mode. This option is also unrelated to 16-bit protected
-	  mode and is not needed to run most 16-bit programs under Wine.
-
-	  Enabling this option increases the complexity of the kernel
-	  and slows down exception handling a tiny bit.
-
-	  If unsure, say N here.
-
-config VM86
-	bool
-	default X86_LEGACY_VM86
 
 config X86_16BIT
 	bool "Enable support for 16-bit segments" if EXPERT
diff --git a/arch/x86/include/asm/processor-flags.h b/arch/x86/include/asm/processor-flags.h
index e5f204b9b33d..ae0d9980912c 100644
--- a/arch/x86/include/asm/processor-flags.h
+++ b/arch/x86/include/asm/processor-flags.h
@@ -5,11 +5,7 @@
 #include <uapi/asm/processor-flags.h>
 #include <linux/mem_encrypt.h>

-#ifdef CONFIG_VM86
-#define X86_VM_MASK	X86_EFLAGS_VM
-#else
-#define X86_VM_MASK	0 /* No VM86 support */
-#endif
+#define X86_VM_MASK     0 /* No VM86 support */
 
 /*
  * CR3's layout varies depending on several things.
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 10b5355b323e..ac9ddde54a93 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -488,10 +488,7 @@ struct thread_struct {
 	unsigned long		cr2;
 	unsigned long		trap_nr;
 	unsigned long		error_code;
-#ifdef CONFIG_VM86
-	/* Virtual 86 mode info */
-	struct vm86		*vm86;
-#endif
+
 	/* IO permissions: */
 	struct io_bitmap	*io_bitmap;

diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
index 0067684afb5b..a4af29a906b5 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -36,11 +36,7 @@
  * dynamic, but for now it is always 2 words longer.
  */
 #ifdef CONFIG_X86_32
-# ifdef CONFIG_VM86
-#  define TOP_OF_KERNEL_STACK_PADDING 16
-# else
-#  define TOP_OF_KERNEL_STACK_PADDING 8
-# endif
+# define TOP_OF_KERNEL_STACK_PADDING 8
 #else /* x86-64 */
 # ifdef CONFIG_X86_FRED
 #  define TOP_OF_KERNEL_STACK_PADDING (2 * 8)
diff --git a/arch/x86/include/asm/vm86.h b/arch/x86/include/asm/vm86.h
deleted file mode 100644
index 62ee19909903..000000000000
--- a/arch/x86/include/asm/vm86.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_X86_VM86_H
-#define _ASM_X86_VM86_H
-
-#include <asm/ptrace.h>
-#include <uapi/asm/vm86.h>
-
-/*
- * This is the (kernel) stack-layout when we have done a "SAVE_ALL" from vm86
- * mode - the main change is that the old segment descriptors aren't
- * useful any more and are forced to be zero by the kernel (and the
- * hardware when a trap occurs), and the real segment descriptors are
- * at the end of the structure. Look at ptrace.h to see the "normal"
- * setup. For user space layout see 'struct vm86_regs' above.
- */
-
-struct kernel_vm86_regs {
-/*
- * normal regs, with special meaning for the segment descriptors..
- */
-	struct pt_regs pt;
-/*
- * these are specific to v86 mode:
- */
-	unsigned short es, __esh;
-	unsigned short ds, __dsh;
-	unsigned short fs, __fsh;
-	unsigned short gs, __gsh;
-};
-
-struct vm86 {
-	struct vm86plus_struct __user *user_vm86;
-	struct pt_regs regs32;
-	unsigned long veflags;
-	unsigned long veflags_mask;
-	unsigned long saved_sp0;
-
-	unsigned long flags;
-	unsigned long cpu_type;
-	struct revectored_struct int_revectored;
-	struct revectored_struct int21_revectored;
-	struct vm86plus_info_struct vm86plus;
-};
-
-#ifdef CONFIG_VM86
-
-void handle_vm86_fault(struct kernel_vm86_regs *, long);
-int handle_vm86_trap(struct kernel_vm86_regs *, long, int);
-void save_v86_state(struct kernel_vm86_regs *, int);
-
-struct task_struct;
-
-#define free_vm86(t) do {				\
-	struct thread_struct *__t = (t);		\
-	if (__t->vm86 != NULL) {			\
-		kfree(__t->vm86);			\
-		__t->vm86 = NULL;			\
-	}						\
-} while (0)
-
-/*
- * Support for VM86 programs to request interrupts for
- * real mode hardware drivers:
- */
-#define FIRST_VM86_IRQ		 3
-#define LAST_VM86_IRQ		15
-
-static inline int invalid_vm86_irq(int irq)
-{
-	return irq < FIRST_VM86_IRQ || irq > LAST_VM86_IRQ;
-}
-
-void release_vm86_irqs(struct task_struct *);
-
-#else
-
-#define handle_vm86_fault(a, b)
-#define release_vm86_irqs(a)
-
-static inline int handle_vm86_trap(struct kernel_vm86_regs *a, long b, int c)
-{
-	return 0;
-}
-
-static inline void save_v86_state(struct kernel_vm86_regs *a, int b) { }
-
-#define free_vm86(task) do { (void)(task); } while(0)
-
-#endif /* CONFIG_VM86 */
-
-#endif /* _ASM_X86_VM86_H */
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index 47a32f583930..4820aff6cc1b 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -129,7 +129,6 @@ obj-y				+= kprobes/
 obj-$(CONFIG_MODULES)		+= module.o
 obj-$(CONFIG_X86_32)		+= doublefault_32.o
 obj-$(CONFIG_KGDB)		+= kgdb.o
-obj-$(CONFIG_VM86)		+= vm86_32.o
 obj-$(CONFIG_EARLY_PRINTK)	+= early_printk.o
 
 obj-$(CONFIG_HPET_TIMER) 	+= hpet.o
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index 4c718f8adc59..7f52fa76b048 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -107,9 +107,6 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
 	/* fpu_clone() will initialize the "dst_fpu" memory */
 	memcpy_and_pad(dst, arch_task_struct_size, src, sizeof(*dst), 0);
 
-#ifdef CONFIG_VM86
-	dst->thread.vm86 = NULL;
-#endif

 	return 0;
 }
@@ -127,12 +124,10 @@ void arch_release_task_struct(struct task_struct *tsk)
  */
 void exit_thread(struct task_struct *tsk)
 {
-	struct thread_struct *t = &tsk->thread;
 
 	if (test_thread_flag(TIF_IO_BITMAP))
 		io_bitmap_exit(tsk);
 
-	free_vm86(t);
 
 	shstk_free(tsk);
 	fpu__drop(tsk);
diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
deleted file mode 100644
index b4c1cabc7a4b..000000000000
--- a/arch/x86/kernel/vm86_32.c
+++ /dev/null
@@ -1,831 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- *  Copyright (C) 1994  Linus Torvalds
- *
- *  29 dec 2001 - Fixed oopses caused by unchecked access to the vm86
- *                stack - Manfred Spraul <manfred@colorfullife.com>
- *
- *  22 mar 2002 - Manfred detected the stackfaults, but didn't handle
- *                them correctly. Now the emulation will be in a
- *                consistent state after stackfaults - Kasper Dupont
- *                <kasperd@daimi.au.dk>
- *
- *  22 mar 2002 - Added missing clear_IF in set_vflags_* Kasper Dupont
- *                <kasperd@daimi.au.dk>
- *
- *  ?? ??? 2002 - Fixed premature returns from handle_vm86_fault
- *                caused by Kasper Dupont's changes - Stas Sergeev
- *
- *   4 apr 2002 - Fixed CHECK_IF_IN_TRAP broken by Stas' changes.
- *                Kasper Dupont <kasperd@daimi.au.dk>
- *
- *   9 apr 2002 - Changed syntax of macros in handle_vm86_fault.
- *                Kasper Dupont <kasperd@daimi.au.dk>
- *
- *   9 apr 2002 - Changed stack access macros to jump to a label
- *                instead of returning to userspace. This simplifies
- *                do_int, and is needed by handle_vm6_fault. Kasper
- *                Dupont <kasperd@daimi.au.dk>
- *
- */
-
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
-#include <linux/capability.h>
-#include <linux/errno.h>
-#include <linux/interrupt.h>
-#include <linux/syscalls.h>
-#include <linux/sched.h>
-#include <linux/sched/task_stack.h>
-#include <linux/kernel.h>
-#include <linux/signal.h>
-#include <linux/string.h>
-#include <linux/mm.h>
-#include <linux/smp.h>
-#include <linux/highmem.h>
-#include <linux/ptrace.h>
-#include <linux/audit.h>
-#include <linux/stddef.h>
-#include <linux/slab.h>
-#include <linux/security.h>
-
-#include <linux/uaccess.h>
-#include <asm/io.h>
-#include <asm/tlbflush.h>
-#include <asm/irq.h>
-#include <asm/traps.h>
-#include <asm/vm86.h>
-#include <asm/switch_to.h>
-
-/*
- * Known problems:
- *
- * Interrupt handling is not guaranteed:
- * - a real x86 will disable all interrupts for one instruction
- *   after a "mov ss,xx" to make stack handling atomic even without
- *   the 'lss' instruction. We can't guarantee this in v86 mode,
- *   as the next instruction might result in a page fault or similar.
- * - a real x86 will have interrupts disabled for one instruction
- *   past the 'sti' that enables them. We don't bother with all the
- *   details yet.
- *
- * Let's hope these problems do not actually matter for anything.
- */
-
-
-/*
- * 8- and 16-bit register defines..
- */
-#define AL(regs)	(((unsigned char *)&((regs)->pt.ax))[0])
-#define AH(regs)	(((unsigned char *)&((regs)->pt.ax))[1])
-#define IP(regs)	(*(unsigned short *)&((regs)->pt.ip))
-#define SP(regs)	(*(unsigned short *)&((regs)->pt.sp))
-
-/*
- * virtual flags (16 and 32-bit versions)
- */
-#define VFLAGS	(*(unsigned short *)&(current->thread.vm86->veflags))
-#define VEFLAGS	(current->thread.vm86->veflags)
-
-#define set_flags(X, new, mask) \
-((X) = ((X) & ~(mask)) | ((new) & (mask)))
-
-#define SAFE_MASK	(0xDD5)
-#define RETURN_MASK	(0xDFF)
-
-void save_v86_state(struct kernel_vm86_regs *regs, int retval)
-{
-	struct task_struct *tsk = current;
-	struct vm86plus_struct __user *user;
-	struct vm86 *vm86 = current->thread.vm86;
-
-	/*
-	 * This gets called from entry.S with interrupts disabled, but
-	 * from process context. Enable interrupts here, before trying
-	 * to access user space.
-	 */
-	local_irq_enable();
-
-	BUG_ON(!vm86);
-
-	set_flags(regs->pt.flags, VEFLAGS, X86_EFLAGS_VIF | vm86->veflags_mask);
-	user = vm86->user_vm86;
-
-	if (!user_access_begin(user, vm86->vm86plus.is_vm86pus ?
-		       sizeof(struct vm86plus_struct) :
-		       sizeof(struct vm86_struct)))
-		goto Efault;
-
-	unsafe_put_user(regs->pt.bx, &user->regs.ebx, Efault_end);
-	unsafe_put_user(regs->pt.cx, &user->regs.ecx, Efault_end);
-	unsafe_put_user(regs->pt.dx, &user->regs.edx, Efault_end);
-	unsafe_put_user(regs->pt.si, &user->regs.esi, Efault_end);
-	unsafe_put_user(regs->pt.di, &user->regs.edi, Efault_end);
-	unsafe_put_user(regs->pt.bp, &user->regs.ebp, Efault_end);
-	unsafe_put_user(regs->pt.ax, &user->regs.eax, Efault_end);
-	unsafe_put_user(regs->pt.ip, &user->regs.eip, Efault_end);
-	unsafe_put_user(regs->pt.cs, &user->regs.cs, Efault_end);
-	unsafe_put_user(regs->pt.flags, &user->regs.eflags, Efault_end);
-	unsafe_put_user(regs->pt.sp, &user->regs.esp, Efault_end);
-	unsafe_put_user(regs->pt.ss, &user->regs.ss, Efault_end);
-	unsafe_put_user(regs->es, &user->regs.es, Efault_end);
-	unsafe_put_user(regs->ds, &user->regs.ds, Efault_end);
-	unsafe_put_user(regs->fs, &user->regs.fs, Efault_end);
-	unsafe_put_user(regs->gs, &user->regs.gs, Efault_end);
-
-	/*
-	 * Don't write screen_bitmap in case some user had a value there
-	 * and expected it to remain unchanged.
-	 */
-
-	user_access_end();
-
-exit_vm86:
-	preempt_disable();
-	tsk->thread.sp0 = vm86->saved_sp0;
-	tsk->thread.sysenter_cs = __KERNEL_CS;
-	update_task_stack(tsk);
-	refresh_sysenter_cs(&tsk->thread);
-	vm86->saved_sp0 = 0;
-	preempt_enable();
-
-	memcpy(&regs->pt, &vm86->regs32, sizeof(struct pt_regs));
-
-	loadsegment(gs, vm86->regs32.gs);
-
-	regs->pt.ax = retval;
-	return;
-
-Efault_end:
-	user_access_end();
-Efault:
-	pr_alert("could not access userspace vm86 info\n");
-	force_exit_sig(SIGSEGV);
-	goto exit_vm86;
-}
-
-static int do_vm86_irq_handling(int subfunction, int irqnumber);
-static long do_sys_vm86(struct vm86plus_struct __user *user_vm86, bool plus);
-
-SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, user_vm86)
-{
-	return do_sys_vm86((struct vm86plus_struct __user *) user_vm86, false);
-}
-
-
-SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
-{
-	switch (cmd) {
-	case VM86_REQUEST_IRQ:
-	case VM86_FREE_IRQ:
-	case VM86_GET_IRQ_BITS:
-	case VM86_GET_AND_RESET_IRQ:
-		return do_vm86_irq_handling(cmd, (int)arg);
-	case VM86_PLUS_INSTALL_CHECK:
-		/*
-		 * NOTE: on old vm86 stuff this will return the error
-		 *  from access_ok(), because the subfunction is
-		 *  interpreted as (invalid) address to vm86_struct.
-		 *  So the installation check works.
-		 */
-		return 0;
-	}
-
-	/* we come here only for functions VM86_ENTER, VM86_ENTER_NO_BYPASS */
-	return do_sys_vm86((struct vm86plus_struct __user *) arg, true);
-}
-
-
-static long do_sys_vm86(struct vm86plus_struct __user *user_vm86, bool plus)
-{
-	struct task_struct *tsk = current;
-	struct vm86 *vm86 = tsk->thread.vm86;
-	struct kernel_vm86_regs vm86regs;
-	struct pt_regs *regs = current_pt_regs();
-	unsigned long err = 0;
-	struct vm86_struct v;
-
-	err = security_mmap_addr(0);
-	if (err) {
-		/*
-		 * vm86 cannot virtualize the address space, so vm86 users
-		 * need to manage the low 1MB themselves using mmap.  Given
-		 * that BIOS places important data in the first page, vm86
-		 * is essentially useless if mmap_min_addr != 0.  DOSEMU,
-		 * for example, won't even bother trying to use vm86 if it
-		 * can't map a page at virtual address 0.
-		 *
-		 * To reduce the available kernel attack surface, simply
-		 * disallow vm86(old) for users who cannot mmap at va 0.
-		 *
-		 * The implementation of security_mmap_addr will allow
-		 * suitably privileged users to map va 0 even if
-		 * vm.mmap_min_addr is set above 0, and we want this
-		 * behavior for vm86 as well, as it ensures that legacy
-		 * tools like vbetool will not fail just because of
-		 * vm.mmap_min_addr.
-		 */
-		pr_info_once("Denied a call to vm86(old) from %s[%d] (uid: %d).  Set the vm.mmap_min_addr sysctl to 0 and/or adjust LSM mmap_min_addr policy to enable vm86 if you are using a vm86-based DOS emulator.\n",
-			     current->comm, task_pid_nr(current),
-			     from_kuid_munged(&init_user_ns, current_uid()));
-		return -EPERM;
-	}
-
-	if (!vm86) {
-		if (!(vm86 = kzalloc_obj(*vm86)))
-			return -ENOMEM;
-		tsk->thread.vm86 = vm86;
-	}
-	if (vm86->saved_sp0)
-		return -EPERM;
-
-	if (copy_from_user(&v, user_vm86,
-			offsetof(struct vm86_struct, int_revectored)))
-		return -EFAULT;
-
-
-	/* VM86_SCREEN_BITMAP had numerous bugs and appears to have no users. */
-	if (v.flags & VM86_SCREEN_BITMAP) {
-		pr_info_once("vm86: '%s' uses VM86_SCREEN_BITMAP, which is no longer supported\n",
-			     current->comm);
-		return -EINVAL;
-	}
-
-	memset(&vm86regs, 0, sizeof(vm86regs));
-
-	vm86regs.pt.bx = v.regs.ebx;
-	vm86regs.pt.cx = v.regs.ecx;
-	vm86regs.pt.dx = v.regs.edx;
-	vm86regs.pt.si = v.regs.esi;
-	vm86regs.pt.di = v.regs.edi;
-	vm86regs.pt.bp = v.regs.ebp;
-	vm86regs.pt.ax = v.regs.eax;
-	vm86regs.pt.ip = v.regs.eip;
-	vm86regs.pt.cs = v.regs.cs;
-	vm86regs.pt.flags = v.regs.eflags;
-	vm86regs.pt.sp = v.regs.esp;
-	vm86regs.pt.ss = v.regs.ss;
-	vm86regs.es = v.regs.es;
-	vm86regs.ds = v.regs.ds;
-	vm86regs.fs = v.regs.fs;
-	vm86regs.gs = v.regs.gs;
-
-	vm86->flags = v.flags;
-	vm86->cpu_type = v.cpu_type;
-
-	if (copy_from_user(&vm86->int_revectored,
-			   &user_vm86->int_revectored,
-			   sizeof(struct revectored_struct)))
-		return -EFAULT;
-	if (copy_from_user(&vm86->int21_revectored,
-			   &user_vm86->int21_revectored,
-			   sizeof(struct revectored_struct)))
-		return -EFAULT;
-	if (plus) {
-		if (copy_from_user(&vm86->vm86plus, &user_vm86->vm86plus,
-				   sizeof(struct vm86plus_info_struct)))
-			return -EFAULT;
-		vm86->vm86plus.is_vm86pus = 1;
-	} else
-		memset(&vm86->vm86plus, 0,
-		       sizeof(struct vm86plus_info_struct));
-
-	memcpy(&vm86->regs32, regs, sizeof(struct pt_regs));
-	vm86->user_vm86 = user_vm86;
-
-/*
- * The flags register is also special: we cannot trust that the user
- * has set it up safely, so this makes sure interrupt etc flags are
- * inherited from protected mode.
- */
-	VEFLAGS = vm86regs.pt.flags;
-	vm86regs.pt.flags &= SAFE_MASK;
-	vm86regs.pt.flags |= regs->flags & ~SAFE_MASK;
-	vm86regs.pt.flags |= X86_VM_MASK;
-
-	vm86regs.pt.orig_ax = regs->orig_ax;
-
-	switch (vm86->cpu_type) {
-	case CPU_286:
-		vm86->veflags_mask = 0;
-		break;
-	case CPU_386:
-		vm86->veflags_mask = X86_EFLAGS_NT | X86_EFLAGS_IOPL;
-		break;
-	case CPU_486:
-		vm86->veflags_mask = X86_EFLAGS_AC | X86_EFLAGS_NT | X86_EFLAGS_IOPL;
-		break;
-	default:
-		vm86->veflags_mask = X86_EFLAGS_ID | X86_EFLAGS_AC | X86_EFLAGS_NT | X86_EFLAGS_IOPL;
-		break;
-	}
-
-/*
- * Save old state
- */
-	vm86->saved_sp0 = tsk->thread.sp0;
-	savesegment(gs, vm86->regs32.gs);
-
-	/* make room for real-mode segments */
-	preempt_disable();
-	tsk->thread.sp0 += 16;
-
-	if (boot_cpu_has(X86_FEATURE_SEP)) {
-		tsk->thread.sysenter_cs = 0;
-		refresh_sysenter_cs(&tsk->thread);
-	}
-
-	update_task_stack(tsk);
-	preempt_enable();
-
-	memcpy((struct kernel_vm86_regs *)regs, &vm86regs, sizeof(vm86regs));
-	return regs->ax;
-}
-
-static inline void set_IF(struct kernel_vm86_regs *regs)
-{
-	VEFLAGS |= X86_EFLAGS_VIF;
-}
-
-static inline void clear_IF(struct kernel_vm86_regs *regs)
-{
-	VEFLAGS &= ~X86_EFLAGS_VIF;
-}
-
-static inline void clear_TF(struct kernel_vm86_regs *regs)
-{
-	regs->pt.flags &= ~X86_EFLAGS_TF;
-}
-
-static inline void clear_AC(struct kernel_vm86_regs *regs)
-{
-	regs->pt.flags &= ~X86_EFLAGS_AC;
-}
-
-/*
- * It is correct to call set_IF(regs) from the set_vflags_*
- * functions. However someone forgot to call clear_IF(regs)
- * in the opposite case.
- * After the command sequence CLI PUSHF STI POPF you should
- * end up with interrupts disabled, but you ended up with
- * interrupts enabled.
- *  ( I was testing my own changes, but the only bug I
- *    could find was in a function I had not changed. )
- * [KD]
- */
-
-static inline void set_vflags_long(unsigned long flags, struct kernel_vm86_regs *regs)
-{
-	set_flags(VEFLAGS, flags, current->thread.vm86->veflags_mask);
-	set_flags(regs->pt.flags, flags, SAFE_MASK);
-	if (flags & X86_EFLAGS_IF)
-		set_IF(regs);
-	else
-		clear_IF(regs);
-}
-
-static inline void set_vflags_short(unsigned short flags, struct kernel_vm86_regs *regs)
-{
-	set_flags(VFLAGS, flags, current->thread.vm86->veflags_mask);
-	set_flags(regs->pt.flags, flags, SAFE_MASK);
-	if (flags & X86_EFLAGS_IF)
-		set_IF(regs);
-	else
-		clear_IF(regs);
-}
-
-static inline unsigned long get_vflags(struct kernel_vm86_regs *regs)
-{
-	unsigned long flags = regs->pt.flags & RETURN_MASK;
-
-	if (VEFLAGS & X86_EFLAGS_VIF)
-		flags |= X86_EFLAGS_IF;
-	flags |= X86_EFLAGS_IOPL;
-	return flags | (VEFLAGS & current->thread.vm86->veflags_mask);
-}
-
-static inline int is_revectored(int nr, struct revectored_struct *bitmap)
-{
-	return test_bit(nr, bitmap->__map);
-}
-
-#define val_byte(val, n) (((__u8 *)&val)[n])
-
-#define pushb(base, ptr, val, err_label) \
-	do { \
-		__u8 __val = val; \
-		ptr--; \
-		if (put_user(__val, base + ptr) < 0) \
-			goto err_label; \
-	} while (0)
-
-#define pushw(base, ptr, val, err_label) \
-	do { \
-		__u16 __val = val; \
-		ptr--; \
-		if (put_user(val_byte(__val, 1), base + ptr) < 0) \
-			goto err_label; \
-		ptr--; \
-		if (put_user(val_byte(__val, 0), base + ptr) < 0) \
-			goto err_label; \
-	} while (0)
-
-#define pushl(base, ptr, val, err_label) \
-	do { \
-		__u32 __val = val; \
-		ptr--; \
-		if (put_user(val_byte(__val, 3), base + ptr) < 0) \
-			goto err_label; \
-		ptr--; \
-		if (put_user(val_byte(__val, 2), base + ptr) < 0) \
-			goto err_label; \
-		ptr--; \
-		if (put_user(val_byte(__val, 1), base + ptr) < 0) \
-			goto err_label; \
-		ptr--; \
-		if (put_user(val_byte(__val, 0), base + ptr) < 0) \
-			goto err_label; \
-	} while (0)
-
-#define popb(base, ptr, err_label) \
-	({ \
-		__u8 __res; \
-		if (get_user(__res, base + ptr) < 0) \
-			goto err_label; \
-		ptr++; \
-		__res; \
-	})
-
-#define popw(base, ptr, err_label) \
-	({ \
-		__u16 __res; \
-		if (get_user(val_byte(__res, 0), base + ptr) < 0) \
-			goto err_label; \
-		ptr++; \
-		if (get_user(val_byte(__res, 1), base + ptr) < 0) \
-			goto err_label; \
-		ptr++; \
-		__res; \
-	})
-
-#define popl(base, ptr, err_label) \
-	({ \
-		__u32 __res; \
-		if (get_user(val_byte(__res, 0), base + ptr) < 0) \
-			goto err_label; \
-		ptr++; \
-		if (get_user(val_byte(__res, 1), base + ptr) < 0) \
-			goto err_label; \
-		ptr++; \
-		if (get_user(val_byte(__res, 2), base + ptr) < 0) \
-			goto err_label; \
-		ptr++; \
-		if (get_user(val_byte(__res, 3), base + ptr) < 0) \
-			goto err_label; \
-		ptr++; \
-		__res; \
-	})
-
-/* There are so many possible reasons for this function to return
- * VM86_INTx, so adding another doesn't bother me. We can expect
- * userspace programs to be able to handle it. (Getting a problem
- * in userspace is always better than an Oops anyway.) [KD]
- */
-static void do_int(struct kernel_vm86_regs *regs, int i,
-    unsigned char __user *ssp, unsigned short sp)
-{
-	unsigned long __user *intr_ptr;
-	unsigned long segoffs;
-	struct vm86 *vm86 = current->thread.vm86;
-
-	if (regs->pt.cs == BIOSSEG)
-		goto cannot_handle;
-	if (is_revectored(i, &vm86->int_revectored))
-		goto cannot_handle;
-	if (i == 0x21 && is_revectored(AH(regs), &vm86->int21_revectored))
-		goto cannot_handle;
-	intr_ptr = (unsigned long __user *) (i << 2);
-	if (get_user(segoffs, intr_ptr))
-		goto cannot_handle;
-	if ((segoffs >> 16) == BIOSSEG)
-		goto cannot_handle;
-	pushw(ssp, sp, get_vflags(regs), cannot_handle);
-	pushw(ssp, sp, regs->pt.cs, cannot_handle);
-	pushw(ssp, sp, IP(regs), cannot_handle);
-	regs->pt.cs = segoffs >> 16;
-	SP(regs) -= 6;
-	IP(regs) = segoffs & 0xffff;
-	clear_TF(regs);
-	clear_IF(regs);
-	clear_AC(regs);
-	return;
-
-cannot_handle:
-	save_v86_state(regs, VM86_INTx + (i << 8));
-}
-
-int handle_vm86_trap(struct kernel_vm86_regs *regs, long error_code, int trapno)
-{
-	struct vm86 *vm86 = current->thread.vm86;
-
-	if (vm86->vm86plus.is_vm86pus) {
-		if ((trapno == 3) || (trapno == 1)) {
-			save_v86_state(regs, VM86_TRAP + (trapno << 8));
-			return 0;
-		}
-		do_int(regs, trapno, (unsigned char __user *) (regs->pt.ss << 4), SP(regs));
-		return 0;
-	}
-	if (trapno != 1)
-		return 1; /* we let this handle by the calling routine */
-	current->thread.trap_nr = trapno;
-	current->thread.error_code = error_code;
-	force_sig(SIGTRAP);
-	return 0;
-}
-
-void handle_vm86_fault(struct kernel_vm86_regs *regs, long error_code)
-{
-	unsigned char opcode;
-	unsigned char __user *csp;
-	unsigned char __user *ssp;
-	unsigned short ip, sp, orig_flags;
-	int data32, pref_done;
-	struct vm86plus_info_struct *vmpi = &current->thread.vm86->vm86plus;
-
-#define CHECK_IF_IN_TRAP \
-	if (vmpi->vm86dbg_active && vmpi->vm86dbg_TFpendig) \
-		newflags |= X86_EFLAGS_TF
-
-	orig_flags = *(unsigned short *)&regs->pt.flags;
-
-	csp = (unsigned char __user *) (regs->pt.cs << 4);
-	ssp = (unsigned char __user *) (regs->pt.ss << 4);
-	sp = SP(regs);
-	ip = IP(regs);
-
-	data32 = 0;
-	pref_done = 0;
-	do {
-		switch (opcode = popb(csp, ip, simulate_sigsegv)) {
-		case 0x66:      /* 32-bit data */     data32 = 1; break;
-		case 0x67:      /* 32-bit address */  break;
-		case 0x2e:      /* CS */              break;
-		case 0x3e:      /* DS */              break;
-		case 0x26:      /* ES */              break;
-		case 0x36:      /* SS */              break;
-		case 0x65:      /* GS */              break;
-		case 0x64:      /* FS */              break;
-		case 0xf2:      /* repnz */       break;
-		case 0xf3:      /* rep */             break;
-		default: pref_done = 1;
-		}
-	} while (!pref_done);
-
-	switch (opcode) {
-
-	/* pushf */
-	case 0x9c:
-		if (data32) {
-			pushl(ssp, sp, get_vflags(regs), simulate_sigsegv);
-			SP(regs) -= 4;
-		} else {
-			pushw(ssp, sp, get_vflags(regs), simulate_sigsegv);
-			SP(regs) -= 2;
-		}
-		IP(regs) = ip;
-		goto vm86_fault_return;
-
-	/* popf */
-	case 0x9d:
-		{
-		unsigned long newflags;
-		if (data32) {
-			newflags = popl(ssp, sp, simulate_sigsegv);
-			SP(regs) += 4;
-		} else {
-			newflags = popw(ssp, sp, simulate_sigsegv);
-			SP(regs) += 2;
-		}
-		IP(regs) = ip;
-		CHECK_IF_IN_TRAP;
-		if (data32)
-			set_vflags_long(newflags, regs);
-		else
-			set_vflags_short(newflags, regs);
-
-		goto check_vip;
-		}
-
-	/* int xx */
-	case 0xcd: {
-		int intno = popb(csp, ip, simulate_sigsegv);
-		IP(regs) = ip;
-		if (vmpi->vm86dbg_active) {
-			if ((1 << (intno & 7)) & vmpi->vm86dbg_intxxtab[intno >> 3]) {
-				save_v86_state(regs, VM86_INTx + (intno << 8));
-				return;
-			}
-		}
-		do_int(regs, intno, ssp, sp);
-		return;
-	}
-
-	/* iret */
-	case 0xcf:
-		{
-		unsigned long newip;
-		unsigned long newcs;
-		unsigned long newflags;
-		if (data32) {
-			newip = popl(ssp, sp, simulate_sigsegv);
-			newcs = popl(ssp, sp, simulate_sigsegv);
-			newflags = popl(ssp, sp, simulate_sigsegv);
-			SP(regs) += 12;
-		} else {
-			newip = popw(ssp, sp, simulate_sigsegv);
-			newcs = popw(ssp, sp, simulate_sigsegv);
-			newflags = popw(ssp, sp, simulate_sigsegv);
-			SP(regs) += 6;
-		}
-		IP(regs) = newip;
-		regs->pt.cs = newcs;
-		CHECK_IF_IN_TRAP;
-		if (data32) {
-			set_vflags_long(newflags, regs);
-		} else {
-			set_vflags_short(newflags, regs);
-		}
-		goto check_vip;
-		}
-
-	/* cli */
-	case 0xfa:
-		IP(regs) = ip;
-		clear_IF(regs);
-		goto vm86_fault_return;
-
-	/* sti */
-	/*
-	 * Damn. This is incorrect: the 'sti' instruction should actually
-	 * enable interrupts after the /next/ instruction. Not good.
-	 *
-	 * Probably needs some horsing around with the TF flag. Aiee..
-	 */
-	case 0xfb:
-		IP(regs) = ip;
-		set_IF(regs);
-		goto check_vip;
-
-	default:
-		save_v86_state(regs, VM86_UNKNOWN);
-	}
-
-	return;
-
-check_vip:
-	if ((VEFLAGS & (X86_EFLAGS_VIP | X86_EFLAGS_VIF)) ==
-	    (X86_EFLAGS_VIP | X86_EFLAGS_VIF)) {
-		save_v86_state(regs, VM86_STI);
-		return;
-	}
-
-vm86_fault_return:
-	if (vmpi->force_return_for_pic  && (VEFLAGS & (X86_EFLAGS_IF | X86_EFLAGS_VIF))) {
-		save_v86_state(regs, VM86_PICRETURN);
-		return;
-	}
-	if (orig_flags & X86_EFLAGS_TF)
-		handle_vm86_trap(regs, 0, X86_TRAP_DB);
-	return;
-
-simulate_sigsegv:
-	/* FIXME: After a long discussion with Stas we finally
-	 *        agreed, that this is wrong. Here we should
-	 *        really send a SIGSEGV to the user program.
-	 *        But how do we create the correct context? We
-	 *        are inside a general protection fault handler
-	 *        and has just returned from a page fault handler.
-	 *        The correct context for the signal handler
-	 *        should be a mixture of the two, but how do we
-	 *        get the information? [KD]
-	 */
-	save_v86_state(regs, VM86_UNKNOWN);
-}
-
-/* ---------------- vm86 special IRQ passing stuff ----------------- */
-
-#define VM86_IRQNAME		"vm86irq"
-
-static struct vm86_irqs {
-	struct task_struct *tsk;
-	int sig;
-} vm86_irqs[16];
-
-static DEFINE_SPINLOCK(irqbits_lock);
-static int irqbits;
-
-#define ALLOWED_SIGS (1 /* 0 = don't send a signal */ \
-	| (1 << SIGUSR1) | (1 << SIGUSR2) | (1 << SIGIO)  | (1 << SIGURG) \
-	| (1 << SIGUNUSED))
-
-static irqreturn_t irq_handler(int intno, void *dev_id)
-{
-	int irq_bit;
-	unsigned long flags;
-
-	spin_lock_irqsave(&irqbits_lock, flags);
-	irq_bit = 1 << intno;
-	if ((irqbits & irq_bit) || !vm86_irqs[intno].tsk)
-		goto out;
-	irqbits |= irq_bit;
-	if (vm86_irqs[intno].sig)
-		send_sig(vm86_irqs[intno].sig, vm86_irqs[intno].tsk, 1);
-	/*
-	 * IRQ will be re-enabled when user asks for the irq (whether
-	 * polling or as a result of the signal)
-	 */
-	disable_irq_nosync(intno);
-	spin_unlock_irqrestore(&irqbits_lock, flags);
-	return IRQ_HANDLED;
-
-out:
-	spin_unlock_irqrestore(&irqbits_lock, flags);
-	return IRQ_NONE;
-}
-
-static inline void free_vm86_irq(int irqnumber)
-{
-	unsigned long flags;
-
-	free_irq(irqnumber, NULL);
-	vm86_irqs[irqnumber].tsk = NULL;
-
-	spin_lock_irqsave(&irqbits_lock, flags);
-	irqbits &= ~(1 << irqnumber);
-	spin_unlock_irqrestore(&irqbits_lock, flags);
-}
-
-void release_vm86_irqs(struct task_struct *task)
-{
-	int i;
-	for (i = FIRST_VM86_IRQ ; i <= LAST_VM86_IRQ; i++)
-	    if (vm86_irqs[i].tsk == task)
-		free_vm86_irq(i);
-}
-
-static inline int get_and_reset_irq(int irqnumber)
-{
-	int bit;
-	unsigned long flags;
-	int ret = 0;
-
-	if (invalid_vm86_irq(irqnumber)) return 0;
-	if (vm86_irqs[irqnumber].tsk != current) return 0;
-	spin_lock_irqsave(&irqbits_lock, flags);
-	bit = irqbits & (1 << irqnumber);
-	irqbits &= ~bit;
-	if (bit) {
-		enable_irq(irqnumber);
-		ret = 1;
-	}
-
-	spin_unlock_irqrestore(&irqbits_lock, flags);
-	return ret;
-}
-
-
-static int do_vm86_irq_handling(int subfunction, int irqnumber)
-{
-	int ret;
-	switch (subfunction) {
-		case VM86_GET_AND_RESET_IRQ: {
-			return get_and_reset_irq(irqnumber);
-		}
-		case VM86_GET_IRQ_BITS: {
-			return irqbits;
-		}
-		case VM86_REQUEST_IRQ: {
-			int sig = irqnumber >> 8;
-			int irq = irqnumber & 255;
-			if (!capable(CAP_SYS_ADMIN)) return -EPERM;
-			if (!((1 << sig) & ALLOWED_SIGS)) return -EPERM;
-			if (invalid_vm86_irq(irq)) return -EPERM;
-			if (vm86_irqs[irq].tsk) return -EPERM;
-			ret = request_irq(irq, &irq_handler, 0, VM86_IRQNAME, NULL);
-			if (ret) return ret;
-			vm86_irqs[irq].sig = sig;
-			vm86_irqs[irq].tsk = current;
-			return irq;
-		}
-		case  VM86_FREE_IRQ: {
-			if (invalid_vm86_irq(irqnumber)) return -EPERM;
-			if (!vm86_irqs[irqnumber].tsk) return 0;
-			if (vm86_irqs[irqnumber].tsk != current) return -EPERM;
-			free_vm86_irq(irqnumber);
-			return 0;
-		}
-	}
-	return -EINVAL;
-}
-
--
2.43.0
Re: [PATCH v2] x86/vm86: Remove deprecated VM86 support
Posted by Brian Gerst 1 week, 2 days ago
On Wed, May 27, 2026 at 3:33 AM Ashwin Gundarapu
<linuxuser509@zohomail.in> wrote:
>
> VM86 support allows 16-bit DOS programs to run in virtual 8086 mode
> on 32-bit x86 kernels. This feature has been deprecated and the Kconfig
> help text itself states that any recent software works without it.
>
> Remove the vm86 subsystem entirely including the main driver source,
> Kconfig options, header file, and all references in thread_info,
> processor, and processor-flags headers.
>
> Signed-off-by: Ashwin Gundarapu <linuxuser509@zohomail.in>
> ---
> v2: Also remove arch/x86/include/asm/vm86.h and arch/x86/kernel/vm86_32.c
>     as pointed out by Christophe JAILLET.
> ---
>  arch/x86/Kconfig                       |  30 -
>  arch/x86/include/asm/processor-flags.h |   6 +-
>  arch/x86/include/asm/processor.h       |   5 +-
>  arch/x86/include/asm/thread_info.h     |   6 +-
>  arch/x86/include/asm/vm86.h            |  91 ---
>  arch/x86/kernel/Makefile               |   1 -
>  arch/x86/kernel/process.c              |   5 -
>  arch/x86/kernel/vm86_32.c              | 831 -------------------------
>  8 files changed, 3 insertions(+), 972 deletions(-)
>  delete mode 100644 arch/x86/include/asm/vm86.h
>  delete mode 100644 arch/x86/kernel/vm86_32.c

An additional cleanup is to remove the code to switch
MSR_IA32_SYSENTER_CS, which is only needed when entering VM86 mode.
Re: [PATCH v2] x86/vm86: Remove deprecated VM86 support
Posted by kernel test robot 1 week, 4 days ago
Hi Ashwin,

kernel test robot noticed the following build errors:

[auto build test ERROR on v7.1-rc5]
[also build test ERROR on linus/master next-20260527]
[cannot apply to tip/x86/core]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Ashwin-Gundarapu/x86-vm86-Remove-deprecated-VM86-support/20260527-153401
base:   v7.1-rc5
patch link:    https://lore.kernel.org/r/19e6858d9db.3a90532342003.5043853571553507480%40zohomail.in
patch subject: [PATCH v2] x86/vm86: Remove deprecated VM86 support
config: x86_64-allnoconfig (https://download.01.org/0day-ci/archive/20260528/202605281705.9gRlhp1Y-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260528/202605281705.9gRlhp1Y-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202605281705.9gRlhp1Y-lkp@intel.com/

All errors (new ones prefixed by >>):

>> arch/x86/kernel/signal.c:261:3: error: call to undeclared function 'save_v86_state'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     261 |                 save_v86_state((struct kernel_vm86_regs *) regs, VM86_SIGNAL);
         |                 ^
   1 error generated.
--
>> arch/x86/kernel/traps.c:289:9: error: call to undeclared function 'handle_vm86_trap'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     289 |                         if (!handle_vm86_trap((struct kernel_vm86_regs *) regs,
         |                              ^
>> arch/x86/kernel/traps.c:927:3: error: call to undeclared function 'handle_vm86_fault'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     927 |                 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
         |                 ^
   arch/x86/kernel/traps.c:927:3: note: did you mean 'handle_mm_fault'?
   include/linux/mm.h:3144:19: note: 'handle_mm_fault' declared here
    3144 | extern vm_fault_t handle_mm_fault(struct vm_area_struct *vma,
         |                   ^
   arch/x86/kernel/traps.c:1347:3: error: call to undeclared function 'handle_vm86_trap'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    1347 |                 handle_vm86_trap((struct kernel_vm86_regs *)regs, 0, X86_TRAP_DB);
         |                 ^
   3 errors generated.


vim +/save_v86_state +261 arch/x86/kernel/signal.c

1d13024e624d0e2 arch/x86/kernel/signal_32.c Hiroshi Shimamoto   2008-09-05  253  
a610d6e672d6d37 arch/x86/kernel/signal.c    Al Viro             2012-05-21  254  static void
235b80226b986da arch/x86/kernel/signal.c    Al Viro             2012-11-09  255  handle_signal(struct ksignal *ksig, struct pt_regs *regs)
^1da177e4c3f415 arch/i386/kernel/signal.c   Linus Torvalds      2005-04-16  256  {
fd0f86b66425bd8 arch/x86/kernel/signal.c    Oleg Nesterov       2015-04-16  257  	bool stepping, failed;
e3bfa3859936da3 arch/x86/kernel/signal.c    Ingo Molnar         2025-04-09  258  	struct fpu *fpu = x86_task_fpu(current);
fd0f86b66425bd8 arch/x86/kernel/signal.c    Oleg Nesterov       2015-04-16  259  
5ed92a8ab71f886 arch/x86/kernel/signal.c    Brian Gerst         2015-07-29  260  	if (v8086_mode(regs))
5ed92a8ab71f886 arch/x86/kernel/signal.c    Brian Gerst         2015-07-29 @261  		save_v86_state((struct kernel_vm86_regs *) regs, VM86_SIGNAL);
5ed92a8ab71f886 arch/x86/kernel/signal.c    Brian Gerst         2015-07-29  262  
^1da177e4c3f415 arch/i386/kernel/signal.c   Linus Torvalds      2005-04-16  263  	/* Are we from a system call? */
9ddcb87b9218dec arch/x86/kernel/signal.c    H. Peter Anvin      2021-05-10  264  	if (syscall_get_nr(current, regs) != -1) {
^1da177e4c3f415 arch/i386/kernel/signal.c   Linus Torvalds      2005-04-16  265  		/* If so, check system call restarting.. */
bb57925f5057837 arch/x86/kernel/signal_32.c Hiroshi Shimamoto   2008-09-05  266  		switch (syscall_get_error(current, regs)) {
^1da177e4c3f415 arch/i386/kernel/signal.c   Linus Torvalds      2005-04-16  267  		case -ERESTART_RESTARTBLOCK:
^1da177e4c3f415 arch/i386/kernel/signal.c   Linus Torvalds      2005-04-16  268  		case -ERESTARTNOHAND:
65ea5b034990358 arch/x86/kernel/signal_32.c H. Peter Anvin      2008-01-30  269  			regs->ax = -EINTR;
^1da177e4c3f415 arch/i386/kernel/signal.c   Linus Torvalds      2005-04-16  270  			break;
^1da177e4c3f415 arch/i386/kernel/signal.c   Linus Torvalds      2005-04-16  271  
^1da177e4c3f415 arch/i386/kernel/signal.c   Linus Torvalds      2005-04-16  272  		case -ERESTARTSYS:
235b80226b986da arch/x86/kernel/signal.c    Al Viro             2012-11-09  273  			if (!(ksig->ka.sa.sa_flags & SA_RESTART)) {
65ea5b034990358 arch/x86/kernel/signal_32.c H. Peter Anvin      2008-01-30  274  				regs->ax = -EINTR;
^1da177e4c3f415 arch/i386/kernel/signal.c   Linus Torvalds      2005-04-16  275  				break;
^1da177e4c3f415 arch/i386/kernel/signal.c   Linus Torvalds      2005-04-16  276  			}
df561f6688fef77 arch/x86/kernel/signal.c    Gustavo A. R. Silva 2020-08-23  277  			fallthrough;
^1da177e4c3f415 arch/i386/kernel/signal.c   Linus Torvalds      2005-04-16  278  		case -ERESTARTNOINTR:
65ea5b034990358 arch/x86/kernel/signal_32.c H. Peter Anvin      2008-01-30  279  			regs->ax = regs->orig_ax;
65ea5b034990358 arch/x86/kernel/signal_32.c H. Peter Anvin      2008-01-30  280  			regs->ip -= 2;
ac66f3fd89ee20b arch/x86/kernel/signal_32.c Harvey Harrison     2008-02-08  281  			break;
^1da177e4c3f415 arch/i386/kernel/signal.c   Linus Torvalds      2005-04-16  282  		}
^1da177e4c3f415 arch/i386/kernel/signal.c   Linus Torvalds      2005-04-16  283  	}
^1da177e4c3f415 arch/i386/kernel/signal.c   Linus Torvalds      2005-04-16  284  
^1da177e4c3f415 arch/i386/kernel/signal.c   Linus Torvalds      2005-04-16  285  	/*
fd0f86b66425bd8 arch/x86/kernel/signal.c    Oleg Nesterov       2015-04-16  286  	 * If TF is set due to a debugger (TIF_FORCED_TF), clear TF now
fd0f86b66425bd8 arch/x86/kernel/signal.c    Oleg Nesterov       2015-04-16  287  	 * so that register information in the sigcontext is correct and
fd0f86b66425bd8 arch/x86/kernel/signal.c    Oleg Nesterov       2015-04-16  288  	 * then notify the tracer before entering the signal handler.
^1da177e4c3f415 arch/i386/kernel/signal.c   Linus Torvalds      2005-04-16  289  	 */
fd0f86b66425bd8 arch/x86/kernel/signal.c    Oleg Nesterov       2015-04-16  290  	stepping = test_thread_flag(TIF_SINGLESTEP);
fd0f86b66425bd8 arch/x86/kernel/signal.c    Oleg Nesterov       2015-04-16  291  	if (stepping)
fd0f86b66425bd8 arch/x86/kernel/signal.c    Oleg Nesterov       2015-04-16  292  		user_disable_single_step(current);
^1da177e4c3f415 arch/i386/kernel/signal.c   Linus Torvalds      2005-04-16  293  
235b80226b986da arch/x86/kernel/signal.c    Al Viro             2012-11-09  294  	failed = (setup_rt_frame(ksig, regs) < 0);
235b80226b986da arch/x86/kernel/signal.c    Al Viro             2012-11-09  295  	if (!failed) {
8b9c5ff380aa4f1 arch/x86/kernel/signal_32.c Roland McGrath      2008-04-19  296  		/*
8b9c5ff380aa4f1 arch/x86/kernel/signal_32.c Roland McGrath      2008-04-19  297  		 * Clear the direction flag as per the ABI for function entry.
ddd40da4ccbabdd arch/x86/kernel/signal.c    Jiri Olsa           2013-05-01  298  		 *
24cda10996f5420 arch/x86/kernel/signal.c    Jiri Olsa           2013-05-01  299  		 * Clear RF when entering the signal handler, because
24cda10996f5420 arch/x86/kernel/signal.c    Jiri Olsa           2013-05-01  300  		 * it might disable possible debug exception from the
24cda10996f5420 arch/x86/kernel/signal.c    Jiri Olsa           2013-05-01  301  		 * signal handler.
ddd40da4ccbabdd arch/x86/kernel/signal.c    Jiri Olsa           2013-05-01  302  		 *
fd0f86b66425bd8 arch/x86/kernel/signal.c    Oleg Nesterov       2015-04-16  303  		 * Clear TF for the case when it wasn't set by debugger to
fd0f86b66425bd8 arch/x86/kernel/signal.c    Oleg Nesterov       2015-04-16  304  		 * avoid the recursive send_sigtrap() in SIGTRAP handler.
8b9c5ff380aa4f1 arch/x86/kernel/signal_32.c Roland McGrath      2008-04-19  305  		 */
ddd40da4ccbabdd arch/x86/kernel/signal.c    Jiri Olsa           2013-05-01  306  		regs->flags &= ~(X86_EFLAGS_DF|X86_EFLAGS_RF|X86_EFLAGS_TF);
66463db4fc5605d arch/x86/kernel/signal.c    Oleg Nesterov       2014-09-02  307  		/*
66463db4fc5605d arch/x86/kernel/signal.c    Oleg Nesterov       2014-09-02  308  		 * Ensure the signal handler starts with the new fpu state.
66463db4fc5605d arch/x86/kernel/signal.c    Oleg Nesterov       2014-09-02  309  		 */
b860eb8dce5906b arch/x86/kernel/signal.c    Fenghua Yu          2020-05-12  310  		fpu__clear_user_states(fpu);
235b80226b986da arch/x86/kernel/signal.c    Al Viro             2012-11-09  311  	}
fd0f86b66425bd8 arch/x86/kernel/signal.c    Oleg Nesterov       2015-04-16  312  	signal_setup_done(failed, ksig, stepping);
^1da177e4c3f415 arch/i386/kernel/signal.c   Linus Torvalds      2005-04-16  313  }
^1da177e4c3f415 arch/i386/kernel/signal.c   Linus Torvalds      2005-04-16  314  

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH v2] x86/vm86: Remove deprecated VM86 support
Posted by kernel test robot 1 week, 4 days ago
Hi Ashwin,

kernel test robot noticed the following build errors:

[auto build test ERROR on v7.1-rc5]
[also build test ERROR on linus/master next-20260527]
[cannot apply to tip/x86/core]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Ashwin-Gundarapu/x86-vm86-Remove-deprecated-VM86-support/20260527-153401
base:   v7.1-rc5
patch link:    https://lore.kernel.org/r/19e6858d9db.3a90532342003.5043853571553507480%40zohomail.in
patch subject: [PATCH v2] x86/vm86: Remove deprecated VM86 support
config: i386-allnoconfig (https://download.01.org/0day-ci/archive/20260528/202605281749.4b3Hss7l-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260528/202605281749.4b3Hss7l-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202605281749.4b3Hss7l-lkp@intel.com/

All errors (new ones prefixed by >>):

   arch/x86/lib/insn-eval.c: In function 'get_segment_selector':
>> arch/x86/lib/insn-eval.c:380:40: error: invalid use of undefined type 'struct kernel_vm86_regs'
     380 |                         return vm86regs->ds;
         |                                        ^~
   arch/x86/lib/insn-eval.c:382:40: error: invalid use of undefined type 'struct kernel_vm86_regs'
     382 |                         return vm86regs->es;
         |                                        ^~
   arch/x86/lib/insn-eval.c:384:40: error: invalid use of undefined type 'struct kernel_vm86_regs'
     384 |                         return vm86regs->fs;
         |                                        ^~
   arch/x86/lib/insn-eval.c:386:40: error: invalid use of undefined type 'struct kernel_vm86_regs'
     386 |                         return vm86regs->gs;
         |                                        ^~
--
   arch/x86/kernel/process_32.c: In function 'release_thread':
>> arch/x86/kernel/process_32.c:108:9: error: implicit declaration of function 'release_vm86_irqs' [-Wimplicit-function-declaration]
     108 |         release_vm86_irqs(dead_task);
         |         ^~~~~~~~~~~~~~~~~
--
   arch/x86/kernel/signal.c: In function 'handle_signal':
>> arch/x86/kernel/signal.c:261:17: error: implicit declaration of function 'save_v86_state' [-Wimplicit-function-declaration]
     261 |                 save_v86_state((struct kernel_vm86_regs *) regs, VM86_SIGNAL);
         |                 ^~~~~~~~~~~~~~
--
   arch/x86/kernel/traps.c: In function 'do_trap_no_signal':
>> arch/x86/kernel/traps.c:289:30: error: implicit declaration of function 'handle_vm86_trap' [-Wimplicit-function-declaration]
     289 |                         if (!handle_vm86_trap((struct kernel_vm86_regs *) regs,
         |                              ^~~~~~~~~~~~~~~~
   arch/x86/kernel/traps.c: In function '__exc_general_protection':
>> arch/x86/kernel/traps.c:927:17: error: implicit declaration of function 'handle_vm86_fault'; did you mean 'handle_mm_fault'? [-Wimplicit-function-declaration]
     927 |                 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
         |                 ^~~~~~~~~~~~~~~~~
         |                 handle_mm_fault


vim +380 arch/x86/lib/insn-eval.c

32d0b95300db03 Ricardo Neri 2017-10-27  323  
32d0b95300db03 Ricardo Neri 2017-10-27  324  /**
32d0b95300db03 Ricardo Neri 2017-10-27  325   * get_segment_selector() - obtain segment selector
32d0b95300db03 Ricardo Neri 2017-10-27  326   * @regs:		Register values as seen when entering kernel mode
32d0b95300db03 Ricardo Neri 2017-10-27  327   * @seg_reg_idx:	Segment register index to use
32d0b95300db03 Ricardo Neri 2017-10-27  328   *
32d0b95300db03 Ricardo Neri 2017-10-27  329   * Obtain the segment selector from any of the CS, SS, DS, ES, FS, GS segment
32d0b95300db03 Ricardo Neri 2017-10-27  330   * registers. In CONFIG_X86_32, the segment is obtained from either pt_regs or
32d0b95300db03 Ricardo Neri 2017-10-27  331   * kernel_vm86_regs as applicable. In CONFIG_X86_64, CS and SS are obtained
32d0b95300db03 Ricardo Neri 2017-10-27  332   * from pt_regs. DS, ES, FS and GS are obtained by reading the actual CPU
32d0b95300db03 Ricardo Neri 2017-10-27  333   * registers. This done for only for completeness as in CONFIG_X86_64 segment
32d0b95300db03 Ricardo Neri 2017-10-27  334   * registers are ignored.
32d0b95300db03 Ricardo Neri 2017-10-27  335   *
32d0b95300db03 Ricardo Neri 2017-10-27  336   * Returns:
32d0b95300db03 Ricardo Neri 2017-10-27  337   *
32d0b95300db03 Ricardo Neri 2017-10-27  338   * Value of the segment selector, including null when running in
32d0b95300db03 Ricardo Neri 2017-10-27  339   * long mode.
32d0b95300db03 Ricardo Neri 2017-10-27  340   *
32d0b95300db03 Ricardo Neri 2017-10-27  341   * -EINVAL on error.
32d0b95300db03 Ricardo Neri 2017-10-27  342   */
32d0b95300db03 Ricardo Neri 2017-10-27  343  static short get_segment_selector(struct pt_regs *regs, int seg_reg_idx)
32d0b95300db03 Ricardo Neri 2017-10-27  344  {
32d0b95300db03 Ricardo Neri 2017-10-27  345  	unsigned short sel;
32d0b95300db03 Ricardo Neri 2017-10-27  346  
3a24a60854d2ef Brian Gerst  2022-03-25  347  #ifdef CONFIG_X86_64
32d0b95300db03 Ricardo Neri 2017-10-27  348  	switch (seg_reg_idx) {
32d0b95300db03 Ricardo Neri 2017-10-27  349  	case INAT_SEG_REG_IGNORE:
32d0b95300db03 Ricardo Neri 2017-10-27  350  		return 0;
32d0b95300db03 Ricardo Neri 2017-10-27  351  	case INAT_SEG_REG_CS:
32d0b95300db03 Ricardo Neri 2017-10-27  352  		return (unsigned short)(regs->cs & 0xffff);
32d0b95300db03 Ricardo Neri 2017-10-27  353  	case INAT_SEG_REG_SS:
32d0b95300db03 Ricardo Neri 2017-10-27  354  		return (unsigned short)(regs->ss & 0xffff);
32d0b95300db03 Ricardo Neri 2017-10-27  355  	case INAT_SEG_REG_DS:
32d0b95300db03 Ricardo Neri 2017-10-27  356  		savesegment(ds, sel);
32d0b95300db03 Ricardo Neri 2017-10-27  357  		return sel;
32d0b95300db03 Ricardo Neri 2017-10-27  358  	case INAT_SEG_REG_ES:
32d0b95300db03 Ricardo Neri 2017-10-27  359  		savesegment(es, sel);
32d0b95300db03 Ricardo Neri 2017-10-27  360  		return sel;
32d0b95300db03 Ricardo Neri 2017-10-27  361  	case INAT_SEG_REG_FS:
32d0b95300db03 Ricardo Neri 2017-10-27  362  		savesegment(fs, sel);
32d0b95300db03 Ricardo Neri 2017-10-27  363  		return sel;
32d0b95300db03 Ricardo Neri 2017-10-27  364  	case INAT_SEG_REG_GS:
32d0b95300db03 Ricardo Neri 2017-10-27  365  		savesegment(gs, sel);
32d0b95300db03 Ricardo Neri 2017-10-27  366  		return sel;
32d0b95300db03 Ricardo Neri 2017-10-27  367  	default:
32d0b95300db03 Ricardo Neri 2017-10-27  368  		return -EINVAL;
32d0b95300db03 Ricardo Neri 2017-10-27  369  	}
32d0b95300db03 Ricardo Neri 2017-10-27  370  #else /* CONFIG_X86_32 */
32d0b95300db03 Ricardo Neri 2017-10-27  371  	struct kernel_vm86_regs *vm86regs = (struct kernel_vm86_regs *)regs;
32d0b95300db03 Ricardo Neri 2017-10-27  372  
32d0b95300db03 Ricardo Neri 2017-10-27  373  	if (v8086_mode(regs)) {
32d0b95300db03 Ricardo Neri 2017-10-27  374  		switch (seg_reg_idx) {
32d0b95300db03 Ricardo Neri 2017-10-27  375  		case INAT_SEG_REG_CS:
32d0b95300db03 Ricardo Neri 2017-10-27  376  			return (unsigned short)(regs->cs & 0xffff);
32d0b95300db03 Ricardo Neri 2017-10-27  377  		case INAT_SEG_REG_SS:
32d0b95300db03 Ricardo Neri 2017-10-27  378  			return (unsigned short)(regs->ss & 0xffff);
32d0b95300db03 Ricardo Neri 2017-10-27  379  		case INAT_SEG_REG_DS:
32d0b95300db03 Ricardo Neri 2017-10-27 @380  			return vm86regs->ds;
32d0b95300db03 Ricardo Neri 2017-10-27  381  		case INAT_SEG_REG_ES:
32d0b95300db03 Ricardo Neri 2017-10-27  382  			return vm86regs->es;
32d0b95300db03 Ricardo Neri 2017-10-27  383  		case INAT_SEG_REG_FS:
32d0b95300db03 Ricardo Neri 2017-10-27  384  			return vm86regs->fs;
32d0b95300db03 Ricardo Neri 2017-10-27  385  		case INAT_SEG_REG_GS:
32d0b95300db03 Ricardo Neri 2017-10-27  386  			return vm86regs->gs;
32d0b95300db03 Ricardo Neri 2017-10-27  387  		case INAT_SEG_REG_IGNORE:
32d0b95300db03 Ricardo Neri 2017-10-27  388  		default:
32d0b95300db03 Ricardo Neri 2017-10-27  389  			return -EINVAL;
32d0b95300db03 Ricardo Neri 2017-10-27  390  		}
32d0b95300db03 Ricardo Neri 2017-10-27  391  	}
32d0b95300db03 Ricardo Neri 2017-10-27  392  
32d0b95300db03 Ricardo Neri 2017-10-27  393  	switch (seg_reg_idx) {
32d0b95300db03 Ricardo Neri 2017-10-27  394  	case INAT_SEG_REG_CS:
32d0b95300db03 Ricardo Neri 2017-10-27  395  		return (unsigned short)(regs->cs & 0xffff);
32d0b95300db03 Ricardo Neri 2017-10-27  396  	case INAT_SEG_REG_SS:
32d0b95300db03 Ricardo Neri 2017-10-27  397  		return (unsigned short)(regs->ss & 0xffff);
32d0b95300db03 Ricardo Neri 2017-10-27  398  	case INAT_SEG_REG_DS:
32d0b95300db03 Ricardo Neri 2017-10-27  399  		return (unsigned short)(regs->ds & 0xffff);
32d0b95300db03 Ricardo Neri 2017-10-27  400  	case INAT_SEG_REG_ES:
32d0b95300db03 Ricardo Neri 2017-10-27  401  		return (unsigned short)(regs->es & 0xffff);
32d0b95300db03 Ricardo Neri 2017-10-27  402  	case INAT_SEG_REG_FS:
32d0b95300db03 Ricardo Neri 2017-10-27  403  		return (unsigned short)(regs->fs & 0xffff);
32d0b95300db03 Ricardo Neri 2017-10-27  404  	case INAT_SEG_REG_GS:
3a24a60854d2ef Brian Gerst  2022-03-25  405  		savesegment(gs, sel);
3a24a60854d2ef Brian Gerst  2022-03-25  406  		return sel;
32d0b95300db03 Ricardo Neri 2017-10-27  407  	case INAT_SEG_REG_IGNORE:
32d0b95300db03 Ricardo Neri 2017-10-27  408  	default:
32d0b95300db03 Ricardo Neri 2017-10-27  409  		return -EINVAL;
32d0b95300db03 Ricardo Neri 2017-10-27  410  	}
32d0b95300db03 Ricardo Neri 2017-10-27  411  #endif /* CONFIG_X86_64 */
32d0b95300db03 Ricardo Neri 2017-10-27  412  }
32d0b95300db03 Ricardo Neri 2017-10-27  413  

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki