File: linux-6.19.patch

package info (click to toggle)
virtualbox 7.2.6-dfsg-3.2
  • links: PTS, VCS
  • area: contrib
  • in suites: sid
  • size: 684,308 kB
  • sloc: ansic: 2,692,693; cpp: 2,685,536; asm: 402,532; python: 239,820; xml: 89,849; sh: 33,358; perl: 9,380; makefile: 8,889; java: 5,337; cs: 4,872; pascal: 1,785; javascript: 1,692; objc: 1,131; lex: 931; sed: 929; php: 906; yacc: 707
file content (214 lines) | stat: -rw-r--r-- 8,247 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
Description: Linux host: Introduce initial support for kernel 6.19
Origin: upstream, https://github.com/VirtualBox/virtualbox/commit/280303b3f03d7087
Last-Update: 2026-03-26

--- a/src/VBox/HostDrivers/Support/linux/SUPDrv-linux.c
+++ b/src/VBox/HostDrivers/Support/linux/SUPDrv-linux.c
@@ -190,6 +190,12 @@ static bool                 g_fEnabledHw
 static int                  (*g_pfnKvmEnableVirtualization)(void);
 /** Function pointer to kvm_disable_virtualization(). */
 static void                 (*g_pfnKvmDisableVirtualization)(void);
+# if RTLNX_VER_MIN(6,19,0)
+/** Function pointer to cr4_update_irqsoff(). */
+static void                 (*g_pfnCr4UpdateIrqsoff)(unsigned long set, unsigned long clear);
+/** Function pointer to cr4_read_shadow(). */
+static unsigned long        (*g_pfnCr4ReadShadow)(void);
+# endif
 /** Pointer to the KVM hardware specific module. */
 struct module               *g_pKvmHwvirtModule;
 #endif
