All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	patches@lists.linux.dev, Lu Baolu <baolu.lu@linux.intel.com>,
	Joerg Roedel <jroedel@suse.de>, Sasha Levin <sashal@kernel.org>,
	Dave Jiang <dave.jiang@intel.com>
Subject: [PATCH 5.10 020/104] iommu/vt-d: Fix lockdep splat in intel_pasid_get_entry()
Date: Wed, 15 Mar 2023 13:11:51 +0100	[thread overview]
Message-ID: <20230315115732.924259380@linuxfoundation.org> (raw)
In-Reply-To: <20230315115731.942692602@linuxfoundation.org>

From: Lu Baolu <baolu.lu@linux.intel.com>

[ Upstream commit 803766cbf85fb8edbf896729bbefc2d38dcf1e0a ]

The pasid_lock is used to synchronize different threads from modifying a
same pasid directory entry at the same time. It causes below lockdep splat.

[   83.296538] ========================================================
[   83.296538] WARNING: possible irq lock inversion dependency detected
[   83.296539] 5.12.0-rc3+ #25 Tainted: G        W
[   83.296539] --------------------------------------------------------
[   83.296540] bash/780 just changed the state of lock:
[   83.296540] ffffffff82b29c98 (device_domain_lock){..-.}-{2:2}, at:
           iommu_flush_dev_iotlb.part.0+0x32/0x110
[   83.296547] but this lock took another, SOFTIRQ-unsafe lock in the past:
[   83.296547]  (pasid_lock){+.+.}-{2:2}
[   83.296548]

           and interrupts could create inverse lock ordering between them.

[   83.296549] other info that might help us debug this:
[   83.296549] Chain exists of:
                 device_domain_lock --> &iommu->lock --> pasid_lock
[   83.296551]  Possible interrupt unsafe locking scenario:

[   83.296551]        CPU0                    CPU1
[   83.296552]        ----                    ----
[   83.296552]   lock(pasid_lock);
[   83.296553]                                local_irq_disable();
[   83.296553]                                lock(device_domain_lock);
[   83.296554]                                lock(&iommu->lock);
[   83.296554]   <Interrupt>
[   83.296554]     lock(device_domain_lock);
[   83.296555]
                *** DEADLOCK ***

Fix it by replacing the pasid_lock with an atomic exchange operation.

Reported-and-tested-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Link: https://lore.kernel.org/r/20210320020916.640115-1-baolu.lu@linux.intel.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Stable-dep-of: 194b3348bdbb ("iommu/vt-d: Fix PASID directory pointer coherency")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/iommu/intel/pasid.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c
index 86fd49ae7f612..f821153390e53 100644
--- a/drivers/iommu/intel/pasid.c
+++ b/drivers/iommu/intel/pasid.c
@@ -24,7 +24,6 @@
 /*
  * Intel IOMMU system wide PASID name space:
  */
-static DEFINE_SPINLOCK(pasid_lock);
 u32 intel_pasid_max_id = PASID_MAX;
 
 int vcmd_alloc_pasid(struct intel_iommu *iommu, u32 *pasid)
@@ -259,19 +258,25 @@ struct pasid_entry *intel_pasid_get_entry(struct device *dev, u32 pasid)
 	dir_index = pasid >> PASID_PDE_SHIFT;
 	index = pasid & PASID_PTE_MASK;
 
-	spin_lock(&pasid_lock);
+retry:
 	entries = get_pasid_table_from_pde(&dir[dir_index]);
 	if (!entries) {
 		entries = alloc_pgtable_page(info->iommu->node);
-		if (!entries) {
-			spin_unlock(&pasid_lock);
+		if (!entries)
 			return NULL;
-		}
 
-		WRITE_ONCE(dir[dir_index].val,
-			   (u64)virt_to_phys(entries) | PASID_PTE_PRESENT);
+		/*
+		 * The pasid directory table entry won't be freed after
+		 * allocation. No worry about the race with free and
+		 * clear. However, this entry might be populated by others
+		 * while we are preparing it. Use theirs with a retry.
+		 */
+		if (cmpxchg64(&dir[dir_index].val, 0ULL,
+			      (u64)virt_to_phys(entries) | PASID_PTE_PRESENT)) {
+			free_pgtable_page(entries);
+			goto retry;
+		}
 	}
-	spin_unlock(&pasid_lock);
 
 	return &entries[index];
 }
-- 
2.39.2




  parent reply	other threads:[~2023-03-15 12:20 UTC|newest]

