From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19E522DB7B7 for ; Sun, 22 Mar 2026 09:59:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774173562; cv=none; b=I2e1tJFmHJ2uknz0DGYGV3Nn5Hrn5oLpljqDrQQnH4pXmGu3WJLljvZaLM9UkHtG+hHRBVndhYOwbljyK0M9+6EJ31cEAXEs5Km9GGVM3pQRqZylHXeFWPZeWV82NYyatj2ztEjDYmCiKDmdw6tSsPZzNRx17iAysUx8KaPrz7U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774173562; c=relaxed/simple; bh=fzAhID9+olF/3pw6JanjWFFA8h7Hu/gKkT4lYi0XRUE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tJRSaATc7h8yBCwkQATZIECH0kZTWl3iI1+kRDiXFiEwwEecZerbcUJr3HVR/FGQuBIk6Hnq8pHV9j+Y1i/5C9IqWig/AsU8vPj+Fvu23Yc6B4lTO1b0A2PfoCTcwAS+k2vNXS9JAP9nhC8eIjTKXcc2gOWwWG5uRDGYV2TNmd8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=vSMJ9dyH; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vSMJ9dyH" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-48569636800so83575e9.0 for ; Sun, 22 Mar 2026 02:59:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774173559; x=1774778359; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=L8UfK3idjeSnXM54b42BvUpeoVLCS0bpqH6oHgrA4JU=; b=vSMJ9dyHY+B4/k60iUrzqwLA9L+YAVTHOIe1ShAhau1j5jKqQDJtLRYrfVTlhPk/f1 OT1qimLuBRvUUTV6ojlQSsVW/hgPs/egmVdjg7oA0VXgXz5VIS5par4e8aUFnmDAqMn9 D8zHREel4+/KYLN1ZBJN9Um65li/YiTXY/VO/u0MV3lsvSeNP+Yr+6LpdiUE6u9IvIv9 Q+/SmD6gqVGlsxvpDjEKQ8aeRyglcTNFGo7RT5NiJUSHtTNodDec+TyVQ+NCfO4caWl3 nVCA/WfwTuVL9vzjjBcGnxrLBRokvm50yv6aNUayvwjYLSTROhZQd3Jn1IvvlIUyGTai zkJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774173559; x=1774778359; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=L8UfK3idjeSnXM54b42BvUpeoVLCS0bpqH6oHgrA4JU=; b=AGUS7OcZ8MOy+Dk6a5LlM+xK0ThQoeaeprT3w+Sh50cGSgyUYFy6mGdBylPfvgu81u 4m241nKa4/T2XtUjrBeYfP2eEYMcuKuXB4NZgKc9h002uWjK7u0LtQ6WbWafzOd23+Zo DEsUok1VVZHuDWBOBd+tT4qMEOg9jTbbzbAF3O0oGi52Drb1H98IlBu1Tmkv8W+BG5Pj U7YrqEZCiW2o2pBtGEZWZelnI9YeMLoo5/n94hx9OUPuMIGdZhyjK9uUF3VMwIXiSyQD HZ0F8WW1szHBp+WpXzNP0Pr02EbQSkOCyLfY+dbnE0fA9zgRmI4Wg9Ek8QVqzfy9/Rq6 fRJw== X-Gm-Message-State: AOJu0Yyfz2XH/DtMpRqBg/aUajbnCPoacL25DBtu5AM4b3TPy26kO04w eJTUdjVuMAu2B5+VD0zvtTZyZgNbBq3b/kc7JbPcdTKKGO5FM6Igm4APBA/qbeJjYw== X-Gm-Gg: ATEYQzxxxxqtwHsxG3yj4SLiT7pSDfA/PkUY+Ccd6U2GhFGDWbo3ziGcLHoalSXr4pY YHXLmP6ATNHsiHi7FgLX2n4mmZ2WyEbAIHJo25v5mEQyJLwKg3C6gVnRw8IVvj+rvQZAPKrDiiH 4tLzlOuBmDdWhRtCrLRJIhhWy6x5LGvAgmilo2vGP6s+pUmsVAhHl1HTVhm6Gs3U2Rn82wot1rc xJCHO3HJkUkATpB+PQzEh5n/0bcajIfuxImT1FfjARrMBpFus0sjUM6py8nlMPieb/qAcZjKU96 GBlFgK28vXjy7WzfHxUIbmCv8sUFVVptGYoqhNhX/bXdj/ft6gziikkRzKHoupxL4svSntej/Cj D/FzCFYGft9XTh8A/4X8/soZ6CDQ+45UHrphZGTyeKUi7OwdpSbW8YflGj3D26cjjuqetgzTwyM uHnHzb49GeeI0gglCkg8bB7EbkTRoSv/r9jOqEnY0ewb93STsEf9mbWM73 X-Received: by 2002:a05:600c:8b61:b0:483:6a76:11a6 with SMTP id 5b1f17b1804b1-487037efce5mr1409085e9.5.1774173559118; Sun, 22 Mar 2026 02:59:19 -0700 (PDT) Received: from google.com (54.95.38.34.bc.googleusercontent.com. [34.38.95.54]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43b647120a1sm21082830f8f.30.2026.03.22.02.59.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Mar 2026 02:59:18 -0700 (PDT) Date: Sun, 22 Mar 2026 09:59:15 +0000 From: Mostafa Saleh To: Jacob Pan Cc: linux-kernel@vger.kernel.org, "iommu@lists.linux.dev" , Jason Gunthorpe , Alex Williamson , Joerg Roedel , David Matlack , Robin Murphy , Nicolin Chen , "Tian, Kevin" , Yi Liu , skhawaja@google.com, pasha.tatashin@soleen.com, Will Deacon , Baolu Lu Subject: Re: [PATCH V2 05/11] vfio: Allow null group for noiommu without containers Message-ID: References: <20260312155637.376854-1-jacob.pan@linux.microsoft.com> <20260312155637.376854-6-jacob.pan@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260312155637.376854-6-jacob.pan@linux.microsoft.com> On Thu, Mar 12, 2026 at 08:56:31AM -0700, Jacob Pan wrote: > In case of noiommu mode is enabled for VFIO cdev without VFIO container > nor IOMMUFD provided compatibility container, there is no need to > create a dummy group. Update the group operations to tolerate null group > pointer. > > Signed-off-by: Jacob Pan > --- > drivers/vfio/group.c | 14 ++++++++++++++ > drivers/vfio/vfio.h | 17 +++++++++++++++++ > 2 files changed, 31 insertions(+) > > diff --git a/drivers/vfio/group.c b/drivers/vfio/group.c > index 4f15016d2a5f..98f2a4f2ebff 100644 > --- a/drivers/vfio/group.c > +++ b/drivers/vfio/group.c > @@ -381,6 +381,9 @@ int vfio_device_block_group(struct vfio_device *device) > struct vfio_group *group = device->group; > int ret = 0; > > + if (vfio_null_group_allowed() && !group) > + return 0; > + > mutex_lock(&group->group_lock); > if (group->opened_file) { > ret = -EBUSY; > @@ -398,6 +401,9 @@ void vfio_device_unblock_group(struct vfio_device *device) > { > struct vfio_group *group = device->group; > > + if (vfio_null_group_allowed() && !group) > + return; > + > mutex_lock(&group->group_lock); > group->cdev_device_open_cnt--; > mutex_unlock(&group->group_lock); > @@ -589,6 +595,14 @@ static struct vfio_group *vfio_noiommu_group_alloc(struct device *dev, > struct vfio_group *group; > int ret; > > + /* > + * With noiommu enabled under cdev interface only, there is no need to > + * create a vfio_group if the group based containers are not enabled. > + * The cdev interface is exclusively used for iommufd. > + */ > + if (vfio_null_group_allowed()) > + return NULL; > + Now vfio_device_set_group() can return NULL when called from __vfio_register_dev() where the error path calls vfio_device_remove_group() which I believe would break. But is that really needed, I feel like this optimization is not worth the extra effort to add those checks and the possiblity of missing some. what do you think? Thanks, Mostafa > iommu_group = iommu_group_alloc(); > if (IS_ERR(iommu_group)) > return ERR_CAST(iommu_group); > diff --git a/drivers/vfio/vfio.h b/drivers/vfio/vfio.h > index 50128da18bca..838c08077ce2 100644 > --- a/drivers/vfio/vfio.h > +++ b/drivers/vfio/vfio.h > @@ -113,6 +113,18 @@ bool vfio_device_has_container(struct vfio_device *device); > int __init vfio_group_init(void); > void vfio_group_cleanup(void); > > +/* > + * With noiommu enabled and no containers are supported, allow devices that > + * don't have a dummy group. > + */ > +static inline bool vfio_null_group_allowed(void) > +{ > + if (vfio_noiommu && (!IS_ENABLED(CONFIG_VFIO_CONTAINER) && !IS_ENABLED(CONFIG_IOMMUFD_VFIO_CONTAINER))) > + return true; > + > + return false; > +} > + > static inline bool vfio_device_is_noiommu(struct vfio_device *vdev) > { > return IS_ENABLED(CONFIG_VFIO_NOIOMMU) && > @@ -189,6 +201,11 @@ static inline void vfio_group_cleanup(void) > { > } > > +static inline bool vfio_null_group_allowed(void) > +{ > + return false; > +} > + > static inline bool vfio_device_is_noiommu(struct vfio_device *vdev) > { > return false; > -- > 2.34.1 >