Sun Jul 19 07:35:08 2020 UTC ()
Revert most of ad's movs/stos change. Instead do a lot simpler: declare
svs_quad_copy() used by SVS only, with no need for instrumentation, because
SVS is disabled when sanitizers are on.


(maxv)
diff -r1.63 -r1.64 src/sys/arch/amd64/amd64/cpufunc.S
diff -r1.51 -r1.52 src/sys/arch/amd64/include/frameasm.h
diff -r1.48 -r1.49 src/sys/arch/i386/i386/cpufunc.S
diff -r1.124 -r1.125 src/sys/arch/x86/include/pmap.h
diff -r1.38 -r1.39 src/sys/arch/x86/x86/svs.c

cvs diff -r1.63 -r1.64 src/sys/arch/amd64/amd64/cpufunc.S (expand / switch to unified diff)

--- src/sys/arch/amd64/amd64/cpufunc.S 2020/06/24 18:09:37 1.63
+++ src/sys/arch/amd64/amd64/cpufunc.S 2020/07/19 07:35:08 1.64
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: cpufunc.S,v 1.63 2020/06/24 18:09:37 maxv Exp $ */ 1/* $NetBSD: cpufunc.S,v 1.64 2020/07/19 07:35:08 maxv Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998, 2007, 2008, 2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998, 2007, 2008, 2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum, and by Andrew Doran. 8 * by Charles M. Hannum, and by Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -436,20 +436,23 @@ ENTRY(outw) @@ -436,20 +436,23 @@ ENTRY(outw)
436 movq %rdi, %rdx 436 movq %rdi, %rdx
437 movq %rsi, %rax 437 movq %rsi, %rax
438 outw %ax, %dx 438 outw %ax, %dx
439 ret 439 ret
440END(outw) 440END(outw)
441 441
442ENTRY(outl) 442ENTRY(outl)
443 movq %rdi, %rdx 443 movq %rdi, %rdx
444 movq %rsi, %rax 444 movq %rsi, %rax
445 outl %eax, %dx 445 outl %eax, %dx
446 ret 446 ret
447END(outl) 447END(outl)
448 448
449ENTRY(x86_movs) 449/*
 450 * Used by SVS only, to make an atomic but fast copy. Doesn't have
 451 * sanitizer instrumentation, but sanitizers disable SVS, so no problem.
 452 */
 453ENTRY(svs_quad_copy)
450 movq %rdx,%rcx 454 movq %rdx,%rcx
451 KMSAN_REP_STOS(8) 
452 rep 455 rep
453 movsq 456 movsq
454 ret 457 ret
455END(x86_movs) 458END(svs_quad_copy)

cvs diff -r1.51 -r1.52 src/sys/arch/amd64/include/frameasm.h (expand / switch to unified diff)