Thread overview: 119+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-15 12:11 [PATCH 5.10 000/104] 5.10.175-rc1 review Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 001/104] fs: prevent out-of-bounds array speculation when closing a file descriptor Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 002/104] fork: allow CLONE_NEWTIME in clone3 flags Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 003/104] x86/CPU/AMD: Disable XSAVES on AMD family 0x17 Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 004/104] drm/amdgpu: fix error checking in amdgpu_read_mm_registers for soc15 Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 005/104] drm/connector: print max_requested_bpc in state debugfs Greg Kroah-Hartman
2023-03-15 12:11   ` Greg Kroah-Hartman
2023-03-15 12:11   ` Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 006/104] ext4: fix cgroup writeback accounting with fs-layer encryption Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 007/104] ext4: fix RENAME_WHITEOUT handling for inline directories Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 008/104] ext4: fix another off-by-one fsmap error on 1k block filesystems Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 009/104] ext4: move where set the MAY_INLINE_DATA flag is set Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 010/104] ext4: fix WARNING in ext4_update_inline_data Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 011/104] ext4: zero i_disksize when initializing the bootloader inode Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 012/104] nfc: change order inside nfc_se_io error path Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 013/104] udf: Fix off-by-one error when discarding preallocation Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 014/104] irq: Fix typos in comments Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 015/104] irqdomain: Look for existing mapping only once Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 016/104] irqdomain: Refactor __irq_domain_alloc_irqs() Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 017/104] irqdomain: Fix mapping-creation race Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 018/104] irqdomain: Change the type of size in __irq_domain_add() to be consistent Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 019/104] irqdomain: Fix domain registration race Greg Kroah-Hartman
2023-03-15 12:11 ` Greg Kroah-Hartman [this message]
2023-03-15 12:11 ` [PATCH 5.10 021/104] iommu/vt-d: Fix PASID directory pointer coherency Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 022/104] arm64: efi: Make efi_rt_lock a raw_spinlock Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 023/104] RISC-V: Avoid dereferening NULL regs in die() Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 024/104] riscv: Avoid enabling interrupts " Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 025/104] riscv: Add header include guards to insn.h Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 026/104] scsi: core: Remove the /proc/scsi/${proc_name} directory earlier Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 027/104] ext4: Fix possible corruption when moving a directory Greg Kroah-Hartman
2023-03-15 12:11 ` [PATCH 5.10 028/104] drm/nouveau/kms/nv50-: remove unused functions Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 029/104] drm/nouveau/kms/nv50: fix nv50_wndw_new_ prototype Greg Kroah-Hartman
2023-03-15 12:12   ` Greg Kroah-Hartman
2023-03-15 12:12   ` [Nouveau] " Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 030/104] drm/msm: Fix potential invalid ptr free Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 031/104] drm/msm/a5xx: fix setting of the CP_PREEMPT_ENABLE_LOCAL register Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 032/104] drm/msm: Document and rename preempt_lock Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 033/104] drm/msm/a5xx: fix the emptyness check in the preempt code Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 034/104] drm/msm/a5xx: fix context faults during ring switch Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 035/104] bgmac: fix *initial* chip reset to support BCM5358 Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 036/104] nfc: fdp: add null check of devm_kmalloc_array in fdp_nci_i2c_read_device_properties Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 037/104] powerpc: dts: t1040rdb: fix compatible string for Rev A boards Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 038/104] ila: do not generate empty messages in ila_xlat_nl_cmd_get_mapping() Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 039/104] selftests: nft_nat: ensuring the listening side is up before starting the client Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 040/104] net: usb: lan78xx: Remove lots of set but unused ret variables Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 041/104] net: lan78xx: fix accessing the LAN7800s internal phy specific registers from the MAC driver Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 042/104] net: caif: Fix use-after-free in cfusbl_device_notify() Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 043/104] net: stmmac: add to set device wake up flag when stmmac init phy Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 044/104] net: phylib: get rid of unnecessary locking Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 045/104] bnxt_en: Avoid order-5 memory allocation for TPA data Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 046/104] netfilter: ctnetlink: revert to dumping mark regardless of event type Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 047/104] netfilter: tproxy: fix deadlock due to missing BH disable Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 048/104] btf: fix resolving BTF_KIND_VAR after ARRAY, STRUCT, UNION, PTR Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 049/104] net: ethernet: mtk_eth_soc: fix RX data corruption issue Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 050/104] scsi: megaraid_sas: Update max supported LD IDs to 240 Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 051/104] platform: x86: MLX_PLATFORM: select REGMAP instead of depending on it Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 052/104] net/smc: fix fallback failed while sendmsg with fastopen Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 053/104] SUNRPC: Fix a server shutdown leak Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 054/104] riscv: Use READ_ONCE_NOCHECK in imprecise unwinding stack mode Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 055/104] RISC-V: Dont check text_mutex during stop_machine Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 056/104] ext4: Fix deadlock during directory rename Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 057/104] iommu/amd: Add a length limitation for the ivrs_acpihid command-line parameter Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 058/104] PCI/PM: Define pci_restore_standard_config() only for CONFIG_PM_SLEEP Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 059/104] watch_queue: fix IOC_WATCH_QUEUE_SET_SIZE alloc error paths Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 060/104] tpm/eventlog: Dont abort tpm_read_log on faulty ACPI address Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 061/104] block, bfq: fix possible uaf for bfqq->bic Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 062/104] block, bfq: fix uaf for bfqq in bfq_exit_icq_bfqq Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 063/104] block/bfq-iosched.c: use "false" rather than "BLK_RW_ASYNC" Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 064/104] block, bfq: replace 0/1 with false/true in bic apis Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 065/104] block, bfq: fix uaf for bfqq in bic_set_bfqq() Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 066/104] clk: qcom: mmcc-apq8084: remove spdm clocks Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 067/104] MIPS: Fix a compilation issue Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 068/104] powerpc: Check !irq instead of irq == NO_IRQ and remove NO_IRQ Greg Kroah-Hartman
2023-03-15 12:31   ` Christophe Leroy
2023-03-15 12:12 ` [PATCH 5.10 069/104] powerpc/kcsan: Exclude udelay to prevent recursive instrumentation Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 070/104] alpha: fix R_ALPHA_LITERAL reloc for large modules Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 071/104] macintosh: windfarm: Use unsigned type for 1-bit bitfields Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 072/104] PCI: Add SolidRun vendor ID Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 073/104] PCI: Avoid FLR for SolidRun SNET DPU rev 1 Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 074/104] scripts: handle BrokenPipeError for python scripts Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 075/104] media: ov5640: Fix analogue gain control Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 076/104] media: rc: gpio-ir-recv: add remove function Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 077/104] ipmi/watchdog: replace atomic_add() and atomic_sub() Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 078/104] ipmi:watchdog: Set panic count to proper value on a panic Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 079/104] skbuff: Fix nfct leak on napi stolen Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 080/104] drm/i915: Dont use BAR mappings for ring buffers with LLC Greg Kroah-Hartman
2023-03-15 12:12   ` [Intel-gfx] " Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 081/104] sched/uclamp: Make task_fits_capacity() use util_fits_cpu() Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 082/104] sched/uclamp: Fix fits_capacity() check in feec() Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 083/104] sched/uclamp: Make select_idle_capacity() use util_fits_cpu() Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 084/104] sched/uclamp: Make asym_fits_capacity() " Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 085/104] sched/uclamp: Make cpu_overutilized() " Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 086/104] sched/uclamp: Cater for uclamp in find_energy_efficient_cpu()s early exit condition Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 087/104] sched/fair: Detect capacity inversion Greg Kroah-Hartman
2023-03-15 12:12 ` [PATCH 5.10 088/104] sched/fair: Consider capacity inversion in util_fits_cpu() Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 089/104] sched/uclamp: Fix a uninitialized variable warnings Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 090/104] sched/fair: Fixes for capacity inversion detection Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 091/104] ext4: refactor ext4_free_blocks() to pull out ext4_mb_clear_bb() Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 092/104] ext4: add ext4_sb_block_valid() refactored out of ext4_inode_block_valid() Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 093/104] ext4: add strict range checks while freeing blocks Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 094/104] ext4: block range must be validated before use in ext4_mb_clear_bb() Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 095/104] arch: fix broken BuildID for arm64 and riscv Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 096/104] powerpc/vmlinux.lds: Define RUNTIME_DISCARD_EXIT Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 097/104] powerpc/vmlinux.lds: Dont discard .rela* for relocatable builds Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 098/104] s390: define RUNTIME_DISCARD_EXIT to fix link error with GNU ld < 2.36 Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 099/104] sh: define RUNTIME_DISCARD_EXIT Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 100/104] UML: " Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 101/104] KVM: nVMX: Dont use Enlightened MSR Bitmap for L3 Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 102/104] KVM: VMX: Introduce vmx_msr_bitmap_l01_changed() helper Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 103/104] KVM: VMX: Fix crash due to uninitialized current_vmcs Greg Kroah-Hartman
2023-03-15 12:13 ` [PATCH 5.10 104/104] s390/dasd: add missing discipline function Greg Kroah-Hartman
2023-03-15 14:21 ` [PATCH 5.10 000/104] 5.10.175-rc1 review Chris Paterson
2023-03-15 14:23 ` Guenter Roeck
2023-03-15 14:26 ` Guenter Roeck
2023-03-16  7:56   ` Greg Kroah-Hartman
2023-03-15 20:18 ` Florian Fainelli
2023-03-15 23:17 ` Daniel Díaz
2023-03-15 23:58 ` Shuah Khan
2023-03-16  0:00 ` Shuah Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230315115732.924259380@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=baolu.lu@linux.intel.com \
    --cc=dave.jiang@intel.com \
    --cc=jroedel@suse.de \
    --cc=patches@lists.linux.dev \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.