Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp887112lqc; Fri, 8 Mar 2024 15:07:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVtHpqS9LPAMiUQeXveJf+JsNElpanhWKMY7pZnLNSTMajXCZJMq7/zaUqs7JnJdIW0gVDk47UcbJIHdoXjaXmt7hAE0ojMv3ZKitt26Q== X-Google-Smtp-Source: AGHT+IHs3KIpjQKroFCbAB12UK2cVhLAV3Ls4kN9qvnRz+1IWSbEnkyGNp2ZHrXsUzqFF8QbY8Nf X-Received: by 2002:a05:6808:e8e:b0:3c2:1d16:c389 with SMTP id k14-20020a0568080e8e00b003c21d16c389mr685408oil.19.1709939255428; Fri, 08 Mar 2024 15:07:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709939255; cv=pass; d=google.com; s=arc-20160816; b=LtTCsH7udlEz2lB4uSaCa4BQEVtlhfOaDa4KZNT3cl0oY3o/H3ELoUorIhRBtsEoog 6E1ocfq+dAQVg6+UsTVJfPng/6fPik45wK6nMwpXpbcqFE4Ou0GuOEsx0zTAhG6E4DSq 5Nn9usIjEDricZJLfh7w27na1i1iV6HwjtR53wEdO6Cc4t2oVnlA+TiTL8t5BhL0P5xv qsCRw7yYWCJbfYwGM/WJ9WlscUtGn8MMSafxC105LOW23jTTbEjuiiGQ2qUTbTCqAWu2 aCa3ALxK6QVruewWRks9Og63C4frEAxHSKJRM+vK2pA7RhxDx6j4RIME4SMvhpi5A5bC fgXA== 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=s1fqiArHyLhCU0d5Vyof/5+mbhO22X+BF7PWrc8qFrE=; fh=AON1tP1R2s0GAvYSrU1I/R6N81mWhzuaPDd8Cwaumc8=; b=hyjFR7XtD+QxhRhKfg52XTswf8ZA0NXJBT/cVnHJGE2muV6ODgAJJO+CmTps4hGRCI N6Rz3JXdL9GGdqBI0URNpWNxkYcFEZSyxZd7gF17BCUvB3WmQ9c/tfXJO78ULONQHKOZ mm1nqhMYj9GKLCRxqhnPFUWSD3it8Pr94cAuZnveaWAej0CSlNJWvLhWHWkTWR42uPR0 N0Sfo5XzxMu6/zElPrA+TjkiKQvmkQwfzCboxcWSLzmkvI596MwvqyfAhx7f+tDv1Bqx R+iocqcq6IKEAwLifcfy4SQl9UEr+UvlL2yQl4IavwHZMHKQ/6MXVssCGieCehZFcUNb 7mvA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=T0+rmlTR; 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-97679-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97679-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id g13-20020a63dd4d000000b005d8c06e15e6si400100pgj.533.2024.03.08.15.07.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 15:07:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-97679-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=T0+rmlTR; 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-97679-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97679-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 75C15283180 for ; Fri, 8 Mar 2024 23:07:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BF9DA3B79C; Fri, 8 Mar 2024 23:06:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="T0+rmlTR" 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 3B3AF43170 for ; Fri, 8 Mar 2024 23:06: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=1709939176; cv=none; b=CWCG/zZTvan82WcepRNIBTN2xzWKU0ImUfQy7VG2lPGwmLQFkhDucbxiCIrbFTF4BDkAjRVtE9kN4XilmI7sE2wUT5FpVMmQ/JJnx9fcAGmBbdDDtIwG1p6Ut5rbs7pwV+HdvbDco3NzlCkkpT73hMicBronPjxUY7ccyA42ZAY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709939176; c=relaxed/simple; bh=heT93CNz8M4GwBdCOZkIHxkdserSfvqS5SdZ6rnGMbA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sQZX08yOvGqgvZU1El40Jb+Ig4GMwvMDeQHbEuQC14gzcXvTHPBLkpBGq12GKuJdN8zeAKDMYwbp2pObQMp7hDEgaEifJgBHJGeSu1ZwZx/9EnJQMUF3rmrBOR6963Z9eP7apelR2nwt/KOTXap9ZRjEqOqrgqEkmWOTvq3qYuQ= 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=T0+rmlTR; 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=1709939174; 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=s1fqiArHyLhCU0d5Vyof/5+mbhO22X+BF7PWrc8qFrE=; b=T0+rmlTRcmjA5xFUJQhkJREr3UBtIbX5/FJk4nusvMHbPGASUVAxVBp5JJ399Ut/x8I//9 jzRKtQXsyg3a40iWHhlTuTQoygBUOIDw1UD6TSn21jdJ8PKvJcOBidDzDmT8GTn8mL/M+0 0PY62IKjwLrwu8T/aqPoqZumBFiIWME= 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-347-7t25bQA-P66lx1ZIL_U-7g-1; Fri, 08 Mar 2024 18:06:06 -0500 X-MC-Unique: 7t25bQA-P66lx1ZIL_U-7g-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 3B9408007A2; Fri, 8 Mar 2024 23:06:06 +0000 (UTC) Received: from omen.home.shazbot.org (unknown [10.22.8.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4112A37FD; Fri, 8 Mar 2024 23:06:04 +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, stable@vger.kernel.org Subject: [PATCH v2 1/7] vfio/pci: Disable auto-enable of exclusive INTx IRQ Date: Fri, 8 Mar 2024 16:05:22 -0700 Message-ID: <20240308230557.805580-2-alex.williamson@redhat.com> In-Reply-To: <20240308230557.805580-1-alex.williamson@redhat.com> References: <20240308230557.805580-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. Cc: stable@vger.kernel.org Fixes: 89e1f7d4c66d ("vfio: Add PCI device driver") Reviewed-by: Kevin Tian 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.44.0