PCI: Only override AMD USB controller if required
Subsystems (10)
Sasha Levin
maintainerPATCH 1/19 PCI: Only override AMD USB controller if required
From: "Guilherme G. Piccoli" <[email protected]>
[ Upstream commit e585a37e5061f6d5060517aed1ca4ccb2e56a34c ]
By running a Van Gogh device (Steam Deck), the following message was noticed in the kernel log:
pci 0000:04:00.3: PCI class overridden (0x0c03fe -> 0x0c03fe) so dwc3 driver can claim this instead of xhci
Effectively this means the quirk executed but changed nothing, since the class of this device was already the proper one (likely adjusted by newer firmware versions).
Check and perform the override only if necessary.
--- drivers/pci/quirks.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/pci/quirks.c +7 -4
@@ -604,10 +604,13 @@ static void quirk_amd_dwc_class(struct pci_dev *pdev) {u32 class = pdev->class; -/* Use "USB Device (not host controller)" class */ - pdev->class =PCI_CLASS_SERIAL_USB_DEVICE ; -pci_info (pdev,"PCI class overridden (%#08x -> %#08x) so dwc3 driver can claim this instead of xhci\n" , - class, pdev->class); +if (class !=PCI_CLASS_SERIAL_USB_DEVICE ) { +/* Use "USB Device (not host controller)" class */ + pdev->class =PCI_CLASS_SERIAL_USB_DEVICE ; +pci_info (pdev, +"PCI class overridden (%#08x -> %#08x) so dwc3 driver can claim this instead of xhci\n" , + class, pdev->class); + } }DECLARE_PCI_FIXUP_HEADER (PCI_VENDOR_ID_AMD ,PCI_DEVICE_ID_AMD_NL_USB , quirk_amd_dwc_class);
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 2/19 PCI: switchtec: Fix stdev_release() crash after surprise hot remove
From: Daniel Stodden <[email protected]>
[ Upstream commit df25461119d987b8c81d232cfe4411e91dcabe66 ]
A PCI device hot removal may occur while stdev->cdev is held open. The call to stdev_release() then happens during close or exit, at a point way past switchtec_pci_remove(). Otherwise the last ref would vanish with the trailing put_device(), just before return.
At that later point in time, the devm cleanup has already removed the stdev->mmio_mrpc mapping. Also, the stdev->pdev reference was not a counted one. Therefore, in DMA mode, the iowrite32() in stdev_release() will cause a fatal page fault, and the subsequent dma_free_coherent(), if reached, would pass a stale &stdev->pdev->dev pointer.
Fix by moving MRPC DMA shutdown into switchtec_pci_remove(), after stdev_kill(). Counting the stdev->pdev ref is now optional, but may prevent future accidents.
Reproducible via the script at
https://lore.kernel.org/r/[email protected]
--- drivers/pci/switch/switchtec.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
drivers/pci/switch/switchtec.c +17 -8
@@ -1250,13 +1250,6 @@ static void stdev_release(struct device *dev) {struct switchtec_dev *stdev =to_stdev (dev); -if (stdev->dma_mrpc) { -iowrite32 (0 , &stdev->mmio_mrpc->dma_en); -flush_wc_buf (stdev); -writeq (0 , &stdev->mmio_mrpc->dma_addr); -dma_free_coherent (&stdev->pdev->dev,sizeof (*stdev->dma_mrpc), - stdev->dma_mrpc, stdev->dma_mrpc_dma_addr); - }kfree (stdev); }
@@ -1300,7 +1293,7 @@ static struct switchtec_dev *stdev_create(struct pci_dev *pdev)return ERR_PTR (-ENOMEM ); stdev->alive = true; - stdev->pdev = pdev; + stdev->pdev =pci_dev_get (pdev);INIT_LIST_HEAD (&stdev->mrpc_queue);mutex_init (&stdev->mrpc_mutex); stdev->mrpc_busy =0 ;
@@ -1334,6 +1327,7 @@ static struct switchtec_dev *stdev_create(struct pci_dev *pdev)return stdev; err_put: +pci_dev_put (stdev->pdev);put_device (&stdev->dev);return ERR_PTR (rc); }
@@ -1586,6 +1580,18 @@ static int switchtec_init_pci(struct switchtec_dev *stdev,return 0 ; } +static void switchtec_exit_pci (struct switchtec_dev *stdev) +{ +if (stdev->dma_mrpc) { +iowrite32 (0 , &stdev->mmio_mrpc->dma_en); +flush_wc_buf (stdev); +writeq (0 , &stdev->mmio_mrpc->dma_addr); +dma_free_coherent (&stdev->pdev->dev,sizeof (*stdev->dma_mrpc), + stdev->dma_mrpc, stdev->dma_mrpc_dma_addr); + stdev->dma_mrpc =NULL ; + } +} +static int switchtec_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id) {
@@ -1645,6 +1651,9 @@ static void switchtec_pci_remove(struct pci_dev *pdev)ida_simple_remove (&switchtec_minor_ida,MINOR (stdev->dev.devt));dev_info (&stdev->dev,"unregistered.\n" );stdev_kill (stdev); +switchtec_exit_pci (stdev); +pci_dev_put (stdev->pdev); + stdev->pdev =NULL ;put_device (&stdev->dev); }
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 3/19 perf cs-etm: Bump minimum OpenCSD version to ensure a bugfix is present
In reply to Sasha LevinFrom: James Clark <[email protected]>
[ Upstream commit 2dbba30fd69b604802a9535b74bddb5bcca23793 ]
Since commit d927ef5004ef ("perf cs-etm: Add exception level consistency check"), the exception that was added to Perf will be triggered unless the following bugfix from OpenCSD is present:
- _Version 1.2.1_:
- __Bugfix__:
ETM4x / ETE - output of context elements to client can in some circumstances be delayed until after subsequent atoms have been processed leading to incorrect memory decode access via the client callbacks. Fixed to flush context elements immediately they are committed.
Rather than remove the assert and silently fail, just increase the minimum version requirement to avoid hard to debug issues and regressions.
--- tools/build/feature/test-libopencsd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/build/feature/test-libopencsd.c +2 -2
@@ -4,9 +4,9 @@/* * Check OpenCSD library version is sufficient to provide required features */ -#define OCSD_MIN_VER ((1 << 16) | (1 << 8) | (1)) +#define OCSD_MIN_VER ((1 << 16) | (2 << 8) | (1))#if !defined(OCSD_VER_NUM ) || (OCSD_VER_NUM <OCSD_MIN_VER ) -#error "OpenCSD >= 1.1.1 is required" +#error "OpenCSD >= 1.2.1 is required"#endif int main (void )
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 4/19 xhci: fix possible null pointer deref during xhci urb enqueue
In reply to Sasha LevinFrom: Mathias Nyman <[email protected]>
[ Upstream commit e2e2aacf042f52854c92775b7800ba668e0bdfe4 ]
There is a short gap between urb being submitted and actually added to the endpoint queue (linked). If the device is disconnected during this time then usb core is not yet aware of the pending urb, and device may be freed just before xhci_urq_enqueue() continues, dereferencing the freed device.
Freeing the device is protected by the xhci spinlock, so make sure we take and keep the lock while checking that device exists, dereference it, and add the urb to the queue.
Remove the unnecessary URB check, usb core checks it before calling xhci_urb_enqueue()
--- drivers/usb/host/xhci.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-)
drivers/usb/host/xhci.c +23 -17
@@ -1644,24 +1644,7 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flagstruct urb_priv *urb_priv;int num_tds; -if (!urb) -return -EINVAL ; - ret =xhci_check_args (hcd, urb->dev, urb->ep, - true, true, __func__); -if (ret <=0 ) -return ret ? ret : -EINVAL ; - - slot_id = urb->dev->slot_id; ep_index =xhci_get_endpoint_index (&urb->ep->desc); - ep_state = &xhci->devs[slot_id]->eps[ep_index].ep_state; - -if (!HCD_HW_ACCESSIBLE (hcd)) -return -ESHUTDOWN ; - -if (xhci->devs[slot_id]->flags &VDEV_PORT_ERROR ) { -xhci_dbg (xhci,"Can't queue urb, port error, link inactive\n" ); -return -ENODEV ; - }if (usb_endpoint_xfer_isoc (&urb->ep->desc)) num_tds = urb->number_of_packets;
@@ -1700,12 +1683,35 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flagspin_lock_irqsave (&xhci->lock, flags); + ret =xhci_check_args (hcd, urb->dev, urb->ep, + true, true, __func__); +if (ret <=0 ) { + ret = ret ? ret : -EINVAL ; + goto free_priv; + } + + slot_id = urb->dev->slot_id; + +if (!HCD_HW_ACCESSIBLE (hcd)) { + ret = -ESHUTDOWN ; + goto free_priv; + } + +if (xhci->devs[slot_id]->flags &VDEV_PORT_ERROR ) { +xhci_dbg (xhci,"Can't queue urb, port error, link inactive\n" ); + ret = -ENODEV ; + goto free_priv; + } +if (xhci->xhc_state &XHCI_STATE_DYING ) {xhci_dbg (xhci,"Ep 0x%x: URB %p submitted for non-responsive xHCI host.\n" , urb->ep->desc.bEndpointAddress, urb); ret = -ESHUTDOWN ; goto free_priv; } + + ep_state = &xhci->devs[slot_id]->eps[ep_index].ep_state; +if (*ep_state & (EP_GETTING_STREAMS |EP_GETTING_NO_STREAMS )) {xhci_warn (xhci,"WARN: Can't enqueue URB, ep in streams transition state %x\n" , *ep_state);
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 5/19 usb: hub: Replace hardcoded quirk value with BIT() macro
In reply to Sasha LevinFrom: Hardik Gajjar <[email protected]>
[ Upstream commit 6666ea93d2c422ebeb8039d11e642552da682070 ]
This patch replaces the hardcoded quirk value in the macro with BIT().
--- drivers/usb/core/hub.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/core/hub.c +2 -2
@@ -46,8 +46,8 @@#define USB_VENDOR_TEXAS_INSTRUMENTS 0x0451#define USB_PRODUCT_TUSB8041_USB3 0x8140#define USB_PRODUCT_TUSB8041_USB2 0x8142 -#define HUB_QUIRK_CHECK_PORT_AUTOSUSPEND 0x01 -#define HUB_QUIRK_DISABLE_AUTOSUSPEND 0x02 +#define HUB_QUIRK_CHECK_PORT_AUTOSUSPEND BIT(0) +#define HUB_QUIRK_DISABLE_AUTOSUSPEND BIT(1)#define USB_TP_TRANSMISSION_DELAY 40/* ns */ #define USB_TP_TRANSMISSION_DELAY_MAX 65535/* ns */
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 6/19 selftests/sgx: Fix linker script asserts
In reply to Sasha LevinFrom: Jo Van Bulck <[email protected]>
[ Upstream commit 9fd552ee32c6c1e27c125016b87d295bea6faea7 ]
DEFINED only considers symbols, not section names. Hence, replace the check for .got.plt with the _GLOBAL_OFFSET_TABLE_ symbol and remove other (non-essential) asserts.
--- tools/testing/selftests/sgx/test_encl.lds | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
tools/testing/selftests/sgx/test_encl.lds +1 -5
@@ -34,8 +34,4 @@ SECTIONS } } -ASSERT(!DEFINED(.altinstructions), "ALTERNATIVES are not supported in enclaves") -ASSERT(!DEFINED(.altinstr_replacement), "ALTERNATIVES are not supported in enclaves") -ASSERT(!DEFINED(.discard.retpoline_safe), "RETPOLINE ALTERNATIVES are not supported in enclaves") -ASSERT(!DEFINED(.discard.nospec), "RETPOLINE ALTERNATIVES are not supported in enclaves") -ASSERT(!DEFINED(.got.plt), "Libcalls are not supported in enclaves") +ASSERT(!DEFINED(_GLOBAL_OFFSET_TABLE_), "Libcalls through GOT are not supported in enclaves")
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 7/19 tty: allow TIOCSLCKTRMIOS with CAP_CHECKPOINT_RESTORE
In reply to Sasha LevinFrom: Adrian Reber <[email protected]>
[ Upstream commit e0f25b8992345aa5f113da2815f5add98738c611 ]
The capability CAP_CHECKPOINT_RESTORE was introduced to allow non-root users to checkpoint and restore processes as non-root with CRIU.
This change extends CAP_CHECKPOINT_RESTORE to enable the CRIU option '--shell-job' as non-root. CRIU's man-page describes the '--shell-job' option like this:
Allow one to dump shell jobs. This implies the restored task will inherit session and process group ID from the criu itself. This option also allows to migrate a single external tty connection, to migrate applications like top.
TIOCSLCKTRMIOS can only be done if the process has CAP_SYS_ADMIN and this change extends it to CAP_SYS_ADMIN or CAP_CHECKPOINT_RESTORE.
With this change it is possible to checkpoint and restore processes which have a tty connection as non-root if CAP_CHECKPOINT_RESTORE is set.
--- drivers/tty/tty_ioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/tty_ioctl.c +2 -2
@@ -786,7 +786,7 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file, ret = -EFAULT ;return ret;case TIOCSLCKTRMIOS : -if (!capable (CAP_SYS_ADMIN )) +if (!checkpoint_restore_ns_capable (&init_user_ns))return -EPERM ;copy_termios_locked (real_tty, &kterm); if (user_termios_to_kernel_termios(&kterm,
@@ -803,7 +803,7 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file, ret = -EFAULT ;return ret;case TIOCSLCKTRMIOS : -if (!capable (CAP_SYS_ADMIN )) +if (!checkpoint_restore_ns_capable (&init_user_ns))return -EPERM ;copy_termios_locked (real_tty, &kterm); if (user_termios_to_kernel_termios_1(&kterm,
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 8/19 fs/kernfs/dir: obey S_ISGID
In reply to Sasha LevinFrom: Max Kellermann <[email protected]>
[ Upstream commit 5133bee62f0ea5d4c316d503cc0040cac5637601 ]
Handling of S_ISGID is usually done by inode_init_owner() in all other filesystems, but kernfs doesn't use that function. In kernfs, struct kernfs_node is the primary data structure, and struct inode is only created from it on demand. Therefore, inode_init_owner() can't be used and we need to imitate its behavior.
S_ISGID support is useful for the cgroup filesystem; it allows subtrees managed by an unprivileged process to retain a certain owner gid, which then enables sharing access to the subtree with another unprivileged process.
--
v1 -> v2: minor coding style fix (comment)
--- fs/kernfs/dir.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
fs/kernfs/dir.c +12 -0
@@ -654,6 +654,18 @@ struct kernfs_node *kernfs_new_node(struct kernfs_node *parent, {struct kernfs_node *kn; +if (parent->mode &S_ISGID ) { +/* this code block imitates inode_init_owner() for +* kernfs +*/ + +if (parent->iattr) + gid = parent->iattr->ia_gid; + +if (flags &KERNFS_DIR ) + mode |=S_ISGID ; + } + kn =__kernfs_new_node (kernfs_root (parent), parent, name, mode, uid, gid, flags);if (kn) {
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 9/19 PCI: Fix 64GT/s effective data rate calculation
In reply to Sasha LevinFrom: Ilpo Järvinen <[email protected]>
[ Upstream commit ac4f1897fa5433a1b07a625503a91b6aa9d7e643 ]
Unlike the lower rates, the PCIe 64GT/s Data Rate uses 1b/1b encoding, not 128b/130b (PCIe r6.1 sec 1.2, Table 1-1). Correct the PCIE_SPEED2MBS_ENC() calculation to reflect that.
--- drivers/pci/pci.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pci.h +1 -1
@@ -312,7 +312,7 @@ void pci_bus_put(struct pci_bus *bus);/* PCIe speed to Mb/s reduced by encoding overhead */ #define PCIE_SPEED2MBS_ENC (speed) \ - ((speed) == PCIE_SPEED_64_0GT ? 64000*128/130 : \ + ((speed) == PCIE_SPEED_64_0GT ? 64000*1/1 : \ (speed) == PCIE_SPEED_32_0GT ? 32000*128/130 : \ (speed) == PCIE_SPEED_16_0GT ? 16000*128/130 : \ (speed) == PCIE_SPEED_8_0GT ? 8000*128/130 : \
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 10/19 PCI/AER: Decode Requester ID when no error info found
In reply to Sasha LevinFrom: Bjorn Helgaas <[email protected]>
[ Upstream commit 1291b716bbf969e101d517bfb8ba18d958f758b8 ]
When a device with AER detects an error, it logs error information in its own AER Error Status registers. It may send an Error Message to the Root Port (RCEC in the case of an RCiEP), which logs the fact that an Error Message was received (Root Error Status) and the Requester ID of the message source (Error Source Identification).
aer_print_port_info() prints the Requester ID from the Root Port Error Source in the usual Linux "bb:dd.f" format, but when find_source_device() finds no error details in the hierarchy below the Root Port, it printed the raw Requester ID without decoding it.
Decode the Requester ID in the usual Linux format so it matches other messages.
Sample message changes:
- pcieport 0000:00:1c.5: AER: Correctable error received: 0000:00:1c.5
- pcieport 0000:00:1c.5: AER: can't find device of ID00e5
+ pcieport 0000:00:1c.5: AER: Correctable error message received from 0000:00:1c.5
+ pcieport 0000:00:1c.5: AER: found no error details for 0000:00:1c.5
--- drivers/pci/pcie/aer.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/pci/pcie/aer.c +7 -2
@@ -743,7 +743,7 @@ static void aer_print_port_info(struct pci_dev *dev, struct aer_err_info *info)u8 bus = info->id >>8 ;u8 devfn = info->id &0xff ; - pci_info(dev, "%s%s error received: %04x:%02x:%02x.%d\n", + pci_info(dev, "%s%s error message received from %04x:%02x:%02x.%d\n", info->multi_error_valid ? "Multiple " : "", aer_error_severity_string[info->severity], pci_domain_nr(dev->bus), bus, PCI_SLOT(devfn),
@@ -931,7 +931,12 @@ static bool find_source_device(struct pci_dev *parent,pci_walk_bus (parent->subordinate, find_device_iter, e_info);if (!e_info->error_dev_num) { -pci_info (parent,"can't find device of ID%04x\n" , e_info->id); +u8 bus = e_info->id >>8 ; +u8 devfn = e_info->id &0xff ; + +pci_info (parent,"found no error details for %04x:%02x:%02x.%d\n" , +pci_domain_nr (parent->bus), bus,PCI_SLOT (devfn), +PCI_FUNC (devfn));return false; }return true;
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 11/19 misc: lis3lv02d_i2c: Add missing setting of the reg_ctrl callback
In reply to Sasha LevinFrom: Hans de Goede <[email protected]>
[ Upstream commit b1b9f7a494400c0c39f8cd83de3aaa6111c55087 ]
The lis3lv02d_i2c driver was missing a line to set the lis3_dev's reg_ctrl callback.
lis3_reg_ctrl(on) is called from the init callback, but due to the missing reg_ctrl callback the regulators where never turned off again leading to the following oops/backtrace when detaching the driver:
[ 82.313527] ------------[ cut here ]------------ [ 82.313546] WARNING: CPU: 1 PID: 1724 at drivers/regulator/core.c:2396 _regulator_put+0x219/0x230 ... [ 82.313695] RIP: 0010:_regulator_put+0x219/0x230 ... [ 82.314767] Call Trace: [ 82.314770] <TASK> [ 82.314772] ? _regulator_put+0x219/0x230 [ 82.314777] ? __warn+0x81/0x170 [ 82.314784] ? _regulator_put+0x219/0x230 [ 82.314791] ? report_bug+0x18d/0x1c0 [ 82.314801] ? handle_bug+0x3c/0x80 [ 82.314806] ? exc_invalid_op+0x13/0x60 [ 82.314812] ? asm_exc_invalid_op+0x16/0x20 [ 82.314845] ? _regulator_put+0x219/0x230 [ 82.314857] regulator_bulk_free+0x39/0x60 [ 82.314865] i2c_device_remove+0x22/0xb0
Add the missing setting of the callback so that the regulators properly get turned off again when not used.
--- drivers/misc/lis3lv02d/lis3lv02d_i2c.c | 1 + 1 file changed, 1 insertion(+)
drivers/misc/lis3lv02d/lis3lv02d_i2c.c +1 -0
@@ -151,6 +151,7 @@ static int lis3lv02d_i2c_probe(struct i2c_client *client, lis3_dev.init = lis3_i2c_init; lis3_dev.read = lis3_i2c_read; lis3_dev.write = lis3_i2c_write; + lis3_dev.reg_ctrl = lis3_reg_ctrl; lis3_dev.irq = client->irq; lis3_dev.ac = lis3lv02d_axis_map; lis3_dev.pm_dev = &client->dev;
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 12/19 libsubcmd: Fix memory leak in uniq()
In reply to Sasha LevinFrom: Ian Rogers <[email protected]>
[ Upstream commit ad30469a841b50dbb541df4d6971d891f703c297 ]
uniq() will write one command name over another causing the overwritten string to be leaked. Fix by doing a pass that removes duplicates and a second that removes the holes.
--- tools/lib/subcmd/help.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
tools/lib/subcmd/help.c +14 -4
@@ -50,11 +50,21 @@ void uniq(struct cmdnames *cmds)if (!cmds->cnt)return ; -for (i = j =1 ; i < cmds->cnt; i++) -if (strcmp (cmds->names[i]->name, cmds->names[i-1 ]->name)) - cmds->names[j++] = cmds->names[i]; - +for (i =1 ; i < cmds->cnt; i++) { +if (!strcmp (cmds->names[i]->name, cmds->names[i-1 ]->name)) +zfree (&cmds->names[i -1 ]); + } +for (i =0 , j =0 ; i < cmds->cnt; i++) { +if (cmds->names[i]) { +if (i == j) + j++; +else + cmds->names[j++] = cmds->names[i]; + } + } cmds->cnt = j; +while (j < i) + cmds->names[j++] =NULL ; }void exclude_cmds (struct cmdnames *cmds,struct cmdnames *excludes)
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 13/19 drm/amdkfd: Fix lock dependency warning
In reply to Sasha LevinFrom: Felix Kuehling <[email protected]>
[ Upstream commit 47bf0f83fc86df1bf42b385a91aadb910137c5c9 ]
======================================================
WARNING: possible circular locking dependency detected
6.5.0-kfd-fkuehlin #276 Not tainted
------------------------------------------------------
kworker/8:2/2676 is trying to acquire lock:ffff9435aae95c88 ((work_completion)(&svm_bo->eviction_work)){+.+.}-{0:0}, at: __flush_work+0x52/0x550
but task is already holding lock:ffff9435cd8e1720 (&svms->lock){+.+.}-{3:3}, at: svm_range_deferred_list_work+0xe8/0x340 [amdgpu]
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #2 (&svms->lock){+.+.}-{3:3}:
__mutex_lock+0x97/0xd30
kfd_ioctl_alloc_memory_of_gpu+0x6d/0x3c0 [amdgpu]
kfd_ioctl+0x1b2/0x5d0 [amdgpu]
__x64_sys_ioctl+0x86/0xc0
do_syscall_64+0x39/0x80
entry_SYSCALL_64_after_hwframe+0x63/0xcd-> #1 (&mm->mmap_lock){++++}-{3:3}:
down_read+0x42/0x160
svm_range_evict_svm_bo_worker+0x8b/0x340 [amdgpu]
process_one_work+0x27a/0x540
worker_thread+0x53/0x3e0
kthread+0xeb/0x120
ret_from_fork+0x31/0x50
ret_from_fork_asm+0x11/0x20-> #0 ((work_completion)(&svm_bo->eviction_work)){+.+.}-{0:0}:
__lock_acquire+0x1426/0x2200
lock_acquire+0xc1/0x2b0
__flush_work+0x80/0x550
__cancel_work_timer+0x109/0x190
svm_range_bo_release+0xdc/0x1c0 [amdgpu]
svm_range_free+0x175/0x180 [amdgpu]
svm_range_deferred_list_work+0x15d/0x340 [amdgpu]
process_one_work+0x27a/0x540
worker_thread+0x53/0x3e0
kthread+0xeb/0x120
ret_from_fork+0x31/0x50
ret_from_fork_asm+0x11/0x20other info that might help us debug this:
Chain exists of: (work_completion)(&svm_bo->eviction_work) --> &mm->mmap_lock --> &svms->lock Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(&svms->lock);
lock(&mm->mmap_lock);
lock(&svms->lock);lock((work_completion)(&svm_bo->eviction_work));
I believe this cannot really lead to a deadlock in practice, because svm_range_evict_svm_bo_worker only takes the mmap_read_lock if the BO refcount is non-0. That means it's impossible that svm_range_bo_release is running concurrently. However, there is no good way to annotate this.
To avoid the problem, take a BO reference in svm_range_schedule_evict_svm_bo instead of in the worker. That way it's impossible for a BO to get freed while eviction work is pending and the cancel_work_sync call in svm_range_bo_release can be eliminated.
v2: Use svm_bo_ref_unless_zero and explained why that's safe. Also removed redundant checks that are already done in amdkfd_fence_enable_signaling.
--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +10 -16
@@ -347,14 +347,9 @@ static void svm_range_bo_release(struct kref *kref)spin_lock (&svm_bo->list_lock); }spin_unlock (&svm_bo->list_lock); -if (!dma_fence_is_signaled (&svm_bo->eviction_fence->base)) { -/* We're not in the eviction worker. -* Signal the fence and synchronize with any -* pending eviction work. -*/ +if (!dma_fence_is_signaled (&svm_bo->eviction_fence->base)) +/* We're not in the eviction worker. Signal the fence. */ dma_fence_signal (&svm_bo->eviction_fence->base); -cancel_work_sync (&svm_bo->eviction_work); - }dma_fence_put (&svm_bo->eviction_fence->base);amdgpu_bo_unref (&svm_bo->bo);kfree (svm_bo);
@@ -2872,13 +2867,14 @@ svm_range_trigger_migration(struct mm_struct *mm, struct svm_range *prange,int svm_range_schedule_evict_svm_bo (struct amdgpu_amdkfd_fence *fence) { -if (!fence) -return -EINVAL ; - -if (dma_fence_is_signaled (&fence->base)) -return 0 ; - -if (fence->svm_bo) { +/* Dereferencing fence->svm_bo is safe here because the fence hasn't +* signaled yet and we're under the protection of the fence->lock. +* After the fence is signaled in svm_range_bo_release, we cannot get +* here any more. +* +* Reference is dropped in svm_range_evict_svm_bo_worker. +*/ +if (svm_bo_ref_unless_zero (fence->svm_bo)) {WRITE_ONCE (fence->svm_bo->evicting,1 );schedule_work (&fence->svm_bo->eviction_work); }
@@ -2893,8 +2889,6 @@ static void svm_range_evict_svm_bo_worker(struct work_struct *work)struct mm_struct *mm; svm_bo = container_of(work, struct svm_range_bo, eviction_work); -if (!svm_bo_ref_unless_zero (svm_bo)) -return ;/* svm_bo was freed while eviction was pending */ /* svm_range_bo_release destroys this worker thread. So during * the lifetime of this thread, kfd_process and mm will be valid.
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 14/19 virtio_net: Fix "‘%d’ directive writing between 1 and 11 bytes into a region of size 10" warnings
In reply to Sasha LevinFrom: Zhu Yanjun <[email protected]>
[ Upstream commit e3fe8d28c67bf6c291e920c6d04fa22afa14e6e4 ]
Fix the warnings when building virtio_net driver.
"drivers/net/virtio_net.c: In function ‘init_vqs’:drivers/net/virtio_net.c:4551:48: warning: ‘%d’ directive writing between 1 and 11 bytes into a region of size 10 [-Wformat-overflow=]
4551 | sprintf(vi->rq[i].name, "input.%d", i);
| ^~
In function ‘virtnet_find_vqs’,
inlined from ‘init_vqs’ at drivers/net/virtio_net.c:4645:8:drivers/net/virtio_net.c:4551:41: note: directive argument in the range [-2147483643, 65534]
4551 | sprintf(vi->rq[i].name, "input.%d", i);
| ^~~~~~~~~~drivers/net/virtio_net.c:4551:17: note: ‘sprintf’ output between 8 and 18 bytes into a destination of size 16
4551 | sprintf(vi->rq[i].name, "input.%d", i);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~drivers/net/virtio_net.c: In function ‘init_vqs’:drivers/net/virtio_net.c:4552:49: warning: ‘%d’ directive writing between 1 and 11 bytes into a region of size 9 [-Wformat-overflow=]
4552 | sprintf(vi->sq[i].name, "output.%d", i);
| ^~
In function ‘virtnet_find_vqs’,
inlined from ‘init_vqs’ at drivers/net/virtio_net.c:4645:8:drivers/net/virtio_net.c:4552:41: note: directive argument in the range [-2147483643, 65534]
4552 | sprintf(vi->sq[i].name, "output.%d", i);
| ^~~~~~~~~~~drivers/net/virtio_net.c:4552:17: note: ‘sprintf’ output between 9 and 19 bytes into a destination of size 16
4552 | sprintf(vi->sq[i].name, "output.%d", i);
"
--- drivers/net/virtio_net.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/net/virtio_net.c +5 -4
@@ -2913,10 +2913,11 @@ static int virtnet_find_vqs(struct virtnet_info *vi) {vq_callback_t **callbacks;struct virtqueue **vqs; -int ret = -ENOMEM ; -int i, total_vqs;const char **names; +int ret = -ENOMEM ; +int total_vqs;bool *ctx; +u16 i;/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by * possible N-1 RX/TX queue pairs used in multiqueue mode, followed by
@@ -2953,8 +2954,8 @@ static int virtnet_find_vqs(struct virtnet_info *vi)for (i =0 ; i < vi->max_queue_pairs; i++) { callbacks[rxq2vq (i)] = skb_recv_done; callbacks[txq2vq (i)] = skb_xmit_done; -sprintf (vi->rq[i].name,"input.%d" , i); -sprintf (vi->sq[i].name,"output.%d" , i); +sprintf (vi->rq[i].name,"input.%u" , i); +sprintf (vi->sq[i].name,"output.%u" , i); names[rxq2vq (i)] = vi->rq[i].name; names[txq2vq (i)] = vi->sq[i].name;if (ctx)
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 15/19 blk-mq: fix IO hang from sbitmap wakeup race
In reply to Sasha LevinFrom: Ming Lei <[email protected]>
[ Upstream commit 5266caaf5660529e3da53004b8b7174cab6374ed ]
In blk_mq_mark_tag_wait(), __add_wait_queue() may be re-ordered with the following blk_mq_get_driver_tag() in case of getting driver tag failure.
Then in __sbitmap_queue_wake_up(), waitqueue_active() may not observe the added waiter in blk_mq_mark_tag_wait() and wake up nothing, meantime blk_mq_mark_tag_wait() can't get driver tag successfully.
This issue can be reproduced by running the following test in loop, and fio hang can be observed in < 30min when running it on my test VM in laptop.
modprobe -r scsi_debug
modprobe scsi_debug delay=0 dev_size_mb=4096 max_queue=1 host_max_queue=1 submit_queues=4 dev=ls -d /sys/bus/pseudo/drivers/scsi_debug/adapter*/host*/target*/*/block/* | head -1 | xargs basename fio --filename=/dev/"$dev" --direct=1 --rw=randrw --bs=4k --iodepth=1 \
--runtime=100 --numjobs=40 --time_based --name=test \
--ioengine=libaio
Fix the issue by adding one explicit barrier in blk_mq_mark_tag_wait(), which is just fine in case of running out of tag.
--- block/blk-mq.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
block/blk-mq.c +16 -0
@@ -1176,6 +1176,22 @@ static bool blk_mq_mark_tag_wait(struct blk_mq_hw_ctx *hctx, wait->flags &= ~WQ_FLAG_EXCLUSIVE ;__add_wait_queue (wq, wait); +/* +* Add one explicit barrier since blk_mq_get_driver_tag() may +* not imply barrier in case of failure. +* +* Order adding us to wait queue and allocating driver tag. +* +* The pair is the one implied in sbitmap_queue_wake_up() which +* orders clearing sbitmap tag bits and waitqueue_active() in +* __sbitmap_queue_wake_up(), since waitqueue_active() is lockless +* +* Otherwise, re-order of adding wait queue and getting driver tag +* may cause __sbitmap_queue_wake_up() to wake up nothing because +* the waitqueue_active() may not observe us in wait queue. +*/ +smp_mb (); +/* * It's possible that a tag was freed in the window between the * allocation failure and adding the hardware queue to the wait
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 16/19 ceph: fix deadlock or deadcode of misusing dget()
In reply to Sasha LevinFrom: Xiubo Li <[email protected]>
[ Upstream commit b493ad718b1f0357394d2cdecbf00a44a36fa085 ]
The lock order is incorrect between denty and its parent, we should always make sure that the parent get the lock first.
But since this deadcode is never used and the parent dir will always be set from the callers, let's just remove it.
--- fs/ceph/caps.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
fs/ceph/caps.c +3 -6
@@ -4536,12 +4536,14 @@ int ceph_encode_dentry_release(void **p, struct dentry *dentry,struct inode *dir, int mds, int drop, int unless) { - struct dentry *parent = NULL; struct ceph_mds_request_release *rel = *p;struct ceph_dentry_info *di =ceph_dentry (dentry);int force =0 ;int ret; +/* This shouldn't happen */ +BUG_ON (!dir); +/* * force an record for the directory caps if we have a dentry lease. * this is racy (can't take i_ceph_lock and d_lock together), but it
@@ -4551,14 +4553,9 @@ int ceph_encode_dentry_release(void **p, struct dentry *dentry,spin_lock (&dentry->d_lock);if (di->lease_session && di->lease_session->s_mds == mds) force =1 ; -if (!dir) { - parent =dget (dentry->d_parent); - dir =d_inode (parent); - }spin_unlock (&dentry->d_lock); ret =ceph_encode_inode_release (p, dir, mds, drop, unless, force); -dput (parent);spin_lock (&dentry->d_lock);if (ret && di->lease_session && di->lease_session->s_mds == mds) {
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 17/19 drm/amd/powerplay: Fix kzalloc parameter 'ATOM_Tonga_PPM_Table' in 'get_platform_power_management_table()'
In reply to Sasha LevinFrom: Srinivasan Shanmugam <[email protected]>
[ Upstream commit 6616b5e1999146b1304abe78232af810080c67e3 ]
In 'struct phm_ppm_table *ptr' allocation using kzalloc, an incorrect structure type is passed to sizeof() in kzalloc, larger structure types were used, thus using correct type 'struct phm_ppm_table' fixes the below:
drivers/gpu/drm/amd/amdgpu/../pm/powerplay/hwmgr/process_pptables_v1_0.c:203 get_platform_power_management_table() warn: struct type mismatch 'phm_ppm_table vs _ATOM_Tonga_PPM_Table'
--- drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/powerplay/hwmgr/process_pptables_v1_0.c +1 -1
@@ -200,7 +200,7 @@ static int get_platform_power_management_table(struct pp_hwmgr *hwmgr, ATOM_Tonga_PPM_Table *atom_ppm_table) { - struct phm_ppm_table *ptr = kzalloc(sizeof(ATOM_Tonga_PPM_Table), GFP_KERNEL); + struct phm_ppm_table *ptr = kzalloc(sizeof(*ptr), GFP_KERNEL);struct phm_ppt_v1_information *pp_table_information = (struct phm_ppt_v1_information *)(hwmgr->pptable);
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 18/19 drm/amdgpu: Release 'adev->pm.fw' before return in 'amdgpu_device_need_post()'
In reply to Sasha LevinFrom: Srinivasan Shanmugam <[email protected]>
[ Upstream commit 8a44fdd3cf91debbd09b43bd2519ad2b2486ccf4 ]
In function 'amdgpu_device_need_post(struct amdgpu_device *adev)' - 'adev->pm.fw' may not be released before return.
Using the function release_firmware() to release adev->pm.fw.
Thus fixing the below:drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:1571 amdgpu_device_need_post() warn: 'adev->pm.fw' from request_firmware() not released on lines: 1554.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
@@ -1292,6 +1292,7 @@ bool amdgpu_device_need_post(struct amdgpu_device *adev)return true; fw_ver = *((uint32_t *)adev->pm.fw->data +69 ); +release_firmware (adev->pm.fw);if (fw_ver <0x00160e00 )return true; }
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 19/19 drm/amdkfd: Fix 'node' NULL check in 'svm_range_get_range_boundaries()'
In reply to Sasha LevinFrom: Srinivasan Shanmugam <[email protected]>
[ Upstream commit d7a254fad873775ce6c32b77796c81e81e6b7f2e ]
Range interval [start, last] is ordered by rb_tree, rb_prev, rb_next return value still needs NULL check, thus modified from "node" to "rb_node".
Fixes the below:drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_svm.c:2691 svm_range_get_range_boundaries() warn: can 'node' even be NULL?
--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +5 -5
@@ -2325,6 +2325,7 @@ svm_range_get_range_boundaries(struct kfd_process *p, int64_t addr, {struct vm_area_struct *vma;struct interval_tree_node *node; +struct rb_node *rb_node;unsigned long start_limit, end_limit; vma =find_vma (p->mm, addr <<PAGE_SHIFT );
@@ -2341,16 +2342,15 @@ svm_range_get_range_boundaries(struct kfd_process *p, int64_t addr,if (node) { end_limit =min (end_limit, node->start);/* Last range that ends before the fault address */ - node =container_of (rb_prev (&node->rb), - struct interval_tree_node, rb); + rb_node =rb_prev (&node->rb); }else {/* Last range must end before addr because * there was no range after addr */ - node =container_of (rb_last (&p->svms.objects.rb_root), - struct interval_tree_node, rb); + rb_node =rb_last (&p->svms.objects.rb_root); } -if (node) { +if (rb_node) { + node = container_of(rb_node, struct interval_tree_node, rb);if (node->last >= addr) {WARN (1 ,"Overlap with prev node and page fault addr\n" );return -EFAULT ;
Signature · 1 line
2.43.0