Hi Arnd, Thanks for your review! ---- On Mon, 11 Jul 2022 21:36:12 +0800 Arnd Bergmann <arnd@xxxxxxxx> wrote --- > On Mon, Jul 11, 2022 at 2:24 PM Li Chen <me@linux.beauty> wrote: > > > +config OF_RESERVED_MEM_DIO_SUPPORT > > + bool "add Direct I/O support to reserved_mem" > > + depends on ZONE_DEVICE && ARCH_KEEP_MEMBLOCK > > + help > > + By default, reserved memory don't get struct page support, which > > + means you cannot do Direct I/O from this region. This config takes > > + uses of ZONE_DEVICE and treats rmem as hotplug mem to get struct > > + page and DIO support. > > This probably does not need to be user visible, it's enough to select it from > the drivers that need it. When you say "user visible", do you mean the config can be dropped or something else like Kconfig type other than bool? > > > @@ -72,7 +72,6 @@ void __init fdt_reserved_mem_save_node(unsigned long node, const char *uname, > > rmem->size = size; > > > > reserved_mem_count++; > > - return; > > } > > This change is not wrong, but it does not belong into the same patch > as the rest, just drop it. > > > +/** > > + * get_reserved_mem_from_dev() - get reserved_mem from a device node > > + * @dev: device pointer > > + * > > + * This function look for reserved_mem from given device. > > + * > > + * Returns a reserved_mem pointer, or NULL on error. > > + */ > > +struct reserved_mem *get_reserved_mem_from_dev(struct device *dev) > > +{ > > + struct device_node *np = dev_of_node(dev); > > + struct device_node *rmem_np; > > + struct reserved_mem *rmem = NULL; > > + > > + rmem_np = of_parse_phandle(np, "memory-region", 0); > > + if (!rmem_np) { > > + dev_err(dev, "failed to get memory region node\n"); > > + return ERR_PTR(-ENODEV); > > + } > > + > > + rmem = of_reserved_mem_lookup(rmem_np); > > + if (!rmem) { > > + dev_err(dev, "Failed to lookup reserved memory\n"); > > + return ERR_PTR(EINVAL); > > This needs to be a negative error code rather than the positive EINVAL. > No need to initialize rmem=NULL first if you override it here. > > > + if (likely(reserved_mem_dio_in_region(pfn << PAGE_SHIFT, PAGE_SIZE, rmem) < > > + 0)) > > + goto out; > > It's not performance critical, so just drop the 'likely()' and put the > rest into one line. > > > > + if (page) { > > + *page = pfn_to_page(pfn); > > + get_page(*page); > > + } > > + > > + ret = 0; > > + > > +out: > > + pte_unmap(pte); > > + return ret; > > +} > > Should you perhaps return an error when 'page' is NULL? > > > +#ifdef CONFIG_OF_RESERVED_MEM_DIO_SUPPORT > > +int reserved_mem_dio_mmap(struct file *file, struct vm_area_struct *vma, struct reserved_mem *rmem); > > +void *reserved_mem_memremap_pages(struct device *dev, struct reserved_mem *rmem); > > +#endif > > The '#ifdef' check can be dropped here, declarations are normally > not hidden like this. > > Arnd > These will be fixed in v2. Regards, Li