From nobody Wed Dec 17 18:01:30 2025 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66570DF60 for ; Sat, 14 Dec 2024 00:53:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734137591; cv=none; b=avCXhp4FoTjCakxtYfpadPveZgFUOhsFR4jh+ouXHueX8DodQB+XtjlZE8HWLCSjA6bp53mUARuHUgWG9YWADZWhjGw6SZQpr2WE21SbP/kHzYyGcTzli5G7svFNWiv+q7pj43L9EaXjQ9zmHrVfTkbWu7eOAZK+3VO/w9b/i/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734137591; c=relaxed/simple; bh=9VcI1y4DrqTHAqxzGhnqIkcAzN8r48f8mRzXZKwipic=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ocTWnStrzb3frzG1bbQtwAbcFwSubzT++DKH2wQeVGqr+743rxcSXLcCPEMVR0FPDI50aucohLkfKFWRB50iEDBmhD2QtV/j6U4C79rVbK6A3Wu7gx4qV5jKhdinemejkhGMumx2XAz8tPMhjg/ioqRRPiw2G6/dEMI8ABJ/kJU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=XZhzuWgi; arc=none smtp.client-ip=209.85.216.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="XZhzuWgi" Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-2ee989553c1so1951700a91.3 for ; Fri, 13 Dec 2024 16:53:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1734137589; x=1734742389; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HCYhLJZhR58ewaFrjgMGyGbHfnpNdzHm23IqgQZ/0wM=; b=XZhzuWgiWcMoHTc1oBI2ureLcOzeudbOg7Sl9c9eMJx03AbZgEc9ZyLe08aNBR/CRn gEUDvPZJ19Gx63EvcNB4tMIB5kZHkMfz6CO8+J0Ss3LsRL8cr6oFwiJ2dbXpFTHi7enT tGwu9cOXFQmAHinwhGahaSsENDbxIrwXf1/q4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734137589; x=1734742389; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HCYhLJZhR58ewaFrjgMGyGbHfnpNdzHm23IqgQZ/0wM=; b=GDRDrSHUCUEmDtbIAlLNXeRU1ijME/4dadft8SoaWDNUluf5ZkIngX8a3RjZq5y3pe y8Skn+MgBNy41LNdsyyDi8dML6NA7K44y0nrsMRg/6TUaWvFtIV7skzr+m/TDbzBCJfU o5NhLZIPMgawFRulUcFalOqLmkvLFvHd+xhKAPuLYnnJfbauJRyPCzw+4y777e+Aw1Gc wlPFP1W/4GJGMdhCuWJvCkVv/Rv/suhykRhIZYCAjnUp4IvTH19qs/fyGN1/K9pbxnWJ +u4x09pw90HQLPufS5FBI4/A/S1EjETIto2pjKREHnok3UM64DETIw+qX24wd7ORyvso 2GJw== X-Forwarded-Encrypted: i=1; AJvYcCVV1bz+YFGXXy9fUm0wfqkiHzHK1UhSs4p98zDPQsS2ymGNHUlEz9I0wANXaqu5loOK1ndeGZpre6zpPHc=@vger.kernel.org X-Gm-Message-State: AOJu0YzE2u39JMMdi+xkgP0Yo8BP9Qdqz3ougBX1LJ8M+GXoMhP2bh0g 0Aoigjq+rJThunmSTVfG3Pb6PVFUrrStR8YRxihUW1NSguE67r2Z0SRdSmMGFg== X-Gm-Gg: ASbGncvHu+B0UiaBxEkJjZHIBKrS+GqkUXOFglqbuRTbBYZO2KvHK8EvyXcip6UF+gY v1yWqb+4D8+Kl2rBebGL60DcHKE+AuqBdtLjfyxGWxPC4LdpjxWpLS9D5gL68+9PowhCdTltnDu qmGt1OxU/u3UAFMdalcUGUjhDV1zjReLzdLRFORAznXCWcTmSk52sTpdMYO3Rql9JRkUnuKgv5t j9Qefb7JLqgOwjctgy0IroI5c5hi2MxXnVERA36ijww1pL26pEKNWHFKL1x1u3c+tHK29pmZWmp X-Google-Smtp-Source: AGHT+IGyZAYcBNhvS6uotk+yKNrfDXGIRBKVBPzRwnHoQvCbP1TZ1iFVgP8Qo1WHFe4yMk8mfH9X9g== X-Received: by 2002:a17:90b:4d08:b0:2ee:ab10:c187 with SMTP id 98e67ed59e1d1-2f28fd6b5f3mr6479214a91.18.1734137588765; Fri, 13 Dec 2024 16:53:08 -0800 (PST) Received: from dianders.sjc.corp.google.com ([2620:15c:9d:2:ae86:44a5:253c:f9bf]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f142f9e186sm3788270a91.41.2024.12.13.16.53.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Dec 2024 16:53:08 -0800 (PST) From: Douglas Anderson To: Catalin Marinas , Will Deacon , Mark Rutland Cc: linux-arm-msm@vger.kernel.org, Jeffrey Hugo , Julius Werner , linux-arm-kernel@lists.infradead.org, Roxana Bradescu , Trilok Soni , bjorn.andersson@oss.qualcomm.com, Douglas Anderson , stable@vger.kernel.org, James Morse , linux-kernel@vger.kernel.org Subject: [PATCH v2 1/6] arm64: errata: Assume that unknown CPUs _are_ vulnerable to Spectre BHB Date: Fri, 13 Dec 2024 16:52:02 -0800 Message-ID: <20241213165201.v2.1.I2040fa004dafe196243f67ebcc647cbedbb516e6@changeid> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog In-Reply-To: <20241214005248.198803-1-dianders@chromium.org> References: <20241214005248.198803-1-dianders@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The code for detecting CPUs that are vulnerable to Spectre BHB was based on a hardcoded list of CPU IDs that were known to be affected. Unfortunately, the list mostly only contained the IDs of standard ARM cores. The IDs for many cores that are minor variants of the standard ARM cores (like many Qualcomm Kyro CPUs) weren't listed. This led the code to assume that those variants were not affected. Flip the code on its head and instead list CPU IDs for cores that are known to be _not_ affected. Now CPUs will be assumed vulnerable until added to the list saying that they're safe. As of right now, the only CPU IDs added to the "unaffected" list are ARM Cortex A35, A53, and A55. This list was created by looking at older cores listed in cputype.h that weren't listed in the "affected" list previously. Unfortunately, while this solution is better than what we had before, it's still an imperfect solution. Specifically there are two ways to mitigate Spectre BHB and one of those ways is parameterized with a "k" value indicating how many loops are needed to mitigate. If we have an unknown CPU ID then we've got to guess about how to mitigate it. Since more cores seem to be mitigated by looping (and because it's unlikely that the needed FW code will be in place for FW mitigation for unknown cores), we'll choose looping for unknown CPUs and choose the highest "k" value of 32. The downside of our guessing is that some CPUs may now report as "mitigated" when in reality they should need a firmware mitigation. We'll choose to put a WARN_ON splat in the logs in this case any time we had to make a guess since guessing the right mitigation is pretty awful. Hopefully this will encourage CPU vendors to add their CPU IDs to the list. Fixes: 558c303c9734 ("arm64: Mitigate spectre style branch history side cha= nnels") Cc: stable@vger.kernel.org Signed-off-by: Douglas Anderson --- Changes in v2: - New arch/arm64/kernel/proton-pack.c | 46 +++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kernel/proton-pack.c b/arch/arm64/kernel/proton-pac= k.c index da53722f95d4..39c5573c7527 100644 --- a/arch/arm64/kernel/proton-pack.c +++ b/arch/arm64/kernel/proton-pack.c @@ -841,13 +841,31 @@ enum bhb_mitigation_bits { }; static unsigned long system_bhb_mitigations; =20 +static const struct midr_range spectre_bhb_firmware_mitigated_list[] =3D { + MIDR_ALL_VERSIONS(MIDR_CORTEX_A73), + MIDR_ALL_VERSIONS(MIDR_CORTEX_A75), + {}, +}; + +static const struct midr_range spectre_bhb_safe_list[] =3D { + MIDR_ALL_VERSIONS(MIDR_CORTEX_A35), + MIDR_ALL_VERSIONS(MIDR_CORTEX_A53), + MIDR_ALL_VERSIONS(MIDR_CORTEX_A55), + {}, +}; + /* * This must be called with SCOPE_LOCAL_CPU for each type of CPU, before a= ny * SCOPE_SYSTEM call will give the right answer. + * + * NOTE: Unknown CPUs are reported as affected. In order to make this work + * and still keep the list short, only handle CPUs where: + * - supports_csv2p3() returned false + * - supports_clearbhb() returned false. */ u8 spectre_bhb_loop_affected(int scope) { - u8 k =3D 0; + u8 k; static u8 max_bhb_k; =20 if (scope =3D=3D SCOPE_LOCAL_CPU) { @@ -886,6 +904,16 @@ u8 spectre_bhb_loop_affected(int scope) k =3D 11; else if (is_midr_in_range_list(read_cpuid_id(), spectre_bhb_k8_list)) k =3D 8; + else if (is_midr_in_range_list(read_cpuid_id(), spectre_bhb_safe_list) || + is_midr_in_range_list(read_cpuid_id(), spectre_bhb_firmware_mitigated_= list)) + k =3D 0; + else { + WARN_ONCE(true, + "Unrecognized CPU %#010x, assuming Spectre BHB vulnerable\n", + read_cpuid_id()); + /* Hopefully k =3D 32 handles the worst case for unknown CPUs */ + k =3D 32; + } =20 max_bhb_k =3D max(max_bhb_k, k); } else { @@ -916,24 +944,26 @@ static enum mitigation_state spectre_bhb_get_cpu_fw_m= itigation_state(void) } } =20 +/* + * NOTE: Unknown CPUs are reported as affected. In order to make this work + * and still keep the list short, only handle CPUs where: + * - supports_csv2p3() returned false + * - supports_clearbhb() returned false. + * - spectre_bhb_loop_affected() returned 0. + */ static bool is_spectre_bhb_fw_affected(int scope) { static bool system_affected; enum mitigation_state fw_state; bool has_smccc =3D arm_smccc_1_1_get_conduit() !=3D SMCCC_CONDUIT_NONE; - static const struct midr_range spectre_bhb_firmware_mitigated_list[] =3D { - MIDR_ALL_VERSIONS(MIDR_CORTEX_A73), - MIDR_ALL_VERSIONS(MIDR_CORTEX_A75), - {}, - }; bool cpu_in_list =3D is_midr_in_range_list(read_cpuid_id(), - spectre_bhb_firmware_mitigated_list); + spectre_bhb_safe_list); =20 if (scope !=3D SCOPE_LOCAL_CPU) return system_affected; =20 fw_state =3D spectre_bhb_get_cpu_fw_mitigation_state(); - if (cpu_in_list || (has_smccc && fw_state =3D=3D SPECTRE_MITIGATED)) { + if (!cpu_in_list || (has_smccc && fw_state =3D=3D SPECTRE_MITIGATED)) { system_affected =3D true; return true; } --=20 2.47.1.613.gc27f4b7a9f-goog