From patchwork Fri Feb 2 04:56:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reinette Chatre X-Patchwork-Id: 195563 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp211821dyc; Thu, 1 Feb 2024 20:59:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IHgr8CdUJ817gjbIFY+49mzzBYDi5n34emlsEPbqMB9eLDNocBWAaPa+qK09+97hePOtDvH X-Received: by 2002:a25:dc12:0:b0:dc2:4d19:4fea with SMTP id y18-20020a25dc12000000b00dc24d194feamr4855145ybe.11.1706849949158; Thu, 01 Feb 2024 20:59:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706849949; cv=pass; d=google.com; s=arc-20160816; b=s1mCaJ2Y/FmfyJJUOtewppJ0DlUJZPwEHy+9cDHBvaEk1aFp0d770767Fk8RX3DIji r2zN3jYhSDSziFLKla03QUlRggCFcu/Io/ISboFvyIFL2n8umaNdUO9mAiArS2qQ9wqV 9n/hmA9kmMHjwSpkqqHsFFSJU+cWyCdXqNuomgeV6WLH91LIaMIKmrNYfDnsdlCzXo/0 OM7rVyWiuiIz90Hvylj0RI/w3D2Ih/U06ybyePPZ9lYEW5OuGqPlzBfiwQgE6O6kPoB/ vIxtfQLLgHcZdNZ6Cu4z8LCWa4IEr5rMI8AXV2cWSCSsDsl97+KEEszXRxdPRRYvH7Bt hy1A== 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=digfdQYLHXIbNNfPRaunuk8o6A/o182DqpyZ6kXWM1g=; fh=6YNxkWumKWm8KmuHmi5/znw4WsOLriowyl42ozfWDug=; b=DRn3ETO5zha7F3XrbkFvBd798U1ChMRMhcgAYZ4VZQg1c+Nq6ebUtsqfeZ7UOP9EaE ScseijUnC9ADTthqJvmMmw58UUrAN3OhKJotjV4xBeuzLYcZoZHILzb7xEg36j+Q7HO/ 8x1Sy+3QEQb2g+pSwWCo8b30L//zk65ysSP4Atbjwt7HbUF2k7Pjw4Ruyf3CbL3WWXhY BVMcuUREXI9q/vDOSKvor6YrI9w/4iiT73OWEm83qbRIf6gAn78yHl85gQkIZH3CHOPJ BklPsnQNWCEXaCOXpds0u4C5Mvgycm7QsqTot/QWhk9lqoumeFZipPN6SED9KaXIWNn1 dhgg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=X06nBpSC; 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-49206-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49206-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCU0b6Z1MpogKV0yxzpSjvZ5KLms/6dXC5krj6K9mifCRxpaj0FnFUKQzSDqKxWDkE7L5+edRMa7/3UHznyapwQp70790g== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id e22-20020a05622a111600b0042bef93f113si1219686qty.26.2024.02.01.20.59.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 20:59:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49206-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=X06nBpSC; 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-49206-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49206-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D1FD11C23096 for ; Fri, 2 Feb 2024 04:59:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D508417758; Fri, 2 Feb 2024 04:57:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="X06nBpSC" 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 1A3C5F9C2; Fri, 2 Feb 2024 04:57:26 +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=1706849850; cv=none; b=Z86BOmk7lpup2uSX5wPL8LBSC4bxbJCyo5FqkahwnouEbqThfS8OGn5V9E9bkWIcMwQtuElOQ9EH9YOLnpptMNh+2HOnKoOM4/XWo7XriFdIJlqiJ9+fpWAiVD9tdEt7tmsa1HQXip+Sleoix0dzRmfquTaWapLkNuyOYdz4TWw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706849850; c=relaxed/simple; bh=5y4NGXUar57YI25p8xEfMr33IxH4G1iGgFkp7ARQYPM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=duFzRpA0gV3GcRdLKxkPZRlrY6Eh1BfA963R0fIY1O5HI7GLQfoKgFFhzd9IGeWDoBxCuETJ0Z8FrsKDoPzX8qbc4YO8SgtF4b3vr06VhzjZ7UZK+jfWnpn/NIhN1v1eR6dk8xhRiBzfNR1pDpj0uvvf0pjr6clRczUgKj4n8Aw= 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=X06nBpSC; 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=1706849847; x=1738385847; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5y4NGXUar57YI25p8xEfMr33IxH4G1iGgFkp7ARQYPM=; b=X06nBpSCcFJa/ccHO+TvH10Yy0jQjTtonVm1Fml/qBWPNDz5EdLqlzGL bEEdf7vgqBZATalA4T466LR0WiyDQYDxGZERujWoWih+ZndAL58QM0HFr JHEA8itFJVAJPNgwbJl2ZPMAdte4dLYu8ZRh64ORySZ/kNCULm8pW9pGu 2QqEZP5av4atOEKfyuEMffnnV6veA4H+tgmHncsnfwE7haAbhopbPmKmd 8hHQR3rRygpKupnCOGVpCA6RIIz7RyWsr1l/2zuKG0mOgnEhVkuYGMrul dSaS7ZJ3j+1nWtH9U+1Gys8CwxiYwmsM+xa+3J69KjZ5p13eqRmHeaEEu w==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="17615791" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="17615791" 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:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="912339759" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="912339759" 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:24 -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 01/17] vfio/pci: Use unsigned int instead of unsigned Date: Thu, 1 Feb 2024 20:56:55 -0800 Message-Id: <81103b9a7f0448bbd8740389fbb77f78c150620d.1706849424.git.reinette.chatre@intel.com> 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: 1789761891912492524 X-GMAIL-MSGID: 1789761891912492524 checkpatch.pl warns about usage of bare unsigned. Change unsigned to unsigned int to eliminate checkpatch.pl warnings about existing code that are encountered by changes to the interrupt management code at or near lines using bare unsigned. Signed-off-by: Reinette Chatre --- Note to maintainers: Originally formed part of the IMS submission below, but is not specific to IMS. https://lore.kernel.org/lkml/cover.1696609476.git.reinette.chatre@intel.com drivers/vfio/pci/vfio_pci_intrs.c | 42 ++++++++++++++++++------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index 237beac83809..f9280e32972a 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -503,8 +503,9 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev, return ret; } -static int vfio_msi_set_block(struct vfio_pci_core_device *vdev, unsigned start, - unsigned count, int32_t *fds, bool msix) +static int vfio_msi_set_block(struct vfio_pci_core_device *vdev, + unsigned int start, unsigned int count, + int32_t *fds, bool msix) { unsigned int i, j; int ret = 0; @@ -553,8 +554,9 @@ static void vfio_msi_disable(struct vfio_pci_core_device *vdev, bool msix) * IOCTL support */ static int vfio_pci_set_intx_unmask(struct vfio_pci_core_device *vdev, - unsigned index, unsigned start, - unsigned count, uint32_t flags, void *data) + unsigned int index, unsigned int start, + unsigned int count, uint32_t flags, + void *data) { if (!is_intx(vdev) || start != 0 || count != 1) return -EINVAL; @@ -584,8 +586,8 @@ static int vfio_pci_set_intx_unmask(struct vfio_pci_core_device *vdev, } static int vfio_pci_set_intx_mask(struct vfio_pci_core_device *vdev, - unsigned index, unsigned start, - unsigned count, uint32_t flags, void *data) + unsigned int index, unsigned int start, + unsigned int count, uint32_t flags, void *data) { if (!is_intx(vdev) || start != 0 || count != 1) return -EINVAL; @@ -604,8 +606,9 @@ static int vfio_pci_set_intx_mask(struct vfio_pci_core_device *vdev, } static int vfio_pci_set_intx_trigger(struct vfio_pci_core_device *vdev, - unsigned index, unsigned start, - unsigned count, uint32_t flags, void *data) + unsigned int index, unsigned int start, + unsigned int count, uint32_t flags, + void *data) { if (is_intx(vdev) && !count && (flags & VFIO_IRQ_SET_DATA_NONE)) { vfio_intx_disable(vdev); @@ -647,8 +650,9 @@ static int vfio_pci_set_intx_trigger(struct vfio_pci_core_device *vdev, } static int vfio_pci_set_msi_trigger(struct vfio_pci_core_device *vdev, - unsigned index, unsigned start, - unsigned count, uint32_t flags, void *data) + unsigned int index, unsigned int start, + unsigned int count, uint32_t flags, + void *data) { struct vfio_pci_irq_ctx *ctx; unsigned int i; @@ -755,8 +759,9 @@ static int vfio_pci_set_ctx_trigger_single(struct eventfd_ctx **ctx, } static int vfio_pci_set_err_trigger(struct vfio_pci_core_device *vdev, - unsigned index, unsigned start, - unsigned count, uint32_t flags, void *data) + unsigned int index, unsigned int start, + unsigned int count, uint32_t flags, + void *data) { if (index != VFIO_PCI_ERR_IRQ_INDEX || start != 0 || count > 1) return -EINVAL; @@ -766,8 +771,9 @@ static int vfio_pci_set_err_trigger(struct vfio_pci_core_device *vdev, } static int vfio_pci_set_req_trigger(struct vfio_pci_core_device *vdev, - unsigned index, unsigned start, - unsigned count, uint32_t flags, void *data) + unsigned int index, unsigned int start, + unsigned int count, uint32_t flags, + void *data) { if (index != VFIO_PCI_REQ_IRQ_INDEX || start != 0 || count > 1) return -EINVAL; @@ -777,11 +783,11 @@ static int vfio_pci_set_req_trigger(struct vfio_pci_core_device *vdev, } int vfio_pci_set_irqs_ioctl(struct vfio_pci_core_device *vdev, uint32_t flags, - unsigned index, unsigned start, unsigned count, - void *data) + unsigned int index, unsigned int start, + unsigned int count, void *data) { - int (*func)(struct vfio_pci_core_device *vdev, unsigned index, - unsigned start, unsigned count, uint32_t flags, + int (*func)(struct vfio_pci_core_device *vdev, unsigned int index, + unsigned int start, unsigned int count, uint32_t flags, void *data) = NULL; switch (index) { From patchwork Fri Feb 2 04:56:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reinette Chatre X-Patchwork-Id: 195567 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp212484dyc; Thu, 1 Feb 2024 21:00:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IFt2Vg05uPc7HbLbapyTLsVfWnWMdiS5qrKwDWF64meRel5ki+B98LJ7YjeiRm/isWTJVm0 X-Received: by 2002:a17:90b:400e:b0:28f:f249:3c4a with SMTP id ie14-20020a17090b400e00b0028ff2493c4amr1782146pjb.19.1706850059613; Thu, 01 Feb 2024 21:00:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706850059; cv=pass; d=google.com; s=arc-20160816; b=gtWZKKQix0SKXDA9MtV2kSs3XmjBxTFrpzZMQ0HRousGc/nCm3ByHekQ0lJczpUb4R Lm/YMAt6KwZO95Wc64oV84LnVbCEQfgnkKdbTg7ZX79RFKkPOxpiJbyxm+PHIiyjxE5Y o2JsyyAR3isXpsreacdrQvA1ugM5xLq7mSAyNDE4YTyXdGQ+3osxN4jlIv82L1s5IUiD 4q06f48R2mX8h8kKl+sL+BQ0fWyVdS2bniFmRbmMxRTD7LAEF4mWqGDjbqL+BWbsEwiG bp6WM1lVifDr7Y/sEyysReZfxPM6tYASZ1L1t1EnzAfO1rg5fnRdO9Q0cynPV7dOBGcJ JrRA== 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=JMyd3Ep1HGe72xO4L5c9qsMV8ESJty8jmcXxNxNB+Qg=; fh=VOpM48OE/Q0ZpY5AW8eIbLzMHbsNvZsvmsJ+XcktaoU=; b=IaXHLNfDWoU+05QAAwOBEbCrg4wgGOX+W1gToJIlOghqR/+Yrg7qhA1qN5j5ockSx7 oNsdQ+zJcF5rT3mHp5xcrhgcsTxQgqQ+DodeV1Zl3irNOIL+5O7KIvHDvZciiVAmEdyn g9iAnIKQKtIg4UbWI+qZVnc5W7lx8CARNJvpy4So4lCUiKPGVPrAtvmcY5HEIyLCHocy DzFBtioD9i3FqoRIVzZI7LKIADvcSAB11ZWnJwLvyjEWjSvT3DjLzlUG4lt5bXx+JrsY hm/1Dr8ckeoGdk10RpXnNOBZL81qLi9L2QpO+40QYOGJlDSJ8f6p0xS1zmqkpsseR2el ZY+g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BW6dVVNj; 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-49205-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49205-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCUw9lcwJlFjIgN8UqkWsVP9koRQ5wvfKxtxDbCdxGau4DDV81hvZ+DypNp5LCLcjgUy2HZNypITY8c10dmR2+asZJQyog== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id n15-20020a170903110f00b001d8aac2072csi1138760plh.172.2024.02.01.21.00.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 21:00:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49205-ouuuleilei=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=@intel.com header.s=Intel header.b=BW6dVVNj; 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-49205-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49205-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 ED40F28CFA6 for ; Fri, 2 Feb 2024 04:58:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9B0FF17545; Fri, 2 Feb 2024 04:57:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="BW6dVVNj" 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 EF400D521; Fri, 2 Feb 2024 04:57:27 +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=1706849849; cv=none; b=VO2QUAlF36Jv4ye7lFf98SHVJJGBY7BC6UqMYN1GOa8O3u5MdL+capowuBqgenrdHhUUZZIWD22GS5sfHVQxKQFhBZOXLuLHsPS4h8nn54v+wZQzJP72qnfXPPywvemVw44N/xEVT2dQOZVnJj4o6l9cccCX4JnL/Mpr1AbDLR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706849849; c=relaxed/simple; bh=SRyuqWoDw8f/ODrjmB+YtXDl8kO/6S8q7xI8rCGmDRA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZGOs7zrR9nAFlUVynv3fv+eVjns6afjM09h2RyxXU1/qV8ZYnfrwCYgkU+M9JwVn2rI5EtM1sgumbrHvTfYjRtEwW0Rb+HZcU+YD7p7x44kGAt/Ldd2XYdlqLXQ8IUISmrCa8FUCn6DCFu/0zeLpHqogN9xk0aUw7dtR2AkQD5k= 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=BW6dVVNj; 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=1706849848; x=1738385848; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SRyuqWoDw8f/ODrjmB+YtXDl8kO/6S8q7xI8rCGmDRA=; b=BW6dVVNjLZUGEz26OkuVhAvAiR4prWmvehVUbmWtDzh81Vr4YZZOPdo3 f+vzGbgcs7pn21B6K6NnWe7vsclh48Ectsq8P+0MMJkkAKFz6EVwkXToL GcYk3NNhKdCkf2m5xpSV/8m40fbEcoF26/H6nElV1yiFuJQIwLcKbPytn +fBUKug3axMxD7TuPC8vgdrVryEhNJGZ09ZtNX2tIgMS6Yx4mYx5tpzJi uwxWGgs1bgUIVA0lbNvVeHXmuQlpOmoy6LN935WFO81y8OLm4ip/7m4py SBZR7hpWbAj1TjSRqj79vh9HAULvaRU352+YaE8j1fcC4h9OMTL60Zasp w==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="17615796" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="17615796" 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:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="912339761" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="912339761" 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:24 -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 02/17] vfio/pci: Remove duplicate check from vfio_pci_set_ctx_trigger_single() wrappers Date: Thu, 1 Feb 2024 20:56:56 -0800 Message-Id: <1429dd8025b6807e4d6951a18c813b94bbc52c0e.1706849424.git.reinette.chatre@intel.com> 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: 1789762007967076225 X-GMAIL-MSGID: 1789762007967076225 Both wrappers of vfio_pci_set_ctx_trigger_single() perform the same parameter checks before calling vfio_pci_set_ctx_trigger_single(). vfio_pci_set_ctx_trigger_single() only handles a single interrupt that is expected to start from 0. Move parameter checks into vfio_pci_set_ctx_trigger_single() instead of duplicated in its callers. Signed-off-by: Reinette Chatre --- drivers/vfio/pci/vfio_pci_intrs.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index f9280e32972a..69ab11863282 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -704,9 +704,13 @@ static int vfio_pci_set_msi_trigger(struct vfio_pci_core_device *vdev, } static int vfio_pci_set_ctx_trigger_single(struct eventfd_ctx **ctx, + unsigned int start, unsigned int count, uint32_t flags, void *data) { + if (start != 0 || count > 1) + return -EINVAL; + /* DATA_NONE/DATA_BOOL enables loopback testing */ if (flags & VFIO_IRQ_SET_DATA_NONE) { if (*ctx) { @@ -763,10 +767,10 @@ static int vfio_pci_set_err_trigger(struct vfio_pci_core_device *vdev, unsigned int count, uint32_t flags, void *data) { - if (index != VFIO_PCI_ERR_IRQ_INDEX || start != 0 || count > 1) + if (index != VFIO_PCI_ERR_IRQ_INDEX) return -EINVAL; - return vfio_pci_set_ctx_trigger_single(&vdev->err_trigger, + return vfio_pci_set_ctx_trigger_single(&vdev->err_trigger, start, count, flags, data); } @@ -775,10 +779,10 @@ static int vfio_pci_set_req_trigger(struct vfio_pci_core_device *vdev, unsigned int count, uint32_t flags, void *data) { - if (index != VFIO_PCI_REQ_IRQ_INDEX || start != 0 || count > 1) + if (index != VFIO_PCI_REQ_IRQ_INDEX) return -EINVAL; - return vfio_pci_set_ctx_trigger_single(&vdev->req_trigger, + return vfio_pci_set_ctx_trigger_single(&vdev->req_trigger, start, count, flags, data); } From patchwork Fri Feb 2 04:56:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reinette Chatre X-Patchwork-Id: 195566 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp212238dyc; Thu, 1 Feb 2024 21:00:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IFTjKBrdGZyuN+i8qUq2OzpYG9ZgEqYLLw8+eOO414ydX4YZ6zY99qEmVWIUGl1bBHKmSg3 X-Received: by 2002:a05:6402:759:b0:55f:fc6f:835b with SMTP id p25-20020a056402075900b0055ffc6f835bmr35032edy.35.1706850027561; Thu, 01 Feb 2024 21:00:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706850027; cv=pass; d=google.com; s=arc-20160816; b=mOnDlVUcqN+TwnLFqb42mH9kwBP/vwDE/yOvrzFq6rLrXShaWU9Sto3M6sOxOn8XWo /3p/O3vSDn5vxv1dfEajgrPgLEdlRUAkAVVJoBR+U5oJWJW4P82oA4ZFDfSAQ+pcxm5l 0UvUdWjKd8TVR7Ulxlw4bjPoKXn/L5p1iWduGwasI7UGQeiVfmOwEsqi6m3zQEslv6AT UkV5DcbUQ+ZezxRWdf3esKg+D6Ja9k+j3tZ9GAlM5zHw+WYdvjte336Y82yh1PdmdsxY qsb9LPb95P0DQzyKGFyvZcNkhHZoGLvu161g6kS2SHKl4+3SLU7aQEa9vMQLDdrhiZIw lxbw== 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=gE06lMYQmUxVU0JvG/WOUQk7GlgMgt2axMsZ+cKNkTQ=; fh=rwh4CxpUkJg1ijvg4FIPstUQS+RUWenzOInbH5i808M=; b=UhG61k9PXFpzZYc96nF2ZYiATg2p7/kGnmWzK+HHg2CVaa8PAVirVmcdldICdbQ6yo 05bRIDiRggTskRk/8kdKC+gshgkFlKh4XqN17OZRDHeTrjNyliNY3GLmfA43BFGan7kp zH0erm43S4W8BU5lpHmmvNXoM5VT8HhJln+gquTTK7fpzw6F8NCJiy3oouvc+UkUmu/9 3G3rql8MSuPmdTL/03VwtR/vyJgRQ5NvYha0q0qVzd1GGX2fsZL0tUT9bkQj9tWYk/0V SZBixc56GQNHZr8iGZDmUIdHEgX1XJLOKKFYc9ZQxlyzrejHg5dQSt4K87/Z8Gbj6DaN PyBg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=G33JQGfS; 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-49209-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49209-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCVWUv5Jgef3CUbwnsaqgJlMYx9P6KyCYrvxYCqnvS6GKW3TINHemGywRwxcmnoPPG3pmgQRea/t/I2crCCzLGt71uO51w== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id w5-20020a056402128500b0055fc4f9f736si472072edv.284.2024.02.01.21.00.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 21:00:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49209-ouuuleilei=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=@intel.com header.s=Intel header.b=G33JQGfS; 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-49209-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49209-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 am.mirrors.kernel.org (Postfix) with ESMTPS id EBBDC1F27D5A for ; Fri, 2 Feb 2024 05:00:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CF68418AEE; Fri, 2 Feb 2024 04:57:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="G33JQGfS" 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 1FFD5F9D3; Fri, 2 Feb 2024 04:57:29 +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=1706849852; cv=none; b=JxwZGNAoVRJhItTuBv7cDAsS79WbwDA4t5oHg/cOwTId0q7KuY4XEOwgy3nDmDuKBoF+8BramyhicS2YQL0cLmWpZ8vW9NeeFGy17tT7c+G4j41iOz/FN4Fr6pDNzeAHektWgK9EbuoO/ha1/sq0Dy8JwkNv4beIWN5HzVcbZu4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706849852; c=relaxed/simple; bh=JWucdCztDGT+G4ZMaH9FIiM5mhLJXuyhplUEEPj9ZAU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XwWFMUW6MUCTqWsUJQJXSgEW+NdtNWlvuOCvci3ZpHJoPaLrcZtIQDdBAmpgRK7AoijATCSkfuwhY1vLtgye44OlcEJ3JkOwuWgsldLpL/tYbjGT2u4smd0wAZeTtYou8hWBrZypuTsh85EKcDd4mofXdXDrqrjX5nb/yI0IMgo= 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=G33JQGfS; 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=1706849849; x=1738385849; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JWucdCztDGT+G4ZMaH9FIiM5mhLJXuyhplUEEPj9ZAU=; b=G33JQGfSAFNAwEemVxQvWRWYBcXBnJJLkOwEseI2KZD9lBjS16Z/+AGe BWRleeN8X7Q8juOMluJBTzAHRtioGCVfMT3HSO+C+PfiWZNvkOXqJddHB fHG2dyMZDmThLfSjhAe9oQwkNr2jUfo3LxCi4au5AQYxva1qEL1ye8NrI dXPfduk/fKDFEs1zVEiI1ZvIbhQGH6+v+Yb5khw71jX4vGKvrRU/mjHM+ cjVaHA8aLuY9QP9AHin2HkLvxgrZIFNsSnjA5pWs9ACLahZHy9ejak/ii eBXmdiF3pOSgygadSLVNm2pU4ZvBiYmcMNDP+U5VQyZlpw91t22hj1PSo Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="17615802" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="17615802" 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:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="912339765" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="912339765" 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:24 -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 03/17] vfio/pci: Consistently acquire mutex for interrupt management Date: Thu, 1 Feb 2024 20:56:57 -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: 1789761974499986175 X-GMAIL-MSGID: 1789761974499986175 vfio_pci_set_irqs_ioctl() is the entrypoint for interrupt management via the VFIO_DEVICE_SET_IRQS ioctl(). The igate mutex is obtained before calling vfio_pci_set_irqs_ioctl() for management of all interrupt types to protect against concurrent changes to the eventfds associated with device request notification and error interrupts. The igate mutex is not acquired consistently. The mutex is always (for all interrupt types) acquired from within vfio_pci_ioctl_set_irqs() before calling vfio_pci_set_irqs_ioctl(), but vfio_pci_set_irqs_ioctl() is called via vfio_pci_core_disable() without the mutex held. The latter is expected to be correct if the code flow can be guaranteed that the provided interrupt type is not a device request notification or error interrupt. Move igate mutex acquire and release into vfio_pci_set_irqs_ioctl() to make the locking consistent irrespective of interrupt type. This is one step closer to contain the interrupt management locking internals within the interrupt management code so that the VFIO PCI core can trigger management of the eventfds associated with device request notification and error interrupts without needing to access and manipulate VFIO interrupt management locks and data. Signed-off-by: Reinette Chatre --- Note to maintainers: Originally formed part of the IMS submission below, but is not specific to IMS. https://lore.kernel.org/lkml/cover.1696609476.git.reinette.chatre@intel.com drivers/vfio/pci/vfio_pci_core.c | 3 --- drivers/vfio/pci/vfio_pci_intrs.c | 10 ++++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index 1cbc990d42e0..d2847ca2f0cb 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -1214,12 +1214,9 @@ static int vfio_pci_ioctl_set_irqs(struct vfio_pci_core_device *vdev, return PTR_ERR(data); } - mutex_lock(&vdev->igate); - ret = vfio_pci_set_irqs_ioctl(vdev, hdr.flags, hdr.index, hdr.start, hdr.count, data); - mutex_unlock(&vdev->igate); kfree(data); return ret; diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index 69ab11863282..97a3bb22b186 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -793,7 +793,9 @@ int vfio_pci_set_irqs_ioctl(struct vfio_pci_core_device *vdev, uint32_t flags, int (*func)(struct vfio_pci_core_device *vdev, unsigned int index, unsigned int start, unsigned int count, uint32_t flags, void *data) = NULL; + int ret = -ENOTTY; + mutex_lock(&vdev->igate); switch (index) { case VFIO_PCI_INTX_IRQ_INDEX: switch (flags & VFIO_IRQ_SET_ACTION_TYPE_MASK) { @@ -838,7 +840,11 @@ int vfio_pci_set_irqs_ioctl(struct vfio_pci_core_device *vdev, uint32_t flags, } if (!func) - return -ENOTTY; + goto out_unlock; + + ret = func(vdev, index, start, count, flags, data); +out_unlock: + mutex_unlock(&vdev->igate); + return ret; - return func(vdev, index, start, count, flags, data); } From patchwork Fri Feb 2 04:56:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reinette Chatre X-Patchwork-Id: 195564 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp211897dyc; Thu, 1 Feb 2024 20:59:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IFOwtaCAQ56ZUZEo4D5kWpxfDSkWYQ2P38uNEzNG5o0j1X9hfxJFSqbBPTvgkujmx8Pc+aS X-Received: by 2002:a17:906:5a8c:b0:a36:4789:3629 with SMTP id l12-20020a1709065a8c00b00a3647893629mr3015717ejq.25.1706849972948; Thu, 01 Feb 2024 20:59:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706849972; cv=pass; d=google.com; s=arc-20160816; b=aZNyFPOk/l21esB2YwwK1S4AnHO/toGUqAckG743SdOWqDWpqI3faWIwNZzIhap7Za ru60/r2Lcnmfo3Sxub/swBM/npK88Y0H39VP0M3XFV6/vUPlq13ZlyihQo3W8S7RTIF6 /m/kMM1iAGU55UvzmYGl9z23hUj/Dil3oIy6SifizBEUIcCstC8opuWF+MzbvwdzA26b CbX+RjFYkav3uX5ozSeA6lMOAhLE0KQrt/8O0BUOae7raU6+TdeDjvBiXQP/QMryZxEz rhKPEID4uk2r9k69nnyucQ32viUUnhlJ5PsSQelfXKTRawnQ2HC4Da4ZfPY5EfdMhvW4 lsiQ== 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=A+0fFqbJEazIIdxUlrwEdNJxU8r3dwXoceXjZhuDMWo=; fh=0hRJvNOpeju/Zx+Ea+uUgwiot4+NvLiCUM75yMu4Jcc=; b=ahgB/NR+azSM7CL/J9mpWmNVE8ib/64USTW9eYHzWQKynBNjQ3QZAuO2f9SUvoyB1y Z/XPpK+elBk0VIu/Ed6gP2vTmAvNJxTPyMuYGWyaHB+JKbW5m4MxvqMcDd/NbiFDueyo hvOdtEHMHodA2SZHwT2lNTID1iyozzWCWa4odXjXniKvdGPndVaBt8grFPIVI+/tZnt6 LYQFEPu3LPedGe9U0fq+0lgl+pZGUuqZTqGTmaFLOpn0CrdAch6l3BDwJ06gABmVUq6w SEt6QuqpW6C5ZreGlPDiNpAY68TgosW/rF0aj60FIw5wyxtsOVqnHoBU4O88LDwXR16m Z9GA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hNdMs8MS; 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-49207-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49207-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCWWiyWtT8isgxPxtfxTbdnrwz457PFO/acxT5EgAC+qWXCDi0NdxZ+hVv6mJwFXxuhDaUCgDzKbT5qCorbDpQxQosQjuw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id gf17-20020a170906e21100b00a370685d59esi209381ejb.621.2024.02.01.20.59.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 20:59:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49207-ouuuleilei=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=@intel.com header.s=Intel header.b=hNdMs8MS; 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-49207-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49207-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 9066A1F27931 for ; Fri, 2 Feb 2024 04:59:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A6CA217BBA; Fri, 2 Feb 2024 04:57:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hNdMs8MS" 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 A363EF9F8; Fri, 2 Feb 2024 04:57:29 +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=1706849851; cv=none; b=b2ZO2bxSKVwf9DRrV9SYLcON1M65j43hbfU3NtpigX59fxDhPoheE1AzkomBpy701WZiDyeoiHZh1csgnn7SRYiQOsHPEF8dFf1M9oTtNDiXiNeXjC7Q6Uj7PhxNY/79XY3FW5+vHjy0mcra1yzIeUu1R+8zGqlkfIXtCqv+Xe4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706849851; c=relaxed/simple; bh=HP2huTcvvO7TUh3mgU3qMuAjpGy887H4YuFiJWxsEUU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uGlqab8hO/7FgYmAf92K+MrrjTbPS9ue0fXd+05fwvU1jwMrH1VDIWHO2m7EFV2GbRGMLoXizJBYKNriODYTeA5l1lw4o8zl0wDPWGkNARE6A9+xWGyZu7kryGLIS43uGIXw7Ez52MKAx7UFGU5xDc1pcdbKOKSvk++kTvckX+Q= 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=hNdMs8MS; 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=1706849850; x=1738385850; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HP2huTcvvO7TUh3mgU3qMuAjpGy887H4YuFiJWxsEUU=; b=hNdMs8MS3e/bBEIeiIY5VHWX6P4SRBeKIi6QUjuZ/EDca/go53DmWCdi 3uyvbRwp3dNWR8onnBl4grBBVSeNsBIdcg8ekFNzS6c5lOzipRQtXsnwb xEwfJc1dGvgxB5XyLOMsJ5kFr/KBOkBbBw/PpvZxuvwOBDgQYl6vbxHBC Q7OtnPnpaxrN4yguZzsehQ7onLNlD6Xg6GxWmcYi6Ls4ovQuCLb+mMi7e k/nHKpu/zhwmABdhTtXd2RsEqy/Vlyl3Iv6PMZ7HX/pHOoTXAHCIn0U0g RjZt5jcz5xNTX3a6XCOisrc+vWarDxqQUKOpql1+11/gyaot8zKldBLaQ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="17615808" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="17615808" 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:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="912339768" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="912339768" 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:24 -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 04/17] vfio/pci: Remove duplicate interrupt management from core VFIO PCI Date: Thu, 1 Feb 2024 20:56:58 -0800 Message-Id: <93dfe93e8fc53e83ac585ed3a891cefde32b3016.1706849424.git.reinette.chatre@intel.com> 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: 1789761917185960801 X-GMAIL-MSGID: 1789761917185960801 The eventfds associated with device request notification and error IRQ are managed by the VFIO PCI interrupt management code contained in vfio_pci_intrs.c. The VFIO PCI interrupt management code supports acquiring, releasing, as well as signaling of these eventfd. The VFIO PCI core code duplicates the signaling of device request notification and error interrupts and does so by acquiring the lock and accessing data that should ideally be contained within the VFIO PCI interrupt management code. Do not duplicate but instead call existing VFIO PCI interrupt management code to signal device request notification and error interrupts. Signed-off-by: Reinette Chatre --- drivers/vfio/pci/vfio_pci_core.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index d2847ca2f0cb..de097174e455 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -700,16 +700,12 @@ void vfio_pci_core_close_device(struct vfio_device *core_vdev) #endif vfio_pci_core_disable(vdev); - mutex_lock(&vdev->igate); - if (vdev->err_trigger) { - eventfd_ctx_put(vdev->err_trigger); - vdev->err_trigger = NULL; - } - if (vdev->req_trigger) { - eventfd_ctx_put(vdev->req_trigger); - vdev->req_trigger = NULL; - } - mutex_unlock(&vdev->igate); + vfio_pci_set_irqs_ioctl(vdev, VFIO_IRQ_SET_DATA_NONE | + VFIO_IRQ_SET_ACTION_TRIGGER, + VFIO_PCI_ERR_IRQ_INDEX, 0, 0, NULL); + vfio_pci_set_irqs_ioctl(vdev, VFIO_IRQ_SET_DATA_NONE | + VFIO_IRQ_SET_ACTION_TRIGGER, + VFIO_PCI_REQ_IRQ_INDEX, 0, 0, NULL); } EXPORT_SYMBOL_GPL(vfio_pci_core_close_device); From patchwork Fri Feb 2 04:56:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reinette Chatre X-Patchwork-Id: 195565 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp212000dyc; Thu, 1 Feb 2024 20:59:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IHkYjsolO+IgsQog2aOgNqTt3ivexWUUr54mpAJtADVCDQrdXYTvpVd5ga9/PyxTCnSE8// X-Received: by 2002:a05:622a:34a:b0:42a:3195:e8be with SMTP id r10-20020a05622a034a00b0042a3195e8bemr4868061qtw.51.1706849992549; Thu, 01 Feb 2024 20:59:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706849992; cv=pass; d=google.com; s=arc-20160816; b=hvdobVy2QtJ7BqbID77YhJq2xDD4x29Y+Cna+UX7dFmXCzlksdQc0sAIgwhEwsnLq1 CNV7Pdkk4VOzfYE3LYIvRzbQsXwwQu2H5hOhQvuIfSmcvGLuzmd7CdOgdUxwHMRxLpIb OBnctPWPs0l3hvqfu1i3Q+kBnaUFwU8l8Ydq01pby1QkQvR23kYks4rherYGKsXqUJXB 0b2WMWKS+yEAorNkiFazmEiLA0pRLWwI2A0RhLEM7Blbq//YQfsD6AN7vHueuMSarA30 7hu85OvykL7kqp20YcBCjCTD4ibO/O5cJ0fnhH3HI3PxU27LjkWyOWrDvroVcLIkjAqQ w10w== 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=bX6PujnvYzVWvXvG1VP4BCFUIjqKZt+tDJb+USnp6aA=; fh=ORhuBRDL5kyCNilIT7kKOjTR6ie6WlesRBPi260/j0I=; b=JFaH4UN+W4AJNskvgfJO232Dv2Ky+9E8TVv3mcns+fVG6iihkLHvFD5NDH5Wa/6zXj Vhq8vBh8fRmP90mTx7BtZYhirOHRppb6Y7eg6nRxzOtyl6+eNO9NP02HyRzqNjvneamG QqLDPJG/WS41ykAEh7xwdP0yUc0HJDAttf3/9pjKrzCPN149YncCi1ok8xZtssCZtCSt Hda651h1SPZIcW2VxGdyuZzLHmHD9aPV+e6w1HaBhfO6faj4IwhvzAOa+WQNJDTpdpyd ThJb6j4WvQqnJUybyTlCgtkFRe84cbbqxYA8k8j1R93nFs02Z7c772WiLMcEtXj8yUA5 ukQA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hWDHKiky; 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-49208-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49208-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCWu4QQ/2IdL4qDaQt0j1TQ/lFfEZsZZrKfJFPfW39FAWX2UfHkBBa7UsmjC3TXBsnKGlV04zBKfUyNWv1sZLG0zxR07zA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f32-20020a05622a1a2000b0042bff27388asi1206376qtb.151.2024.02.01.20.59.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 20:59:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49208-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hWDHKiky; 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-49208-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49208-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 591AF1C24CE3 for ; Fri, 2 Feb 2024 04:59:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6DEBA18027; Fri, 2 Feb 2024 04:57:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hWDHKiky" 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 2DC91101EC; Fri, 2 Feb 2024 04:57:30 +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=1706849851; cv=none; b=frFarHnJmAT9RLRerrCWX/GYRDf611wcwST3EnGFPZjUJrIqc33/100eXSks3mof5qX56M1cYpjZxKSMlSP+JVWovtADfyasKmb9no5YX9LmJT6Uj6actaOGngsAUm3qP7M5Fy4eVNET3XnMnuMWH+z5gogeVsNPrXMz21TVN9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706849851; c=relaxed/simple; bh=wjShxdkTqGwADOgBt3EJHJs5FYJXIg/tseoEaV8uAgM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=h+LiooV3yfqwWDWfXPczHc26MoycSQt5xqEigxgDQQZE/fdWD0WPa7xWrDOwfCgEzplFDh1vnC0svFqHLAM/DkElpeJV1j0hFg8mduk0CICx46MyhU/2/Liwp7eCUaOQCqQtD89uZmHTzIft/fB+L9P0GT/B1i17nbPe41NzHBc= 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=hWDHKiky; 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=1706849850; x=1738385850; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wjShxdkTqGwADOgBt3EJHJs5FYJXIg/tseoEaV8uAgM=; b=hWDHKikybu6AUycg4O0oPYwBVNvSHN0JWa0LTlEpkXFJFC2UwlIWk7B4 4CJYR0u7q4+d4dN8UITwRaahaSVNtbEDldb9m44QCv/9miCWlwiAtlI6Y lPPaqACjaFOGPavV4f4X3XU0DjGY8W0KxwJFm70kWiE5a5vcAnZM3vRDh I0rLwf/Qf6DpPUJ/Lbb8NocBUS3DvgCUhDg2OJeoZm+3l0YyY5033mZbR 4/6izxhOJGiJ4JR+V7znizMzu/+y5K11OuJMufKsJuZ2tlnyaGsiwyZZi 5YIDviDDO0EOTgwlFTaUf3o5kDBkc+Pc3qiQyglmNeztWiF4qG4jpivTs g==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="17615813" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="17615813" 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:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="912339771" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="912339771" 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:24 -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 05/17] vfio/pci: Limit eventfd signaling to interrupt management code Date: Thu, 1 Feb 2024 20:56:59 -0800 Message-Id: <54ba34d884de30f479bbe3844c4a342980760d79.1706849424.git.reinette.chatre@intel.com> 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: 1789761937693636768 X-GMAIL-MSGID: 1789761937693636768 VFIO PCI interrupt management has full support for configuring, signaling, and clearing the eventfds associated with device request notification and error interrupts. Core VFIO PCI duplicates eventfd signaling while also accessing data that should be contained within the interrupt management code. Remove the duplicate eventfd signaling from core VFIO PCI and rely on VFIO PCI interrupt management for eventfd signaling. Signed-off-by: Reinette Chatre --- drivers/vfio/pci/vfio_pci_core.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index de097174e455..a8235b9c1a81 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -1868,21 +1868,20 @@ void vfio_pci_core_request(struct vfio_device *core_vdev, unsigned int count) struct vfio_pci_core_device *vdev = container_of(core_vdev, struct vfio_pci_core_device, vdev); struct pci_dev *pdev = vdev->pdev; + int ret; - mutex_lock(&vdev->igate); + ret = vfio_pci_set_irqs_ioctl(vdev, VFIO_IRQ_SET_DATA_NONE | + VFIO_IRQ_SET_ACTION_TRIGGER, + VFIO_PCI_REQ_IRQ_INDEX, 0, 1, NULL); - if (vdev->req_trigger) { - if (!(count % 10)) - pci_notice_ratelimited(pdev, - "Relaying device request to user (#%u)\n", - count); - eventfd_signal(vdev->req_trigger); - } else if (count == 0) { + if (!ret && !(count % 10)) { + pci_notice_ratelimited(pdev, + "Relaying device request to user (#%u)\n", + count); + } else if (ret && count == 0) { pci_warn(pdev, - "No device request channel registered, blocked until released by user\n"); + "No device request channel registered, blocked until released by user\n"); } - - mutex_unlock(&vdev->igate); } EXPORT_SYMBOL_GPL(vfio_pci_core_request); @@ -2292,12 +2291,9 @@ pci_ers_result_t vfio_pci_core_aer_err_detected(struct pci_dev *pdev, { struct vfio_pci_core_device *vdev = dev_get_drvdata(&pdev->dev); - mutex_lock(&vdev->igate); - - if (vdev->err_trigger) - eventfd_signal(vdev->err_trigger); - - mutex_unlock(&vdev->igate); + vfio_pci_set_irqs_ioctl(vdev, VFIO_IRQ_SET_DATA_NONE | + VFIO_IRQ_SET_ACTION_TRIGGER, + VFIO_PCI_ERR_IRQ_INDEX, 0, 1, NULL); return PCI_ERS_RESULT_CAN_RECOVER; } From patchwork Fri Feb 2 04:57:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reinette Chatre X-Patchwork-Id: 195568 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp212508dyc; Thu, 1 Feb 2024 21:01:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IEDGsgiHKBHWcMN5PFmAmy+aW4b4rW0XTSZPEzKeaHWwhxGt2xx0wqesafd9fSWfsKqeAUE X-Received: by 2002:a0c:b681:0:b0:68c:8525:a349 with SMTP id u1-20020a0cb681000000b0068c8525a349mr1186483qvd.29.1706850062973; Thu, 01 Feb 2024 21:01:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706850062; cv=pass; d=google.com; s=arc-20160816; b=E2nx5G5oY5lYxK8KWUJkK9xQvK7M7Ubfhk2EzrvCFZXY6kKvuLNbE4q0br8sEJJquv ColVGC5ZdLcKrEkP8APgTt/UuoPIIaFWD5UYUdFO7GRhg0+UYw5H31v7262SITRHOMu1 KlxoRTUXUvS0axHq8XSUqLBL0+YopYAJ+LlWBAAzAjB3cK3xtZd2JU5IBM1CfmpBrd9e H7mnjo6rhyAwKa6DECynsCLG4bokqejF7OfBkF3/3iXzlZhTvsiDNCg/KwbP1WVPNqPm 82Qi+qylCe9+2tGBo1bu/dTrGPDUs1ENEsSH95y2oGXULhTQfUiY9P/ELVUn+zU8iU62 juyg== 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=CnFMO2PLxHRxkDWG8sVRLXVgc/PuCIuV0Ln2Z+rK9sM=; fh=J1An2a2+BfIvGWIUUwnt/F1AjavlViLb2Fw0+K86g4I=; b=AGVQjqbX4F7SbSyu+cH7n3eV3NPYQLzUYe6FUbM4wtEVZX0Avngz5eGV2tvFuwPZES M2CxM9hVD9Ig7vJGxlzLG3SFbWUzYGNbVHYBw0w8GwIJXMP5a51Zcw/obmda6qdCE/ai BBV0DiOi8xyKHI6oeUvLLJ+q5mzLu8uMeN34HltHyxfc/SGOG+caURbM3BMPItmqHfhQ MeZ6t36qVxcfd8J2tYTSdigNQ+uHidN7dHhL1xcpGg6MyMM5JxqBggSUrwFdTGNfMsFF 3fGSsAJm1NYat/c2d/hwM2u2E8qE2mVvDxHzSad/qBdH+mhDnbglYJwOWoSs+fsfIUxw FMPQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=b17HEZKp; 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-49210-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49210-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCWf1/RnaVRNlMXZWfK7acAeGIf2UFciPXPYhG2W3zbZO3npvSTfYvwCxwcIZVM56h+sIg4Hi2+NrmhXnm3sdxxeduOBeQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a3-20020a0ce903000000b0068c730740a7si1186843qvo.404.2024.02.01.21.01.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 21:01:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49210-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=b17HEZKp; 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-49210-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49210-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 221F81C26521 for ; Fri, 2 Feb 2024 05:00:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 905561946C; Fri, 2 Feb 2024 04:57:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="b17HEZKp" 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 68E901643E; Fri, 2 Feb 2024 04:57:31 +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=1706849853; cv=none; b=JcsLsY10AahD2sPIsHteSytZfREDzEd1N9doEPr6tpFcmzLFpNXa69Y3/3lwGbRiDGUHm+wn1RkZKGVcVP/T8CcBdfQtFEuiEEbkKEnXYFZ4XM0weUCriVAdzXaYY8bn+PHjWFk0iOEHiVXdU/sdGbk2cOjCIJZCiQcXZ5f5cpU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706849853; c=relaxed/simple; bh=Kxk7o9A62R7KtL/giSvWj2QXePnCiz/Qp5YtBYfbf9E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=J5A/dqRO35Hgkqoa0RvraIpJg8r0xSSrD+iwpf71kqexISTVR60Zcid1U+kq30OP4D244YC8WzOLUeKSZNFk7rRWVVvusqi8P6ddBVLpaQUPnDNFaNrBt0BNiN5coYrSCEK4AR6jIoNF8VXc4snhAZ1y+a8tyE4ks2U+83BmP/o= 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=b17HEZKp; 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=1706849852; x=1738385852; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Kxk7o9A62R7KtL/giSvWj2QXePnCiz/Qp5YtBYfbf9E=; b=b17HEZKprk1chPeVsxf0dJpuHjnLK5y8AEqpnQcTfM6r/o2gqE8NAUB8 mEOUR5C0xShwXwqYFveMUtajxdj5N6+JA2+n9kgi2+SWQ4BDmv0fn6o0S YFmR+B2Y9UtkP5rZxtZIBCFNbTihiJu0Zk+VFEDOIX0hicWrxMigDx829 L9s5BtVq537tJ1U9wlGpSaeQ0LFsPW8l5ch3zN7d1gLet6RWbTDRp8L8m SqEICcPwLZc9AUQRBbXth6UdjNUiQs/rfw2gmQbFwd1QJI9kC3gHxWZJb 0zpHdwZCniiWYgJZLwmP6PDJKiLwkhZIJOowyPO2Qx31ZKlbLLWVgt+YN Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="17615818" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="17615818" 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:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="912339774" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="912339774" 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:24 -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 06/17] vfio/pci: Remove interrupt index interpretation from wrappers Date: Thu, 1 Feb 2024 20:57:00 -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: 1789762011675211618 X-GMAIL-MSGID: 1789762011675211618 vfio_pci_set_intx_trigger() and vfio_pci_set_msi_trigger() have similar enough flows that can be converged into one shared flow instead of duplicated. To share code between management of interrupt types it is necessary that the type of the interrupt is only interpreted by the code specific to the interrupt type being managed. Remove interrupt type interpretation from what will eventually be shared code (vfio_pci_set_msi_trigger(), vfio_msi_set_block()) by pushing this interpretation to be within the interrupt type specific code (vfio_msi_enable(), (temporary) vfio_msi_set_vector_signal()). Signed-off-by: Reinette Chatre --- Note to maintainers: Originally formed part of the IMS submission below, but is not specific to IMS. https://lore.kernel.org/lkml/cover.1696609476.git.reinette.chatre@intel.com drivers/vfio/pci/vfio_pci_intrs.c | 38 +++++++++++++++++-------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index 97a3bb22b186..31f73c70fcd2 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -346,16 +346,19 @@ static irqreturn_t vfio_msihandler(int irq, void *arg) return IRQ_HANDLED; } -static int vfio_msi_enable(struct vfio_pci_core_device *vdev, int nvec, bool msix) +static int vfio_msi_enable(struct vfio_pci_core_device *vdev, int nvec, + unsigned int index) { struct pci_dev *pdev = vdev->pdev; - unsigned int flag = msix ? PCI_IRQ_MSIX : PCI_IRQ_MSI; + unsigned int flag; int ret; u16 cmd; if (!is_irq_none(vdev)) return -EINVAL; + flag = (index == VFIO_PCI_MSIX_IRQ_INDEX) ? PCI_IRQ_MSIX : PCI_IRQ_MSI; + /* return the number of supported vectors if we can't get all: */ cmd = vfio_pci_memory_lock_and_enable(vdev); ret = pci_alloc_irq_vectors(pdev, 1, nvec, flag); @@ -367,10 +370,9 @@ static int vfio_msi_enable(struct vfio_pci_core_device *vdev, int nvec, bool msi } vfio_pci_memory_unlock_and_restore(vdev, cmd); - vdev->irq_type = msix ? VFIO_PCI_MSIX_IRQ_INDEX : - VFIO_PCI_MSI_IRQ_INDEX; + vdev->irq_type = index; - if (!msix) { + if (index == VFIO_PCI_MSI_IRQ_INDEX) { /* * Compute the virtual hardware field for max msi vectors - * it is the log base 2 of the number of vectors. @@ -413,8 +415,10 @@ static int vfio_msi_alloc_irq(struct vfio_pci_core_device *vdev, } static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev, - unsigned int vector, int fd, bool msix) + unsigned int vector, int fd, + unsigned int index) { + bool msix = (index == VFIO_PCI_MSIX_IRQ_INDEX) ? true : false; struct pci_dev *pdev = vdev->pdev; struct vfio_pci_irq_ctx *ctx; struct eventfd_ctx *trigger; @@ -505,25 +509,26 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev, static int vfio_msi_set_block(struct vfio_pci_core_device *vdev, unsigned int start, unsigned int count, - int32_t *fds, bool msix) + int32_t *fds, unsigned int index) { unsigned int i, j; int ret = 0; for (i = 0, j = start; i < count && !ret; i++, j++) { int fd = fds ? fds[i] : -1; - ret = vfio_msi_set_vector_signal(vdev, j, fd, msix); + ret = vfio_msi_set_vector_signal(vdev, j, fd, index); } if (ret) { for (i = start; i < j; i++) - vfio_msi_set_vector_signal(vdev, i, -1, msix); + vfio_msi_set_vector_signal(vdev, i, -1, index); } return ret; } -static void vfio_msi_disable(struct vfio_pci_core_device *vdev, bool msix) +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; @@ -533,7 +538,7 @@ static void vfio_msi_disable(struct vfio_pci_core_device *vdev, bool msix) xa_for_each(&vdev->ctx, i, ctx) { vfio_virqfd_disable(&ctx->unmask); vfio_virqfd_disable(&ctx->mask); - vfio_msi_set_vector_signal(vdev, i, -1, msix); + vfio_msi_set_vector_signal(vdev, i, -1, index); } cmd = vfio_pci_memory_lock_and_enable(vdev); @@ -656,10 +661,9 @@ static int vfio_pci_set_msi_trigger(struct vfio_pci_core_device *vdev, { struct vfio_pci_irq_ctx *ctx; unsigned int i; - bool msix = (index == VFIO_PCI_MSIX_IRQ_INDEX) ? true : false; if (irq_is(vdev, index) && !count && (flags & VFIO_IRQ_SET_DATA_NONE)) { - vfio_msi_disable(vdev, msix); + vfio_msi_disable(vdev, index); return 0; } @@ -672,15 +676,15 @@ static int vfio_pci_set_msi_trigger(struct vfio_pci_core_device *vdev, if (vdev->irq_type == index) return vfio_msi_set_block(vdev, start, count, - fds, msix); + fds, index); - ret = vfio_msi_enable(vdev, start + count, msix); + ret = vfio_msi_enable(vdev, start + count, index); if (ret) return ret; - ret = vfio_msi_set_block(vdev, start, count, fds, msix); + ret = vfio_msi_set_block(vdev, start, count, fds, index); if (ret) - vfio_msi_disable(vdev, msix); + vfio_msi_disable(vdev, index); return ret; } From patchwork Fri Feb 2 04:57:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reinette Chatre X-Patchwork-Id: 195570 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp212553dyc; Thu, 1 Feb 2024 21:01:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IGlu0XR1XM9LhjYhhMFli1nEi1+xfBntdSOuj+KkMfFunyHhEW/1Qc4ZqXZXkiXcSw9xZuV X-Received: by 2002:a0c:e413:0:b0:686:c31:d8b1 with SMTP id o19-20020a0ce413000000b006860c31d8b1mr4227565qvl.17.1706850069339; Thu, 01 Feb 2024 21:01:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706850069; cv=pass; d=google.com; s=arc-20160816; b=audAOZY62y0VkKJU2YwX8sFRHac3OlgRBH4baMEWYKhbshFAJ6b5lk/J6zIb/Ie/4a i3KklH8y93xw3zNsE/v6hVY82yREnG+ex1lJevaa+r7fNes9YuHMa6O0oF9bHWjXZnbE l2mo5YBCYg9ZJA8uDQ9Eb0PYi8fclStSAOuS8jmSnVdPhZ2WyhoXLUtWO1youc6EOvKo ibXPhPGht0ctTj35yTv/SZAKvFwkTTHFa396JXrDeGc20Qcs7Pd4iGq9zZr4n8lJO7h6 UWogH5JbNoMG46qj7ZxLySbOuac1W8mAc2U9XwouAy385nYbPzAgYcLYgwmfm/wchHIo tUuw== 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=2vmxLTX+mQuYlx77J9XrJ1RYMjTSTKX8DRsC4JPHdiA=; fh=fS11JZpAsRnq9RnuFonumGAH6qkdhjbKa/EAw3XkgWU=; b=LIk8mroi+NkJtTCjWCUYQG6MhXXbzedx5+bpB6J4Nty9lCiGwzcsOoopaIqNT8tzqT SPUUneIfpY5ZunABpQ+YQ0uIzBT+GyxGO4LdQOvvlcLGikyHwnH3PailPNZ95UP6NFR3 E1MrbzQpO3iuV0/gb7woTvOAbEP2blRRlpMfPfdFrRiBY97v6ORzmwTVf4aXSzvSyl7E xYEMH6sXx5IP3puwoyjOq3oNHNNKL3VNfHF1TdSN0btxjfdin0UsR3Y0qiX3vdJV7c+0 U+W73RXdfhI+dvxeNPHjFdUt1BHWQEiHH10UF3fDOBluCsHFMdoCJ2vQc2pqPiagTBvy 8w8g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="WC4Zj/1A"; 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-49211-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49211-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCUbK/SSeeAw8vl5z0sanu656aARE4b2mdbjYY8ASLb5zAb0gUJ7mJ3dkCpM8qO4FrOHTnnr8tCB647wNwJqW+k0uhji/w== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a3-20020a0ce903000000b0068c730740a7si1186843qvo.404.2024.02.01.21.01.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 21:01:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49211-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="WC4Zj/1A"; 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-49211-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49211-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 9F2B71C24F9F for ; Fri, 2 Feb 2024 05:00:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0F38CF9CE; Fri, 2 Feb 2024 04:57:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WC4Zj/1A" 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 E682F168DF; Fri, 2 Feb 2024 04:57:31 +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=1706849853; cv=none; b=CUbSfhFaD4jPfU9GFpLNbxUwazdczBoXSOXw5yZRNoDBDnQF+6qUHygWALO4PAPOenaTtw8zMHQWjHRJxUtdHaq1AZoQKvwh09n0+EbwAavE7AHF9pG5rrWUJ1NN1kmiJfIrnG6MAtzuU62HoZQ2UUcoZJtzHJfvlFDXZ1uHRFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706849853; c=relaxed/simple; bh=Y8mGWLOXkQHarvJTOtXDGSt3QFUWy8OXLPs0vhIlLNk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZCUP3myB891NUQXLHdQcT4ubcJcRJsT9/pY++GgCz801GP9SDVC0cLBVyA/hXZ7eWuHMPbeAavta4V3R/9A41Ay8tX8fYBDS45brrYTK0Zf4JoZokzecEvTAmSt5C8SurvBqddkNgAbziOsTJ73fracdCOmHhyvZKYczMvuC1LE= 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=WC4Zj/1A; 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=1706849852; x=1738385852; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Y8mGWLOXkQHarvJTOtXDGSt3QFUWy8OXLPs0vhIlLNk=; b=WC4Zj/1A+LpV9zvH+RjiNYlbHjnJMsGLoNT1EWi6IewmvNpGg/I1K9W+ lDC5Gqsfr34JsDMMLjvxwhvWxnNpuGMZHCyI8EXCiY1uZN3tuFsGtvp9s D0GDKb6LDMrFrZpm52UeUcPIFIqBF+98wKdC/1YI+oiDX85TTvu2Yg2qY OrMp8Hp6TtwyDk0bq4ZtWGVw80g4B2Baoo0pmyoXQBlb8YB7ybvjhauIX 05eyUsFIpxGJx+4upiP242AZtqbb11vn1f6mtjzi8xGNnlXLaL104gzOa 3td5kmIvqP0h3+TEEpZHzeQvpVNsFAKtmsKrpqqMqWDfHzOdwAzbu/EX+ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="17615823" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="17615823" 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:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="912339776" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="912339776" 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:24 -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 07/17] vfio/pci: Preserve per-interrupt contexts Date: Thu, 1 Feb 2024 20:57:01 -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: 1789762018375852518 X-GMAIL-MSGID: 1789762018375852518 MSI and MSI-X interrupt management for PCI passthrough devices create a new per-interrupt context every time an interrupt is allocated, freeing it when the interrupt is freed. The per-interrupt context contains the properties of a particular interrupt. Without a property that persists across interrupt allocation and free it is acceptable to always create a new per-interrupt context. INTx interrupt context has a "masked" property that persists across allocation and free and thus preserves its interrupt context across interrupt allocation and free calls. MSI and MSI-X interrupts already remain allocated across interrupt allocation and free requests, additionally maintaining the individual interrupt context is a reflection of this existing behavior and matches INTx behavior so that more code can be shared. An additional benefit is that maintaining interrupt context supports a potential future use case of emulated interrupts, where the "is this interrupt emulated" is a property that needs to persist across allocation and free requests. Persistent interrupt contexts means that existence of per-interrupt context no longer implies a valid trigger, pointers to freed memory should be cleared, and a new per-interrupt context cannot be assumed needing allocation when an interrupt is allocated. Signed-off-by: Reinette Chatre --- Note to maintainers: This addition originally formed part of the IMS work below that mostly ignored INTx. This work focuses on INTx, MSI, MSI-X where this addition is relevant. https://lore.kernel.org/lkml/cover.1696609476.git.reinette.chatre@intel.com drivers/vfio/pci/vfio_pci_intrs.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index 31f73c70fcd2..7ca2b983b66e 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -427,7 +427,7 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev, ctx = vfio_irq_ctx_get(vdev, vector); - if (ctx) { + if (ctx && ctx->trigger) { irq_bypass_unregister_producer(&ctx->producer); irq = pci_irq_vector(pdev, vector); cmd = vfio_pci_memory_lock_and_enable(vdev); @@ -435,8 +435,9 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev, vfio_pci_memory_unlock_and_restore(vdev, cmd); /* Interrupt stays allocated, will be freed at MSI-X disable. */ kfree(ctx->name); + ctx->name = NULL; eventfd_ctx_put(ctx->trigger); - vfio_irq_ctx_free(vdev, ctx, vector); + ctx->trigger = NULL; } if (fd < 0) @@ -449,16 +450,17 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev, return irq; } - ctx = vfio_irq_ctx_alloc(vdev, vector); - if (!ctx) - return -ENOMEM; + /* Per-interrupt context remain allocated. */ + if (!ctx) { + ctx = vfio_irq_ctx_alloc(vdev, vector); + if (!ctx) + return -ENOMEM; + } ctx->name = kasprintf(GFP_KERNEL_ACCOUNT, "vfio-msi%s[%d](%s)", msix ? "x" : "", vector, pci_name(pdev)); - if (!ctx->name) { - ret = -ENOMEM; - goto out_free_ctx; - } + if (!ctx->name) + return -ENOMEM; trigger = eventfd_ctx_fdget(fd); if (IS_ERR(trigger)) { @@ -502,8 +504,7 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev, eventfd_ctx_put(trigger); out_free_name: kfree(ctx->name); -out_free_ctx: - vfio_irq_ctx_free(vdev, ctx, vector); + ctx->name = NULL; return ret; } @@ -539,6 +540,7 @@ static void vfio_msi_disable(struct vfio_pci_core_device *vdev, vfio_virqfd_disable(&ctx->unmask); vfio_virqfd_disable(&ctx->mask); vfio_msi_set_vector_signal(vdev, i, -1, index); + vfio_irq_ctx_free(vdev, ctx, i); } cmd = vfio_pci_memory_lock_and_enable(vdev); @@ -694,7 +696,7 @@ static int vfio_pci_set_msi_trigger(struct vfio_pci_core_device *vdev, for (i = start; i < start + count; i++) { ctx = vfio_irq_ctx_get(vdev, i); - if (!ctx) + if (!ctx || !ctx->trigger) continue; if (flags & VFIO_IRQ_SET_DATA_NONE) { eventfd_signal(ctx->trigger); From patchwork Fri Feb 2 04:57:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reinette Chatre X-Patchwork-Id: 195571 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp212973dyc; Thu, 1 Feb 2024 21:01:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IGOKzH33XULz0ADdcySrtVXbq+hMOVNzJQubalBe557KItrtx1l+jx18UFKNJkJTVT54B8s X-Received: by 2002:a05:6102:1171:b0:468:ded:78bd with SMTP id k17-20020a056102117100b004680ded78bdmr1019638vsg.30.1706850104263; Thu, 01 Feb 2024 21:01:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706850104; cv=pass; d=google.com; s=arc-20160816; b=cIZapo3zV3J1BX1lom5NwuWSCvRBIAI1dqOy82Q1QdBo2l/ZDCoe4YPVDEivTYiFjY gMNVvDUfCmLTMzZRRR1XS+IltlEULkfisfvbm6b+78GxmIF7aSbIWlpkHvPYc8LCjQWT bRZcjUD5zpt9q0E4Qdjnov9kNfBUPZVhHK/3t6bKA55kyacyTiQUYctKQ03il4dSPeai /D4Aqb3v0++f2EzA5uLIi1TAfSHBG29tYMD0Km7KIYWf40s1+w3RfxQkqcIscM95vgIq thUi3G3Nmef1aEypjgaV20Hlhcjku5bjqkY9yiLZxiB92Vn9REfAYllRUHthzG/fRoTh oryA== 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=kTy7hqIutuKU+mSp2T1vOuzhrv6JPFrIzl0i0By24MA=; fh=8j7CsxpQurAYsrL6mKpr6NdSDRlu2F6N5/0LqthJ+BI=; b=x2FVvdCVTsNzkW6L9Q0QvcyoUlr1DghzJMeMRCBWrtc4g4vPNWy813A3NfO9Ld6Tnl 5FyZbxvJEyEgajyqg8WGEYiSyWvai2jzK3leUzMEfyqOvTOtuVTiPWjMnmnkcqmZq83R /BQJ1jfW1i9EfhkPHHzmp5FI35/XqiU/5eEcaNOL12RqpTcJT1dlJpjNuVhDDetrM4Oh dfJMFA+HRnZ4WHyg42P56aXbQtSKgfbgb3Yg4Sh/uIlk5el+2+O7wdUdjBjYoGDOMsGt Xk8o/tq/mA56Bep9KQIEmwTi9yKOYLwuOBBsF0eIYwSy9kdhHSbm9r4Z/i9SuNc4+nJ+ 6pVw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=C1deUzSI; 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-49213-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49213-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCUwN/Apz9qSdosDi4LfwDhK7LYNWICecxWDo9oIPe5qxD2haqS1S6JmN97of678E2bR+9xZzphE8PnvW3xNgDfmILFfHA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id fc6-20020ad44f26000000b0068059ec19b2si1198815qvb.73.2024.02.01.21.01.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 21:01:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49213-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=C1deUzSI; 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-49213-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49213-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 036321C21CE4 for ; Fri, 2 Feb 2024 05:01:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E870CF9EB; Fri, 2 Feb 2024 04:57:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="C1deUzSI" 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 6909817589; Fri, 2 Feb 2024 04:57:33 +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=1706849855; cv=none; b=kZKviJM1ssHtqE0QOYkSjRoux4YvURB6kmXCN40FezkUawvwDgO35skyZOF5OL0+EAJbNMrtEEOX1ErHmRh4UaoxrnM1QwdfzjXeyB+kwC22ZibSzG01kyRWpvH7sFjIIZrwPoCX6mt8omCYDrlCAm5kXVrohZuTBpSan90lj04= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706849855; c=relaxed/simple; bh=hPTVpULSZEGp+qlRQ7yydOeKGAslemxYjjTwBe0NPao=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=T0x4YZ9TaOiAQtHPCulHJQbKIELkN0hIP+YtniNyjj9LUZUx/Ql4er5GQIqLWYD/ngXTfmN4rMtlRhudq9CtMbfL1SzBuzQpQ/+r5bCK5QKLhMuQMT3YPm/FC9QyGmhcEnNTMOFFHgmY3mAeRq8OIsGTBnJ6MdjZJelgCm2KExY= 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=C1deUzSI; 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=1706849854; x=1738385854; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hPTVpULSZEGp+qlRQ7yydOeKGAslemxYjjTwBe0NPao=; b=C1deUzSI5rrujqcoF2dIGoBuWU1jD/6bAhBMdd/Eu15ipU1sopLF73KI uG4A1ldnxqnG6Tvhdb5nGOqgUnzqx+rmRQ8ZeIxwkSsIA9lyHEP2/HD2H ovHHri4FeZ29vhvyNZaY/mGUn/7PbqXjCfRyrw2xoGLDEQUtU8OscwBvj zuC4D5RL6RT/2EFLD8mWL9KS4l1EURmZpFFJJRIYyxrS+PHKc1ThxlH0e vVCaC3XKm8VYcmdW1yPH2dZHDjL/Fr/5SHHMH4B2whLlqlskUe+dxinsI 52IagxZcYw1ptS/5d9SG1/L2LFHi5lovXSTxbpCmMZ6Ntk2qurKol/ryr w==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="17615834" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="17615834" 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:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="912339780" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="912339780" 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:24 -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 08/17] vfio/pci: Extract MSI/MSI-X specific code from common flow Date: Thu, 1 Feb 2024 20:57:02 -0800 Message-Id: <79aec9a35a494dcd11be059021a3c4c3f4f74b40.1706849424.git.reinette.chatre@intel.com> 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: 1789762054963575533 X-GMAIL-MSGID: 1789762054963575533 vfio_intx_set_signal() and vfio_msi_set_signal() have similar code flow mixed with actions specific to the interrupt type. Code that is similar between MSI, MSI-X, and INTx management can be shared instead of duplicated. Start by replacing the MSI/MSI-X specific code within vfio_msi_set_signal() with functions. These functions that are specific to the management of MSI/MSI-X can later be called from a shared flow. Signed-off-by: Reinette Chatre --- Note to maintainers: This is similar to "vfio/pci: Separate frontend and backend code during interrupt enable/disable" that was submitted as part of IMS changes, but is not specific to IMS. https://lore.kernel.org/lkml/cover.1696609476.git.reinette.chatre@intel.com drivers/vfio/pci/vfio_pci_intrs.c | 134 ++++++++++++++++++++---------- 1 file changed, 89 insertions(+), 45 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index 7ca2b983b66e..70f2382c9c0c 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -414,26 +414,99 @@ static int vfio_msi_alloc_irq(struct vfio_pci_core_device *vdev, return map.index < 0 ? map.index : map.virq; } +static void vfio_msi_free_interrupt(struct vfio_pci_core_device *vdev, + struct vfio_pci_irq_ctx *ctx, + unsigned int vector) +{ + struct pci_dev *pdev = vdev->pdev; + int irq; + u16 cmd; + + irq = pci_irq_vector(pdev, vector); + cmd = vfio_pci_memory_lock_and_enable(vdev); + free_irq(irq, ctx->trigger); + vfio_pci_memory_unlock_and_restore(vdev, cmd); + /*Interrupt stays allocated, will be freed at MSI/MSI-X disable. */ +} + +static int vfio_msi_request_interrupt(struct vfio_pci_core_device *vdev, + struct vfio_pci_irq_ctx *ctx, + unsigned int vector, unsigned int index) +{ + bool msix = (index == VFIO_PCI_MSIX_IRQ_INDEX) ? true : false; + int irq, ret; + u16 cmd; + + irq = vfio_msi_alloc_irq(vdev, vector, msix); + if (irq < 0) + return irq; + + /* + * If the vector was previously allocated, refresh the on-device + * message data before enabling in case it had been cleared or + * corrupted (e.g. due to backdoor resets) since writing. + */ + cmd = vfio_pci_memory_lock_and_enable(vdev); + if (msix) { + struct msi_msg msg; + + get_cached_msi_msg(irq, &msg); + pci_write_msi_msg(irq, &msg); + } + + ret = request_irq(irq, vfio_msihandler, 0, ctx->name, ctx->trigger); + vfio_pci_memory_unlock_and_restore(vdev, cmd); + + return ret; +} + +static char *vfio_msi_device_name(struct vfio_pci_core_device *vdev, + unsigned int vector, unsigned int index) +{ + struct pci_dev *pdev = vdev->pdev; + + return kasprintf(GFP_KERNEL_ACCOUNT, "vfio-msi%s[%d](%s)", + index == VFIO_PCI_MSIX_IRQ_INDEX ? "x" : "", + vector, pci_name(pdev)); +} + +static void vfio_msi_register_producer(struct vfio_pci_core_device *vdev, + struct vfio_pci_irq_ctx *ctx, + unsigned int vector) +{ + struct pci_dev *pdev = vdev->pdev; + int ret; + + ctx->producer.token = ctx->trigger; + ctx->producer.irq = pci_irq_vector(pdev, vector); + ret = irq_bypass_register_producer(&ctx->producer); + if (unlikely(ret)) { + dev_info(&pdev->dev, + "irq bypass producer (token %p) registration fails: %d\n", + ctx->producer.token, ret); + ctx->producer.token = NULL; + ctx->producer.irq = 0; + } +} + +static void vfio_msi_unregister_producer(struct vfio_pci_irq_ctx *ctx) +{ + irq_bypass_unregister_producer(&ctx->producer); +} + static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev, unsigned int vector, int fd, unsigned int index) { - bool msix = (index == VFIO_PCI_MSIX_IRQ_INDEX) ? true : false; - struct pci_dev *pdev = vdev->pdev; struct vfio_pci_irq_ctx *ctx; struct eventfd_ctx *trigger; - int irq = -EINVAL, ret; - u16 cmd; + int ret; ctx = vfio_irq_ctx_get(vdev, vector); if (ctx && ctx->trigger) { - irq_bypass_unregister_producer(&ctx->producer); - irq = pci_irq_vector(pdev, vector); - cmd = vfio_pci_memory_lock_and_enable(vdev); - free_irq(irq, ctx->trigger); - vfio_pci_memory_unlock_and_restore(vdev, cmd); - /* Interrupt stays allocated, will be freed at MSI-X disable. */ + vfio_msi_unregister_producer(ctx); + vfio_msi_free_interrupt(vdev, ctx, vector); kfree(ctx->name); ctx->name = NULL; eventfd_ctx_put(ctx->trigger); @@ -443,13 +516,6 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev, if (fd < 0) return 0; - if (irq == -EINVAL) { - /* Interrupt stays allocated, will be freed at MSI-X disable. */ - irq = vfio_msi_alloc_irq(vdev, vector, msix); - if (irq < 0) - return irq; - } - /* Per-interrupt context remain allocated. */ if (!ctx) { ctx = vfio_irq_ctx_alloc(vdev, vector); @@ -457,8 +523,7 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev, return -ENOMEM; } - ctx->name = kasprintf(GFP_KERNEL_ACCOUNT, "vfio-msi%s[%d](%s)", - msix ? "x" : "", vector, pci_name(pdev)); + ctx->name = vfio_msi_device_name(vdev, vector, index); if (!ctx->name) return -ENOMEM; @@ -468,40 +533,19 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev, goto out_free_name; } - /* - * If the vector was previously allocated, refresh the on-device - * message data before enabling in case it had been cleared or - * corrupted (e.g. due to backdoor resets) since writing. - */ - cmd = vfio_pci_memory_lock_and_enable(vdev); - if (msix) { - struct msi_msg msg; - - get_cached_msi_msg(irq, &msg); - pci_write_msi_msg(irq, &msg); - } + ctx->trigger = trigger; - ret = request_irq(irq, vfio_msihandler, 0, ctx->name, trigger); - vfio_pci_memory_unlock_and_restore(vdev, cmd); + ret = vfio_msi_request_interrupt(vdev, ctx, vector, index); if (ret) goto out_put_eventfd_ctx; - ctx->producer.token = trigger; - ctx->producer.irq = irq; - ret = irq_bypass_register_producer(&ctx->producer); - if (unlikely(ret)) { - dev_info(&pdev->dev, - "irq bypass producer (token %p) registration fails: %d\n", - ctx->producer.token, ret); - - ctx->producer.token = NULL; - } - ctx->trigger = trigger; + vfio_msi_register_producer(vdev, ctx, vector); return 0; out_put_eventfd_ctx: - eventfd_ctx_put(trigger); + eventfd_ctx_put(ctx->trigger); + ctx->trigger = NULL; out_free_name: kfree(ctx->name); ctx->name = NULL; From patchwork Fri Feb 2 04:57:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reinette Chatre X-Patchwork-Id: 195569 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp212530dyc; Thu, 1 Feb 2024 21:01:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IHamlQddQXDqlz9u9bu1HVqzc2j0fXnX2FoVJ8GWymopGynZpWh7Pnpu6S90/Pc8/s++LT1 X-Received: by 2002:ac8:7f93:0:b0:42a:b21f:2111 with SMTP id z19-20020ac87f93000000b0042ab21f2111mr1182787qtj.29.1706850066752; Thu, 01 Feb 2024 21:01:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706850066; cv=pass; d=google.com; s=arc-20160816; b=jPCQ/PAlAABXxPp6GiZlkhN/oJ1YuSlmoikiuRT0dG8jcnF0U4CbWFGpt4W0ZSRQoo jWhkJQwf6tc9PTlNXJRb1oNpNyJMDfjhvkpX/a70GHvK3WGS8lOfqtS5hyeMIxpH71ET 8ABM/gAnFe8Yx4tIifG6ictnCcMVG8rVhlHXWfp9QaJtLR8fJ4UpxXxlZwJgdTjHlXQ6 kYb37xUM3/ArRAit9GFTo3Ytn/oaF5xvBrfmK8pzZ/YmEgBHnV+Dy1HFso2uMArYvhYA VrPHDML3tZeX7ISKR4rn4jctlzjNoSgRN0wyIOKP+pRUVjX/yN+NA/r+YZv6T/FeYoW7 uT6A== 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=i4LHnIQvQA/iun1EPSOEq1RhRSonGvaLxOeaDiPgfTQ=; fh=I3KdSTiKEkgvm1pW/NJ9tgAArsj4WTFRm0adFSu20z8=; b=sGGXIR7DPtNhzoTyGj/pgxrvr0uU8oYFA1XVfK4d9FheF/1zojIv4q6q2qNEKSZE8r tGXu0E2n5Ht/TRvqFMVAkLWbeuAgUWSXhXKU1L5me33OOpdl+ioi2o6/5r9YqMC6ty2K +XLP0IOUmn/iENbQfDfKaTWbCX86WfngK44ZduUfctRphuwuSb7bfOwBWalJJyblVtRi LCP2cWCG2rbVEozHpCdGSsx8bhq2TxeBRx7xCYQ0vJig96lEbwi1O0e1k4A0GNL9BaA0 0G8HWsoCpJ61ywto7aYAIRcQbtOUgvYl51CBtvrn7etltxCtlz7qtYGtEIB81L3/JDxL H1Jg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jFZ7ofY3; 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-49212-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49212-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCWWGES6NvcjkFjEYJ/l6IF5C3UQfxXYMWFqkaC2WQHtm+dBFllK2FudCRnXufkzaOR4Kcmt0T3Jkfsm64YptdAb7gWvCg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 11-20020ac84e8b000000b0042bed047689si1233961qtp.315.2024.02.01.21.01.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 21:01:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49212-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jFZ7ofY3; 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-49212-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49212-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id BAAC21C270A8 for ; Fri, 2 Feb 2024 05:00:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CCDE1199BC; Fri, 2 Feb 2024 04:57:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jFZ7ofY3" 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 4E8B1171BB; Fri, 2 Feb 2024 04:57:32 +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=1706849854; cv=none; b=syFgmW23vMRWb1xYVVdBC0PFnyHSjNHhqRBDaQTck0Rb0IAIVubMND1Wahu32ZMmrg5QovuU3tpa0BlTZEhkMFZUNhAzY4aw1FPx1eybKnt4g1If611f3v8Y92pLts6A6VrW65jisri0umEoIvw98lAyRMe/jL4MWUew39e6DT8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706849854; c=relaxed/simple; bh=JgRfCrK7Y34Oc8Goi+1GvDvltDbKKC8kZ84KFNDHKXM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eOo035wwKnfEXt2FlpExUTYgkn9HrzRdgwGTX8Jaxt972JML7411UuZ5XjY82PA1voDYUO1BfRXBSPP2pIUhf36jQDdo/Ytp0UJk4O59JSUtbqqS3N0ACOwYkqv92p4dnniWvxIF37VrTGlpS95TOI7zIsaUCBRty5JJXYGO9LQ= 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=jFZ7ofY3; 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=1706849852; x=1738385852; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JgRfCrK7Y34Oc8Goi+1GvDvltDbKKC8kZ84KFNDHKXM=; b=jFZ7ofY3rBygnljUqyFOkJzq526CJJ/nxKV/1nxuu5nohx55IcTAe08K sWuSQKPeS0fanu3/a0HwdFMGCoec66NQbOlmoAimFjFCo3Vp7VIMZ7dBL fCwCS+iuT5OwD8HJ4k5P1cla+1FYfYr+9ZWm01/+bubXtrsmeZvNduptx terVCoMDWfhOIwyw08dF00WK/rjxJ2zMLxKiqEfqjmwJudswOANaPsyh2 8ujoXArVthdljtki8DxiNztTpXMN93kWUlF8pDQ7kDLl22+6OHahTtDYr FaPTg9rue0cLz9tcJsmXo8I+oiygsfi8QGU0udKYGRCVNGeSXbjQUHprL g==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="17615828" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="17615828" 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:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="912339783" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="912339783" 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 09/17] vfio/pci: Converge similar code flows Date: Thu, 1 Feb 2024 20:57:03 -0800 Message-Id: <250808eb11a206075c0b92f2dae23a924f73c390.1706849424.git.reinette.chatre@intel.com> 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: 1789762015450966284 X-GMAIL-MSGID: 1789762015450966284 vfio_intx_set_signal() and vfio_msi_set_vector_signal() have similar code flows that can be shared. Modify vfio_intx_set_signal()'s signature to resemble that of vfio_msi_set_vector_signal() by also providing the vector and interrupt type as parameters. For vfio_intx_set_signal() these two additional parameters are redundant and unused since the vector is always 0 and the interrupt type is always INTx. Adding these parameters make it possible to refactor vfio_intx_set_signal() to call INTx specific functions with the same signature as the MSI/MSI-X specific functions in preparation for these interrupt type specific functions to be called by shared code. Signed-off-by: Reinette Chatre --- drivers/vfio/pci/vfio_pci_intrs.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index 70f2382c9c0c..98b099f58b2b 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -260,7 +260,9 @@ static int vfio_intx_enable(struct vfio_pci_core_device *vdev) return 0; } -static int vfio_intx_set_signal(struct vfio_pci_core_device *vdev, int fd) +static int vfio_intx_set_signal(struct vfio_pci_core_device *vdev, + unsigned int vector, int fd, + unsigned int index) { struct pci_dev *pdev = vdev->pdev; unsigned long irqflags = IRQF_SHARED; @@ -330,7 +332,7 @@ static void vfio_intx_disable(struct vfio_pci_core_device *vdev) vfio_virqfd_disable(&ctx->unmask); vfio_virqfd_disable(&ctx->mask); } - vfio_intx_set_signal(vdev, -1); + vfio_intx_set_signal(vdev, 0, -1, VFIO_PCI_INTX_IRQ_INDEX); vdev->irq_type = VFIO_PCI_NUM_IRQS; vfio_irq_ctx_free(vdev, ctx, 0); } @@ -674,13 +676,13 @@ static int vfio_pci_set_intx_trigger(struct vfio_pci_core_device *vdev, int ret; if (is_intx(vdev)) - return vfio_intx_set_signal(vdev, fd); + return vfio_intx_set_signal(vdev, start, fd, index); ret = vfio_intx_enable(vdev); if (ret) return ret; - ret = vfio_intx_set_signal(vdev, fd); + ret = vfio_intx_set_signal(vdev, start, fd, index); if (ret) vfio_intx_disable(vdev); From patchwork Fri Feb 2 04:57:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reinette Chatre X-Patchwork-Id: 195572 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp213004dyc; Thu, 1 Feb 2024 21:01:47 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXYJWaM/E+SfIPXdGwHONgQst7xYD5bURKkFr3b4ePGrkg3gJtSRlP7/7TP3ecq8La7ufrgBXiJSIW1Q9U92CfNUl0UlQ== X-Google-Smtp-Source: AGHT+IGNOIbRWhPcUUHEWZbaKj3Bzts+DurC69++ILfxGn7qJNXAFljUlWLW6szTsdRvJDUvwoUU X-Received: by 2002:a17:906:6789:b0:a35:46d8:53ce with SMTP id q9-20020a170906678900b00a3546d853cemr699075ejp.18.1706850107273; Thu, 01 Feb 2024 21:01:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706850107; cv=pass; d=google.com; s=arc-20160816; b=OGaMuCau/RPCmrKaASeRwIMdGHOxqp9hwT+dNHqbMoUlmkjnzPvPPkx2wvZU+3MR97 59MkaeS7wh/s+Db+yv4KvWC4cRGnOzAPxqt7cNeFIzcj22Hp00CZln11jnKCs7FIFpaZ 0ZCzp0LlbqFn2VSDVkfKza5X2NeGzXScK1WcONX1CMt4vy24I1Sa1tD/iOaaY7eMiZWo nnM0a4LD6/N+M2t73mmV4+Tr97WcSts34f+z8VqHVTGpBWzdJo05wWzEJKJeMbRddN8r eDe/KiaUAP9gSvyQggqE/d9FmOEZISTg18xhL9W5VRaTnlHJrwQ7swjnJuub/stDZ8KI 3tsA== 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=xPtALXFxo1OVS8pG3XZu1jodP+gfX1M1+3MAjUFri+o=; fh=8xNgkpGyzmmQLL5OgPhu5/9tMgbTg6L2WK74ia0JDLQ=; b=FYnqUc+xRZKhySOe4MG3VwQoblLtUBrPtyT4kjLAXwKL2t6gHe+H+BaBFdSJ8H8I5K D3kXIfA0rnmca1Ejl3n1lT6Jc/KW+HEKEvyumtDGUmUs0CXcnWV31kUlJj0ghQ7Xr9Qt GuUksNHkZwY3NZi8/atw48I0eUPU56jO8b05yBxzNMO1ez+x7oS9DmjWadKaw0Yj5jgK GMVc3djk2gwX8kUK5CoAVUuvcNzoGV9AOl6262D/JKM+Uxm11O+9OoUOXluRiYuw3paT X+N+ZN+BEy/RiXPC3sNK6uwWwPxGGlv12fBeMEVL02vZlUBJEWc5yNpUw/atvd5HkAz+ rCjw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bZzF8kbn; 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-49214-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49214-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCXpHZkEO4N6L98hUkcP95avdxmaAFRz4knZriiNynHbCMnH9ZIaC5VFaNHWG0ltO4PhH5H9byk8B8yt3+hfUkWwm95i2g== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a9-20020a17090680c900b00a3189ddd839si453571ejx.92.2024.02.01.21.01.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 21:01:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49214-ouuuleilei=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=@intel.com header.s=Intel header.b=bZzF8kbn; 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-49214-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49214-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 am.mirrors.kernel.org (Postfix) with ESMTPS id DD7BB1F2276A for ; Fri, 2 Feb 2024 05:01:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 06921168DF; Fri, 2 Feb 2024 04:57:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="bZzF8kbn" 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 EA8E417983; Fri, 2 Feb 2024 04:57:33 +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=1706849856; cv=none; b=RabVAZE/C8yf7XPAd+KndCYXo5c7P/F9L0irhmg9J6Kgf3MmiKKsXNBsnbGGwjLKU9arG/z+p3Fg+B8hZV9Evx1yYEVkzO+XwVgWCb7//GuyLhVqgezhdaFYSvcek435Z1aLMAQ4tDl0u4RFbBGukz8dLkOtxzQtlsKiECPPhJ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706849856; c=relaxed/simple; bh=HLRJyna+Zk3jXF4APHd23iO3eqvDn9o+9jiToz4XQtQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=L/rZGJ9k9XNBOCxb4oq1RWF6em9XXXBJ8HhBvmh0Z5tpDPRR+fu6tJiTBQQTWC0orhLViMWEzyeoWyZ387/dbLGl5KJd5/7HhQvZa7lfMeZ6cHRDzWR0hwFz0T0I+nq8H1m1vE1bgPSCcAeaugz2HwuBQt4hhgdqnHR30FaEDC8= 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=bZzF8kbn; 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=1706849854; x=1738385854; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HLRJyna+Zk3jXF4APHd23iO3eqvDn9o+9jiToz4XQtQ=; b=bZzF8kbnFfD6ePrnb1FsH6pXAI2YzADRBwBZA0v9mcDNsQWeEYUNmnm5 e95AfmeLenQqQ2WoirBQESi2gtAwOMIReql3Ln1oRW6GGbDr9q2zEhGsW SGXtIrXtAFqkAuqaPpIkLH68xCt//WHX7OYbY41gPG+51inJD1Z/4TsTn cf+J13FesttL1viAD/QnFaOxJJLV+NXIaWcIgp1GQI0ZxqYpmSsLVNEY6 1lSmXPT6/RSN89A2ZjZ4gcuTlNnRiiVZbVws5i/ZciGzTEpUjcMfGio2W H0I6iQPROaqdX8rzy76iUvB4Btz0srAjajHXQuspTNYE4HkcRLCRHWrsA g==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="17615840" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="17615840" 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="912339786" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="912339786" 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 10/17] vfio/pci: Extract INTx specific code from vfio_intx_set_signal() Date: Thu, 1 Feb 2024 20:57:04 -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: 1789762057964782181 X-GMAIL-MSGID: 1789762057964782181 vfio_intx_set_signal() and vfio_msi_set_vector_signal() use the same code flow for INTx, MSI, and MSI-X interrupt management. Extract the INTx specific code from vfio_intx_set_signal() to leave behind the same flow as vfio_msi_set_vector_signal(), ready for sharing. Signed-off-by: Reinette Chatre --- drivers/vfio/pci/vfio_pci_intrs.c | 69 ++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 20 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index 98b099f58b2b..6eef4e2d7c13 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -260,15 +260,58 @@ static int vfio_intx_enable(struct vfio_pci_core_device *vdev) return 0; } +static void vfio_intx_free_interrupt(struct vfio_pci_core_device *vdev, + struct vfio_pci_irq_ctx *ctx, + unsigned int vector) +{ + struct pci_dev *pdev = vdev->pdev; + + free_irq(pdev->irq, vdev); +} + +static int vfio_intx_request_interrupt(struct vfio_pci_core_device *vdev, + struct vfio_pci_irq_ctx *ctx, + unsigned int vector, unsigned int index) +{ + unsigned long irqflags = IRQF_SHARED; + struct pci_dev *pdev = vdev->pdev; + unsigned long flags; + int ret; + + if (!vdev->pci_2_3) + irqflags = 0; + + ret = request_irq(pdev->irq, vfio_intx_handler, irqflags, + ctx->name, vdev); + if (ret) + 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); + spin_unlock_irqrestore(&vdev->irqlock, flags); + + return 0; +} + +static char *vfio_intx_device_name(struct vfio_pci_core_device *vdev, + unsigned int vector, unsigned int index) +{ + struct pci_dev *pdev = vdev->pdev; + + return kasprintf(GFP_KERNEL_ACCOUNT, "vfio-intx(%s)", pci_name(pdev)); +} + static int vfio_intx_set_signal(struct vfio_pci_core_device *vdev, unsigned int vector, int fd, unsigned int index) { - struct pci_dev *pdev = vdev->pdev; - unsigned long irqflags = IRQF_SHARED; struct vfio_pci_irq_ctx *ctx; struct eventfd_ctx *trigger; - unsigned long flags; int ret; ctx = vfio_irq_ctx_get(vdev, 0); @@ -276,7 +319,7 @@ static int vfio_intx_set_signal(struct vfio_pci_core_device *vdev, return -EINVAL; if (ctx->trigger) { - free_irq(pdev->irq, vdev); + vfio_intx_free_interrupt(vdev, ctx, vector); kfree(ctx->name); eventfd_ctx_put(ctx->trigger); ctx->trigger = NULL; @@ -285,8 +328,7 @@ static int vfio_intx_set_signal(struct vfio_pci_core_device *vdev, if (fd < 0) /* Disable only */ return 0; - ctx->name = kasprintf(GFP_KERNEL_ACCOUNT, "vfio-intx(%s)", - pci_name(pdev)); + ctx->name = vfio_intx_device_name(vdev, vector, index); if (!ctx->name) return -ENOMEM; @@ -298,11 +340,7 @@ static int vfio_intx_set_signal(struct vfio_pci_core_device *vdev, ctx->trigger = trigger; - if (!vdev->pci_2_3) - irqflags = 0; - - ret = request_irq(pdev->irq, vfio_intx_handler, - irqflags, ctx->name, vdev); + ret = vfio_intx_request_interrupt(vdev, ctx, vector, index); if (ret) { ctx->trigger = NULL; kfree(ctx->name); @@ -310,15 +348,6 @@ static int vfio_intx_set_signal(struct vfio_pci_core_device *vdev, 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); - spin_unlock_irqrestore(&vdev->irqlock, flags); - return 0; } From patchwork Fri Feb 2 04:57:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reinette Chatre X-Patchwork-Id: 195573 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp213007dyc; Thu, 1 Feb 2024 21:01:48 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWYUKy3pJVkqZeIfmtgFQ9MYJOKo4+oEag0DCOIt32DBoqoIvVAJG9cmfz9fiJ70VNhVd80N15pY7YdwVJyr2csMCosnQ== X-Google-Smtp-Source: AGHT+IFOBYXBiDhc3fwEwVGezYBo/Dam+EJawsZZOerLb5c3nNH73ewRL81yi6Zwc+DhtyoY8tcv X-Received: by 2002:a17:907:88d:b0:a36:2d2f:3385 with SMTP id zt13-20020a170907088d00b00a362d2f3385mr568632ejb.9.1706850107867; Thu, 01 Feb 2024 21:01:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706850107; cv=pass; d=google.com; s=arc-20160816; b=gnKLr7SU6DLzKx62fiGa0TGEnzpBjz7FLtOxLHd38nrVFJrBUmwjzZbO3UVJ4kDV5X lacgIrHcr3OGJSP1xTAy/kcTf+pOgXldNopCCia50p/tWBzTmRWD04XbTYH02OUvOcku PEnEwflqum1eoU+DUejMC/iE6JQHrE+gBhOwYzJP6ykvjUnvOKwxsMet9mszo/4bTaU3 oYoOp47jPlfjORqcaChzpAMKAWBAJfkGr3fcpft0+/QAWUafHsojisliSQcIYpoU+1js IuxM/NIeznrrGw4boogr1VhWrL24gd63STXNko7D4cCSsLlAfHJSJrKJOcaagfbUwL9O Cgkw== 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=goB4Bq2sJtHfbvwTf4kP2sEFkQtgEe8OZONwo71rTj8=; fh=QCAc00PICrjSTayjShtso2xOLCwzCceKtIXxwT9ltzU=; b=s9p1MNn/cavaqCi+fExJSrIJErEUWweQc4BxU2fjJHbVvfnpB+zarVER7ZaNHW/jCs hcVXjr+XypoI5f5HMQ8uIUSlEAdGD1xPWULzGwGnFWOGTKMlgItm6BO1/4Fd7le06hAZ mrSVS87ork4e6X2QUPzwMzGZu4Hlx965Ps1yp5DDRrdZwzZnwOsJfEA78wdRR49OUJmy yeg9qgbe6bfBXkCKQGocQOwjty1/oPlxAWGJxRQu3Gym+dTPXmKJvBcatatKomopMQet krP8p7NdEN7RqJekT1PxjxOwDcTq4WswSPl1dzv6wjlct6TZxY0Grk7XnAVwjzgl7x/p GXeQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dalA8Zbf; 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-49215-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49215-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCWinvUKDLNluzlmYtW2Nxx5lFuz0DVSlVGHlSyKjUxULDexJm6AxgMDrTgf/OyVurZ5qUOMksKEXLXo4oeO5+KzfIongw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id x13-20020a170906134d00b00a37026f56e0si270304ejb.346.2024.02.01.21.01.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 21:01:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49215-ouuuleilei=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=@intel.com header.s=Intel header.b=dalA8Zbf; 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-49215-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49215-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 7A4661F2274B for ; Fri, 2 Feb 2024 05:01:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 06A3D32C88; Fri, 2 Feb 2024 04:57:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dalA8Zbf" 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 515D0179B7; Fri, 2 Feb 2024 04:57:34 +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=1706849856; cv=none; b=lxeWo8LsegXjZv1ulID0YLmfMzFWY7o7V/QPrIM3b35u3v8GUhE13qisy5oV/Wterg1+FyV5y7oQTaM53rN/PoOMLNNgcded2T7EJgcXu4K5H7nEbo0DsD9EUec+TcuHaZ/aY+83fmD+QcBErNBQtwk7dHvBtsa4xl5h0DiS1G0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706849856; c=relaxed/simple; bh=i1ZuVfKb6uZ0Dp+3vSDXltmIsz2QMq5Yyj+6aoiLHUY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Fd2PKC+6swxOwSZFNR7m4tWHdCYThMFNG109HHMiGorhIVK9SdatH//cTZFuJpJQflGe/X+GmkG7mLpuuG40exlcw/XiMev4sn1F1Vn1zV/tclxcNXSybaoUFl9eyNiwcm4MpNit0WMFqbtgtJD0jiaMLM23435JpaghyMMSqwk= 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=dalA8Zbf; 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=1706849854; x=1738385854; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=i1ZuVfKb6uZ0Dp+3vSDXltmIsz2QMq5Yyj+6aoiLHUY=; b=dalA8Zbf82p2Sq03WFvifSQojFcgyf91WvqmKPKvKSP16WfL1vYsPixX ROJkVtXcxd07xgVRkFEG3Kh8aghjKmCUpt4UK/sUJNE1MHYt32mPiZ3ld zToiuuIagDVIrdJkX2mF+88kRTOg/DpHhBOXqDK1BuegdPnxPPFJYvgpb AHjaHZqiTy/iqj+mftwANGf7RCM95DOub8UoI0AG1bxffqkjk9XHf69Ol ULkfkoj3KPqdmTN5qoFR++AYSdMxnzvKyYoM4wBr00Ii1LsmHeyX+jNqs G50Gsko6dXTxjHz4b5GwLWqeIELMo4iq2SoiwbQdS+9eTFygZisIZjGp2 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="17615848" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="17615848" 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="912339789" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="912339789" 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 11/17] vfio/pci: Perform MSI/MSI-X interrupt management via callbacks Date: Thu, 1 Feb 2024 20:57:05 -0800 Message-Id: <4e04371e86722f8e2d867fe813a67c10f48222af.1706849424.git.reinette.chatre@intel.com> 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: 1789762058649598963 X-GMAIL-MSGID: 1789762058649598963 vfio_msi_set_vector_signal() is specific to MSI and MSI-X interrupt management but its flow is the same as vfio_intx_set_signal() that manages the INTx interrupts. Replace the MSI and MSI-X specific calls with callbacks in preparation for vfio_msi_set_vector_signal() to manage INTx interrupts also. In preparation for support of INTx only the IRQ bypass code is made optional. Signed-off-by: Reinette Chatre --- Note to maintainers: This change resembles "vfio/pci: Replace backend specific calls with callbacks" that formed part of the IMS submission, but is not specific to IMS. https://lore.kernel.org/lkml/cover.1696609476.git.reinette.chatre@intel.com drivers/vfio/pci/vfio_pci_intrs.c | 44 +++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index 6eef4e2d7c13..07dc388c4513 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -31,6 +31,21 @@ struct vfio_pci_irq_ctx { struct irq_bypass_producer producer; }; +struct vfio_pci_intr_ops { + int (*request_interrupt)(struct vfio_pci_core_device *vdev, + struct vfio_pci_irq_ctx *ctx, + unsigned int vector, unsigned int index); + void (*free_interrupt)(struct vfio_pci_core_device *vdev, + struct vfio_pci_irq_ctx *ctx, + unsigned int vector); + char *(*device_name)(struct vfio_pci_core_device *vdev, + unsigned int vector, unsigned int index); + void (*register_producer)(struct vfio_pci_core_device *vdev, + struct vfio_pci_irq_ctx *ctx, + unsigned int vector); + void (*unregister_producer)(struct vfio_pci_irq_ctx *ctx); +}; + static bool irq_is(struct vfio_pci_core_device *vdev, int type) { return vdev->irq_type == type; @@ -525,6 +540,23 @@ static void vfio_msi_unregister_producer(struct vfio_pci_irq_ctx *ctx) irq_bypass_unregister_producer(&ctx->producer); } +static struct vfio_pci_intr_ops intr_ops[] = { + [VFIO_PCI_MSI_IRQ_INDEX] = { + .request_interrupt = vfio_msi_request_interrupt, + .free_interrupt = vfio_msi_free_interrupt, + .device_name = vfio_msi_device_name, + .register_producer = vfio_msi_register_producer, + .unregister_producer = vfio_msi_unregister_producer, + }, + [VFIO_PCI_MSIX_IRQ_INDEX] = { + .request_interrupt = vfio_msi_request_interrupt, + .free_interrupt = vfio_msi_free_interrupt, + .device_name = vfio_msi_device_name, + .register_producer = vfio_msi_register_producer, + .unregister_producer = vfio_msi_unregister_producer, + }, +}; + static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev, unsigned int vector, int fd, unsigned int index) @@ -536,8 +568,9 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev, ctx = vfio_irq_ctx_get(vdev, vector); if (ctx && ctx->trigger) { - vfio_msi_unregister_producer(ctx); - vfio_msi_free_interrupt(vdev, ctx, vector); + if (intr_ops[index].unregister_producer) + intr_ops[index].unregister_producer(ctx); + intr_ops[index].free_interrupt(vdev, ctx, vector); kfree(ctx->name); ctx->name = NULL; eventfd_ctx_put(ctx->trigger); @@ -554,7 +587,7 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev, return -ENOMEM; } - ctx->name = vfio_msi_device_name(vdev, vector, index); + ctx->name = intr_ops[index].device_name(vdev, vector, index); if (!ctx->name) return -ENOMEM; @@ -566,11 +599,12 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev, ctx->trigger = trigger; - ret = vfio_msi_request_interrupt(vdev, ctx, vector, index); + ret = intr_ops[index].request_interrupt(vdev, ctx, vector, index); if (ret) goto out_put_eventfd_ctx; - vfio_msi_register_producer(vdev, ctx, vector); + if (intr_ops[index].register_producer) + intr_ops[index].register_producer(vdev, ctx, vector); return 0; From patchwork Fri Feb 2 04:57:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reinette Chatre X-Patchwork-Id: 195574 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp213252dyc; Thu, 1 Feb 2024 21:02:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IFTj3E5Hee3ygT4jwVG2gbVuZtI7jcduFGbPI9v4yFQtTdCMBMcka6sXURiuPWRBA7wk2Pu X-Received: by 2002:ac8:7d4d:0:b0:42b:f5b0:36bf with SMTP id h13-20020ac87d4d000000b0042bf5b036bfmr2142612qtb.34.1706850141297; Thu, 01 Feb 2024 21:02:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706850141; cv=pass; d=google.com; s=arc-20160816; b=XcD2Ilf5lpc1v6oW//2ILXLdELOMoFlU7jH6zifGhEZ4GN4dWprvPh+DSO28NJ0M8I dEanPbp4ibrzn5p4mBk1YpueS6um5fJKN+4/2efYBJf+wtw9qIDXjMytlVlHE2kFYtzx 9mCD3EihkoYFgAJWm9krwMdiEsgguexvFpNq9o4y3BM/2yOh8URABI1T30V6pCSZWSh5 dpnyFLim8zrDGlHF26Z9mncsFknBo/6xhkDZaGFwacBKk+bGQwthqw8TsoUt2sD4KZ/q zhvvz86pag80Vb1EE9PId4ZGnQvwy5FcVhmqLB0VdDt/QstcLg1d0Akv0rmlgoJvm/uH WQnA== 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=Dd9cW9mN3qWiOUniv0zJM5hT0pLdzRVExcmsoAXEW9Y=; fh=p+frus4yfIT7T3EHTsiSDujY2vevbPOCpjqt2lSk7v4=; b=Bs5lqdNzAvz3GV/LeyOk+LkREwR4Ze7Lwwm2l2JVFHWu37ADQormyr63RjeS8T/ua3 nbkMHQ5ibcjB537Q6U5GAhAueLKlrHNwIzw8HozjuMXUd4Qf0H0RNaoumyTI/uI/nxQW Wrozr64sOTrt1amA1DjnZDsbo79728f3PmS0S/Efj93o3/ZB3Re0g3uWh8papZRqlOtL 2QhfLKkz2D5q9ipQTsuwbl7+9oixlGr8I1y3dXtOvZvsClXxVKFgx408EkEAijS1NyVN NhwI8dErXMgEGBnj8jG5nLJV+0r7Eo6OM8+2njIwvOd/K+KK2wEtGUbgYwRbdrWRJJwk Fs0g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RCFKid6y; 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-49216-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49216-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCWV2Ff1eCv8ZoZHgHVSG8ALNWiuSLomLdhnSDcRlxSSE0rM1QYjkk/nWXiDsHMgS2pvP7yGn0JBCsLG5muchMtaKfDzHw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id k19-20020ac85fd3000000b0042aa7503250si1159263qta.135.2024.02.01.21.02.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 21:02:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49216-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RCFKid6y; 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-49216-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49216-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 1C7581C225D8 for ; Fri, 2 Feb 2024 05:02:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4913D42074; Fri, 2 Feb 2024 04:57:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="RCFKid6y" 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 9195418041; Fri, 2 Feb 2024 04:57:35 +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=1706849857; cv=none; b=rcz6hQj7h8OM7DbcHTx+sjC5XFGN3nwCYeOgBLiL99b/1pEbB2pdnYOE1nYQirfYGcFZSAFRdaqvwtRX5yH7IOM5pvAeH2ljhWK+ZR5LDv8OZkvUJrDJQruYN8CcGcACoUyEtqADoONbSxTPtQhkUZyCIVlObwjnw+w7bssfmp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706849857; c=relaxed/simple; bh=BJ/iiqpnrpLGQqepNldAyRvzSYt7cnd2BvmP/2lcET0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fixUsKsK5oQV6mr5/DwOUb1ynkkz9TGw6b95j2wpFzGigIVq8xpPQ5gRvYS+fEF/Zp2ORnuArN5lgiN+2okn8MXY5V7rBrgyGMd00ECApnNPwkEeka9OQllcjCK/uZtjmA7d1uTILYghM8J8aj+vzGl9c6nYND/KtGgF9AdJKkY= 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=RCFKid6y; 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=1706849856; x=1738385856; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BJ/iiqpnrpLGQqepNldAyRvzSYt7cnd2BvmP/2lcET0=; b=RCFKid6yYwTVoGcBw1kh22Wld3UKLnA7bJB62o1/ztSGHhf9W9Pxe3f1 kuVQhL+OSwKOO4JDCo1R6VhD+zwu1fQWhSd9nxveurjDcaE4VEl5KVuKT CLP9W3nK4R83+v713bkXtvJVG5Tg0MrAw/ZvJCvxulzoufLclloSetw19 f9HgWT+7VAa8YknDDaxMXY6dRR0l5W6HTuAjNEDAHJCAuW2C9M7/vD388 m5xUnfSogPI/QRDKGtG9LZgUD9eeMqAxyjWdF+g4r8KyriY+f8zsuqaH2 bSVKfNR1ljh6T6YuMz7dk09vFsEbEiLwAFwXBIrN5rm40vJmCNSnDg//u A==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="17615850" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="17615850" 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="912339792" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="912339792" 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 12/17] vfio/pci: Remove msi term from generic code Date: Thu, 1 Feb 2024 20:57:06 -0800 Message-Id: <0550572e64505df6ecff0b08f1eca869a79f6acf.1706849424.git.reinette.chatre@intel.com> 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: 1789762094076670535 X-GMAIL-MSGID: 1789762094076670535 vfio_msi_set_vector_signal() and by extension vfio_msi_set_block() are no longer specific to MSI and MSI-X interrupts. Change the name of these functions in preparation for them to be used for management of INTx interrupts. Signed-off-by: Reinette Chatre --- drivers/vfio/pci/vfio_pci_intrs.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index 07dc388c4513..7f9dc81cb97f 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -557,7 +557,7 @@ static struct vfio_pci_intr_ops intr_ops[] = { }, }; -static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev, +static int vfio_irq_set_vector_signal(struct vfio_pci_core_device *vdev, unsigned int vector, int fd, unsigned int index) { @@ -617,7 +617,7 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev, return ret; } -static int vfio_msi_set_block(struct vfio_pci_core_device *vdev, +static int vfio_irq_set_block(struct vfio_pci_core_device *vdev, unsigned int start, unsigned int count, int32_t *fds, unsigned int index) { @@ -626,12 +626,12 @@ static int vfio_msi_set_block(struct vfio_pci_core_device *vdev, for (i = 0, j = start; i < count && !ret; i++, j++) { int fd = fds ? fds[i] : -1; - ret = vfio_msi_set_vector_signal(vdev, j, fd, index); + ret = vfio_irq_set_vector_signal(vdev, j, fd, index); } if (ret) { for (i = start; i < j; i++) - vfio_msi_set_vector_signal(vdev, i, -1, index); + vfio_irq_set_vector_signal(vdev, i, -1, index); } return ret; @@ -648,7 +648,7 @@ static void vfio_msi_disable(struct vfio_pci_core_device *vdev, xa_for_each(&vdev->ctx, i, ctx) { vfio_virqfd_disable(&ctx->unmask); vfio_virqfd_disable(&ctx->mask); - vfio_msi_set_vector_signal(vdev, i, -1, index); + vfio_irq_set_vector_signal(vdev, i, -1, index); vfio_irq_ctx_free(vdev, ctx, i); } @@ -786,14 +786,14 @@ static int vfio_pci_set_msi_trigger(struct vfio_pci_core_device *vdev, int ret; if (vdev->irq_type == index) - return vfio_msi_set_block(vdev, start, count, + return vfio_irq_set_block(vdev, start, count, fds, index); ret = vfio_msi_enable(vdev, start + count, index); if (ret) return ret; - ret = vfio_msi_set_block(vdev, start, count, fds, index); + ret = vfio_irq_set_block(vdev, start, count, fds, index); if (ret) vfio_msi_disable(vdev, index); From patchwork Fri Feb 2 04:57:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reinette Chatre X-Patchwork-Id: 195577 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp214570dyc; Thu, 1 Feb 2024 21:05:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IGgizGboggE8zHM8T4lVrGGj15r3jGRYsba+/rivu1wDwuNCKrnARCscHlAdqRitA3IB7I2 X-Received: by 2002:a05:6808:b33:b0:3be:cdbd:5dd7 with SMTP id t19-20020a0568080b3300b003becdbd5dd7mr4206808oij.22.1706850339695; Thu, 01 Feb 2024 21:05:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706850339; cv=pass; d=google.com; s=arc-20160816; b=s5bWSn9vo8KkM6KaYN8+EcFXjG86VIGix/PD8gfzzw6BbDf7XdzaEIdeJMeM7uTeJ2 khq5hygEiLfk9Sh87oVXMrr7CVTF6Er9CzBRcguuO58oZXNQWoxYum10ujxgML/36HfM ooK2Bom4HVtIP8UJYk9r+kTx4nuYUlak5R7+9Ng4Je1oF1OgpPQKGug91Gbdb1GCfdZp /y8Y9vkVWBWQAUWQQXY3iGktp86IUhzp1IPwty6ZENryhhd4uCBpzdWZzqtgRw6lwFmq 81idkQU4Yr1gGYhuJoUYaPnX7eWWmhBrvcUTbZVRiPlrZzDJLp6R4AcQwZ2FL3gl1V+V RTrg== 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=ZDerv2quIxk78oUNxK3H4gRgKPGuMTBOlFB3q+C11OY=; fh=sE3c76XM0LFo3dQjM4ssl8yV8OoXdOwQxKcd1tCtudQ=; b=0MthK6Qg/O52SgNuU4FT6UuOF9YNupvogfAJusFfW4M1vPz4akYrpwOBIehWTSBsm7 QcXt9bLiRdNsPLKx9pK75qqzJBzgmXZVAfkccfRkDCh+onNfaJLtZt9eK3WZV9rQm4xb iPHddHlA7MJGFuDaJwW1cWqnIwIBH+bPJq2kwH69PbDMKU6ts5BBYrs/7FOoa9bbiDOV k10KYs856Tqe6ysq6ma27DlBTZCPur35yWkwikt5XpLhlIYC31YrUkUMexrGQRvNWfbt yhSCo+0WpTaZ/J7VHgfmXRRoaTBIsNXPEQ9wTmdVCMf1SYSv/5ZsVhttu+c6LgORHT91 Ai8Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TRPBhh8h; 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-49218-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49218-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCVQL1brY2P1cnpRXe2hqICxQHJa6l3E112/capuracfWOxElpisKDpAcLmwlk3NXOjVG6jie4izscuDzzsOEcz+uq/WZQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id e10-20020a631e0a000000b005d2014b75b5si911966pge.618.2024.02.01.21.05.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 21:05:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49218-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=TRPBhh8h; 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-49218-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49218-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 82AD5286EDE for ; Fri, 2 Feb 2024 05:02:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 705E2481A0; Fri, 2 Feb 2024 04:57:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="TRPBhh8h" 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 3216A182D4; Fri, 2 Feb 2024 04:57:36 +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=1706849859; cv=none; b=qiflQxr7kNAkOKh+lSr1wtZaO9cOrKxInGD7xDSRYIifYMUJRPoJoHfX2lRvu9l8NTFNXW4DZ15vgaC/LwJlsw7DAlqhs7bQBdw4K1VHsZRDjym/0j4QJCC2SuXhAuyZHW+H371b2sP+1CDg+3fMuCQTBGJycu9CPwON2VUZQg0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706849859; c=relaxed/simple; bh=j7fvY/2gZZFN9ycFck7Q2a4mMpEwf8X0nASlEstU/wQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ijdcj7KlvoyMKgmkXw9RNdv/vG0x9kABH5vZDdSsY+044DdkZFaFMSNAEzDeNr1YzsDSFOKb7oo4RaW3Qe6fyYo6oWqXhWrhB9Ig9BT7JBZqFZP+81k4BsiEd6pie/iWBncyCQ3b7mz97CBOyvKLBa0zNai0K6wcDOegMlel3po= 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=TRPBhh8h; 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=1706849856; x=1738385856; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=j7fvY/2gZZFN9ycFck7Q2a4mMpEwf8X0nASlEstU/wQ=; b=TRPBhh8hVWlGV3pVkqhREqPlwYQoEnaoYL57eSL30nFAo//s+AfSb5Un h6z9VeDM44LX7ct0u7KKB35V0pUjAKojZ6ssRcKzzyYi+0UwSHEf9+OXH WhCds5Fi1nVYQ/o56Tv6CFelvyPH0TWgMgEXVsVBtm21wASFiGmlDE3RQ Wry9JsrCWQDr+yDo69SPJETMGWNZKKgXr95Wm6UbrSizmKA5Nj48xVPk1 kCBG+CYf+oiqNNQ8beymRHW9+9GqAogK44A6lahm3FUrtWga1i1Jn7C+R iyfLIbegFFzLxMEWmv2057ucC43+L+IAo7iIaxY8cySA60GpvqNl/Deso w==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="17615858" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="17615858" 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="912339794" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="912339794" 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 13/17] vfio/pci: Remove vfio_intx_set_signal() Date: Thu, 1 Feb 2024 20:57:07 -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: 1789762301413040748 X-GMAIL-MSGID: 1789762301413040748 The interrupt management flow of vfio_intx_set_signal() is available from the now generic vfio_irq_set_signal(). Initialize the INTx specific management ops so that vfio_irq_set_signal() can be used to manage INTx interrupts and point all existing INTx specific interrupt management calls to vfio_irq_set_signal(). Use vfio_irq_set_block() within vfio_pci_set_intx_trigger() to highlight its similarities with vfio_pci_set_msi_trigger() for the next stage of uniting the interrupt management code. vfio_pci_set_intx_trigger() ensures that start == 0 and count == 1 before vfio_irq_set_block() is called so the loop within it is essentially a direct call to vfio_irq_set_vector_signal(). Signed-off-by: Reinette Chatre --- drivers/vfio/pci/vfio_pci_intrs.c | 62 +++++++------------------------ 1 file changed, 13 insertions(+), 49 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index 7f9dc81cb97f..d7c2cd739d74 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -46,6 +46,10 @@ struct vfio_pci_intr_ops { void (*unregister_producer)(struct vfio_pci_irq_ctx *ctx); }; +static int vfio_irq_set_vector_signal(struct vfio_pci_core_device *vdev, + unsigned int vector, int fd, + unsigned int index); + static bool irq_is(struct vfio_pci_core_device *vdev, int type) { return vdev->irq_type == type; @@ -321,51 +325,6 @@ static char *vfio_intx_device_name(struct vfio_pci_core_device *vdev, return kasprintf(GFP_KERNEL_ACCOUNT, "vfio-intx(%s)", pci_name(pdev)); } -static int vfio_intx_set_signal(struct vfio_pci_core_device *vdev, - unsigned int vector, int fd, - unsigned int index) -{ - struct vfio_pci_irq_ctx *ctx; - struct eventfd_ctx *trigger; - int ret; - - ctx = vfio_irq_ctx_get(vdev, 0); - if (WARN_ON_ONCE(!ctx)) - return -EINVAL; - - if (ctx->trigger) { - vfio_intx_free_interrupt(vdev, ctx, vector); - kfree(ctx->name); - eventfd_ctx_put(ctx->trigger); - ctx->trigger = NULL; - } - - if (fd < 0) /* Disable only */ - return 0; - - ctx->name = vfio_intx_device_name(vdev, vector, index); - if (!ctx->name) - return -ENOMEM; - - trigger = eventfd_ctx_fdget(fd); - if (IS_ERR(trigger)) { - kfree(ctx->name); - return PTR_ERR(trigger); - } - - ctx->trigger = trigger; - - ret = vfio_intx_request_interrupt(vdev, ctx, vector, index); - if (ret) { - ctx->trigger = NULL; - kfree(ctx->name); - eventfd_ctx_put(trigger); - return ret; - } - - return 0; -} - static void vfio_intx_disable(struct vfio_pci_core_device *vdev) { struct vfio_pci_irq_ctx *ctx; @@ -376,7 +335,7 @@ static void vfio_intx_disable(struct vfio_pci_core_device *vdev) vfio_virqfd_disable(&ctx->unmask); vfio_virqfd_disable(&ctx->mask); } - vfio_intx_set_signal(vdev, 0, -1, VFIO_PCI_INTX_IRQ_INDEX); + vfio_irq_set_vector_signal(vdev, 0, -1, VFIO_PCI_INTX_IRQ_INDEX); vdev->irq_type = VFIO_PCI_NUM_IRQS; vfio_irq_ctx_free(vdev, ctx, 0); } @@ -541,6 +500,11 @@ static void vfio_msi_unregister_producer(struct vfio_pci_irq_ctx *ctx) } static struct vfio_pci_intr_ops intr_ops[] = { + [VFIO_PCI_INTX_IRQ_INDEX] = { + .request_interrupt = vfio_intx_request_interrupt, + .free_interrupt = vfio_intx_free_interrupt, + .device_name = vfio_intx_device_name, + }, [VFIO_PCI_MSI_IRQ_INDEX] = { .request_interrupt = vfio_msi_request_interrupt, .free_interrupt = vfio_msi_free_interrupt, @@ -735,17 +699,17 @@ static int vfio_pci_set_intx_trigger(struct vfio_pci_core_device *vdev, return -EINVAL; if (flags & VFIO_IRQ_SET_DATA_EVENTFD) { - int32_t fd = *(int32_t *)data; + int32_t *fds = data; int ret; if (is_intx(vdev)) - return vfio_intx_set_signal(vdev, start, fd, index); + return vfio_irq_set_block(vdev, start, count, fds, index); ret = vfio_intx_enable(vdev); if (ret) return ret; - ret = vfio_intx_set_signal(vdev, start, fd, index); + ret = vfio_irq_set_block(vdev, start, count, fds, index); if (ret) vfio_intx_disable(vdev); From patchwork Fri Feb 2 04:57:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reinette Chatre X-Patchwork-Id: 195575 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp213305dyc; Thu, 1 Feb 2024 21:02:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IFfrKrkbUDbg2zami51GzOT8JCmT2boyFTfhpm8g3dFekWMbU/RIociB1+4M/VqdXF40xUs X-Received: by 2002:a05:622a:1111:b0:42b:f6c1:dc1b with SMTP id e17-20020a05622a111100b0042bf6c1dc1bmr4215195qty.31.1706850148993; Thu, 01 Feb 2024 21:02:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706850148; cv=pass; d=google.com; s=arc-20160816; b=ZfmSzVVOqJaKpV7gya4wrNJcI3Q2JOUbSVnIMQDaElAVClbVFvZyInDuklooOL2vpk wuWCSD8PNb2ajw3TY5By80jttVzaZgQdF9sX3/+oP3ztUdt549LGsDLwjRtXBpDXwipE es3XCe8CNy0YKQhPYnQ7GLt9M0e2Qvd2/gptI9q4IifbwCPV1LKYWymy3Rh+q6TCZfEV N9miW17ooY/em9+IqtOck/pMUyN+IRJk/nuQB0hhUhX98AtN90pDaRR5I9gZLkM4rISE d0+0rsXrd8mhLcH8/ASVv26RJbYoC5MXxn1W/BeH5aSB+clT+InDwKqqjeoBcBo4YeWq 0Img== 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=HrHc2OPdWZscPjBhv9ThK3Pupaea2Q0mpQ7X+3m2QFs=; fh=d7KOHbnfS0agiPTeSMn8IFrhB5j4oKJ94vHXB9Wmn4U=; b=iCXaDQRAmNgp3qZg5sh+X8GtpFznkiH+g6sw5NMfuCO7dwYeq91BxwVFFHDudUe/TQ /H6qp5lyIJ5kwhmMd7AzduPc8Vt0VppJ4vK+1pvzC3Pm0yUgDpPnTBggcGGlN6WQMcJ/ r5Ou+OZKH1Ha9uZCl/VKapkwkKRPpSvYofBhR+AZXj2c2WTfGqMv0+lQMTY/Dk5RbMpa 3M6drsnsKouJqlvBbZH1UeE5XCxg3ybeyWNvRgqTEEFFbmNoVd+cLHwxiYNPIY2zubQv IQpFSfXZXxsbNqwdCliWCuH00z9WDt/qMk9FTamVHUn9hxWQTIIccBkH8CUy8fz4f09m 1+SA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aIaAUh6M; 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-49217-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49217-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCX1LbIpiUGcmm3ZSUSsOq53BBgOSl2W44y7dhw0tWuwnhf+W3P8EIlj6y/gQ600dJrgGhRhVyBDcOnDb2dEVbqeQUMlSQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id b9-20020a05620a126900b00783f4c38a96si1240177qkl.354.2024.02.01.21.02.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 21:02:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49217-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aIaAUh6M; 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-49217-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49217-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id C53281C20E3B for ; Fri, 2 Feb 2024 05:02:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 83FA94436E; Fri, 2 Feb 2024 04:57:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="aIaAUh6M" 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 41EC618624; Fri, 2 Feb 2024 04:57:36 +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=1706849858; cv=none; b=QyCxGrk+fBd6N2pMgNcvi17owKZmtZkU+gnpgYQSZ/Yzm4wh96DDdJAwytS9G6/JYlQZNrBczX8NuDDF/GkZmOgOZeksaIjsfwtV486IMakQmcQ9HzMf3dimo4XFIq5cNoCORQ9qIGxEnlrvVLDLqWxB8rfSbEMIwO0k/PIUmLw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706849858; c=relaxed/simple; bh=QAj3VSDW4vnn+85iNztQ9s3NyXx5nCvtMRrW9/sf7+4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HWkFRrw6VoeB6VWtLHOrEwKDKvZgskeutYlvEovIIHmgMeY1UneSJajkClnMTN8bO0SZexT0PqkOYrU5yx2xYRhN+dYkrcy/9l64fgLy+X74Ec+dox3oBodGO9mfiZOh8MkOrPGU3xVK5sDacWn7JLBLdcNL4ewbLtKwXThUk/U= 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=aIaAUh6M; 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=1706849856; x=1738385856; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QAj3VSDW4vnn+85iNztQ9s3NyXx5nCvtMRrW9/sf7+4=; b=aIaAUh6MXBBKLpWpRk3Va8xm9/sQUBNqoX0OxgOO9TqtbxSC6mJzmZt4 Lg5Grropsi1eCTx4oYLEDYaek4K282UtnbOQxfH+yqs9qFNkm2WoBF+ap s3cRkUFU+hgQasbNe5cqSx4NHFkwNTrW82155OBPzXkdLykwEV3u4uAWv Wqkis985A2AE/rwv1lkRag8drbTlYBBR8rMj6k1BJzPhe7juIALgOzRiQ Yb7W/53py2KEivNlqquzUl8SSwWUnEKshTvljXYM7k/hihIP6YKaw/bRm EOxodCJpfSw3sE0a605iT1qTYDhi4PAhnZ9ihd8YqJdrDwEPNbJPa2dQe Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="17615861" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="17615861" 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="912339798" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="912339798" 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 14/17] vfio/pci: Add utility to trigger INTx eventfd knowing interrupt context Date: Thu, 1 Feb 2024 20:57:08 -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: 1789762101849735675 X-GMAIL-MSGID: 1789762101849735675 vfio_send_intx_eventfd() is available to signal the eventfd associated with the INTx interrupt. It does so by first obtaining the vector's interrupt context and then signaling the eventfd. The interrupt context may already be available before vfio_send_intx_eventfd() is called, making the additional query unnecessary. Introduce vfio_send_intx_eventfd_ctx() that can be used to signal the eventfd associated with the INTx interrupt when the interrupt context is already known and use it instead of vfio_send_intx_eventfd() in the one instance where the interrupt context is already known. Replace usage of vfio_send_intx_eventfd() within vfio_pci_set_intx_trigger() with a new snippet that results in the same functionality while mirroring the flow vfio_pci_set_msi_trigger() as a preparatory step to merge vfio_pci_set_msi_trigger() and vfio_pci_set_intx_trigger(). The new snippet is marked as "temporary" until the flows are merged. Signed-off-by: Reinette Chatre --- drivers/vfio/pci/vfio_pci_intrs.c | 32 ++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index d7c2cd739d74..37065623d286 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -103,6 +103,13 @@ vfio_irq_ctx_alloc(struct vfio_pci_core_device *vdev, unsigned long index) /* * INTx */ +static void vfio_send_intx_eventfd_ctx(struct vfio_pci_core_device *vdev, + struct vfio_pci_irq_ctx *ctx) +{ + if (likely(is_intx(vdev) && !vdev->virq_disabled)) + eventfd_signal(ctx->trigger); +} + static void vfio_send_intx_eventfd(void *opaque, void *unused) { struct vfio_pci_core_device *vdev = opaque; @@ -245,7 +252,7 @@ static irqreturn_t vfio_intx_handler(int irq, void *dev_id) spin_unlock_irqrestore(&vdev->irqlock, flags); if (ret == IRQ_HANDLED) - vfio_send_intx_eventfd(vdev, NULL); + vfio_send_intx_eventfd_ctx(vdev, ctx); return ret; } @@ -690,6 +697,9 @@ static int vfio_pci_set_intx_trigger(struct vfio_pci_core_device *vdev, unsigned int count, uint32_t flags, void *data) { + struct vfio_pci_irq_ctx *ctx; + unsigned int i; + if (is_intx(vdev) && !count && (flags & VFIO_IRQ_SET_DATA_NONE)) { vfio_intx_disable(vdev); return 0; @@ -719,13 +729,21 @@ static int vfio_pci_set_intx_trigger(struct vfio_pci_core_device *vdev, if (!is_intx(vdev)) return -EINVAL; - if (flags & VFIO_IRQ_SET_DATA_NONE) { - vfio_send_intx_eventfd(vdev, NULL); - } else if (flags & VFIO_IRQ_SET_DATA_BOOL) { - uint8_t trigger = *(uint8_t *)data; - if (trigger) - vfio_send_intx_eventfd(vdev, NULL); + /* temporary */ + for (i = start; i < start + count; i++) { + ctx = vfio_irq_ctx_get(vdev, i); + if (!ctx || !ctx->trigger) + continue; + if (flags & VFIO_IRQ_SET_DATA_NONE) { + vfio_send_intx_eventfd_ctx(vdev, ctx); + } else if (flags & VFIO_IRQ_SET_DATA_BOOL) { + uint8_t *bools = data; + + if (bools[i - start]) + vfio_send_intx_eventfd_ctx(vdev, ctx); + } } + return 0; } From patchwork Fri Feb 2 04:57:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reinette Chatre X-Patchwork-Id: 195578 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp214622dyc; Thu, 1 Feb 2024 21:05:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IHLoSOuvKF/Hbnvl+QHyz6Q1nD3ekR3D/eVE3pHiAX/TyAMJpjHUR7RunP+aqHx8XHaIbCL X-Received: by 2002:a05:6a00:1828:b0:6d9:be60:9b93 with SMTP id y40-20020a056a00182800b006d9be609b93mr1718445pfa.12.1706850349044; 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=b4tITt18U1hABWJzfVd5ZYfzJ+YiA/VEWCnFsVTxIH6mW9fp51ENXhNLy2bL/u1Lwa AzDNaqhM3zmWmCeO5Vlxjn8b6N/FXjxOqOcEFkUuNpLEM213d07Hn+ndYtKzW7pEM8Wb 4p7fRxmaeWFeYEAP17Ays7p5T6elhJeNHlFW5JNydQO1EqBWbILP6bh3wOpn2r203Fii IxTsTxbJvWYo9Z3tAcGyUqQzPlPR3MQVy7Sv+2SHW5JLsiLNYnc5TfqzPT/6Iys/NDNE 3BIPlF05a/8XYofEli5hSYvyXSGcAbpig+5twdmTGsq/Rrl8JCteCHV+mfpEdQfAlfNC 3+WA== 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=T76H+abMxRRHTaophuRik9t5fAXAQhESBjCf99FD0dA=; fh=kukBMek97G7SvpioH22KjFRF3VKT7usgUSdtWBHO0dw=; b=YNSWhoAg61YN1KRNikwVAS88mJuW+Sc55FUJmflB5JgbprVbwxBDVQkrqUQZzYU3Qu aYBiBvDfQ4qBsfzC6NPx+WJld4H6XnQxeM+pAIPv9W6a6Ik+1uMAsJPyKE7EKX01IIi3 wduV88g0vtJoKrfR23OANQUPECjJ5ED6R/YWSMxsOhnJ1Mr2MZ7TLPCZr9q3Y7stGA+k TWoz8UwgKsVlZVLZmdQ2r2iSg/FNGzCRGeyVtmHWmcAvithAGWWJa3o7KDLtaXyTXtbM YPbtEAJq4TJM+/rZ13BBcEhZiArMpWvbp6oj2cI5N4DEHwdkOUcLn8BwHi1nK9SP7WAZ MVMg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=T0w3GHBm; 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-49219-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49219-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCXyoN3N8L6XQlHZeXmoMTZMZ6InACVtw8SOjqi+EVugEkd51nwOX+NzYBhgzKKWf8n+CvTyHb3heC86tiUt9adGOvwFig== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id o38-20020a634e66000000b005d8bb714e79si991194pgl.586.2024.02.01.21.05.48 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-49219-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=T0w3GHBm; 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-49219-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49219-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 158542877CC 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 426B3481C7; 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="T0w3GHBm" 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 D1081199C7; Fri, 2 Feb 2024 04:57:37 +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=1706849859; cv=none; b=Txy4UqsYPqzjUiTTEoNnm+YFJy2tvB+YdUOEcvg0UUDZnhEDHDQfnQOjoUeqereswXbqA6MYzZK7CwiUJ5qMw7wfOvRZlbLITI4IZqrHrIzoVrMA3XKGKMrtq+l3CgVYAEK+NpoAI9grxkWzT9D+wPySujsU6xapQPYM9D44xvU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706849859; c=relaxed/simple; bh=UPkU4CgiMaVZ/F/r+r3Za8ed6ay66IJYSHKlYHufPks=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=j2iomrYfDzplSmc79ibCkHiw1dfjY9QyEp1YpIJG6Jjuyiu6FqYzKUWqwYxEyPYpo/r7F7dGrpWhQ41inZB4owRF2ODBwHUMFg3u4NxjBTSsLcs2MxNVYsqHPg7imCMgs26GK6yMvTP/4umfZAOnjY7e7hDHWjJ2Ov8MkukaOl8= 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=T0w3GHBm; 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=UPkU4CgiMaVZ/F/r+r3Za8ed6ay66IJYSHKlYHufPks=; b=T0w3GHBm46+6MvQbdSXdnZ7OTOnlxg64zn0FSGiOt7m67z5m4fO3tKGI E2xD9Os5j2oFs7n6yCQmqyqdtUETeIg3gySlphB8eN5PW8u7bK9rMqFvt NSeUKzcd8Nk+kDVjFUYEJ/f1I13tkMECHftAcII/6kVwa08dR4t0A7T9/ BovkDpAW3t4yyHLEnthfAmhj2GDSWgsWo6NWq/xFaXv7nOIxzSgoENc8v OyZErmmUuux8BSqbgxvaqlDAEFFTD4LXvNf3hMjDShpAbOWytnIlSDEPN 9qINJYIK+PZi0H63NNZF7igfNkMZ6Lu7SIkWjTk1xRqgXEm0bTZrvm22a g==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="17615868" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="17615868" 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="912339801" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="912339801" 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 15/17] vfio/pci: Let enable and disable of interrupt types use same signature Date: Thu, 1 Feb 2024 20:57:09 -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: 1789762311098331206 X-GMAIL-MSGID: 1789762311098331206 vfio_pci_set_intx_trigger() and vfio_pci_set_msi_trigger() have flows that can be shared. For INTx, MSI, and MSI-X interrupt management to share the same enable/disable flow the interrupt specific enable and disable functions should have the same signatures. Let vfio_intx_enable() and vfio_msi_enable() use the same parameters by passing "start" and "count" to these functions instead of letting the (what will eventually be) common code interpret these values. Providing "start" and "count" to vfio_intx_enable() enables the INTx specific check of these parameters to move into the INTx specific vfio_intx_enable(). Similarly, providing "start" and "count" to vfio_msi_enable() enables the MSI/MSI-X specific code to initialize number of vectors needed. The shared MSI/MSI-X code needs the interrupt index. Provide the interrupt index (clearly marked as unused) to the INTx code to use the same signatures. With interrupt type specific code using the same parameters it is possible to have common code that calls the enable/disable code for different interrupt types. Signed-off-by: Reinette Chatre --- drivers/vfio/pci/vfio_pci_intrs.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index 37065623d286..9217fea3f636 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -257,13 +257,18 @@ static irqreturn_t vfio_intx_handler(int irq, void *dev_id) return ret; } -static int vfio_intx_enable(struct vfio_pci_core_device *vdev) +static int vfio_intx_enable(struct vfio_pci_core_device *vdev, + unsigned int start, unsigned int count, + unsigned int __always_unused index) { struct vfio_pci_irq_ctx *ctx; if (!is_irq_none(vdev)) return -EINVAL; + if (start != 0 || count != 1) + return -EINVAL; + if (!vdev->pdev->irq) return -ENODEV; @@ -332,7 +337,8 @@ static char *vfio_intx_device_name(struct vfio_pci_core_device *vdev, return kasprintf(GFP_KERNEL_ACCOUNT, "vfio-intx(%s)", pci_name(pdev)); } -static void vfio_intx_disable(struct vfio_pci_core_device *vdev) +static void vfio_intx_disable(struct vfio_pci_core_device *vdev, + unsigned int __always_unused index) { struct vfio_pci_irq_ctx *ctx; @@ -358,17 +364,20 @@ static irqreturn_t vfio_msihandler(int irq, void *arg) return IRQ_HANDLED; } -static int vfio_msi_enable(struct vfio_pci_core_device *vdev, int nvec, +static int vfio_msi_enable(struct vfio_pci_core_device *vdev, + unsigned int start, unsigned int count, unsigned int index) { struct pci_dev *pdev = vdev->pdev; unsigned int flag; - int ret; + int ret, nvec; u16 cmd; if (!is_irq_none(vdev)) return -EINVAL; + nvec = start + count; + flag = (index == VFIO_PCI_MSIX_IRQ_INDEX) ? PCI_IRQ_MSIX : PCI_IRQ_MSI; /* return the number of supported vectors if we can't get all: */ @@ -701,11 +710,11 @@ static int vfio_pci_set_intx_trigger(struct vfio_pci_core_device *vdev, unsigned int i; if (is_intx(vdev) && !count && (flags & VFIO_IRQ_SET_DATA_NONE)) { - vfio_intx_disable(vdev); + vfio_intx_disable(vdev, index); return 0; } - if (!(is_intx(vdev) || is_irq_none(vdev)) || start != 0 || count != 1) + if (!(is_intx(vdev) || is_irq_none(vdev))) return -EINVAL; if (flags & VFIO_IRQ_SET_DATA_EVENTFD) { @@ -715,13 +724,13 @@ static int vfio_pci_set_intx_trigger(struct vfio_pci_core_device *vdev, if (is_intx(vdev)) return vfio_irq_set_block(vdev, start, count, fds, index); - ret = vfio_intx_enable(vdev); + ret = vfio_intx_enable(vdev, start, count, index); if (ret) return ret; ret = vfio_irq_set_block(vdev, start, count, fds, index); if (ret) - vfio_intx_disable(vdev); + vfio_intx_disable(vdev, index); return ret; } @@ -771,7 +780,7 @@ static int vfio_pci_set_msi_trigger(struct vfio_pci_core_device *vdev, return vfio_irq_set_block(vdev, start, count, fds, index); - ret = vfio_msi_enable(vdev, start + count, index); + ret = vfio_msi_enable(vdev, start, count, index); if (ret) return ret; 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 */ From patchwork Fri Feb 2 04:57:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reinette Chatre X-Patchwork-Id: 195576 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp213620dyc; Thu, 1 Feb 2024 21:03:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IHCaZ6Gp3uIGJ4w6tEo5f2fbf/2IT80p+7BkwH6NNGeMov/k9Hfnv3tjUgeU6ksRwpUQ0Rk X-Received: by 2002:a05:6102:952:b0:46d:1a3:cdf7 with SMTP id a18-20020a056102095200b0046d01a3cdf7mr500038vsi.26.1706850186089; Thu, 01 Feb 2024 21:03:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706850186; cv=pass; d=google.com; s=arc-20160816; b=aINFl4zNxpTGkmzV+gc/WRczjLIgwNaRYLkpWm407rLVGWFWjGmRAJl8bhym7A1Qgr kx213xGE6zWVJ7y9fB3aDoc6QtZcvUd2LZH5kYZ1c+ns5W/7iRlL04sBo9wE825hPmL5 R+8xPL65qQBFj7ehqMR1kHuQ3TfYO34sz0cqWx1DDWHawisdr6IZNHXsAgHhqidpC4Sp wJ6myvRw1yjX8yn82dLbY+Bl/aGTv3M+L4Dcb5Z6z/NAWp2KUkuXjViEyZoSCo2htb1L xKlHIXIgaT7URl20l1D9+tiAj/Guvma9fvghAVS58/EKxrJybbbD9N3palUaPfAqlNuP hXWw== 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=03Dl+XifFsmG0byQGql7AzarJVwqGM/v6VLGLwWQ/gc=; fh=lDND0oHUirSzhWjZGeFVmyHr7ghF6iqL0nZHJflYpKc=; b=EChpAh5P7c9WoWyDX/+8R15V/839KJAmkiVk1a+L7iihf2k8nua1xQVlhjfwnLpXgh yBuvxSbghk9KBVpFQRW4C3ePd8BzobeQl1SzFTDvTyJHd7WWuj2bvp/IaD8bkf1C23jR X16BIR8YPojRmMZHZO7pur9RGFD++EpuOgBEkYUDOzD7hN+SNKfjOBnVbVbJAX6/3PDD 7xLbkjxG1MikcFJr3c9CqAm/SwwbMTtDFhTy26PPWCijGN98nzBmYdGH392E3Gfik2Sa pSmcPjxayfLkj80AURzluicp8gKEYhoY/w4Zvk7ByIxgqkt69z40CgqMiXWrzD0tca2R LMBQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Iy8CILgn; 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-49221-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49221-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCWzVeflXr+mG9W6Hr7pNq1DxUVvT1W6O1Ra3osyy+dYvR0n4Z1Shywg2703NV5/f+Yt8ZITtplFfXK4cGWou7qZd1btMQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j2-20020a0ceb02000000b0068c46c2ed43si1193789qvp.16.2024.02.01.21.03.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 21:03:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49221-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Iy8CILgn; 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-49221-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49221-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id CD8C51C24654 for ; Fri, 2 Feb 2024 05:03:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A9314482D1; Fri, 2 Feb 2024 04:57:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Iy8CILgn" 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 23F3A1B299; Fri, 2 Feb 2024 04:57:39 +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=1706849861; cv=none; b=cjYuL2NXN0qPIelN2C6Exxuk/ucP7aBFfjLnw608uYhCQTdWsz2ihTNQJi3y4CI7Un/6YndIW3ZtEBGsbdME+a8JziSIX9Xyd67Xs0v++a08/GWN2Zm3t9+fsgMji32F419Hn4w0V40+fTtwr9twngkt1q3gHpzoDYA86cnhqgo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706849861; c=relaxed/simple; bh=4QFGx+82iSOQD5Uy7w9iqIN8hz1HoOJM57vM7BEXPkc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oT/Ddg0Npb6DrhmZQqZVy/tuC3nvM9Sua9qjQxh9FiskNKVkhhf8vXqhcd7VjOVcXbnjwLThNmuklNM5s+3QdJBGE4+8wIvHmku/tlbJgo0KlJhPLjJFQoZMGdIfVXkPP8yze15lozziz1OIgFkKWKW2SpiH3XbHGXZmY2gaHG4= 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=Iy8CILgn; 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=1706849859; x=1738385859; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4QFGx+82iSOQD5Uy7w9iqIN8hz1HoOJM57vM7BEXPkc=; b=Iy8CILgnJZ1cQcQ52vjAEEuKGn3rwbhWJG2pc9idgTpLbkNBO9K29kZG 4V89/Lf3zUJKw5XZMOLAdyWv1SsPOefjHKwt7Sz0RdatupE2N/eciA7Bz ktJqopQUd0HGNneZVM2fDOEhMCsIRlmnKoCRS74MA8VTfzwcgVPbCNnRu jYvZJZJSiYstvG0mkzrIr8k7WUXgmdUJTe0pl1qop3+P+rbnjJivsg+9E dWsZVne9+65x/PbTl/WZtIjt5u7yQog5Za4iwoIV4jNkb7aQ/7AVo+Chy KyZCDsa1+xx8T+elmMN0JOLxpnu/AZiMqAXNwzPbX1upNwaocDdSoCf7u g==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="17615872" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="17615872" 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="912339806" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="912339806" 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 17/17] vfio/pci: Remove duplicate interrupt management flow Date: Thu, 1 Feb 2024 20:57:11 -0800 Message-Id: <6ec901daffab4170d9740c7d066becd079925d53.1706849424.git.reinette.chatre@intel.com> 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: 1789762140650919488 X-GMAIL-MSGID: 1789762140650919488 vfio_pci_set_intx_trigger() and vfio_pci_set_trigger() have the same flow that calls interrupt type (INTx, MSI, MSI-X) specific functions. Create callbacks for the interrupt type specific code that can be called by the shared code so that only one of these functions are needed. Rename the final generic function shared by all interrupt types vfio_pci_set_trigger(). Relocate the "IOCTL support" marker to correctly mark the now generic code. Signed-off-by: Reinette Chatre --- drivers/vfio/pci/vfio_pci_intrs.c | 104 ++++++++++-------------------- 1 file changed, 35 insertions(+), 69 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index daa84a317f40..a5b337cfae60 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -32,6 +32,12 @@ struct vfio_pci_irq_ctx { }; struct vfio_pci_intr_ops { + int (*enable)(struct vfio_pci_core_device *vdev, unsigned int start, + unsigned int count, unsigned int index); + void (*disable)(struct vfio_pci_core_device *vdev, + unsigned int index); + void (*send_eventfd)(struct vfio_pci_core_device *vdev, + struct vfio_pci_irq_ctx *ctx); int (*request_interrupt)(struct vfio_pci_core_device *vdev, struct vfio_pci_irq_ctx *ctx, unsigned int vector, unsigned int index); @@ -356,6 +362,12 @@ static void vfio_intx_disable(struct vfio_pci_core_device *vdev, /* * MSI/MSI-X */ +static void vfio_send_msi_eventfd(struct vfio_pci_core_device *vdev, + struct vfio_pci_irq_ctx *ctx) +{ + eventfd_signal(ctx->trigger); +} + static irqreturn_t vfio_msihandler(int irq, void *arg) { struct eventfd_ctx *trigger = arg; @@ -544,13 +556,22 @@ static void vfio_msi_unregister_producer(struct vfio_pci_irq_ctx *ctx) irq_bypass_unregister_producer(&ctx->producer); } +/* + * IOCTL support + */ static struct vfio_pci_intr_ops intr_ops[] = { [VFIO_PCI_INTX_IRQ_INDEX] = { + .enable = vfio_intx_enable, + .disable = vfio_intx_disable, + .send_eventfd = vfio_send_intx_eventfd_ctx, .request_interrupt = vfio_intx_request_interrupt, .free_interrupt = vfio_intx_free_interrupt, .device_name = vfio_intx_device_name, }, [VFIO_PCI_MSI_IRQ_INDEX] = { + .enable = vfio_msi_enable, + .disable = vfio_msi_disable, + .send_eventfd = vfio_send_msi_eventfd, .request_interrupt = vfio_msi_request_interrupt, .free_interrupt = vfio_msi_free_interrupt, .device_name = vfio_msi_device_name, @@ -558,6 +579,9 @@ static struct vfio_pci_intr_ops intr_ops[] = { .unregister_producer = vfio_msi_unregister_producer, }, [VFIO_PCI_MSIX_IRQ_INDEX] = { + .enable = vfio_msi_enable, + .disable = vfio_msi_disable, + .send_eventfd = vfio_send_msi_eventfd, .request_interrupt = vfio_msi_request_interrupt, .free_interrupt = vfio_msi_free_interrupt, .device_name = vfio_msi_device_name, @@ -646,9 +670,6 @@ static int vfio_irq_set_block(struct vfio_pci_core_device *vdev, return ret; } -/* - * IOCTL support - */ static int vfio_pci_set_intx_unmask(struct vfio_pci_core_device *vdev, unsigned int index, unsigned int start, unsigned int count, uint32_t flags, @@ -701,71 +722,16 @@ static int vfio_pci_set_intx_mask(struct vfio_pci_core_device *vdev, return 0; } -static int vfio_pci_set_intx_trigger(struct vfio_pci_core_device *vdev, - unsigned int index, unsigned int start, - unsigned int count, uint32_t flags, - void *data) -{ - struct vfio_pci_irq_ctx *ctx; - unsigned int i; - - if (is_intx(vdev) && !count && (flags & VFIO_IRQ_SET_DATA_NONE)) { - vfio_intx_disable(vdev, index); - return 0; - } - - if (!(is_intx(vdev) || is_irq_none(vdev))) - return -EINVAL; - - if (flags & VFIO_IRQ_SET_DATA_EVENTFD) { - int32_t *fds = data; - int ret; - - if (is_intx(vdev)) - return vfio_irq_set_block(vdev, start, count, fds, index); - - ret = vfio_intx_enable(vdev, start, count, index); - if (ret) - return ret; - - ret = vfio_irq_set_block(vdev, start, count, fds, index); - if (ret) - vfio_intx_disable(vdev, index); - - return ret; - } - - if (!is_intx(vdev)) - return -EINVAL; - - /* temporary */ - for (i = start; i < start + count; i++) { - ctx = vfio_irq_ctx_get(vdev, i); - if (!ctx || !ctx->trigger) - continue; - if (flags & VFIO_IRQ_SET_DATA_NONE) { - vfio_send_intx_eventfd_ctx(vdev, ctx); - } else if (flags & VFIO_IRQ_SET_DATA_BOOL) { - uint8_t *bools = data; - - if (bools[i - start]) - vfio_send_intx_eventfd_ctx(vdev, ctx); - } - } - - return 0; -} - -static int vfio_pci_set_msi_trigger(struct vfio_pci_core_device *vdev, - unsigned int index, unsigned int start, - unsigned int count, uint32_t flags, - void *data) +static int vfio_pci_set_trigger(struct vfio_pci_core_device *vdev, + unsigned int index, unsigned int start, + unsigned int count, uint32_t flags, + void *data) { struct vfio_pci_irq_ctx *ctx; unsigned int i; if (irq_is(vdev, index) && !count && (flags & VFIO_IRQ_SET_DATA_NONE)) { - vfio_msi_disable(vdev, index); + intr_ops[index].disable(vdev, index); return 0; } @@ -780,13 +746,13 @@ static int vfio_pci_set_msi_trigger(struct vfio_pci_core_device *vdev, return vfio_irq_set_block(vdev, start, count, fds, index); - ret = vfio_msi_enable(vdev, start, count, index); + ret = intr_ops[index].enable(vdev, start, count, index); if (ret) return ret; ret = vfio_irq_set_block(vdev, start, count, fds, index); if (ret) - vfio_msi_disable(vdev, index); + intr_ops[index].disable(vdev, index); return ret; } @@ -799,11 +765,11 @@ static int vfio_pci_set_msi_trigger(struct vfio_pci_core_device *vdev, if (!ctx || !ctx->trigger) continue; if (flags & VFIO_IRQ_SET_DATA_NONE) { - eventfd_signal(ctx->trigger); + intr_ops[index].send_eventfd(vdev, ctx); } else if (flags & VFIO_IRQ_SET_DATA_BOOL) { uint8_t *bools = data; if (bools[i - start]) - eventfd_signal(ctx->trigger); + intr_ops[index].send_eventfd(vdev, ctx); } } return 0; @@ -912,7 +878,7 @@ int vfio_pci_set_irqs_ioctl(struct vfio_pci_core_device *vdev, uint32_t flags, func = vfio_pci_set_intx_unmask; break; case VFIO_IRQ_SET_ACTION_TRIGGER: - func = vfio_pci_set_intx_trigger; + func = vfio_pci_set_trigger; break; } break; @@ -924,7 +890,7 @@ int vfio_pci_set_irqs_ioctl(struct vfio_pci_core_device *vdev, uint32_t flags, /* XXX Need masking support exported */ break; case VFIO_IRQ_SET_ACTION_TRIGGER: - func = vfio_pci_set_msi_trigger; + func = vfio_pci_set_trigger; break; } break;