]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
x86/vsyscall: Reorganize the page fault emulation code
authorSohil Mehta <sohil.mehta@intel.com>
Mon, 9 Mar 2026 18:10:25 +0000 (11:10 -0700)
committerDave Hansen <dave.hansen@linux.intel.com>
Thu, 19 Mar 2026 22:11:12 +0000 (15:11 -0700)
With LASS, vsyscall page accesses will cause a #GP instead of a #PF.
Separate out the core vsyscall emulation code from the #PF specific
handling in preparation for the upcoming #GP emulation.

No functional change intended.

Signed-off-by: Sohil Mehta <sohil.mehta@intel.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
Tested-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
Link: https://patch.msgid.link/20260309181029.398498-2-sohil.mehta@intel.com
arch/x86/entry/vsyscall/vsyscall_64.c
arch/x86/include/asm/vsyscall.h
arch/x86/mm/fault.c

index 4bd1e271bb22b313fd6140cd0430a4ed94ab4f01..398b1ed16f1e4f5cd6ad07c33d14cad85b2fffff 100644 (file)
@@ -111,43 +111,13 @@ static bool write_ok_or_segv(unsigned long ptr, size_t size)
        }
 }
 
-bool emulate_vsyscall(unsigned long error_code,
-                     struct pt_regs *regs, unsigned long address)
+static bool __emulate_vsyscall(struct pt_regs *regs, unsigned long address)
 {
        unsigned long caller;
        int vsyscall_nr, syscall_nr, tmp;
        long ret;
        unsigned long orig_dx;
 
-       /* Write faults or kernel-privilege faults never get fixed up. */
-       if ((error_code & (X86_PF_WRITE | X86_PF_USER)) != X86_PF_USER)
-               return false;
-
-       /*
-        * Assume that faults at regs->ip are because of an
-        * instruction fetch. Return early and avoid
-        * emulation for faults during data accesses:
-        */
-       if (address != regs->ip) {
-               /* Failed vsyscall read */
-               if (vsyscall_mode == EMULATE)
-                       return false;
-
-               /*
-                * User code tried and failed to read the vsyscall page.
-                */
-               warn_bad_vsyscall(KERN_INFO, regs, "vsyscall read attempt denied -- look up the vsyscall kernel parameter if you need a workaround");
-               return false;
-       }
-
-       /*
-        * X86_PF_INSTR is only set when NX is supported.  When
-        * available, use it to double-check that the emulation code
-        * is only being used for instruction fetches:
-        */
-       if (cpu_feature_enabled(X86_FEATURE_NX))
-               WARN_ON_ONCE(!(error_code & X86_PF_INSTR));
-
        /*
         * No point in checking CS -- the only way to get here is a user mode
         * trap to a high address, which means that we're in 64-bit user code.
@@ -280,6 +250,40 @@ sigsegv:
        return true;
 }
 
+bool emulate_vsyscall_pf(unsigned long error_code, struct pt_regs *regs,
+                        unsigned long address)
+{
+       /* Write faults or kernel-privilege faults never get fixed up. */
+       if ((error_code & (X86_PF_WRITE | X86_PF_USER)) != X86_PF_USER)
+               return false;
+
+       /*
+        * Assume that faults at regs->ip are because of an instruction
+        * fetch. Return early and avoid emulation for faults during
+        * data accesses:
+        */
+       if (address != regs->ip) {
+               /* Failed vsyscall read */
+               if (vsyscall_mode == EMULATE)
+                       return false;
+
+               /* User code tried and failed to read the vsyscall page. */
+               warn_bad_vsyscall(KERN_INFO, regs,
+                                 "vsyscall read attempt denied -- look up the vsyscall kernel parameter if you need a workaround");
+               return false;
+       }
+
+       /*
+        * X86_PF_INSTR is only set when NX is supported.  When
+        * available, use it to double-check that the emulation code
+        * is only being used for instruction fetches:
+        */
+       if (cpu_feature_enabled(X86_FEATURE_NX))
+               WARN_ON_ONCE(!(error_code & X86_PF_INSTR));
+
+       return __emulate_vsyscall(regs, address);
+}
+
 /*
  * A pseudo VMA to allow ptrace access for the vsyscall page.  This only
  * covers the 64bit vsyscall page now. 32bit has a real VMA now and does
index 472f0263dbc6129c30636f149b94d5828ac300c6..f349023649726b813f844a4df3a6d8dd72512cc6 100644 (file)
@@ -14,12 +14,11 @@ extern void set_vsyscall_pgtable_user_bits(pgd_t *root);
  * Called on instruction fetch fault in vsyscall page.
  * Returns true if handled.
  */
-extern bool emulate_vsyscall(unsigned long error_code,
-                            struct pt_regs *regs, unsigned long address);
+bool emulate_vsyscall_pf(unsigned long error_code, struct pt_regs *regs, unsigned long address);
 #else
 static inline void map_vsyscall(void) {}
-static inline bool emulate_vsyscall(unsigned long error_code,
-                                   struct pt_regs *regs, unsigned long address)
+static inline bool emulate_vsyscall_pf(unsigned long error_code,
+                                      struct pt_regs *regs, unsigned long address)
 {
        return false;
 }
index b83a06739b511874e0136d22f272be56e29c3de0..f0e77e0844820782538f108f897b438c71544d2f 100644 (file)
@@ -1314,7 +1314,7 @@ void do_user_addr_fault(struct pt_regs *regs,
         * to consider the PF_PK bit.
         */
        if (is_vsyscall_vaddr(address)) {
-               if (emulate_vsyscall(error_code, regs, address))
+               if (emulate_vsyscall_pf(error_code, regs, address))
                        return;
        }
 #endif