Add Apple T2 NHI device links
Subsystems (11)
v2 cover Add Apple T2 NHI device links
This series adds a cached flag to detect Apple T2 systems, then uses it to create device links for the Thunderbolt NHI.
Changes in v2:
- Used a less generic name for has_t2_chip
- Used DMI instead of PCI for has_apple_t2_chip to avoid PCI problems
- Initialized ret in tb_apple_add_links
Link to v1:
https://lore.kernel.org/all/[email protected]/
Atharva Tiwari (2):
treewide: Add a flag to detect the Apple T2 chip
thunderbolt: Add device links for Apple T2 NHI
arch/x86/kernel/quirks.c | 105 ++++++++++++++++++ drivers/thunderbolt/tb.c | 51 ++++++++- include/linux/platform_data/x86/apple.h | 5 + security/integrity/platform_certs/load_uefi.c | 38 ++----- 4 files changed, 168 insertions(+), 31 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/2 treewide: Add a flag to detect the Apple T2 chip
Add a flag to detect Apple T2 chips on Intel Macs. Cache the result to avoid repeated checks. That will be used in upcoming patches.
--- arch/x86/kernel/quirks.c | 105 ++++++++++++++++++ include/linux/platform_data/x86/apple.h | 5 + security/integrity/platform_certs/load_uefi.c | 38 ++----- 3 files changed, 118 insertions(+), 30 deletions(-)
arch/x86/kernel/quirks.c +105 -0
@@ -664,8 +664,113 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2083, quirk_intel_purley_xeon_rasbool x86_apple_machine;EXPORT_SYMBOL (x86_apple_machine); +bool has_apple_t2_chip; +EXPORT_SYMBOL (has_apple_t2_chip); + +static const struct dmi_system_id apple_t2_devices[] = { + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"MacBookPro15,1" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"MacBookPro15,2" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"MacBookPro15,3" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"MacBookPro15,4" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"MacBookPro16,1" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"MacBookPro16,2" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"MacBookPro16,3" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"MacBookPro16,4" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"MacBookAir8,1" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"MacBookAir8,2" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"MacBookAir9,1" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Macmini8,1" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"MacPro7,1" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"iMac20,1" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"iMac20,2" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"iMacPro1,1" ), + }, + }, + { } +}; +void __init early_platform_quirks (void ) { x86_apple_machine =dmi_match (DMI_SYS_VENDOR ,"Apple Inc." ) ||dmi_match (DMI_SYS_VENDOR ,"Apple Computer, Inc." ); + + has_apple_t2_chip =dmi_check_system (apple_t2_devices); }
include/linux/platform_data/x86/apple.h +5 -0
@@ -6,8 +6,13 @@* x86_apple_machine - whether the machine is an x86 Apple Macintosh */ extern bool x86_apple_machine; +/** +* has_apple_t2_chip - whether the machine has the Apple T2 chip +*/ +extern bool has_apple_t2_chip;#else #define x86_apple_machine false +#define has_t2_chip false#endif #endif
security/integrity/platform_certs/load_uefi.c +8 -30
@@ -3,42 +3,16 @@#include <linux/kernel.h> #include <linux/sched.h> #include <linux/cred.h> -#include <linux/dmi.h> #include <linux/err.h> #include <linux/efi.h> #include <linux/slab.h> #include <linux/ima.h> +#include <linux/platform_data/x86/apple.h> #include <keys/asymmetric-type.h> #include <keys/system_keyring.h> #include "../integrity.h" #include "keyring_handler.h" -/* -* On T2 Macs reading the db and dbx efi variables to load UEFI Secure Boot -* certificates causes occurrence of a page fault in Apple's firmware and -* a crash disabling EFI runtime services. The following quirk skips reading -* these variables. -*/ -static const struct dmi_system_id uefi_skip_cert[] = { - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacBookPro15,1" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacBookPro15,2" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacBookPro15,3" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacBookPro15,4" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacBookPro16,1" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacBookPro16,2" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacBookPro16,3" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacBookPro16,4" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacBookAir8,1" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacBookAir8,2" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacBookAir9,1" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"Macmini8,1" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacPro7,1" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"iMac20,1" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"iMac20,2" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"iMacPro1,1" ) }, - { } -}; -/* * Look to see if a UEFI variable called MokIgnoreDB exists and return true if * it does.
@@ -165,10 +139,14 @@ static int __init load_uefi_certs(void)unsigned long dbsize =0 , dbxsize =0 , mokxsize =0 ;efi_status_t status;int rc =0 ; -const struct dmi_system_id *dmi_id; - dmi_id =dmi_first_match (uefi_skip_cert); -if (dmi_id) { +/* +* On T2 Macs reading the db and dbx efi variables to load UEFI Secure Boot +* certificates causes occurrence of a page fault in Apple's firmware and +* a crash disabling EFI runtime services. The following quirk skips reading +* these variables. +*/ +if (has_apple_t2_chip) {pr_err ("Reading UEFI Secure Boot Certs is not supported on T2 Macs.\n" );return false; }
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v2 1/2] treewide: Add a flag to detect the Apple T2 chip
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Low] Build failure on non-x86 architectures due to an undeclared identifier in the fallback macro.…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Low] Build failure on non-x86 architectures due to an undeclared identifier in the fallback macro.
- [Low] The apple_t2_devices DMI match table wastes memory because it lacks the __initconst attribute.
- [Low] Leftover UEFI_QUIRK_SKIP_CERT macro is completely unused after removing the DMI table in load_uefi.c. --
--- Patch [1]: [PATCH v2 1/2] treewide: Add a flag to detect the Apple T2 chip --- commit 7dbd2538a2e2da67cae6a20bc7aa3350603d9016
Author: Atharva Tiwari <[email protected]>
treewide: Add a flag to detect the Apple T2 chip
This commit adds a flag to detect Apple T2 chips on Intel Macs and caches the result to avoid repeated checks. It introduces a DMI match table in x86 quirks and updates UEFI certificate loading code to use this new cached flag.
Quoted 4 lines
arch/x86/kernel/quirks.c +0
-0
[ ... ]
arch/x86/kernel/quirks.c DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2083, quirk_intel_purley_xeon_ras · line 670
Quoted 8 lines
arch/x86/kernel/quirks.c +4
-0@@ -664,8 +664,113 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2083, quirk_intel_purley_xeon_rasbool x86_apple_machine;EXPORT_SYMBOL (x86_apple_machine); +bool has_apple_t2_chip; +EXPORT_SYMBOL (has_apple_t2_chip); + +static const struct dmi_system_id apple_t2_devices[] = {
[Severity: Low]
Since apple_t2_devices is only used by early_platform_quirks() which is marked __init, should this array be marked with __initconst so its memory can be freed after system initialization?
Quoted 4 lines
arch/x86/kernel/quirks.c +4
-0+ { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), + DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro15,1"),
[ ... ]
Quoted 5 lines
include/linux/platform_data/x86/apple.h +0
-0
include/linux/platform_data/x86/apple.h line 15
Quoted 10 lines
include/linux/platform_data/x86/apple.h +5
-0@@ -6,8 +6,13 @@* x86_apple_machine - whether the machine is an x86 Apple Macintosh */ extern bool x86_apple_machine; +/** +* has_apple_t2_chip - whether the machine has the Apple T2 chip +*/ +extern bool has_apple_t2_chip;#else #define x86_apple_machine false +#define has_t2_chip false
[Severity: Low]
Does this fallback macro name cause a build regression on non-x86 architectures?
The macro is named has_t2_chip here, but the generic UEFI code in load_uefi_certs() expects has_apple_t2_chip. When CONFIG_LOAD_UEFI_KEYS is enabled on other architectures, could this result in an undeclared identifier error since has_apple_t2_chip would not be defined?
Quoted 7 lines
include/linux/platform_data/x86/apple.h +0
-0#endif #endif security/integrity/platform_certs/load_uefi.c +0
-0
[ ... ]
security/integrity/platform_certs/load_uefi.c line 23
Quoted 8 lines
security/integrity/platform_certs/load_uefi.c +0
-8-/* -* On T2 Macs reading the db and dbx efi variables to load UEFI Secure Boot -* certificates causes occurrence of a page fault in Apple's firmware and -* a crash disabling EFI runtime services. The following quirk skips reading -* these variables. -*/ -static const struct dmi_system_id uefi_skip_cert[] = { - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacBookPro15,1" ) },
[Severity: Low]
With the removal of the uefi_skip_cert array, the UEFI_QUIRK_SKIP_CERT macro defined in security/integrity/platform_certs/keyring_handler.h appears to be completely unused.
Should that macro definition be cleaned up as well to prevent leftover code?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v2 1/2] treewide: Add a flag to detect the Apple T2 chip
In reply to Atharva TiwariQuoted 216 lines · Atharva Tiwari
Add a flag to detect Apple T2 chips on Intel Macs. Cache the result to avoid repeated checks. That will be used in upcoming patches.
Signed-off-by Atharva Tiwari <[email protected]>--- arch/x86/kernel/quirks.c | 105 ++++++++++++++++++ include/linux/platform_data/x86/apple.h | 5 + security/integrity/platform_certs/load_uefi.c | 38 ++----- 3 files changed, 118 insertions(+), 30 deletions(-)arch/x86/kernel/quirks.c +105
-0@@ -664,8 +664,113 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2083, quirk_intel_purley_xeon_rasbool x86_apple_machine;EXPORT_SYMBOL (x86_apple_machine); +bool has_apple_t2_chip; +EXPORT_SYMBOL (has_apple_t2_chip); + +static const struct dmi_system_id apple_t2_devices[] = { + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"MacBookPro15,1" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"MacBookPro15,2" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"MacBookPro15,3" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"MacBookPro15,4" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"MacBookPro16,1" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"MacBookPro16,2" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"MacBookPro16,3" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"MacBookPro16,4" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"MacBookAir8,1" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"MacBookAir8,2" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"MacBookAir9,1" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Macmini8,1" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"MacPro7,1" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"iMac20,1" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"iMac20,2" ), + }, + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"iMacPro1,1" ), + }, + }, + { } +}; +void __init early_platform_quirks (void ) { x86_apple_machine =dmi_match (DMI_SYS_VENDOR ,"Apple Inc." ) ||dmi_match (DMI_SYS_VENDOR ,"Apple Computer, Inc." ); + + has_apple_t2_chip =dmi_check_system (apple_t2_devices); }include/linux/platform_data/x86/apple.h +5
-0@@ -6,8 +6,13 @@* x86_apple_machine - whether the machine is an x86 Apple Macintosh */ extern bool x86_apple_machine; +/** +* has_apple_t2_chip - whether the machine has the Apple T2 chip +*/ +extern bool has_apple_t2_chip;#else #define x86_apple_machine false +#define has_t2_chip false#endif #endif security/integrity/platform_certs/load_uefi.c +8
-30@@ -3,42 +3,16 @@#include <linux/kernel.h> #include <linux/sched.h> #include <linux/cred.h> -#include <linux/dmi.h> #include <linux/err.h> #include <linux/efi.h> #include <linux/slab.h> #include <linux/ima.h> +#include <linux/platform_data/x86/apple.h> #include <keys/asymmetric-type.h> #include <keys/system_keyring.h> #include "../integrity.h" #include "keyring_handler.h" -/* -* On T2 Macs reading the db and dbx efi variables to load UEFI Secure Boot -* certificates causes occurrence of a page fault in Apple's firmware and -* a crash disabling EFI runtime services. The following quirk skips reading -* these variables. -*/ -static const struct dmi_system_id uefi_skip_cert[] = { - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacBookPro15,1" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacBookPro15,2" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacBookPro15,3" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacBookPro15,4" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacBookPro16,1" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacBookPro16,2" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacBookPro16,3" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacBookPro16,4" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacBookAir8,1" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacBookAir8,2" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacBookAir9,1" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"Macmini8,1" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"MacPro7,1" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"iMac20,1" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"iMac20,2" ) }, - {UEFI_QUIRK_SKIP_CERT ("Apple Inc." ,"iMacPro1,1" ) }, - { } -}; -/* * Look to see if a UEFI variable called MokIgnoreDB exists and return true if * it does. @@ -165,10 +139,14 @@ static int __init load_uefi_certs(void)unsigned long dbsize =0 , dbxsize =0 , mokxsize =0 ;efi_status_t status;int rc =0 ; -const struct dmi_system_id *dmi_id; - dmi_id =dmi_first_match (uefi_skip_cert); -if (dmi_id) { +/* +* On T2 Macs reading the db and dbx efi variables to load UEFI Secure Boot +* certificates causes occurrence of a page fault in Apple's firmware and +* a crash disabling EFI runtime services. The following quirk skips reading +* these variables. +*/ +if (has_apple_t2_chip) {pr_err ("Reading UEFI Secure Boot Certs is not supported on T2 Macs.\n" );return false; }Signature · 1 line
2.43.0
BR, Jarkko
PATCH v2 2/2 thunderbolt: Add device links for Apple T2 NHI
In reply to Atharva TiwariFrom: Andre Eikmeyer <[email protected]>
Thunderbolt NHI on T2 Macs (2018-2020). The NHI and its associated PCIe root ports all sit directly on the root complex with no upstream port. Apple's ACPI tables name Thunderbolt root ports as TRP0, TRP1, etc. Find them and create device links back to the NHI so that PCIe tunnels can be re-established after sleep.
--- drivers/thunderbolt/tb.c | 51 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-)
drivers/thunderbolt/tb.c +50 -1
@@ -6,6 +6,7 @@* Copyright (C) 2019, Intel Corporation */ +#include <linux/acpi.h> #include <linux/slab.h> #include <linux/errno.h> #include <linux/delay.h>
@@ -3305,11 +3306,59 @@ static const struct tb_cm_ops tb_cm_ops = {static bool tb_apple_add_links (struct tb_nhi *nhi) {struct pci_dev *upstream, *pdev; -bool ret; +bool ret = false;if (!x86_apple_machine)return false; +/* On T2 Macs. the root ports are stored in ACPI as TRP0, +* TRP1, etc. Find them and create device links +* so that PCIe tunnels can be re-established after +* sleep. +*/ +if (has_apple_t2_chip) { +struct acpi_device *adev; +unsigned int slot, func; +const struct device_link *link; +const char *bid; + +for (slot =0 ; slot <32 ; slot++) { +for (func =0 ; func <8 ; func++) { + pdev =pci_get_slot (nhi->pdev->bus,PCI_DEVFN (slot, func)); +if (!pdev) +continue ; + +if (!pci_is_pcie (pdev) ||pci_pcie_type (pdev) != +PCI_EXP_TYPE_ROOT_PORT ) + goto put_pdev; + + adev =ACPI_COMPANION (&pdev->dev); +if (!adev) + goto put_pdev; + + bid =acpi_device_bid (adev); +if (!bid ||strncmp (bid,"TRP" ,3 ) !=0 ) + goto put_pdev; + + link =device_link_add (&pdev->dev, &nhi->pdev->dev, +DL_FLAG_AUTOREMOVE_SUPPLIER | +DL_FLAG_PM_RUNTIME ); +if (link) { +dev_dbg (&nhi->pdev->dev,"created link from %s\n" , +dev_name (&pdev->dev)); + ret = true; + }else +dev_warn (&nhi->pdev->dev, +"device link creation from %s failed\n" , +dev_name (&pdev->dev)); + +put_pdev: +pci_dev_put (pdev); + } + } +return ret; + } +switch (nhi->pdev->device) {case PCI_DEVICE_ID_INTEL_LIGHT_RIDGE :case PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_4C :
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v2 2/2] thunderbolt: Add device links for Apple T2 NHI
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
New issues:
- [High] Undeclared identifier 'has_apple_t2_chip' when CONFIG_X86 is disabled, causing compilation failure.
- [High] Implicit declaration of 'acpi_device_bid' when CONFIG_ACPI is disabled.
- [Low] Tautological NULL check on array address triggers a -Waddress compiler warning.
Pre-existing issues:
- [High] Preexisting lockless traversal of PCI bridge lists leading to potential Use-After-Free during concurrent hotplug. --
--- Patch [2]: [PATCH v2 2/2] thunderbolt: Add device links for Apple T2 NHI --- commit 5087a210c6d3fe9227441543aeb910ee2d98e69e
Author: Andre Eikmeyer <[email protected]>
thunderbolt: Add device links for Apple T2 NHI
This commit adds support for creating device links on Apple T2 Macs. It finds root ports named TRP0, TRP1, etc. in ACPI and creates device links back to the NHI so that PCIe tunnels can be re-established after sleep.
Quoted 9 lines
drivers/thunderbolt/tb.c +1
-1@@ -3305,11 +3306,59 @@ static const struct tb_cm_ops tb_cm_ops = {static bool tb_apple_add_links (struct tb_nhi *nhi) {struct pci_dev *upstream, *pdev; -bool ret; +bool ret = false;
drivers/thunderbolt/tb.c static const struct tb_cm_ops tb_cm_ops = { · line 3319
Quoted 10 lines
drivers/thunderbolt/tb.c +6
-0if (!x86_apple_machine)return false; +/* On T2 Macs. the root ports are stored in ACPI as TRP0, +* TRP1, etc. Find them and create device links +* so that PCIe tunnels can be re-established after +* sleep. +*/ +if (has_apple_t2_chip) {
[Severity: High]
Will this fail to compile when CONFIG_X86 is disabled?
It looks like the fallback macro in include/linux/platform_data/x86/apple.h was named has_t2_chip instead of has_apple_t2_chip. This would leave the symbol undeclared for non-x86 architectures, potentially breaking the build for Apple Silicon hardware.
Quoted 10 lines
drivers/thunderbolt/tb.c +10
-0+struct acpi_device *adev; +unsigned int slot, func; +const struct device_link *link; +const char *bid; + +for (slot =0 ; slot <32 ; slot++) { +for (func =0 ; func <8 ; func++) { + pdev =pci_get_slot (nhi->pdev->bus,PCI_DEVFN (slot, func)); +if (!pdev) +continue ;
drivers/thunderbolt/tb.c static const struct tb_cm_ops tb_cm_ops = { · line 3339
Quoted 10 lines
drivers/thunderbolt/tb.c +10
-0+ +if (!pci_is_pcie (pdev) ||pci_pcie_type (pdev) != +PCI_EXP_TYPE_ROOT_PORT ) + goto put_pdev; + + adev =ACPI_COMPANION (&pdev->dev); +if (!adev) + goto put_pdev; + + bid =acpi_device_bid (adev);
[Severity: High]
Does this cause an implicit declaration build failure when CONFIG_ACPI is disabled?
The acpi_device_bid() macro is provided by acpi/acpi_bus.h which is only included when CONFIG_ACPI is enabled, and there doesn't appear to be a stub fallback definition for the !CONFIG_ACPI case.
drivers/thunderbolt/tb.c static const struct tb_cm_ops tb_cm_ops = { · line 3340
Quoted 1 line
drivers/thunderbolt/tb.c +1
-0+if (!bid ||strncmp (bid,"TRP" ,3 ) !=0 )
[Severity: Low]
Is the !bid condition check necessary here?
Since acpi_device_bid() expands to adev->pnp.bus_id, which is an inline character array of fixed size, it decays into a pointer to its first element and can never evaluate to NULL. This might trigger a -Waddress compiler warning.
Quoted 3 lines
drivers/thunderbolt/tb.c +3
-0+ goto put_pdev; + + link = device_link_add(&pdev->dev, &nhi->pdev->dev,
[ ... ]
drivers/thunderbolt/tb.c
Quoted 7 lines
drivers/thunderbolt/tb.c +0
-0/* * For each hotplug downstream port, create add device link * back to NHI so that PCIe tunnels can be re-established after * sleep. */ ret = false;for_each_pci_bridge (pdev, upstream->subordinate) {
[Severity: High]
This is a pre-existing issue, but does this loop risk a use-after-free during concurrent PCIe hotplug events?
In the legacy execution path for non-T2 Macs, the for_each_pci_bridge() macro iterates over downstream devices locklessly, without holding the pci_bus_sem read lock. If a concurrent hotplug event adds or removes devices while this list iteration is in progress, it could read freed memory.
Quoted 3 lines
drivers/thunderbolt/tb.c +0
-0const struct device_link *link;if (!pci_is_pcie (pdev))
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2