[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH v2 03/11] IOMMU/MMU: enhance the call trees of IOMMU unmapping and mapping



>>> On 27.04.16 at 10:49, <quan.xu@xxxxxxxxx> wrote:
> On April 25, 2016 5:51 PM, Jan Beulich <JBeulich@xxxxxxxx> wrote:
>> >>> On 18.04.16 at 16:00, <quan.xu@xxxxxxxxx> wrote:
>> > --- a/xen/arch/x86/mm.c
>> > +++ b/xen/arch/x86/mm.c
>> > @@ -2467,7 +2467,7 @@ static int __get_page_type(struct page_info
>> *page, unsigned long type,
>> >                             int preemptible)  {
>> >      unsigned long nx, x, y = page->u.inuse.type_info;
>> > -    int rc = 0;
>> > +    int rc = 0, ret = 0;
>> >
>> >      ASSERT(!(type & ~(PGT_type_mask | PGT_pae_xen_l2)));
>> >
>> > @@ -2578,11 +2578,11 @@ static int __get_page_type(struct page_info
>> *page, unsigned long type,
>> >          if ( d && is_pv_domain(d) && unlikely(need_iommu(d)) )
>> >          {
>> >              if ( (x & PGT_type_mask) == PGT_writable_page )
>> > -                iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)));
>> > +                ret = iommu_unmap_page(d, mfn_to_gmfn(d,
>> > + page_to_mfn(page)));
>> >              else if ( type == PGT_writable_page )
>> > -                iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
>> > -                               page_to_mfn(page),
>> > -                               IOMMUF_readable|IOMMUF_writable);
>> > +                ret = iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
>> > +                                     page_to_mfn(page),
>> > +
>> > + IOMMUF_readable|IOMMUF_writable);
>> >          }
>> >      }
>> >
>> > @@ -2599,6 +2599,9 @@ static int __get_page_type(struct page_info
>> *page, unsigned long type,
>> >      if ( (x & PGT_partial) && !(nx & PGT_partial) )
>> >          put_page(page);
>> >
>> > +    if ( unlikely(ret) )
>> > +        rc = ret;
>> 
>> Please don't overwrite the more relevant "rc" value in situations like this 
> in
>> case that is already non-zero. In this specific case you can actually get 
> away
>> without introducing a second error code variable, since the only place rc 
> gets
>> altered is between the two hunks above, and overwriting the rc value from
>> map/unmap is then exactly what we want (but I'd much appreciate if you
>> added a comment to this effect).
>> 
> 
> 
> Make sense. 
> I hope I have got your point.. then, I will modify it as below:

But I screwed it up. Looking at it as you have it:

> --- a/xen/arch/x86/mm.c
> +++ b/xen/arch/x86/mm.c
> @@ -2578,11 +2578,11 @@ static int __get_page_type(struct page_info *page, 
> unsigned long type,
>          if ( d && is_pv_domain(d) && unlikely(need_iommu(d)) )
>          {
>              if ( (x & PGT_type_mask) == PGT_writable_page )
> -                iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)));
> +                rc = iommu_unmap_page(d, mfn_to_gmfn(d, page_to_mfn(page)));
>              else if ( type == PGT_writable_page )
> -                iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
> -                               page_to_mfn(page),
> -                               IOMMUF_readable|IOMMUF_writable);
> +                rc = iommu_map_page(d, mfn_to_gmfn(d, page_to_mfn(page)),
> +                                    page_to_mfn(page),
> +                                    IOMMUF_readable|IOMMUF_writable);
>          }
>      }
> 
> @@ -2593,6 +2593,8 @@ static int __get_page_type(struct page_info *page, 
> unsigned long type,
>              page->nr_validated_ptes = 0;
>              page->partial_pte = 0;
>          }
> +
> +        /* Overwrite the rc value from IOMMU map and unmap. */
>          rc = alloc_page_type(page, type, preemptible);
>      }

... it is clear that this is wrong: You'd now also discard an error from
the map/unmap with possible success coming back here. I.e. you
want to overwrite the earlier rc only when you get a non-zero value
back here.

> btw, I am clumsy at comment, I'd be pleased if you could help me enhance it.

With the above, the comment is not needed anymore.

> What about:
> 
> +        if ( rc )
> +            printk(XENLOG_WARNING
> +                   "iommu_hwdom_init: IOMMU mapping failed for dom%d.",
> +                   d->domain_id);
> 
> If this is still not what you want, could you help me enhance it and I can
> follow it as a pattern. Sorry to bother you with such a case.

Looks okay.

Jan

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.