From patchwork Fri Feb 2 04:57:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reinette Chatre X-Patchwork-Id: 195579 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp214624dyc; Thu, 1 Feb 2024 21:05:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IEJcRmqjG2vC4KYh/rPjC8GpS48aVwoe/Lownsf8ZrxlBrXsAfxoo3rf8DvAhHroqZVJGIn X-Received: by 2002:a05:6a20:24a2:b0:19c:9d09:957 with SMTP id m34-20020a056a2024a200b0019c9d090957mr6628049pzd.7.1706850349738; Thu, 01 Feb 2024 21:05:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706850349; cv=pass; d=google.com; s=arc-20160816; b=J2CKzoWpzjdDnLVO22G/WocmP1jMAdl5rKVxKDv6FZalzaMAw2YIFvX+2pT8SHk5l0 2zg2gT1VNsCwYyrWiiLziUxE9MZI0Qmmx2vB0VDzVhVv6P78QtJHmu1JkuN2nptkdw+X /4arAetsobOfqdmhx6TR7ofRfwjbW0ilpKGsDNraaj4hT/g9ncdHRW7XAJ/MS1qO9l4A 22AD67pwRezZq+1VghTFqYXdlbRa1pRX6/pwGFFLgkZT0n3TD+5PXjnfGNLs+is+XrAU fEhNTvi4tNB7jfTqCHyl3U1RcaNiMCHUCmq0VFilhpdB+JMU0lR9GNqG3lut6pplvcy2 RJMw== 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=yheIVuWL1NBnephwZQmKkeK4ofNDZJ2oytZt5T+YeVo=; fh=OeLUwr4OwG6c7odG6cR57mFyDmBjQh9Vb9sWqMvjRHc=; b=hl77uBhqiqrYH7gBTvkKxl3A0hbLbMkJfvDg3Scihwj9p0D9H1O4U+WCB+BKQA6MAJ fV03H+fpWQZbkMRIP9La8s5HNBU652BRFb8uxbTWVAqjmxic+FgcoNQHS6f+SJoiUzcW aX4Ydf3ouUW0Tk/1Imlyox8CdpadwgrbGye9SwmWGi/bpVhJgjvtTtdEtsEd+aBoethc 33TyywNlBUimsGHNh09Pr1U8nzuwEmuLCYaQfT/2t0CP3InxSdWDQIjlo1rrSt3VNuqb bwi+4mj0opba0WTe7UscSdE64cQNl9jIJX/mqx2NZpX9tRC/HbDCyOtOh6ReOEoyS9SX KLPQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HnSP4nyM; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49220-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49220-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCWreTVM8RNRxnhfgD7v+3oUtKWVV75yBiCrOHYkaBRhWmO4cNvvHdi0U84spzTjQauB7Oxd9OANgtgWefEXuaG3JGYYFQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id t11-20020a170902dccb00b001d89ed15302si977657pll.495.2024.02.01.21.05.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 21:05:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49220-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HnSP4nyM; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-49220-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49220-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 6EE6C28598B for ; Fri, 2 Feb 2024 05:02:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4B776481CC; Fri, 2 Feb 2024 04:57:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="HnSP4nyM" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 5955B1758D; Fri, 2 Feb 2024 04:57:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706849860; cv=none; b=A+B8Vf44CAXbSdUt3VBr39Z09IUQc2BdaHpfU7ub+C/b6phDdUKvyXLCu2c2vK5L1aRJjOJuIuRZny5bJ2MFX7kB8CuhhrfgRcT5zuy1DBQGGU7FZPlBKaJ3GSGU0XHqVzsXfoixs/k1A6+Jl4pWhsnQYRyNsTCQzAyR99FdWpA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706849860; c=relaxed/simple; bh=hJ099FlQtbdXqo2+oz8/ORBdCodnOxTdeN2C2GWn1FE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iKHYw9W3VxZuTzp4A1xbwL5aHx7rahnUgsgx+RzVtZhdKmv45EWMRm1sRB3few4mi+HElVv5iBoL6OOkkK8AFVp+tpHnU2k0NH1C1mFfMFdJs3m9OFBkIDP3qS7X0zlCS6YR3GgGIOM1KYnVy6o+oRqcXOhmC/DvlMA/0Lfed8w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=HnSP4nyM; arc=none smtp.client-ip=192.198.163.8 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706849858; x=1738385858; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hJ099FlQtbdXqo2+oz8/ORBdCodnOxTdeN2C2GWn1FE=; b=HnSP4nyMS6sVrE6l4bOm1KcNKXsfD73JTXxRMl8U7y2wtC7H2mSCFekR ecLLfq3bIGDMzVI19nt8Xm/AlA9lOgpRICNLEupxfKhxb1TUBxGXg+UA7 E6XZTpd3AdF01CW8yp+Q56k6PnyA5jkyUjjvOH2Wv2qU6eHMJ3lb7HO+z N/P7YXQ5Hb1Iuornjr2w/sYS3uZ5ECblSnZpo0tPnXune1EYPs75HOfXv UgL+2zG31Wt+cDyxWt9RVKaJ7ujZB5A0XXvY5UXheoO+wxRrA6MLc+EHN SLe1f58gkA5PdF6YNjHM1Dzv6YDiciwbQSp1P/hETtcFRhqLYENp7NnLI g==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="17615870" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="17615870" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2024 20:57:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="912339803" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="912339803" Received: from rchatre-ws.ostc.intel.com ([10.54.69.144]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2024 20:57:25 -0800 From: Reinette Chatre To: jgg@nvidia.com, yishaih@nvidia.com, shameerali.kolothum.thodi@huawei.com, kevin.tian@intel.com, alex.williamson@redhat.com Cc: kvm@vger.kernel.org, dave.jiang@intel.com, ashok.raj@intel.com, reinette.chatre@intel.com, linux-kernel@vger.kernel.org, patches@lists.linux.dev Subject: [PATCH 16/17] vfio/pci: Move vfio_msi_disable() to be with other MSI/MSI-X management code Date: Thu, 1 Feb 2024 20:57:10 -0800 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789762312569932506 X-GMAIL-MSGID: 1789762312569932506 The interrupt management code is mostly organized in four sections: shared code (interrupt type checking and interrupt context management), INTx management code, MSI/MSI-X management code, and IOCTL support. vfio_msi_disable() is separate from the other MSI/MSI-X code. This may have been required because vfio_msi_disable() relies on vfio_irq_set_vector_signal() within the IOCTL support. Since vfio_irq_set_vector_signal() is declared earlier it is not required for MSI/MSI-X management code to be mixed with the IOCTL support. Move vfio_msi_disable() to be located with all the other MSI/MSI-X management code. This move makes it simpler to initialize the interrupt management callbacks with vfio_msi_disable() so that it can be provided to the IOCTL support code. Signed-off-by: Reinette Chatre --- drivers/vfio/pci/vfio_pci_intrs.c | 58 +++++++++++++++---------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index 9217fea3f636..daa84a317f40 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -404,6 +404,35 @@ static int vfio_msi_enable(struct vfio_pci_core_device *vdev, return 0; } +static void vfio_msi_disable(struct vfio_pci_core_device *vdev, + unsigned int index) +{ + struct pci_dev *pdev = vdev->pdev; + struct vfio_pci_irq_ctx *ctx; + unsigned long i; + u16 cmd; + + xa_for_each(&vdev->ctx, i, ctx) { + vfio_virqfd_disable(&ctx->unmask); + vfio_virqfd_disable(&ctx->mask); + vfio_irq_set_vector_signal(vdev, i, -1, index); + vfio_irq_ctx_free(vdev, ctx, i); + } + + cmd = vfio_pci_memory_lock_and_enable(vdev); + pci_free_irq_vectors(pdev); + vfio_pci_memory_unlock_and_restore(vdev, cmd); + + /* + * Both disable paths above use pci_intx_for_msi() to clear DisINTx + * via their shutdown paths. Restore for NoINTx devices. + */ + if (vdev->nointx) + pci_intx(pdev, 0); + + vdev->irq_type = VFIO_PCI_NUM_IRQS; +} + /* * vfio_msi_alloc_irq() returns the Linux IRQ number of an MSI or MSI-X device * interrupt vector. If a Linux IRQ number is not available then a new @@ -617,35 +646,6 @@ static int vfio_irq_set_block(struct vfio_pci_core_device *vdev, return ret; } -static void vfio_msi_disable(struct vfio_pci_core_device *vdev, - unsigned int index) -{ - struct pci_dev *pdev = vdev->pdev; - struct vfio_pci_irq_ctx *ctx; - unsigned long i; - u16 cmd; - - xa_for_each(&vdev->ctx, i, ctx) { - vfio_virqfd_disable(&ctx->unmask); - vfio_virqfd_disable(&ctx->mask); - vfio_irq_set_vector_signal(vdev, i, -1, index); - vfio_irq_ctx_free(vdev, ctx, i); - } - - cmd = vfio_pci_memory_lock_and_enable(vdev); - pci_free_irq_vectors(pdev); - vfio_pci_memory_unlock_and_restore(vdev, cmd); - - /* - * Both disable paths above use pci_intx_for_msi() to clear DisINTx - * via their shutdown paths. Restore for NoINTx devices. - */ - if (vdev->nointx) - pci_intx(pdev, 0); - - vdev->irq_type = VFIO_PCI_NUM_IRQS; -} - /* * IOCTL support */