From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 0C6A9306B18 for ; Tue, 2 Dec 2025 23:03:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764716614; cv=none; b=Pp3tZGVlNS7kFrRyVrbN1UpbVxvVJYJTfieMMVzeh80OkMGmly4ZU9Eb1H5vQOyMJ3YPUcJBsK6xBbv01iV1k9M37FVx6L+JY2yIZrdgjreWplHxECE6skQqdMvc3hqAR/IrXcKhhpLOTGNIzLf4Ag29f8jFfeMVFkGRlsSBVOc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764716614; c=relaxed/simple; bh=tOydq3slfdu9JtyTiKAwwp6Hpif0D2PUjntntIRibp4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jExW6SSX1ig10jtL0ZBBXdC2ZPNm0eoC8WyxNe7wJPcVpDgIDo4qgJnqWKysMqAQhE/HBT7GuynVHHprCziB8brYemy1Ur0ekL55eogU0/KPqupoX+NIecZkcqfwP9mMhd6/LtARbT7p3qvsfsZ/w1ct/riWDIe49vk1iY73CqA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--skhawaja.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Uw4tMR0V; arc=none smtp.client-ip=209.85.216.73 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=flex--skhawaja.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Uw4tMR0V" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-343fb64cea6so11027679a91.3 for ; Tue, 02 Dec 2025 15:03:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764716612; x=1765321412; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=I2j0Lgb/rNw+C0ZmBDCgYVjwCBWA7vES7WrfyQecVmE=; b=Uw4tMR0VTXEH7vmLqsOUxOfxYlAMojoqBpfzqckQkHIWFr1oO2YgKKJr22Tc36WdOn vDFvtH29EPcRSeyT/SdxtEnkNJTO7U+Ay05Ulzef0spzpSeUtmmNTNxy2t7fkZNj9xBc sHcPkKWl6IxibZ/Px2C4MMHLSjbeW9lfwOl9GUQixEat/fX/pVZ3FOzW3wbR0lepyWBi l9WdPNhDd4yZwsnpuA01IbbPqlYIk3QTaHdFo7P6Cg3q25yKkRCcepHpiB4Hi8DG/8Uc qV5lj3O6lhJv6qLlWU0+xHhpSHfKOAn39PfC8/p7pWrhHYh0x0XjaS9rL4fGpSOlz6pS yddA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764716612; x=1765321412; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=I2j0Lgb/rNw+C0ZmBDCgYVjwCBWA7vES7WrfyQecVmE=; b=vqNOPp4dHnmi6884iA/RlH8ivZpM55MHI8tbzGgoD4REaUDZuq1QiAuOWijsadgHhZ eH6Zw4dsAZJFzPjgqvpsYBAscSDyCPmWiDh2jYg/uTPoy2xD6F7zBOhF0u/dV7+sTsj3 3PXH6NxtdMonKoMLCcAysmbSZsEooSznh8eItwhudXIXeaY6dI2VbRlrz7S+9kzqHUaj jyRDqvR0Ixcv/9P1l6b3ti1D8hitmG1JhRIFYtULdnTeD1E67HT+04YfUi1af3PFNjDb 5+Vlso1RsGlm5hIlgg93IgG4nFeJsL4Vknnqc5wRPoqT1xIBiMfYHAD46vNgbBAAPm+o wTpQ== X-Forwarded-Encrypted: i=1; AJvYcCXomGkD3bse/4OHa/NTtjKYjPoGuz8T4U+cT6rgnBlRUYlHR+0KOIyR9vWM3suVjeaijo8/Gyv2sCsn4Kc=@vger.kernel.org X-Gm-Message-State: AOJu0YzRi9VCx/Ks6Zu+1Ec9/+CCBBVhd0qXNNjdEJ8NLDJmUfAoERzj Gwv7t07It7gpPXpVtWjktaJE3438B6K/rfjdbEcAVz3k7Ys4sQa0n8/2Cl4Uijnl5zFvSHUuytq /JBtr1SqdZ5GtRQ== X-Google-Smtp-Source: AGHT+IG53fov/iVxOs61D15owy8vLQDQJREsle6WJATSFGxAcKk6SVrPQxDs4qzsSKXKbiYGmQN/hKivZgWafw== X-Received: from pjbpw13.prod.google.com ([2002:a17:90b:278d:b0:33d:ee1f:6fb7]) (user=skhawaja job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3b81:b0:340:ecad:414 with SMTP id 98e67ed59e1d1-349126b81acmr352148a91.27.1764716612215; Tue, 02 Dec 2025 15:03:32 -0800 (PST) Date: Tue, 2 Dec 2025 23:02:48 +0000 In-Reply-To: <20251202230303.1017519-1-skhawaja@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251202230303.1017519-1-skhawaja@google.com> X-Mailer: git-send-email 2.52.0.158.g65b55ccf14-goog Message-ID: <20251202230303.1017519-19-skhawaja@google.com> Subject: [RFC PATCH v2 18/32] iommufd: Add APIs to preserve/unpreserve a vfio cdev From: Samiullah Khawaja To: David Woodhouse , Lu Baolu , Joerg Roedel , Will Deacon , Pasha Tatashin , Jason Gunthorpe , iommu@lists.linux.dev Cc: Samiullah Khawaja , Robin Murphy , Pratyush Yadav , Kevin Tian , Alex Williamson , linux-kernel@vger.kernel.org, Saeed Mahameed , Adithya Jayachandran , Parav Pandit , Leon Romanovsky , William Tu , Vipin Sharma , dmatlack@google.com, YiFei Zhu , Chris Li , praan@google.com Content-Type: text/plain; charset="UTF-8" Add APIs that can be used to preserve and unpreserve a vfio cdev. Use the APIs exported by the IOMMU core to preserve/unpreserve device. Once preserved, the token is returned to the caller so it can be used to restore/rebind to the device after liveupdate. Signed-off-by: Samiullah Khawaja --- drivers/iommu/iommufd/device.c | 39 ++++++++++++++++++++++++++++++++++ include/linux/iommufd.h | 6 ++++++ 2 files changed, 45 insertions(+) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index ba4d9c3cfa8b..2c81bfa7dedd 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -2,6 +2,7 @@ /* Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES */ #include +#include #include #include #include @@ -1666,3 +1667,41 @@ int iommufd_get_hw_info(struct iommufd_ucmd *ucmd) iommufd_put_object(ucmd->ictx, &idev->obj); return rc; } + +#ifdef CONFIG_LIVEUPDATE +int iommufd_device_preserve(struct iommufd_device *idev, ioasid_t pasid) +{ + struct iommufd_group *igroup = idev->igroup; + struct iommufd_hwpt_paging *hwpt_paging; + struct iommufd_hw_pagetable *hwpt; + struct iommufd_attach *attach; + int ret; + + mutex_lock(&igroup->lock); + attach = xa_load(&igroup->pasid_attach, pasid); + if (!attach) { + ret = -ENOENT; + goto out; + } + + hwpt = attach->hwpt; + hwpt_paging = find_hwpt_paging(hwpt); + if (!hwpt_paging || !hwpt_paging->lu_preserved) { + ret = -EINVAL; + goto out; + } + + /* TODO: Add support PASIDs */ + ret = iommu_preserve_device(hwpt_paging->common.domain, idev->dev); + +out: + mutex_unlock(&igroup->lock); + return ret; +} +EXPORT_SYMBOL_NS_GPL(iommufd_device_preserve, "IOMMUFD"); + +void iommufd_device_unpreserve(struct iommufd_device *idev) +{ +} +EXPORT_SYMBOL_NS_GPL(iommufd_device_unpreserve, "IOMMUFD"); +#endif diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h index 6e7efe83bc5d..ba433fb1a481 100644 --- a/include/linux/iommufd.h +++ b/include/linux/iommufd.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -71,6 +72,11 @@ void iommufd_device_detach(struct iommufd_device *idev, ioasid_t pasid); struct iommufd_ctx *iommufd_device_to_ictx(struct iommufd_device *idev); u32 iommufd_device_to_id(struct iommufd_device *idev); +#ifdef CONFIG_LIVEUPDATE +int iommufd_device_preserve(struct iommufd_device *idev, ioasid_t pasid); +void iommufd_device_unpreserve(struct iommufd_device *idev); +#endif + struct iommufd_access_ops { u8 needs_pin_pages : 1; void (*unmap)(void *data, unsigned long iova, unsigned long length); -- 2.52.0.158.g65b55ccf14-goog