From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.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 9AD84EEC3 for ; Fri, 1 May 2026 21:45:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777671926; cv=none; b=JBRfDnrdy3ejM0P8wWyfI0ZY8zXJm7Jcf2c2WMkcUFb364icgZD9lRBTnx6uFH8Wwjzqg+5wYkvWkp3D4mz5iVedul07faZ1l5hzJXJpMQsJ90xNyuz8XruYDSIpdPx8Olh+nMHl7yyXdsLTgYj8hvHdmDbx60GrBdRWHO8VLTI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777671926; c=relaxed/simple; bh=wONl8ymJLcFAu45GW0iEPDy4OF4pO+1gALRXgGMmCEY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=A30m7Y+5W8D9xsKlxwB4OxVB1ARnMOEJVCi0U/QAT9HDlAvsX/lpLha089szHtwdIUmDF2N2ylqf+8CHsl0uweAA4U4O/MQ8D+kydBM8wECCXhQLuBR0ReC+Q/ZBBHYvDmdOLHLxNg6TaSNLS/AFiLWPb3g/nJuVTQbv35So4cI= 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=ZKgGaWTx; arc=none smtp.client-ip=209.85.210.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="ZKgGaWTx" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-82d0b68837aso1323027b3a.2 for ; Fri, 01 May 2026 14:45:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777671925; x=1778276725; 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=EnSyBxXT0t6Az3EuJiRgBhCI9ryWONltfzcDE6vjMFY=; b=ZKgGaWTxKfYu93BepUC43B/BeNI2w/pUGHScvrZ2zsZoxhdKMvv4a3fP4wPgFs7S9x CErMgdhDA0txv19HVKk5rqNJkMNbYJCAY38mQv0ZgpUsx8L4U6UZ/f+Xhc5FO1IiuKme TMqR3LXUFtpmJF0z2+IK2VDx+7prsjegvBoLtn1FwtdKEQyUlQWKR5lq+JgDxh0AlMrL buBtlGKS2rrHdTloaTwZzaya3gggAiZDoL4jiLjK+v7IyyaarFZuaxwwCDDO2baCM7yc 571HhtbjzpDmKUt8cPMkhn/9rqOueS5+cSZI0sMg4+PT4KKxy0tkc2xHI1KSS/HrnmAh YVNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777671925; x=1778276725; 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=EnSyBxXT0t6Az3EuJiRgBhCI9ryWONltfzcDE6vjMFY=; b=smJ12ukuH+2n7vC/wFZhVFLi2gY04Ybj8wenX6LeNkjNTzQ7K63Ya1RBuTL5Ic7EDN N+kWUClE149hn4m9XaA+6dPPY9mOdQzC9ugIxHzWA9r8gua6u84ui3g4y802oBeU9lN9 ZPAxqjPE7vi0/UzUM0M+P/iS6WszSAr8NfzTzIrcjmvHH/qRnOoaH6P4dP7CipgqbEir hg91r+qkK71+S9GWGNjdDWcNiw31U0taYcP+0gkd1wbvno5qDYxcDJZv3OZZwP9HpIeo +4fz1TkjJ7Rm0xjzCiC0siCQ3KjbFGviV1VuXXNMqD1F8c2NgMvm2HpCFFN4yb2tt4s9 azQA== X-Forwarded-Encrypted: i=1; AFNElJ/SIxOj7UD2X0lDiXQXFZKR/3ZL3IfxwgoKoL7nk0lEoJL1hmRIZeL8CSzQpk100YsQqd5gZeZvx0ZtNAg=@vger.kernel.org X-Gm-Message-State: AOJu0YwN1INkObEzl7P3RHl82aajZLMYXWp9J/v8B9/mgKBXjVIGssh3 gJDZdnBmv+fw8heSgDlalsqbVfukECeUUJw58UTYC7y35bGX2YkOcvdc/PJwbbG/Eg== X-Gm-Gg: AeBDievVP1JIj6Bq717ufghnbkQp3FdweRwW0eGEr7SExPxWLiM/ZRM5PxTMzDBeoDD QIG2x/5o3xRx5WNEkjHgy0lE/ADgdIA3qyXrZG5CRlPM+YD/xJ6tLh52Vv0pz3iKvMy3Yp+5511 ga97HmNLYGl/eC5/mInkgNaMLI3SdLhaEPKgaRMWdwQ3JOVChmRLrGZO1EBDD4JVVIN+q9IYl/B TsDcLC66x4dQ6HPWMKFGjaUc5WYhwLVoiU8cWlCyeAtk4ar6aDU0irsZQaLSJGMGOxr5ln0TVwB boh5sHuITy1mWNbWvTM389mDwDfoYvl4eXaiBTzNq+nNm3Ta7JxWw66Yhhmo0LdCEolH2gn0V2p vU8+5mUEDU1Fp4XcpmyAjL8l3OVz52huVAczmc54I/MYFKssiFJCmDmo8M7FnvN26XJbH1XF9W4 MBqIAG792tgo7bHeyNHCITzsmCfZ78baPH618jWaCgjq3wLpdb7t3d+bKrFsPMSBtnnSa6BTepY +Gs/A== X-Received: by 2002:a05:6a00:1d8d:b0:82a:7734:8c6a with SMTP id d2e1a72fcca58-8352d371a37mr648847b3a.48.1777671924329; Fri, 01 May 2026 14:45:24 -0700 (PDT) Received: from google.com (76.9.127.34.bc.googleusercontent.com. [34.127.9.76]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-83515ad0049sm4007877b3a.33.2026.05.01.14.45.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 May 2026 14:45:23 -0700 (PDT) Date: Fri, 1 May 2026 21:45:19 +0000 From: David Matlack 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 , Andrew Morton , Chris Li , Pranjal Shrivastava , Vipin Sharma , YiFei Zhu Subject: Re: [PATCH v2 02/16] iommu: Implement IOMMU Live update FLB callbacks Message-ID: References: <20260427175633.1978233-1-skhawaja@google.com> <20260427175633.1978233-3-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: <20260427175633.1978233-3-skhawaja@google.com> On 2026-04-27 05:56 PM, Samiullah Khawaja wrote: > Add liveupdate FLB for IOMMU state preservation. Use KHO preserve memory > alloc/free helper functions to allocate memory for the IOMMU Live update > FLB object and the serialization structs for device, domain and iommu. > > During retrieve, walk through the preserved obj array headers and > restore each folio. Also recreate the FLB obj. > > Signed-off-by: Samiullah Khawaja > +static void *iommu_liveupdate_restore_array(u64 array_phys) > +{ > + struct iommu_array_hdr_ser *array_hdr; > + void *vaddr = array_phys ? phys_to_virt(array_phys) : NULL; > + > + while (array_phys) { > + /* > + * Failure to restore preserved IOMMU state is considered fatal. > + * > + * This is because the IOMMU translations for preserved IOMMUs > + * were kept enabled in the previous kernel and the preserved > + * devices have their IOMMU domains still present. Not being > + * able to restore means that the memory mapped into preserved > + * domains might be already corrupted by the preserved devices. > + * > + * There is no way to confirm the integrity of the memory that > + * was mapped. BUG_ON is the safest option at this point. > + */ > + BUG_ON(!kho_restore_folio(array_phys)); > + array_hdr = phys_to_virt(array_phys); > + array_phys = array_hdr->next_array_phys; > + } > + > + return vaddr; > +} > +static int iommu_liveupdate_flb_retrieve(struct liveupdate_flb_op_args *argp) > +{ > + struct iommu_flb_obj *obj; > + struct iommu_flb_ser *ser; > + > + obj = kzalloc_obj(*obj, GFP_KERNEL); > + if (!obj) > + return -ENOMEM; Should this be considered fatal for the same reason iommu_liveupdate_restore_array() is considered fatal? If anything in iommu_liveupdate_flb_retrieve() fails then the risk of corruption as described in iommu_liveupdate_restore_array() is possible. > + > + /* Data must be present and valid from the previous kernel */ > + BUG_ON(!kho_restore_folio(argp->data)); > + > + mutex_init(&obj->lock); > + ser = phys_to_virt(argp->data); > + obj->ser = ser; > + > + obj->curr_domain_array = iommu_liveupdate_restore_array(ser->iommu_domain_array_phys); > + obj->curr_device_array = iommu_liveupdate_restore_array(ser->device_array_phys); > + obj->curr_iommu_array = iommu_liveupdate_restore_array(ser->iommu_array_phys); > + argp->obj = obj; > + return 0; > +} > + > +static struct liveupdate_flb_ops iommu_flb_ops = { > + .preserve = iommu_liveupdate_flb_preserve, > + .unpreserve = iommu_liveupdate_flb_unpreserve, > + .finish = iommu_liveupdate_flb_finish, > + .retrieve = iommu_liveupdate_flb_retrieve, nit: I think it's helpful to put these in the order they are expected to be called. .preserve = iommu_liveupdate_flb_preserve, .unpreserve = iommu_liveupdate_flb_unpreserve, .retrieve = iommu_liveupdate_flb_retrieve, .finish = iommu_liveupdate_flb_finish, > diff --git a/include/linux/kho/abi/iommu.h b/include/linux/kho/abi/iommu.h > new file mode 100644 > index 000000000000..37b967820f14 > +enum iommu_type_ser { > + IOMMU_INVALID, > +}; Please document this enum. > + > +/** > + * struct iommu_hdr_ser - Common header for all serialized IOMMU objects > + * @ref_count: Reference count for the object > + * @deleted: Flag indicating if the object is deleted > + * @incoming: Flag indicating if the object was preserved in previous kernel > + */ > +struct iommu_hdr_ser { > + u32 ref_count; > + u32 deleted:1; > + u32 incoming:1; Are C bitfields safe to use in Live Update ABI? > +} __packed; > +/** > + * struct iommu_flb_obj - FLB object allocated in current kernel pointing to > + * preserved state in FLB > + * @lock: Mutex protecting the object > + * @ser: Pointer to the serialized state in FLB > + * @curr_iommu_array: Pointer to the current array of IOMMU instances > + * @curr_domain_array: Pointer to the current array of domains > + * @curr_device_array: Pointer to the current array of devices > + */ > +struct iommu_flb_obj { > + /* @lock: Protects the serialized objects during concurrent preservation */ > + struct mutex lock; > + struct iommu_flb_ser *ser; > + > + struct iommu_hw_array_ser *curr_iommu_array; > + struct iommu_domain_array_ser *curr_domain_array; > + struct iommu_device_array_ser *curr_device_array; > +} __packed; This struct is not ABI so it should not be __packed nor defined in this file. I haven't read the whole series yet but this definition can probably go in drivers/iommu/liveupdate.c.