Author: grehan
Date: Mon Aug 24 11:49:49 2020
New Revision: 364656
URL: https://svnweb.freebsd.org/changeset/base/364656

Log:
  cpu_auxmsr: assert caller is preventing CPU migration.
  
  Submitted by: Adam Fenn (adam at fenn dot io)
  Requested by: kib
  Reviewed by:  kib, grehan
  Approved by:  kib
  MFC after:    3 weeks
  Differential Revision:        https://reviews.freebsd.org/D26166

Modified:
  head/sys/amd64/amd64/initcpu.c
  head/sys/i386/i386/initcpu.c

Modified: head/sys/amd64/amd64/initcpu.c
==============================================================================
--- head/sys/amd64/amd64/initcpu.c      Mon Aug 24 11:44:20 2020        
(r364655)
+++ head/sys/amd64/amd64/initcpu.c      Mon Aug 24 11:49:49 2020        
(r364656)
@@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$");
 
 #include <machine/cputypes.h>
 #include <machine/md_var.h>
+#include <machine/psl.h>
 #include <machine/specialreg.h>
 
 #include <vm/vm.h>
@@ -218,11 +219,14 @@ init_via(void)
 }
 
 /*
- * The value for the TSC_AUX MSR and rdtscp/rdpid.
+ * The value for the TSC_AUX MSR and rdtscp/rdpid on the invoking CPU.
+ *
+ * Caller should prevent CPU migration.
  */
 u_int
 cpu_auxmsr(void)
 {
+       KASSERT((read_rflags() & PSL_I) == 0, ("context switch possible"));
        return (PCPU_GET(cpuid));
 }
 

Modified: head/sys/i386/i386/initcpu.c
==============================================================================
--- head/sys/i386/i386/initcpu.c        Mon Aug 24 11:44:20 2020        
(r364655)
+++ head/sys/i386/i386/initcpu.c        Mon Aug 24 11:49:49 2020        
(r364656)
@@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$");
 
 #include <machine/cputypes.h>
 #include <machine/md_var.h>
+#include <machine/psl.h>
 #include <machine/specialreg.h>
 
 #include <vm/vm.h>
@@ -628,11 +629,14 @@ init_transmeta(void)
 #endif
 
 /*
- * The value for the TSC_AUX MSR and rdtscp/rdpid.
+ * The value for the TSC_AUX MSR and rdtscp/rdpid on the invoking CPU.
+ *
+ * Caller should prevent CPU migration.
  */
 u_int
 cpu_auxmsr(void)
 {
+       KASSERT((read_eflags() & PSL_I) == 0, ("context switch possible"));
        return (PCPU_GET(cpuid));
 }
 
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to