svn commit: r339321 - in head/sys: amd64/include conf kern sys x86/x86 x86/xen

Mateusz Guzik mjg at FreeBSD.org
Thu Oct 11 23:28:06 UTC 2018


Author: mjg
Date: Thu Oct 11 23:28:04 2018
New Revision: 339321
URL: https://svnweb.freebsd.org/changeset/base/339321

Log:
  Provide string functions for use before ifuncs get resolved.
  
  The change is a no-op for architectures which don't ifunc memset,
  memcpy nor memmove.
  
  Convert places which need them. Xen bits by royger.
  
  Reviewed by:	kib
  Approved by:	re (gjb)
  Sponsored by:	The FreeBSD Foundation
  Differential Revision:	https://reviews.freebsd.org/D17487

Modified:
  head/sys/amd64/include/cpu.h
  head/sys/conf/files
  head/sys/kern/link_elf.c
  head/sys/sys/systm.h
  head/sys/x86/x86/ucode.c
  head/sys/x86/xen/pv.c

Modified: head/sys/amd64/include/cpu.h
==============================================================================
--- head/sys/amd64/include/cpu.h	Thu Oct 11 23:25:14 2018	(r339320)
+++ head/sys/amd64/include/cpu.h	Thu Oct 11 23:28:04 2018	(r339321)
@@ -92,6 +92,10 @@ get_cyclecount(void)
 	return (rdtsc());
 }
 
+#define MEMSET_EARLY_FUNC       memset_std
+#define MEMCPY_EARLY_FUNC       memcpy_std
+#define MEMMOVE_EARLY_FUNC      memmove_std
+
 #endif
 
 #endif /* !_MACHINE_CPU_H_ */

Modified: head/sys/conf/files
==============================================================================
--- head/sys/conf/files	Thu Oct 11 23:25:14 2018	(r339320)
+++ head/sys/conf/files	Thu Oct 11 23:28:04 2018	(r339321)
@@ -3876,6 +3876,7 @@ kern/subr_compressor.c		standard \
 kern/subr_counter.c		standard
 kern/subr_devstat.c		standard
 kern/subr_disk.c		standard
+kern/subr_early.c		standard
 kern/subr_epoch.c		standard
 kern/subr_eventhandler.c	standard
 kern/subr_fattime.c		standard

Modified: head/sys/kern/link_elf.c
==============================================================================
--- head/sys/kern/link_elf.c	Thu Oct 11 23:25:14 2018	(r339320)
+++ head/sys/kern/link_elf.c	Thu Oct 11 23:28:04 2018	(r339321)
@@ -1682,14 +1682,10 @@ link_elf_ireloc(caddr_t kmdp)
 {
 	struct elf_file eff;
 	elf_file_t ef;
-	volatile char *c;
-	size_t i;
 
 	ef = &eff;
 
-	/* Do not use bzero/memset before ireloc is done. */
-	for (c = (char *)ef, i = 0; i < sizeof(*ef); i++)
-		c[i] = 0;
+	bzero_early(ef, sizeof(*ef));
 
 	ef->modptr = kmdp;
 	ef->dynamic = (Elf_Dyn *)&_DYNAMIC;

Modified: head/sys/sys/systm.h
==============================================================================
--- head/sys/sys/systm.h	Thu Oct 11 23:25:14 2018	(r339320)
+++ head/sys/sys/systm.h	Thu Oct 11 23:28:04 2018	(r339321)
@@ -324,6 +324,12 @@ void	*memmove(void * _Nonnull dest, const void * _Nonn
 int	memcmp(const void *b1, const void *b2, size_t len);
 #define memcmp(b1, b2, len) __builtin_memcmp((b1), (b2), (len))
 
+void	*memset_early(void * _Nonnull buf, int c, size_t len);
+#define bzero_early(buf, len) memset_early((buf), 0, (len))
+void	*memcpy_early(void * _Nonnull to, const void * _Nonnull from, size_t len);
+void	*memmove_early(void * _Nonnull dest, const void * _Nonnull src, size_t n);
+#define bcopy_early(from, to, len) memmove_early((to), (from), (len))
+
 int	copystr(const void * _Nonnull __restrict kfaddr,
 	    void * _Nonnull __restrict kdaddr, size_t len,
 	    size_t * __restrict lencopied);

Modified: head/sys/x86/x86/ucode.c
==============================================================================
--- head/sys/x86/x86/ucode.c	Thu Oct 11 23:25:14 2018	(r339320)
+++ head/sys/x86/x86/ucode.c	Thu Oct 11 23:28:04 2018	(r339321)
@@ -355,8 +355,7 @@ ucode_load_bsp(uintptr_t free)
 		if (match != NULL) {
 			addr = map_ucode(free, len);
 			/* We can't use memcpy() before ifunc resolution. */
-			for (i = 0; i < len; i++)
-				addr[i] = ((volatile uint8_t *)match)[i];
+			memcpy_early(addr, match, len);
 			match = addr;
 
 			error = ucode_loader->load(match, false, &nrev, &orev);

Modified: head/sys/x86/xen/pv.c
==============================================================================
--- head/sys/x86/xen/pv.c	Thu Oct 11 23:25:14 2018	(r339320)
+++ head/sys/x86/xen/pv.c	Thu Oct 11 23:28:04 2018	(r339321)
@@ -259,7 +259,7 @@ hammer_time_xen_legacy(start_info_t *si, uint64_t xens
 	 */
 	kenv = (void *)(physfree + KERNBASE);
 	physfree += PAGE_SIZE;
-	bzero(kenv, PAGE_SIZE);
+	bzero_early(kenv, PAGE_SIZE);
 	init_static_kenv(kenv, PAGE_SIZE);
 
 	/* Set the hooks for early functions that diverge from bare metal */
@@ -320,7 +320,7 @@ hammer_time_xen(vm_paddr_t start_info_paddr)
 	 */
 	kenv = (void *)(physfree + KERNBASE);
 	physfree += PAGE_SIZE;
-	bzero(kenv, PAGE_SIZE);
+	bzero_early(kenv, PAGE_SIZE);
 	init_static_kenv(kenv, PAGE_SIZE);
 
 	if (start_info->modlist_paddr != 0) {


More information about the svn-src-head mailing list