From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 E3793384250 for ; Mon, 18 May 2026 17:20:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779124847; cv=none; b=aPtUmiY2NX2NUC40bMoDqPwPrz2r0y5IUdBBTCoV5+SpQHpxHrpGvj5zEfzBgiQJSq5NNl4lIr0jtzSKtiS8PtDMymGaaWbbmEQ+8n3EM1+6zm42/3+495EWUc6xhtsVjMlSKElMI9QOYwyd7A9AIBwPLeb0Pdy59ymDeD8feBY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779124847; c=relaxed/simple; bh=dj6sO1dq24qPoPg8t/jjU62zkoEGx+WZ2bGv3+pLqUg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DXE3IWrbWEeYVR1hKftiFqVAa3PynoRXOptQCCgiObj0LCw7gDLKocgWQ3Gl/RqfMqV7ZfNQ0YUm3KgzzmHsgWxu8iJ6frKpi/92rxQkVPG6jUzXJ8TfCrlN2+mQZZPXq/sl9yV+r6aiSh0vrzCLQx3x++1vgmHZk7HOkRLoc38= 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=H57uDpav; arc=none smtp.client-ip=209.85.214.181 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="H57uDpav" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2ba3b9bcf69so1435ad.0 for ; Mon, 18 May 2026 10:20:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779124845; x=1779729645; 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=wacrkWwKLVRP9x12vc+54brUCUoi0SSZqKwPJxVr82E=; b=H57uDpav90R/HDZlCXbI/iK4j/NMjkoccn2Pqy+GNNnf5DEI0KgfDi3zw9Ysr4k1lN +RL7HYpShgEZbH1v59JjhlyizYBisSJgr1S3mVgSRKbKh2vDQiaG/fGzsiCFXRVAsN5r 2kTfWXJdiMdKKmHfhWrEkKzq4Mb2etuD6UXxfPsxEg4L0Pd7iOKFtOFXTcJ8k3DaOSQx XVaF7kg4flVpLxgulgZbhvCUQIg8LvpbPcRZ7D0cbmeeqJTf07VC9XhEDayef27ny6tO LYyB+LZGPoJmtdI6/nJEgflvNhGyuzkHZgZJNOdTZSNEFcLoBWT6w4bOLFsRiVfWSyFJ JmrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779124845; x=1779729645; 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=wacrkWwKLVRP9x12vc+54brUCUoi0SSZqKwPJxVr82E=; b=RR1q5cM4AU5dSbdSyz+K4L8buZ/2L8I0K5vxX2mwVU8lo1UiVaZkPXSsW1b713O/CM 8j+Goa0iiOUpioZhwS/Sx0mb6g/mYZklKZieZYMQ0dkw6broCd6GplAJ3XMYohAJMXYF jC6Q/JbOL+cwGPFgpJ8Fv1VEVB+QkloiG83GJAirhY3QV4zeXbjx6Rl4pcPCX1QX9xMH ilwJny0vhr2hL6WJm/zS18AkjudiV8a7NUwLXlRHABPnb2AKQG0TBB+n1RXi7OsiBe6I Z6ACU7RaK1L/ELfDWGJZswQFQ2o/HXvLrKxiGXn/Ugqufm6v8Fxt8ppaCvYe8B65LbYo Gubg== X-Forwarded-Encrypted: i=1; AFNElJ8RYlhN5erR3aHKQjgIg3Dkid0fniUuSmQTrkVLSFmEW0kyH0xa6QEhOGeDx6fusmcXp+5cSObh18n6+lc=@vger.kernel.org X-Gm-Message-State: AOJu0Yy1HAul/kxTZTNS2b/QrQyOMgqD7iVc54RmbeHAesbuiKrRK+R3 VjoB+cRXcF6T+Vz0TUc+sClCJquwMWQS1HPYd84GjEP6PRND68WZzaipqik3Cdqk6A== X-Gm-Gg: Acq92OEAq60C8s1/Vsw6bmDLLI3ECFY5h5GSnKouEWuLqR4L2A8b07pQrzI2gKYjO+u oJ9QcoiQDjTc7t6xgWUJqq7ljd+nJo7KyV1Nd6osiIZYFYAAdJ9CZDknVMc1VOT8PNwm4JT9qGz 4Z2dUCP7c78pc1/PgNJZwC4Si9iUpjzBrm3z/vvDpJI9JTrL+n9WFC4szN+1BcJHSdCSILKMBkT XVuDL5HlT3zcB0EGl6tTyCSiSdU8Nt+apnO+P9PQ0+geuRag4Q5HP/uwALrl6XY7oMStjNj/bun fcHg/7CZNQtQ/4ZhgqjUIQHa3nvJ4cZNjFw/grTzTWOpYOu+WDVjgdjnB2pNmkFi4zi7f43OHkT Fixfpibxi8i/EJgy6U1xaI1ixvjhOlPrWMy5PG4iz0E8VfrXMkEr3eS/K7IXpIoNassw6Qw4TlP OX0Tdu8uAjcJiyKmzxJT+vfwe4dI470IKHjvBYULPmCn4Nb3MM7SUlIeyJ9f68bY4I84AjUjgJw spE3Lh1 X-Received: by 2002:a17:903:3205:b0:2b0:5193:1212 with SMTP id d9443c01a7336-2bdb03a2d06mr3134135ad.4.1779124844385; Mon, 18 May 2026 10:20:44 -0700 (PDT) Received: from google.com (153.46.83.34.bc.googleusercontent.com. [34.83.46.153]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-83f196660f9sm19017886b3a.10.2026.05.18.10.20.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 10:20:43 -0700 (PDT) Date: Mon, 18 May 2026 17:20:40 +0000 From: Samiullah Khawaja To: Pranjal Shrivastava Cc: David Matlack , 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 , 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 Mon, May 18, 2026 at 12:33:25PM +0000, Pranjal Shrivastava wrote: >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. >> > >Righ... Nice catch. I suppose we should BUG_ON() this because >luo_flb_file_finish_one [1] returns void. Thus, if we return -ENOMEM >here all we get is a WARN_ON without panic. The error is propagated by get_flb_incoming(). The finish path has a WARN. But that is fine because finish won't be called as can_finish() will fail if FLB retrieve fails and restore cannot be done. I will add a comment about this here. > >We can't statically allocate obj in liveupdate_flb_op_args because obj >is a void ptr. I believe we must add a BUG_ON() here. > >> > + >> > + /* 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; >> > +} > >Thanks, >Praan > >[1] https://elixir.bootlin.com/linux/v7.1-rc3/source/kernel/liveupdate/luo_flb.c#L208