On Tue, Jun 02, 2026 at 06:46:12PM +0800, Guanghui Feng wrote:
> +static __always_inline int __do_iova_to_phys_length(struct pt_range *range,
> +                                            void *arg, unsigned int level,
> +                                            struct pt_table_p *table,
> +                                            pt_level_fn_t descend_fn)
>  {
>       struct pt_state pts = pt_init(range, level, table);
> -     pt_oaddr_t *res = arg;
> +     struct iova_to_phys_length_data *data = arg;
>  
>       switch (pt_load_single_entry(&pts)) {
>       case PT_ENTRY_EMPTY:
> @@ -159,45 +164,53 @@ static __always_inline int __do_iova_to_phys(struct 
> pt_range *range, void *arg,
>       case PT_ENTRY_TABLE:
>               return pt_descend(&pts, arg, descend_fn);
>       case PT_ENTRY_OA:
> -             *res = pt_entry_oa_exact(&pts);
> -             return 0;
> +             break;
>       }
> -     return -ENOENT;
> +
> +     data->phys = pt_entry_oa_exact(&pts);
> +     data->length = log2_to_int(pt_entry_oa_lg2sz(&pts));

I really do want this to accumulate the contiguous length if we are
changing things like this.

As I said before only iommufd needs to do this, the other drivers
don't have to, but the wrapper should take care to give a consistent
result so we don't have callers open coding another inefficient loop
on top.

vfio and iommufd should call it exactly once and then move on.

Jason

Reply via email to