@@ -395,6 +401,28 @@ static int supdrvLinuxInitKvmSymbols(voi
         void *pfnDisable = __symbol_get("kvm_disable_virtualization");
         if (pfnDisable)
         {
+# if RTLNX_VER_MIN(6,19,0)
+            void *pfnCr4UpdateIrqsoff = __symbol_get("cr4_update_irqsoff");
+            void *pfnRr4ReadShadow = __symbol_get("cr4_read_shadow");
+
+            if (   pfnCr4UpdateIrqsoff
+                && pfnRr4ReadShadow)
+            {
+                g_pfnCr4UpdateIrqsoff   = pfnCr4UpdateIrqsoff;
+                g_pfnCr4ReadShadow      = pfnRr4ReadShadow;
+
+                printk(KERN_INFO "vboxdrv: Found extra KVM hardware-virtualization symbols\n");
+            }
+            else
+            {
+                printk(KERN_WARNING "vboxdrv: Failed to find extra KVM hardware-virtualization symbols\n");
+
+                if (pfnCr4UpdateIrqsoff)
+                    symbol_put_addr(pfnCr4UpdateIrqsoff);
+                if (pfnRr4ReadShadow)
+                    symbol_put_addr(pfnRr4ReadShadow);
+            }
+#endif
             /*
              * Try to obtain a reference to kvm_intel/kvm_amd module in addition to the
              * reference to the kvm module. If we fail, we will not try to use KVM for
@@ -466,6 +494,18 @@ static void supdrvLinuxTermKvmSymbols(vo
         symbol_put_addr(g_pfnKvmDisableVirtualization);
         g_pfnKvmDisableVirtualization = NULL;
     }
+# if RTLNX_VER_MIN(6,19,0)
+    if (g_pfnCr4UpdateIrqsoff)
+    {
+        symbol_put_addr(g_pfnCr4UpdateIrqsoff);
+        g_pfnCr4UpdateIrqsoff = NULL;
+    }
+    if (g_pfnCr4ReadShadow)
+    {
+        symbol_put_addr(g_pfnCr4ReadShadow);
+        g_pfnCr4ReadShadow = NULL;
+    }
+#endif
     if (g_pKvmHwvirtModule)
     {
         module_put(g_pKvmHwvirtModule);
@@ -1146,6 +1186,35 @@ SUPR0DECL(int) SUPDrvLinuxLdrDeregisterW
 }
 EXPORT_SYMBOL(SUPDrvLinuxLdrDeregisterWrappedModule);
 
+/**
+ * Wrapper function for cr4_update_irqsoff() which was
+ * exported only for KVM starting from kernel 6.19.
+ */
+static void supdrvLinux_cr4_update_irqsoff(unsigned long set, unsigned long clear)
+{
+#if RTLNX_VER_MIN(6,19,0) && defined(SUPDRV_LINUX_HAS_KVM_HWVIRT_API)
+    if (g_pfnCr4UpdateIrqsoff)
+        g_pfnCr4UpdateIrqsoff(set, clear);
+#else
+    cr4_update_irqsoff(set, clear);
+#endif
+}
+
+/**
+ * Wrapper function for supdrvLinux_cr4_read_shadow() which was
+ * exported only for KVM starting from kernel 6.19.
+ */
+static unsigned long supdrvLinux_cr4_read_shadow(void)
+{
+    unsigned long cr4 = 0;
+#if RTLNX_VER_MIN(6,19,0) && defined(SUPDRV_LINUX_HAS_KVM_HWVIRT_API)
+    if (g_pfnCr4ReadShadow)
+        cr4 = g_pfnCr4ReadShadow();
+#else
+    cr4 = cr4_read_shadow();
+#endif
+    return cr4;
+}
 
 #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
 RTCCUINTREG VBOXCALL supdrvOSChangeCR4(RTCCUINTREG fOrMask, RTCCUINTREG fAndMask)
@@ -1153,10 +1222,10 @@ RTCCUINTREG VBOXCALL supdrvOSChangeCR4(R
 # if RTLNX_VER_MIN(5,8,0)
     unsigned long fSavedFlags;
     local_irq_save(fSavedFlags);
-    RTCCUINTREG const uOld = cr4_read_shadow();
-    cr4_update_irqsoff(fOrMask, ~fAndMask); /* Same as this function, only it is not returning the old value. */
-    AssertMsg(cr4_read_shadow() == ((uOld & fAndMask) | fOrMask),
-              ("fOrMask=%#RTreg fAndMask=%#RTreg uOld=%#RTreg; new cr4=%#llx\n", fOrMask, fAndMask, uOld, cr4_read_shadow()));
+    RTCCUINTREG const uOld = supdrvLinux_cr4_read_shadow();
+    supdrvLinux_cr4_update_irqsoff(fOrMask, ~fAndMask); /* Same as this function, only it is not returning the old value. */
+    AssertMsg(supdrvLinux_cr4_read_shadow() == ((uOld & fAndMask) | fOrMask),
+              ("fOrMask=%#RTreg fAndMask=%#RTreg uOld=%#RTreg; new cr4=%#llx\n", fOrMask, fAndMask, uOld, supdrvLinux_cr4_read_shadow()));
     local_irq_restore(fSavedFlags);
 # else
 #  if RTLNX_VER_MIN(3,20,0)
--- a/src/VBox/Runtime/r0drv/linux/initterm-r0drv-linux.c
+++ b/src/VBox/Runtime/r0drv/linux/initterm-r0drv-linux.c
@@ -60,6 +60,11 @@ static DECLARE_TASK_QUEUE(g_rtR0LnxWorkQ
  * This is a special mm structure used to manage the kernel address space. */
 struct mm_struct *g_pLnxInitMm = NULL;
 
+#if RTLNX_VER_MIN(6,19,0)
+/** Pointer to __flush_tlb_all kernel symbol. */
+void (*g_pfnLinuxFlushTlbAll)(void);
+#endif
+
 
 /**
  * Pushes an item onto the IPRT work queue.
@@ -136,6 +141,11 @@ DECLHIDDEN(int) rtR0InitNative(void)
             printk("rtR0InitNative: g_pLnxInitMm=%p\n", g_pLnxInitMm);
 
             RTR0DbgKrnlInfoRelease(hKrnlInfo);
+# if RTLNX_VER_MIN(6,19,0)
+            g_pfnLinuxFlushTlbAll = __symbol_get("__flush_tlb_all");
+            if (!RT_VALID_PTR(g_pfnLinuxFlushTlbAll))
+                printk("rtR0InitNative: can't load __flush_tlb_all\n");
+# endif
         }
         else
             printk("rtR0InitNative: RTR0DbgKrnlInfoOpen failed: %d\n", rc);
@@ -151,6 +161,12 @@ DECLHIDDEN(void) rtR0TermNative(void)
 {
     IPRT_LINUX_SAVE_EFL_AC();
 
+# if RTLNX_VER_MIN(6,19,0)
+    if (RT_VALID_PTR(g_pfnLinuxFlushTlbAll))
+        symbol_put_addr(g_pfnLinuxFlushTlbAll);
+    g_pfnLinuxFlushTlbAll = NULL;
+#endif
+
     rtR0LnxWorkqueueFlush();
 #if RTLNX_VER_MIN(2,5,41)
     destroy_workqueue(g_prtR0LnxWorkQueue);
--- a/src/VBox/Runtime/r0drv/linux/memobj-r0drv-linux.c
+++ b/src/VBox/Runtime/r0drv/linux/memobj-r0drv-linux.c
@@ -181,7 +181,7 @@ static const struct
 *   Internal Functions                                                                                                           *
 *********************************************************************************************************************************/
 static void rtR0MemObjLinuxFreePages(PRTR0MEMOBJLNX pMemLnx);
-
+static void rtR0MemObjLinuxFlushTlbAll(void);
 
 
 /**
@@ -2108,6 +2108,15 @@ DECLHIDDEN(int) rtR0MemObjNativeMapUser(
     return rc;
 }
 
+static void rtR0MemObjLinuxFlushTlbAll(void)
+{
+#if RTLNX_VER_MIN(6,19,0)
+    if (RT_LIKELY(RT_VALID_PTR(g_pfnLinuxFlushTlbAll)))
+        g_pfnLinuxFlushTlbAll();
+#else
+    __flush_tlb_all();
+#endif
+}
 
 DECLHIDDEN(int) rtR0MemObjNativeProtect(PRTR0MEMOBJINTERNAL pMem, size_t offSub, size_t cbSub, uint32_t fProt)
 {
@@ -2128,7 +2137,7 @@ DECLHIDDEN(int) rtR0MemObjNativeProtect(
             set_pte(papPtes[i], mk_pte(pMemLnx->apPages[i], fPg));
         }
         preempt_disable();
-        __flush_tlb_all();
+        rtR0MemObjLinuxFlushTlbAll();
         preempt_enable();
         return VINF_SUCCESS;
     }
@@ -2174,7 +2183,7 @@ DECLHIDDEN(int) rtR0MemObjNativeProtect(
             flush_icache_range((uintptr_t)pMemLnx->Core.pv + offSub, cbSub);
 #  if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86) /* flush_tlb_kernel_range is not exported, but __flush_tlb_all is. */
         preempt_disable();
-        __flush_tlb_all();
+        rtR0MemObjLinuxFlushTlbAll();
         preempt_enable();
 #  else
         flush_tlb_kernel_range((uintptr_t)pMemLnx->Core.pv + offSub, cbSub);
--- a/src/VBox/Runtime/r0drv/linux/the-linux-kernel.h
+++ b/src/VBox/Runtime/r0drv/linux/the-linux-kernel.h
@@ -512,6 +512,9 @@ RTDECL(struct page *) rtR0MemObjLinuxVir
 
 
 extern struct mm_struct *g_pLnxInitMm;
+#if RTLNX_VER_MIN(6,19,0)
+extern void (*g_pfnLinuxFlushTlbAll)(void);
+#endif
 
 
 #endif /* !IPRT_INCLUDED_SRC_r0drv_linux_the_linux_kernel_h */