From owner-svn-src-all@freebsd.org Thu Oct 11 23:28:06 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 11E1B10CB620; Thu, 11 Oct 2018 23:28:06 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id B963786FF5; Thu, 11 Oct 2018 23:28:05 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id AE381173E0; Thu, 11 Oct 2018 23:28:05 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w9BNS5EY099018; Thu, 11 Oct 2018 23:28:05 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w9BNS4Er099012; Thu, 11 Oct 2018 23:28:04 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201810112328.w9BNS4Er099012@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Thu, 11 Oct 2018 23:28:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r339321 - in head/sys: amd64/include conf kern sys x86/x86 x86/xen X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: in head/sys: amd64/include conf kern sys x86/x86 x86/xen X-SVN-Commit-Revision: 339321 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Oct 2018 23:28:06 -0000 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) {