From nobody Mon Nov 13 15:51:17 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 4STYnL0Ngdz51Bt3; Mon, 13 Nov 2023 15:51:18 +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 4STYnK6sQwz3Z1p; Mon, 13 Nov 2023 15:51:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1699890678; 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=42nRfY6oR/n7Df4me5t8nMRL9LvlXQ7MLmYljUQK0HE=; b=iratwd/KiR9mCpAzwbZYk2mdtfk3qegkWdnAEOggfLuKgyPL0sMvAhxxYUBqpXliCeaBS3 SFRY0yurq5z01pIrRYTGXMBGuOJ3u1zipb0mm2KUx/FF39/qdvnYLfeayv7LaH72G5V0FU yJnmFqJir5zNcjdeVAjGWHw+LsAGrBr2Xve6Jm5Q5bCZdBbPimVIxaFgJfDtlvGIYVYIrM 2XtziBbef2vFdWi1FK5Sh+oYDiSkkHc4PuXTnNfvT0JCZADowzHVd7EyqZDPO8Zt2mxyYh uRh3RHLGMCUCcZgEL1jByIFhQp5lRHkNpQzRcImDK8rI6oHEnUSsRzjss6e/UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1699890678; 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=42nRfY6oR/n7Df4me5t8nMRL9LvlXQ7MLmYljUQK0HE=; b=VXTASwIGtTobXjlIX1A6Sa41acZDuLafXsuYdf/Pn/n1BFPv6bG1WMVt3p7dV5v5wjGNpS wbMsvZgAcyqqply8LTUC+V0ip6AdV2KXo7g0guHPMS44z+nunQWMoYqYwRIOTFopKxcN6U iKQMRmyb5iuydGZ8tFp+IKdsxJtcgrs7b6tO3PcZIVXwgcc7aJ7jpYFiUfrJ2jufr+bwvF Yp+P0n5pfx3tYaiSxGVSgW3UuF/VR9PPK6fhHCfzWwSbrlu5BCoWrWS+S3RMzOjFYpDH5W 2M9hRSaJ2Q8sVjjHkiMdZEJHQ0yJbFdhh0z7swxJJ32JJqDO/SGD+lauhwo8Og== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1699890678; a=rsa-sha256; cv=none; b=xaC8LyQwxK2aEcvYm1xgSjDpiIa3NCCwFval4uzv2PmrPsK1AGzEgqyesoUM0B+a563/d/ XnkkjU3KgKHA8zcIoKwFikQIIK6tomPQwwaWqFt8/RsL8vkhOAWT/VMweVETy8IqJGzWdw WghZIPdPexa59yvD+5N8V+KbRB7nx3pojaFMfO7R+/3y8pOVA0iQR1Xf8Ax+B/quFM1382 Q9GjihaWhcZyHANeF3psVlWSJs2L8xmHU71vvLGy276chH17mQESRnVKmsm95FcJ0OduOR B55gWKT9yiXIDnttaXP29Oc3BSP4cHjrOtFBITmbRG4p7nUeS6i2fXdKwhgoiA== 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 4STYnK5y5Bz19mH; Mon, 13 Nov 2023 15:51:17 +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 3ADFpHKZ004263; Mon, 13 Nov 2023 15:51:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3ADFpHhg004260; Mon, 13 Nov 2023 15:51:17 GMT (envelope-from git) Date: Mon, 13 Nov 2023 15:51:17 GMT Message-Id: <202311131551.3ADFpHhg004260@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: b9c0003f0fa3 - main - 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/main X-Git-Reftype: branch X-Git-Commit: b9c0003f0fa39ead4bb3953b9118ae6f08e560f8 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=b9c0003f0fa39ead4bb3953b9118ae6f08e560f8 commit b9c0003f0fa39ead4bb3953b9118ae6f08e560f8 Author: Mark Johnston AuthorDate: 2023-11-13 15:44:45 +0000 Commit: Mark Johnston CommitDate: 2023-11-13 15:44:45 +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 --- 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 d55a21e9c55e..d77963d42461 100644 --- a/sys/arm64/arm64/locore.S +++ b/sys/arm64/arm64/locore.S @@ -247,6 +247,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);