From nobody Tue May 14 02:41:46 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C94C5156861; Wed, 27 Mar 2024 12:16:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711541772; cv=none; b=miNsx6Mc92sRALM2+9lzSnjysB26/tdj/vHIh/zho47VQoDEcv1Y3cjteQ3Cf5AUrFrGOo5arDV+sbqfibtvEpX/HOPNmNtMMew2WdxymU19Qj0hzZdC94asty5lrKB1EsE8sfzZQQy5beVYm0LpiNFSR7JyIkgZEmRmrhpFkdc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711541772; c=relaxed/simple; bh=9RyTMMwBIF8uAtriar+c5TuJAZDF70y2ckZWzIn2edE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=hVSdeVEo/aV+5ZW2EKnsSmIlBnSDOofhbwdCF5syWohrQQUejxBo5ojoZ5rJKENGSmFYVAxwxMadcJWvWqv6xEBuVzk/ZroBDx5EDrTm0NF0c0TnxbCjI4Tn6c6nGuRAjJWbupzp4/6/5pIOu+Py2yD1bvhWd4DAW2jG2rTDLFw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tYzQ1n+Z; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tYzQ1n+Z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE871C433F1; Wed, 27 Mar 2024 12:16:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711541772; bh=9RyTMMwBIF8uAtriar+c5TuJAZDF70y2ckZWzIn2edE=; h=From:To:Cc:Subject:Date:From; b=tYzQ1n+Z2zbMNEZNUcKJ+ivw9hMQokaBMROedsZgNvXs6ticRB8c14iyUSnHXk09E se4OJqoFKMbTzH8EusiMCdMk/7OeoRg7aktPaJp9sxm8OuBTf8J+qT3+KtQuqm29Nd Fk7xM/npgqwfMJSw4/dTueJCB+qDl18+cJvt9IKlSyPFId9CUzGb8XMQ2aRuh7P7Ph iyGc21CZxkZroCVxulM7ly1yaBIpRPzJhP5qLq1467KmhUJ4cf2o/X4EGc4kzzTCTO oK9m4ohYqjwnSO61WVIhy6vTtV+FWX0+vcx2knVZG/97022cu6AFcxfcH4s+5X86/R CZJqi9MJpyHzQ== From: Sasha Levin To: stable@vger.kernel.org, alex.williamson@redhat.com Cc: Reinette Chatre , Kevin Tian , Eric Auger , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: FAILED: Patch "vfio/pci: Lock external INTx masking ops" failed to apply to 5.15-stable tree Date: Wed, 27 Mar 2024 08:16:10 -0400 Message-ID: <20240327121610.2832499-1-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Hint: ignore X-stable: review Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The patch below does not apply to the 5.15-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . Thanks, Sasha Reported-by: Reinette Chatre Reviewed-by: Eric Auger Reviewed-by: Kevin Tian Reviewed-by: Reinette Chatre ------------------ original commit in Linus's tree ------------------ From 810cd4bb53456d0503cc4e7934e063835152c1b7 Mon Sep 17 00:00:00 2001 From: Alex Williamson Date: Fri, 8 Mar 2024 16:05:23 -0700 Subject: [PATCH] vfio/pci: Lock external INTx masking ops Mask operations through config space changes to DisINTx may race INTx configuration changes via ioctl. Create wrappers that add locking for paths outside of the core interrupt code. In particular, irq_type is updated holding igate, therefore testing is_intx() requires holding igate. For example clearing DisINTx from config space can otherwise race changes of the interrupt configuration. This aligns interfaces which may trigger the INTx eventfd into two camps, one side serialized by igate and the other only enabled while INTx is configured. A subsequent patch introduces synchronization for the latter flows. Cc: Fixes: 89e1f7d4c66d ("vfio: Add PCI device driver") Reported-by: Reinette Chatre Reviewed-by: Kevin Tian Reviewed-by: Reinette Chatre Reviewed-by: Eric Auger Link: https://lore.kernel.org/r/20240308230557.805580-3-alex.williamson@red= hat.com Signed-off-by: Alex Williamson --- drivers/vfio/pci/vfio_pci_intrs.c | 34 +++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_= intrs.c index 136101179fcbd..75c85eec21b3c 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -99,13 +99,15 @@ static void vfio_send_intx_eventfd(void *opaque, void *= unused) } =20 /* Returns true if the INTx vfio_pci_irq_ctx.masked value is changed. */ -bool vfio_pci_intx_mask(struct vfio_pci_core_device *vdev) +static bool __vfio_pci_intx_mask(struct vfio_pci_core_device *vdev) { struct pci_dev *pdev =3D vdev->pdev; struct vfio_pci_irq_ctx *ctx; unsigned long flags; bool masked_changed =3D false; =20 + lockdep_assert_held(&vdev->igate); + spin_lock_irqsave(&vdev->irqlock, flags); =20 /* @@ -143,6 +145,17 @@ bool vfio_pci_intx_mask(struct vfio_pci_core_device *v= dev) return masked_changed; } =20 +bool vfio_pci_intx_mask(struct vfio_pci_core_device *vdev) +{ + bool mask_changed; + + mutex_lock(&vdev->igate); + mask_changed =3D __vfio_pci_intx_mask(vdev); + mutex_unlock(&vdev->igate); + + return mask_changed; +} + /* * If this is triggered by an eventfd, we can't call eventfd_signal * or else we'll deadlock on the eventfd wait queue. Return >0 when @@ -194,12 +207,21 @@ static int vfio_pci_intx_unmask_handler(void *opaque,= void *unused) return ret; } =20 -void vfio_pci_intx_unmask(struct vfio_pci_core_device *vdev) +static void __vfio_pci_intx_unmask(struct vfio_pci_core_device *vdev) { + lockdep_assert_held(&vdev->igate); + if (vfio_pci_intx_unmask_handler(vdev, NULL) > 0) vfio_send_intx_eventfd(vdev, NULL); } =20 +void vfio_pci_intx_unmask(struct vfio_pci_core_device *vdev) +{ + mutex_lock(&vdev->igate); + __vfio_pci_intx_unmask(vdev); + mutex_unlock(&vdev->igate); +} + static irqreturn_t vfio_intx_handler(int irq, void *dev_id) { struct vfio_pci_core_device *vdev =3D dev_id; @@ -563,11 +585,11 @@ static int vfio_pci_set_intx_unmask(struct vfio_pci_c= ore_device *vdev, return -EINVAL; =20 if (flags & VFIO_IRQ_SET_DATA_NONE) { - vfio_pci_intx_unmask(vdev); + __vfio_pci_intx_unmask(vdev); } else if (flags & VFIO_IRQ_SET_DATA_BOOL) { uint8_t unmask =3D *(uint8_t *)data; if (unmask) - vfio_pci_intx_unmask(vdev); + __vfio_pci_intx_unmask(vdev); } else if (flags & VFIO_IRQ_SET_DATA_EVENTFD) { struct vfio_pci_irq_ctx *ctx =3D vfio_irq_ctx_get(vdev, 0); int32_t fd =3D *(int32_t *)data; @@ -594,11 +616,11 @@ static int vfio_pci_set_intx_mask(struct vfio_pci_cor= e_device *vdev, return -EINVAL; =20 if (flags & VFIO_IRQ_SET_DATA_NONE) { - vfio_pci_intx_mask(vdev); + __vfio_pci_intx_mask(vdev); } else if (flags & VFIO_IRQ_SET_DATA_BOOL) { uint8_t mask =3D *(uint8_t *)data; if (mask) - vfio_pci_intx_mask(vdev); + __vfio_pci_intx_mask(vdev); } else if (flags & VFIO_IRQ_SET_DATA_EVENTFD) { return -ENOTTY; /* XXX implement me */ } --=20 2.43.0