Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F140131874
D26166.id76121.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D26166.id76121.diff
View Options
Index: sys/amd64/amd64/initcpu.c
===================================================================
--- sys/amd64/amd64/initcpu.c
+++ sys/amd64/amd64/initcpu.c
@@ -42,6 +42,7 @@
#include <machine/cputypes.h>
#include <machine/md_var.h>
+#include <machine/psl.h>
#include <machine/specialreg.h>
#include <vm/vm.h>
@@ -218,11 +219,24 @@
}
/*
- * 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 from before the call until after
+ * consuming the call's return value.
*/
u_int
cpu_auxmsr(void)
{
+ /*
+ * Although disabling interrupts is, of course, not the only way to
+ * prevent CPU migration, since all existing callers happen to do
+ * this, make this the precedent for future callers until there is
+ * a reason to do otherwise.
+ */
+ KASSERT((read_rflags() & PSL_I) == 0,
+ ("cpu_auxmsr() returns a CPU-specific value; caller "
+ "should prevent migration until after consuming it."));
+
return (PCPU_GET(cpuid));
}
Index: sys/i386/i386/initcpu.c
===================================================================
--- sys/i386/i386/initcpu.c
+++ sys/i386/i386/initcpu.c
@@ -41,6 +41,7 @@
#include <machine/cputypes.h>
#include <machine/md_var.h>
+#include <machine/psl.h>
#include <machine/specialreg.h>
#include <vm/vm.h>
@@ -628,11 +629,24 @@
#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 from before the call until after
+ * consuming the call's return value.
*/
u_int
cpu_auxmsr(void)
{
+ /*
+ * Although disabling interrupts is, of course, not the only way to
+ * prevent CPU migration, since all existing callers happen to do
+ * this, make this the precedent for future callers until there is
+ * a reason to do otherwise.
+ */
+ KASSERT((read_eflags() & PSL_I) == 0,
+ ("cpu_auxmsr() returns a CPU-specific value; caller "
+ "should prevent migration until after consuming it."));
+
return (PCPU_GET(cpuid));
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 21, 4:21 PM (2 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27115745
Default Alt Text
D26166.id76121.diff (2 KB)
Attached To
Mode
D26166: cpu_auxmsr: assert caller is preventing CPU migration
Attached
Detach File
Event Timeline
Log In to Comment