From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 5C79E37DEB8 for ; Mon, 23 Mar 2026 21:17:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774300657; cv=none; b=cNh7jBua28uGRbwYWkot/y157nL4bc/2qLtVGvOO3e2WGqvHgUfOI04d6msfTmdXbVVEfMQUCa5YpQTTYIdnKbyRmvaYoyjAqe7OWqjP2w0Doc0HuwQZ/z3qwu0QTVir7kFaCeXGsIzPubk5Ch3AY+K52nGyAxE7pLMwQ1Hnvj4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774300657; c=relaxed/simple; bh=Nm+VZTxnT9qw3EFPipXSMTWJ48lruE6BGIiYuVcKFcM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fVzgxTK+vnwixY4qZfr8+QJkgq1KZQN/M2PStmaq0mlX++qq7mRwkI+YbObRDpC8ASoqS/+OT1iae85pRrxa0UtDy2b9GCOfeSVLZ4h+KT82E70jAgnW6quR5jsnF8azSmlTMm5vc4r0IuX9wqgNZm1u3jw7RCXv8NWoQNOZpvA= 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=c61Ts3gt; arc=none smtp.client-ip=209.85.214.176 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="c61Ts3gt" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2b052562254so31295ad.0 for ; Mon, 23 Mar 2026 14:17:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774300654; x=1774905454; 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=layxP6Fhjqp+wTdLPHecG2YnZ/zXdi50jvGwdG06cGQ=; b=c61Ts3gtnAu2t8de0j/2MHv47QAf3V13VebXbfJUAPH5K3XURZ78ssAjKFXT8Nfmy2 0mZEEHXSue843jJI6wvzx91Qb0h/Zp76fnnGQe6RGqMgtgN6FtdSdHIiJvdqaoT8v90l QLDxscz2EUyHHQD5GOTQfp3Jdx/j9t5+hX1CSvlzI9CwzdDRULDPoZI5uQzI6/XGHIsw NzoMy9tyCFj5qZCtyt2eT0zS0XkC7yYTpuGu18whr0DrU3ay60Tn6B5bASEcBio/bpMh bZyLmVmWY2S4xZbC0sMxqFEr9zw9/N2hc54x9LbFwmEJDg+G7NityR8NKzOy2hrqxYwM 2RpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774300654; x=1774905454; 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=layxP6Fhjqp+wTdLPHecG2YnZ/zXdi50jvGwdG06cGQ=; b=VL8m0fenmMWylZcOePjjskoXbjNhAPuUou7zTJR7cv/r7S8Q7UZxkCCbDnc/K6eCOW wGDCx97lZfK+7VlFjETY46J7D3iJxJQ1lOshvQHaDa5FYVJClv8EIaL+/VGKNtMO+Eer yhJqn1GdusYxDFRX5uPbcsFH8E8nHZ29oRQ3MhYmVyHIojcZYocer3AbCwibxlNpHcya yZxhaFgLWCrDh04vCiDcBP45BMtDrypjAwEsRFP8bk4Fr0aiP3nJmc2vZDl3g00ilajC cQtA4JD0ZG53oEz2d7HYg7dzQBsqp7baapos7lSZpPyXdxTBPP6KEDptuEmiTKH0LeBl 4C5w== X-Forwarded-Encrypted: i=1; AJvYcCV7tJinm2I4Cnk+FQbm4NqCE4vJHazQEIrIuIMjegdF33hasFBC5HgG//Eo1Jfe6M3LdpjWm4rNhwt28zE=@vger.kernel.org X-Gm-Message-State: AOJu0YyWdaK49G3uuUlxIs2+B9FUbCJDIdzWc16N9RIXcQlCHOYxp2/8 OBtv03f9QelWwRxQ0JGMN8chLZdOSGl5AXkcInvata6bk3YcqJWOJLiEmNiVsMBArQ== X-Gm-Gg: ATEYQzyObxeAdjp+b1TjpcKOyNQX/6jVNghMkxSBXxdeY99M/KSmQ5B3M7K38aNb/rd sLHgqpqxVn3VbORBcxIyqs5hYLaHcKq1vdxGBGnq5al4HZiQQJh4w+TUhwwu5vqg/bNH5ttPyyi 0ea7Lh3LBrCZi8Imq1u2133dR8TvVIlq7z5dWBNhD4nfXPWdoga8lGIuUmiunVJMkZaVrtg8CAZ gEaRFf+gVxdiN2VqV4008qAQRAPHNISYKlVnyxRqfxE8smCP6iBixv+C8fd5fi7kUKK5Wdgiss0 t+XyDapSpeJe0dBdAH5+wzJURP3mO2g9kBKfLEwGqZthKiNmE0cr9QRJpBWDRJauJ6bKCicQwLT qrAolPWVW2z6GtfjkSyHDhOyL6Obov+lYs7kdlBqr0EbBeBtUuFkwX1Ywt+pNMeuCYIIlzJ6Fr5 0Rvy2sjkxPbXmCoFOQPRH/awPdqPNYliDtt0JSsLVpzvLZkoaKHewyjwsA6g== X-Received: by 2002:a17:902:c943:b0:2a9:5bfa:54ef with SMTP id d9443c01a7336-2b0a540776emr966405ad.10.1774300654128; Mon, 23 Mar 2026 14:17:34 -0700 (PDT) Received: from google.com (60.89.247.35.bc.googleusercontent.com. [35.247.89.60]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c76565c35desm1829840a12.15.2026.03.23.14.17.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 14:17:33 -0700 (PDT) Date: Mon, 23 Mar 2026 14:17:29 -0700 From: Vipin Sharma To: Samiullah Khawaja 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 , Pranjal Shrivastava , YiFei Zhu Subject: Re: [PATCH 13/14] vfio/pci: Preserve the iommufd state of the vfio cdev Message-ID: <20260323210111.GB2571566.vipinsh@google.com> References: <20260203220948.2176157-1-skhawaja@google.com> <20260203220948.2176157-14-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 Content-Disposition: inline In-Reply-To: <20260203220948.2176157-14-skhawaja@google.com> On Tue, Feb 03, 2026 at 10:09:47PM +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 state of the device > and also the attached domain. The token returned by the preservation API > will be used to restore/rebind to the iommufd state after liveupdate. Lets add token when it is used in restore/rebind patches in future. > diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio_pci_liveupdate.c > @@ -49,15 +51,32 @@ static int vfio_pci_liveupdate_preserve(struct liveupdate_file_op_args *args) > if (vfio_pci_is_intel_display(pdev)) > return -EINVAL; > > +#if CONFIG_IOMMU_LIVEUPDATE > + /* If iommufd is attached, preserve the underlying domain */ > + if (device->iommufd_attached) { > + int err = iommufd_device_preserve(args->session, > + device->iommufd_device, > + &token); > + if (err < 0) > + return err; > + } > +#endif > + > ser = kho_alloc_preserve(sizeof(*ser)); > - if (IS_ERR(ser)) > + if (IS_ERR(ser)) { > + if (device->iommufd_attached) > + iommufd_device_unpreserve(args->session, > + device->iommufd_device, token); > + > return PTR_ERR(ser); > + } driver/vfio/pci/iommufd.c has all of the code which interacts with iommufd in VFIO, I think we should follow the convention and add a function there which can be called from here. > diff --git a/include/linux/kho/abi/vfio_pci.h b/include/linux/kho/abi/vfio_pci.h > +/** > + * struct vfio_iommufd_ser - Serialized state of the attached iommufd. > + * > + * @token: The token of the bound iommufd state. > + */ > +struct vfio_iommufd_ser { > + u32 token; This is u32, whereas the token above is u64.