Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp167671lqi; Wed, 6 Mar 2024 13:18:13 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUEaank3Fzg2WaM2S7ZQQ5kfheb7qJn253Q3OLlVDFEfRQDBltR1DerlM3KDn+H+EJkh0Glc9Dh4WdybM6LpfpfucQJfBMNAItskTvNNg== X-Google-Smtp-Source: AGHT+IFD3cLhJlW80KDWhwFAZehgEsoJDBiUygdbNVk8SY104eTN1r71X71P9whsPZNhg8jMdmGT X-Received: by 2002:a05:6402:2157:b0:565:6f27:9dcf with SMTP id bq23-20020a056402215700b005656f279dcfmr11727817edb.34.1709759893564; Wed, 06 Mar 2024 13:18:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709759893; cv=pass; d=google.com; s=arc-20160816; b=xVzYRvUOAROLKhGKk6R+1VhCF9cfYhCFzUIAJaQj/oZXa4HMTulI1ilPXh2rhkysrB 3KgVAzy9MITKlCnSg2kQ7nml34pYaAi9Yh6J3Cbyd4o0sWJpY1Dmww5D+cZ5MRvx2hOe 3t9Vv3BXJnE48d7Aer+yXxJAYF9CoVYuKcKwCRsSNpXO5vhEWJQ7jMZakCPEZ0YZZyd+ 5986MohkTRmPQY9F+zaWS7uf5UNqETr5JSKrPYa5n98Kv/ISd2cynJOYdP6/51f+IMaG Zh7S4OLfNataKdZQH6BCeEYlznWlzOuNfX45Vh3+rO1QNI/YoqtFxZOynwZmyDBWRqp4 TLNw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=GKxkzdumadq/V7PfTsop/NWO/DaB8TFUcF+bx8hs1/8=; fh=MHJMY1O5a4FZClgQgDgk5IZb0BNqewtXeQgzD9Gumuk=; b=nEWN+zcDKEKM3GpOdd+NjJ8goBSKl4zr5ekhBaGdeUlNPJiI9Mz8rOra6/1CvNy1k/ H6AQYRg5bb18A50j9xvTOK2uVR2eCEvkQ1DoEH6W1NtJxIB+av1gHMDD5QvjXOr+D5xW Lu0ckJqgdIaYv8/le88PixCXxLGuymshiK3AqASjP8r8vf5Lzmb2IZH4lGMHNBR6aefM HgoNZWaC4x8gYmEHfcaTmZb3wzsX0hXhKwS9Q6u6yMg9o87JpgYgSOxf4JrI4pwGSFGx v6tpWTf91dX0MfgempgIs3yBlpXMKZ6BNoJCI1NPMvp8tpbgMZO4A2wx97t4PbCwrYw1 7e0Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=We6FdECl; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-94587-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94587-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id c8-20020a05640227c800b00564951ae492si6629776ede.118.2024.03.06.13.18.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 13:18:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-94587-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=We6FdECl; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-94587-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94587-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8DFE21F21EA2 for ; Wed, 6 Mar 2024 21:17:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EC5E61DA5F; Wed, 6 Mar 2024 21:15:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="We6FdECl" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 993581CFBD for ; Wed, 6 Mar 2024 21:15:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709759717; cv=none; b=O71XUMKv35+cAf3sqx7RJiSemgulGtTs5K+kOmuu91337S5CErYG1QmtiWxBXJqeUEeNCUcthOyBN9dTbLxNAeRIcjhBbdyN8I7Zc9bNTJrnwx9xLjh1WCyVlN3o/O70UCMLyussDQFCvJeq5m6XBPPkprSyTzwCnxY2I/lxwAg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709759717; c=relaxed/simple; bh=wOwDFMT2KiCzev+G+gGCSLvck07O+ju1uFi54jiOVGs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ur6soMO9K1MVuvySQWvANEyEMAAa5uQcHeLcIRBu5YjHUurEEjrWzj7/e7oVyUJB09mvOMSpy1bMaNNwvEKZEMoIYe946QQ9NTpp4tLGqjnCI5LnXxxJuDpFuMWRQZAAhm+BWCFS4k50Xp8wezPYW9Rnbz88Z2uetEuM73WaTOA= 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=We6FdECl; arc=none smtp.client-ip=170.10.129.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709759714; 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=GKxkzdumadq/V7PfTsop/NWO/DaB8TFUcF+bx8hs1/8=; b=We6FdEClrI+/rDTr7j4+zaozvBLqaNRslVkDjKSvHWB7eMEy13jdHYzfGBxLxNX9EDR82i 28HTHEfm1lv9+mMXtQtRyYlyi6V8unQtfFXDK7PYlR/rG5t/xLIy8fu0xHVMV7i4OEHqzb A0OEsuN4o/q38v5WOzJq4BikdV93Tgw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-55-VlFKS75gN6SpkkyvnMo6Hw-1; Wed, 06 Mar 2024 16:15:11 -0500 X-MC-Unique: VlFKS75gN6SpkkyvnMo6Hw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 10A52800266; Wed, 6 Mar 2024 21:14:56 +0000 (UTC) Received: from omen.home.shazbot.org (unknown [10.22.33.99]) by smtp.corp.redhat.com (Postfix) with ESMTP id 236763701; Wed, 6 Mar 2024 21:14:54 +0000 (UTC) From: Alex Williamson To: alex.williamson@redhat.com Cc: kvm@vger.kernel.org, eric.auger@redhat.com, clg@redhat.com, reinette.chatre@intel.com, linux-kernel@vger.kernel.org, kevin.tian@intel.com Subject: [PATCH 1/7] vfio/pci: Disable auto-enable of exclusive INTx IRQ Date: Wed, 6 Mar 2024 14:14:36 -0700 Message-ID: <20240306211445.1856768-2-alex.williamson@redhat.com> In-Reply-To: <20240306211445.1856768-1-alex.williamson@redhat.com> References: <20240306211445.1856768-1-alex.williamson@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@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.1 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. Fixes: 89e1f7d4c66d ("vfio: Add PCI device driver") 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 237beac83809..136101179fcb 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -296,8 +296,15 @@ static int vfio_intx_set_signal(struct vfio_pci_core_device *vdev, int fd) ctx->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, ctx->name, vdev); @@ -308,13 +315,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 && ctx->masked) - disable_irq_nosync(pdev->irq); + if (!vdev->pci_2_3 && !ctx->masked) + enable_irq(pdev->irq); spin_unlock_irqrestore(&vdev->irqlock, flags); return 0; -- 2.43.2