stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org,
	Alex Williamson <alex.williamson@redhat.com>,
	Eric Auger <eric.auger@redhat.com>
Subject: [PATCH 3.18 35/60] vfio: Fix group release deadlock
Date: Tue, 25 Jul 2017 12:16:26 -0700	[thread overview]
Message-ID: <20170725191619.031438920@linuxfoundation.org> (raw)
In-Reply-To: <20170725191614.043749784@linuxfoundation.org>

3.18-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Alex Williamson <alex.williamson@redhat.com>

commit 811642d8d8a82c0cce8dc2debfdaf23c5a144839 upstream.

If vfio_iommu_group_notifier() acquires a group reference and that
reference becomes the last reference to the group, then vfio_group_put
introduces a deadlock code path where we're trying to unregister from
the iommu notifier chain from within a callout of that chain.  Use a
work_struct to release this reference asynchronously.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Tested-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/vfio/vfio.c |   37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

--- a/drivers/vfio/vfio.c
+++ b/drivers/vfio/vfio.c
@@ -278,6 +278,34 @@ static void vfio_group_put(struct vfio_g
 	kref_put_mutex(&group->kref, vfio_group_release, &vfio.group_lock);
 }
 
+struct vfio_group_put_work {
+	struct work_struct work;
+	struct vfio_group *group;
+};
+
+static void vfio_group_put_bg(struct work_struct *work)
+{
+	struct vfio_group_put_work *do_work;
+
+	do_work = container_of(work, struct vfio_group_put_work, work);
+
+	vfio_group_put(do_work->group);
+	kfree(do_work);
+}
+
+static void vfio_group_schedule_put(struct vfio_group *group)
+{
+	struct vfio_group_put_work *do_work;
+
+	do_work = kmalloc(sizeof(*do_work), GFP_KERNEL);
+	if (WARN_ON(!do_work))
+		return;
+
+	INIT_WORK(&do_work->work, vfio_group_put_bg);
+	do_work->group = group;
+	schedule_work(&do_work->work);
+}
+
 /* Assume group_lock or group reference is held */
 static void vfio_group_get(struct vfio_group *group)
 {
@@ -553,7 +581,14 @@ static int vfio_iommu_group_notifier(str
 		break;
 	}
 
-	vfio_group_put(group);
+	/*
+	 * If we're the last reference to the group, the group will be
+	 * released, which includes unregistering the iommu group notifier.
+	 * We hold a read-lock on that notifier list, unregistering needs
+	 * a write-lock... deadlock.  Release our reference asynchronously
+	 * to avoid that situation.
+	 */
+	vfio_group_schedule_put(group);
 	return NOTIFY_OK;
 }
 

  parent reply	other threads:[~2017-07-25 19:16 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-25 19:15 [PATCH 3.18 00/60] 3.18.63-stable review Greg Kroah-Hartman
2017-07-25 19:15 ` [PATCH 3.18 01/60] disable new gcc-7.1.1 warnings for now Greg Kroah-Hartman
2017-07-25 19:15 ` [PATCH 3.18 03/60] x86/rtc: Remove duplicate const specifier Greg Kroah-Hartman
2017-07-25 19:15 ` [PATCH 3.18 04/60] [media] ir-core: fix gcc-7 warning on bool arithmetic Greg Kroah-Hartman
2017-07-25 19:15 ` [PATCH 3.18 05/60] CIFS: Fix handle_cancelled_mid callback initialization Greg Kroah-Hartman
2017-07-25 19:15 ` [PATCH 3.18 06/60] ath9k: fix tx99 use after free Greg Kroah-Hartman
2017-07-25 19:15 ` [PATCH 3.18 07/60] ath9k: fix tx99 bus error Greg Kroah-Hartman
2017-07-25 19:15 ` [PATCH 3.18 08/60] NFC: fix broken device allocation Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 09/60] nfc: Ensure presence of required attributes in the activate_target handler Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 10/60] nfc: Fix the sockaddr length sanitization in llcp_sock_connect Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 11/60] include/stddef.h: Move offsetofend() from vfio.h to a generic kernel header Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 12/60] stddef.h: move offsetofend inside #ifndef/#endif guard, neaten Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 13/60] NFC: Add sockaddr length checks before accessing sa_family in bind handlers Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 14/60] Bluetooth: use constant time memory comparison for secret values Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 15/60] ASoC: compress: Derive substream from stream based on direction Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 16/60] PM / Domains: Fix unsafe iteration over modified list of device links Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 17/60] PM / Domains: Fix unsafe iteration over modified list of domain providers Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 18/60] scsi: ses: do not add a device to an enclosure if enclosure_add_links() fails Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 19/60] powerpc/64: Fix atomic64_inc_not_zero() to return an int Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 20/60] powerpc: Fix emulation of mcrf in emulate_step() Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 21/60] powerpc: Fix emulation of mfocrf " Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 22/60] powerpc/asm: Mark cr0 as clobbered in mftb() Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 23/60] af_key: Fix sadb_x_ipsecrequest parsing Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 24/60] PCI/PM: Restore the status of PCI devices across hibernation Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 25/60] xhci: fix 20000ms port resume timeout Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 26/60] xhci: Fix NULL pointer dereference when cleaning up streams for removed host Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 27/60] usb: storage: return on error to avoid a null pointer dereference Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 28/60] USB: cdc-acm: add device-id for quirky printer Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 29/60] usb: renesas_usbhs: fix usbhsc_resume() for !USBHSF_RUNTIME_PWCTRL Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 30/60] md: dont use flush_signals in userspace processes Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 31/60] Raid5 should update rdev->sectors after reshape Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 32/60] s390/syscalls: Fix out of bounds arguments access Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 34/60] f2fs: Dont clear SGID when inheriting ACLs Greg Kroah-Hartman
2017-07-25 19:16 ` Greg Kroah-Hartman [this message]
2017-07-25 19:16 ` [PATCH 3.18 36/60] vfio: New external user group/file match Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 37/60] MIPS: Fix mips_atomic_set() retry condition Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 38/60] MIPS: Fix mips_atomic_set() with EVA Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 39/60] MIPS: Negate error syscall return in trace Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 40/60] x86/acpi: Prevent out of bound access caused by broken ACPI tables Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 41/60] MIPS: Save static registers before sysmips Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 42/60] MIPS: Actually decode JALX in `__compute_return_epc_for_insn Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 43/60] MIPS: Fix unaligned PC interpretation in `compute_return_epc Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 44/60] MIPS: math-emu: Prevent wrong ISA mode instruction emulation Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 45/60] Input: i8042 - fix crash at boot time Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 46/60] NFS: only invalidate dentrys that are clearly invalid Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 47/60] udf: Fix deadlock between writeback and udf_setsize() Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 48/60] target: Fix COMPARE_AND_WRITE caw_sem leak during se_cmd quiesce Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 50/60] Revert "perf/core: Drop kernel samples even though :u is specified" Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 51/60] staging: rtl8188eu: add TL-WN722N v2 support Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 52/60] drm/mst: Fix error handling during MST sideband message reception Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 53/60] drm/mst: Avoid dereferencing a NULL mstb in drm_dp_mst_handle_up_req() Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 54/60] drm/mst: Avoid processing partially received up/down message transactions Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 55/60] KVM: PPC: Book3S HV: Context-switch EBB registers properly Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 56/60] of: device: Export of_device_{get_modalias, uvent_modalias} to modules Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 57/60] spmi: Include OF based modalias in device uevent Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 58/60] tracing: Fix kmemleak in instance_rmdir Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 59/60] alarmtimer: dont rate limit one-shot timers Greg Kroah-Hartman
2017-07-25 19:16 ` [PATCH 3.18 60/60] MIPS: Send SIGILL for BPOSGE32 in `__compute_return_epc_for_insn Greg Kroah-Hartman
2017-07-26  3:10 ` [PATCH 3.18 00/60] 3.18.63-stable review Guenter Roeck
2017-07-26 14:23 ` 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=20170725191619.031438920@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=alex.williamson@redhat.com \
    --cc=eric.auger@redhat.com \
    --cc=linux-kernel@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).