From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 897D721D00A for ; Sun, 22 Mar 2026 10:02:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774173734; cv=none; b=E+J9aZGzZcgzF9B3jYaEPtIHQxqfma+/bc/dS2fjvcMVmqTtTkvzK4cu8cxTCQ+yaisS6+IDIn9eFL9RlukJyCglBZwrmrtvRGbu/WcniAROK3NQ/STAnNtMiAiDTDS7nC7WmDh7+Tfz/CwyLPHugKp4eKBe9Gnrlf4CSegjJSc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774173734; c=relaxed/simple; bh=MPdvlYF+iWz1K8Rhtff35P9jt2NBVcoETnQ/FL6EmYE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=j8zUa6Os/XZzqZwK00YQELCP55aF51o5kSPoSx+mq/MxWUQDOXGHZX7AGX59u+ARzldmfVkfu2v9KzPjOtQO4R2eKKSEusUJ/r2iafYWr0ZXv/3I+0fBebRW49CJopx+wwd1bEQOREDI9UwV8/b1ZI3b7zaURlP+BysKn/T+jLY= 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=bGSDnD9o; arc=none smtp.client-ip=209.85.128.46 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="bGSDnD9o" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4852ef20fe8so74995e9.1 for ; Sun, 22 Mar 2026 03:02:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774173732; x=1774778532; 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=I//2qfZnYblxfMX6zr8r1FNilN8mRILbWlr2/H3rAfI=; b=bGSDnD9oTW01iBnlwMhCga7hve5AEmJ3in/IO65N7cNscD27oTioO+j9/cSmzc0DaA Su1Qd+bXIR05dbjyI/CVaLeX+xJaJfqBTin8Wiq1QAv19sAN3pudRGYcE3PWqukTW1ud tQvzy1JoXRwCZ81WCim5PW/v+/WC/iN8FQ065tef7C8VIqlEhyRbnRNj8osY1PPGW2fH VYH25eb6/QCy9ITVTsMXTIbK6cXsJglDnTLrjq4MZNtlHYbUEW8x6vNnnyKduyI0zCO2 ppYQD3EdSfAWHeFC6QPzI6h86C07qjF1iVktmT/aBkx/dBwmNlyg79t01YX6oeW6aOJ7 y3eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774173732; x=1774778532; 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=I//2qfZnYblxfMX6zr8r1FNilN8mRILbWlr2/H3rAfI=; b=BBe03shh/VHaYTDg9zgm7WYOXthdB5cYNgBZkp861gBNpaqbpO16NrWCdYrdJXv+C6 071XUyC09Fhl/JneJhiNVJJbn0dJNHpmCg6GOjgdFIsr1YkgIbpt6irW3ZSrBHWKz2St 4ZR8aVcl+Dji4PjBJ8ft0EeUl2mYTqNcm7UaRR5jlXP+0NauF3BEiKtOIIhkoL5V77He ohuiaHWJTVgEvL3wNJdZkPl6iKSMmGjw80BTGbx4RO9grnwTgWyxxD4KoSiDkB2FCCVG 16ANIYz9zbLhrnr2p9DtSMyirCWwoBYbJPuyjFM+bWbKKGTTuREYeRu/9hmcPYcispvb ExEg== X-Gm-Message-State: AOJu0YzSZl5YQ9A3vGDJ1nngpMmQGxDySjQNyWNFbEx+fL0PZghqvtSj h4s/r32sgO/GLK4N4RUOZFl6nQlBnvjKAI8OspcC6IGEaXhHPzdVyHYOMPEWuxjX+A== X-Gm-Gg: ATEYQzws8tITxqugM2eTzYtXRaYbv4zC94bfnMkqT4CqynPr54z9e59CVc59VXtmXNM VzQVRLqAEghxXhKDLPRgoJEm/LMPLPRRXw2nbuXdpWl13ujFpmV5ois9NGPcf+jplbC9RSH729e 5c9Ltm+Hetz6bw09taGUJftDo7ITI9WDGgG98xbkEfwISharxMPx0FBMZGAhVBfi+uDeOp/VPCU N22h5KdQF8/HRuhSmtPFsP/AdhV6hJdBnEL9s3/DlQTU6vK5qCqxN+VwPP6wbrfUjzc8Pq6Bigr OVTBF6on0p3u/DuIpBDFdfN3r+kFAR9gb+7naZ5kOhkEZ8Ns6GH1PFKQgebvRkXqctqrSHhQLyC c3dO7/YxdGd7D3mwIVdo7h6QIsttfbHXFezqX5WgfB860vUfyv3E/evh1ZrI6iFGFrrYeSYZudb eKhkzHzrc4GNbauF4v1d0X/mZlrJ8WQ3rqKeFTw1yRDf7w2fwDbMWiTZiw X-Received: by 2002:a05:600c:6990:b0:45f:2940:d194 with SMTP id 5b1f17b1804b1-48703433ea4mr1665715e9.2.1774173731564; Sun, 22 Mar 2026 03:02:11 -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-43b64703650sm20013069f8f.20.2026.03.22.03.02.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Mar 2026 03:02:10 -0700 (PDT) Date: Sun, 22 Mar 2026 10:02:07 +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 06/11] vfio: Introduce and set noiommu flag on vfio_device Message-ID: References: <20260312155637.376854-1-jacob.pan@linux.microsoft.com> <20260312155637.376854-7-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-7-jacob.pan@linux.microsoft.com> On Thu, Mar 12, 2026 at 08:56:32AM -0700, Jacob Pan wrote: > When a VFIO device is added to a noiommu group, set the noiommu flag on > the vfio_device structure to indicate that the device operates in > noiommu mode. > > Also update function signatures to pass vfio_device instead of device, > which has the direct access to the noiommu flag. > > Signed-off-by: Jacob Pan Reviewed-by: Mostafa Saleh Thanks, Mostafa > --- > drivers/vfio/group.c | 21 +++++++++++---------- > include/linux/vfio.h | 1 + > 2 files changed, 12 insertions(+), 10 deletions(-) > > diff --git a/drivers/vfio/group.c b/drivers/vfio/group.c > index 98f2a4f2ebff..6f98c57de9e0 100644 > --- a/drivers/vfio/group.c > +++ b/drivers/vfio/group.c > @@ -588,7 +588,7 @@ static struct vfio_group *vfio_create_group(struct iommu_group *iommu_group, > return ret; > } > > -static struct vfio_group *vfio_noiommu_group_alloc(struct device *dev, > +static struct vfio_group *vfio_noiommu_group_alloc(struct vfio_device *vdev, > enum vfio_group_type type) > { > struct iommu_group *iommu_group; > @@ -610,7 +610,7 @@ static struct vfio_group *vfio_noiommu_group_alloc(struct device *dev, > ret = iommu_group_set_name(iommu_group, "vfio-noiommu"); > if (ret) > goto out_put_group; > - ret = iommu_group_add_device(iommu_group, dev); > + ret = iommu_group_add_device(iommu_group, vdev->dev); > if (ret) > goto out_put_group; > > @@ -625,7 +625,7 @@ static struct vfio_group *vfio_noiommu_group_alloc(struct device *dev, > return group; > > out_remove_device: > - iommu_group_remove_device(dev); > + iommu_group_remove_device(vdev->dev); > out_put_group: > iommu_group_put(iommu_group); > return ERR_PTR(ret); > @@ -646,23 +646,24 @@ static bool vfio_group_has_device(struct vfio_group *group, struct device *dev) > return false; > } > > -static struct vfio_group *vfio_group_find_or_alloc(struct device *dev) > +static struct vfio_group *vfio_group_find_or_alloc(struct vfio_device *vdev) > { > struct iommu_group *iommu_group; > struct vfio_group *group; > > - iommu_group = iommu_group_get(dev); > + iommu_group = iommu_group_get(vdev->dev); > if (!iommu_group && vfio_noiommu) { > + vdev->noiommu = 1; > /* > * With noiommu enabled, create an IOMMU group for devices that > * don't already have one, implying no IOMMU hardware/driver > * exists. Taint the kernel because we're about to give a DMA > * capable device to a user without IOMMU protection. > */ > - group = vfio_noiommu_group_alloc(dev, VFIO_NO_IOMMU); > + group = vfio_noiommu_group_alloc(vdev, VFIO_NO_IOMMU); > if (!IS_ERR(group)) { > add_taint(TAINT_USER, LOCKDEP_STILL_OK); > - dev_warn(dev, "Adding kernel taint for vfio-noiommu group on device\n"); > + dev_warn(vdev->dev, "Adding kernel taint for vfio-noiommu group on device\n"); > } > return group; > } > @@ -673,7 +674,7 @@ static struct vfio_group *vfio_group_find_or_alloc(struct device *dev) > mutex_lock(&vfio.group_lock); > group = vfio_group_find_from_iommu(iommu_group); > if (group) { > - if (WARN_ON(vfio_group_has_device(group, dev))) > + if (WARN_ON(vfio_group_has_device(group, vdev->dev))) > group = ERR_PTR(-EINVAL); > else > refcount_inc(&group->drivers); > @@ -693,9 +694,9 @@ int vfio_device_set_group(struct vfio_device *device, > struct vfio_group *group; > > if (type == VFIO_IOMMU) > - group = vfio_group_find_or_alloc(device->dev); > + group = vfio_group_find_or_alloc(device); > else > - group = vfio_noiommu_group_alloc(device->dev, type); > + group = vfio_noiommu_group_alloc(device, type); > > if (IS_ERR(group)) > return PTR_ERR(group); > diff --git a/include/linux/vfio.h b/include/linux/vfio.h > index e90859956514..844d14839f96 100644 > --- a/include/linux/vfio.h > +++ b/include/linux/vfio.h > @@ -72,6 +72,7 @@ struct vfio_device { > u8 iommufd_attached:1; > #endif > u8 cdev_opened:1; > + u8 noiommu:1; > #ifdef CONFIG_DEBUG_FS > /* > * debug_root is a static property of the vfio_device > -- > 2.34.1 >