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 A385437F8A6 for ; Mon, 23 Mar 2026 22:07:37 +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=1774303659; cv=none; b=Vy2UHvUiF7LziwG0IZZGFhM5uCo/h3JXfFi8sUSzGv/bzci6RTsMkQuAO2z0/eUA+1rY3i7B1gGz9qOLhG55Gc5O0cbhJDxXnD6uHbng61lCt7C17RUdsjiudZZHGNnxmK6868kA+rxeJ2wLz7kS+tfSWitTNwTz6FxwOatMUwU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774303659; c=relaxed/simple; bh=+5NvPwxkd+9i5GiKKfiHltHB6kQ8dritqed/r7e5gEE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oLVh+W+6/TeViSDt+buobZ41HOrsg5qNuA3DK8NvL7qfJB3Xxvl40pToHRhpqDLPSKhzDc2RB44NTPLgH8GeNDZw5CyUFw2GuFt41wDPn5LeTf6cFB4kRweTSmYusOXf9K3XPKIBtD0EsZBTuWFompUjIBtAsGeVNnO2R5AbWFs= 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=LjnmsVBn; 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="LjnmsVBn" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2b052ec7176so14055ad.1 for ; Mon, 23 Mar 2026 15:07:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774303657; x=1774908457; 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=exBHGWHqN/Fcx1Fk+ursFGf32PtT/7vVoLt/cnZyELU=; b=LjnmsVBnJwZ2aw9PaeRTDBlW6IQkHvKbtyqhL1Ghqdvfx/oDSdRVCRSMjstWY6ST+4 eVyp5eH2bknrQw05qfOP3Qha0cNZwIrfSEe50nh1ApGkmH07tl7Km3q/kvAckLCsSOov VM5UtwM9oBWLe25jxFcBaL03BUUtN79cX+jeJ4VPvQp8vrQuXut4+1PcjMYrf8/nyvLj t3EyL3S1CzzA5rVTH70CCFJ/mLdWCGwqa/SVhPaB3dVZyCpJsHg0pmzVlVl/Cx1PqBOH fUbu40tcZa3PMGW1vbyNezS/ToBrjJ3N5JZ5X8KLiuXflubQYFV265SLJaOhhu91o6KC dyFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774303657; x=1774908457; 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=exBHGWHqN/Fcx1Fk+ursFGf32PtT/7vVoLt/cnZyELU=; b=Zh6OeyfHb5eO3GlEAg0YpN6GLl/fvVN5tPT0nsAVbJVyxyejLkWcCjoYvEtSaazO/c hZathbh25wsJ0F7Jvha4aCvrmikGF3fgkB6surKqIvXjZIDkpz/O4O2Y7FaE2mOuz3tU 1Hi3uq43DbKkF5WEGgIHStpAFQGcBN1r7Trx24f1E6Luuj2x7f7gYgZ7QBlYmu+Jaqb+ rkfIQ4/9SlxI2WDYK7tWFRNKTlPJwywQo9zDvNznJmnbop/bZqxw5ASO+PQzETMBgcwc htPokJzJt7EAkhvoulUoTzHgZozx++bnVA2x5gqW9N0tXPSRBS5V2XPL8w1efuG147Ca tnwQ== X-Forwarded-Encrypted: i=1; AJvYcCU7l4oZ9UN9AUG70P975cXT9W7iMnb7OA7mp8tvP+WJ7L0LamhONdc8w3n7LpvaKgP57cHL7IzelskhPQY=@vger.kernel.org X-Gm-Message-State: AOJu0Ywtg3C8WTB4TRJpAO36BIua49U2bD/d43jWjfmtEH5JICdsUUTS hqZdcUT0V0ulhxpqB2Fm1uMEN3m85rwvDMs8FCLSK7Hed3x2qwCrmLr2iEToJQcC4w== X-Gm-Gg: ATEYQzz9mRKamcMURZVRKDZeKbiGDcMK+X3A0VevkkmM3N7SevmF/GHa13CtBtgjlex L5JSmcttz7ITa+dO+zn6q7yYZa83fQPVUi0x3VZ0EJbUmFpdTbFIdIMs6HY8GTjQsoDReZBPwLT rdv961cePbmCUVyC+NPCAUaxyVCZGGFFqP8VSxosvltq4fs7sii5AxCRGemSh1j1Pxau4IZBYqi h766uxuKiWKqzjDLnspTy/m3upjDuvSrPZjilTNDs72dA5JgCd8gWr60zMB+K72xXkvFqONpPQC js96CQuXKJf8d+XPxDLBYmJdTYLlLwgWbC6qIdZhJLZ6lBZbYqa7DemhvadjyrfqCyOk6fTeWlk hYGIi9uRtTd6aI+XIRgFVQV+Sk/+TC2p/Gll9uI2aTYVvH7Prup83bvqE9ZVUaDbcTI+ME1VKEW ykcL6yqy7n3o+v6kGE5Krc5kpCvU+gJtw+rjHOP9znOwRcvEhCM3I/31uOl5BJag== X-Received: by 2002:a17:902:ce0a:b0:2b0:4613:2e35 with SMTP id d9443c01a7336-2b0a532cbf5mr1341715ad.0.1774303656096; Mon, 23 Mar 2026 15:07:36 -0700 (PDT) Received: from google.com (168.136.83.34.bc.googleusercontent.com. [34.83.136.168]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b0835551c3sm117347225ad.35.2026.03.23.15.07.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 15:07:35 -0700 (PDT) Date: Mon, 23 Mar 2026 22:07:31 +0000 From: Samiullah Khawaja To: Vipin Sharma 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: References: <20260203220948.2176157-1-skhawaja@google.com> <20260203220948.2176157-14-skhawaja@google.com> <20260323210111.GB2571566.vipinsh@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: <20260323210111.GB2571566.vipinsh@google.com> On Mon, Mar 23, 2026 at 02:17:29PM -0700, Vipin Sharma wrote: >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. Agreed. > >> 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. I am assuming you meant driver/vfio/iommufd.c as drivers/vfio/pci/iommufd.c doens't exist. I see iommufd_ctx and other iommufd_ functions being used directly in various places outside drivers/vfio/iommufd.c, so there is not a hard split I think. This will introduce unnecessary indirection I think. > >> 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. Will update. > > Thanks, Sami