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 F096D3093C3 for ; Tue, 2 Dec 2025 23:03:38 +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=1764716620; cv=none; b=q/nhwfh9PG0CIphahDlsnN7s2UUSBsmvRWNmqIu2rknSIyxWHzRkSwLKOMlFYSvfAY47A1UGnKsZJqs++o9rkMdlTtHoGO2CjfxLSgnO2w4izpvMxXXo8PUkCRR8rWfsjDCaJIMGoeIeChFXjrmHe41XyLbPKepwTAu+bnH20xA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764716620; c=relaxed/simple; bh=pvBux9MrnlAMWMFa4Uh7+3qgqbfiM2xGpKsmVCsmNyM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=dggBuDtkhu/bkrAVs3pDhOo+nU1N1+t4ivBXg/QYPWay1pTJ02tfC4DJOciYHepXU2gjY3tb3lhy+w/Q61woO57KeffiRyZdTtDqbIlpDT2a1riDTnuNyCuMxgOfBHmFTB07znRFwrGdEvTgPH/kIONzXU4qNPuV54F9sJvjkpY= 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=U9zExZRv; 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="U9zExZRv" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-7be94e1a073so10256315b3a.2 for ; Tue, 02 Dec 2025 15:03:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764716618; x=1765321418; 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=0rRMYSJaIx0qr3vb82dfybhkCQZzRoj8+W9ZBsbF5AQ=; b=U9zExZRvphzDTp0df1zL8YgCbPSXBypx64xY3rpVYBKuy2/26LfVQsVXIvIJ2/n7Dz TqWtQ9Zyc5rysDgMtM4w4qj7fMFJ0Fu+h+PtZYjG/wj0FNclW/j8Neb4EhDUjNBaaIqT QQS29c0iRkDOlX+u4PXkroAHQZ67XW6p3peimf8IIKJlPuq830inBSyDpcd0jURSm+XH +jlikk05yUqu6sa/IAXzrrMH/cthNaItXgutqdDWRbeNIdIezML3+NMNA+njvBhQYkfY JoiuhCSsdb2maPnIVfjy/rkHGUuIr7fyOOcUDF1o7pRfuHJ9rNfqMHdmFoXmSlg5q893 574g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764716618; x=1765321418; 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=0rRMYSJaIx0qr3vb82dfybhkCQZzRoj8+W9ZBsbF5AQ=; b=Q9dAR3HbtRUWtsn8Aa8g1r7J+YSXdKeyx0EnGamp6rX99oWlYwBIkWt9uOCNlEDb/s +MNjrYrm5WqAF95OxPiuq/HLAawDGnh7VeFpYpwG7N6h+Vr8eUXGtp0t2Cu1bCjRWGEh FDKZVmbUIsq7WDTS0hBIUDtFizWDUQCCIaytcC36xBtnd5XIDySM/LNV10dNUxYqMoQG nGKDI5ZEpjR5Q+VDpyxEBAKWEeGmpQDDiXwll/sDn06mBuSR5+rtfPXSstlg/y4P3Y/9 AKBwdlzafWzQUSMyJ3+BpqIzXwIm3zzPETbne7qS3LQhwi3tqusG79R9HMKCaKOX5I4V B66Q== X-Forwarded-Encrypted: i=1; AJvYcCUIhK2nl6/79FVak/m9lTVknnDPR8ptjuVE3zFtCubZ8D6QosslgHdf8dQQVAGYPRfo7Kg7726RCdmgzXM=@vger.kernel.org X-Gm-Message-State: AOJu0YwsVE/ym7DkVKNWHjm5t0v3WIgabYhED39haO3UPJfZaQJndkDx wAFC3RjnFtk3l02TcogIYShSkfu2otdPvKX6kPjUCUg7TQrCya8KvovuE7UCpzJfIkSZ6XEv+18 A+ozSeUTgWd8bMw== X-Google-Smtp-Source: AGHT+IESTY8l5ddrDwVhJ/K1t5B3qZeQchQ/+iFaGXMixSxBU4Vhr8vdBuXurh0T7DhxTKKU+YN22LfKABc7gQ== X-Received: from pfbfc31.prod.google.com ([2002:a05:6a00:2e1f:b0:7b7:8636:7b21]) (user=skhawaja job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:a24:b0:7b9:ea7a:9cbb with SMTP id d2e1a72fcca58-7e00dfd6852mr173441b3a.19.1764716618194; Tue, 02 Dec 2025 15:03:38 -0800 (PST) Date: Tue, 2 Dec 2025 23:02:52 +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-23-skhawaja@google.com> Subject: [RFC PATCH v2 22/32] iommu: Implement IOMMU FLB retrieve and finish ops 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 implementation of the IOMMU LU FLB retrieve and finish ops. During retrieve walk through the preserved objs nodes and restore each folio. Also recreate the FLB obj. Signed-off-by: Samiullah Khawaja --- drivers/iommu/liveupdate.c | 48 +++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/liveupdate.c b/drivers/iommu/liveupdate.c index 5780761a7024..0dfa03673178 100644 --- a/drivers/iommu/liveupdate.c +++ b/drivers/iommu/liveupdate.c @@ -14,6 +14,17 @@ #include #include +static void iommu_liveupdate_restore_objs(u64 next) +{ + struct iommu_objs_ser *objs; + + while (next) { + BUG_ON(!kho_restore_folio(next)); + objs = __va(next); + next = objs->next_objs; + } +} + static void iommu_liveupdate_free_objs(u64 next, bool incoming) { struct iommu_objs_ser *objs; @@ -98,11 +109,46 @@ static void iommu_liveupdate_flb_unpreserve(struct liveupdate_flb_op_args *argp) static void iommu_liveupdate_flb_finish(struct liveupdate_flb_op_args *argp) { + struct iommu_lu_flb_obj *obj = argp->obj; + + if (obj->iommu_domains) + iommu_liveupdate_free_objs(obj->ser->iommu_domains_phys, true); + + if (obj->devices) + iommu_liveupdate_free_objs(obj->ser->devices_phys, true); + + if (obj->iommus) + iommu_liveupdate_free_objs(obj->ser->iommus_phys, true); + + folio_put(virt_to_folio(obj->ser)); } static int iommu_liveupdate_flb_retrieve(struct liveupdate_flb_op_args *argp) { - return -EOPNOTSUPP; + struct iommu_lu_flb_obj *obj; + struct iommu_lu_flb_ser *ser; + + obj = kzalloc(sizeof(*obj), GFP_ATOMIC); + if (!obj) + return -ENOMEM; + + mutex_init(&obj->lock); + BUG_ON(!kho_restore_folio(argp->data)); + ser = phys_to_virt(argp->data); + obj->ser = ser; + + iommu_liveupdate_restore_objs(ser->iommu_domains_phys); + obj->iommu_domains = phys_to_virt(ser->iommu_domains_phys); + + iommu_liveupdate_restore_objs(ser->devices_phys); + obj->devices = phys_to_virt(ser->devices_phys); + + iommu_liveupdate_restore_objs(ser->iommus_phys); + obj->iommus = phys_to_virt(ser->iommus_phys); + + argp->obj = obj; + + return 0; } static struct liveupdate_flb_ops iommu_flb_ops = { -- 2.52.0.158.g65b55ccf14-goog