From nobody Mon Nov 27 15:09:16 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Sf8BP00tlz52gYg; Mon, 27 Nov 2023 15:09:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Sf8BN6gTWz4HDg; Mon, 27 Nov 2023 15:09:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701097756; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=VPGVULjMXI1tRXngmy8hMpC463uVPN5lDhz8BBE5THc=; b=g56toM5klZY/UwvVsja5DBK/ffgQilOTetoWKTYDmekPkPxUvT/pl1XXWyLCYlU7K3l2+N x6i5suRTzGPV+H/fOy+kYyPliczXRJADbP/t+jOMDo/sHvu3/JyMZNuEDYCck30cgXkkSP xlITNUq+xCGgkbu4jPDfUC/2pJ4u7mRTGlBRJlboaR1M2xwR/rpvSQR7lF4uzr/8avpZm8 db9PwC0g5lqLIKyPP2AOInU/+s3q3fEnG7Mev8owidTtYM/R58XukePAC9GWMovoiDmTJY S5egCBDApQwIl0TSOXQUL+NnK/jMj2sidseBIjR2d7U0CpI0w1KnfsdQmm3XMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701097756; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=VPGVULjMXI1tRXngmy8hMpC463uVPN5lDhz8BBE5THc=; b=OZEjmIO2/M3xy1ytCk+6KxGKrnhcqEzc3ZGIizB5JR4Nta0Lx/8/jEo0ReCV7mw9fYzMwv YTVLJ9a7jpfFDUDfWotE0jS2ZX8mJkOawJDh0UJIYHIHIoy+OR6V2/aNxTuaiJ0wFnEKlZ +Bty8AmaNLEFgJtgpDuGzrmW2EAA7pPIkOlU5yhR+YqHc3m/nK9l7Cg53KERoMrIVNMmnf 4N/afCJ9/bFdiUurFNzGyPSFXrQ+GMK7sgpCuZAec/3qDqa6Uwmzna77JFHv97eGkAoLAF KobKj692iTCijI2D9IUo4U3u652rQRtD4rAP0l67Wt0R0q8irsyyr5leLiO+rA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1701097756; a=rsa-sha256; cv=none; b=xpM91l8Jgu1cK8WWW0Tkg8wC1zd0m2XwYXrOwBnQGUItO3jA9VtEqjKs/PExpqlnRqS9Z6 Ro5TvXLPRMa/+OfCcdO4o7tULw2yJ/RjsMkeaulhw7NoSi3E78KdtzMey/7eaadpjpWa4H G4b9piBviP4y+ZPeiHHQdsM3tFTyT10a0D6F34oJ5JfZyuuEcey3TH1nPWpYij7FLq2HwD mYNW9u3z1fB+RxuZEbmtWw+hj/reUzE/FR9Qod1RcLXjCl8oRVwIt0Y/SJpNTg2VXXPMy5 5EjDf/6y5e8glQSO8twuy7gAGtDrfJsaZIiz3tT6IBgyLCRhGKotvckjTV1u8A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Sf8BN5l3Hzjxs; Mon, 27 Nov 2023 15:09:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3ARF9GID063686; Mon, 27 Nov 2023 15:09:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3ARF9G5F063683; Mon, 27 Nov 2023 15:09:16 GMT (envelope-from git) Date: Mon, 27 Nov 2023 15:09:16 GMT Message-Id: <202311271509.3ARF9G5F063683@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 5a86ae15f071 - stable/14 - arm64: Initialize x18 for APs earlier during boot List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 5a86ae15f0719fc7e057a943c85ce3a4069ba1b0 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=5a86ae15f0719fc7e057a943c85ce3a4069ba1b0 commit 5a86ae15f0719fc7e057a943c85ce3a4069ba1b0 Author: Mark Johnston AuthorDate: 2023-11-13 15:44:45 +0000 Commit: Mark Johnston CommitDate: 2023-11-27 15:09:04 +0000 arm64: Initialize x18 for APs earlier during boot When KMSAN is configured, the instrumentation inserts calls to __msan_get_context_state() into all function prologues. The implementation dereferences curthread and thus assumes that x18 points to the PCPU area. This applies in particular to init_secondary(), which currently is responsible for initializing x18 for APs. Move initialization into locore to avoid this problem. No functional change intended. Reviewed by: kib, andrew MFC after: 2 weeks Sponsored by: Juniper Networks, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D42533 (cherry picked from commit b9c0003f0fa39ead4bb3953b9118ae6f08e560f8) --- sys/arm64/arm64/locore.S | 8 ++++++++ sys/arm64/arm64/mp_machdep.c | 14 +++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/sys/arm64/arm64/locore.S b/sys/arm64/arm64/locore.S index d3dfbdf8a76f..0da7eea8d982 100644 --- a/sys/arm64/arm64/locore.S +++ b/sys/arm64/arm64/locore.S @@ -244,6 +244,14 @@ mp_virtdone: dsb sy isb + /* + * Initialize the per-CPU pointer before calling into C code, for the + * benefit of kernel sanitizers. + */ + adrp x18, bootpcpu + ldr x18, [x18, :lo12:bootpcpu] + msr tpidr_el1, x18 + b init_secondary END(mpentry) #endif diff --git a/sys/arm64/arm64/mp_machdep.c b/sys/arm64/arm64/mp_machdep.c index 1c9bea2349de..5d598b4189a9 100644 --- a/sys/arm64/arm64/mp_machdep.c +++ b/sys/arm64/arm64/mp_machdep.c @@ -134,6 +134,9 @@ void init_secondary(uint64_t); /* Synchronize AP startup. */ static struct mtx ap_boot_mtx; +/* Used to initialize the PCPU ahead of calling init_secondary(). */ +void *bootpcpu; + /* Stacks for AP initialization, discarded once idle threads are started. */ void *bootstack; static void *bootstacks[MAXCPU]; @@ -225,15 +228,6 @@ init_secondary(uint64_t cpu) panic("MPIDR for this CPU is not in pcpu table"); } - pcpup = cpuid_to_pcpu[cpu]; - /* - * Set the pcpu pointer with a backup in tpidr_el1 to be - * loaded when entering the kernel from userland. - */ - __asm __volatile( - "mov x18, %0 \n" - "msr tpidr_el1, %0" :: "r"(pcpup)); - /* * Identify current CPU. This is necessary to setup * affinity registers and to provide support for @@ -242,6 +236,7 @@ init_secondary(uint64_t cpu) * We need this before signalling the CPU is ready to * let the boot CPU use the results. */ + pcpup = cpuid_to_pcpu[cpu]; pcpup->pc_midr = get_midr(); identify_cpu(cpu); @@ -555,6 +550,7 @@ start_cpu(u_int cpuid, uint64_t target_cpu, int domain, vm_paddr_t release_addr) pmap_disable_promotion((vm_offset_t)pcpup, size); pcpu_init(pcpup, cpuid, sizeof(struct pcpu)); pcpup->pc_mpidr = target_cpu & CPU_AFF_MASK; + bootpcpu = pcpup; dpcpu[cpuid - 1] = (void *)(pcpup + 1); dpcpu_init(dpcpu[cpuid - 1], cpuid);