From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 9980C35CB87 for ; Wed, 20 May 2026 19:54:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779306892; cv=none; b=N0qQceSqYEVkSETRfH7XaDa6rY/ivplAu30jYCW+GsqK/Mn3bJ4QcM3ILxjfmXNCuxODJ54QVxH0tU1iXvvcygKz+nZeVF8PZCzlz/eB1085wHwnqj3Y0TS4y6o5as9OAA9h1BTNCKzVut6MhaGrcEpxHMPiV6q7jHvj9NsjfYU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779306892; c=relaxed/simple; bh=DwoLvHtBsMr6cFX0X2XMLQenBS2lTQpE+ExMxyFn8EE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ga9rbQi3dnSyeu8xiCdVWkdDKnZKPOOxmFbDyk856Txy9YV8VM1yFO6gY3hmrVu28Yi213KDY0Vm+N6KAq4UdVUz+aaS9RV6OmgwjAs2ajsYgonXTdZXLIdaWUkaTwHnE3Rck+g0diAJcw+/QLJ/+dCG/sdkqPlbTx3k218f8+o= 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=ul3og3w4; arc=none smtp.client-ip=209.85.214.180 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="ul3og3w4" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2ba180a022dso135ad.1 for ; Wed, 20 May 2026 12:54:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779306890; x=1779911690; 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=odGUqTyiw+s+ktOv1sVN6kVyJPFqIH1UoIVnjwejXQY=; b=ul3og3w4DyuNVcwdZ6Xg7+9qhxBmAfKMk/pD3rSsz/BQ7F6KVhWuuuC45SETBwVf8M MhOrQVVXG3QV2fnVv0BNV8iCaqHYQ4/Y0VB/UedcUMqgK5xNJuSAmp3xVnquwZGSvmQN xpqQYsUHdEUThXo8p4pH645AahgKMl7TS456tOvDUJTPHlkp24nGMXNLROD7S9lPf2UL wCeBt/sQcnDPfDpVfFqSzzoQogonBpDDZn1PP7Gxh/NPNxL2KLpIjuPZDKziNBzS43XX DgMtaJXsArPjGP2k3jjkfpeTRQv/SiJs2t58M5nLzeApZQJrCvdRa05QWRxFj/v9qSYs VrLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779306890; x=1779911690; 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=odGUqTyiw+s+ktOv1sVN6kVyJPFqIH1UoIVnjwejXQY=; b=TbAXPlBkXdLKZI+10s1mUaeYGItss2hWkxZLmDgaRX383d74mq0vd6z+ZMHzzrtPaI z1OVbOFfG2vNTOcwjKSkp7XomRq2yfD566SuJwFdcWK4KvCY/EieP9LNRvXQpLHGzLdf 9PXSRpct4i4Iu4MqVlnEUJ4X4S5mW4+NpvyQ2vlPv39EVQOuatOt7uDjmUfgLgq6WbxY NPc18w56r97g6cm/rXpOX7k0KW/Hmy0rCB4j0EOhUfxknYBIwB54N1nqPrYLRZBLpzql ywGuBUI3bLMFa3JyOIfKkWpl+TfdH3DNlr1rDCCz1/Dvj1xuhIpyJPFVCB1tJQqLc5o9 fJ5w== X-Forwarded-Encrypted: i=1; AFNElJ9L58STYwU2VHsQQ2qJqtMLjoL1FMATcAXAaUT3/Ymf6HVq8diDx6oxOfIaAbi8h8NJ93XveCu+v07uQwk=@vger.kernel.org X-Gm-Message-State: AOJu0Yx2LUbQrC4+roHlhUkdPPWf+t0CEycan8TY53Dcmrvw44y1CUFz /TZDoE9dcRu7B/0ZOorZhu8hkzqpHdnh5ffUu0EhcWOEDhGpsGNzpg5ODxxM+jmRdQ== X-Gm-Gg: Acq92OHU+lN+a64A9IebHmfdFfp3RKiBlT5exKGoTw8GGrNGq56QqJ8h3aRooIVB9si E64ywOGtRmm7BJqS0olXbM0xUYvYt0PCPL7LzjO2MRhQ3BThv9f+uQ0CRtXeXHrfgERPRTKbDOK 9vBKCFcazUWzib+/Gq4kZ6XU6pY8CAodWmMvSjxaw8Ks6Lhq1Uu2breURrQY9gefZGwnfOOMIl8 naPmmqTo72yX6q5W/ithnMhJTZnhXxUDJptU8UKG+JtJhNJsUuWsua6xIin3LflLOr8T7dF+SIt LsIce4eCknvH3dm/MU2Z5Cf1WmmJSU+u1zkTl+pLKfQzezjaHPWtG9LPcl7uOlKn7nIkHRMV0p+ tWHuMUGCJKQ89WQDoOGPgQzMv3XvPo062K4sUTz/VEKprWRlVJDDlV1XSrIt47dPqwDWypSHnjW SQZMmDbCMfpyN4z7p0oa5Iv1/yde/ZMwbetGWXKO2Lb0aT7JeVoMmqDoiBQp/6tlG2y58aFglNc Aq//UQT X-Received: by 2002:a17:903:1a84:b0:2bd:6dad:7ccd with SMTP id d9443c01a7336-2be9f6f3fb7mr619555ad.25.1779306889241; Wed, 20 May 2026 12:54:49 -0700 (PDT) Received: from google.com (153.46.83.34.bc.googleusercontent.com. [34.83.46.153]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-36a3f4ddc23sm206344a91.15.2026.05.20.12.54.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2026 12:54:48 -0700 (PDT) Date: Wed, 20 May 2026 19:54:45 +0000 From: Samiullah Khawaja To: Pranjal Shrivastava Cc: David Woodhouse , Lu Baolu , Joerg Roedel , Will Deacon , Jason Gunthorpe , Robin Murphy , Kevin Tian , Alex Williamson , Shuah Khan , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Saeed Mahameed , Adithya Jayachandran , Parav Pandit , Leon Romanovsky , William Tu , Pratyush Yadav , Pasha Tatashin , David Matlack , Andrew Morton , Chris Li , Vipin Sharma , YiFei Zhu Subject: Re: [PATCH v2 15/16] vfio/pci: Preserve the iommufd state of the vfio cdev Message-ID: References: <20260427175633.1978233-1-skhawaja@google.com> <20260427175633.1978233-16-skhawaja@google.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; format=flowed Content-Disposition: inline In-Reply-To: On Wed, May 20, 2026 at 12:57:40AM +0000, Pranjal Shrivastava wrote: >On Mon, Apr 27, 2026 at 05:56:32PM +0000, Samiullah Khawaja wrote: >> If the vfio cdev is attached to an iommufd, preserve the state of the >> attached iommufd also. Basically preserve the iommu specific state of >> the device and also the attach iommu HW unit. >> >> Once the device and its iommufd attachment is preserved, it cannot be >> detached or attached to another IOAS until it is unpreserved. >> >> Signed-off-by: Samiullah Khawaja >> --- >> drivers/vfio/device_cdev.c | 10 ++++++++ >> drivers/vfio/pci/vfio_pci_liveupdate.c | 33 +++++++++++++++++++++++++- >> 2 files changed, 42 insertions(+), 1 deletion(-) >> > >[...] > >> diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio_pci_liveupdate.c >> index 976ef17e6103..b56d80379ffc 100644 >> --- a/drivers/vfio/pci/vfio_pci_liveupdate.c >> +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c >> @@ -108,10 +108,13 @@ >> #include >> #include >> #include >> +#include >> #include >> >> #include "vfio_pci_priv.h" >> >> +MODULE_IMPORT_NS("IOMMUFD"); >> + >> static bool vfio_pci_liveupdate_can_preserve(struct liveupdate_file_handler *handler, >> struct file *file) >> { >> @@ -153,9 +156,26 @@ static int vfio_pci_liveupdate_preserve(struct liveupdate_file_op_args *args) >> vdev = container_of(device, struct vfio_pci_core_device, vdev); >> pdev = vdev->pdev; >> >> +#ifdef CONFIG_IOMMU_LIVEUPDATE >> + /* If iommufd is attached, preserve the underlying domain */ >> + mutex_lock(&device->dev_set->lock); >> + if (device->iommufd_attached) { >> + u64 token, preserved_state; >> + >> + ret = iommufd_device_preserve(args->session, >> + device->iommufd_device, >> + &token, &preserved_state); >> + if (ret) { >> + mutex_unlock(&device->dev_set->lock); >> + return ret; >> + } >> + } >> + mutex_unlock(&device->dev_set->lock); >> +#endif >> + >> ret = pci_liveupdate_preserve(pdev); >> if (ret) >> - return ret; >> + goto err_iommufd_unpreserve; > >Nit: Would we hit the WARN in patch 14 if (device->iommufd_attached) was >false here? Should we check if (device->iommufd_attached) below before >calling unpreserve? Agreed. I will update this. > >> >> ser = kho_alloc_preserve(sizeof(*ser)); >> if (IS_ERR(ser)) { >> @@ -170,6 +190,9 @@ static int vfio_pci_liveupdate_preserve(struct liveupdate_file_op_args *args) >> args->serialized_data = virt_to_phys(ser); >> return 0; >> >> +err_iommufd_unpreserve: >> + iommufd_device_unpreserve(args->session, device->iommufd_device); >> + >> err_unpreserve: >> pci_liveupdate_unpreserve(pdev); >> return ret; > >With that nit: > >Reviewed-by: Pranjal Shrivastava > >Thanks, >Praan Thanks, Sami