Module Name:    src
Committed By:   riastradh
Date:           Sun Dec 19 01:45:38 UTC 2021

Modified Files:
        src/sys/external/bsd/drm2/include/linux: nospec.h

Log Message:
Fix mistake in array_index_nospec.

j must be constrained to be in the same register on input or output;
otherwise the compiler may put them in different places, expect the
asm code to write to the output register, and read garbage from the
output register when we fail to put anything there.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/external/bsd/drm2/include/linux/nospec.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/drm2/include/linux/nospec.h
diff -u src/sys/external/bsd/drm2/include/linux/nospec.h:1.2 src/sys/external/bsd/drm2/include/linux/nospec.h:1.3
--- src/sys/external/bsd/drm2/include/linux/nospec.h:1.2	Sun Dec 19 01:44:02 2021
+++ src/sys/external/bsd/drm2/include/linux/nospec.h	Sun Dec 19 01:45:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: nospec.h,v 1.2 2021/12/19 01:44:02 riastradh Exp $	*/
+/*	$NetBSD: nospec.h,v 1.3 2021/12/19 01:45:38 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -53,7 +53,7 @@ array_index_nospec(size_t i, size_t n)
 	 * reading from and writing to j but actually does nothing.
 	 */
 	j = i;
-	asm volatile ("" : "=r"(j) : "r"(j));
+	asm volatile ("" : "=r"(j) : "0"(j));
 
 	/* If i >= n, then diff has the high bit set; otherwise clear.  */
 	diff = n - 1 - j;

Reply via email to