Enable CXL PCIe Port Protocol Error handling and logging
Subsystems (6)
v13 cover Enable CXL PCIe Port Protocol Error handling and logging
This patchset updates CXL Protocol Error handling for CXL Ports and CXL Endpoints (EP). Previous versions of this series can be found here:
https://lore.kernel.org/linux-cxl/[email protected]/
The first 2 patches were moved to the front this revision. This is the pcie_is_cxl() patch and the DVSEC definition patch. They were moved to front in case Alejandro needs for his Type2 series.
The next 6 patches prepare and move files. This includes Dave Jiang's patch moving CXL RAS related code from cxl/core/pci.c to cxl/core/ras.c. Restricted CXL host (RCH) related RAS code is moved to cxl/core/ras_rch.c. AER driver related RCH code is moved within the AER driver from pci/pcie/aer.c pci/pcie/aer_cxl_rch.c.
Patches 9-15 are mostly fixups in preparation for following protocol handling changes. This includes introducing the new PCI_ERS_RESULT_PANIC result type, improvements to AER logging for bus type (CXL or PCI), function handler interface updates supporting both Endpoints and CXL Port devices, logging a message if RAS is NULL. The patch "CXL/AER: Update PCI class code check to use FIELD_GET()" was removed from this group per Lukas's request.
Patches 16-17 move more code. The AER driver's virtual hierarchy (VH) RAS related code is moved to pci/pcie/aer_cxl_vh.c in patch 17. Patch 18 introduces cxl_pci_drv_bound() to identify if an EP is using the CXL EP driver. This is to support cases where the CXL driver is not used (eg. VFIO). Accessing cxl_pci_drv_bound() in cxl/pci.c from cxl_core fails with circular build dependencies. This requires moving cxl/pci.c (containing cxl_pci_drv_bound()) to cxl/core/pci_drv.c.
Patches 18-20 create CXL Endpoint error handlers alongside the existing CXL PCI error handlers. Both CXL and PCI error handlers are added for CXL Port devices.
Patches 21-23 implement the kernel kfifo dequeue and logic for calling the correctable or uncorrectable handlers. Signifcant changes were made in the unrecoverable patch for the following.
- Updated locking. The endpoint and port devices lock the following:
EP - pdev->dev (same as cxlds->dev) and cxlmd->dev
RP/USP/DSP - pdev->dev and parent cxl_port
- Move locking out of handlers and into cxl_handle_proto_error() and report_error_detected(). Lock as soon as possible after kfifo dequeue.
- Device's reporting UCEs, are locked after kfifo dequeue. Must make condition check to prevent from locking the reporting device during iteration in do_recovery().
Patches 24-25 enable/disable protocol error interrupt masks.
== Testing ===
Below are the testing results while using QEMU. The QEMU testing uses a CXL Root Port, CXL Upstream Switch Port, CXL Downstream Switch Port and CXL Endpoint as given below. I've attached the QEMU startup commandline used. This testing uses protocol error injection at all the devices.
The sub-topology for the QEMU testing is:
---------------------
| CXL RP - 0C:00.0 |
---------------------
|
---------------------
| CXL USP - 0D:00.0 |
---------------------
|
---------------------
| CXL DSP - 0E:00.0 |
---------------------
|
---------------------
| CXL EP - 0F:00.0 |
---------------------root@tbowman-cxl:~# lspci -t -+-[0000:00]- -00.0 | +-01.0 | +-02.0 | +-03.0 | +-1f.0 | +-1f.2 | \-1f.3 \-[0000:0c]---00.0-[0d-0f]----00.0-[0e-0f]----00.0-[0f]----00.0
The topology was created with:
${qemu} -boot menu=on \
-cpu host \
-nographic \
-monitor telnet:127.0.0.1:1234,server,nowait \
-M virt,cxl=on \
-chardev stdio,id=s1,signal=off,mux=on -serial none \
-device isa-serial,chardev=s1 -mon chardev=s1,mode=readline \
-machine q35,cxl=on \
-m 16G,maxmem=24G,slots=8 \
-cpu EPYC-v3 \
-smp 16 \
-accel kvm \
-drive file=${img},format=raw,index=0,media=disk \
-device e1000,netdev=user.0 \
-netdev user,id=user.0,hostfwd=tcp::5555-:22 \
-object memory-backend-file,id=cxl-mem0,share=on,mem-path=/tmp/cxltest.raw,size=256M \
-object memory-backend-file,id=cxl-lsa0,share=on,mem-path=/tmp/lsa0.raw,size=256M \
-device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1 \
-device cxl-rp,port=0,bus=cxl.1,id=root_port0,chassis=0,slot=0 \
-device cxl-upstream,bus=root_port0,id=us0 \
-device cxl-downstream,port=0,bus=us0,id=swport0,chassis=0,slot=4 \
-device cxl-type3,bus=swport0,volatile-memdev=cxl-mem0,lsa=cxl-lsa0,id=cxl-vmem0 \
-M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G,cxl-fmw.0.interleave-granularity=4k=== Root Port ===
root@tbowman-cxl:~/aer-inject# ./root-ce-inject.sh pcieport 0000:0c:00.0: aer_inject: Injecting errors 00004000/00000000 into device 0000:0c:00.0 pcieport 0000:0c:00.0: AER: Correctable error message received from 0000:0c:00.0 pcieport 0000:0c:00.0: CXL Bus Error: severity=Correctable, type=Transaction Layer, (Receiver ID) pcieport 0000:0c:00.0: device [8086:7075] error status/mask=00004000/0000a000 pcieport 0000:0c:00.0: [14] CorrIntErr cxl_aer_correctable_error: memdev=0000:0c:00.0 host=pci0000:0c serial=0: status: 'CRC Threshold Hit'
root@tbowman-cxl:~/aer-inject# ./root-uce-inject.sh pcieport 0000:0c:00.0: aer_inject: Injecting errors 00000000/00400000 into device 0000:0c:00.0 pcieport 0000:0c:00.0: AER: Uncorrectable (Fatal) error message received from 0000:0c:00.0 aer_event: 0000:0c:00.0 CXL Bus Error: severity=Fatal, Uncorrectable Internal Error, TLP Header=Not available pcieport 0000:0c:00.0: CXL Bus Error: severity=Uncorrectable (Fatal), type=Transaction Layer, (Receiver ID) pcieport 0000:0c:00.0: device [8086:7075] error status/mask=00400000/02000000 pcieport 0000:0c:00.0: [22] UncorrIntErr cxl_aer_uncorrectable_error: memdev=0000:0c:00.0 host=pci0000:0c serial=0: status: 'Cache Byte Enable Parity Error' first_error: 'Cache Byte Enable Parity Error' cxl_aer_uncorrectable_error: memdev=0000:0d:00.0 host=0000:0c:00.0 serial=0: status: 'Cache Byte Enable Parity Error' first_error: 'Cache Byte Enable Parity Error' cxl_aer_uncorrectable_error: memdev=0000:0e:03.0 host=0000:0d:00.0 serial=0: status: 'Cache Byte Enable Parity Error' first_error: 'Cache Byte Enable Parity Error' cxl_aer_uncorrectable_error: memdev=mem3 host=0000:12:00.0 serial=0: status: 'Cache Byte Enable Parity Error' first_error: 'Cache Byte Enable Parity Error' cxl_aer_uncorrectable_error: memdev=0000:0e:02.0 host=0000:0d:00.0 serial=0: status: 'Cache Byte Enable Parity Error' first_error: 'Cache Byte Enable Parity Error' cxl_aer_uncorrectable_error: memdev=mem2 host=0000:11:00.0 serial=0: status: 'Cache Byte Enable Parity Error' first_error: 'Cache Byte Enable Parity Error' cxl_aer_uncorrectable_error: memdev=0000:0e:01.0 host=0000:0d:00.0 serial=0: status: 'Cache Byte Enable Parity Error' first_error: 'Cache Byte Enable Parity Error' cxl_aer_uncorrectable_error: memdev=mem0 host=0000:10:00.0 serial=0: status: 'Cache Byte Enable Parity Error' first_error: 'Cache Byte Enable Parity Error' cxl_aer_uncorrectable_error: memdev=0000:0e:00.0 host=0000:0d:00.0 serial=0: status: 'Cache Byte Enable Parity Error' first_error: 'Cache Byte Enable Parity Error' cxl_aer_uncorrectable_error: memdev=mem1 host=0000:0f:00.0 serial=0: status: 'Cache Byte Enable Parity Error' first_error: 'Cache Byte Enable Parity Error' Kernel panic - not syncing: CXL cachemem error. CPU: 10 UID: 0 PID: 150 Comm: kworker/10:1 Tainted: G E 6.18.0-rc2-00029-g7d4bdf85dccf #3518 PREEMPT(voluntary) Tainted: [E]=UNSIGNED_MODULE Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014 Workqueue: events cxl_proto_err_work_fn [cxl_core] Call Trace: <TASK> vpanic+0x3a0/0x410 panic+0x5b/0x60 ? xa_find_after+0x134/0x250 ? xa_find_after+0x86/0x250 cxl_proto_err_work_fn+0x316/0x320 [cxl_core] ? lock_release+0x1e4/0x3f0 process_one_work+0x22c/0x650 worker_thread+0x188/0x330 ? __pfx_worker_thread+0x10/0x10 kthread+0x102/0x210 ? __pfx_kthread+0x10/0x10 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x278/0x2e0 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK> Kernel Offset: disabled ---[ end Kernel panic - not syncing: CXL cachemem error. ]---
=== Upstream Port ===
root@tbowman-cxl:~/aer-inject# ./us-ce-inject.sh pcieport 0000:0c:00.0: aer_inject: Injecting errors 00004000/00000000 into device 0000:0d:00.0 pcieport 0000:0c:00.0: AER: Correctable error message received from 0000:0d:00.0 pcieport 0000:0d:00.0: CXL Bus Error: severity=Correctable, type=Transaction Layer, (Receiver ID) pcieport 0000:0d:00.0: device [19e5:a128] error status/mask=00004000/0000a000 pcieport 0000:0d:00.0: [14] CorrIntErr cxl_aer_correctable_error: memdev=0000:0d:00.0 host=0000:0c:00.0 serial=0: status: 'CRC Threshold Hit'
root@tbowman-cxl:~/aer-inject# ./us-uce-inject.sh pcieport 0000:0c:00.0: aer_inject: Injecting errors 00000000/00400000 into device 0000:0d:00.0 pcieport 0000:0c:00.0: AER: Uncorrectable (Fatal) error message received from 0000:0d:00.0 aer_event: 0000:0d:00.0 CXL Bus Error: severity=Fatal, , TLP Header=Not available pcieport 0000:0d:00.0: AER: CXL Bus Error: severity=Uncorrectable (Fatal), type=Inaccessible, (Unregistered Agent ID) cxl_aer_uncorrectable_error: memdev=mem1 host=0000:0f:00.0 serial=0: status: 'Cache Byte Enable Parity Error' first_error: 'Cache Byte Enable Parity Error' Kernel panic - not syncing: CXL cachemem error. CPU: 10 UID: 0 PID: 159 Comm: irq/24-aerdrv Tainted: G E 6.18.0-rc2-00029-g7d4bdf85dccf #3518 PREEMPT(voluntary) Tainted: [E]=UNSIGNED_MODULE Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014 Call Trace: <TASK> vpanic+0x3a0/0x410 panic+0x5b/0x60 pci_error_detected+0xb4/0xc0 [cxl_core] report_error_detected+0xbf/0x190 ? __pfx_report_frozen_detected+0x10/0x10 __pci_walk_bus+0x4c/0x70 ? __pfx_report_frozen_detected+0x10/0x10 __pci_walk_bus+0x34/0x70 ? __pfx_report_frozen_detected+0x10/0x10 __pci_walk_bus+0x34/0x70 ? __pfx_report_frozen_detected+0x10/0x10 pci_walk_bus+0x31/0x50 pcie_do_recovery+0x300/0x430 aer_isr_one_error_type+0x20f/0x3c0 aer_isr_one_error+0x117/0x140 aer_isr+0x4c/0x80 irq_thread_fn+0x24/0x60 irq_thread+0x1a0/0x2b0 ? __pfx_irq_thread_fn+0x10/0x10 ? __pfx_irq_thread_dtor+0x10/0x10 ? __pfx_irq_thread+0x10/0x10 kthread+0x102/0x210 ? __pfx_kthread+0x10/0x10 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x278/0x2e0 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK> Kernel Offset: disabled ---[ end Kernel panic - not syncing: CXL cachemem error. ]---
=== Downstream Port ===
root@tbowman-cxl:~/aer-inject# ./ds-ce-inject.sh pcieport 0000:0c:00.0: aer_inject: Injecting errors 00004000/00000000 into device 0000:0e:00.0 pcieport 0000:0c:00.0: AER: Correctable error message received from 0000:0e:00.0 aer_event: 0000:0e:00.0 CXL Bus Error: severity=Corrected, Corrected Internal Error, TLP Header=Not available pcieport 0000:0e:00.0: CXL Bus Error: severity=Correctable, type=Transaction Layer, (Receiver ID) pcieport 0000:0e:00.0: device [19e5:a129] error status/mask=00004000/0000a000 pcieport 0000:0e:00.0: [14] CorrIntErr cxl_aer_correctable_error: memdev=0000:0e:00.0 host=0000:0d:00.0 serial=0: status: 'CRC Threshold Hit'
root@tbowman-cxl:~/aer-inject# ./ds-uce-inject.sh pcieport 0000:0c:00.0: aer_inject: Injecting errors 00000000/00400000 into device 0000:0e:00.0 pcieport 0000:0c:00.0: AER: Uncorrectable (Fatal) error message received from 0000:0e:00.0 aer_event: 0000:0e:00.0 CXL Bus Error: severity=Fatal, Uncorrectable Internal Error, TLP Header=Not available pcieport 0000:0e:00.0: CXL Bus Error: severity=Uncorrectable (Fatal), type=Transaction Layer, (Receiver ID) pcieport 0000:0e:00.0: device [19e5:a129] error status/mask=00400000/02000000 pcieport 0000:0e:00.0: [22] UncorrIntErr cxl_aer_uncorrectable_error: memdev=0000:0d:00.0 host=0000:0c:00.0 serial=0: status: 'Cache Byte Enable Parity Error' first_error: 'Cache Byte Enable Parity Error' cxl_aer_uncorrectable_error: memdev=0000:0e:00.0 host=0000:0d:00.0 serial=0: status: 'Cache Byte Enable Parity Error' first_error: 'Cache Byte Enable Parity Error' cxl_aer_uncorrectable_error: memdev=mem0 host=0000:0f:00.0 serial=0: status: 'Cache Byte Enable Parity Error' first_error: 'Cache Byte Enable Parity Error' cxl_aer_uncorrectable_error: memdev=0000:0e:01.0 host=0000:0d:00.0 serial=0: status: 'Cache Byte Enable Parity Error' first_error: 'Cache Byte Enable Parity Error' cxl_aer_uncorrectable_error: memdev=mem1 host=0000:10:00.0 serial=0: status: 'Cache Byte Enable Parity Error' first_error: 'Cache Byte Enable Parity Error' cxl_aer_uncorrectable_error: memdev=0000:0e:03.0 host=0000:0d:00.0 serial=0: status: 'Cache Byte Enable Parity Error' first_error: 'Cache Byte Enable Parity Error' cxl_aer_uncorrectable_error: memdev=mem2 host=0000:12:00.0 serial=0: status: 'Cache Byte Enable Parity Error' first_error: 'Cache Byte Enable Parity Error' cxl_aer_uncorrectable_error: memdev=0000:0e:02.0 host=0000:0d:00.0 serial=0: status: 'Cache Byte Enable Parity Error' first_error: 'Cache Byte Enable Parity Error' cxl_aer_uncorrectable_error: memdev=mem3 host=0000:11:00.0 serial=0: status: 'Cache Byte Enable Parity Error' first_error: 'Cache Byte Enable Parity Error' Kernel panic - not syncing: CXL cachemem error. CPU: 10 UID: 0 PID: 683 Comm: kworker/10:2 Tainted: G E 6.18.0-rc2-00029-g2e23f5f37fac #3552 PREEMPT(voluntary) Tainted: [E]=UNSIGNED_MODULE Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014 Workqueue: events cxl_proto_err_work_fn [cxl_core] Call Trace: <TASK> vpanic+0x3a0/0x410 panic+0x5b/0x60 ? xa_find_after+0x134/0x250 ? xa_find_after+0x86/0x250 cxl_proto_err_work_fn+0x352/0x360 [cxl_core] ? lock_release+0x1e4/0x3f0 process_one_work+0x22c/0x650 worker_thread+0x188/0x330 ? __pfx_worker_thread+0x10/0x10 kthread+0x102/0x210 ? __pfx_kthread+0x10/0x10 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x278/0x2e0 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK> Kernel Offset: disabled ---[ end Kernel panic - not syncing: CXL cachemem error. ]---
=== Endpoint ===
root@tbowman-cxl:~/aer-inject# ./ep-ce-inject.sh pcieport 0000:0c:00.0: aer_inject: Injecting errors 00004000/00000000 into device 0000:0f:00.0 pcieport 0000:0c:00.0: AER: Correctable error message received from 0000:0f:00.0 aer_event: 0000:0f:00.0 CXL Bus Error: severity=Corrected, Corrected Internal Error, TLP Header=Not available cxl_core 0000:0f:00.0: CXL Bus Error: severity=Correctable, type=Transaction Layer, (Receiver ID) cxl_core 0000:0f:00.0: device [8086:0d93] error status/mask=00004000/00000000 cxl_core 0000:0f:00.0: [14] CorrIntErr cxl_aer_correctable_error: memdev=mem3 host=0000:0f:00.0 serial=0: status: 'CRC Threshold Hit'
root@tbowman-cxl:~/aer-inject# ./ep-uce-inject.sh pcieport 0000:0c:00.0: aer_inject: Injecting errors 00000000/00400000 into device 0000:0f:00.0 pcieport 0000:0c:00.0: AER: Uncorrectable (Fatal) error message received from 0000:0f:00.0 aer_event: 0000:0f:00.0 CXL Bus Error: severity=Fatal, , TLP Header=Not available cxl_core 0000:0f:00.0: AER: CXL Bus Error: severity=Uncorrectable (Fatal), type=Inaccessible, (Unregistered Agent ID) cxl_aer_uncorrectable_error: memdev=mem1 host=0000:0f:00.0 serial=0: status: 'Cache Byte Enable Parity Error' first_error: 'Cache Byte Enable Parity Error' Kernel panic - not syncing: CXL cachemem error. CPU: 10 UID: 0 PID: 159 Comm: irq/24-aerdrv Tainted: G E 6.18.0-rc2-00029-g7d4bdf85dccf #3518 PREEMPT(voluntary) Tainted: [E]=UNSIGNED_MODULE Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014 Call Trace: <TASK> vpanic+0x3a0/0x410 panic+0x5b/0x60 pci_error_detected+0xb4/0xc0 [cxl_core] report_error_detected+0xbf/0x190 ? __pfx_report_frozen_detected+0x10/0x10 __pci_walk_bus+0x4c/0x70 ? __pfx_report_frozen_detected+0x10/0x10 pci_walk_bus+0x31/0x50 pcie_do_recovery+0x300/0x430 aer_isr_one_error_type+0x20f/0x3c0 aer_isr_one_error+0x117/0x140 aer_isr+0x4c/0x80 irq_thread_fn+0x24/0x60 irq_thread+0x1a0/0x2b0 ? __pfx_irq_thread_fn+0x10/0x10 ? __pfx_irq_thread_dtor+0x10/0x10 ? __pfx_irq_thread+0x10/0x10 kthread+0x102/0x210 ? __pfx_kthread+0x10/0x10 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x278/0x2e0 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK> Kernel Offset: disabled ---[ end Kernel panic - not syncing: CXL cachemem error. ]---
== Changes ==
Changes in v12->v13:
CXL/PCI: Move CXL DVSEC definitions into uapi/linux/pci_regs.h
- Add Dave Jiang's reviewed-by
- Remove changes to existing PCI_DVSEC_CXL_PORT* defines. Update commit message. (Jonathan)
PCI/CXL: Introduce pcie_is_cxl()
- Add Ben's "reviewed-by"
cxl/pci: Remove unnecessary CXL Endpoint handling helper functions
- None
cxl/pci: Remove unnecessary CXL RCH handling helper functions
- None
cxl: Remove CXL VH handling in CONFIG_PCIEAER_CXL conditional blocks from core
- None
cxl: Move CXL driver's RCH error handling into core/ras_rch.c
- None
CXL/AER: Replace device_lock() in cxl_rch_handle_error_iter() with guard() lock
- New patch
CXL/AER: Move AER drivers RCH error handling into pcie/aer_cxl_rch.c
- Add forward declararation of 'struct aer_err_info' in pci/pci.h (Terry)
- Changed copyright date from 2025 to 2023 (Jonathan)
- Add David Jiang's, Jonathan's, and Ben's review-by
- Readd 'struct aer_err_info' (Bot)
PCI/AER: Report CXL or PCIe bus error type in trace logging
- Remove duplicated aer_err_info inline comments. Is already in the kernel-doc header (Ben)
cxl/pci: Update RAS handler interfaces to also support CXL Ports
- None
cxl/pci: Log message if RAS registers are unmapped
- Added Bens review-by
cxl/pci: Unify CXL trace logging for CXL Endpoints and CXL Ports
- Added Dave Jiang's review-by
cxl/pci: Update cxl_handle_cor_ras() to return early if no RAS errors
- Add Ben's review-by
cxl/pci: Map CXL Endpoint Port and CXL Switch Port RAS registers
- Change as result of dport delay fix. No longer need switchport and endport approach. Refactor. (Terry)
CXL/PCI: Introduce PCI_ERS_RESULT_PANIC
- Add Dave Jiang's, Jonathan's, Ben's review-by
- Typo fix (Ben)
CXL/AER: Introduce pcie/aer_cxl_vh.c in AER driver for forwarding CXL errors
- Add Dave Jiang's review-by
- Update error message (Ben)
cxl: Introduce cxl_pci_drv_bound() to check for bound driver
- Add Dave Jiang's review-by.
cxl: Change CXL handlers to use guard() instead of scoped_guard()
- New patch
cxl/pci: Introduce CXL protocol error handlers for endpoints
- Updated all the implemetnation and commit message. (Terry)
- Refactored cxl_cor_error_detected()/cxl_error_detected() to remove pdev (Dave Jiang)
CXL/PCI: Introduce CXL Port protocol error handlers
- Move get_pci_cxl_host_dev() and cxl_handle_proto_error() to Dequeue patch (Terry)
- Remove EP case in cxl_get_ras_base(), not used. (Terry)
- Remove check for dport->dport_dev (Dave)
- Remove whitespace (Terry)
PCI/AER: Dequeue forwarded CXL error
- Rewrite cxl_handle_proto_error() and cxl_proto_err_work_fn() (Terry)
- Rename get_cxl_host dev() to be get_cxl_port() (Terry)
- Remove exporting of unused function, pci_aer_clear_fatal_status() (Dave Jiang)
- Change pr_err() calls to ratelimited. (Terry)
- Update commit message. (Terry)
- Remove namespace qualifier from pcie_clear_device_status()
export (Dave Jiang)
- Move locks into cxl_proto_err_work_fn() (Dave)
- Update log messages in cxl_forward_error() (Ben)
CXL/PCI: Export and rename merge_result() to pci_ers_merge_result()
- Renamed pci_ers_merge_result() to pcie_ers_merge_result(). pci_ers_merge_result() is already used in eeh driver. (Bot)
CXL/PCI: Introduce CXL uncorrectable protocol error recovery
- Rewrite report_error_detected() and cxl_walk_port (Terry)
- Add guard() before calling cxl_pci_drv_bound() (Dave Jiang)
- Add guard() calls for EP (cxlds->cxlmd->dev & pdev->dev) and ports (pdev->dev & parent cxl_port) in cxl_report_error_detected() and cxl_handle_proto_error() (Terry)
- Remove unnecessary check for endpoint port. (Dave Jiang)
- Remove check for RCIEP EP in cxl_report_error_detected() (Terry)
CXL/PCI: Enable CXL protocol errors during CXL Port probe
- Add dev and dev_is_pci() NULL checks in cxl_unmask_proto_interrupts() (Terry)
- Add Dave Jiang's and Ben's review-by
CXL/PCI: Disable CXL protocol error interrupts during CXL Port cleanup
- Added dev and dev_is_pci() checks in cxl_mask_proto_interrupts() (Terry)
Changes in v11 -> v12:
cxl/pci: Remove unnecessary CXL Endpoint handling helper functions
- Added Dave Jiang's review by
- Moved to front of series
cxl/pci: Remove unnecessary CXL RCH handling helper functions
- Add reviewed-by for Alejandro & Dave Jiang
- Moved to front of series
cxl: Remove ifdef blocks of CONFIG_PCIEAER_CXL from core/pci.c
- Update CONFIG_CXL_RAS in CXL Kconfig to have CXL_PCI dependency (Terry)
CXL/AER: Remove CONFIG_PCIEAER_CXL and replace with CONFIG_CXL_RAS
- Added review-by for Sathyanarayanan
- Changed Kconfig dependency from PCIEAER_CXL to PCIEAER. Moved
this backwards into this patch.
cxl: Move CXL driver RCH error handling into CONFIG_CXL_RCH_RAS conditio
- Moved CXL_RCH_RAS Kconfig definition here from following commit
CXL/AER: Introduce aer_cxl_rch.c into AER driver for handling CXL RCH errors
- Rename drivers/pci/pcie/cxl_rch.c to drivers/pci/pcie/aer_cxl_rch.c (Lukas)
- Removed forward declararation of 'struct aer_err_info' in pci/pci.h (Terry)
CXL/PCI: Move CXL DVSEC definitions into uapi/linux/pci_regs.h
- Change formatting to be same as existing definitions
- Change GENMASK() -> __GENMASK() and BIT() to _BITUL()
PCI/CXL: Introduce pcie_is_cxl()
- Add review-by for Alejandro
- Add comment in set_pcie_cxl() explaining why updating parent status.
PCI/AER: Report CXL or PCIe bus error type in trace logging
- Change aer_err_info::is_cxl to be bool a bitfield. Update structure padding. (Lukas)
- Add kernel-doc for 'struct aer_err_info' (Lukas)
cxl/pci: Unify CXL trace logging for CXL Endpoints and CXL Ports
- Correct parameters to call trace_cxl_aer_correctable_error() (Shiju)
- Add reviewed-by for Jonathan and Shiju
cxl/pci: Map CXL Endpoint Port and CXL Switch Port RAS registers
- Add check for dport_parent->rch before calling cxl_dport_init_ras_reporting().
- RCH dports are initialized from cxl_dport_init_ras_reporting cxl_mem_probe().
CXL/PCI: Introduce PCI_ERS_RESULT_PANIC
- Documentation requested by (Lukas)
CXL/AER: Introduce aer_cxl_vh.c in AER driver for forwarding CXL errors
- Rename drivers/pci/pcie/cxl_aer.c to drivers/pci/pcie/aer_cxl_vh.c (Lukas)
cxl: Introduce cxl_pci_drv_bound() to check for bound driver
- New patch
PCI/AER: Dequeue forwarded CXL error
- Add guard for CE case in cxl_handle_proto_error() (Dave)
- Updated commit message (Terry)
CXL/PCI: Introduce CXL Port protocol error handlers
- Add call to cxl_pci_drv_bound() in cxl_handle_proto_error() and pci_to_cxl_dev() (Lukas)
- Change cxl_error_detected() -> cxl_cor_error_detected() (Terry)
- Remove NULL variable assignments (Jonathan)
- Replace bus_find_device() with find_cxl_port_by_uport() for upstream port searches. (Dave)
CXL/PCI: Export and rename merge_result() to pci_ers_merge_result()
- Remove static inline pci_ers_merge_result() definition for !CONFIG_PCIEAER. Is not needed. (Lukas)
CXL/PCI: Introduce CXL uncorrectable protocol error recovery
- Clean up port discovery in cxl_do_recovery() (Dave)
- Add PCI_EXP_TYPE_RC_END to type check in cxl_report_error_detected()
Changes in v10 -> v11:
cxl: Remove ifdef blocks of CONFIG_PCIEAER_CXL from core/pci.c
- New patch
CXL/AER: Remove CONFIG_PCIEAER_CXL and replace with CONFIG_CXL_RAS
- New patch
cxl/pci: Remove unnecessary CXL RCH handling helper functions
- New patch
cxl: Move CXL driver RCH error handling into CONFIG_CXL_RCH_RAS conditional block
- New patch
CXL/AER: Introduce rch_aer.c into AER driver for handling CXL RCH errors
- Remove changes in code-split and move to earlier, new patch
- Add #include <linux/bitfield.h> to cxl_ras.c
- Move cxl_rch_handle_error() & cxl_rch_enable_rcec() declarations from pci.h to aer.h, more localized.
- Introduce CONFIG_CXL_RCH_RAS, includes Makefile changes, ras.c ifdef changes CXL/PCI: Move CXL DVSEC definitions into uapi/linux/pci_regs.h
- New patch
PCI/CXL: Introduce pcie_is_cxl()
- Amended set_pcie_cxl() to check for Upstream Port's and EP's parent downstream port by calling set_pcie_cxl(). (Dan)
- Retitle patch: 'Add' -> 'Introduce'
- Add check for CXL.mem and CXL.cache (Alejandro, Dan)
PCI/AER: Report CXL or PCIe bus error type in trace logging
- Remove duplicate call to trace_aer_event() (Shiju)
- Added Dan William's and Dave Jiang's reviewed-by
CXL/AER: Update PCI class code check to use FIELD_GET()
- Add #include <linux/bitfield.h> to cxl_ras.c (Terry)
- Removed line wrapping at "(CXL 3.2, 8.1.12.1)". (Jonathan)
cxl/pci: Log message if RAS registers are unmapped
- Added Dave Jiang's review-by (Terry)
cxl/pci: Unify CXL trace logging for CXL Endpoints and CXL Ports
- Updated CE and UCE trace routines to maintian consistent TP_Struct ABI and unchanged TP_printk() logging. (Shiju, Alison)
cxl/pci: Update cxl_handle_cor_ras() to return early if no RAS errors
- Added Dave Jiang and Jonathan Cameron's review-by
- Changes moved to core/ras.c
cxl/pci: Map CXL Endpoint Port and CXL Switch Port RAS registers
- Use local pointer for readability in cxl_switch_port_init_ras() (Jonathan Cameron)
- Rename port to be ep in cxl_endpoint_port_init_ras() (Dave Jiang)
- Rename dport to be parent_dport in cxl_endpoint_port_init_ras()
and cxl_switch_port_init_ras() (Dave Jiang)
- Port helper changes were in cxl/port.c, now in core/ras.c (Dave Jiang) cxl/pci: Introduce CXL Endpoint protocol error handlers
- cxl_error_detected() - Change handlers' scoped_guard() to guard() (Jonathan)
- cxl_error_detected() - Remove extra line (Shiju)
- Changes moved to core/ras.c (Terry)
- cxl_error_detected(), remove 'ue' and return with function call. (Jonathan)
- Remove extra space in documentation for PCI_ERS_RESULT_PANIC definition
- Move #include "pci.h from cxl.h to core.h (Terry)
- Remove unnecessary includes of cxl.h and core.h in mem.c (Terry) CXL/AER: Introduce cxl_aer.c into AER driver for forwarding CXL errors
- Move RCH implementation to cxl_rch.c and RCH declarations to pci/pci.h. (Terry)
- Introduce 'struct cxl_proto_err_kfifo' containing semaphore, fifo, and work struct. (Dan)
- Remove embedded struct from cxl_proto_err_work (Dan)
- Make 'struct work_struct *cxl_proto_err_work' definition static (Jonathan)
- Add check for NULL cxl_proto_err_kfifo to determine if CXL driver is not registered for workqueue. (Dan)
PCI/AER: Dequeue forwarded CXL error
- Reword patch commit message to remove RCiEP details (Jonathan)
- Add #include <linux/bitfield.h> (Terry)
- is_cxl_rcd() - Fix short comment message wrap (Jonathan)
- is_cxl_rcd() - Combine return calls into 1 (Jonathan)
- cxl_handle_proto_error() - Move comment earlier (Jonathan)
- Usse FIELD_GET() in discovering class code (Jonathan)
- Remove BDF from cxl_proto_err_work_data. Use 'struct pci_dev *' (Dan) CXL/PCI: Introduce CXL Port protocol error handlers
- Removed check for PCI_EXP_TYPE_RC_END in cxl_report_error_detected() (Terry)
- Update is_cxl_error() to check for acceptable PCI EP and port types CXL/PCI: Export and rename merge_result() to pci_ers_merge_result()
- pci_ers_merge_result() - Change export to non-namespace and rename to be pci_ers_merge_result() (Jonathan)
- Move pci_ers_merge_result() definition to pci.h. Needs pci_ers_result (Terry) CXL/PCI: Introduce CXL uncorrectable protocol error recovery
- pci_ers_merge_results() - Move to earlier patch
CXL/PCI: Disable CXL protocol error interrupts during CXL Port cleanup
- Remove guard() in cxl_mask_proto_interrupts(). Observed device lockup/block during testing. (Terry)
Changes in v9 -> v10:
- Add drivers/pci/pcie/cxl_aer.c
- Add drivers/cxl/core/native_ras.c
- Change cxl_register_prot_err_work()/cxl_unregister_prot_err_work to return void
- Check for pcie_ports_native in cxl_do_recovery()
- Remove debug logging in cxl_do_recovery()
- Update PCI_ERS_RESULT_PANIC definition to indicate is CXL specific
- Revert trace logging changes: name,parent -> memdev,host.
- Use FIELD_GET() to check for EP class code (cxl_aer.c & native_ras.c).
- Change _prot_ to _proto_ everywhere
- cxl_rch_handle_error_iter(), check if driver is cxl_pci_driver
- Remove cxl_create_prot_error_info(). Move logic into forward_cxl_error()
- Remove sbdf_to_pci() and move logic into cxl_handle_proto_error()
- Simplify/refactor get_pci_cxl_host_dev()
- Simplify/refactor cxl_get_ras_base()
- Move patch 'Remove unnecessary CXL Endpoint handling helper functions' to front
- Update description for 'CXL/PCI: Introduce CXL Port protocol error handlers' with why state is not used to determine handling
- Introduce cxl_pci_drv_bound() and call from cxl_rch_handle_error_iter()
Changes in v8 -> v9:
- Updated reference counting to use pci_get_device()/pci_put_device() in cxl_disable_prot_errors()/cxl_enable_prot_errors
- Refactored cxl_create_prot_err_info() to fix reference counting
- Removed 'struct cxl_port' driver changes for error handler. Instead check for CXL device type (EP or Port device) and call handler
- Make pcie_is_cxl() static inline in include/linux/linux.h
- Remove NULL check in create_prot_err_info()
- Change success return in cxl_ras_init() to use hardcoded 0
- Changed 'struct work_struct cxl_prot_err_work' declaration to static
- Change to use rate limited log with dev anchor in forward_cxl_error()
- Refactored forward-cxl_error() to remove severity auto variable
- Changed pci_aer_clear_nonfatal_status() to be static inline for !(CONFIG_PCIEAER)
- Renamed merge_result() to be cxl_merge_result()
- Removed 'ue' condition in cxl_error_detected()
- Updated 2nd parameter in call to __cxl_handle_cor_ras()/__cxl_handle_ras() in unify patch
- Added log message for failure while assigning interrupt disable callback
- Updated pci_aer_mask_internal_errors() to use pci_clear_and_set_config_dword()
- Simplified patch titles for clarity
- Moved CXL error interrupt disabling into cxl/core/port.c with CXL Port teardown
- Updated 'struct cxl_port_err_info' to only contain sbdf and severity Removed everything else.
- Added pdev and CXL device get_device()/put_device() before calling handlers
Changes in v7 -> v8:
[Dan] Use kfifo. Move handling to CXL driver. AER forwards error to CXL driver
[Dan] Add device reference incrementors where needed throughout [Dan] Initiate CXL Port RAS init from Switch Port and Endpoint Port init [Dan] Combine CXL Port and CXL Endpoint trace routine
[Dan] Introduce aer_info::is_cxl. Use to indicate CXL or PCI errors [Jonathan] Add serial number for all devices in trace [DaveJ] Move find_cxl_port() change into patch using it [Terry] Move CXL Port RAS init into cxl/port.c
[Terry] Moved kfifo functions into cxl/core/ras.c
Changes in v6 -> v7:
[Terry] Move updated trace routine call to later patch. Was causing build error.
Changes in v5 -> v6:
[Ira] Move pcie_is_cxl(dev) define to a inline function
[Ira] Update returning value from pcie_is_cxl_port() to bool w/o cast
[Ira] Change cxl_report_error_detected() cleanup to return correct bool
[Ira] Introduce and use PCI_ERS_RESULT_PANIC
[Ira] Reuse comment for PCIe and CXL recovery paths
[Jonathan] Add type check in for cxl_handle_cor_ras() and cxl_handle_ras() [Jonathan] cxl_uport/dport_init_ras_reporting(), added a mutex.
[Jonathan] Add logging example to patches updating trace output
[Jonathan] Make parameter 'const' to eliminate for cast in match_uport() [Jonathan] Use __free() in cxl_pci_port_ras()
[Terry] Add patch to log the PCIe SBDF along with CXL device name
[Terry] Add patch to handle CXL endpoint and RCH DP errors as CXL errors [Terry] Remove patch w USP UCE fatal support @ aer_get_device_error_info() [Terry] Rebase to cxl/next commit 5585e342e8d3 ("cxl/memdev: Remove unused partition values") [Gregory] Pre-initialize pointer to NULL in cxl_pci_port_ras()
[Gregory] Move AER driver bus name detection to a static function
Changes in v4 -> v5:
[Alejandro] Refactor cxl_walk_bridge to simplify 'status' variable usage [Alejandro] Add WARN_ONCE() in __cxl_handle_ras() and cxl_handle_cor_ras() [Ming] Remove unnecessary NULL check in cxl_pci_port_ras() [Terry] Add failure check for call to to_cxl_port() in cxl_pci_port_ras() [Ming] Use port->dev for call to devm_add_action_or_reset() in cxl_dport_init_ras_reporting() and cxl_uport_init_ras_reporting() [Jonathan] Use get_device()/put_device() to prevent race condition in cxl_clear_port_error_handlers() and cxl_clear_port_error_handlers() [Terry] Commit message cleanup. Capitalize keywords from CXL and PCI specifications
Changes in v3 -> v4:
[Lukas] Capitalize PCIe and CXL device names as in specifications [Lukas] Move call to pcie_is_cxl() into cxl_port_devsec()
[Lukas] Correct namespace spelling
[Lukas] Removed export from pcie_is_cxl_port()
[Lukas] Simplify 'if' blocks in cxl_handle_error()
[Lukas] Change panic message to remove redundant 'panic' text
[Ming] Update to call cxl_dport_init_ras_reporting() in RCH case [lkp@intel] 'host' parameter is already removed. Remove parameter description too. [Terry] Added field description for cxl_err_handlers in pci.h comment block
Changes in v1 -> v2:
[Jonathan] Remove extra NULL check and cleanup in cxl_pci_port_ras() [Jonathan] Update description to DSP map patch description
[Jonathan] Update cxl_pci_port_ras() to check for NULL port [Jonathan] Dont call handler before handler port changes are present (patch order) [Bjorn] Fix linebreak in cover sheet URL
[Bjorn] Remove timestamps from test logs in cover sheet
[Bjorn] Retitle AER commits to use "PCI/AER:"
[Bjorn] Retitle patch#3 to use renaming instead of refactoring [Bjorn] Fix base commit-id on cover sheet
[Bjorn] Add VH spec reference/citation
[Terry] Removed last 2 patches to enable internal errors. Is not needed because internal errors are enabled in AER driver.
[Dan] Create cxl_do_recovery() and pci_driver::cxl_err_handlers. [Dan] Use kernel panic in CXL recovery
[Dan] cxl_port_hndlrs -> cxl_port_error_handlers
Dave Jiang (1):
cxl: Remove CXL VH handling in CONFIG_PCIEAER_CXL conditional blocks
from core/pci.c
Terry Bowman (24):
CXL/PCI: Move CXL DVSEC definitions into uapi/linux/pci_regs.h PCI/CXL: Introduce pcie_is_cxl()
cxl/pci: Remove unnecessary CXL Endpoint handling helper functions cxl/pci: Remove unnecessary CXL RCH handling helper functions
cxl: Move CXL driver's RCH error handling into core/ras_rch.c CXL/AER: Replace device_lock() in cxl_rch_handle_error_iter() with
guard() lock
CXL/AER: Move AER drivers RCH error handling into pcie/aer_cxl_rch.c PCI/AER: Report CXL or PCIe bus error type in trace logging cxl/pci: Update RAS handler interfaces to also support CXL Ports cxl/pci: Log message if RAS registers are unmapped cxl/pci: Unify CXL trace logging for CXL Endpoints and CXL Ports cxl/pci: Update cxl_handle_cor_ras() to return early if no RAS errors cxl/pci: Map CXL Endpoint Port and CXL Switch Port RAS registers CXL/PCI: Introduce PCI_ERS_RESULT_PANIC
CXL/AER: Introduce pcie/aer_cxl_vh.c in AER driver for forwarding CXL
errors
cxl: Introduce cxl_pci_drv_bound() to check for bound driver
cxl: Change CXL handlers to use guard() instead of scoped_guard() cxl/pci: Introduce CXL protocol error handlers for Endpoints CXL/PCI: Introduce CXL Port protocol error handlers PCI/AER: Dequeue forwarded CXL error
CXL/PCI: Export and rename merge_result() to pci_ers_merge_result() CXL/PCI: Introduce CXL uncorrectable protocol error recovery CXL/PCI: Enable CXL protocol errors during CXL Port probe CXL/PCI: Disable CXL protocol error interrupts during CXL Port cleanup
Documentation/PCI/pci-error-recovery.rst | 6 +
drivers/cxl/Kconfig | 17 +-
drivers/cxl/Makefile | 2 -
drivers/cxl/core/Makefile | 4 +-
drivers/cxl/core/core.h | 66 +++
drivers/cxl/core/pci.c | 380 ++-------------
drivers/cxl/{pci.c => core/pci_drv.c} | 32 +-
drivers/cxl/core/port.c | 28 +-
drivers/cxl/core/ras.c | 572 ++++++++++++++++++++++-
drivers/cxl/core/ras_rch.c | 120 +++++
drivers/cxl/core/regs.c | 12 +-
drivers/cxl/core/trace.h | 68 +--
drivers/cxl/cxl.h | 10 +-
drivers/cxl/cxlpci.h | 68 +--
drivers/cxl/mem.c | 3 +-
drivers/pci/pci.c | 5 +-
drivers/pci/pci.h | 59 ++-
drivers/pci/pcie/Makefile | 2 +
drivers/pci/pcie/aer.c | 155 ++----
drivers/pci/pcie/aer_cxl_rch.c | 96 ++++
drivers/pci/pcie/aer_cxl_vh.c | 98 ++++
drivers/pci/pcie/err.c | 14 +-
drivers/pci/probe.c | 29 ++
include/linux/aer.h | 29 ++
include/linux/pci.h | 18 +
include/ras/ras_event.h | 9 +-
include/uapi/linux/pci_regs.h | 63 ++-
tools/testing/cxl/Kbuild | 4 +-
28 files changed, 1320 insertions(+), 649 deletions(-)
rename drivers/cxl/{pci.c => core/pci_drv.c} (98%)
create mode 100644 drivers/cxl/core/ras_rch.c
create mode 100644 drivers/pci/pcie/aer_cxl_rch.c
create mode 100644 drivers/pci/pcie/aer_cxl_vh.cbase-commit: 211ddde0823f1442e4ad052a2f30f050145ccada
Signature · 1 line
2.34.1
PATCH v13 1/25 CXL/PCI: Move CXL DVSEC definitions into uapi/linux/pci_regs.h
The CXL DVSECs are currently defined in cxl/core/cxlpci.h. These are not accessible to other subsystems. Move these to uapi/linux/pci_regs.h.
Change DVSEC name formatting to follow the existing PCI format in pci_regs.h. The current format uses CXL_DVSEC_XYZ and the CXL defines must be changed to be PCI_DVSEC_CXL_XYZ to match existing pci_regs.h. Leave PCI_DVSEC_CXL_PORT* defines as-is because they are already defined and may be in use by userspace application(s).
Update existing usage to match the name change.
Update the inline documentation to refer to latest CXL spec version.
----
Changes in v12->v13:
- Add Dave Jiang's reviewed-by
- Remove changes to existing PCI_DVSEC_CXL_PORT* defines. Update commit message. (Jonathan)
Changes in v11 -> v12:
- Change formatting to be same as existing definitions
- Change GENMASK() -> __GENMASK() and BIT() to _BITUL()
Changes in v10 -> v11:
- New commit
--- drivers/cxl/core/pci.c | 62 +++++++++++++++++----------------- drivers/cxl/core/regs.c | 12 +++---- drivers/cxl/cxlpci.h | 53 ----------------------------- drivers/cxl/pci.c | 2 +- drivers/pci/pci.c | 4 ++- include/uapi/linux/pci_regs.h | 63 ++++++++++++++++++++++++++++++++--- 6 files changed, 100 insertions(+), 96 deletions(-)
drivers/cxl/core/pci.c +31 -31
@@ -158,19 +158,19 @@ static int cxl_dvsec_mem_range_valid(struct cxl_dev_state *cxlds, int id)int rc, i;u32 temp; -if (id >CXL_DVSEC_RANGE_MAX ) +if (id >PCI_DVSEC_CXL_RANGE_MAX )return -EINVAL ;/* Check MEM INFO VALID bit first, give up after 1s */ i =1 ; do { rc = pci_read_config_dword(pdev, - d + CXL_DVSEC_RANGE_SIZE_LOW(id), + d + PCI_DVSEC_CXL_RANGE_SIZE_LOW(id), &temp); if (rc) return rc; - valid = FIELD_GET(CXL_DVSEC_MEM_INFO_VALID, temp); + valid = FIELD_GET(PCI_DVSEC_CXL_MEM_INFO_VALID, temp); if (valid) break; msleep(1000);
@@ -194,17 +194,17 @@ static int cxl_dvsec_mem_range_active(struct cxl_dev_state *cxlds, int id)int rc, i;u32 temp; -if (id >CXL_DVSEC_RANGE_MAX ) +if (id >PCI_DVSEC_CXL_RANGE_MAX )return -EINVAL ;/* Check MEM ACTIVE bit, up to 60s timeout by default */ for (i = media_ready_timeout; i; i--) { rc =pci_read_config_dword ( - pdev, d +CXL_DVSEC_RANGE_SIZE_LOW (id), &temp); + pdev, d +PCI_DVSEC_CXL_RANGE_SIZE_LOW (id), &temp);if (rc)return rc; - active =FIELD_GET (CXL_DVSEC_MEM_ACTIVE , temp); + active =FIELD_GET (PCI_DVSEC_CXL_MEM_ACTIVE , temp);if (active)break ;msleep (1000 );
@@ -233,11 +233,11 @@ int cxl_await_media_ready(struct cxl_dev_state *cxlds)u16 cap; rc =pci_read_config_word (pdev, - d +CXL_DVSEC_CAP_OFFSET , &cap); + d +PCI_DVSEC_CXL_CAP_OFFSET , &cap);if (rc)return rc; - hdm_count =FIELD_GET (CXL_DVSEC_HDM_COUNT_MASK , cap); + hdm_count =FIELD_GET (PCI_DVSEC_CXL_HDM_COUNT_MASK , cap);for (i =0 ; i < hdm_count; i++) { rc =cxl_dvsec_mem_range_valid (cxlds, i);if (rc)
@@ -265,16 +265,16 @@ static int cxl_set_mem_enable(struct cxl_dev_state *cxlds, u16 val)u16 ctrl;int rc; - rc =pci_read_config_word (pdev, d +CXL_DVSEC_CTRL_OFFSET , &ctrl); + rc =pci_read_config_word (pdev, d +PCI_DVSEC_CXL_CTRL_OFFSET , &ctrl);if (rc <0 )return rc; -if ((ctrl &CXL_DVSEC_MEM_ENABLE ) == val) +if ((ctrl &PCI_DVSEC_CXL_MEM_ENABLE ) == val)return 1 ; - ctrl &= ~CXL_DVSEC_MEM_ENABLE ; + ctrl &= ~PCI_DVSEC_CXL_MEM_ENABLE ; ctrl |= val; - rc =pci_write_config_word (pdev, d +CXL_DVSEC_CTRL_OFFSET , ctrl); + rc =pci_write_config_word (pdev, d +PCI_DVSEC_CXL_CTRL_OFFSET , ctrl);if (rc <0 )return rc;
@@ -290,7 +290,7 @@ static int devm_cxl_enable_mem(struct device *host, struct cxl_dev_state *cxlds) {int rc; - rc =cxl_set_mem_enable (cxlds,CXL_DVSEC_MEM_ENABLE ); + rc =cxl_set_mem_enable (cxlds,PCI_DVSEC_CXL_MEM_ENABLE );if (rc <0 )return rc;if (rc >0 )
@@ -352,11 +352,11 @@ int cxl_dvsec_rr_decode(struct cxl_dev_state *cxlds,return -ENXIO ; } - rc =pci_read_config_word (pdev, d +CXL_DVSEC_CAP_OFFSET , &cap); + rc =pci_read_config_word (pdev, d +PCI_DVSEC_CXL_CAP_OFFSET , &cap);if (rc)return rc; -if (!(cap &CXL_DVSEC_MEM_CAPABLE )) { +if (!(cap &PCI_DVSEC_CXL_MEM_CAPABLE )) {dev_dbg (dev,"Not MEM Capable\n" );return -ENXIO ; }
@@ -367,7 +367,7 @@ int cxl_dvsec_rr_decode(struct cxl_dev_state *cxlds,* driver is for a spec defined class code which must be CXL.mem * capable, there is no point in continuing to enable CXL.mem. */ - hdm_count =FIELD_GET (CXL_DVSEC_HDM_COUNT_MASK , cap); + hdm_count =FIELD_GET (PCI_DVSEC_CXL_HDM_COUNT_MASK , cap);if (!hdm_count || hdm_count >2 )return -EINVAL ;
@@ -376,11 +376,11 @@ int cxl_dvsec_rr_decode(struct cxl_dev_state *cxlds,* disabled, and they will remain moot after the HDM Decoder * capability is enabled. */ - rc =pci_read_config_word (pdev, d +CXL_DVSEC_CTRL_OFFSET , &ctrl); + rc =pci_read_config_word (pdev, d +PCI_DVSEC_CXL_CTRL_OFFSET , &ctrl);if (rc)return rc; - info->mem_enabled =FIELD_GET (CXL_DVSEC_MEM_ENABLE , ctrl); + info->mem_enabled =FIELD_GET (PCI_DVSEC_CXL_MEM_ENABLE , ctrl);if (!info->mem_enabled)return 0 ;
@@ -393,35 +393,35 @@ int cxl_dvsec_rr_decode(struct cxl_dev_state *cxlds,return rc; rc =pci_read_config_dword ( - pdev, d +CXL_DVSEC_RANGE_SIZE_HIGH (i), &temp); + pdev, d +PCI_DVSEC_CXL_RANGE_SIZE_HIGH (i), &temp);if (rc)return rc; size = (u64 )temp <<32 ; rc =pci_read_config_dword ( - pdev, d +CXL_DVSEC_RANGE_SIZE_LOW (i), &temp); + pdev, d +PCI_DVSEC_CXL_RANGE_SIZE_LOW (i), &temp);if (rc)return rc; - size |= temp &CXL_DVSEC_MEM_SIZE_LOW_MASK ; + size |= temp &PCI_DVSEC_CXL_MEM_SIZE_LOW_MASK ;if (!size) {continue ; } rc =pci_read_config_dword ( - pdev, d +CXL_DVSEC_RANGE_BASE_HIGH (i), &temp); + pdev, d +PCI_DVSEC_CXL_RANGE_BASE_HIGH (i), &temp);if (rc)return rc; base = (u64 )temp <<32 ; rc =pci_read_config_dword ( - pdev, d +CXL_DVSEC_RANGE_BASE_LOW (i), &temp); + pdev, d +PCI_DVSEC_CXL_RANGE_BASE_LOW (i), &temp);if (rc)return rc; - base |= temp &CXL_DVSEC_MEM_BASE_LOW_MASK ; + base |= temp &PCI_DVSEC_CXL_MEM_BASE_LOW_MASK ; info->dvsec_range[ranges++] = (struct range ) { .start = base,
@@ -1147,7 +1147,7 @@ u16 cxl_gpf_get_dvsec(struct device *dev) is_port = false; dvsec =pci_find_dvsec_capability (pdev,PCI_VENDOR_ID_CXL , - is_port ?CXL_DVSEC_PORT_GPF :CXL_DVSEC_DEVICE_GPF ); + is_port ?PCI_DVSEC_CXL_PORT_GPF :PCI_DVSEC_CXL_DEVICE_GPF );if (!dvsec)dev_warn (dev,"%s GPF DVSEC not present\n" , is_port ?"Port" :"Device" );
@@ -1163,14 +1163,14 @@ static int update_gpf_port_dvsec(struct pci_dev *pdev, int dvsec, int phase)switch (phase) {case 1 : - offset =CXL_DVSEC_PORT_GPF_PHASE_1_CONTROL_OFFSET ; - base =CXL_DVSEC_PORT_GPF_PHASE_1_TMO_BASE_MASK ; - scale =CXL_DVSEC_PORT_GPF_PHASE_1_TMO_SCALE_MASK ; + offset =PCI_DVSEC_CXL_PORT_GPF_PHASE_1_CONTROL_OFFSET ; + base =PCI_DVSEC_CXL_PORT_GPF_PHASE_1_TMO_BASE_MASK ; + scale =PCI_DVSEC_CXL_PORT_GPF_PHASE_1_TMO_SCALE_MASK ;break ;case 2 : - offset =CXL_DVSEC_PORT_GPF_PHASE_2_CONTROL_OFFSET ; - base =CXL_DVSEC_PORT_GPF_PHASE_2_TMO_BASE_MASK ; - scale =CXL_DVSEC_PORT_GPF_PHASE_2_TMO_SCALE_MASK ; + offset =PCI_DVSEC_CXL_PORT_GPF_PHASE_2_CONTROL_OFFSET ; + base =PCI_DVSEC_CXL_PORT_GPF_PHASE_2_TMO_BASE_MASK ; + scale =PCI_DVSEC_CXL_PORT_GPF_PHASE_2_TMO_SCALE_MASK ;break ;default :return -EINVAL ;
drivers/cxl/core/regs.c +6 -6
@@ -271,10 +271,10 @@ EXPORT_SYMBOL_NS_GPL(cxl_map_device_regs, "CXL");static bool cxl_decode_regblock (struct pci_dev *pdev,u32 reg_lo,u32 reg_hi,struct cxl_register_map *map) { -u8 reg_type =FIELD_GET (CXL_DVSEC_REG_LOCATOR_BLOCK_ID_MASK , reg_lo); -int bar =FIELD_GET (CXL_DVSEC_REG_LOCATOR_BIR_MASK , reg_lo); +u8 reg_type =FIELD_GET (PCI_DVSEC_CXL_REG_LOCATOR_BLOCK_ID_MASK , reg_lo); +int bar =FIELD_GET (PCI_DVSEC_CXL_REG_LOCATOR_BIR_MASK , reg_lo);u64 offset = ((u64 )reg_hi <<32 ) | - (reg_lo &CXL_DVSEC_REG_LOCATOR_BLOCK_OFF_LOW_MASK ); + (reg_lo &PCI_DVSEC_CXL_REG_LOCATOR_BLOCK_OFF_LOW_MASK );if (offset >pci_resource_len (pdev, bar)) { dev_warn(&pdev->dev,
@@ -311,15 +311,15 @@ static int __cxl_find_regblock_instance(struct pci_dev *pdev, enum cxl_regloc_ty }; regloc =pci_find_dvsec_capability (pdev,PCI_VENDOR_ID_CXL , -CXL_DVSEC_REG_LOCATOR ); +PCI_DVSEC_CXL_REG_LOCATOR );if (!regloc)return -ENXIO ;pci_read_config_dword (pdev, regloc +PCI_DVSEC_HEADER1 , ®loc_size); regloc_size =FIELD_GET (PCI_DVSEC_HEADER1_LENGTH_MASK , regloc_size); - regloc +=CXL_DVSEC_REG_LOCATOR_BLOCK1_OFFSET ; - regblocks = (regloc_size -CXL_DVSEC_REG_LOCATOR_BLOCK1_OFFSET ) /8 ; + regloc +=PCI_DVSEC_CXL_REG_LOCATOR_BLOCK1_OFFSET ; + regblocks = (regloc_size -PCI_DVSEC_CXL_REG_LOCATOR_BLOCK1_OFFSET ) /8 ;for (i =0 ; i < regblocks; i++, regloc +=8 ) {u32 reg_lo, reg_hi;
drivers/cxl/cxlpci.h +0 -53
59 lines not on this page · raw message
drivers/cxl/pci.c +1 -1
@@ -933,7 +933,7 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) cxlds->rcd =is_cxl_restricted (pdev); cxlds->serial =pci_get_dsn (pdev); cxlds->cxl_dvsec =pci_find_dvsec_capability ( - pdev,PCI_VENDOR_ID_CXL ,CXL_DVSEC_PCIE_DEVICE ); + pdev,PCI_VENDOR_ID_CXL ,PCI_DVSEC_CXL_DEVICE );if (!cxlds->cxl_dvsec)dev_warn (&pdev->dev,"Device DVSEC not present, skip CXL.mem init\n" );
drivers/pci/pci.c +3 -1
@@ -5002,7 +5002,9 @@ static bool cxl_sbr_masked(struct pci_dev *dev)if (!dvsec)return false; - rc =pci_read_config_word (dev, dvsec +PCI_DVSEC_CXL_PORT_CTL , ®); + rc =pci_read_config_word (dev, + dvsec +PCI_DVSEC_CXL_PORT_CTL , + ®);if (rc ||PCI_POSSIBLE_ERROR (reg))return false;
include/uapi/linux/pci_regs.h +59 -4
68 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v13 2/25 PCI/CXL: Introduce pcie_is_cxl()
In reply to Terry BowmanCXL and AER drivers need the ability to identify CXL devices.
Introduce set_pcie_cxl() with logic checking for CXL.mem or CXL.cache status in the CXL Flexbus DVSEC status register. The CXL Flexbus DVSEC presence is used because it is required for all the CXL PCIe devices.[1]
Add boolean 'struct pci_dev::is_cxl' with the purpose to cache the CXL CXL.cache and CXl.mem status.
In the case the device is an EP or USP, call set_pcie_cxl() on behalf of the parent downstream device. Once a device is created there is possibilty the parent training or CXL state was updated as well. This will make certain the correct parent CXL state is cached.
Add function pcie_is_cxl() to return 'struct pci_dev::is_cxl'.
[1] CXL 3.1 Spec, 8.1.1 PCIe Designated Vendor-Specific Extended Capability (DVSEC) ID Assignment, Table 8-2
---
Changes in v12->v13:
- Add Ben's "reviewed-by"
Changes in v11->v12:
- Add review-by for Alejandro
- Add comment in set_pcie_cxl() explaining why updating parent status.
Changes in v10->v11:
- Amend set_pcie_cxl() to check for Upstream Port's and EP's parent downstream port by calling set_pcie_cxl(). (Dan)
- Retitle patch: 'Add' -> 'Introduce'
- Add check for CXL.mem and CXL.cache (Alejandro, Dan)
--- drivers/pci/probe.c | 29 +++++++++++++++++++++++++++++ include/linux/pci.h | 6 ++++++ 2 files changed, 35 insertions(+)
drivers/pci/probe.c +29 -0
@@ -1709,6 +1709,33 @@ static void set_pcie_thunderbolt(struct pci_dev *dev) dev->is_thunderbolt =1 ; } +static void set_pcie_cxl (struct pci_dev *dev) +{ +struct pci_dev *parent; +u16 dvsec =pci_find_dvsec_capability (dev,PCI_VENDOR_ID_CXL , +PCI_DVSEC_CXL_FLEXBUS_PORT ); +if (dvsec) { +u16 cap; + +pci_read_config_word (dev, dvsec +PCI_DVSEC_CXL_FLEXBUS_STATUS_OFFSET , &cap); + + dev->is_cxl =FIELD_GET (PCI_DVSEC_CXL_FLEXBUS_STATUS_CACHE_MASK , cap) || +FIELD_GET (PCI_DVSEC_CXL_FLEXBUS_STATUS_MEM_MASK , cap); + } + +if (!pci_is_pcie (dev) || + !(pci_pcie_type (dev) ==PCI_EXP_TYPE_ENDPOINT || +pci_pcie_type (dev) ==PCI_EXP_TYPE_UPSTREAM )) +return ; + +/* +* Update parent's CXL state because alternate protocol training +* may have changed +*/ + parent =pci_upstream_bridge (dev); +set_pcie_cxl (parent); +} +static void set_pcie_untrusted (struct pci_dev *dev) {struct pci_dev *parent =pci_upstream_bridge (dev);
@@ -2039,6 +2066,8 @@ int pci_setup_device(struct pci_dev *dev)/* Need to have dev->cfg_size ready */ set_pcie_thunderbolt (dev); +set_pcie_cxl (dev); +set_pcie_untrusted (dev);if (pci_is_pcie (dev))
include/linux/pci.h +6 -0
@@ -460,6 +460,7 @@ struct pci_dev { unsigned int is_pciehp:1; unsigned int shpc_managed:1; /* SHPC owned by shpchp */ unsigned int is_thunderbolt:1; /* Thunderbolt controller */ + unsigned int is_cxl:1; /* Compute Express Link (CXL) *//* * Devices marked being untrusted are the ones that can potentially * execute DMA attacks and similar. They are typically connected
@@ -766,6 +767,11 @@ static inline bool pci_is_display(struct pci_dev *pdev)return (pdev->class >>16 ) ==PCI_BASE_CLASS_DISPLAY ; } +static inline bool pcie_is_cxl (struct pci_dev *pci_dev) +{ +return pci_dev->is_cxl; +} +#define for_each_pci_bridge (dev, bus) \ list_for_each_entry(dev, &bus->devices, bus_list) \ if (!pci_is_bridge(dev)) {} else
Signature · 1 line
2.34.1
PATCH v13 3/25 cxl/pci: Remove unnecessary CXL Endpoint handling helper functions
In reply to Terry BowmanThe CXL driver's cxl_handle_endpoint_cor_ras()/cxl_handle_endpoint_ras() are unnecessary helper functions used only for Endpoints. Remove these functions as they are not common for all CXL devices and do not provide value for EP handling.
Rename __cxl_handle_ras to cxl_handle_ras() and __cxl_handle_cor_ras() to cxl_handle_cor_ras().
Changes in v12->v13:
- None
Changes in v11->v12:
- Added Dave Jiang's review by
- Moved to front of series
Changes in v10->v11:
- None
--- drivers/cxl/core/pci.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-)
drivers/cxl/core/pci.c +8 -18
@@ -711,8 +711,8 @@ void read_cdat_data(struct cxl_port *port) }EXPORT_SYMBOL_NS_GPL (read_cdat_data,"CXL" ); -static void __cxl_handle_cor_ras (struct cxl_dev_state *cxlds, -void __iomem *ras_base) +static void cxl_handle_cor_ras (struct cxl_dev_state *cxlds, +void __iomem *ras_base) {void __iomem *addr;u32 status;
@@ -728,11 +728,6 @@ static void __cxl_handle_cor_ras(struct cxl_dev_state *cxlds, } } -static void cxl_handle_endpoint_cor_ras (struct cxl_dev_state *cxlds) -{ -return __cxl_handle_cor_ras (cxlds, cxlds->regs.ras); -} -/* CXL spec rev3.0 8.2.4.16.1 */ static void header_log_copy (void __iomem *ras_base,u32 *log) {
@@ -754,8 +749,8 @@ static void header_log_copy(void __iomem *ras_base, u32 *log)* Log the state of the RAS status registers and prepare them to log the * next error status. Return 1 if reset needed. */ -static bool __cxl_handle_ras (struct cxl_dev_state *cxlds, -void __iomem *ras_base) +static bool cxl_handle_ras (struct cxl_dev_state *cxlds, +void __iomem *ras_base) {u32 hl[CXL_HEADERLOG_SIZE_U32 ];void __iomem *addr;
@@ -788,11 +783,6 @@ static bool __cxl_handle_ras(struct cxl_dev_state *cxlds,return true; } -static bool cxl_handle_endpoint_ras (struct cxl_dev_state *cxlds) -{ -return __cxl_handle_ras (cxlds, cxlds->regs.ras); -} -#ifdef CONFIG_PCIEAER_CXL static void cxl_dport_map_rch_aer (struct cxl_dport *dport)
@@ -871,13 +861,13 @@ EXPORT_SYMBOL_NS_GPL(cxl_dport_init_ras_reporting, "CXL");static void cxl_handle_rdport_cor_ras (struct cxl_dev_state *cxlds,struct cxl_dport *dport) { -return __cxl_handle_cor_ras (cxlds, dport->regs.ras); +return cxl_handle_cor_ras (cxlds, dport->regs.ras); }static bool cxl_handle_rdport_ras (struct cxl_dev_state *cxlds,struct cxl_dport *dport) { -return __cxl_handle_ras (cxlds, dport->regs.ras); +return cxl_handle_ras (cxlds, dport->regs.ras); }/*
@@ -974,7 +964,7 @@ void cxl_cor_error_detected(struct pci_dev *pdev)if (cxlds->rcd)cxl_handle_rdport_errors (cxlds); -cxl_handle_endpoint_cor_ras (cxlds); +cxl_handle_cor_ras (cxlds, cxlds->regs.ras); } }EXPORT_SYMBOL_NS_GPL (cxl_cor_error_detected,"CXL" );
@@ -1003,7 +993,7 @@ pci_ers_result_t cxl_error_detected(struct pci_dev *pdev,* chance the situation is recoverable dump the status of the RAS * capability registers and bounce the active state of the memdev. */ - ue =cxl_handle_endpoint_ras (cxlds); + ue =cxl_handle_ras (cxlds, cxlds->regs.ras); }
Signature · 1 line
2.34.1
PATCH v13 4/25 cxl/pci: Remove unnecessary CXL RCH handling helper functions
In reply to Terry Bowmancxl_handle_rdport_cor_ras() and cxl_handle_rdport_ras() are specific to Restricted CXL Host (RCH) handling. Improve readability and maintainability by replacing these and instead using the common cxl_handle_cor_ras() and cxl_handle_ras() functions.
---
Changes in v12->v13:
- None
Changes in v11->v12:
- Add reviewed-by for Alejandro & Dave Jiang
- Moved to front of series
Changes in v10->v11:
- New patch
--- drivers/cxl/core/pci.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-)
drivers/cxl/core/pci.c +2 -14
@@ -858,18 +858,6 @@ void cxl_dport_init_ras_reporting(struct cxl_dport *dport, struct device *host) }EXPORT_SYMBOL_NS_GPL (cxl_dport_init_ras_reporting,"CXL" ); -static void cxl_handle_rdport_cor_ras (struct cxl_dev_state *cxlds, -struct cxl_dport *dport) -{ -return cxl_handle_cor_ras (cxlds, dport->regs.ras); -} - -static bool cxl_handle_rdport_ras (struct cxl_dev_state *cxlds, -struct cxl_dport *dport) -{ -return cxl_handle_ras (cxlds, dport->regs.ras); -} -/* * Copy the AER capability registers using 32 bit read accesses. * This is necessary because RCRB AER capability is MMIO mapped. Clear the
@@ -939,9 +927,9 @@ static void cxl_handle_rdport_errors(struct cxl_dev_state *cxlds)pci_print_aer (pdev, severity, &aer_regs);if (severity ==AER_CORRECTABLE ) -cxl_handle_rdport_cor_ras (cxlds, dport); +cxl_handle_cor_ras (cxlds, dport->regs.ras);else - cxl_handle_rdport_ras(cxlds, dport); + cxl_handle_ras(cxlds, dport->regs.ras); }#else
Signature · 1 line
2.34.1
PATCH v13 5/25 cxl: Remove CXL VH handling in CONFIG_PCIEAER_CXL conditional blocks from core/pci.c
In reply to Terry BowmanFrom: Dave Jiang <[email protected]>
Create new config CONFIG_CXL_RAS and put all CXL RAS items behind the config. The config will depend on CPER and PCIE AER to build. Move the related VH RAS code from core/pci.c to core/ras.c.
Restricted CXL host (RCH) RAS functions will be moved in a future patch.
---
Changes in v11->v12:
- None
Changes in v10->v11:
- New patch
- Updated by Terry Bowman to use (ACPI_APEI_GHES && PCIEAER_CXL) dependency in Kconfig. Otherwise checks will be reauired for CONFIG_PCIEAER because AER driver functions are called.
--- drivers/cxl/Kconfig | 4 + drivers/cxl/core/Makefile | 2 +- drivers/cxl/core/core.h | 31 +++++++ drivers/cxl/core/pci.c | 189 +------------------------------------- drivers/cxl/core/ras.c | 176 +++++++++++++++++++++++++++++++++++ drivers/cxl/cxl.h | 8 -- drivers/cxl/cxlpci.h | 16 ++++ tools/testing/cxl/Kbuild | 2 +- 8 files changed, 233 insertions(+), 195 deletions(-)
drivers/cxl/Kconfig +4 -0
@@ -233,4 +233,8 @@ config CXL_MCE def_bool y depends on X86_MCE && MEMORY_FAILURE +config CXL_RAS + def_bool y + depends on ACPI_APEI_GHES && PCIEAER && CXL_PCI + endif
drivers/cxl/core/Makefile +1 -1
@@ -14,9 +14,9 @@ cxl_core-y += pci.o cxl_core-y += hdm.o cxl_core-y += pmu.o cxl_core-y += cdat.o -cxl_core-y += ras.o cxl_core-$(CONFIG_TRACING) += trace.o cxl_core-$(CONFIG_CXL_REGION) += region.o cxl_core-$(CONFIG_CXL_MCE) += mce.o cxl_core-$(CONFIG_CXL_FEATURES) += features.o cxl_core-$(CONFIG_CXL_EDAC_MEM_FEATURES) += edac.o +cxl_core-$(CONFIG_CXL_RAS) += ras.o
drivers/cxl/core/core.h +31 -0
@@ -144,8 +144,39 @@ int cxl_pci_get_bandwidth(struct pci_dev *pdev, struct access_coordinate *c);int cxl_port_get_switch_dport_bandwidth (struct cxl_port *port,struct access_coordinate *c); +#ifdef CONFIG_CXL_RAS int cxl_ras_init (void );void cxl_ras_exit (void ); +bool cxl_handle_ras (struct cxl_dev_state *cxlds,void __iomem *ras_base); +void cxl_handle_cor_ras (struct cxl_dev_state *cxlds,void __iomem *ras_base); +#else +static inline int cxl_ras_init (void ) +{ +return 0 ; +} + +static inline void cxl_ras_exit (void ) +{ +} + +static inline bool cxl_handle_ras (struct cxl_dev_state *cxlds,void __iomem *ras_base) +{ +return false; +} +static inline void cxl_handle_cor_ras (struct cxl_dev_state *cxlds,void __iomem *ras_base) { } +#endif /* CONFIG_CXL_RAS */ + +/* Restricted CXL Host specific RAS functions */ +#ifdef CONFIG_CXL_RAS +void cxl_dport_map_rch_aer (struct cxl_dport *dport); +void cxl_disable_rch_root_ints (struct cxl_dport *dport); +void cxl_handle_rdport_errors (struct cxl_dev_state *cxlds); +#else +static inline void cxl_dport_map_rch_aer (struct cxl_dport *dport) { } +static inline void cxl_disable_rch_root_ints (struct cxl_dport *dport) { } +static inline void cxl_handle_rdport_errors (struct cxl_dev_state *cxlds) { } +#endif /* CONFIG_CXL_RAS */ +int cxl_gpf_port_setup (struct cxl_dport *dport);struct cxl_hdm ;
drivers/cxl/core/pci.c +4 -185
221 lines not on this page · raw message
drivers/cxl/core/ras.c +176 -0
185 lines not on this page · raw message
drivers/cxl/cxl.h +0 -8
@@ -776,14 +776,6 @@ struct cxl_dport *devm_cxl_add_rch_dport(struct cxl_port *port, struct device *dport_dev, int port_id, resource_size_t rcrb); -#ifdef CONFIG_PCIEAER_CXL -void cxl_setup_parent_dport (struct device *host,struct cxl_dport *dport); -void cxl_dport_init_ras_reporting (struct cxl_dport *dport,struct device *host); -#else -static inline void cxl_dport_init_ras_reporting (struct cxl_dport *dport, -struct device *host) { } -#endif -struct cxl_decoder *to_cxl_decoder (struct device *dev);struct cxl_root_decoder *to_cxl_root_decoder (struct device *dev);struct cxl_switch_decoder *to_cxl_switch_decoder (struct device *dev);
drivers/cxl/cxlpci.h +16 -0
@@ -77,7 +77,23 @@ static inline bool cxl_pci_flit_256(struct pci_dev *pdev)int devm_cxl_port_enumerate_dports (struct cxl_port *port);struct cxl_dev_state ;void read_cdat_data (struct cxl_port *port); + +#ifdef CONFIG_CXL_RAS void cxl_cor_error_detected (struct pci_dev *pdev);pci_ers_result_t cxl_error_detected (struct pci_dev *pdev,pci_channel_state_t state); +void cxl_dport_init_ras_reporting (struct cxl_dport *dport,struct device *host); +#else +static inline void cxl_cor_error_detected (struct pci_dev *pdev) { } + +static inline pci_ers_result_t cxl_error_detected (struct pci_dev *pdev, +pci_channel_state_t state) +{ +return PCI_ERS_RESULT_NONE ; +} + +static inline void cxl_dport_init_ras_reporting (struct cxl_dport *dport, +struct device *host) { } +#endif +#endif /* __CXL_PCI_H__ */
tools/testing/cxl/Kbuild +1 -1
@@ -58,12 +58,12 @@ cxl_core-y += $(CXL_CORE_SRC)/pci.o cxl_core-y += $(CXL_CORE_SRC)/hdm.o cxl_core-y += $(CXL_CORE_SRC)/pmu.o cxl_core-y += $(CXL_CORE_SRC)/cdat.o -cxl_core-y += $(CXL_CORE_SRC)/ras.o cxl_core-$(CONFIG_TRACING) += $(CXL_CORE_SRC)/trace.o cxl_core-$(CONFIG_CXL_REGION) += $(CXL_CORE_SRC)/region.o cxl_core-$(CONFIG_CXL_MCE) += $(CXL_CORE_SRC)/mce.o cxl_core-$(CONFIG_CXL_FEATURES) += $(CXL_CORE_SRC)/features.o cxl_core-$(CONFIG_CXL_EDAC_MEM_FEATURES) += $(CXL_CORE_SRC)/edac.o +cxl_core-$(CONFIG_CXL_RAS) += $(CXL_CORE_SRC)/ras.o cxl_core-y += config_check.o cxl_core-y += cxl_core_test.o cxl_core-y += cxl_core_exports.o
Signature · 1 line
2.34.1
PATCH v13 6/25 cxl: Move CXL driver's RCH error handling into core/ras_rch.c
In reply to Terry BowmanRestricted CXL Host (RCH) protocol error handling uses a procedure distinct from the CXL Virtual Hierarchy (VH) handling. This is because of the differences in the RCH and VH topologies. Improve the maintainability and add ability to enable/disable RCH handling.
Move and combine the RCH handling code into a single block conditionally compiled with the CONFIG_CXL_RCH_RAS kernel config.
---
Changes in v12->v13:
- None
Changes v11->v12:
- Moved CXL_RCH_RAS Kconfig definition here from following commit.
Changes v10->v11:
- New patch
--- drivers/cxl/Kconfig | 7 +++ drivers/cxl/core/Makefile | 1 + drivers/cxl/core/core.h | 5 +- drivers/cxl/core/pci.c | 115 ----------------------------------- drivers/cxl/core/ras_rch.c | 120 +++++++++++++++++++++++++++++++++++++ tools/testing/cxl/Kbuild | 1 + 6 files changed, 132 insertions(+), 117 deletions(-) create mode 100644 drivers/cxl/core/ras_rch.c
drivers/cxl/Kconfig +7 -0
@@ -237,4 +237,11 @@ config CXL_RAS def_bool y depends on ACPI_APEI_GHES && PCIEAER && CXL_PCI +config CXL_RCH_RAS + bool "CXL: Restricted CXL Host (RCH) protocol error handling" + def_bool n + depends on CXL_RAS + help + RAS support for Restricted CXL Host (RCH) defined in CXL1.1. + endif
drivers/cxl/core/Makefile +1 -0
@@ -20,3 +20,4 @@ cxl_core-$(CONFIG_CXL_MCE) += mce.o cxl_core-$(CONFIG_CXL_FEATURES) += features.o cxl_core-$(CONFIG_CXL_EDAC_MEM_FEATURES) += edac.o cxl_core-$(CONFIG_CXL_RAS) += ras.o +cxl_core-$(CONFIG_CXL_RCH_RAS) += ras_rch.o
drivers/cxl/core/core.h +3 -2
@@ -4,6 +4,7 @@#ifndef __CXL_CORE_H__#define __CXL_CORE_H__ +#include <linux/pci.h> #include <cxl/mailbox.h> #include <linux/rwsem.h>
@@ -167,7 +168,7 @@ static inline void cxl_handle_cor_ras(struct cxl_dev_state *cxlds, void __iomem#endif /* CONFIG_CXL_RAS */ /* Restricted CXL Host specific RAS functions */ -#ifdef CONFIG_CXL_RAS +#ifdef CONFIG_CXL_RCH_RAS void cxl_dport_map_rch_aer (struct cxl_dport *dport);void cxl_disable_rch_root_ints (struct cxl_dport *dport);void cxl_handle_rdport_errors (struct cxl_dev_state *cxlds);
@@ -175,7 +176,7 @@ void cxl_handle_rdport_errors(struct cxl_dev_state *cxlds);static inline void cxl_dport_map_rch_aer (struct cxl_dport *dport) { }static inline void cxl_disable_rch_root_ints (struct cxl_dport *dport) { }static inline void cxl_handle_rdport_errors (struct cxl_dev_state *cxlds) { } -#endif /* CONFIG_CXL_RAS */ +#endif /* CONFIG_CXL_RCH_RAS */ int cxl_gpf_port_setup (struct cxl_dport *dport);
drivers/cxl/core/pci.c +0 -115
121 lines not on this page · raw message
drivers/cxl/core/ras_rch.c new file +120 -0
120 lines not on this page · raw message
tools/testing/cxl/Kbuild +1 -0
@@ -64,6 +64,7 @@ cxl_core-$(CONFIG_CXL_MCE) += $(CXL_CORE_SRC)/mce.o cxl_core-$(CONFIG_CXL_FEATURES) += $(CXL_CORE_SRC)/features.o cxl_core-$(CONFIG_CXL_EDAC_MEM_FEATURES) += $(CXL_CORE_SRC)/edac.o cxl_core-$(CONFIG_CXL_RAS) += $(CXL_CORE_SRC)/ras.o +cxl_core-$(CONFIG_CXL_RCH_RAS) += $(CXL_CORE_SRC)/ras_rch.o cxl_core-y += config_check.o cxl_core-y += cxl_core_test.o cxl_core-y += cxl_core_exports.o
Signature · 1 line
2.34.1
PATCH v13 7/25 CXL/AER: Replace device_lock() in cxl_rch_handle_error_iter() with guard() lock
In reply to Terry Bowmancxl_rch_handle_error_iter() includes a call to device_lock() using a goto for multiple return paths. Improve readability and maintainability by using the guard() lock variant.
---
Changes in v12->v13:
- New patch
--- drivers/pci/pcie/aer.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/pci/pcie/aer.c +2 -5
@@ -1187,12 +1187,11 @@ static int cxl_rch_handle_error_iter(struct pci_dev *dev, void *data)if (!is_cxl_mem_dev (dev) || !cxl_error_is_native (dev))return 0 ; -/* Protect dev->driver */ -device_lock (&dev->dev); +guard (device)(&dev->dev); err_handler = dev->driver ? dev->driver->err_handler :NULL ;if (!err_handler) - goto out; +return 0 ;if (info->severity ==AER_CORRECTABLE ) {if (err_handler->cor_error_detected)
@@ -1203,8 +1202,6 @@ static int cxl_rch_handle_error_iter(struct pci_dev *dev, void *data)else if (info->severity ==AER_FATAL ) err_handler->error_detected (dev, pci_channel_io_frozen); } -out: -device_unlock (&dev->dev);return 0 ; }
Signature · 1 line
2.34.1
PATCH v13 8/25 CXL/AER: Move AER drivers RCH error handling into pcie/aer_cxl_rch.c
In reply to Terry BowmanThe restricted CXL Host (RCH) AER error handling logic currently resides in the AER driver file, drivers/pci/pcie/aer.c. CXL specific changes are conditionally compiled using #ifdefs.
Improve the AER driver maintainability by separating the RCH specific logic from the AER driver's core functionality and removing the ifdefs. Introduce drivers/pci/pcie/aer_cxl_rch.c for moving the RCH AER logic into. Conditionally compile the file using the CONFIG_CXL_RCH_RAS Kconfig.
Move the CXL logic into the new file but leave helper functions in aer.c for now as they will be moved in future patch for CXL virtual hierarchy handling. Export the handler functions as needed. Export pci_aer_unmask_internal_errors() allowing for all subsystems to use. Avoid multiple declaration moves and export cxl_error_is_native() now to allow access from cxl_core.
Inorder to maintain compilation after the move other changes are required. Change cxl_rch_handle_error() & cxl_rch_enable_rcec() to be non-static inorder for accessing from the AER driver in aer.c.
Update the new file with the SPDX and 2023 AMD copyright notations because the RCH bits were initally contributed in 2023 by AMD.
---
Changes in v12->v13:
- Add forward declararation of 'struct aer_err_info' in pci/pci.h (Terry)
- Changed copyright date from 2025 to 2023 (Jonathan)
- Add David Jiang's, Jonathan's, and Ben's review-by
- Readd 'struct aer_err_info' (Bot)
Changes in v11->v12:
- Rename drivers/pci/pcie/cxl_rch.c to drivers/pci/pcie/aer_cxl_rch.c (Lukas)
- Removed forward declararation of 'struct aer_err_info' in pci/pci.h (Terry)
Changes in v10->v11:
- Remove changes in code-split and move to earlier, new patch
- Add #include <linux/bitfield.h> to cxl_ras.c
- Move cxl_rch_handle_error() & cxl_rch_enable_rcec() declarations from pci.h to aer.h, more localized.
- Introduce CONFIG_CXL_RCH_RAS, includes Makefile changes, ras.c ifdef changes
--- drivers/pci/pci.h | 16 +++++ drivers/pci/pcie/Makefile | 1 + drivers/pci/pcie/aer.c | 105 +++------------------------------ drivers/pci/pcie/aer_cxl_rch.c | 96 ++++++++++++++++++++++++++++++ include/linux/aer.h | 8 +++ 5 files changed, 128 insertions(+), 98 deletions(-) create mode 100644 drivers/pci/pcie/aer_cxl_rch.c
drivers/pci/pci.h +16 -0
@@ -1295,4 +1295,20 @@ static inline int pci_msix_write_tph_tag(struct pci_dev *pdev, unsigned int inde (PCI_CONF1_ADDRESS (bus, dev, func, reg) | \ PCI_CONF1_EXT_REG(reg)) +struct aer_err_info ; + +#ifdef CONFIG_CXL_RCH_RAS +void cxl_rch_handle_error (struct pci_dev *dev,struct aer_err_info *info); +void cxl_rch_enable_rcec (struct pci_dev *rcec); +#else +static inline void cxl_rch_handle_error (struct pci_dev *dev,struct aer_err_info *info) { } +static inline void cxl_rch_enable_rcec (struct pci_dev *rcec) { } +#endif + +#ifdef CONFIG_CXL_RAS +bool is_internal_error (struct aer_err_info *info); +#else +static inline bool is_internal_error (struct aer_err_info *info) {return false; } +#endif +#endif /* DRIVERS_PCI_H */
drivers/pci/pcie/Makefile +1 -0
@@ -8,6 +8,7 @@ obj-$(CONFIG_PCIEPORTBUS) += pcieportdrv.o bwctrl.o obj-y += aspm.o obj-$(CONFIG_PCIEAER) += aer.o err.o tlp.o +obj-$(CONFIG_CXL_RCH_RAS) += aer_cxl_rch.o obj-$(CONFIG_PCIEAER_INJECT) += aer_inject.o obj-$(CONFIG_PCIE_PME) += pme.o obj-$(CONFIG_PCIE_DPC) += dpc.o
drivers/pci/pcie/aer.c +7 -98
130 lines not on this page · raw message
drivers/pci/pcie/aer_cxl_rch.c new file +96 -0
96 lines not on this page · raw message
include/linux/aer.h +8 -0
@@ -56,12 +56,20 @@ struct aer_capability_regs {#if defined(CONFIG_PCIEAER )int pci_aer_clear_nonfatal_status (struct pci_dev *dev);int pcie_aer_is_native (struct pci_dev *dev); +void pci_aer_unmask_internal_errors (struct pci_dev *dev);#else static inline int pci_aer_clear_nonfatal_status (struct pci_dev *dev) {return -EINVAL ; }static inline int pcie_aer_is_native (struct pci_dev *dev) {return 0 ; } +static inline void pci_aer_unmask_internal_errors (struct pci_dev *dev) { } +#endif + +#ifdef CONFIG_CXL_RAS +bool cxl_error_is_native (struct pci_dev *dev); +#else +static inline bool cxl_error_is_native (struct pci_dev *dev) {return false; }#endif void pci_print_aer(struct pci_dev *dev, int aer_severity,
Signature · 1 line
2.34.1
PATCH v13 9/25 PCI/AER: Report CXL or PCIe bus error type in trace logging
In reply to Terry BowmanThe AER service driver and aer_event tracing currently log 'PCIe Bus Type' for all errors. Update the driver and aer_event tracing to log 'CXL Bus Type' for CXL device errors.
This requires the AER can identify and distinguish between PCIe errors and CXL errors.
Introduce boolean 'is_cxl' to 'struct aer_err_info'. Add assignment in aer_get_device_error_info() and pci_print_aer().
Update the aer_event trace routine to accept a bus type string parameter.
---
Changes in v12->v13:
- Remove duplicated aer_err_info inline comments. Is already in the kernel-doc header (Ben)
Changes in v11->v12:
- Change aer_err_info::is_cxl to be bool a bitfield. Update structure padding. (Lukas)
- Add kernel-doc for 'struct aer_err_info' (Lukas)
Changes in v10->v11:
- Remove duplicate call to trace_aer_event() (Shiju)
- Added Dan William's and Dave Jiang's reviewed-by
--- drivers/pci/pci.h | 37 ++++++++++++++++++++++++++++++------- drivers/pci/pcie/aer.c | 18 ++++++++++++------ include/ras/ras_event.h | 9 ++++++--- 3 files changed, 48 insertions(+), 16 deletions(-)
drivers/pci/pci.h +30 -7
@@ -701,31 +701,54 @@ static inline bool pci_dev_binding_disallowed(struct pci_dev *dev)#define AER_MAX_MULTI_ERR_DEVICES 5/* Not likely to have more */ +/** +* struct aer_err_info - AER Error Information +* @dev: Devices reporting error +* @ratelimit_print: Flag to log or not log the devices' error. 0=NotLog/1=Log +* @error_devnum: Number of devices reporting an error +* @level: printk level to use in logging +* @id: Value from register PCI_ERR_ROOT_ERR_SRC +* @severity: AER severity, 0-UNCOR Non-fatal, 1-UNCOR fatal, 2-COR +* @root_ratelimit_print: Flag to log or not log the root's error. 0=NotLog/1=Log +* @multi_error_valid: If multiple errors are reported +* @first_error: First reported error +* @is_cxl: Bus type error: 0-PCI Bus error, 1-CXL Bus error +* @tlp_header_valid: Indicates if TLP field contains error information +* @status: COR/UNCOR error status +* @mask: COR/UNCOR mask +* @tlp: Transaction packet information +*/ struct aer_err_info {struct pci_dev *dev[AER_MAX_MULTI_ERR_DEVICES ];int ratelimit_print[AER_MAX_MULTI_ERR_DEVICES ];int error_dev_num; -const char *level;/* printk level */ +const char *level;unsigned int id:16 ; -unsigned int severity:2 ;/* 0:NONFATAL | 1:FATAL | 2:COR */ -unsigned int root_ratelimit_print:1 ;/* 0=skip, 1=print */ +unsigned int severity:2 ; +unsigned int root_ratelimit_print:1 ;unsigned int __pad1:4 ;unsigned int multi_error_valid:1 ;unsigned int first_error:5 ; -unsigned int __pad2:2 ; +unsigned int __pad2:1 ; +bool is_cxl:1 ;unsigned int tlp_header_valid:1 ; -unsigned int status;/* COR/UNCOR Error Status */ -unsigned int mask;/* COR/UNCOR Error Mask */ -struct pcie_tlp_log tlp;/* TLP Header */ +unsigned int status; +unsigned int mask; +struct pcie_tlp_log tlp; };int aer_get_device_error_info (struct aer_err_info *info,int i);void aer_print_error (struct aer_err_info *info,int i); +static inline const char *aer_err_bus (struct aer_err_info *info) +{ +return info->is_cxl ?"CXL" :"PCIe" ; +} +int pcie_read_tlp_log (struct pci_dev *dev,int where,int where2,unsigned int tlp_len,bool flit,struct pcie_tlp_log *log);
drivers/pci/pcie/aer.c +12 -6
@@ -868,6 +868,7 @@ void aer_print_error(struct aer_err_info *info, int i)struct pci_dev *dev;int layer, agent, id;const char *level = info->level; +const char *bus_type =aer_err_bus (info);if (WARN_ON_ONCE (i >=AER_MAX_MULTI_ERR_DEVICES ))return ;
@@ -876,23 +877,23 @@ void aer_print_error(struct aer_err_info *info, int i) id =pci_dev_id (dev);pci_dev_aer_stats_incr (dev, info); -trace_aer_event (pci_name (dev), (info->status & ~info->mask), +trace_aer_event (pci_name (dev), bus_type, (info->status & ~info->mask), info->severity, info->tlp_header_valid, &info->tlp);if (!info->ratelimit_print[i])return ;if (!info->status) { -pci_err (dev,"PCIe Bus Error: severity=%s, type=Inaccessible, (Unregistered Agent ID)\n" , - aer_error_severity_string[info->severity]); +pci_err (dev,"%s Bus Error: severity=%s, type=Inaccessible, (Unregistered Agent ID)\n" , + bus_type, aer_error_severity_string[info->severity]); goto out; } layer =AER_GET_LAYER_ERROR (info->severity, info->status); agent =AER_GET_AGENT (info->severity, info->status); -aer_printk (level, dev,"PCIe Bus Error: severity=%s, type=%s, (%s)\n" , - aer_error_severity_string[info->severity], +aer_printk (level, dev,"%s Bus Error: severity=%s, type=%s, (%s)\n" , + bus_type, aer_error_severity_string[info->severity], aer_error_layer[layer], aer_agent_string[agent]); aer_printk(level, dev, " device [%04x:%04x] error status/mask=%08x/%08x\n",
@@ -926,6 +927,7 @@ EXPORT_SYMBOL_GPL(cper_severity_to_aer);void pci_print_aer (struct pci_dev *dev,int aer_severity,struct aer_capability_regs *aer) { +const char *bus_type;int layer, agent, tlp_header_valid =0 ;u32 status, mask;struct aer_err_info info = {
@@ -946,9 +948,12 @@ void pci_print_aer(struct pci_dev *dev, int aer_severity, info.status = status; info.mask = mask; + info.is_cxl =pcie_is_cxl (dev); + + bus_type =aer_err_bus (&info);pci_dev_aer_stats_incr (dev, &info); -trace_aer_event (pci_name (dev), (status & ~mask), +trace_aer_event (pci_name (dev), bus_type, (status & ~mask), aer_severity, tlp_header_valid, &aer->header_log);if (!aer_ratelimit (dev, info.severity))
@@ -1309,6 +1314,7 @@ int aer_get_device_error_info(struct aer_err_info *info, int i)/* Must reset in this function */ info->status =0 ; info->tlp_header_valid =0 ; + info->is_cxl =pcie_is_cxl (dev);/* The device might not support AER */ if (!aer)
include/ras/ras_event.h +6 -3
@@ -298,15 +298,17 @@ TRACE_EVENT(non_standard_event, TRACE_EVENT(aer_event, TP_PROTO(const char *dev_name, + const char *bus_type, const u32 status, const u8 severity, const u8 tlp_header_valid, struct pcie_tlp_log *tlp), - TP_ARGS(dev_name, status, severity, tlp_header_valid, tlp), + TP_ARGS(dev_name, bus_type, status, severity, tlp_header_valid, tlp), TP_STRUCT__entry( __string( dev_name, dev_name ) + __string( bus_type, bus_type ) __field( u32, status ) __field( u8, severity ) __field( u8, tlp_header_valid)
@@ -315,6 +317,7 @@ TRACE_EVENT(aer_event,TP_fast_assign ( __assign_str(dev_name); +__assign_str (bus_type); __entry->status = status; __entry->severity = severity; __entry->tlp_header_valid = tlp_header_valid;
@@ -326,8 +329,8 @@ TRACE_EVENT(aer_event, } ), - TP_printk("%s PCIe Bus Error: severity=%s, %s, TLP Header=%s\n", - __get_str(dev_name), + TP_printk("%s %s Bus Error: severity=%s, %s, TLP Header=%s\n", + __get_str(dev_name), __get_str(bus_type), __entry->severity == AER_CORRECTABLE ? "Corrected" : __entry->severity == AER_FATAL ? "Fatal" : "Uncorrected, non-fatal",
Signature · 1 line
2.34.1
PATCH v13 10/25 cxl/pci: Update RAS handler interfaces to also support CXL Ports
In reply to Terry BowmanCXL PCIe Port Protocol Error handling support will be added to the CXL drivers in the future. In preparation, rename the existing interfaces to support handling all CXL PCIe Port Protocol Errors.
The driver's RAS support functions currently rely on a 'struct cxl_dev_state' type parameter, which is not available for CXL Port devices. However, since the same CXL RAS capability structure is needed across most CXL components and devices, a common handling approach should be adopted.
To accommodate this, update the __cxl_handle_cor_ras() and __cxl_handle_ras() functions to use a struct device instead of struct cxl_dev_state.
No functional changes are introduced.
[1] CXL 3.1 Spec, 8.2.4 CXL.cache and CXL.mem Registers
---
Changes in v12->v13:
- Added Ben's review-by
--- drivers/cxl/core/core.h | 15 ++++++--------- drivers/cxl/core/ras.c | 12 ++++++------ drivers/cxl/core/ras_rch.c | 4 ++-- 3 files changed, 14 insertions(+), 17 deletions(-)
drivers/cxl/core/core.h +6 -9
@@ -7,6 +7,7 @@#include <linux/pci.h> #include <cxl/mailbox.h> #include <linux/rwsem.h> +#include <linux/pci.h> extern const struct device_type cxl_nvdimm_bridge_type;extern const struct device_type cxl_nvdimm_type;
@@ -148,23 +149,19 @@ int cxl_port_get_switch_dport_bandwidth(struct cxl_port *port,#ifdef CONFIG_CXL_RAS int cxl_ras_init (void );void cxl_ras_exit (void ); -bool cxl_handle_ras (struct cxl_dev_state *cxlds,void __iomem *ras_base); -void cxl_handle_cor_ras (struct cxl_dev_state *cxlds,void __iomem *ras_base); +bool cxl_handle_ras (struct device *dev,void __iomem *ras_base); +void cxl_handle_cor_ras (struct device *dev,void __iomem *ras_base);#else static inline int cxl_ras_init (void ) {return 0 ; } - -static inline void cxl_ras_exit (void ) -{ -} - -static inline bool cxl_handle_ras (struct cxl_dev_state *cxlds,void __iomem *ras_base) +static inline void cxl_ras_exit (void ) { } +static inline bool cxl_handle_ras (struct device *dev,void __iomem *ras_base) {return false; } -static inline void cxl_handle_cor_ras (struct cxl_dev_state *cxlds,void __iomem *ras_base) { } +static inline void cxl_handle_cor_ras (struct device *dev,void __iomem *ras_base) { }#endif /* CONFIG_CXL_RAS */ /* Restricted CXL Host specific RAS functions */
drivers/cxl/core/ras.c +6 -6
@@ -160,7 +160,7 @@ void cxl_dport_init_ras_reporting(struct cxl_dport *dport, struct device *host) }EXPORT_SYMBOL_NS_GPL (cxl_dport_init_ras_reporting,"CXL" ); -void cxl_handle_cor_ras (struct cxl_dev_state *cxlds,void __iomem *ras_base) +void cxl_handle_cor_ras (struct device *dev,void __iomem *ras_base) {void __iomem *addr;u32 status;
@@ -172,7 +172,7 @@ void cxl_handle_cor_ras(struct cxl_dev_state *cxlds, void __iomem *ras_base) status =readl (addr);if (status &CXL_RAS_CORRECTABLE_STATUS_MASK ) {writel (status &CXL_RAS_CORRECTABLE_STATUS_MASK , addr); -trace_cxl_aer_correctable_error (cxlds->cxlmd, status); +trace_cxl_aer_correctable_error (to_cxl_memdev (dev), status); } }
@@ -197,7 +197,7 @@ static void header_log_copy(void __iomem *ras_base, u32 *log)* Log the state of the RAS status registers and prepare them to log the * next error status. Return 1 if reset needed. */ -bool cxl_handle_ras (struct cxl_dev_state *cxlds,void __iomem *ras_base) +bool cxl_handle_ras (struct device *dev,void __iomem *ras_base) {u32 hl[CXL_HEADERLOG_SIZE_U32 ];void __iomem *addr;
@@ -224,7 +224,7 @@ bool cxl_handle_ras(struct cxl_dev_state *cxlds, void __iomem *ras_base) }header_log_copy (ras_base, hl); -trace_cxl_aer_uncorrectable_error (cxlds->cxlmd, status, fe, hl); +trace_cxl_aer_uncorrectable_error (to_cxl_memdev (dev), status, fe, hl);writel (status &CXL_RAS_UNCORRECTABLE_STATUS_MASK , addr);return true;
@@ -246,7 +246,7 @@ void cxl_cor_error_detected(struct pci_dev *pdev)if (cxlds->rcd)cxl_handle_rdport_errors (cxlds); -cxl_handle_cor_ras (cxlds, cxlds->regs.ras); +cxl_handle_cor_ras (&cxlds->cxlmd->dev, cxlds->regs.ras); } }EXPORT_SYMBOL_NS_GPL (cxl_cor_error_detected,"CXL" );
@@ -275,7 +275,7 @@ pci_ers_result_t cxl_error_detected(struct pci_dev *pdev,* chance the situation is recoverable dump the status of the RAS * capability registers and bounce the active state of the memdev. */ - ue =cxl_handle_ras (cxlds, cxlds->regs.ras); + ue =cxl_handle_ras (&cxlds->cxlmd->dev, cxlds->regs.ras); }
drivers/cxl/core/ras_rch.c +2 -2
@@ -114,7 +114,7 @@ void cxl_handle_rdport_errors(struct cxl_dev_state *cxlds)pci_print_aer (pdev, severity, &aer_regs);if (severity ==AER_CORRECTABLE ) -cxl_handle_cor_ras (cxlds, dport->regs.ras); +cxl_handle_cor_ras (&cxlds->cxlmd->dev, dport->regs.ras);else -cxl_handle_ras (cxlds, dport->regs.ras); +cxl_handle_ras (&cxlds->cxlmd->dev, dport->regs.ras); }
Signature · 1 line
2.34.1
PATCH v13 11/25 cxl/pci: Log message if RAS registers are unmapped
In reply to Terry BowmanThe CXL RAS handlers do not currently log if the RAS registers are unmapped. This is needed in order to help debug CXL error handling. Update the CXL driver to log a warning message if the RAS register block is unmapped during RAS error handling.
---
Chan ges in v12->v13:
- Added Bens review-by
--- drivers/cxl/core/ras.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/cxl/core/ras.c +6 -2
@@ -165,8 +165,10 @@ void cxl_handle_cor_ras(struct device *dev, void __iomem *ras_base)void __iomem *addr;u32 status; -if (!ras_base) +if (!ras_base) { +dev_warn_once (dev,"CXL RAS register block is not mapped" );return ; + } addr = ras_base +CXL_RAS_CORRECTABLE_STATUS_OFFSET ; status =readl (addr);
@@ -204,8 +206,10 @@ bool cxl_handle_ras(struct device *dev, void __iomem *ras_base)u32 status;u32 fe; -if (!ras_base) +if (!ras_base) { +dev_warn_once (dev,"CXL RAS register block is not mapped" );return false; + } addr = ras_base +CXL_RAS_UNCORRECTABLE_STATUS_OFFSET ; status =readl (addr);
Signature · 1 line
2.34.1
PATCH v13 12/25 cxl/pci: Unify CXL trace logging for CXL Endpoints and CXL Ports
In reply to Terry BowmanCXL currently has separate trace routines for CXL Port errors and CXL Endpoint errors. This is inconvenient for the user because they must enable 2 sets of trace routines. Make updates to the trace logging such that a single trace routine logs both CXL Endpoint and CXL Port protocol errors.
Keep the trace log fields 'memdev' and 'host'. While these are not accurate for non-Endpoints the fields will remain as-is to prevent breaking userspace RAS trace consumers.
Add serial number parameter to the trace logging. This is used for EPs and 0 is provided for CXL port devices without a serial number.
Leave the correctable and uncorrectable trace routines' TP_STRUCT__entry() unchanged with respect to member data types and order.
Below is output of correctable and uncorrectable protocol error logging. CXL Root Port and CXL Endpoint examples are included below.
Root Port:cxl_aer_correctable_error: memdev=0000:0c:00.0 host=pci0000:0c serial: 0 status='CRC Threshold Hit'cxl_aer_uncorrectable_error: memdev=0000:0c:00.0 host=pci0000:0c serial: 0 status: 'Cache Byte Enable Parity Error' first_error: 'Cache Byte Enable Parity Error'
Endpoint:cxl_aer_correctable_error: memdev=mem3 host=0000:0f:00.0 serial=0 status='CRC Threshold Hit'cxl_aer_uncorrectable_error: memdev=mem3 host=0000:0f:00.0 serial: 0 status: 'Cache Byte Enable Parity Error' first_error: 'Cache Byte Enable Parity Error'
---
Changes in v12->v13:
- Added Dave Jiang's review-by
Changes in v11 -> v12:
- Correct parameters to call trace_cxl_aer_correctable_error()
- Add reviewed-by for Jonathan and Shiju
Changes in v10->v11:
- Updated CE and UCE trace routines to maintain consistent TP_Struct ABI and unchanged TP_printk() logging.
--- drivers/cxl/core/core.h | 4 +-- drivers/cxl/core/ras.c | 26 ++++++++------- drivers/cxl/core/ras_rch.c | 4 +-- drivers/cxl/core/trace.h | 68 ++++++-------------------------------- 4 files changed, 29 insertions(+), 73 deletions(-)
drivers/cxl/core/core.h +2 -2
@@ -149,8 +149,8 @@ int cxl_port_get_switch_dport_bandwidth(struct cxl_port *port,#ifdef CONFIG_CXL_RAS int cxl_ras_init (void );void cxl_ras_exit (void ); -bool cxl_handle_ras (struct device *dev,void __iomem *ras_base); -void cxl_handle_cor_ras (struct device *dev,void __iomem *ras_base); +bool cxl_handle_ras (struct device *dev,u64 serial,void __iomem *ras_base); +void cxl_handle_cor_ras (struct device *dev,u64 serial,void __iomem *ras_base);#else static inline int cxl_ras_init (void ) {
drivers/cxl/core/ras.c +14 -12
@@ -13,7 +13,7 @@ static void cxl_cper_trace_corr_port_prot_err(struct pci_dev *pdev, {u32 status = ras_cap.cor_status & ~ras_cap.cor_mask; -trace_cxl_port_aer_correctable_error (&pdev->dev, status); +trace_cxl_aer_correctable_error (&pdev->dev, status,0 ); } static void cxl_cper_trace_uncorr_port_prot_err(struct pci_dev *pdev,
@@ -28,8 +28,8 @@ static void cxl_cper_trace_uncorr_port_prot_err(struct pci_dev *pdev,else fe = status; -trace_cxl_port_aer_uncorrectable_error (&pdev->dev, status, fe, - ras_cap.header_log); +trace_cxl_aer_uncorrectable_error (&pdev->dev, status, fe, + ras_cap.header_log,0 ); } static void cxl_cper_trace_corr_prot_err(struct cxl_memdev *cxlmd,
@@ -37,7 +37,7 @@ static void cxl_cper_trace_corr_prot_err(struct cxl_memdev *cxlmd, {u32 status = ras_cap.cor_status & ~ras_cap.cor_mask; -trace_cxl_aer_correctable_error (cxlmd, status); +trace_cxl_aer_correctable_error (&cxlmd->dev, status, cxlmd->cxlds->serial); } static void
@@ -45,6 +45,7 @@ cxl_cper_trace_uncorr_prot_err(struct cxl_memdev *cxlmd, struct cxl_ras_capability_regs ras_cap) {u32 status = ras_cap.uncor_status & ~ras_cap.uncor_mask; +struct cxl_dev_state *cxlds = cxlmd->cxlds;u32 fe;if (hweight32 (status) >1 )
@@ -53,8 +54,9 @@ cxl_cper_trace_uncorr_prot_err(struct cxl_memdev *cxlmd,else fe = status; -trace_cxl_aer_uncorrectable_error (cxlmd, status, fe, - ras_cap.header_log); +trace_cxl_aer_uncorrectable_error (&cxlmd->dev, status, fe, + ras_cap.header_log, + cxlds->serial); }static int match_memdev_by_parent (struct device *dev,const void *uport)
@@ -160,7 +162,7 @@ void cxl_dport_init_ras_reporting(struct cxl_dport *dport, struct device *host) }EXPORT_SYMBOL_NS_GPL (cxl_dport_init_ras_reporting,"CXL" ); -void cxl_handle_cor_ras (struct device *dev,void __iomem *ras_base) +void cxl_handle_cor_ras (struct device *dev,u64 serial,void __iomem *ras_base) {void __iomem *addr;u32 status;
@@ -174,7 +176,7 @@ void cxl_handle_cor_ras(struct device *dev, void __iomem *ras_base) status =readl (addr);if (status &CXL_RAS_CORRECTABLE_STATUS_MASK ) {writel (status &CXL_RAS_CORRECTABLE_STATUS_MASK , addr); -trace_cxl_aer_correctable_error (to_cxl_memdev (dev), status); +trace_cxl_aer_correctable_error (dev, status, serial); } }
@@ -199,7 +201,7 @@ static void header_log_copy(void __iomem *ras_base, u32 *log)* Log the state of the RAS status registers and prepare them to log the * next error status. Return 1 if reset needed. */ -bool cxl_handle_ras (struct device *dev,void __iomem *ras_base) +bool cxl_handle_ras (struct device *dev,u64 serial,void __iomem *ras_base) {u32 hl[CXL_HEADERLOG_SIZE_U32 ];void __iomem *addr;
@@ -228,7 +230,7 @@ bool cxl_handle_ras(struct device *dev, void __iomem *ras_base) }header_log_copy (ras_base, hl); -trace_cxl_aer_uncorrectable_error (to_cxl_memdev (dev), status, fe, hl); +trace_cxl_aer_uncorrectable_error (dev, status, fe, hl, serial);writel (status &CXL_RAS_UNCORRECTABLE_STATUS_MASK , addr);return true;
@@ -250,7 +252,7 @@ void cxl_cor_error_detected(struct pci_dev *pdev)if (cxlds->rcd)cxl_handle_rdport_errors (cxlds); -cxl_handle_cor_ras (&cxlds->cxlmd->dev, cxlds->regs.ras); +cxl_handle_cor_ras (&cxlds->cxlmd->dev, cxlds->serial, cxlds->regs.ras); } }EXPORT_SYMBOL_NS_GPL (cxl_cor_error_detected,"CXL" );
@@ -279,7 +281,7 @@ pci_ers_result_t cxl_error_detected(struct pci_dev *pdev,* chance the situation is recoverable dump the status of the RAS * capability registers and bounce the active state of the memdev. */ - ue =cxl_handle_ras (&cxlds->cxlmd->dev, cxlds->regs.ras); + ue =cxl_handle_ras (&cxlds->cxlmd->dev, cxlds->serial, cxlds->regs.ras); }
drivers/cxl/core/ras_rch.c +2 -2
@@ -114,7 +114,7 @@ void cxl_handle_rdport_errors(struct cxl_dev_state *cxlds)pci_print_aer (pdev, severity, &aer_regs);if (severity ==AER_CORRECTABLE ) -cxl_handle_cor_ras (&cxlds->cxlmd->dev, dport->regs.ras); +cxl_handle_cor_ras (&cxlds->cxlmd->dev,0 , dport->regs.ras);else -cxl_handle_ras (&cxlds->cxlmd->dev, dport->regs.ras); +cxl_handle_ras (&cxlds->cxlmd->dev,0 , dport->regs.ras); }
drivers/cxl/core/trace.h +11 -57
96 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v13 13/25 cxl/pci: Update cxl_handle_cor_ras() to return early if no RAS errors
In reply to Terry BowmanUpdate cxl_handle_cor_ras() to exit early in the case there is no RAS errors detected after applying the status mask. This change will make the correctable handler's implementation consistent with the uncorrectable handler, cxl_handle_ras().
---
Changes v12->v13:
- Added Ben's review-by
Changes v11->v12:
- None
Changes v10->v11:
- Added Dave Jiang and Jonathan Cameron's review-by
- Changes moved to core/ras.c
--- drivers/cxl/core/ras.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/cxl/core/ras.c +5 -4
@@ -174,10 +174,11 @@ void cxl_handle_cor_ras(struct device *dev, u64 serial, void __iomem *ras_base) addr = ras_base +CXL_RAS_CORRECTABLE_STATUS_OFFSET ; status =readl (addr); -if (status &CXL_RAS_CORRECTABLE_STATUS_MASK ) { -writel (status &CXL_RAS_CORRECTABLE_STATUS_MASK , addr); -trace_cxl_aer_correctable_error (dev, status, serial); - } +if (!(status &CXL_RAS_CORRECTABLE_STATUS_MASK )) +return ; +writel (status &CXL_RAS_CORRECTABLE_STATUS_MASK , addr); + +trace_cxl_aer_correctable_error (dev, status, serial); }/* CXL spec rev3.0 8.2.4.16.1 */
Signature · 1 line
2.34.1
PATCH v13 14/25 cxl/pci: Map CXL Endpoint Port and CXL Switch Port RAS registers
In reply to Terry BowmanCXL Endpoint (EP) Ports may include Root Ports (RP) or Downstream Switch Ports (DSP). CXL RPs and DSPs contain RAS registers that require memory mapping to enable RAS logging. This initialization is currently missing and must be added for CXL RPs and DSPs.
Update cxl_dport_init_ras_reporting() to support RP and DSP RAS mapping. Add alongside the existing Restricted CXL Host Downstream Port RAS mapping.
Update cxl_endpoint_port_probe() to invoke cxl_dport_init_ras_reporting(). This will initiate the RAS mapping for CXL RPs and DSPs when each CXL EP is created and added to the EP port.
Make a call to cxl_port_setup_regs() in cxl_port_add(). This will probe the Upstream Port's CXL capabilities' physical location to be used in mapping the RAS registers.
---
Changes in v12->v13:
- Change as result of dport delay fix. No longer need switchport and endport approach. (Terry)
Changes in v11->v12:
- Add check for dport_parent->rch before calling cxl_dport_init_ras_reporting(). RCH dports are initialized from cxl_dport_init_ras_reporting cxl_mem_probe().
Changes in v10->v11:
- Use local pointer for readability in cxl_switch_port_init_ras() (Jonathan Cameron)
- Rename port to be ep in cxl_endpoint_port_init_ras() (Dave Jiang)
- Rename dport to be parent_dport in cxl_endpoint_port_init_ras()
and cxl_switch_port_init_ras() (Dave Jiang)
- Port helper changes were in cxl/port.c, now in core/ras.c (Dave Jiang)
--- drivers/cxl/core/port.c | 4 ++++ drivers/cxl/core/ras.c | 12 ++++++++++++ drivers/cxl/cxl.h | 2 ++ drivers/cxl/cxlpci.h | 4 ++++ drivers/cxl/mem.c | 3 ++- 5 files changed, 24 insertions(+), 1 deletion(-)
drivers/cxl/core/port.c +4 -0
@@ -1194,6 +1194,8 @@ __devm_cxl_add_dport(struct cxl_port *port, struct device *dport_dev,return ERR_PTR (rc); } port->component_reg_phys =CXL_RESOURCE_NONE ; +if (!is_cxl_endpoint (port) &&dev_is_pci (port->uport_dev)) +cxl_uport_init_ras_reporting (port, &port->dev); }get_device (dport_dev);
@@ -1623,6 +1625,8 @@ static struct cxl_dport *cxl_port_add_dport(struct cxl_port *port,cxl_switch_parse_cdat (new_dport); +cxl_dport_init_ras_reporting (new_dport, &port->dev); +if (ida_is_empty (&port->decoder_ida)) { rc =devm_cxl_switch_port_decoders_setup (port);if (rc)
drivers/cxl/core/ras.c +12 -0
@@ -162,6 +162,18 @@ void cxl_dport_init_ras_reporting(struct cxl_dport *dport, struct device *host) }EXPORT_SYMBOL_NS_GPL (cxl_dport_init_ras_reporting,"CXL" ); +void cxl_uport_init_ras_reporting (struct cxl_port *port, +struct device *host) +{ +struct cxl_register_map *map = &port->reg_map; + + map->host = host; +if (cxl_map_component_regs (map, &port->uport_regs, +BIT (CXL_CM_CAP_CAP_ID_RAS ))) +dev_dbg (&port->dev,"Failed to map RAS capability\n" ); +} +EXPORT_SYMBOL_NS_GPL (cxl_uport_init_ras_reporting,"CXL" ); +void cxl_handle_cor_ras (struct device *dev,u64 serial,void __iomem *ras_base) {void __iomem *addr;
drivers/cxl/cxl.h +2 -0
@@ -599,6 +599,7 @@ struct cxl_dax_region {* @parent_dport: dport that points to this port in the parent * @decoder_ida: allocator for decoder ids * @reg_map: component and ras register mapping parameters +* @uport_regs: mapped component registers * @nr_dports: number of entries in @dports * @hdm_end: track last allocated HDM decoder instance for allocation ordering * @commit_end: cursor to track highest committed decoder for commit ordering
@@ -620,6 +621,7 @@ struct cxl_port {struct cxl_dport *parent_dport;struct ida decoder_ida;struct cxl_register_map reg_map; +struct cxl_component_regs uport_regs;int nr_dports;int hdm_end;int commit_end;
drivers/cxl/cxlpci.h +4 -0
@@ -83,6 +83,8 @@ void cxl_cor_error_detected(struct pci_dev *pdev);pci_ers_result_t cxl_error_detected (struct pci_dev *pdev,pci_channel_state_t state);void cxl_dport_init_ras_reporting (struct cxl_dport *dport,struct device *host); +void cxl_uport_init_ras_reporting (struct cxl_port *port, +struct device *host);#else static inline void cxl_cor_error_detected (struct pci_dev *pdev) { }
@@ -94,6 +96,8 @@ static inline pci_ers_result_t cxl_error_detected(struct pci_dev *pdev,static inline void cxl_dport_init_ras_reporting (struct cxl_dport *dport,struct device *host) { } +static inline void cxl_uport_init_ras_reporting (struct cxl_port *port, +struct device *host) { }#endif #endif /* __CXL_PCI_H__ */
drivers/cxl/mem.c +2 -1
@@ -166,7 +166,8 @@ static int cxl_mem_probe(struct device *dev)else endpoint_parent = &parent_port->dev; -cxl_dport_init_ras_reporting (dport, dev); +if (dport->rch) +cxl_dport_init_ras_reporting (dport, dev); scoped_guard(device, endpoint_parent) {if (!endpoint_parent->driver) {
Signature · 1 line
2.34.1
PATCH v13 15/25 CXL/PCI: Introduce PCI_ERS_RESULT_PANIC
In reply to Terry BowmanThe CXL driver's error handling for uncorrectable errors (UCE) will be updated in the future. A required change is for the error handlers to to force a system panic when a UCE is detected.
Introduce PCI_ERS_RESULT_PANIC as a 'enum pci_ers_result' type. This will be used by CXL UCE fatal and non-fatal recovery in future patches. Update PCIe recovery documentation with details of PCI_ERS_RESULT_PANIC.
---
Changes in v12->v13:
- Add Dave Jiang's, Jonathan's, Ben's review-by
- Typo fix (Ben)
Changes v11 -> v12:
- Documentation requested (Lukas)
--- Documentation/PCI/pci-error-recovery.rst | 6 ++++++ include/linux/pci.h | 3 +++ 2 files changed, 9 insertions(+)
Documentation/PCI/pci-error-recovery.rst +6 -0
@@ -102,6 +102,8 @@ Possible return values are:: PCI_ERS_RESULT_NEED_RESET, /* Device driver wants slot to be reset. */ PCI_ERS_RESULT_DISCONNECT, /* Device has completely failed, is unrecoverable */ PCI_ERS_RESULT_RECOVERED, /* Device driver is fully recovered and operational */ + PCI_ERS_RESULT_NO_AER_DRIVER, /* No AER capabilities registered for the driver */ + PCI_ERS_RESULT_PANIC, /* System is unstable, panic. Is CXL specific */ }; A driver does not have to implement all of these callbacks; however,
@@ -116,6 +118,10 @@ The actual steps taken by a platform to recover from a PCI error event will be platform-dependent, but will follow the general sequence described below. +PCI_ERS_RESULT_PANIC is currently unique to CXL and handled in CXL +cxl_do_recovery(). The PCI pcie_do_recovery() routine does not report or +handle PCI_ERS_RESULT_PANIC. + STEP 0: Error Event ------------------- A PCI bus error is detected by the PCI hardware. On powerpc, the slot
include/linux/pci.h +3 -0
@@ -890,6 +890,9 @@ enum pci_ers_result {/* No AER capabilities registered for the driver */ PCI_ERS_RESULT_NO_AER_DRIVER = (__force pci_ers_result_t )6 , + +/* System is unstable, panic. Is CXL specific */ + PCI_ERS_RESULT_PANIC = (__force pci_ers_result_t) 7, };/* PCI bus error event callbacks */
Signature · 1 line
2.34.1
PATCH v13 16/25 CXL/AER: Introduce pcie/aer_cxl_vh.c in AER driver for forwarding CXL errors
In reply to Terry BowmanCXL virtual hierarchy (VH) RAS handling for CXL Port devices will be added soon. This requires a notification mechanism for the AER driver to share the AER interrupt with the CXL driver. The notification will be used as an indication for the CXL drivers to handle and log the CXL RAS errors.
Note, 'CXL protocol error' terminology will refer to CXL VH and not CXL RCH errors unless specifically noted going forward.
Introduce a new file in the AER driver to handle the CXL protocol errors named pci/pcie/aer_cxl_vh.c.
Add a kfifo work queue to be used by the AER and CXL drivers. The AER driver will be the sole kfifo producer adding work and the cxl_core will be the sole kfifo consumer removing work. Add the boilerplate kfifo support. Encapsulate the kfifo, RW semaphore, and work pointer in a single structure.
Add CXL work queue handler registration functions in the AER driver. Export the functions allowing CXL driver to access. Implement registration functions for the CXL driver to assign or clear the work handler function. Synchronize accesses using the RW semaphore.
Introduce 'struct cxl_proto_err_work_data' to serve as the kfifo work data. This will contain a reference to the erring PCI device and the error severity. This will be used when the work is dequeued by the cxl_core driver.
---
Changes in v12->v13:
- Added Dave Jiang's review-by
- Update error message (Ben)
Changes in v11->v12:
- None
Changes in v10->v11:
- cxl_error_detected() - Change handlers' scoped_guard() to guard() (Jonathan)
- cxl_error_detected() - Remove extra line (Shiju)
- Changes moved to core/ras.c (Terry)
- cxl_error_detected(), remove 'ue' and return with function call. (Jonathan)
- Remove extra space in documentation for PCI_ERS_RESULT_PANIC definition
- Move #include "pci.h from cxl.h to core.h (Terry)
- Remove unnecessary includes of cxl.h and core.h in mem.c (Terry)
--- drivers/pci/pci.h | 4 ++ drivers/pci/pcie/Makefile | 1 + drivers/pci/pcie/aer.c | 25 ++------- drivers/pci/pcie/aer_cxl_vh.c | 95 +++++++++++++++++++++++++++++++++++ include/linux/aer.h | 17 +++++++ 5 files changed, 121 insertions(+), 21 deletions(-) create mode 100644 drivers/pci/pcie/aer_cxl_vh.c
drivers/pci/pci.h +4 -0
@@ -1330,8 +1330,12 @@ static inline void cxl_rch_enable_rcec(struct pci_dev *rcec) { }#ifdef CONFIG_CXL_RAS bool is_internal_error (struct aer_err_info *info); +bool is_cxl_error (struct pci_dev *pdev,struct aer_err_info *info); +void cxl_forward_error (struct pci_dev *pdev,struct aer_err_info *info);#else static inline bool is_internal_error (struct aer_err_info *info) {return false; } +static inline bool is_cxl_error (struct pci_dev *pdev,struct aer_err_info *info) {return false; } +static inline void cxl_forward_error (struct pci_dev *pdev,struct aer_err_info *info) { }#endif #endif /* DRIVERS_PCI_H */
drivers/pci/pcie/Makefile +1 -0
@@ -9,6 +9,7 @@ obj-$(CONFIG_PCIEPORTBUS) += pcieportdrv.o bwctrl.o obj-y += aspm.o obj-$(CONFIG_PCIEAER) += aer.o err.o tlp.o obj-$(CONFIG_CXL_RCH_RAS) += aer_cxl_rch.o +obj-$(CONFIG_CXL_RAS) += aer_cxl_vh.o obj-$(CONFIG_PCIEAER_INJECT) += aer_inject.o obj-$(CONFIG_PCIE_PME) += pme.o obj-$(CONFIG_PCIE_DPC) += dpc.o
drivers/pci/pcie/aer.c +4 -21
@@ -1123,8 +1123,6 @@ static bool find_source_device(struct pci_dev *parent,return true; } -#ifdef CONFIG_PCIEAER_CXL -/** * pci_aer_unmask_internal_errors - unmask internal errors * @dev: pointer to the pci_dev data structure
@@ -1150,24 +1148,6 @@ void pci_aer_unmask_internal_errors(struct pci_dev *dev) }EXPORT_SYMBOL_GPL (pci_aer_unmask_internal_errors); -bool cxl_error_is_native (struct pci_dev *dev) -{ -struct pci_host_bridge *host =pci_find_host_bridge (dev->bus); - -return (pcie_ports_native || host->native_aer); -} -EXPORT_SYMBOL_NS_GPL (cxl_error_is_native,"CXL" ); - -bool is_internal_error (struct aer_err_info *info) -{ -if (info->severity ==AER_CORRECTABLE ) -return info->status &PCI_ERR_COR_INTERNAL ; - -return info->status &PCI_ERR_UNC_INTN ; -} -EXPORT_SYMBOL_NS_GPL (is_internal_error,"CXL" ); -#endif /* CONFIG_CXL_RAS */ -/** * pci_aer_handle_error - handle logging error into an event log * @dev: pointer to pci_dev data structure of error source device
@@ -1204,7 +1184,10 @@ static void pci_aer_handle_error(struct pci_dev *dev, struct aer_err_info *info)static void handle_error_source (struct pci_dev *dev,struct aer_err_info *info) {cxl_rch_handle_error (dev, info); -pci_aer_handle_error (dev, info); +if (is_cxl_error (dev, info)) +cxl_forward_error (dev, info); +else +pci_aer_handle_error (dev, info);pci_dev_put (dev); }
drivers/pci/pcie/aer_cxl_vh.c new file +95 -0
95 lines not on this page · raw message
include/linux/aer.h +17 -0
@@ -10,6 +10,7 @@#include <linux/errno.h> #include <linux/types.h> +#include <linux/workqueue_types.h> #define AER_NONFATAL 0#define AER_FATAL 1
@@ -53,6 +54,16 @@ struct aer_capability_regs {u16 uncor_err_source; }; +/** +* struct cxl_proto_err_work_data - Error information used in CXL error handling +* @severity: AER severity +* @pdev: PCI device detecting the error +*/ +struct cxl_proto_err_work_data { +int severity; +struct pci_dev *pdev; +}; +#if defined(CONFIG_PCIEAER )int pci_aer_clear_nonfatal_status (struct pci_dev *dev);int pcie_aer_is_native (struct pci_dev *dev);
@@ -68,8 +79,14 @@ static inline void pci_aer_unmask_internal_errors(struct pci_dev *dev) { }#ifdef CONFIG_CXL_RAS bool cxl_error_is_native (struct pci_dev *dev); +int cxl_proto_err_kfifo_get (struct cxl_proto_err_work_data *wd); +void cxl_register_proto_err_work (struct work_struct *work); +void cxl_unregister_proto_err_work (void );#else static inline bool cxl_error_is_native (struct pci_dev *dev) {return false; } +static inline int cxl_proto_err_kfifo_get (struct cxl_proto_err_work_data *wd) {return 0 ; } +static inline void cxl_register_proto_err_work (struct work_struct *work) { } +static inline void cxl_unregister_proto_err_work (void ) { }#endif void pci_print_aer(struct pci_dev *dev, int aer_severity,
Signature · 1 line
2.34.1
PATCH v13 17/25 cxl: Introduce cxl_pci_drv_bound() to check for bound driver
In reply to Terry BowmanCXL devices handle protocol errors via driver-specific callbacks rather than the generic pci_driver::err_handlers by default. The callbacks are implemented in the cxl_pci driver and are not part of struct pci_driver, so cxl_core must verify that a device is actually bound to the cxl_pci module's driver before invoking the callbacks (the device could be bound to another driver, e.g. VFIO).
However, cxl_core can not reference symbols in the cxl_pci module because it creates a circular dependency. This prevents cxl_core from checking the EP's bound driver and calling the callbacks.
To fix this, move drivers/cxl/pci.c into drivers/cxl/core/pci_drv.c and build it as part of the cxl_core module. Compile into cxl_core using CXL_PCI and CXL_CORE Kconfig dependencies. This removes the standalone cxl_pci module, consolidates the cxl_pci driver code into cxl_core, and eliminates the circular dependency so cxl_core can safely perform bound-driver checks and invoke the CXL PCI callbacks.
Introduce cxl_pci_drv_bound() to return boolean depending on if the PCI EP parameter is bound to a CXL driver instance. This will be used in future patch when dequeuing work from the kfifo.
---
Changes in v12->v13;
- Add Dave Jiang's review-by.
Changes in v11->v12:
- Add device_lock_assert() in cxl_pci_drv_bound() (Dave Jiang)
- Add Jonathan's review-by
Changes in v11->v12:
- None
Changes in v10->v11:
- cxl_error_detected() - Change handlers' scoped_guard() to guard() (Jonathan)
- cxl_error_detected() - Remove extra line (Shiju)
- Changes moved to core/ras.c (Terry)
- cxl_error_detected(), remove 'ue' and return with function call. (Jonathan)
- Remove extra space in documentation for PCI_ERS_RESULT_PANIC definition
- Move #include "pci.h from cxl.h to core.h (Terry)
- Remove unnecessary includes of cxl.h and core.h in mem.c (Terry)
---
drivers/cxl/Kconfig | 6 +++---
drivers/cxl/Makefile | 2 --
drivers/cxl/core/Makefile | 1 +
drivers/cxl/core/core.h | 9 +++++++++
drivers/cxl/{pci.c => core/pci_drv.c} | 21 +++++++++++++--------
drivers/cxl/core/port.c | 3 +++
tools/testing/cxl/Kbuild | 1 +
7 files changed, 30 insertions(+), 13 deletions(-)
rename drivers/cxl/{pci.c => core/pci_drv.c} (99%)drivers/cxl/Kconfig +3 -3
@@ -20,7 +20,7 @@ menuconfig CXL_BUS if CXL_BUS config CXL_PCI - tristate "PCI manageability" + bool "PCI manageability" default CXL_BUS help The CXL specification defines a "CXL memory device" sub-class in the
@@ -29,12 +29,12 @@ config CXL_PCI memory to be mapped into the system address map (Host-managed Device Memory (HDM)). - Say 'y/m' to enable a driver that will attach to CXL memory expander + Say 'y' to enable a driver that will attach to CXL memory expander devices enumerated by the memory device class code for configuration and management primarily via the mailbox interface. See Chapter 2.3 Type 3 CXL Device in the CXL 2.0 specification for more details. - If unsure say 'm'. + If unsure say 'y'. config CXL_MEM_RAW_COMMANDS bool "RAW Command Interface for Memory Devices"
drivers/cxl/Makefile +0 -2
@@ -12,10 +12,8 @@ obj-$(CONFIG_CXL_PORT) += cxl_port.o obj-$(CONFIG_CXL_ACPI) += cxl_acpi.o obj-$(CONFIG_CXL_PMEM) += cxl_pmem.o obj-$(CONFIG_CXL_MEM) += cxl_mem.o -obj-$(CONFIG_CXL_PCI) += cxl_pci.o cxl_port-y := port.o cxl_acpi-y := acpi.o cxl_pmem-y := pmem.o security.o cxl_mem-y := mem.o -cxl_pci-y := pci.o
drivers/cxl/core/Makefile +1 -0
@@ -21,3 +21,4 @@ cxl_core-$(CONFIG_CXL_FEATURES) += features.o cxl_core-$(CONFIG_CXL_EDAC_MEM_FEATURES) += edac.o cxl_core-$(CONFIG_CXL_RAS) += ras.o cxl_core-$(CONFIG_CXL_RCH_RAS) += ras_rch.o +cxl_core-$(CONFIG_CXL_PCI) += pci_drv.o
drivers/cxl/core/core.h +9 -0
@@ -195,4 +195,13 @@ int cxl_set_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid, u16 *return_code);#endif +#ifdef CONFIG_CXL_PCI +bool cxl_pci_drv_bound (struct pci_dev *pdev); +int cxl_pci_driver_init (void ); +void cxl_pci_driver_exit (void ); +#else +static inline bool cxl_pci_drv_bound (struct pci_dev *pdev) {return false; }; +static inline int cxl_pci_driver_init (void ) {return 0 ; } +static inline void cxl_pci_driver_exit (void ) { } +#endif #endif /* __CXL_CORE_H__ */
drivers/cxl/core/pci_drv.c renamed from drivers/cxl/pci.c +13 -8
@@ -1131,6 +1131,17 @@ static struct pci_driver cxl_pci_driver = { }, }; +bool cxl_pci_drv_bound (struct pci_dev *pdev) +{ +device_lock_assert (&pdev->dev); + +if (pdev->driver != &cxl_pci_driver) +pr_err_ratelimited ("%s device not bound to CXL PCI driver\n" , +pci_name (pdev)); + +return (pdev->driver == &cxl_pci_driver); +} +#define CXL_EVENT_HDR_FLAGS_REC_SEVERITY GENMASK(1, 0)static void cxl_handle_cper_event (enum cxl_event_type ev_type,struct cxl_cper_event_rec *rec)
@@ -1177,7 +1188,7 @@ static void cxl_cper_work_fn(struct work_struct *work) } static DECLARE_WORK(cxl_cper_work, cxl_cper_work_fn); -static int __init cxl_pci_driver_init (void ) +int __init cxl_pci_driver_init (void ) {int rc;
@@ -1192,15 +1203,9 @@ static int __init cxl_pci_driver_init(void)return rc; } -static void __exit cxl_pci_driver_exit(void) +void cxl_pci_driver_exit (void ) {cxl_cper_unregister_work (&cxl_cper_work);cancel_work_sync (&cxl_cper_work);pci_unregister_driver (&cxl_pci_driver); } - -module_init (cxl_pci_driver_init); -module_exit (cxl_pci_driver_exit); -MODULE_DESCRIPTION ("CXL: PCI manageability" ); -MODULE_LICENSE ("GPL v2" ); -MODULE_IMPORT_NS ("CXL" );
drivers/cxl/core/port.c +3 -0
@@ -2507,6 +2507,8 @@ static __init int cxl_core_init(void)if (rc) goto err_ras; +cxl_pci_driver_init (); +return 0 ; err_ras:
@@ -2522,6 +2524,7 @@ static __init int cxl_core_init(void)static void cxl_core_exit (void ) { +cxl_pci_driver_exit ();cxl_ras_exit ();cxl_region_exit ();bus_unregister (&cxl_bus_type);
tools/testing/cxl/Kbuild +1 -0
@@ -65,6 +65,7 @@ cxl_core-$(CONFIG_CXL_FEATURES) += $(CXL_CORE_SRC)/features.o cxl_core-$(CONFIG_CXL_EDAC_MEM_FEATURES) += $(CXL_CORE_SRC)/edac.o cxl_core-$(CONFIG_CXL_RAS) += $(CXL_CORE_SRC)/ras.o cxl_core-$(CONFIG_CXL_RCH_RAS) += $(CXL_CORE_SRC)/ras_rch.o +cxl_core-$(CONFIG_CXL_PCI) += $(CXL_CORE_SRC)/pci_drv.o cxl_core-y += config_check.o cxl_core-y += cxl_core_test.o cxl_core-y += cxl_core_exports.o
Signature · 1 line
2.34.1
PATCH v13 18/25 cxl: Change CXL handlers to use guard() instead of scoped_guard()
In reply to Terry BowmanThe CXL protocol error handlers use scoped_guard() to guarantee access to the underlying CXL memory device. Improve readability and reduce complexity by changing the current scoped_guard() to be guard().
---
Changes in v12->v13:
- New patch
--- drivers/cxl/core/ras.c | 53 +++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 27 deletions(-)
drivers/cxl/core/ras.c +26 -27
@@ -254,19 +254,19 @@ void cxl_cor_error_detected(struct pci_dev *pdev)struct cxl_dev_state *cxlds =pci_get_drvdata (pdev);struct device *dev = &cxlds->cxlmd->dev; - scoped_guard(device, dev) { -if (!dev->driver) { -dev_warn (&pdev->dev, -"%s: memdev disabled, abort error handling\n" , -dev_name (dev)); -return ; - } - -if (cxlds->rcd) -cxl_handle_rdport_errors (cxlds); +guard (device)(dev); -cxl_handle_cor_ras (&cxlds->cxlmd->dev, cxlds->serial, cxlds->regs.ras); +if (!dev->driver) { +dev_warn (&pdev->dev, +"%s: memdev disabled, abort error handling\n" , +dev_name (dev)); +return ; } + +if (cxlds->rcd) +cxl_handle_rdport_errors (cxlds); + +cxl_handle_cor_ras (&cxlds->cxlmd->dev, cxlds->serial, cxlds->regs.ras); }EXPORT_SYMBOL_NS_GPL (cxl_cor_error_detected,"CXL" );
@@ -278,25 +278,24 @@ pci_ers_result_t cxl_error_detected(struct pci_dev *pdev,struct device *dev = &cxlmd->dev;bool ue; - scoped_guard(device, dev) { -if (!dev->driver) { -dev_warn (&pdev->dev, -"%s: memdev disabled, abort error handling\n" , -dev_name (dev)); -return PCI_ERS_RESULT_DISCONNECT ; - } +guard (device)(dev); -if (cxlds->rcd) -cxl_handle_rdport_errors (cxlds); -/* -* A frozen channel indicates an impending reset which is fatal to -* CXL.mem operation, and will likely crash the system. On the off -* chance the situation is recoverable dump the status of the RAS -* capability registers and bounce the active state of the memdev. -*/ - ue =cxl_handle_ras (&cxlds->cxlmd->dev, cxlds->serial, cxlds->regs.ras); +if (!dev->driver) { +dev_warn (&pdev->dev, +"%s: memdev disabled, abort error handling\n" , +dev_name (dev)); +return PCI_ERS_RESULT_DISCONNECT ; } +if (cxlds->rcd) +cxl_handle_rdport_errors (cxlds); +/* +* A frozen channel indicates an impending reset which is fatal to +* CXL.mem operation, and will likely crash the system. On the off +* chance the situation is recoverable dump the status of the RAS +* capability registers and bounce the active state of the memdev. +*/ + ue =cxl_handle_ras (&cxlds->cxlmd->dev, cxlds->serial, cxlds->regs.ras);switch (state) {case pci_channel_io_normal:
Signature · 1 line
2.34.1
PATCH v13 19/25 cxl/pci: Introduce CXL protocol error handlers for Endpoints
In reply to Terry BowmanCXL Endpoint protocol errors are currently handled by generic PCI error handlers. However, uncorrectable errors (UCEs) require CXL.mem protocol- specific handling logic that the PCI handlers cannot provide.
Add dedicated CXL protocol error handlers for CXL Endpoints. Rename the existing cxl_error_handlers to pci_error_handlers to better reflect their purpose and maintain naming consistency. Update the PCI error handlers to invoke the new CXL protocol handlers when the endpoint is operating in CXL.mem mode.
Implement cxl_handle_ras() to return PCI_ERS_RESULT_NONE or PCI_ERS_RESULT_PANIC. Remove unnecessary result checks from the previous endpoint UCE handler since CXL UCE recovery is not implemented in this patch.
Add device lock assertions to protect against concurrent device or RAS register removal during error handling. Two devices require locking for CXL endpoints:
1. The PCI device (pdev->dev) - RAS registers are allocated and mapped using devm_* functions with this device as the host. Locking prevents the RAS registers from being unmapped until after error handling completes.
2. The CXL memory device (cxlmd->dev) - Holds a reference to the RAS registers accessed during error handling. Locking prevents the memory device and its RAS register references from being removed during error handling.
The lock assertions added here will be satisfied by device locks introduced in a subsequent patch. A future patch will extend the CXL UCE handler to support full UCE recovery.
---
Changes in v12->v13:
- Update commit messaqge (Terry)
- Updated all the implemetnation and commit message. (Terry)
- Refactored cxl_cor_error_detected()/cxl_error_detected() to remove pdev (Dave Jiang)
Changes in v11->v12:
- None
Changes in v10->v11:
- cxl_error_detected() - Change handlers' scoped_guard() to guard() (Jonathan)
- cxl_error_detected() - Remove extra line (Shiju)
- Changes moved to core/ras.c (Terry)
- cxl_error_detected(), remove 'ue' and return with function call. (Jonathan)
- Remove extra space in documentation for PCI_ERS_RESULT_PANIC definition
- Move #include "pci.h from cxl.h to core.h (Terry)
- Remove unnecessary includes of cxl.h and core.h in mem.c (Terry)
--- drivers/cxl/core/core.h | 22 +++++++-- drivers/cxl/core/pci_drv.c | 9 ++-- drivers/cxl/core/ras.c | 97 +++++++++++++++++++++++--------------- drivers/cxl/cxlpci.h | 11 ----- 4 files changed, 82 insertions(+), 57 deletions(-)
drivers/cxl/core/core.h +18 -4
@@ -149,19 +149,33 @@ int cxl_port_get_switch_dport_bandwidth(struct cxl_port *port,#ifdef CONFIG_CXL_RAS int cxl_ras_init (void );void cxl_ras_exit (void ); -bool cxl_handle_ras (struct device *dev,u64 serial,void __iomem *ras_base); +pci_ers_result_t cxl_handle_ras (struct device *dev,u64 serial, +void __iomem *ras_base);void cxl_handle_cor_ras (struct device *dev,u64 serial,void __iomem *ras_base); +pci_ers_result_t cxl_error_detected (struct device *dev); +void cxl_cor_error_detected (struct device *dev); +pci_ers_result_t pci_error_detected (struct pci_dev *pdev, +pci_channel_state_t error); +void pci_cor_error_detected (struct pci_dev *pdev);#else static inline int cxl_ras_init (void ) {return 0 ; }static inline void cxl_ras_exit (void ) { } -static inline bool cxl_handle_ras (struct device *dev,void __iomem *ras_base) +static inline pci_ers_result_t cxl_handle_ras (struct device *dev,u64 serial, +void __iomem *ras_base) { -return false; +return PCI_ERS_RESULT_NONE ; } -static inline void cxl_handle_cor_ras (struct device *dev,void __iomem *ras_base) { } +static inline void cxl_handle_cor_ras (struct device *dev,u64 serial, +void __iomem *ras_base) { } +static inline pci_ers_result_t pci_error_detected (struct pci_dev *pdev, +pci_channel_state_t error) +{ +return PCI_ERS_RESULT_NONE ; +} +static inline void pci_cor_error_detected (struct pci_dev *pdev) { }#endif /* CONFIG_CXL_RAS */ /* Restricted CXL Host specific RAS functions */
drivers/cxl/core/pci_drv.c +5 -4
@@ -16,6 +16,7 @@#include "cxlpci.h" #include "cxl.h" #include "pmu.h" +#include "core/core.h" /** * DOC: cxl pci
@@ -1112,11 +1113,11 @@ static void cxl_reset_done(struct pci_dev *pdev) } } -static const struct pci_error_handlers cxl_error_handlers = { - .error_detected = cxl_error_detected, +static const struct pci_error_handlers pci_error_handlers = { + .error_detected = pci_error_detected, .slot_reset = cxl_slot_reset, .resume = cxl_error_resume, - .cor_error_detected = cxl_cor_error_detected, + .cor_error_detected = pci_cor_error_detected, .reset_done = cxl_reset_done, };
@@ -1124,7 +1125,7 @@ static struct pci_driver cxl_pci_driver = { .name = KBUILD_MODNAME, .id_table = cxl_mem_pci_tbl, .probe = cxl_pci_probe, - .err_handler = &cxl_error_handlers, + .err_handler = &pci_error_handlers, .dev_groups = cxl_rcd_groups, .driver = { .probe_type = PROBE_PREFER_ASYNCHRONOUS,
drivers/cxl/core/ras.c +59 -38
153 lines not on this page · raw message
drivers/cxl/cxlpci.h +0 -11
@@ -79,21 +79,10 @@ struct cxl_dev_state;void read_cdat_data (struct cxl_port *port);#ifdef CONFIG_CXL_RAS -void cxl_cor_error_detected (struct pci_dev *pdev); -pci_ers_result_t cxl_error_detected (struct pci_dev *pdev, -pci_channel_state_t state);void cxl_dport_init_ras_reporting (struct cxl_dport *dport,struct device *host);void cxl_uport_init_ras_reporting (struct cxl_port *port,struct device *host);#else -static inline void cxl_cor_error_detected (struct pci_dev *pdev) { } - -static inline pci_ers_result_t cxl_error_detected (struct pci_dev *pdev, -pci_channel_state_t state) -{ -return PCI_ERS_RESULT_NONE ; -} -static inline void cxl_dport_init_ras_reporting (struct cxl_dport *dport,struct device *host) { } static inline void cxl_uport_init_ras_reporting(struct cxl_port *port,
Signature · 1 line
2.34.1
PATCH v13 20/25 CXL/PCI: Introduce CXL Port protocol error handlers
In reply to Terry BowmanAdd CXL protocol error handlers for CXL Port devices (Root Ports, Downstream Ports, and Upstream Ports). Implement cxl_port_cor_error_detected() and cxl_port_error_detected() to handle correctable and uncorrectable errors respectively.
Introduce cxl_get_ras_base() to retrieve the cached RAS register base address for a given CXL port. This function supports CXL Root Ports, Downstream Ports, and Upstream Ports by returning their previously mapped RAS register addresses.
Add device lock assertions to protect against concurrent device or RAS register removal during error handling. The port error handlers require two device locks:
1. The port's CXL parent device - RAS registers are mapped using devm_* functions with the parent port as the host. Locking the parent prevents the RAS registers from being unmapped during error handling.
2. The PCI device (pdev->dev) - Locking prevents concurrent modifications to the PCI device structure during error handling.
The lock assertions added here will be satisfied by device locks introduced in a subsequent patch.
Introduce get_pci_cxl_host_dev() to return the device responsible for managing the RAS register mapping. This function increments the reference count on the host device to prevent premature resource release during error handling. The caller is responsible for decrementing the reference count. For CXL endpoints, which manage resources without a separate host device, this function returns NULL.
Update the AER driver's is_cxl_error() to recognize CXL Port devices in addition to CXL Endpoints, as both now have CXL-specific error handlers.
---
Changes in v12->v13:
- Move get_pci_cxl_host_dev() and cxl_handle_proto_error() to Dequeue patch (Terry)
- Remove EP case in cxl_get_ras_base(), not used. (Terry)
- Remove check for dport->dport_dev (Dave)
- Remove whitespace (Terry)
Changes in v11->v12:
- Add call to cxl_pci_drv_bound() in cxl_handle_proto_error() and pci_to_cxl_dev()
- Change cxl_error_detected() -> cxl_cor_error_detected()
- Remove NULL variable assignments
- Replace bus_find_device() with find_cxl_port_by_uport() for upstream port searches.
Changes in v10->v11:
- None
--- drivers/cxl/core/core.h | 10 +++++++ drivers/cxl/core/port.c | 7 ++--- drivers/cxl/core/ras.c | 49 +++++++++++++++++++++++++++++++++++ drivers/pci/pcie/aer_cxl_vh.c | 5 +++- 4 files changed, 67 insertions(+), 4 deletions(-)
drivers/cxl/core/core.h +10 -0
@@ -157,6 +157,8 @@ void cxl_cor_error_detected(struct device *dev);pci_ers_result_t pci_error_detected (struct pci_dev *pdev,pci_channel_state_t error);void pci_cor_error_detected (struct pci_dev *pdev); +pci_ers_result_t cxl_port_error_detected (struct device *dev); +void cxl_port_cor_error_detected (struct device *dev);#else static inline int cxl_ras_init (void ) {
@@ -176,6 +178,11 @@ static inline pci_ers_result_t pci_error_detected(struct pci_dev *pdev, return PCI_ERS_RESULT_NONE; }static inline void pci_cor_error_detected (struct pci_dev *pdev) { } +static inline void cxl_port_cor_error_detected (struct device *dev) { } +static inline pci_ers_result_t cxl_port_error_detected (struct device *dev) +{ +return PCI_ERS_RESULT_NONE ; +}#endif /* CONFIG_CXL_RAS */ /* Restricted CXL Host specific RAS functions */
@@ -190,6 +197,9 @@ static inline void cxl_handle_rdport_errors(struct cxl_dev_state *cxlds) { }#endif /* CONFIG_CXL_RCH_RAS */ int cxl_gpf_port_setup (struct cxl_dport *dport); +struct cxl_port *find_cxl_port (struct device *dport_dev, +struct cxl_dport **dport); +struct cxl_port *find_cxl_port_by_uport (struct device *uport_dev);struct cxl_hdm ; int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
drivers/cxl/core/port.c +4 -3
@@ -1360,8 +1360,8 @@ static struct cxl_port *__find_cxl_port(struct cxl_find_port_ctx *ctx)return NULL ; } -static struct cxl_port *find_cxl_port (struct device *dport_dev, -struct cxl_dport **dport) +struct cxl_port *find_cxl_port (struct device *dport_dev, +struct cxl_dport **dport) {struct cxl_find_port_ctx ctx = { .dport_dev = dport_dev,
@@ -1564,7 +1564,7 @@ static int match_port_by_uport(struct device *dev, const void *data)* Function takes a device reference on the port device. Caller should do a * put_device() when done. */ -static struct cxl_port *find_cxl_port_by_uport (struct device *uport_dev) +struct cxl_port *find_cxl_port_by_uport (struct device *uport_dev) {struct device *dev;
@@ -1573,6 +1573,7 @@ static struct cxl_port *find_cxl_port_by_uport(struct device *uport_dev)return to_cxl_port (dev);return NULL ; } +EXPORT_SYMBOL_NS_GPL (find_cxl_port_by_uport,"CXL" );static int update_decoder_targets (struct device *dev,void *data) {
drivers/cxl/core/ras.c +49 -0
61 lines not on this page · raw message
drivers/pci/pcie/aer_cxl_vh.c +4 -1
@@ -43,7 +43,10 @@ bool is_cxl_error(struct pci_dev *pdev, struct aer_err_info *info)if (!info || !info->is_cxl)return false; -if (pci_pcie_type (pdev) !=PCI_EXP_TYPE_ENDPOINT ) +if ((pci_pcie_type (pdev) !=PCI_EXP_TYPE_ENDPOINT ) && + (pci_pcie_type (pdev) !=PCI_EXP_TYPE_ROOT_PORT ) && + (pci_pcie_type (pdev) !=PCI_EXP_TYPE_UPSTREAM ) && + (pci_pcie_type (pdev) !=PCI_EXP_TYPE_DOWNSTREAM ))return false;return is_internal_error (info);
Signature · 1 line
2.34.1
PATCH v13 21/25 PCI/AER: Dequeue forwarded CXL error
In reply to Terry BowmanThe AER driver now forwards CXL protocol errors to the CXL driver via a kfifo. The CXL driver must consume these work items, initiate protocol error handling, and ensure RAS mappings remain valid throughout processing.
Implement cxl_proto_err_work_fn() to dequeue work items forwarded by the AER service driver and begin protocol error processing by calling cxl_handle_proto_error().
Add a PCI device lock on &pdev->dev within cxl_proto_err_work_fn() to keep the PCI device structure valid during handling. Locking an Endpoint will also defer RAS unmapping until the device is unlocked.
For Endpoints, add a lock on CXL memory device cxlds->dev. The CXL memory device structure holds the RAS register reference needed during error handling.
Add lock for the parent CXL Port for Root Ports, Downstream Ports, and Upstream Ports to prevent destruction of structures holding mapped RAS addresses while they are in use.
Invoke cxl_do_recovery() for uncorrectable errors. Treat this as a stub for now; implement its functionality in a future patch.
Export pci_clean_device_status() to enable cleanup of AER status following error handling.
---
Changes in v12->v13:
- Add cxlmd lock using guard() (Terry)
- Remove exporting of unused function, pci_aer_clear_fatal_status() (Dave Jiang)
- Change pr_err() calls to ratelimited. (Terry)
- Update commit message. (Terry)
- Remove namespace qualifier from pcie_clear_device_status()
export (Dave Jiang)
- Move locks into cxl_proto_err_work_fn() (Dave)
- Update log messages in cxl_forward_error() (Ben)
Changes in v11->v12:
- Add guard for CE case in cxl_handle_proto_error() (Dave)
Changes in v10->v11:
- Reword patch commit message to remove RCiEP details (Jonathan)
- Add #include <linux/bitfield.h> (Terry)
- is_cxl_rcd() - Fix short comment message wrap (Jonathan)
- is_cxl_rcd() - Combine return calls into 1 (Jonathan)
- cxl_handle_proto_error() - Move comment earlier (Jonathan)
- Use FIELD_GET() in discovering class code (Jonathan)
- Remove BDF from cxl_proto_err_work_data. Use 'struct pci_dev *' (Dan)
--- drivers/cxl/core/ras.c | 153 ++++++++++++++++++++++++++++++++++++++--- drivers/pci/pci.c | 1 + drivers/pci/pci.h | 1 - include/linux/pci.h | 2 + 4 files changed, 145 insertions(+), 12 deletions(-)
drivers/cxl/core/ras.c +142 -11
@@ -117,17 +117,6 @@ static void cxl_cper_prot_err_work_fn(struct work_struct *work) } static DECLARE_WORK(cxl_cper_prot_err_work, cxl_cper_prot_err_work_fn); -int cxl_ras_init (void ) -{ -return cxl_cper_register_prot_err_work (&cxl_cper_prot_err_work); -} - -void cxl_ras_exit (void ) -{ -cxl_cper_unregister_prot_err_work (&cxl_cper_prot_err_work); -cancel_work_sync (&cxl_cper_prot_err_work); -} -static bool is_pcie_endpoint (struct pci_dev *pdev) {return pci_pcie_type (pdev) ==PCI_EXP_TYPE_ENDPOINT ;
@@ -178,6 +167,51 @@ static void __iomem *cxl_get_ras_base(struct device *dev)return NULL ; } +/* +* Return 'struct cxl_port *' parent CXL port of dev's +* +* Reference count increments on success +* +* dev: Find the parent port of this dev +*/ +static struct cxl_port *get_cxl_port (struct pci_dev *pdev) +{ +switch (pci_pcie_type (pdev)) { +case PCI_EXP_TYPE_ROOT_PORT : +case PCI_EXP_TYPE_DOWNSTREAM : + { +struct cxl_dport *dport; +struct cxl_port *port =find_cxl_port (&pdev->dev, &dport); + +if (!port) { +pci_err (pdev,"Failed to find the CXL device" ); +return NULL ; + } +return port; + } +case PCI_EXP_TYPE_UPSTREAM : + { +struct cxl_port *port =find_cxl_port_by_uport (&pdev->dev); + +if (!port) { +pci_err (pdev,"Failed to find the CXL device" ); +return NULL ; + } +return port; + } +case PCI_EXP_TYPE_ENDPOINT : + { +struct cxl_dev_state *cxlds =pci_get_drvdata (pdev); +struct cxl_port *port = cxlds->cxlmd->endpoint; + +get_device (&port->dev); +return port; + } + } +pci_warn_once (pdev,"Error: Unsupported device type (%X)" ,pci_pcie_type (pdev)); +return NULL ; +} +/** * cxl_dport_init_ras_reporting - Setup CXL RAS report on this dport * @dport: the cxl_dport that needs to be initialized
@@ -212,6 +246,23 @@ void cxl_uport_init_ras_reporting(struct cxl_port *port, }EXPORT_SYMBOL_NS_GPL (cxl_uport_init_ras_reporting,"CXL" ); +static bool device_lock_if (struct device *dev,bool cond) +{ +if (cond) +device_lock (dev); +return cond; +} + +static void device_unlock_if (struct device *dev,bool take) +{ +if (take) +device_unlock (dev); +} + +static void cxl_do_recovery (struct pci_dev *pdev) +{ +} +void cxl_handle_cor_ras (struct device *dev,u64 serial,void __iomem *ras_base) {void __iomem *addr;
@@ -388,3 +439,83 @@ pci_ers_result_t pci_error_detected(struct pci_dev *pdev,return rc; }EXPORT_SYMBOL_NS_GPL (pci_error_detected,"CXL" ); + +static void cxl_handle_proto_error (struct cxl_proto_err_work_data *err_info) +{ +struct pci_dev *pdev = err_info->pdev; +struct cxl_dev_state *cxlds =pci_get_drvdata (pdev); + +if (err_info->severity ==AER_CORRECTABLE ) { + +if (pdev->aer_cap) +pci_clear_and_set_config_dword (pdev, + pdev->aer_cap +PCI_ERR_COR_STATUS , +0 ,PCI_ERR_COR_INTERNAL ); + +if (is_pcie_endpoint (pdev)) +cxl_cor_error_detected (&cxlds->cxlmd->dev); +else +cxl_port_cor_error_detected (&pdev->dev); + +pcie_clear_device_status (pdev); + }else { +cxl_do_recovery (pdev); + } +} + +static void cxl_proto_err_work_fn (struct work_struct *work) +{ +struct cxl_proto_err_work_data wd; + +while (cxl_proto_err_kfifo_get (&wd)) { + struct pci_dev *pdev __free(pci_dev_put) = pci_dev_get(wd.pdev); +struct device *cxlmd_dev; + +if (!pdev) { +pr_err_ratelimited ("NULL PCI device passed in AER-CXL KFIFO\n" ); +continue ; + } + +guard (device)(&pdev->dev); +if (is_pcie_endpoint (pdev)) { +struct cxl_dev_state *cxlds =pci_get_drvdata (pdev); + +if (!cxl_pci_drv_bound (pdev)) +return ; + cxlmd_dev = &cxlds->cxlmd->dev; +device_lock_if (cxlmd_dev, cxlmd_dev); + }else { + cxlmd_dev =NULL ; + } + + struct cxl_port *port __free(put_cxl_port) = get_cxl_port(pdev); +if (!port) +return ; +guard (device)(&port->dev); + +cxl_handle_proto_error (&wd); +device_unlock_if (cxlmd_dev, cxlmd_dev); + } +} + +static struct work_struct cxl_proto_err_work; +static DECLARE_WORK(cxl_proto_err_work, cxl_proto_err_work_fn); + +int cxl_ras_init (void ) +{ +if (cxl_cper_register_prot_err_work (&cxl_cper_prot_err_work)) +pr_err ("Failed to initialize CXL RAS CPER\n" ); + +cxl_register_proto_err_work (&cxl_proto_err_work); + +return 0 ; +} + +void cxl_ras_exit (void ) +{ +cxl_cper_unregister_prot_err_work (&cxl_cper_prot_err_work); +cancel_work_sync (&cxl_cper_prot_err_work); + +cxl_unregister_proto_err_work (); +cancel_work_sync (&cxl_proto_err_work); +}
drivers/pci/pci.c +1 -0
@@ -2277,6 +2277,7 @@ void pcie_clear_device_status(struct pci_dev *dev)pcie_capability_read_word (dev,PCI_EXP_DEVSTA , &sta); pcie_capability_write_word(dev, PCI_EXP_DEVSTA, sta); } +EXPORT_SYMBOL_GPL (pcie_clear_device_status);#endif /**
drivers/pci/pci.h +0 -1
@@ -229,7 +229,6 @@ void pci_refresh_power_state(struct pci_dev *dev);int pci_power_up (struct pci_dev *dev);void pci_disable_enabled_device (struct pci_dev *dev);int pci_finish_runtime_suspend (struct pci_dev *dev); -void pcie_clear_device_status (struct pci_dev *dev);void pcie_clear_root_pme_status (struct pci_dev *dev);bool pci_check_pme_status (struct pci_dev *dev);void pci_pme_wakeup_bus (struct pci_bus *bus);
include/linux/pci.h +2 -0
@@ -1886,8 +1886,10 @@ static inline void pci_hp_unignore_link_change(struct pci_dev *pdev) { }#ifdef CONFIG_PCIEAER bool pci_aer_available (void ); +void pcie_clear_device_status (struct pci_dev *dev);#else static inline bool pci_aer_available (void ) {return false; } +static inline void pcie_clear_device_status (struct pci_dev *dev) { }#endif bool pci_ats_disabled (void );
Signature · 1 line
2.34.1
PATCH v13 22/25 CXL/PCI: Export and rename merge_result() to pci_ers_merge_result()
In reply to Terry BowmanCXL uncorrectable errors (UCE) will soon be handled separately from the PCI AER handling. The merge_result() function can be made common to use in both handling paths.
Rename the PCI subsystem's merge_result() to be pci_ers_merge_result(). Export pci_ers_merge_result() to make available for the CXL and other drivers to use.
Update pci_ers_merge_result() to support recently introduced PCI_ERS_RESULT_PANIC result.
---
Changes in v12->v13:
- Renamed pci_ers_merge_result() to pcie_ers_merge_result(). pci_ers_merge_result() is already used in eeh driver. (Bot)
Changes in v11->v12:
- Remove static inline pci_ers_merge_result() definition for !CONFIG_PCIEAER. Is not needed. (Lukas)
Changes in v10->v11:
- New patch
- pci_ers_merge_result() - Change export to non-namespace and rename to be pci_ers_merge_result()
- Move pci_ers_merge_result() definition to pci.h. Needs pci_ers_result
--- drivers/pci/pcie/err.c | 14 +++++++++----- include/linux/pci.h | 7 +++++++ 2 files changed, 16 insertions(+), 5 deletions(-)
drivers/pci/pcie/err.c +9 -5
@@ -21,9 +21,12 @@#include "portdrv.h" #include "../pci.h" -static pci_ers_result_t merge_result (enum pci_ers_result orig, -enum pci_ers_result new) +pci_ers_result_t pcie_ers_merge_result (enum pci_ers_result orig, +enum pci_ers_result new) { +if (new ==PCI_ERS_RESULT_PANIC ) +return PCI_ERS_RESULT_PANIC ; +if (new ==PCI_ERS_RESULT_NO_AER_DRIVER )return PCI_ERS_RESULT_NO_AER_DRIVER ;
@@ -45,6 +48,7 @@ static pci_ers_result_t merge_result(enum pci_ers_result orig,return orig; } +EXPORT_SYMBOL (pcie_ers_merge_result); static int report_error_detected(struct pci_dev *dev, pci_channel_state_t state,
@@ -81,7 +85,7 @@ static int report_error_detected(struct pci_dev *dev, vote = err_handler->error_detected (dev, state); }pci_uevent_ers (dev, vote); - *result =merge_result (*result, vote); + *result =pcie_ers_merge_result (*result, vote);device_unlock (&dev->dev);return 0 ; }
@@ -139,7 +143,7 @@ static int report_mmio_enabled(struct pci_dev *dev, void *data) err_handler = pdrv->err_handler; vote = err_handler->mmio_enabled (dev); - *result =merge_result (*result, vote); + *result =pcie_ers_merge_result (*result, vote); out:device_unlock (&dev->dev);return 0 ;
@@ -159,7 +163,7 @@ static int report_slot_reset(struct pci_dev *dev, void *data) err_handler = pdrv->err_handler; vote = err_handler->slot_reset (dev); - *result =merge_result (*result, vote); + *result =pcie_ers_merge_result (*result, vote); out:device_unlock (&dev->dev);return 0 ;
include/linux/pci.h +7 -0
@@ -1887,9 +1887,16 @@ static inline void pci_hp_unignore_link_change(struct pci_dev *pdev) { }#ifdef CONFIG_PCIEAER bool pci_aer_available (void );void pcie_clear_device_status (struct pci_dev *dev); +pci_ers_result_t pcie_ers_merge_result (enum pci_ers_result orig, +enum pci_ers_result new);#else static inline bool pci_aer_available (void ) {return false; }static inline void pcie_clear_device_status (struct pci_dev *dev) { } +static inline pci_ers_result_t pcie_ers_merge_result (enum pci_ers_result orig, +enum pci_ers_result new) +{ +return PCI_ERS_RESULT_NONE ; +}#endif bool pci_ats_disabled (void );
Signature · 1 line
2.34.1
Re: [PATCH v13 01/25] CXL/PCI: Move CXL DVSEC definitions into uapi/linux/pci_regs.h
In reply to Terry BowmanQuoted 15 lines · Terry Bowman
The CXL DVSECs are currently defined in
cxl/core/cxlpci.h. These are not accessible to other subsystems. Move these touapi/linux/pci_regs.h.Change DVSEC name formatting to follow the existing PCI format in
pci_regs.h. The current format usesCXL_DVSEC_XYZand the CXL defines must be changed to bePCI_DVSEC_CXL_XYZto match existingpci_regs.h. Leave PCI_DVSEC_CXL_PORT* defines as-is because they are already defined and may be in use by userspace application(s).Update existing usage to match the name change.
Update the inline documentation to refer to latest CXL spec version.
+++
b/drivers/pci/pci.c
drivers/pci/pci.c static bool cxl_sbr_masked(struct pci_dev *dev) · line 5007
Quoted 7 lines
drivers/pci/pci.c +3
-1@@ -5002,7 +5002,9 @@ static bool cxl_sbr_masked(struct pci_dev *dev)if (!dvsec)return false; - rc =pci_read_config_word (dev, dvsec +PCI_DVSEC_CXL_PORT_CTL , ®); + rc =pci_read_config_word (dev, + dvsec +PCI_DVSEC_CXL_PORT_CTL , + ®);
Stray change.
Quoted 7 lines
include/uapi/linux/pci_regs.h +1
-2+++ b/include/uapi/linux/pci_regs.h@@ -1244,9 +1244,64 @@/* Deprecated old name, replaced with PCI_DOE_DATA_OBJECT_DISC_RSP_3_TYPE */ #define PCI_DOE_DATA_OBJECT_DISC_RSP_3_PROTOCOL PCI_DOE_DATA_OBJECT_DISC_RSP_3_TYPE -/* Compute Express Link (CXL r3.1, sec 8.1.5) */ -#define PCI_DVSEC_CXL_PORT 3
include/uapi/linux/pci_regs.h line 1254
Quoted 10 lines
include/uapi/linux/pci_regs.h +8
-2-#define PCI_DVSEC_CXL_PORT_CTL 0x0c -#define PCI_DVSEC_CXL_PORT_CTL_UNMASK_SBR 0x00000001 +/* Compute Express Link (CXL r3.2, sec 8.1) +* +* Note that CXL DVSEC id 3 and 7 to be ignored when the CXL link state +* is "disconnected" (CXL r3.2, sec 9.12.3). Re-enumerate these +* registers on downstream link-up events. +*/ + +#define PCI_DVSEC_HEADER1_LENGTH_MASK __GENMASK(31, 20)
Looks like a functional duplicate of PCI_DVSEC_HEADER1_LEN().
Why __GENMASK() instead of GENMASK()? I don't know the purpose of __GENMASK(), but I see other include/uapi/ files using GENMASK(). Maybe they're wrong?
Same questions for _BITUL() below.
Quoted 15 lines
include/uapi/linux/pci_regs.h +15
-0+/* CXL 3.2 8.1.3: PCIe DVSEC for CXL Device */ +#define PCI_DVSEC_CXL_DEVICE 0 +#define PCI_DVSEC_CXL_CAP_OFFSET 0xA +#define PCI_DVSEC_CXL_MEM_CAPABLE _BITUL(2) +#define PCI_DVSEC_CXL_HDM_COUNT_MASK __GENMASK(5, 4) +#define PCI_DVSEC_CXL_CTRL_OFFSET 0xC +#define PCI_DVSEC_CXL_MEM_ENABLE _BITUL(2) +#define PCI_DVSEC_CXL_RANGE_SIZE_HIGH (i) (0x18 + (i * 0x10)) +#define PCI_DVSEC_CXL_RANGE_SIZE_LOW (i) (0x1C + (i * 0x10)) +#define PCI_DVSEC_CXL_MEM_INFO_VALID _BITUL(0) +#define PCI_DVSEC_CXL_MEM_ACTIVE _BITUL(1) +#define PCI_DVSEC_CXL_MEM_SIZE_LOW_MASK __GENMASK(31, 28) +#define PCI_DVSEC_CXL_RANGE_BASE_HIGH (i) (0x20 + (i * 0x10)) +#define PCI_DVSEC_CXL_RANGE_BASE_LOW (i) (0x24 + (i * 0x10)) +#define PCI_DVSEC_CXL_MEM_BASE_LOW_MASK __GENMASK(31, 28)
Re: [PATCH v13 01/25] CXL/PCI: Move CXL DVSEC definitions into uapi/linux/pci_regs.h
Quoted 46 lines · Bjorn Helgaas
Quoted 15 lines · Terry Bowman
The CXL DVSECs are currently defined in
cxl/core/cxlpci.h. These are not accessible to other subsystems. Move these touapi/linux/pci_regs.h.Change DVSEC name formatting to follow the existing PCI format in
pci_regs.h. The current format usesCXL_DVSEC_XYZand the CXL defines must be changed to bePCI_DVSEC_CXL_XYZto match existingpci_regs.h. Leave PCI_DVSEC_CXL_PORT* defines as-is because they are already defined and may be in use by userspace application(s).Update existing usage to match the name change.
Update the inline documentation to refer to latest CXL spec version.
+++
b/drivers/pci/pci.cdrivers/pci/pci.c static bool cxl_sbr_masked(struct pci_dev *dev) · line 5007
Quoted 7 lines
drivers/pci/pci.c +3
-1@@ -5002,7 +5002,9 @@ static bool cxl_sbr_masked(struct pci_dev *dev)if (!dvsec)return false; - rc =pci_read_config_word (dev, dvsec +PCI_DVSEC_CXL_PORT_CTL , ®); + rc =pci_read_config_word (dev, + dvsec +PCI_DVSEC_CXL_PORT_CTL , + ®);Stray change.
Quoted 7 lines
include/uapi/linux/pci_regs.h +1
-2+++ b/include/uapi/linux/pci_regs.h@@ -1244,9 +1244,64 @@/* Deprecated old name, replaced with PCI_DOE_DATA_OBJECT_DISC_RSP_3_TYPE */ #define PCI_DOE_DATA_OBJECT_DISC_RSP_3_PROTOCOL PCI_DOE_DATA_OBJECT_DISC_RSP_3_TYPE -/* Compute Express Link (CXL r3.1, sec 8.1.5) */ -#define PCI_DVSEC_CXL_PORT 3include/uapi/linux/pci_regs.h line 1254
Quoted 10 lines
include/uapi/linux/pci_regs.h +8
-2-#define PCI_DVSEC_CXL_PORT_CTL 0x0c -#define PCI_DVSEC_CXL_PORT_CTL_UNMASK_SBR 0x00000001 +/* Compute Express Link (CXL r3.2, sec 8.1) +* +* Note that CXL DVSEC id 3 and 7 to be ignored when the CXL link state +* is "disconnected" (CXL r3.2, sec 9.12.3). Re-enumerate these +* registers on downstream link-up events. +*/ + +#define PCI_DVSEC_HEADER1_LENGTH_MASK __GENMASK(31, 20)Looks like a functional duplicate of
PCI_DVSEC_HEADER1_LEN().
Quoted 5 lines
Why
__GENMASK()instead ofGENMASK()? I don't know the purpose of__GENMASK(), but I see otherinclude/uapi/files usingGENMASK(). Maybe they're wrong?Same questions for
_BITUL()below.
See this commit:
3c7a8e190bc5 uapi: introduce uapi-friendly macros for GENMASK
GENMASK() for a long time was not available to uapi headers since uapi headers can only include other include/uapi/ headers, not include/linux/. That commit made some common kernel bitfield helpers finally available to the uapi side of the house.
Re: [PATCH v13 02/25] PCI/CXL: Introduce pcie_is_cxl()
In reply to Terry BowmanQuoted 6 lines · Terry Bowman
CXL and AER drivers need the ability to identify CXL devices.
Introduce
set_pcie_cxl()with logic checking for CXL.mem or CXL.cache status in the CXL Flexbus DVSEC status register. The CXL Flexbus DVSEC presence is used because it is required for all the CXL PCIe devices.[1]
Quoted 7 lines
Add boolean 'struct
pci_dev::is_cxl' with the purpose to cache the CXL CXL.cache and CXl.mem status.In the case the device is an EP or USP, call
set_pcie_cxl()on behalf of the parent downstream device. Once a device is created there is possibilty the parent training or CXL state was updated as well. This will make certain the correct parent CXL state is cached.
See question at comment below.
s/on behalf of the parent downstream device/for the parent bridge/ s/possibilty/possibility/
Quoted 7 lines
+++
b/drivers/pci/probe.cdrivers/pci/probe.c +2
-0@@ -1709,6 +1709,33 @@ static void set_pcie_thunderbolt(struct pci_dev *dev) dev->is_thunderbolt =1 ; } +static void set_pcie_cxl (struct pci_dev *dev) +{
drivers/pci/probe.c static void set_pcie_thunderbolt(struct pci_dev *dev) · line 1723
Quoted 10 lines
drivers/pci/probe.c +10
-0+struct pci_dev *parent; +u16 dvsec =pci_find_dvsec_capability (dev,PCI_VENDOR_ID_CXL , +PCI_DVSEC_CXL_FLEXBUS_PORT ); +if (dvsec) { +u16 cap; + +pci_read_config_word (dev, dvsec +PCI_DVSEC_CXL_FLEXBUS_STATUS_OFFSET , &cap); + + dev->is_cxl =FIELD_GET (PCI_DVSEC_CXL_FLEXBUS_STATUS_CACHE_MASK , cap) || +FIELD_GET (PCI_DVSEC_CXL_FLEXBUS_STATUS_MEM_MASK , cap);
Wrap to fit in 80 columns like the rest of the file.
Not sure the "_MASK" and "_OFFSET" on the end of all these #defines is really needed. Other items in pci_regs.h typically don't include them, and these names get really long.
drivers/pci/probe.c static void set_pcie_thunderbolt(struct pci_dev *dev) · line 1729
Quoted 6 lines
drivers/pci/probe.c +6
-0+ } + +if (!pci_is_pcie (dev) || + !(pci_pcie_type (dev) ==PCI_EXP_TYPE_ENDPOINT || +pci_pcie_type (dev) ==PCI_EXP_TYPE_UPSTREAM )) +return ;
Maybe could do the pci_is_pcie() check first, before the pci_find_dvsec_capability(), so we could avoid that search, e.g.,
if (!pci_is_pcie(dev))
return;
dvsec = pci_find_dvsec_capability(dev, PCI_VENDOR_ID_CXL, ...);
drivers/pci/probe.c static void set_pcie_thunderbolt(struct pci_dev *dev) · line 1733
Quoted 3 lines
drivers/pci/probe.c +3
-0+/* +* Update parent's CXL state because alternate protocol training +* may have changed
What is the event that changes alternate protocol training? The commit log says "once a device is created", but I don't know what that means in terms of hardware.
Quoted 4 lines
drivers/pci/probe.c +4
-0+*/ + parent =pci_upstream_bridge (dev); +set_pcie_cxl (parent); +}
Re: [PATCH v13 01/25] CXL/PCI: Move CXL DVSEC definitions into uapi/linux/pci_regs.h
In reply to [email protected]Quoted 15 lines · On Fri, Dec 05, 2025 at 04:41:40PM -0800, [email protected] wrote:
Quoted 6 lines · Bjorn Helgaas
Quoted 4 lines · Terry Bowman
The CXL DVSECs are currently defined in
cxl/core/cxlpci.h. These are not accessible to other subsystems. Move these touapi/linux/pci_regs.h.+#define
PCI_DVSEC_HEADER1_LENGTH_MASK__GENMASK(31, 20)Quoted 7 lines
Looks like a functional duplicate of
PCI_DVSEC_HEADER1_LEN().Why
__GENMASK()instead ofGENMASK()? I don't know the purpose of__GENMASK(), but I see otherinclude/uapi/files usingGENMASK(). Maybe they're wrong?Same questions for
_BITUL()below.
Quoted 8 lines
See this commit:
3c7a8e190bc5uapi: introduce uapi-friendly macros for GENMASK
GENMASK()for a long time was not available to uapi headers since uapi headers can only include otherinclude/uapi/headers, notinclude/linux/. That commit made some common kernel bitfield helpers finally available to the uapi side of the house.
So are the uses I see here wrong?
git grep "\<GENMASK\|\<BIT\>" include/uapi/
Re: [PATCH v13 01/25] CXL/PCI: Move CXL DVSEC definitions into uapi/linux/pci_regs.h
Quoted 20 lines · Bjorn Helgaas
Quoted 19 lines · On Fri, Dec 05, 2025 at 04:41:40PM -0800, [email protected] wrote:
Quoted 6 lines · Bjorn Helgaas
Quoted 4 lines · Terry Bowman
The CXL DVSECs are currently defined in
cxl/core/cxlpci.h. These are not accessible to other subsystems. Move these touapi/linux/pci_regs.h.+#define
PCI_DVSEC_HEADER1_LENGTH_MASK__GENMASK(31, 20)Quoted 7 lines
Looks like a functional duplicate of
PCI_DVSEC_HEADER1_LEN().Why
__GENMASK()instead ofGENMASK()? I don't know the purpose of__GENMASK(), but I see otherinclude/uapi/files usingGENMASK(). Maybe they're wrong?Same questions for
_BITUL()below.See this commit:
3c7a8e190bc5uapi: introduce uapi-friendly macros for GENMASK
Quoted 8 lines
Quoted 4 lines
GENMASK()for a long time was not available to uapi headers since uapi headers can only include otherinclude/uapi/headers, notinclude/linux/. That commit made some common kernel bitfield helpers finally available to the uapi side of the house.So are the uses I see here wrong?
git grep "\<GENMASK\|\<BIT\>"
include/uapi/
Yes, but the build failure for userspace can be mitigated if it provides a replacement defintion. For example, the project for CXL user tooling locally defines:
util/bitmap.h:34:#define BIT(nr) (1UL << (nr))
util/bitmap.h:31:#define GENMASK(h, l) \
...to supplement the missing kernel definitions, but those predated 2023. Paolo solved the problem globally with 3c7a8e190bc5.
Otherwise, userspace projects that do not already locally define GENMASK() but include uapi/pci_regs.h would start seeing new build failures when they update kernel headers.
Re: [PATCH v13 02/25] PCI/CXL: Introduce pcie_is_cxl()
In reply to Bjorn HelgaasQuoted 15 lines · Bjorn Helgaas
Quoted 6 lines · Terry Bowman
CXL and AER drivers need the ability to identify CXL devices.
Introduce
set_pcie_cxl()with logic checking for CXL.mem or CXL.cache status in the CXL Flexbus DVSEC status register. The CXL Flexbus DVSEC presence is used because it is required for all the CXL PCIe devices.[1]Quoted 7 lines
Add boolean 'struct
pci_dev::is_cxl' with the purpose to cache the CXL CXL.cache and CXl.mem status.In the case the device is an EP or USP, call
set_pcie_cxl()on behalf of the parent downstream device. Once a device is created there is possibilty the parent training or CXL state was updated as well. This will make certain the correct parent CXL state is cached.
Quoted 5 lines
See question at comment below.
s/on behalf of the parent downstream device/for the parent bridge/ s/possibilty/possibility/
Ok
Quoted 5 lines
Quoted 5 lines
+++
b/drivers/pci/probe.cdrivers/pci/probe.c +0
-0@@ -1709,6 +1709,33 @@ static void set_pcie_thunderbolt(struct pci_dev *dev) dev->is_thunderbolt =1 ; }
Quoted 15 lines
drivers/pci/probe.c static void set_pcie_thunderbolt(struct pci_dev *dev) · line 1723
Quoted 12 lines
drivers/pci/probe.c +12
-0+static void set_pcie_cxl (struct pci_dev *dev) +{ +struct pci_dev *parent; +u16 dvsec =pci_find_dvsec_capability (dev,PCI_VENDOR_ID_CXL , +PCI_DVSEC_CXL_FLEXBUS_PORT ); +if (dvsec) { +u16 cap; + +pci_read_config_word (dev, dvsec +PCI_DVSEC_CXL_FLEXBUS_STATUS_OFFSET , &cap); + + dev->is_cxl =FIELD_GET (PCI_DVSEC_CXL_FLEXBUS_STATUS_CACHE_MASK , cap) || +FIELD_GET (PCI_DVSEC_CXL_FLEXBUS_STATUS_MEM_MASK , cap);Wrap to fit in 80 columns like the rest of the file.
Ok
Quoted 4 lines
Not sure the "
_MASK" and "_OFFSET" on the end of all these #defines is really needed. Other items inpci_regs.htypically don't include them, and these names get really long.
These were moved over from local CXL header. As a result they are not consistent in the usage of offset and mask. Would you like for this to be made the same ? This would be to change all points where used.
Quoted 10 lines
drivers/pci/probe.c static void set_pcie_thunderbolt(struct pci_dev *dev) · line 1729
Quoted 6 lines
drivers/pci/probe.c +6
-0+ } + +if (!pci_is_pcie (dev) || + !(pci_pcie_type (dev) ==PCI_EXP_TYPE_ENDPOINT || +pci_pcie_type (dev) ==PCI_EXP_TYPE_UPSTREAM )) +return ;Maybe could do the
pci_is_pcie()check first, before thepci_find_dvsec_capability(), so we could avoid that search, e.g.,
Good idea.
Quoted 5 lines
if (!pci_is_pcie(dev))
return;dvsec = pci_find_dvsec_capability(dev, PCI_VENDOR_ID_CXL, ...);
Quoted 8 lines
drivers/pci/probe.c static void set_pcie_thunderbolt(struct pci_dev *dev) · line 1733
Quoted 3 lines
drivers/pci/probe.c +3
-0+/* +* Update parent's CXL state because alternate protocol training +* may have changed What is the event that changes alternate protocol training? The commit log says "once a device is created", but I don't know what that means in terms of hardware.
There is potential an upstream device (switch) was hotpluged and in the case of the alt training retries may not be correctly cached in pci_dev::is_cxl.
Quoted 4 lines
drivers/pci/probe.c static void set_pcie_thunderbolt(struct pci_dev *dev) · line 1737
Quoted 4 lines
drivers/pci/probe.c +4
-0+*/ + parent =pci_upstream_bridge (dev); +set_pcie_cxl (parent); +}
Thanks for reviewing.
Note, this is the wrong series (the last 2 patches in this series failed to send). I resent here:
https://lore.kernel.org/linux-cxl/[email protected]/
Regards,
Terry
Re: [PATCH v13 07/25] CXL/AER: Replace device_lock() in cxl_rch_handle_error_iter() with guard() lock
In reply to Terry BowmanQuoted 3 lines · Terry Bowman
cxl_rch_handle_error_iter()includes a call todevice_lock()using a goto for multiple return paths. Improve readability and maintainability by using theguard()lock variant.
I would reorder this patch to be after you move the function to aer_cxl_rch.c. Then the subjects could be more like this, which would be a better match for the history:
PCI/AER: Move CXL RCH error handling to aer_cxl_rch.c PCI/AER: Use guard() in cxl_rch_handle_error_iter()
I expect CXL content in drivers/pci/ to be mostly incidental, so I think prefixes like "PCI/AER" or "PCI/ERR" are probably appropriate, and "CXL" can appear in the rest of the line if relevant.
drivers/pci/pcie/aer.c static int cxl_rch_handle_error_iter(struct pci_dev *dev, void *data) · line 1190
Quoted 6 lines
+++
b/drivers/pci/pcie/aer.cdrivers/pci/pcie/aer.c +0
-1@@ -1187,12 +1187,11 @@ static int cxl_rch_handle_error_iter(struct pci_dev *dev, void *data)if (!is_cxl_mem_dev (dev) || !cxl_error_is_native (dev))return 0 ; -/* Protect dev->driver */
The comment seems worth keeping.
Quoted 22 lines
drivers/pci/pcie/aer.c +2
-4-device_lock (&dev->dev); +guard (device)(&dev->dev); err_handler = dev->driver ? dev->driver->err_handler :NULL ;if (!err_handler) - goto out; +return 0 ;if (info->severity ==AER_CORRECTABLE ) {if (err_handler->cor_error_detected)@@ -1203,8 +1202,6 @@ static int cxl_rch_handle_error_iter(struct pci_dev *dev, void *data)else if (info->severity ==AER_FATAL ) err_handler->error_detected (dev, pci_channel_io_frozen); } -out: -device_unlock (&dev->dev);return 0 ; }Signature · 1 line
2.34.1
Re: [PATCH v13 08/25] CXL/AER: Move AER drivers RCH error handling into pcie/aer_cxl_rch.c
In reply to Terry BowmanI vote for a subject like:
PCI/AER: Move CXL RCH error handling to aer_cxl_rch.c
I think stuff in drivers/pci should have a PCI/... prefix. "CXL" is really its own major subsystem, not a feature of PCI.
Quoted 3 lines · Terry Bowman
The restricted CXL Host (RCH) AER error handling logic currently resides in the AER driver file,
drivers/pci/pcie/aer.c. CXL specific changes are conditionally compiled using #ifdefs.
s|the AER driver file, drivers/pci/pcie/aer.c|aer.c|
Quoted 12 lines
Improve the AER driver maintainability by separating the RCH specific logic from the AER driver's core functionality and removing the ifdefs. Introduce
drivers/pci/pcie/aer_cxl_rch.cfor moving the RCH AER logic into. Conditionally compile the file using theCONFIG_CXL_RCH_RASKconfig.Move the CXL logic into the new file but leave helper functions in
aer.cfor now as they will be moved in future patch for CXL virtual hierarchy handling. Export the handler functions as needed. Exportpci_aer_unmask_internal_errors()allowing for all subsystems to use. Avoid multiple declaration moves and exportcxl_error_is_native()now to allow access fromcxl_core.
Quoted 3 lines
Inorder to maintain compilation after the move other changes are required. Change
cxl_rch_handle_error()&cxl_rch_enable_rcec()to be non-static inorder for accessing from the AER driver inaer.c.
s/Inorder to/In order to/ (or just "To maintain ...") /inorder for accessing from the AER driver in/so they can be used by/
Quoted 2 lines
Update the new file with the SPDX and 2023 AMD copyright notations because the RCH bits were initally contributed in 2023 by AMD.
Maybe cite the commit that did this so it's easy to check.
drivers/pci/pci.h static inline int pci_msix_write_tph_tag(struct pci_dev *pdev, unsigned int inde · line 1311
Quoted 6 lines
+++
b/drivers/pci/pci.hdrivers/pci/pci.h +4
-0+#ifdef CONFIG_CXL_RAS +bool is_internal_error (struct aer_err_info *info); +#else +static inline bool is_internal_error (struct aer_err_info *info) {return false; }
This used to be static and internal. "is_internal_error()" seems a little too generic now that it's not static; probably should include "aer". Maybe rename it in a preliminary patch so the move is more of a pure move.
Quoted 11 lines
+++
b/drivers/pci/pcie/aer.cdrivers/pci/pcie/aer.c +1
-1@@ -1130,7 +1130,7 @@ static bool find_source_device(struct pci_dev *parent,* Note: AER must be enabled and supported by the device which must be * checked in advance, e.g. with pcie_aer_is_native(). */ -static void pci_aer_unmask_internal_errors (struct pci_dev *dev) +void pci_aer_unmask_internal_errors (struct pci_dev *dev) {int aer = dev->aer_cap;u32 mask;
drivers/pci/pcie/aer.c static void pci_aer_unmask_internal_errors(struct pci_dev *dev) · line 1146
Quoted 4 lines
drivers/pci/pcie/aer.c +1
-0@@ -1143,116 +1143,25 @@ static void pci_aer_unmask_internal_errors(struct pci_dev *dev) mask &= ~PCI_ERR_COR_INTERNAL ;pci_write_config_dword (dev, aer +PCI_ERR_COR_MASK , mask); } +EXPORT_SYMBOL_GPL (pci_aer_unmask_internal_errors);
Not sure why these EXPORTs are needed. Is there a caller that can be a module? The callers I see look like they would be builtin. If you add callers later that need this, the export can be done then.
Quoted 9 lines
include/linux/aer.h +2
-0+++ b/include/linux/aer.h@@ -56,12 +56,20 @@ struct aer_capability_regs {#if defined(CONFIG_PCIEAER )int pci_aer_clear_nonfatal_status (struct pci_dev *dev);int pcie_aer_is_native (struct pci_dev *dev); +void pci_aer_unmask_internal_errors (struct pci_dev *dev);#else static inline int pci_aer_clear_nonfatal_status (struct pci_dev *dev) {
include/linux/aer.h struct aer_capability_regs { · line 72
Quoted 10 lines
include/linux/aer.h +7
-0return -EINVAL; }static inline int pcie_aer_is_native (struct pci_dev *dev) {return 0 ; } +static inline void pci_aer_unmask_internal_errors (struct pci_dev *dev) { } +#endif + +#ifdef CONFIG_CXL_RAS +bool cxl_error_is_native (struct pci_dev *dev); +#else +static inline bool cxl_error_is_native (struct pci_dev *dev) {return false; }
These include/linux/aer.h changes look like a separate patch. Moving code from aer.c to aer_cxl_rch.c doesn't add any callers outside drivers/pci, so these shouldn't need to be in include/linux/.
Re: [PATCH v13 02/25] PCI/CXL: Introduce pcie_is_cxl()
In reply to Bowman, TerryQuoted 7 lines · Terry
Quoted 6 lines · Bjorn Helgaas
Quoted 5 lines · Terry Bowman
CXL and AER drivers need the ability to identify CXL devices.
Introduce
set_pcie_cxl()with logic checking for CXL.mem or CXL.cache status in the CXL Flexbus DVSEC status register. The CXL Flexbus DVSEC presence is used because it is required for all the CXL PCIe devices.[1]
Spec usage seems to be "Flex Bus", which would help searches.
Quoted 18 lines
Quoted 7 lines
Quoted 7 lines
Add boolean 'struct
pci_dev::is_cxl' with the purpose to cache the CXL CXL.cache and CXl.mem status.In the case the device is an EP or USP, call
set_pcie_cxl()on behalf of the parent downstream device. Once a device is created there is possibilty the parent training or CXL state was updated as well. This will make certain the correct parent CXL state is cached....
Quoted 8 lines
drivers/pci/probe.c static void set_pcie_thunderbolt(struct pci_dev *dev) · line 1723
Quoted 4 lines
drivers/pci/probe.c +4
-0+pci_read_config_word (dev, dvsec +PCI_DVSEC_CXL_FLEXBUS_STATUS_OFFSET , &cap); + + dev->is_cxl =FIELD_GET (PCI_DVSEC_CXL_FLEXBUS_STATUS_CACHE_MASK , cap) || +FIELD_GET (PCI_DVSEC_CXL_FLEXBUS_STATUS_MEM_MASK , cap);Not sure the "
_MASK" and "_OFFSET" on the end of all these #defines is really needed. Other items inpci_regs.htypically don't include them, and these names get really long.
Quoted 3 lines
These were moved over from local CXL header. As a result they are not consistent in the usage of offset and mask. Would you like for this to be made the same ? This would be to change all points where used.
I think it's worth dropping "_MASK" and "_OFFSET" to reduce the length.
Quoted 10 lines
Quoted 6 lines
drivers/pci/probe.c static void set_pcie_thunderbolt(struct pci_dev *dev) · line 1733
Quoted 2 lines
drivers/pci/probe.c +2
-0+* Update parent's CXL state because alternate protocol training +* may have changed What is the event that changes alternate protocol training? The commit log says "once a device is created", but I don't know what that means in terms of hardware.
There is potential an upstream device (switch) was hotpluged and in the case of the alt training retries may not be correctly cached in
pci_dev::is_cxl.
I assume this refers to the Alternate Protocol Negotiation (PCIe r7.0, seg 4.2.5.2), which happens during link training.
IIUC, the problem here is that we may enumerate a bridge before its secondary link has trained. In that case, the Cache_Enabled and Mem_Enabled bits in the bridge's Flex Bus Port Status may be zero. After the secondary link has trained, those bits may be set based on the alternate protocol negotiation, so we need to re-read the bridges Port Status. Annoying that these are documented as RO when they don't really seem to be read-only.
Maybe there's no point in reading the bridge Flex Bus Port Status at all until we enumerate a device *below* the bridge, e.g, something like this:
if (!pci_is_pcie(dev))
return;
if (!(pci_pcie_type(dev) == PCI_EXP_TYPE_ENDPOINT ||
pci_pcie_type(dev) == PCI_EXP_TYPE_UPSTREAM))
return; /* Parent's CXL status only valid when link to child has trained */ bridge = pci_upstream_bridge(dev);
dvsec = pci_find_dvsec_capability(bridge, PCI_VENDOR_ID_CXL,
PCI_DVSEC_CXL_FLEXBUS_PORT);
if (!dvsec)
return;pci_read_config_word(bridge, dvsec + PCI_DVSEC_CXL_FLEXBUS_STATUS_OFFSET, &cap); ...
Re: [PATCH v13 16/25] CXL/AER: Introduce pcie/aer_cxl_vh.c in AER driver for forwarding CXL errors
In reply to Terry BowmanMaybe:
PCI/AER: Add CXL error forwarding in aer_cxl_vh.c
Quoted 16 lines · Terry Bowman
CXL virtual hierarchy (VH) RAS handling for CXL Port devices will be added soon. This requires a notification mechanism for the AER driver to share the AER interrupt with the CXL driver. The notification will be used as an indication for the CXL drivers to handle and log the CXL RAS errors.
Note, 'CXL protocol error' terminology will refer to CXL VH and not CXL RCH errors unless specifically noted going forward.
Introduce a new file in the AER driver to handle the CXL protocol errors named
pci/pcie/aer_cxl_vh.c.Add a kfifo work queue to be used by the AER and CXL drivers. The AER driver will be the sole kfifo producer adding work and the
cxl_corewill be the sole kfifo consumer removing work. Add the boilerplate kfifo support. Encapsulate the kfifo, RW semaphore, and work pointer in a single structure.
Quoted 8 lines
Add CXL work queue handler registration functions in the AER driver. Export the functions allowing CXL driver to access. Implement registration functions for the CXL driver to assign or clear the work handler function. Synchronize accesses using the RW semaphore.
Introduce 'struct
cxl_proto_err_work_data' to serve as the kfifo work data. This will contain a reference to the erring PCI device and the error severity. This will be used when the work is dequeued by thecxl_coredriver.
s/erring PCI device/PCI error source device/
drivers/pci/pcie/aer_cxl_vh.c line 30
Quoted 7 lines
drivers/pci/pcie/aer_cxl_vh.c new file +7
-0+bool cxl_error_is_native (struct pci_dev *dev) +{ +struct pci_host_bridge *host =pci_find_host_bridge (dev->bus); + +return (pcie_ports_native || host->native_aer); +} +EXPORT_SYMBOL_NS_GPL (cxl_error_is_native,"CXL" );
I don't see modular callers of any of these that would require EXPORT().
include/linux/aer.h line 13
Quoted 6 lines
+++
b/include/linux/aer.hinclude/linux/aer.h +1
-0@@ -10,6 +10,7 @@#include <linux/errno.h> #include <linux/types.h> +#include <linux/workqueue_types.h>
Looks like "struct work_struct;" would be sufficient without including linux/workqueue_types.h.
include/linux/aer.h struct aer_capability_regs { · line 64
Quoted 3 lines
include/linux/aer.h +3
-0+struct cxl_proto_err_work_data { +int severity; +struct pci_dev *pdev;
Is there a reason to order them this way? I would have put the pdev pointer first because it's the more general part and might result in better alignment in memory.
Re: [PATCH v13 20/25] CXL/PCI: Introduce CXL Port protocol error handlers
In reply to Terry BowmanQuoted 18 lines · Terry Bowman
Add CXL protocol error handlers for CXL Port devices (Root Ports, Downstream Ports, and Upstream Ports). Implement
cxl_port_cor_error_detected()andcxl_port_error_detected()to handle correctable and uncorrectable errors respectively.Introduce
cxl_get_ras_base()to retrieve the cached RAS register base address for a given CXL port. This function supports CXL Root Ports, Downstream Ports, and Upstream Ports by returning their previously mapped RAS register addresses.Add device lock assertions to protect against concurrent device or RAS register removal during error handling. The port error handlers require two device locks:
1. The port's CXL parent device - RAS registers are mapped using devm_* functions with the parent port as the host. Locking the parent prevents the RAS registers from being unmapped during error handling.
Quoted 5 lines
2. The PCI device (
pdev->dev) - Locking prevents concurrent modifications to the PCI device structure during error handling.The lock assertions added here will be satisfied by device locks introduced in a subsequent patch.
Weird. Can't you add the lock assertions at the same time you add the locks?
Quoted 7 lines
Introduce
get_pci_cxl_host_dev()to return the device responsible for managing the RAS register mapping. This function increments the reference count on the host device to prevent premature resource release during error handling. The caller is responsible for decrementing the reference count. For CXL endpoints, which manage resources without a separate host device, this function returns NULL.
Quoted 6 lines
Update the AER driver's
is_cxl_error()to recognize CXL Port devices in addition to CXL Endpoints, as both now have CXL-specific error handlers.Signed-off-by Terry Bowman <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Kuppuswamy Sathyanarayanan <[email protected]>
drivers/cxl/core/port.c static struct cxl_port *find_cxl_port_by_uport(struct device *uport_dev) · line 1576
Quoted 5 lines
drivers/cxl/core/port.c +1
-0@@ -1573,6 +1573,7 @@ static struct cxl_port *find_cxl_port_by_uport(struct device *uport_dev)return to_cxl_port (dev);return NULL ; } +EXPORT_SYMBOL_NS_GPL (find_cxl_port_by_uport,"CXL" );
The usual export question: is there a modular caller()?
drivers/cxl/core/ras.c static void cxl_dport_map_ras(struct cxl_dport *dport) · line 177
Quoted 1 line
drivers/cxl/core/ras.c +1
-0+dev_warn_once (dev,"Error: Unsupported device type (%X)" ,pci_pcie_type (pdev));
Maybe "%#x" (add 0x prefix and use lower-case hex, unless there's a different CXL convention)?
Re: [PATCH v13 22/25] CXL/PCI: Export and rename merge_result() to pci_ers_merge_result()
In reply to Terry BowmanPossible subject:
PCI/ERR: Rename merge_result() to pcie_ers_merge_result()
since there's no CXL content here.
Quoted 7 lines · Terry Bowman
CXL uncorrectable errors (UCE) will soon be handled separately from the PCI AER handling. The
merge_result()function can be made common to use in both handling paths.Rename the PCI subsystem's
merge_result()to bepci_ers_merge_result(). Exportpci_ers_merge_result()to make available for the CXL and other drivers to use.
Still dubious about exporting this.
Quoted 2 lines
Update
pci_ers_merge_result()to support recently introducedPCI_ERS_RESULT_PANICresult.
Code is pcie_ers_merge_result(), not pci_ers_merge_result().
But I actually think "pci" might be more appropriate because I think this is used in generic PCI paths that can be exercised for non-PCIe. Either way, make them all consistent.
drivers/pci/pcie/err.c line 28
Quoted 12 lines
+++
b/drivers/pci/pcie/err.cdrivers/pci/pcie/err.c +4
-2@@ -21,9 +21,12 @@#include "portdrv.h" #include "../pci.h" -static pci_ers_result_t merge_result (enum pci_ers_result orig, -enum pci_ers_result new) +pci_ers_result_t pcie_ers_merge_result (enum pci_ers_result orig, +enum pci_ers_result new) { +if (new ==PCI_ERS_RESULT_PANIC ) +return PCI_ERS_RESULT_PANIC ;
I think this should be squashed with the "CXL/PCI: Introduce PCI_ERS_RESULT_PANIC" patch and called:
PCI/ERR: Add PCI_ERS_RESULT_PANIC
so the new functionality is all together and the rename is separate.
Re: [PATCH v13 08/25] CXL/AER: Move AER drivers RCH error handling into pcie/aer_cxl_rch.c
In reply to Bjorn HelgaasQuoted 30 lines · Bjorn Helgaas
I vote for a subject like:
PCI/AER: Move CXL RCH error handling to
aer_cxl_rch.cI think stuff in
drivers/pcishould have a PCI/... prefix. "CXL" is really its own major subsystem, not a feature of PCI.Quoted 3 lines · Terry Bowman
The restricted CXL Host (RCH) AER error handling logic currently resides in the AER driver file,
drivers/pci/pcie/aer.c. CXL specific changes are conditionally compiled using #ifdefs.s|the AER driver file, drivers/pci/pcie/aer.c|aer.c|
Quoted 12 lines
Improve the AER driver maintainability by separating the RCH specific logic from the AER driver's core functionality and removing the ifdefs. Introduce
drivers/pci/pcie/aer_cxl_rch.cfor moving the RCH AER logic into. Conditionally compile the file using theCONFIG_CXL_RCH_RASKconfig.Move the CXL logic into the new file but leave helper functions in
aer.cfor now as they will be moved in future patch for CXL virtual hierarchy handling. Export the handler functions as needed. Exportpci_aer_unmask_internal_errors()allowing for all subsystems to use. Avoid multiple declaration moves and exportcxl_error_is_native()now to allow access fromcxl_core.Quoted 3 lines
Inorder to maintain compilation after the move other changes are required. Change
cxl_rch_handle_error()&cxl_rch_enable_rcec()to be non-static inorder for accessing from the AER driver inaer.c.
Quoted 8 lines
s/Inorder to/In order to/ (or just "To maintain ...") /inorder for accessing from the AER driver in/so they can be used by/
Quoted 2 lines
Update the new file with the SPDX and 2023 AMD copyright notations because the RCH bits were initally contributed in 2023 by AMD.
Maybe cite the commit that did this so it's easy to check.
Ok
Quoted 23 lines
drivers/pci/pci.h static inline int pci_msix_write_tph_tag(struct pci_dev *pdev, unsigned int inde · line 1311
Quoted 6 lines
+++
b/drivers/pci/pci.hdrivers/pci/pci.h +4
-0+#ifdef CONFIG_CXL_RAS +bool is_internal_error (struct aer_err_info *info); +#else +static inline bool is_internal_error (struct aer_err_info *info) {return false; }This used to be static and internal. "
is_internal_error()" seems a little too generic now that it's not static; probably should include "aer". Maybe rename it in a preliminary patch so the move is more of a pure move.Quoted 11 lines
+++
b/drivers/pci/pcie/aer.cdrivers/pci/pcie/aer.c +1
-1@@ -1130,7 +1130,7 @@ static bool find_source_device(struct pci_dev *parent,* Note: AER must be enabled and supported by the device which must be * checked in advance, e.g. with pcie_aer_is_native(). */ -static void pci_aer_unmask_internal_errors (struct pci_dev *dev) +void pci_aer_unmask_internal_errors (struct pci_dev *dev) {int aer = dev->aer_cap;u32 mask;@@ -1143,116 +1143,25 @@ static void pci_aer_unmask_internal_errors(struct pci_dev *dev)
Quoted 9 lines
drivers/pci/pcie/aer.c static void pci_aer_unmask_internal_errors(struct pci_dev *dev) · line 1146
Quoted 4 lines
drivers/pci/pcie/aer.c +1
-0mask &= ~PCI_ERR_COR_INTERNAL ;pci_write_config_dword (dev, aer +PCI_ERR_COR_MASK , mask); } +EXPORT_SYMBOL_GPL (pci_aer_unmask_internal_errors);Not sure why these EXPORTs are needed. Is there a caller that can be a module? The callers I see look like they would be builtin. If you add callers later that need this, the export can be done then.
pci_aer_unmask_internal_errors() is called by the cxl_core module later in the 2nd to-last patch. I'll move the export change to the later patch. At one point I was trying to avoid changes to same definitions multiple times.
Quoted 15 lines
Quoted 15 lines
include/linux/aer.h +5
-0+++ b/include/linux/aer.h@@ -56,12 +56,20 @@ struct aer_capability_regs {#if defined(CONFIG_PCIEAER )int pci_aer_clear_nonfatal_status (struct pci_dev *dev);int pcie_aer_is_native (struct pci_dev *dev); +void pci_aer_unmask_internal_errors (struct pci_dev *dev);#else static inline int pci_aer_clear_nonfatal_status (struct pci_dev *dev) {return -EINVAL ; }static inline int pcie_aer_is_native (struct pci_dev *dev) {return 0 ; } +static inline void pci_aer_unmask_internal_errors (struct pci_dev *dev) { } +#endif +
Quoted 8 lines
include/linux/aer.h struct aer_capability_regs { · line 72
Quoted 4 lines
include/linux/aer.h +4
-0+#ifdef CONFIG_CXL_RAS +bool cxl_error_is_native (struct pci_dev *dev); +#else +static inline bool cxl_error_is_native (struct pci_dev *dev) {return false; }These
include/linux/aer.hchanges look like a separate patch. Moving code fromaer.ctoaer_cxl_rch.cdoesn't add any callers outsidedrivers/pci, so these shouldn't need to be ininclude/linux/.
I'll remove these from here.
- Terry
Re: [PATCH v13 20/25] CXL/PCI: Introduce CXL Port protocol error handlers
In reply to Bjorn HelgaasQuoted 19 lines · Bjorn Helgaas
Quoted 18 lines · Terry Bowman
Add CXL protocol error handlers for CXL Port devices (Root Ports, Downstream Ports, and Upstream Ports). Implement
cxl_port_cor_error_detected()andcxl_port_error_detected()to handle correctable and uncorrectable errors respectively.Introduce
cxl_get_ras_base()to retrieve the cached RAS register base address for a given CXL port. This function supports CXL Root Ports, Downstream Ports, and Upstream Ports by returning their previously mapped RAS register addresses.Add device lock assertions to protect against concurrent device or RAS register removal during error handling. The port error handlers require two device locks:
1. The port's CXL parent device - RAS registers are mapped using devm_* functions with the parent port as the host. Locking the parent prevents the RAS registers from being unmapped during error handling.
Quoted 9 lines
Quoted 5 lines
2. The PCI device (
pdev->dev) - Locking prevents concurrent modifications to the PCI device structure during error handling.The lock assertions added here will be satisfied by device locks introduced in a subsequent patch.
Weird. Can't you add the lock assertions at the same time you add the locks?
It is a bit. I will try to fix this. I might try adding adding the lockdep() checks in the later later patch.
Quoted 7 lines
Quoted 7 lines
Introduce
get_pci_cxl_host_dev()to return the device responsible for managing the RAS register mapping. This function increments the reference count on the host device to prevent premature resource release during error handling. The caller is responsible for decrementing the reference count. For CXL endpoints, which manage resources without a separate host device, this function returns NULL.
Quoted 9 lines
Quoted 6 lines
Update the AER driver's
is_cxl_error()to recognize CXL Port devices in addition to CXL Endpoints, as both now have CXL-specific error handlers.Signed-off-by Terry Bowman <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Kuppuswamy Sathyanarayanan <[email protected]>Acked-by Bjorn Helgaas <[email protected]>
Thanks.
Quoted 8 lines
drivers/cxl/core/port.c static struct cxl_port *find_cxl_port_by_uport(struct device *uport_dev) · line 1576
Quoted 5 lines
drivers/cxl/core/port.c +1
-0@@ -1573,6 +1573,7 @@ static struct cxl_port *find_cxl_port_by_uport(struct device *uport_dev)return to_cxl_port (dev);return NULL ; } +EXPORT_SYMBOL_NS_GPL (find_cxl_port_by_uport,"CXL" );The usual export question: is there a modular
caller()?
This should be non-static and non-exported. I'll change.
Quoted 4 lines
drivers/cxl/core/ras.c static void cxl_dport_map_ras(struct cxl_dport *dport) · line 177
Quoted 1 line
drivers/cxl/core/ras.c +1
-0+dev_warn_once (dev,"Error: Unsupported device type (%X)" ,pci_pcie_type (pdev));Maybe "%#x" (add 0x prefix and use lower-case hex, unless there's a different CXL convention)?
Ok
-Terry
Re: [PATCH v13 08/25] CXL/AER: Move AER drivers RCH error handling into pcie/aer_cxl_rch.c
In reply to Bowman, TerryQuoted 103 lines · Terry
Quoted 30 lines · Bjorn Helgaas
I vote for a subject like:
PCI/AER: Move CXL RCH error handling to
aer_cxl_rch.cI think stuff in
drivers/pcishould have a PCI/... prefix. "CXL" is really its own major subsystem, not a feature of PCI.Quoted 3 lines · Terry Bowman
The restricted CXL Host (RCH) AER error handling logic currently resides in the AER driver file,
drivers/pci/pcie/aer.c. CXL specific changes are conditionally compiled using #ifdefs.s|the AER driver file, drivers/pci/pcie/aer.c|aer.c|
Quoted 12 lines
Improve the AER driver maintainability by separating the RCH specific logic from the AER driver's core functionality and removing the ifdefs. Introduce
drivers/pci/pcie/aer_cxl_rch.cfor moving the RCH AER logic into. Conditionally compile the file using theCONFIG_CXL_RCH_RASKconfig.Move the CXL logic into the new file but leave helper functions in
aer.cfor now as they will be moved in future patch for CXL virtual hierarchy handling. Export the handler functions as needed. Exportpci_aer_unmask_internal_errors()allowing for all subsystems to use. Avoid multiple declaration moves and exportcxl_error_is_native()now to allow access fromcxl_core.Quoted 3 lines
Inorder to maintain compilation after the move other changes are required. Change
cxl_rch_handle_error()&cxl_rch_enable_rcec()to be non-static inorder for accessing from the AER driver inaer.c.Quoted 8 lines
s/Inorder to/In order to/ (or just "To maintain ...") /inorder for accessing from the AER driver in/so they can be used by/
Quoted 2 lines
Update the new file with the SPDX and 2023 AMD copyright notations because the RCH bits were initally contributed in 2023 by AMD.
Maybe cite the commit that did this so it's easy to check.
Ok
Quoted 23 lines
drivers/pci/pci.h static inline int pci_msix_write_tph_tag(struct pci_dev *pdev, unsigned int inde · line 1311
Quoted 6 lines
+++
b/drivers/pci/pci.hdrivers/pci/pci.h +4
-0+#ifdef CONFIG_CXL_RAS +bool is_internal_error (struct aer_err_info *info); +#else +static inline bool is_internal_error (struct aer_err_info *info) {return false; }This used to be static and internal. "
is_internal_error()" seems a little too generic now that it's not static; probably should include "aer". Maybe rename it in a preliminary patch so the move is more of a pure move.Quoted 11 lines
+++
b/drivers/pci/pcie/aer.cdrivers/pci/pcie/aer.c +1
-1@@ -1130,7 +1130,7 @@ static bool find_source_device(struct pci_dev *parent,* Note: AER must be enabled and supported by the device which must be * checked in advance, e.g. with pcie_aer_is_native(). */ -static void pci_aer_unmask_internal_errors (struct pci_dev *dev) +void pci_aer_unmask_internal_errors (struct pci_dev *dev) {int aer = dev->aer_cap;u32 mask;@@ -1143,116 +1143,25 @@ static void pci_aer_unmask_internal_errors(struct pci_dev *dev)Quoted 9 lines
drivers/pci/pcie/aer.c static void pci_aer_unmask_internal_errors(struct pci_dev *dev) · line 1146
Quoted 4 lines
drivers/pci/pcie/aer.c +1
-0mask &= ~PCI_ERR_COR_INTERNAL ;pci_write_config_dword (dev, aer +PCI_ERR_COR_MASK , mask); } +EXPORT_SYMBOL_GPL (pci_aer_unmask_internal_errors);Not sure why these EXPORTs are needed. Is there a caller that can be a module? The callers I see look like they would be builtin. If you add callers later that need this, the export can be done then.
pci_aer_unmask_internal_errors()is called by thecxl_coremodule later in the 2nd to-last patch. I'll move the export change to the later patch. At one point I was trying to avoid changes to same definitions multiple times.Quoted 15 lines
Quoted 15 lines
include/linux/aer.h +5
-0+++ b/include/linux/aer.h@@ -56,12 +56,20 @@ struct aer_capability_regs {#if defined(CONFIG_PCIEAER )int pci_aer_clear_nonfatal_status (struct pci_dev *dev);int pcie_aer_is_native (struct pci_dev *dev); +void pci_aer_unmask_internal_errors (struct pci_dev *dev);#else static inline int pci_aer_clear_nonfatal_status (struct pci_dev *dev) {return -EINVAL ; }static inline int pcie_aer_is_native (struct pci_dev *dev) {return 0 ; } +static inline void pci_aer_unmask_internal_errors (struct pci_dev *dev) { } +#endif +Quoted 8 lines
include/linux/aer.h struct aer_capability_regs { · line 72
Quoted 4 lines
include/linux/aer.h +4
-0+#ifdef CONFIG_CXL_RAS +bool cxl_error_is_native (struct pci_dev *dev); +#else +static inline bool cxl_error_is_native (struct pci_dev *dev) {return false; }These
include/linux/aer.hchanges look like a separate patch. Moving code fromaer.ctoaer_cxl_rch.cdoesn't add any callers outsidedrivers/pci, so these shouldn't need to be ininclude/linux/.
Quoted 3 lines
I'll remove these from here.
- Terry
Hi Bjorn,
I reviewed this more closely and recalled the reasoning behind the change. Lukas requested that pci_aer_unmask_internal_errors() be made available across the entire kernel. I already noted this in the commit message, but I can also include a link to Lukas’s request. Alternatively, I could split this into a separate patch with a Recommended-by tag, leave it as is, or make another adjustment. Additionally, I’ll update cxl_error_is_native() so it’s only included when necessary.
Terry
Re: [PATCH v13 08/25] CXL/AER: Move AER drivers RCH error handling into pcie/aer_cxl_rch.c
Quoted 49 lines · Terry
Quoted 5 lines · Terry
Quoted 4 lines · Bjorn Helgaas
Quoted 3 lines · Terry Bowman
The restricted CXL Host (RCH) AER error handling logic currently resides in the AER driver file,
drivers/pci/pcie/aer.c. CXL specific changes are conditionally compiled using #ifdefs....
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Export
pci_aer_unmask_internal_errors()allowing for all subsystems to use....
Quoted 35 lines
Quoted 10 lines
drivers/pci/pcie/aer.c static void pci_aer_unmask_internal_errors(struct pci_dev *dev) · line 1146
Quoted 5 lines
drivers/pci/pcie/aer.c +1
-0@@ -1143,116 +1143,25 @@ static void pci_aer_unmask_internal_errors(struct pci_dev *dev) mask &= ~PCI_ERR_COR_INTERNAL ;pci_write_config_dword (dev, aer +PCI_ERR_COR_MASK , mask); } +EXPORT_SYMBOL_GPL (pci_aer_unmask_internal_errors);Not sure why these EXPORTs are needed. Is there a caller that can be a module? The callers I see look like they would be builtin. If you add callers later that need this, the export can be done then.
pci_aer_unmask_internal_errors()is called by thecxl_coremodule later in the 2nd to-last patch. I'll move the export change to the later patch. At one point I was trying to avoid changes to same definitions multiple times.Quoted 10 lines
Quoted 10 lines
include/linux/aer.h +2
-0+++ b/include/linux/aer.h@@ -56,12 +56,20 @@ struct aer_capability_regs {#if defined(CONFIG_PCIEAER )int pci_aer_clear_nonfatal_status (struct pci_dev *dev);int pcie_aer_is_native (struct pci_dev *dev); +void pci_aer_unmask_internal_errors (struct pci_dev *dev);#else static inline int pci_aer_clear_nonfatal_status (struct pci_dev *dev) {return -EINVAL ;Quoted 8 lines
include/linux/aer.h struct aer_capability_regs { · line 66
Quoted 3 lines
include/linux/aer.h +1
-0}static inline int pcie_aer_is_native (struct pci_dev *dev) {return 0 ; } +static inline void pci_aer_unmask_internal_errors (struct pci_dev *dev) { }These
include/linux/aer.hchanges look like a separate patch. Moving code fromaer.ctoaer_cxl_rch.cdoesn't add any callers outsidedrivers/pci, so these shouldn't need to be ininclude/linux/.Quoted 1 line
I'll remove these from here.
Quoted 8 lines
I reviewed this more closely and recalled the reasoning behind the change. Lukas requested that
pci_aer_unmask_internal_errors()be made available across the entire kernel. I already noted this in the commit message, but I can also include a link to Lukas’s request. Alternatively, I could split this into a separate patch with a Recommended-by tag, leave it as is, or make another adjustment. Additionally, I’ll updatecxl_error_is_native()so it’s only included when necessary.
There's a lot going on in this patch, which makes the commit log long and a bit cluttered.
Let's make the pci_aer_unmask_internal_errors() change a separate patch, combined with or immediately before adding a new user outside drivers/pci.
I assume you're referring to Lukas's email at [1], but he's responding to a patch that exported pci_aer_unmask_internal_errors() for modules but left the declaration in drivers/pci/pci.h.