Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Reinette Chatre <reinette.chatre@intel.com>
Cc: jgg@nvidia.com, yishaih@nvidia.com,
	shameerali.kolothum.thodi@huawei.com, kevin.tian@intel.com,
	kvm@vger.kernel.org, dave.jiang@intel.com, ashok.raj@intel.com,
	linux-kernel@vger.kernel.org, patches@lists.linux.dev
Subject: Re: [PATCH 07/17] vfio/pci: Preserve per-interrupt contexts
Date: Mon, 5 Feb 2024 15:35:09 -0700	[thread overview]
Message-ID: <20240205153509.333c2c95.alex.williamson@redhat.com> (raw)
In-Reply-To: <d6e32e0e7adaf61da39fb6cd2863298b15a2663e.1706849424.git.reinette.chatre@intel.com>

On Thu,  1 Feb 2024 20:57:01 -0800
Reinette Chatre <reinette.chatre@intel.com> wrote:

> 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 <reinette.chatre@intel.com>
> ---
> 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;

Setting ctx->name = NULL is not strictly necessary and does not match
the INTx code that we're claiming to try to emulate.  ctx->name is only
tested immediately after allocation below, otherwise it can be inferred
from ctx->trigger.  Thanks,

Alex

>  		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);


  reply	other threads:[~2024-02-05 22:36 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-02  4:56 [PATCH 00/17] vfio/pci: Remove duplicate code and logic from VFIO PCI interrupt management Reinette Chatre
2024-02-02  4:56 ` [PATCH 01/17] vfio/pci: Use unsigned int instead of unsigned Reinette Chatre
2024-02-02  4:56 ` [PATCH 02/17] vfio/pci: Remove duplicate check from vfio_pci_set_ctx_trigger_single() wrappers Reinette Chatre
2024-02-02  4:56 ` [PATCH 03/17] vfio/pci: Consistently acquire mutex for interrupt management Reinette Chatre
2024-02-05 22:34   ` Alex Williamson
2024-02-06 21:44     ` Reinette Chatre
2024-02-02  4:56 ` [PATCH 04/17] vfio/pci: Remove duplicate interrupt management from core VFIO PCI Reinette Chatre
2024-02-02  4:56 ` [PATCH 05/17] vfio/pci: Limit eventfd signaling to interrupt management code Reinette Chatre
2024-02-02  4:57 ` [PATCH 06/17] vfio/pci: Remove interrupt index interpretation from wrappers Reinette Chatre
2024-02-05 22:35   ` Alex Williamson
2024-02-06 21:44     ` Reinette Chatre
2024-02-02  4:57 ` [PATCH 07/17] vfio/pci: Preserve per-interrupt contexts Reinette Chatre
2024-02-05 22:35   ` Alex Williamson [this message]
2024-02-06 21:45     ` Reinette Chatre
2024-02-06 22:03       ` Alex Williamson
2024-02-06 22:21         ` Reinette Chatre
2024-02-02  4:57 ` [PATCH 08/17] vfio/pci: Extract MSI/MSI-X specific code from common flow Reinette Chatre
2024-02-02  4:57 ` [PATCH 09/17] vfio/pci: Converge similar code flows Reinette Chatre
2024-02-02  4:57 ` [PATCH 10/17] vfio/pci: Extract INTx specific code from vfio_intx_set_signal() Reinette Chatre
2024-02-02  4:57 ` [PATCH 11/17] vfio/pci: Perform MSI/MSI-X interrupt management via callbacks Reinette Chatre
2024-02-02  4:57 ` [PATCH 12/17] vfio/pci: Remove msi term from generic code Reinette Chatre
2024-02-05 22:35   ` Alex Williamson
2024-02-06 21:45     ` Reinette Chatre
2024-02-02  4:57 ` [PATCH 13/17] vfio/pci: Remove vfio_intx_set_signal() Reinette Chatre
2024-02-02  4:57 ` [PATCH 14/17] vfio/pci: Add utility to trigger INTx eventfd knowing interrupt context Reinette Chatre
2024-02-02  4:57 ` [PATCH 15/17] vfio/pci: Let enable and disable of interrupt types use same signature Reinette Chatre
2024-02-05 22:35   ` Alex Williamson
2024-02-06 21:46     ` Reinette Chatre
2024-02-06 22:03       ` Alex Williamson
2024-02-06 22:22         ` Reinette Chatre
2024-02-06 23:19           ` Alex Williamson
2024-02-07 23:30             ` Reinette Chatre
2024-02-08 21:08               ` Alex Williamson
2024-02-14 19:37                 ` Reinette Chatre
2024-02-02  4:57 ` [PATCH 16/17] vfio/pci: Move vfio_msi_disable() to be with other MSI/MSI-X management code Reinette Chatre
2024-02-02  4:57 ` [PATCH 17/17] vfio/pci: Remove duplicate interrupt management flow Reinette Chatre
2024-02-05 22:35   ` Alex Williamson
2024-02-06 21:46     ` Reinette Chatre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240205153509.333c2c95.alex.williamson@redhat.com \
    --to=alex.williamson@redhat.com \
    --cc=ashok.raj@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=jgg@nvidia.com \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=reinette.chatre@intel.com \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=yishaih@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox