Hi Pratyush, Thanks for reviewing!
On Wed, Apr 02, 2025 at 19:16:27 +0000, Pratyush Yadav <ptya...@amazon.de> wrote: > Hi Changyuan, > > On Wed, Mar 19 2025, Changyuan Lyu wrote: > > [...] > > +int kho_preserve_phys(phys_addr_t phys, size_t size) > > +{ > > + unsigned long pfn = PHYS_PFN(phys), end_pfn = PHYS_PFN(phys + size); > > + unsigned int order = ilog2(end_pfn - pfn); > > This caught my eye when playing around with the code. It does not put > any limit on the order, so it can exceed NR_PAGE_ORDERS. I agree with Mike that this should not be a problem. > Also, when > initializing the page after KHO, we pass the order directly to > prep_compound_page() without sanity checking it. The next kernel might > not support all the orders the current one supports. Perhaps something > to fix? Yes the new kernel should check the order. > > + unsigned long failed_pfn; > > + int err = 0; > > + > > + if (!kho_enable) > > + return -EOPNOTSUPP; > > + > > + down_read(&kho_out.tree_lock); > > + if (kho_out.fdt) { > > + err = -EBUSY; > > + goto unlock; > > + } > > + > > + for (; pfn < end_pfn; > > + pfn += (1 << order), order = ilog2(end_pfn - pfn)) { > > + err = __kho_preserve(&kho_mem_track, pfn, order); I realized another bug here: we did not check if "pfn" is aligned to 1 << order. For example, if the function input is @phys = 4096, @size = 8192, in the 1st iteration, pfn = 1, end_pfn = 3, order = 1. This is problematic since these 2 pages should be viewed as 2 folios of order 0, instead of 1 folio of order 1. > > + if (err) { > > + failed_pfn = pfn; > > + break; > > + } > > + } > [...] I will fix the 2 bugs above in V6. Best, Changyuan