From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 403CF3815D4 for ; Mon, 18 May 2026 17:22:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779124939; cv=none; b=nIsBf5h6Iez43DuvzXmMglI1dSFETFomJbknm/t9+uiYhrUxo5LtSD0B6Od93skN/BD7woN1r234VCt3bG+f7Ps6Btnssq9cmgC+IbIH0R2nrxq8oguOASRVPaY6BRZJtvOxvwtl6qA9Llhvgm+yABNIiXax5KfdK4nYKMm7qQ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779124939; c=relaxed/simple; bh=kvzoRRtRkt99R85TCv6fmYGvBN6W9hGpuH3oahXqcoc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VkRlm2ezgWnw4yq4LTZaNs5XdTP0mNq1hEwTSMkg7IJk2+QQfYMwgO0zytiJ4/pWQeK4h7/uRVSkDAkq5S8xCp+262E/j6NuBDDjY2ndeFPxsMQ01Lz0+zljxdcfzG75CQpdwvel8Xi1fuVdnzGekF9Gy+lokuzINrMUvPkIXWs= 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=wRnmEKV7; arc=none smtp.client-ip=209.85.214.170 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="wRnmEKV7" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2ba3b9bcf69so1705ad.0 for ; Mon, 18 May 2026 10:22:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779124937; x=1779729737; 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=GOpQmNzrJoZpllcvwCwLtMCpq7AcJeE0RS7V56u/5aU=; b=wRnmEKV7Gn0+cpKGfju2xG6LMM21L+rDxOwYGAQMXQikqVzr97GMtlp5V6Uvu9zjup 4m6KZZNQK6U+cyg9vkJHZqwOfJgA6DSlP2eHfYAiaaLN1li85tzlCotjE31t79YdEBk7 pofxZ1sZyaMMl4oCcfNDIqca8/+4OtdBu1nDjizgm9Y8uyR7FnfYHxVLmHsiRr0nCuih bp0gVG/ApSSg/M+GLHpvAHAnCZCX+rng4DuQi7pBncmQ0kiu31QvngFeiGQWDDnbGEje PZw5FAIkyukpLvHfhS8bwaQWOzjiFcWjWgihPDwanZE8kkFpl7PqXx6bxAV9g/VBeO24 hvOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779124937; x=1779729737; 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=GOpQmNzrJoZpllcvwCwLtMCpq7AcJeE0RS7V56u/5aU=; b=jntl7vfw+OtEPIKn/y6OaOh3muymIBQIzpNGO42cnXIrItRZHn7LOVyGqQ+7BM+4xO Gh3jRMm7b8jK75r+En7sTyNiFhk5Wp4K8qV8yq+EHnY7ZqxdBZv8+/FRRTTM4SzeK7T3 gqbYkcF+g9A7ujBm0cjJC2+LVN5EoiW00esqv1CmlBtGz5Lf1MCSq1qts1LBPEjf9EZw q0IKZ8ppLTezEJhJTcRusS0uSnPdX8s0Q+h2ip/A+gM4OgnYBOybcJIAwFBNCb9Hb+vY ZSSz5he9kT9NDdV3ySlMiqmlPPUkdPqOk3/MXmEWezXgoJvde5NniHoeCguWJnROi4uD JO5Q== X-Forwarded-Encrypted: i=1; AFNElJ8bJDLyG+Xgf1elvjrAfE6qMVGXbP4fxBJQUVWizLt/3mVjSnmbLzorIsFHf2rILkux53k20Zqt9sgufc0=@vger.kernel.org X-Gm-Message-State: AOJu0YxV3pnXZKaw2RgDqNbHo/HMNB23sZSH0sWJiNtbWcUlc6TrdzZl OErwFkSXyxzqVWr7iX+BRKYbj6pWMo830x8DTml8D+Ymb3ZU3q/3+NE/Hzn33oCNrA== X-Gm-Gg: Acq92OFH8MHDTJhrcF58j33xH2GLeM7pFFVwlZ05Qw6ZUjSzH4oFf845h9jMo36gtvZ RvSHilpOikCIM/VIVAl7eCouNc7eMM8vSvf1JCk7veoJTjbHsx4fyXTH6xbzLh0Mrt8fvba0lcf VklA1GwCq5h6bIjfxwpMHLGWksu6RE3J0KZDcmqVmgcIm/SSUsiRY/vUVaZA1RDzJH43v3cwkH5 0thkOtUp4QIQPRyP5ijzioGRDSQBcfdJFgz+IrPW93RPwKlOsMa6dXqTBLR6nGIFF9c8N47P1yk Zf+eCdT4a+kzezrx/o9AxUm1xO1iN+K2rwJ7gbAVwL4TVyAktg+WeSwNQa0cr6c5MLxhc2+s6sf 5mZZagd5mGGSlLuYHgoAKGdy61Rp9xm4EEPC95wHM3ZybQTlNSRFHdPeHVQRy4xzG0REBmXacXN I9E6DNmjYa7r3ZkxFPwcGA//ljFvZCPco9Cvu9pZWpWZltsXcjC4Y5XUz7HlxluMrEOR5E1e1FM iOYLXao X-Received: by 2002:a17:903:228e:b0:2b0:aee4:afe7 with SMTP id d9443c01a7336-2bdb03a197bmr3385745ad.10.1779124935806; Mon, 18 May 2026 10:22:15 -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-83f1977b779sm15315177b3a.23.2026.05.18.10.22.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 10:22:15 -0700 (PDT) Date: Mon, 18 May 2026 17:22:12 +0000 From: Samiullah Khawaja To: Pranjal Shrivastava 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 , David Matlack , Andrew Morton , Chris Li , Vipin Sharma , YiFei Zhu Subject: Re: [PATCH v2 05/16] iommu/pages: Add APIs to preserve/unpreserve/restore iommu pages Message-ID: References: <20260427175633.1978233-1-skhawaja@google.com> <20260427175633.1978233-6-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 02:23:17PM +0000, Pranjal Shrivastava wrote: >On Mon, Apr 27, 2026 at 05:56:22PM +0000, Samiullah Khawaja wrote: >> IOMMU pages are allocated/freed using APIs using struct ioptdesc. For >> the proper preservation and restoration of ioptdesc add helper >> functions. >> >> Signed-off-by: Samiullah Khawaja >> --- >> drivers/iommu/iommu-pages.c | 108 ++++++++++++++++++++++++++++++++++-- >> drivers/iommu/iommu-pages.h | 30 ++++++++++ >> 2 files changed, 134 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/iommu/iommu-pages.c b/drivers/iommu/iommu-pages.c >> index 3bab175d8557..b1ffeb930e6d 100644 >> --- a/drivers/iommu/iommu-pages.c >> +++ b/drivers/iommu/iommu-pages.c >> @@ -6,6 +6,7 @@ >> #include "iommu-pages.h" >> #include >> #include >> +#include >> #include >> > >[snip] > >> + >> +/** >> + * iommu_unpreserve_pages - Unpreserve pages that were preserved in KHO >> + * @list: List of pages to unpreserve >> + */ >> +void iommu_unpreserve_pages(struct iommu_pages_list *list) >> +{ >> + struct ioptdesc *iopt; >> + >> + list_for_each_entry(iopt, &list->pages, iopt_freelist_elm) >> + kho_unpreserve_folio(ioptdesc_folio(iopt)); >> +} >> +EXPORT_SYMBOL_GPL(iommu_unpreserve_pages); >> + >> +/** >> + * iommu_restore_page - Restore a page that was preserved in KHO >> + * @phys: Physical address of a page >> + */ >> +void iommu_restore_page(u64 phys) >> +{ >> + struct ioptdesc *iopt; >> + struct folio *folio; >> + unsigned long pgcnt; >> + unsigned int order; >> + >> + folio = kho_restore_folio(phys); >> + BUG_ON(!folio); >> + >> + iopt = folio_ioptdesc(folio); >> + >> + /* >> + * For the restored pages incoherent is set to false as these are not >> + * mapped using the DMA_API. The remapping of these pages using DMA_API >> + * is not needed as these are not going to be written to by the new >> + * kernel. >> + */ > >Looks good. > >> + iopt->incoherent = false; >> + >> + order = folio_order(folio); >> + pgcnt = 1UL << order; >> + iommu_folio_update_stats(folio, pgcnt); >> +} >> +EXPORT_SYMBOL_GPL(iommu_restore_page); >> + >> +/** >> + * iommu_preserve_pages - Preserve pages during kexec handover >> + * @list: List of pages to preserve >> + * >> + * Returns 0 on success, negative error on failure >> + */ >> +int iommu_preserve_pages(struct iommu_pages_list *list) >> +{ >> + struct ioptdesc *iopt; >> + int ret; >> + >> + list_for_each_entry(iopt, &list->pages, iopt_freelist_elm) { >> + ret = kho_preserve_folio(ioptdesc_folio(iopt)); >> + if (ret) >> + goto err; >> + } >> + >> + return 0; >> + >> +err: >> + list_for_each_entry_continue_reverse(iopt, &list->pages, iopt_freelist_elm) >> + kho_unpreserve_folio(ioptdesc_folio(iopt)); >> + > >Looks good. > >> + return ret; >> +} >> +EXPORT_SYMBOL_GPL(iommu_preserve_pages); >> +#endif >> + > >[snip] > >> +static inline int iommu_preserve_pages(struct iommu_pages_list *list) >> +{ >> + return -EOPNOTSUPP; >> +} >> + >> +static inline void iommu_unpreserve_pages(struct iommu_pages_list *list, int count) > >Nit: This is inconsistent from the signature in it's counter part in >IS_ENABLED(CONFIG_IOMMU_LIVEUPDATE) Oh. I will update this in next revision > >Let's remove `int count` from the arguments to avoid broken builds. > >> +{ >> +} >> + >> +static inline void iommu_restore_page(u64 phys) >> +{ >> +} >> +#endif >> + > >With that stub argument fixed, >Reviewed-by: Pranjal Shrivastava praan@google.com Thanks Pranjal. > >Thanks, >Praan