From nobody Fri Sep 19 10:30:08 2025 X-Original-To: dev-commits-src-main@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 4cSpfn4BSZz67nZM; Fri, 19 Sep 2025 10:30:09 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cSpfm5hMZz3LS3; Fri, 19 Sep 2025 10:30:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758277808; 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=kHJSwOAJ88LQjt41wvmHZraJ5KeAMBZk8HyBFW7RWcw=; b=STiTNeGE4S+wUE6Q67E8x8k6cYI8aUCsnZFWILV5s3i6anIpOrZl6ORIgJdfUoK+ylZYRH A7CZ9JOzMPUxJt6I4LX/OPv2oidB6Vbs5GjbMEAlU4p/p5f/bT0PboWTPRz0H9MgkQjGns IE4jA+4DlriJQ3TMVDmD8cLIh2dXGdX1iKNU1msstNN/o8VqCIfxuoubxlFVkQCYnjoKfW BzVny56zbP72clu397oe9iLOjPB7NxjaUiR5H7EhjWNKIS09kG19AHN8nV6wVLRYMiCJan G+N//fmz8rwOIOQngJGmEhwwSgoUhFVFjAJnDYzdr4vrxgJRbo24iIk9U1MwJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758277808; 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=kHJSwOAJ88LQjt41wvmHZraJ5KeAMBZk8HyBFW7RWcw=; b=f2ppJJ6wlqMA1SLI9vx43le0yvCoor9+9qNxNWQVD5r7LBKMZik8J0tJFwzOz4+F8XGWmy wpSscSDdSfBrIfkP5UaVkLFZffFa4kGtMzVwoRCUGzWRgRKUKTN3UdpNtKCd/NdrBJOlZ1 aZdyPc93mVK/IyZ9ZkqTFb+TOTU/P83tW6WnLWKJh9E1p0nxD4XEbo56QK3yJYbO9nfEFs H9TrwnPrqc5HAGN0DGSU6mAIyhebJyp6mn3t3JUsuSoQ7xeYQdsJf2Sv6EJlkIt6Rc/VK8 MhmlAa7Rt6ITHqP9HlW7OBO3qlCFXhsirusdoF5co9MpZouedNF36gnT4CMspw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1758277808; a=rsa-sha256; cv=none; b=ySiqILDE4mRD6ScdaNd+a/bgHrsfbESYxUA32lAivLPtlCysjYK7K24R2XMuH5QNbEmIhm YTTbEAUymE/YKlF+HasI0uoTXJa6LMUJ33D8SmBGWuld8eEDPOZ20OJ51Z9/4R70iFMc4z pnsxdi6MJO2mneVlwN9xy3X1Z0Zs3N/4aVYfYgiek4pFtcyUEAjLpdoKIK/ayM67iqTy9Z yPsN2L3l4R1cfWXN6ywqHGGzdtRBONqq9kzNCqyVTY1brtXOHqAKx1etHNhtJy6OtbslN6 fa+t82SoV00eANtXhQaYxAlS6bhCVoVLHgozGV/6wWbOw8ZTkp0+oRRlEZ1qXQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4cSpfm4bnRztdt; Fri, 19 Sep 2025 10:30:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 58JAU8ON004515; Fri, 19 Sep 2025 10:30:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58JAU8DS004512; Fri, 19 Sep 2025 10:30:08 GMT (envelope-from git) Date: Fri, 19 Sep 2025 10:30:08 GMT Message-Id: <202509191030.58JAU8DS004512@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: 5e0e2565288f - main - arm64: Read the CPU feature tunables once List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5e0e2565288f3d1f1b4223d8bb53c7d70e0aa92c Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=5e0e2565288f3d1f1b4223d8bb53c7d70e0aa92c commit 5e0e2565288f3d1f1b4223d8bb53c7d70e0aa92c Author: Andrew Turner AuthorDate: 2025-09-19 10:05:47 +0000 Commit: Andrew Turner CommitDate: 2025-09-19 10:05:47 +0000 arm64: Read the CPU feature tunables once Rather than reading the CPU tunables each time we enable a feature just read them once on boot. Reading them early on non-boot CPUs causes issues where they try to allocate memory before the core is set up to do so. As they don't change it is safe to cache the state of them. Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D52578 --- sys/arm64/arm64/cpu_feat.c | 35 +++++++++++++++++++++++++---------- sys/arm64/include/cpu_feat.h | 3 +++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/sys/arm64/arm64/cpu_feat.c b/sys/arm64/arm64/cpu_feat.c index 0ffcdf2c9ed1..fb065ea463cf 100644 --- a/sys/arm64/arm64/cpu_feat.c +++ b/sys/arm64/arm64/cpu_feat.c @@ -54,6 +54,21 @@ enable_cpu_feat(uint32_t stage) SET_FOREACH(featp, cpu_feat_set) { feat = *featp; + /* Read any tunable the user may have set */ + if (stage == CPU_FEAT_EARLY_BOOT && PCPU_GET(cpuid) == 0) { + snprintf(tunable, sizeof(tunable), "hw.feat.%s", + feat->feat_name); + if (TUNABLE_BOOL_FETCH(tunable, &val)) { + if (val) { + feat->feat_flags |= + CPU_FEAT_USER_ENABLED; + } else { + feat->feat_flags |= + CPU_FEAT_USER_DISABLED; + } + } + } + /* Run the enablement code at the correct stage of boot */ if ((feat->feat_flags & CPU_FEAT_STAGE_MASK) != stage) continue; @@ -71,17 +86,17 @@ enable_cpu_feat(uint32_t stage) if (check_status == FEAT_ALWAYS_DISABLE) goto next; - snprintf(tunable, sizeof(tunable), "hw.feat.%s", - feat->feat_name); - if (TUNABLE_BOOL_FETCH(tunable, &val)) { - /* Is the feature disabled by the tunable? */ - if (!val) - goto next; - /* If enabled by the tunable then enable it */ - } else if (check_status == FEAT_DEFAULT_DISABLE) { - /* No tunable set and disabled by default */ + /* The user disabled the feature */ + if ((feat->feat_flags & CPU_FEAT_USER_DISABLED) != 0) + goto next; + + /* + * The feature was disabled by default and the user + * didn't enable it then skip. + */ + if (check_status == FEAT_DEFAULT_DISABLE && + (feat->feat_flags & CPU_FEAT_USER_ENABLED) == 0) goto next; - } /* * Check if the feature has any errata that may need a diff --git a/sys/arm64/include/cpu_feat.h b/sys/arm64/include/cpu_feat.h index 20c743a7e507..6a311d4000bb 100644 --- a/sys/arm64/include/cpu_feat.h +++ b/sys/arm64/include/cpu_feat.h @@ -73,6 +73,9 @@ typedef enum { #define CPU_FEAT_PER_CPU 0x00000000 #define CPU_FEAT_SYSTEM 0x00000010 +#define CPU_FEAT_USER_ENABLED 0x40000000 +#define CPU_FEAT_USER_DISABLED 0x80000000 + struct cpu_feat; typedef cpu_feat_en (cpu_feat_check)(const struct cpu_feat *, u_int);