--- src/sys/arch/amd64/include/frameasm.h 2020/06/21 16:53:37 1.51
+++ src/sys/arch/amd64/include/frameasm.h 2020/07/19 07:35:08 1.52
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: frameasm.h,v 1.51 2020/06/21 16:53:37 bouyer Exp $ */ 1/* $NetBSD: frameasm.h,v 1.52 2020/07/19 07:35:08 maxv Exp $ */
2 2
3#ifndef _AMD64_MACHINE_FRAMEASM_H 3#ifndef _AMD64_MACHINE_FRAMEASM_H
4#define _AMD64_MACHINE_FRAMEASM_H 4#define _AMD64_MACHINE_FRAMEASM_H
5 5
6#ifdef _KERNEL_OPT 6#ifdef _KERNEL_OPT
7#include "opt_xen.h" 7#include "opt_xen.h"
8#include "opt_svs.h" 8#include "opt_svs.h"
9#include "opt_kcov.h" 9#include "opt_kcov.h"
10#include "opt_kmsan.h" 10#include "opt_kmsan.h"
11#endif 11#endif
12 12
13/* 13/*
14 * Macros to define pushing/popping frames for interrupts, traps 14 * Macros to define pushing/popping frames for interrupts, traps
@@ -266,53 +266,31 @@ @@ -266,53 +266,31 @@
266 pushq %r10 ; \ 266 pushq %r10 ; \
267 pushq %r11 ; \ 267 pushq %r11 ; \
268 movq $sz,%rdi ; \ 268 movq $sz,%rdi ; \
269 callq _C_LABEL(kmsan_init_ret); \ 269 callq _C_LABEL(kmsan_init_ret); \
270 popq %r11 ; \ 270 popq %r11 ; \
271 popq %r10 ; \ 271 popq %r10 ; \
272 popq %r9 ; \ 272 popq %r9 ; \
273 popq %r8 ; \ 273 popq %r8 ; \
274 popq %rdi ; \ 274 popq %rdi ; \
275 popq %rsi ; \ 275 popq %rsi ; \
276 popq %rdx ; \ 276 popq %rdx ; \
277 popq %rcx ; \ 277 popq %rcx ; \
278 popq %rax 278 popq %rax
279#define KMSAN_REP_STOS(scale) \ 
280 pushq %rax ; \ 
281 pushq %rcx ; \ 
282 pushq %rdx ; \ 
283 pushq %rsi ; \ 
284 pushq %rdi ; \ 
285 pushq %r8 ; \ 
286 pushq %r9 ; \ 
287 pushq %r10 ; \ 
288 pushq %r11 ; \ 
289 leaq (,%rcx,scale),%rsi ; \ 
290 callq _C_LABEL(__msan_instrument_asm_store); \ 
291 popq %r11 ; \ 
292 popq %r10 ; \ 
293 popq %r9 ; \ 
294 popq %r8 ; \ 
295 popq %rdi ; \ 
296 popq %rsi ; \ 
297 popq %rdx ; \ 
298 popq %rcx ; \ 
299 popq %rax 
300#else 279#else
301#define KMSAN_ENTER /* nothing */ 280#define KMSAN_ENTER /* nothing */
302#define KMSAN_LEAVE /* nothing */ 281#define KMSAN_LEAVE /* nothing */
303#define KMSAN_INIT_ARG(sz) /* nothing */ 282#define KMSAN_INIT_ARG(sz) /* nothing */
304#define KMSAN_INIT_RET(sz) /* nothing */ 283#define KMSAN_INIT_RET(sz) /* nothing */
305#define KMSAN_REP_STOS(scale) /* nothing */ 
306#endif 284#endif
307 285
308#ifdef KCOV 286#ifdef KCOV
309#define KCOV_DISABLE \ 287#define KCOV_DISABLE \
310 incl CPUVAR(IDEPTH) 288 incl CPUVAR(IDEPTH)
311#define KCOV_ENABLE \ 289#define KCOV_ENABLE \
312 decl CPUVAR(IDEPTH) 290 decl CPUVAR(IDEPTH)
313#else 291#else
314#define KCOV_DISABLE /* nothing */ 292#define KCOV_DISABLE /* nothing */
315#define KCOV_ENABLE /* nothing */ 293#define KCOV_ENABLE /* nothing */
316#endif 294#endif
317 295
318#define INTRENTRY \ 296#define INTRENTRY \

cvs diff -r1.48 -r1.49 src/sys/arch/i386/i386/cpufunc.S (expand / switch to unified diff)

