2 * Copyright (c) 2003 Peter Wemm.
3 * Copyright (c) 1993 The Regents of the University of California.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <machine/asmacros.h>
36 #include <machine/specialreg.h>
37 #include <machine/pmap.h>
46 movq $PAGE_SIZE/8,%rcx
65 * pagecopy(%rdi=from, %rsi=to)
69 movq $PAGE_SIZE/8,%rcx
87 * The loop takes 29 bytes. Ensure that it doesn't cross a 32-byte
92 movnti %rax,(%rdi,%rdx)
93 movnti %rax,8(%rdi,%rdx)
94 movnti %rax,16(%rdi,%rdx)
95 movnti %rax,24(%rdi,%rdx)
104 * memcmpy(b1, b2, len)
116 movzbl (%rdi,%rcx,1),%eax
117 movzbl (%rsi,%rcx,1),%r8d
123 movzbl (%rdi,%rcx,1),%eax
124 movzbl (%rsi,%rcx,1),%r8d
130 movzbl (%rdi,%rcx,1),%eax
131 movzbl (%rsi,%rcx,1),%r8d
137 movzbl (%rdi,%rcx,1),%eax
138 movzbl (%rsi,%rcx,1),%r8d
198 * memmove(dst, src, cnt)
200 * Adapted from bcopy written by:
201 * ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
205 * Register state at entry is supposed to be as follows:
210 * The macro possibly clobbers the above and: rcx, r8.
211 * It does not clobber rax, r10 nor r11.
213 .macro MEMMOVE erms overlap begin end
218 cmpq %rcx,%r8 /* overlapping && src < dst? */
300 shrq $3,%rcx /* copy by 64-bit words */
304 andb $7,%cl /* any bytes left? */
399 andq $7,%rcx /* any fractional bytes? */
404 movq %rdx,%rcx /* copy remainder by 32-bit words */
428 MEMMOVE erms=0 overlap=1 begin=MEMMOVE_BEGIN end=MEMMOVE_END
432 MEMMOVE erms=1 overlap=1 begin=MEMMOVE_BEGIN end=MEMMOVE_END
436 * memcpy(dst, src, len)
439 * Note: memcpy does not support overlapping copies
442 MEMMOVE erms=0 overlap=0 begin=MEMMOVE_BEGIN end=MEMMOVE_END
446 MEMMOVE erms=1 overlap=0 begin=MEMMOVE_BEGIN end=MEMMOVE_END
450 * memset(dst, c, len)
458 movabs $0x0101010101010101,%rax
541 /* fillw(pat, base, cnt) */
542 /* %rdi,%rsi, %rdx */
554 /*****************************************************************************/
555 /* copyout and fubyte family */
556 /*****************************************************************************/
558 * Access user memory from inside the kernel. These routines should be
559 * the only places that do this.
561 * These routines set curpcb->pcb_onfault for the time they execute. When a
562 * protection violation occurs inside the functions, the trap handler
563 * returns to *curpcb->pcb_onfault instead of the function.
566 .macro SMAP_DISABLE smap
573 .macro SMAP_ENABLE smap
579 .macro COPYINOUT_BEGIN
583 movq %rax,PCB_ONFAULT(%r11)
587 .macro COPYINOUT_SMAP_END
593 * copyout(from_kernel, to_user, len)
596 .macro COPYOUT smap erms
598 movq PCPU(CURPCB),%r11
599 movq $copy_fault,PCB_ONFAULT(%r11)
602 * Check explicitly for non-user addresses. If 486 write protection
603 * is being used, this check is essential because we are in kernel
604 * mode so the h/w does not provide any protection against writing
609 * First, prevent address wrapping.
615 * XXX STOP USING VM_MAXUSER_ADDRESS.
616 * It is an end address, not a max, so every time it is used correctly it
617 * looks like there is an off by one error, and of course it caused an off
618 * by one error in several places.
620 movq $VM_MAXUSER_ADDRESS,%rcx
625 * Set return value to zero. Remaining failure mode goes through
631 * Set up arguments for MEMMOVE.
641 MEMMOVE erms=\erms overlap=0 begin=COPYINOUT_BEGIN end=COPYINOUT_SMAP_END
643 MEMMOVE erms=\erms overlap=0 begin=COPYINOUT_BEGIN end=COPYINOUT_END
648 ENTRY(copyout_nosmap_std)
649 COPYOUT smap=0 erms=0
650 END(copyout_nosmap_std)
652 ENTRY(copyout_smap_std)
653 COPYOUT smap=1 erms=0
654 END(copyout_smap_std)
656 ENTRY(copyout_nosmap_erms)
657 COPYOUT smap=0 erms=1
658 END(copyout_nosmap_erms)
660 ENTRY(copyout_smap_erms)
661 COPYOUT smap=1 erms=1
662 END(copyout_smap_erms)
665 * copyin(from_user, to_kernel, len)
668 .macro COPYIN smap erms
670 movq PCPU(CURPCB),%r11
671 movq $copy_fault,PCB_ONFAULT(%r11)
674 * make sure address is valid
679 movq $VM_MAXUSER_ADDRESS,%rcx
692 MEMMOVE erms=\erms overlap=0 begin=COPYINOUT_BEGIN end=COPYINOUT_SMAP_END
694 MEMMOVE erms=\erms overlap=0 begin=COPYINOUT_BEGIN end=COPYINOUT_END
699 ENTRY(copyin_nosmap_std)
701 END(copyin_nosmap_std)
703 ENTRY(copyin_smap_std)
707 ENTRY(copyin_nosmap_erms)
709 END(copyin_nosmap_erms)
711 ENTRY(copyin_smap_erms)
713 END(copyin_smap_erms)
716 /* Trap entry clears PSL.AC */
718 movq $0,PCB_ONFAULT(%r11)
724 * casueword32. Compare and set user integer. Returns -1 on fault,
725 * 0 if access was successful. Old value is written to *oldp.
726 * dst = %rdi, old = %esi, oldp = %rdx, new = %ecx
728 ENTRY(casueword32_nosmap)
730 movq PCPU(CURPCB),%r8
731 movq $fusufault,PCB_ONFAULT(%r8)
733 movq $VM_MAXUSER_ADDRESS-4,%rax
734 cmpq %rax,%rdi /* verify address is valid */
737 movl %esi,%eax /* old */
741 cmpxchgl %ecx,(%rdi) /* new = %ecx */
744 * The old value is in %eax. If the store succeeded it will be the
745 * value we expected (old) from before the store, otherwise it will
746 * be the current value. Save %eax into %esi to prepare the return
751 movq %rax,PCB_ONFAULT(%r8)
754 * Access the oldp after the pcb_onfault is cleared, to correctly
755 * catch corrupted pointer.
757 movl %esi,(%rdx) /* oldp = %rdx */
760 END(casueword32_nosmap)
762 ENTRY(casueword32_smap)
764 movq PCPU(CURPCB),%r8
765 movq $fusufault,PCB_ONFAULT(%r8)
767 movq $VM_MAXUSER_ADDRESS-4,%rax
768 cmpq %rax,%rdi /* verify address is valid */
771 movl %esi,%eax /* old */
776 cmpxchgl %ecx,(%rdi) /* new = %ecx */
780 * The old value is in %eax. If the store succeeded it will be the
781 * value we expected (old) from before the store, otherwise it will
782 * be the current value. Save %eax into %esi to prepare the return
787 movq %rax,PCB_ONFAULT(%r8)
790 * Access the oldp after the pcb_onfault is cleared, to correctly
791 * catch corrupted pointer.
793 movl %esi,(%rdx) /* oldp = %rdx */
796 END(casueword32_smap)
799 * casueword. Compare and set user long. Returns -1 on fault,
800 * 0 if access was successful. Old value is written to *oldp.
801 * dst = %rdi, old = %rsi, oldp = %rdx, new = %rcx
803 ENTRY(casueword_nosmap)
805 movq PCPU(CURPCB),%r8
806 movq $fusufault,PCB_ONFAULT(%r8)
808 movq $VM_MAXUSER_ADDRESS-4,%rax
809 cmpq %rax,%rdi /* verify address is valid */
812 movq %rsi,%rax /* old */
816 cmpxchgq %rcx,(%rdi) /* new = %rcx */
819 * The old value is in %rax. If the store succeeded it will be the
820 * value we expected (old) from before the store, otherwise it will
821 * be the current value.
825 movq %rax,PCB_ONFAULT(%r8)
829 END(casueword_nosmap)
831 ENTRY(casueword_smap)
833 movq PCPU(CURPCB),%r8
834 movq $fusufault,PCB_ONFAULT(%r8)
836 movq $VM_MAXUSER_ADDRESS-4,%rax
837 cmpq %rax,%rdi /* verify address is valid */
840 movq %rsi,%rax /* old */
845 cmpxchgq %rcx,(%rdi) /* new = %rcx */
849 * The old value is in %rax. If the store succeeded it will be the
850 * value we expected (old) from before the store, otherwise it will
851 * be the current value.
855 movq %rax,PCB_ONFAULT(%r8)
862 * Fetch (load) a 64-bit word, a 32-bit word, a 16-bit word, or an 8-bit
863 * byte from user memory.
864 * addr = %rdi, valp = %rsi
867 ENTRY(fueword_nosmap)
869 movq PCPU(CURPCB),%rcx
870 movq $fusufault,PCB_ONFAULT(%rcx)
872 movq $VM_MAXUSER_ADDRESS-8,%rax
873 cmpq %rax,%rdi /* verify address is valid */
878 movq %rax,PCB_ONFAULT(%rcx)
886 movq PCPU(CURPCB),%rcx
887 movq $fusufault,PCB_ONFAULT(%rcx)
889 movq $VM_MAXUSER_ADDRESS-8,%rax
890 cmpq %rax,%rdi /* verify address is valid */
897 movq %rax,PCB_ONFAULT(%rcx)
903 ENTRY(fueword32_nosmap)
905 movq PCPU(CURPCB),%rcx
906 movq $fusufault,PCB_ONFAULT(%rcx)
908 movq $VM_MAXUSER_ADDRESS-4,%rax
909 cmpq %rax,%rdi /* verify address is valid */
914 movq %rax,PCB_ONFAULT(%rcx)
918 END(fueword32_nosmap)
920 ENTRY(fueword32_smap)
922 movq PCPU(CURPCB),%rcx
923 movq $fusufault,PCB_ONFAULT(%rcx)
925 movq $VM_MAXUSER_ADDRESS-4,%rax
926 cmpq %rax,%rdi /* verify address is valid */
933 movq %rax,PCB_ONFAULT(%rcx)
939 ENTRY(fuword16_nosmap)
941 movq PCPU(CURPCB),%rcx
942 movq $fusufault,PCB_ONFAULT(%rcx)
944 movq $VM_MAXUSER_ADDRESS-2,%rax
949 movq $0,PCB_ONFAULT(%rcx)
956 movq PCPU(CURPCB),%rcx
957 movq $fusufault,PCB_ONFAULT(%rcx)
959 movq $VM_MAXUSER_ADDRESS-2,%rax
966 movq $0,PCB_ONFAULT(%rcx)
973 movq PCPU(CURPCB),%rcx
974 movq $fusufault,PCB_ONFAULT(%rcx)
976 movq $VM_MAXUSER_ADDRESS-1,%rax
981 movq $0,PCB_ONFAULT(%rcx)
988 movq PCPU(CURPCB),%rcx
989 movq $fusufault,PCB_ONFAULT(%rcx)
991 movq $VM_MAXUSER_ADDRESS-1,%rax
998 movq $0,PCB_ONFAULT(%rcx)
1004 * Store a 64-bit word, a 32-bit word, a 16-bit word, or an 8-bit byte to
1006 * addr = %rdi, value = %rsi
1008 ENTRY(suword_nosmap)
1010 movq PCPU(CURPCB),%rcx
1011 movq $fusufault,PCB_ONFAULT(%rcx)
1013 movq $VM_MAXUSER_ADDRESS-8,%rax
1014 cmpq %rax,%rdi /* verify address validity */
1019 movq PCPU(CURPCB),%rcx
1020 movq %rax,PCB_ONFAULT(%rcx)
1027 movq PCPU(CURPCB),%rcx
1028 movq $fusufault,PCB_ONFAULT(%rcx)
1030 movq $VM_MAXUSER_ADDRESS-8,%rax
1031 cmpq %rax,%rdi /* verify address validity */
1038 movq PCPU(CURPCB),%rcx
1039 movq %rax,PCB_ONFAULT(%rcx)
1044 ENTRY(suword32_nosmap)
1046 movq PCPU(CURPCB),%rcx
1047 movq $fusufault,PCB_ONFAULT(%rcx)
1049 movq $VM_MAXUSER_ADDRESS-4,%rax
1050 cmpq %rax,%rdi /* verify address validity */
1055 movq PCPU(CURPCB),%rcx
1056 movq %rax,PCB_ONFAULT(%rcx)
1059 END(suword32_nosmap)
1061 ENTRY(suword32_smap)
1063 movq PCPU(CURPCB),%rcx
1064 movq $fusufault,PCB_ONFAULT(%rcx)
1066 movq $VM_MAXUSER_ADDRESS-4,%rax
1067 cmpq %rax,%rdi /* verify address validity */
1074 movq PCPU(CURPCB),%rcx
1075 movq %rax,PCB_ONFAULT(%rcx)
1080 ENTRY(suword16_nosmap)
1082 movq PCPU(CURPCB),%rcx
1083 movq $fusufault,PCB_ONFAULT(%rcx)
1085 movq $VM_MAXUSER_ADDRESS-2,%rax
1086 cmpq %rax,%rdi /* verify address validity */
1091 movq PCPU(CURPCB),%rcx /* restore trashed register */
1092 movq %rax,PCB_ONFAULT(%rcx)
1095 END(suword16_nosmap)
1097 ENTRY(suword16_smap)
1099 movq PCPU(CURPCB),%rcx
1100 movq $fusufault,PCB_ONFAULT(%rcx)
1102 movq $VM_MAXUSER_ADDRESS-2,%rax
1103 cmpq %rax,%rdi /* verify address validity */
1110 movq PCPU(CURPCB),%rcx /* restore trashed register */
1111 movq %rax,PCB_ONFAULT(%rcx)
1116 ENTRY(subyte_nosmap)
1118 movq PCPU(CURPCB),%rcx
1119 movq $fusufault,PCB_ONFAULT(%rcx)
1121 movq $VM_MAXUSER_ADDRESS-1,%rax
1122 cmpq %rax,%rdi /* verify address validity */
1128 movq PCPU(CURPCB),%rcx /* restore trashed register */
1129 movq %rax,PCB_ONFAULT(%rcx)
1136 movq PCPU(CURPCB),%rcx
1137 movq $fusufault,PCB_ONFAULT(%rcx)
1139 movq $VM_MAXUSER_ADDRESS-1,%rax
1140 cmpq %rax,%rdi /* verify address validity */
1148 movq PCPU(CURPCB),%rcx /* restore trashed register */
1149 movq %rax,PCB_ONFAULT(%rcx)
1155 /* Fault entry clears PSL.AC */
1157 movq PCPU(CURPCB),%rcx
1159 movq %rax,PCB_ONFAULT(%rcx)
1165 * copyinstr(from, to, maxlen, int *lencopied)
1166 * %rdi, %rsi, %rdx, %rcx
1168 * copy a string from 'from' to 'to', stop when a 0 character is reached.
1169 * return ENAMETOOLONG if string is longer than maxlen, and
1170 * EFAULT on protection violations. If lencopied is non-zero,
1171 * return the actual length in *lencopied.
1173 .macro COPYINSTR smap
1175 movq %rdx,%r8 /* %r8 = maxlen */
1176 movq PCPU(CURPCB),%r9
1177 movq $cpystrflt,PCB_ONFAULT(%r9)
1179 movq $VM_MAXUSER_ADDRESS,%rax
1181 /* make sure 'from' is within bounds */
1187 /* restrict maxlen to <= VM_MAXUSER_ADDRESS-from */
1195 jz copyinstr_toolong
1197 jz copyinstr_toolong_smap
1209 /* Success -- 0 byte reached */
1213 /* set *lencopied and return %eax */
1214 movq %rax,PCB_ONFAULT(%r9)
1231 ENTRY(copyinstr_nosmap)
1233 END(copyinstr_nosmap)
1235 ENTRY(copyinstr_smap)
1240 /* Fault entry clears PSL.AC */
1243 /* set *lencopied and return %eax */
1244 movq $0,PCB_ONFAULT(%r9)
1254 copyinstr_toolong_smap:
1257 /* rdx is zero - return ENAMETOOLONG or EFAULT */
1258 movq $VM_MAXUSER_ADDRESS,%rax
1261 movl $ENAMETOOLONG,%eax
1265 * copystr(from, to, maxlen, int *lencopied)
1266 * %rdi, %rsi, %rdx, %rcx
1270 movq %rdx,%r8 /* %r8 = maxlen */
1283 /* Success -- 0 byte reached */
1289 /* set *lencopied and return %rax */
1296 /* rdx is zero -- return ENAMETOOLONG */
1297 movl $ENAMETOOLONG,%eax
1302 * Handling of special amd64 registers and descriptor tables etc
1304 /* void lgdt(struct region_descriptor *rdp); */
1306 /* reload the descriptor table */
1309 /* flush the prefetch q */
1316 movl %eax,%fs /* Beware, use wrmsr to set 64 bit base */
1320 /* reload code selector by turning return into intersegmental return */
1328 /*****************************************************************************/
1329 /* setjump, longjump */
1330 /*****************************************************************************/
1333 movq %rbx,0(%rdi) /* save rbx */
1334 movq %rsp,8(%rdi) /* save rsp */
1335 movq %rbp,16(%rdi) /* save rbp */
1336 movq %r12,24(%rdi) /* save r12 */
1337 movq %r13,32(%rdi) /* save r13 */
1338 movq %r14,40(%rdi) /* save r14 */
1339 movq %r15,48(%rdi) /* save r15 */
1340 movq 0(%rsp),%rdx /* get rta */
1341 movq %rdx,56(%rdi) /* save rip */
1342 xorl %eax,%eax /* return(0); */
1347 movq 0(%rdi),%rbx /* restore rbx */
1348 movq 8(%rdi),%rsp /* restore rsp */
1349 movq 16(%rdi),%rbp /* restore rbp */
1350 movq 24(%rdi),%r12 /* restore r12 */
1351 movq 32(%rdi),%r13 /* restore r13 */
1352 movq 40(%rdi),%r14 /* restore r14 */
1353 movq 48(%rdi),%r15 /* restore r15 */
1354 movq 56(%rdi),%rdx /* get rta */
1355 movq %rdx,0(%rsp) /* put in return frame */
1356 xorl %eax,%eax /* return(1); */
1362 * Support for reading MSRs in the safe manner. (Instead of panic on #gp,
1366 /* int rdmsr_safe(u_int msr, uint64_t *data) */
1368 movq PCPU(CURPCB),%r8
1369 movq $msr_onfault,PCB_ONFAULT(%r8)
1371 rdmsr /* Read MSR pointed by %ecx. Returns
1372 hi byte in edx, lo in %eax */
1373 salq $32,%rdx /* sign-shift %rdx left */
1374 movl %eax,%eax /* zero-extend %eax -> %rax */
1378 movq %rax,PCB_ONFAULT(%r8)
1383 * Support for writing MSRs in the safe manner. (Instead of panic on #gp,
1387 /* int wrmsr_safe(u_int msr, uint64_t data) */
1389 movq PCPU(CURPCB),%r8
1390 movq $msr_onfault,PCB_ONFAULT(%r8)
1395 wrmsr /* Write MSR pointed by %ecx. Accepts
1396 hi byte in edx, lo in %eax. */
1398 movq %rax,PCB_ONFAULT(%r8)
1403 * MSR operations fault handler
1407 movq $0,PCB_ONFAULT(%r8)
1413 * void pmap_pti_pcid_invalidate(uint64_t ucr3, uint64_t kcr3);
1414 * Invalidates address space addressed by ucr3, then returns to kcr3.
1415 * Done in assembler to ensure no other memory accesses happen while
1419 ENTRY(pmap_pti_pcid_invalidate)
1422 movq %rdi,%cr3 /* to user page table */
1423 movq %rsi,%cr3 /* back to kernel */
1428 * void pmap_pti_pcid_invlpg(uint64_t ucr3, uint64_t kcr3, vm_offset_t va);
1429 * Invalidates virtual address va in address space ucr3, then returns to kcr3.
1432 ENTRY(pmap_pti_pcid_invlpg)
1435 movq %rdi,%cr3 /* to user page table */
1437 movq %rsi,%cr3 /* back to kernel */
1442 * void pmap_pti_pcid_invlrng(uint64_t ucr3, uint64_t kcr3, vm_offset_t sva,
1444 * Invalidates virtual addresses between sva and eva in address space ucr3,
1445 * then returns to kcr3.
1448 ENTRY(pmap_pti_pcid_invlrng)
1451 movq %rdi,%cr3 /* to user page table */
1453 addq $PAGE_SIZE,%rdx
1456 movq %rsi,%cr3 /* back to kernel */
1461 .macro ibrs_seq_label l
1464 .macro ibrs_call_label l
1467 .macro ibrs_seq count
1470 ibrs_call_label %(ll)
1472 ibrs_seq_label %(ll)
1478 /* all callers already saved %rax, %rdx, and %rcx */
1479 ENTRY(handle_ibrs_entry)
1480 cmpb $0,hw_ibrs_active(%rip)
1482 movl $MSR_IA32_SPEC_CTRL,%ecx
1484 orl $(IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP),%eax
1485 orl $(IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP)>>32,%edx
1487 movb $1,PCPU(IBPB_SET)
1488 testl $CPUID_STDEXT_SMEP,cpu_stdext_feature(%rip)
1492 END(handle_ibrs_entry)
1494 ENTRY(handle_ibrs_exit)
1495 cmpb $0,PCPU(IBPB_SET)
1497 movl $MSR_IA32_SPEC_CTRL,%ecx
1499 andl $~(IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP),%eax
1500 andl $~((IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP)>>32),%edx
1502 movb $0,PCPU(IBPB_SET)
1504 END(handle_ibrs_exit)
1506 /* registers-neutral version, but needs stack */
1507 ENTRY(handle_ibrs_exit_rs)
1508 cmpb $0,PCPU(IBPB_SET)
1513 movl $MSR_IA32_SPEC_CTRL,%ecx
1515 andl $~(IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP),%eax
1516 andl $~((IA32_SPEC_CTRL_IBRS|IA32_SPEC_CTRL_STIBP)>>32),%edx
1521 movb $0,PCPU(IBPB_SET)
1523 END(handle_ibrs_exit_rs)
1528 * Flush L1D cache. Load enough of the data from the kernel text
1529 * to flush existing L1D content.
1531 * N.B. The function does not follow ABI calling conventions, it corrupts %rbx.
1532 * The vmm.ko caller expects that only %rax, %rdx, %rbx, %rcx, %r9, and %rflags
1533 * registers are clobbered. The NMI handler caller only needs %r13 preserved.
1536 #define L1D_FLUSH_SIZE (64 * 1024)
1538 movq $-L1D_FLUSH_SIZE, %rcx
1540 * pass 1: Preload TLB.
1541 * Kernel text is mapped using superpages. TLB preload is
1542 * done for the benefit of older CPUs which split 2M page
1543 * into 4k TLB entries.
1545 1: movb L1D_FLUSH_SIZE(%r9, %rcx), %al
1546 addq $PAGE_SIZE, %rcx
1550 movq $-L1D_FLUSH_SIZE, %rcx
1551 /* pass 2: Read each cache line. */
1552 2: movb L1D_FLUSH_SIZE(%r9, %rcx), %al
1557 #undef L1D_FLUSH_SIZE