From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (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 966B33254B3 for ; Tue, 2 Dec 2025 23:03:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764716631; cv=none; b=aHFAxD4Gs+Cn2YSyjhaq6NOludHPf2FSQOOwmSJJLLgBaRjRpWh9G8iyXoJdorVzHa79Y/yPnf3uYYiXnMw9a32YMRDw8HREmADmYXSwGBMtNh4d9SSw74DBL5M6ncY6/ozu+DKJHabNS3yOVDWrWrQqcKCNgB8N9fb0RmdS0WQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764716631; c=relaxed/simple; bh=tuMmnL8kWBlel7HULWOxQsUVB1nLdJi3c5N1cwgmLXs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=RjOT+pO3j1llYG0Or8UT4/8WWzuBYsebzJpGaYNoxW3cewE9PLzsNd+vBU+GaPyXBH+PkCkvU17Ti2rR1GIB/zx6vI3JDuVs7zTatFLd61EQyUwFqTrbTwwde4/E0s04sCJNybjR9vmNuTcymwHnetvMNBDIGxroDBZmITEAazg= 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=X2z26DY8; arc=none smtp.client-ip=209.85.210.201 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="X2z26DY8" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-7a9fb6fcc78so4374581b3a.3 for ; Tue, 02 Dec 2025 15:03:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764716629; x=1765321429; 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=k59EbfleIcJoy+5EzizBoaCnf/ll7pOIinGcBu3hfz4=; b=X2z26DY8NzdcRGzCQmtT35TqgYEttP5kP/GzSRTuWR8cCP0FGmLcPlxuHf3j83b9mK u5kGODSmvRzJ3FKJXcvNSm7O5u0SqNTwx7NDdRiLpIWbM7YhGe0Nd4FBKAYNbKNwaFtt M4nXzA8xqkyn8MUz8Qi+HU9MwzCvJbWX9CO4gctgGOg4UNonIhzf7CRmZm1RipjWFbsW 18uRXodaCXP2pTMUNvdiHApXECk6MWunydwxwNUnG6e3amCf0YbcXYmOaQ/clf2tt0Z/ SAB0kNXKv1pSpEC4LWcQpz9GSKZ4N4oMYPFo9siwg5snQoTR8w0ylS+aVBVQ+6T+/xj0 M7+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764716629; x=1765321429; 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=k59EbfleIcJoy+5EzizBoaCnf/ll7pOIinGcBu3hfz4=; b=Y31pwLfwhNHPrassAjEcDcn/ibZdvgxb9bWz+HQjTGEl1IS985DlCL3dXeI5Nbcbmd OUKCd0ToZmbfiPTgRDmSHmwTfBQgBwBFj8Nd9ePSc2efz2LwSfeaWlHTiAyo4yYvA56i mXBZJIZQXc+Ulfd0DL44z6gPORJH52ixWhfJouDPJ8Ty8SyI6z8Nlrz63pvsPakLLAqH aJiA8F1itiI8g9iFGOnffD4DBls0wjRJzlmIFAp1VXGPi/H4tJtVi231Ahu7gS97TaUh NR1bNWu7O89EVUlcoOtmpHIHirLgz1No4MZbDgxjMSPO4NLk9CRd9thyCKiIj9KrFMyc ckgw== X-Forwarded-Encrypted: i=1; AJvYcCUyMRRwJekfmrovL6hOwZVw4taIGoLVqKbgqylM2JnO6ngyUfmWfM95Fh9vEed22kAD0ZHGJAFCoFahUyI=@vger.kernel.org X-Gm-Message-State: AOJu0YwWgILghqEVH1OaEQHVCP4d4Jpo8zJteTDFEViJGIsynwIBEdh4 SsLBLZgisJbaHsizm9O2YTjDQdmdaHcKwOzNkzo/H3+tZBFGd79fxgBZZnPSNv2aeC7vfhJdwzh jsX6qwbeU/nNR8A== X-Google-Smtp-Source: AGHT+IHNZF7hxsRSp55PFXeM9EtFqxELzPE8x8BH2lj5GjmzOZvrRqo6QMh5gMNPIfQGqxqKmNSvKLvn/TVNsw== X-Received: from pfoh7.prod.google.com ([2002:aa7:86c7:0:b0:7b9:3791:eaee]) (user=skhawaja job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:3d46:b0:7bf:1a4b:1670 with SMTP id d2e1a72fcca58-7e00a0df2f2mr192443b3a.6.1764716628794; Tue, 02 Dec 2025 15:03:48 -0800 (PST) Date: Tue, 2 Dec 2025 23:02:59 +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-30-skhawaja@google.com> Subject: [RFC PATCH v2 29/32] iommufd: Handle the iommufd can_finish properly 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" IOMMUFD cannot finish until the restored domains have attachments. The devices attached to the restored domains should be detached or hotswapped to different iommu domains before the finish can happen. Signed-off-by: Samiullah Khawaja --- drivers/iommu/iommufd/iommufd_private.h | 4 +- drivers/iommu/iommufd/liveupdate.c | 55 ++++++++++++++++++++----- 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index 0d358e5486d0..3ae324d7da14 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -383,6 +383,7 @@ struct iommufd_hwpt_paging { bool nest_parent : 1; #ifdef CONFIG_LIVEUPDATE bool lu_preserved : 1; + bool lu_restored : 1; u32 lu_token; #endif /* Head at iommufd_ioas::hwpt_list */ @@ -728,9 +729,6 @@ int iommufd_liveupdate_unregister_lufs(void); int iommufd_hwpt_lu_set_preserved(struct iommufd_ucmd *ucmd); int iommufd_hwpt_lu_restore(struct iommufd_ucmd *ucmd); - -/* TODO */ -#define iommu_domain_has_attachments(x) (false) #else static inline int iommufd_liveupdate_register_lufs(void) { diff --git a/drivers/iommu/iommufd/liveupdate.c b/drivers/iommu/iommufd/liveupdate.c index 5b45071d7dd2..fe4c514811a4 100644 --- a/drivers/iommu/iommufd/liveupdate.c +++ b/drivers/iommu/iommufd/liveupdate.c @@ -265,16 +265,6 @@ static int iommufd_liveupdate_retrieve(struct liveupdate_file_op_args *args) return rc; } -static bool iommufd_liveupdate_can_finish(struct liveupdate_file_op_args *args) -{ - if (!args->retrieved || !args->file) { - pr_warn("%s: fd not reclaimed\n", __func__); - return false; - } - - return true; -} - int iommufd_hwpt_lu_restore(struct iommufd_ucmd *ucmd) { struct iommu_hwpt_lu_restore *cmd = ucmd->cmd; @@ -319,6 +309,7 @@ int iommufd_hwpt_lu_restore(struct iommufd_ucmd *ucmd) iommufd_object_finalize(ictx, &hwpt->common.obj); hwpt_lu->reclaimed = true; + hwpt->lu_restored = true; cmd->pt_id = hwpt->common.obj.id; return 0; @@ -327,6 +318,50 @@ int iommufd_hwpt_lu_restore(struct iommufd_ucmd *ucmd) return rc; } +static bool iommufd_liveupdate_can_finish(struct liveupdate_file_op_args *args) +{ + struct iommufd_hwpt_paging *hwpt; + struct iommufd_hwpt_lu *hwpt_lu; + struct iommufd_lu *iommufd_lu; + struct iommufd_object *obj; + struct iommufd_ctx *ictx; + unsigned long index; + unsigned int i; + + if (!args->retrieved || !args->file) { + pr_warn("%s: fd not reclaimed\n", __func__); + return false; + } + + ictx = iommufd_ctx_from_file(args->file); + iommufd_lu = ictx->lu; + + for (i = 0; i < iommufd_lu->nr_hwpts; i++) { + hwpt_lu = &iommufd_lu->hwpts[i]; + + if (!hwpt_lu->reclaimed) + return false; + } + + xa_lock(&ictx->objects); + xa_for_each(&ictx->objects, index, obj) { + if (obj->type != IOMMUFD_OBJ_HWPT_PAGING) + continue; + + hwpt = container_of(obj, struct iommufd_hwpt_paging, common.obj); + if (!hwpt->lu_restored) + continue; + + if (!hwpt->common.domain || iommu_domain_has_attachments(hwpt->common.domain)) { + xa_unlock(&ictx->objects); + return false; + } + } + xa_unlock(&ictx->objects); + + return true; +} + static void iommufd_liveupdate_finish(struct liveupdate_file_op_args *args) { struct iommufd_lu *iommufd_lu; -- 2.52.0.158.g65b55ccf14-goog