--- src/sys/arch/i386/i386/cpufunc.S 2020/06/24 18:09:37 1.48
+++ src/sys/arch/i386/i386/cpufunc.S 2020/07/19 07:35:08 1.49
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: cpufunc.S,v 1.48 2020/06/24 18:09:37 maxv Exp $ */ 1/* $NetBSD: cpufunc.S,v 1.49 2020/07/19 07:35:08 maxv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1998, 2007, 2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998, 2007, 2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum, and by Andrew Doran. 8 * by Charles M. Hannum, and by Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -28,27 +28,27 @@ @@ -28,27 +28,27 @@
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32/* 32/*
33 * Functions to provide access to i386-specific instructions. 33 * Functions to provide access to i386-specific instructions.
34 * 34 *
35 * These are shared with NetBSD/xen. 35 * These are shared with NetBSD/xen.
36 */ 36 */
37 37
38#include <sys/errno.h> 38#include <sys/errno.h>
39 39
40#include <machine/asm.h> 40#include <machine/asm.h>
41__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.48 2020/06/24 18:09:37 maxv Exp $"); 41__KERNEL_RCSID(0, "$NetBSD: cpufunc.S,v 1.49 2020/07/19 07:35:08 maxv Exp $");
42 42
43#include "opt_xen.h" 43#include "opt_xen.h"
44 44
45#include <machine/specialreg.h> 45#include <machine/specialreg.h>
46#include <machine/segments.h> 46#include <machine/segments.h>
47 47
48#include "assym.h" 48#include "assym.h"
49 49
50ENTRY(x86_lfence) 50ENTRY(x86_lfence)
51 lock 51 lock
52 addl $0, -4(%esp) 52 addl $0, -4(%esp)
53 ret 53 ret
54END(x86_lfence) 54END(x86_lfence)
@@ -343,29 +343,13 @@ END(outb) @@ -343,29 +343,13 @@ END(outb)
343ENTRY(outw) 343ENTRY(outw)
344 movl 4(%esp), %edx 344 movl 4(%esp), %edx
345 movl 8(%esp), %eax 345 movl 8(%esp), %eax
346 outw %ax, %dx 346 outw %ax, %dx
347 ret 347 ret
348END(outw) 348END(outw)
349 349
350ENTRY(outl) 350ENTRY(outl)
351 movl 4(%esp), %edx 351 movl 4(%esp), %edx
352 movl 8(%esp), %eax 352 movl 8(%esp), %eax
353 outl %eax, %dx 353 outl %eax, %dx
354 ret 354 ret
355END(outl) 355END(outl)
356 
357ENTRY(x86_movs) 
358 pushl %ebp 
359 movl %esp,%ebp 
360 pushl %edi 
361 pushl %esi 
362 movl 8(%ebp),%edi 
363 movl 12(%ebp),%esi 
364 movl 16(%ebp),%ecx 
365 rep 
366 movsl 
367 popl %esi 
368 popl %edi 
369 leave 
370 ret 
371END(x86_movs) 

cvs diff -r1.124 -r1.125 src/sys/arch/x86/include/pmap.h (expand / switch to unified diff)

--- src/sys/arch/x86/include/pmap.h 2020/07/14 00:45:53 1.124
+++ src/sys/arch/x86/include/pmap.h 2020/07/19 07:35:08 1.125
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pmap.h,v 1.124 2020/07/14 00:45:53 yamaguchi Exp $ */ 1/* $NetBSD: pmap.h,v 1.125 2020/07/19 07:35:08 maxv Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1997 Charles D. Cranor and Washington University. 4 * Copyright (c) 1997 Charles D. Cranor and Washington University.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -602,18 +602,18 @@ extern vaddr_t pmap_direct_end; @@ -602,18 +602,18 @@ extern vaddr_t pmap_direct_end;
602#define PMAP_DIRECT_END pmap_direct_end 602#define PMAP_DIRECT_END pmap_direct_end
603 603
604#define PMAP_DIRECT_MAP(pa) ((vaddr_t)PMAP_DIRECT_BASE + (pa)) 604#define PMAP_DIRECT_MAP(pa) ((vaddr_t)PMAP_DIRECT_BASE + (pa))
605#define PMAP_DIRECT_UNMAP(va) ((paddr_t)(va) - PMAP_DIRECT_BASE) 605#define PMAP_DIRECT_UNMAP(va) ((paddr_t)(va) - PMAP_DIRECT_BASE)
606 606
607/* 607/*
608 * Alternate mapping hooks for pool pages. 608 * Alternate mapping hooks for pool pages.
609 */ 609 */
610#define PMAP_MAP_POOLPAGE(pa) PMAP_DIRECT_MAP((pa)) 610#define PMAP_MAP_POOLPAGE(pa) PMAP_DIRECT_MAP((pa))
611#define PMAP_UNMAP_POOLPAGE(va) PMAP_DIRECT_UNMAP((va)) 611#define PMAP_UNMAP_POOLPAGE(va) PMAP_DIRECT_UNMAP((va))
612 612
613#endif /* __HAVE_DIRECT_MAP */ 613#endif /* __HAVE_DIRECT_MAP */
614 614
615void x86_movs(void *, void *, long); 615void svs_quad_copy(void *, void *, long);
616 616
617#endif /* _KERNEL */ 617#endif /* _KERNEL */
618 618
619#endif /* _X86_PMAP_H_ */ 619#endif /* _X86_PMAP_H_ */

