Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 2BCEC13E048 for ; Fri, 29 Mar 2024 23:00:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711753202; cv=none; b=V+6Xu+6j0QxbmpVxCAkBSlLaARZEMzbh5WcSgDj6KTn795asqcQCaTSVG5ux61InAYsa2Gv6H8MRlYPcRuE5EYvm8496v/fNoKsLSc3lt4adZA6tA4aYuRLu8x9WGBjqCOBHffp1WfU5y+2lP3ToSDYZNMjPr/OpgLHcsmkVU1g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711753202; c=relaxed/simple; bh=rdb6V+5TN4wZuFzjjvJmvg6ZbqLbTQQhlfGDCC8tcHc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X4h/aiS3ZsEN4i46k2sLhDkzB4g7gecItYoKN3fFXpm4xMEw3n/9OnhDsD5S2Y5A1gsI6ig5nTt45qhUGQcUJuo9x4q+vh/Z4hhdNDr5ijrYu1ZAlqJPVUdyNTw7lDPaFbRuFkI9pEgE/eT/EddFNjf7RsD3peyo2iJlx9/94Mk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=WCiVlFcU; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WCiVlFcU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711753200; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jhEFoVQD5djgJeb80sVWE5t7O49S1HvjFqDiQ3IeHQk=; b=WCiVlFcUyEZ6fDXoQLM3Qg3hMbs9k3Z+pgOJ8C/aRounRC+737PoVUR9IfPh/LUn1AMHeL Xqgrmm46XLFz9osyLGC1BPMvNf3JskPax6v8YAgj+7VfpOB7IhuuaP5kf7ifoHSpF6o97E 6ARdHrRsmNf3mr+psDmDR/Qgbs5ZiZQ= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-650-bKToaEvUNmyLf5lFZb1gtQ-1; Fri, 29 Mar 2024 18:59:56 -0400 X-MC-Unique: bKToaEvUNmyLf5lFZb1gtQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0835929AC005; Fri, 29 Mar 2024 22:59:56 +0000 (UTC) Received: from omen.home.shazbot.org (unknown [10.22.34.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C37AC017A1; Fri, 29 Mar 2024 22:59:55 +0000 (UTC) From: Alex Williamson To: stable@vger.kernel.org Cc: Alex Williamson , sashal@kernel.org, gregkh@linuxfoundation.org, eric.auger@redhat.com, Kevin Tian Subject: [PATCH 5.15.y 1/6] vfio/pci: Disable auto-enable of exclusive INTx IRQ Date: Fri, 29 Mar 2024 16:59:37 -0600 Message-ID: <20240329225944.3294388-2-alex.williamson@redhat.com> In-Reply-To: <20240329225944.3294388-1-alex.williamson@redhat.com> References: <20240329225944.3294388-1-alex.williamson@redhat.com> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 [ Upstream commit fe9a7082684eb059b925c535682e68c34d487d43 ] Currently for devices requiring masking at the irqchip for INTx, ie. devices without DisINTx support, the IRQ is enabled in request_irq() and subsequently disabled as necessary to align with the masked status flag. This presents a window where the interrupt could fire between these events, resulting in the IRQ incrementing the disable depth twice. This would be unrecoverable for a user since the masked flag prevents nested enables through vfio. Instead, invert the logic using IRQF_NO_AUTOEN such that exclusive INTx is never auto-enabled, then unmask as required. Cc: Fixes: 89e1f7d4c66d ("vfio: Add PCI device driver") Reviewed-by: Kevin Tian Reviewed-by: Eric Auger Link: https://lore.kernel.org/r/20240308230557.805580-2-alex.williamson@redhat.com Signed-off-by: Alex Williamson --- drivers/vfio/pci/vfio_pci_intrs.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index 6069a11fb51a..0f2739e113b2 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -199,8 +199,15 @@ static int vfio_intx_set_signal(struct vfio_pci_core_device *vdev, int fd) vdev->ctx[0].trigger = trigger; + /* + * Devices without DisINTx support require an exclusive interrupt, + * IRQ masking is performed at the IRQ chip. The masked status is + * protected by vdev->irqlock. Setup the IRQ without auto-enable and + * unmask as necessary below under lock. DisINTx is unmodified by + * the IRQ configuration and may therefore use auto-enable. + */ if (!vdev->pci_2_3) - irqflags = 0; + irqflags = IRQF_NO_AUTOEN; ret = request_irq(pdev->irq, vfio_intx_handler, irqflags, vdev->ctx[0].name, vdev); @@ -211,13 +218,9 @@ static int vfio_intx_set_signal(struct vfio_pci_core_device *vdev, int fd) return ret; } - /* - * INTx disable will stick across the new irq setup, - * disable_irq won't. - */ spin_lock_irqsave(&vdev->irqlock, flags); - if (!vdev->pci_2_3 && vdev->ctx[0].masked) - disable_irq_nosync(pdev->irq); + if (!vdev->pci_2_3 && !vdev->ctx[0].masked) + enable_irq(pdev->irq); spin_unlock_irqrestore(&vdev->irqlock, flags); return 0; -- 2.44.0