On an Intel CPU supporting VMX, KVM will emulate instructions while the CPU state remains "invalid". In real mode, the CPU state is defined to be "invalid" if any segment register has a base which is not equal to (sreg<<4) or a limit which is not equal to 64kB. We don't actually use the base stored in the REAL_DS descriptor for any significant purpose. Change the base stored in this descriptor to be equal to (REAL_DS<<4). A segment register loaded with REAL_DS is then automatically valid in both real and protected modes. This allows KVM to stop emulating instructions much sooner. The only use of REAL_DS for memory accesses currently occurs in the indirect ljmp within prot_to_real. Change this to a direct ljmp, storing rm_cs in .text16 as part of the ljmp instruction. This removes the only memory access via REAL_DS (thereby allowing for the above descriptor base address hack), and also simplifies the ljmp instruction (which will still have to be emulated). Load the real-mode interrupt descriptor table register before switching to real mode, since this avoids triggering an EXCEPTION_NMI and corresponding VM exit. This reduces the time taken by prot_to_real under KVM by around 65%. Signed-off-by: Michael Brown <mcb30@ipxe.org>tags/v1.20.1
|
|
||
| 165 |
|
165 |
|
| 166 |
|
166 |
|
| 167 |
|
167 |
|
| 168 |
|
|
|
| 169 |
|
|
|
|
168 |
|
|
|
169 |
|
|
| 170 |
|
170 |
|
| 171 |
|
171 |
|
| 172 |
|
172 |
|
|
|
||
| 72 |
|
72 |
|
| 73 |
|
73 |
|
| 74 |
|
74 |
|
| 75 |
|
|
|
|
75 |
|
|
| 76 |
|
76 |
|
| 77 |
|
77 |
|
| 78 |
|
78 |
|
|
|
||
| 111 |
|
111 |
|
| 112 |
|
112 |
|
| 113 |
|
113 |
|
| 114 |
|
|
|
|
114 |
|
|
| 115 |
|
115 |
|
| 116 |
|
116 |
|
| 117 |
|
117 |
|
| 118 |
|
118 |
|
| 119 |
|
119 |
|
| 120 |
|
120 |
|
| 121 |
|
|
|
|
121 |
|
|
| 122 |
|
122 |
|
| 123 |
|
123 |
|
| 124 |
|
124 |
|
| 125 |
|
125 |
|
| 126 |
|
|
|
| 127 |
|
|
|
| 128 |
|
126 |
|
| 129 |
|
127 |
|
| 130 |
|
128 |
|
|
|
||
| 241 |
|
239 |
|
| 242 |
|
240 |
|
| 243 |
|
241 |
|
| 244 |
|
|
|
|
242 |
|
|
| 245 |
|
243 |
|
| 246 |
|
244 |
|
| 247 |
|
245 |
|
|
|
||
| 287 |
|
285 |
|
| 288 |
|
286 |
|
| 289 |
|
287 |
|
|
288 |
|
|
|
289 |
|
|
|
290 |
|
|
| 290 |
|
291 |
|
| 291 |
|
292 |
|
| 292 |
|
293 |
|
|
|
||
| 302 |
|
303 |
|
| 303 |
|
304 |
|
| 304 |
|
305 |
|
| 305 |
|
|
|
| 306 |
|
|
|
| 307 |
|
|
|
|
306 |
|
|
|
307 |
|
|
|
308 |
|
|
| 308 |
|
309 |
|
| 309 |
|
310 |
|
| 310 |
|
311 |
|
|
|
||
| 314 |
|
315 |
|
| 315 |
|
316 |
|
| 316 |
|
317 |
|
| 317 |
|
|
|
| 318 |
|
|
|
| 319 |
|
|
|
| 320 |
|
318 |
|
| 321 |
|
319 |
|
| 322 |
|
320 |
|
| 323 |
|
321 |
|
| 324 |
|
322 |
|
| 325 |
|
323 |
|
| 326 |
|
|
|
| 327 |
|
|
|
| 328 |
|
|
|
|
324 |
|
|
|
325 |
|
|
|
326 |
|
|
|
327 |
|
|
|
328 |
|
|
| 329 |
|
329 |
|
| 330 |
|
|
|
| 331 |
|
|
|
| 332 |
|
|
|
| 333 |
|
330 |
|
| 334 |
|
|
|
| 335 |
|
|
|
|
331 |
|
|
|
332 |
|
|
| 336 |
|
333 |
|
|
334 |
|
|
| 337 |
|
335 |
|
| 338 |
|
336 |
|
| 339 |
|
337 |
|