cvs diff -r1.38 -r1.39 src/sys/arch/x86/x86/svs.c (expand / switch to unified diff)

--- src/sys/arch/x86/x86/svs.c 2020/07/14 00:45:53 1.38
+++ src/sys/arch/x86/x86/svs.c 2020/07/19 07:35:08 1.39
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: svs.c,v 1.38 2020/07/14 00:45:53 yamaguchi Exp $ */ 1/* $NetBSD: svs.c,v 1.39 2020/07/19 07:35:08 maxv Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2018-2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 2018-2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Maxime Villard. 8 * by Maxime Villard.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: svs.c,v 1.38 2020/07/14 00:45:53 yamaguchi Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: svs.c,v 1.39 2020/07/19 07:35:08 maxv Exp $");
34 34
35#include "opt_svs.h" 35#include "opt_svs.h"
36#include "opt_user_ldt.h" 36#include "opt_user_ldt.h"
37 37
38#include <sys/param.h> 38#include <sys/param.h>
39#include <sys/systm.h> 39#include <sys/systm.h>
40#include <sys/proc.h> 40#include <sys/proc.h>
41#include <sys/cpu.h> 41#include <sys/cpu.h>
42#include <sys/kauth.h> 42#include <sys/kauth.h>
43#include <sys/sysctl.h> 43#include <sys/sysctl.h>
44#include <sys/xcall.h> 44#include <sys/xcall.h>
45#include <sys/reboot.h> 45#include <sys/reboot.h>
46 46
@@ -694,27 +694,27 @@ svs_pdir_switch(struct pmap *pmap) @@ -694,27 +694,27 @@ svs_pdir_switch(struct pmap *pmap)
694{ 694{
695 struct cpu_info *ci = curcpu(); 695 struct cpu_info *ci = curcpu();
696 struct svs_utls *utls; 696 struct svs_utls *utls;
697 697
698 KASSERT(kpreempt_disabled()); 698 KASSERT(kpreempt_disabled());
699 KASSERT(pmap != pmap_kernel()); 699 KASSERT(pmap != pmap_kernel());
700 700
701 /* Update the info in the UTLS page */ 701 /* Update the info in the UTLS page */
702 utls = (struct svs_utls *)ci->ci_svs_utls; 702 utls = (struct svs_utls *)ci->ci_svs_utls;
703 utls->kpdirpa = pmap_pdirpa(pmap, 0) | svs_pcid_kcr3; 703 utls->kpdirpa = pmap_pdirpa(pmap, 0) | svs_pcid_kcr3;
704 704
705 /* Copy user slots. */ 705 /* Copy user slots. */
706 mutex_enter(&ci->ci_svs_mtx); 706 mutex_enter(&ci->ci_svs_mtx);
707 x86_movs(ci->ci_svs_updir, pmap->pm_pdir, PDIR_SLOT_USERLIM); 707 svs_quad_copy(ci->ci_svs_updir, pmap->pm_pdir, PDIR_SLOT_USERLIM);
708 mutex_exit(&ci->ci_svs_mtx); 708 mutex_exit(&ci->ci_svs_mtx);
709 709
710 if (svs_pcid) { 710 if (svs_pcid) {
711 invpcid(INVPCID_CONTEXT, PMAP_PCID_USER, 0); 711 invpcid(INVPCID_CONTEXT, PMAP_PCID_USER, 0);
712 } 712 }
713} 713}
714 714
715static void 715static void
716svs_enable(void) 716svs_enable(void)
717{ 717{
718 svs_enabled = true; 718 svs_enabled = true;
719 719
720 x86_hotpatch(HP_NAME_SVS_ENTER, 0); 720 x86_hotpatch(HP_NAME_SVS_ENTER, 0);