From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 8A56F382381 for ; Mon, 18 May 2026 17:06:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779123980; cv=none; b=hexVYeTMfwOEE1Tsp+FNZF4ThKz67vTlUXUGyLZqV3WBQrr0y88WAu+qYjUHzx1ALNOYyTT8gBP/Iw89lOElVa1wzaAY+DoBMIRJCXuAiBzGmWge7TrChU+VNVlbzMGojTGYoOgQrr8+EXyvlh2PY7q5nNFjuO2XI2Xcxyc+HJA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779123980; c=relaxed/simple; bh=t9OxCZoF6YbRVKylmH+0HlyPwlgHH9K8/ORJEjD0asQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jQddxLg7lTw1O7mJcRPa46ZluRuwiE4IGVxZLjQ3rEHy/ohvzgWHg+3e1+nY0vchpRfTK0jjxNZDvt9g8cu/mdRSSxrV1/fd5273FpWEhN+bWHmmJHQIVXVsJDFPp3eczGc/dek2KGniTZbIbv2vgNZijsFi0fOA20O/XGgfYhY= 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=G6zuTYc/; arc=none smtp.client-ip=209.85.214.169 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="G6zuTYc/" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2ba180a022dso535ad.1 for ; Mon, 18 May 2026 10:06:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779123978; x=1779728778; 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=dkqatbApjTcUOlv+bi7ee5TYL+ejmFz/3nd+bMkwd8c=; b=G6zuTYc/FtnON0JY02TCs4XR9U267YypH7Z1jT04n6GNM+98bGeIUXzEvbVNconrjl N2Q6lWET2HAJAJen+s1Vq9R5gzoD/V/g0JxmFGt/Kx10JZvLGdRhqYtXPBmx8QReli4z AW6EeZAk5MH5aDnxTTDxjvlVxUsMQf+epPnrYbb2Felzl7yZ5/GE5xWt0umrAyoPcoVj 4dNOGdMiR5Y/YmLiMjG3bxBXzhsE/iO2Smvrd6+pR4yvYtAWh8tCo2469oWmbdPnMVdB TOLj/RoVq7U77VAHiEoOt2d2p1wAz1luhSH6yA/27N3EHdzwY/YUf9Z99Ma+OCI9NoB5 zyeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779123978; x=1779728778; 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=dkqatbApjTcUOlv+bi7ee5TYL+ejmFz/3nd+bMkwd8c=; b=QsjzMat2PxY/mbvF49HT19qPMX+yUdIXcyHVuO/uBxTu6kuqQDl+U+iIqP183kv5zc RI9dkb9y1F6eMzuvnDQwgfvFfzUaJpb3o33aV4LBve3JjOKnVXgI8hXQOSDbmwxoOVcl p64vA0b1RKakiTqy3JbGTOwBm/Zh+cr3zTF6QqxtXvr/rdQGG7R/3MPmxvqWJ1rgcDwP jJ+JIMqea+rG/eYKvqx4iCnZH0gTVxJL9ZZxV4rEl1FuO0Bckrq2q8ykmKP/NCkROOE4 DtuYZhYoKqjWOkFvRF6kVo7ODIMzLGaJhzeAH8Zwqpinx7kv+o4FThp1MVx8juV+HjK1 MC4Q== X-Forwarded-Encrypted: i=1; AFNElJ94T6FSIkbxLhuDiQggCh13i/4X18GOQF0yVGL7BqN0PstdUfbLvkcnW/u97B7V42A1MiigQ0KQeNS1qDA=@vger.kernel.org X-Gm-Message-State: AOJu0YyT7sutfXjufx8jx631TI1QOEIoVwBDVkrIO2cwt5pO70UbvxEC UZ+MbtfLj+8Z0s9+iWktM5iEMOMZ3yXWdSgWkTvc7cM7V+NpO1Ul3XKYGpB18kzTjA== X-Gm-Gg: Acq92OH1M1dPUkw4PRhMJXLJ5H20ryswFhisS7g668n9RggfymydHroeILt1ZfsnsDS F+tdQMWss/0d9mcDZ2+qvK47CPIWb+1TGLOJ6R4pmFS6ylRopR7yXjO2yEEgueqb/uGxLIIHJHn W4/OcNcF5MlY6TukQTs/naVijwAxDHDxiEw0grHh6xxh7420dqhOCepU0YAG7I+S78IJfYDKZiZ EpZTGeSU23O2PjiGgwzUtmbdpf9cLswUcPC1ZXWOdF1ongTbzOK/FTICDUicqHBb+V9WBKbqRp5 UywtmiizaKFUwYJmubI8c33VEwOZR95p8LYGFvKklPQs0UPY7uSczrV2jMa5En1PFovZJlw2np/ h68HFcBU/pIo5Z0bzzJgWwWCe2cXCjgeaaEVsXUMfIStQOfyJFw20VHpJsn9YV4rk7kR63o359Z OoPgLYo4vyKFYoW5UCfw4zHEPeSkRtYqP+fQgj88t0cAdnsLsx5h/N2tMj70TldZBca0Ro5w== X-Received: by 2002:a17:903:37d0:b0:2b7:b03d:9dce with SMTP id d9443c01a7336-2bdb041671dmr3410875ad.18.1779123977360; Mon, 18 May 2026 10:06:17 -0700 (PDT) Received: from google.com (153.46.83.34.bc.googleusercontent.com. [34.83.46.153]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3695a09e95esm4591161a91.9.2026.05.18.10.06.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 10:06:16 -0700 (PDT) Date: Mon, 18 May 2026 17:06:12 +0000 From: Samiullah Khawaja To: David Matlack 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; format=flowed Content-Disposition: inline In-Reply-To: On Fri, May 01, 2026 at 09:45:19PM +0000, David Matlack wrote: >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. This one is a little tricky, it is not really fatal as it doesn't represent a corruption or unexpected behaviour. I think if this fails the probe of IOMMUs should fail and with a rescan, the user can retry this. I will handle this properly in the caller to make sure a retry can happen for these. > >> + >> + /* 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, Agreed. I will do this. > >> 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. Agreed. Will do. > >> + >> +/** >> + * 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. Agreed on both points. I think it can be moved to liveupdate.c. Will do. Thanks, Sami