Message ID | cea2307f-1aae-51cb-20ac-fbaf4b945771@suse.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | x86/mem-paging: misc cleanup | expand |
On Thu, Apr 23, 2020 at 10:37:06AM +0200, Jan Beulich wrote: > The condition of the second can be true only if the condition of the > first was met; the second half of the condition of the second then also > is redundant with an earlier check. Combine them, drop a pointless > local variable, and re-flow the affected gdprintk(). > > Signed-off-by: Jan Beulich <jbeulich@suse.com> Reviewed-by: Roger Pau Monné <roger.pau@citrix.com> > > --- a/xen/arch/x86/mm/p2m.c > +++ b/xen/arch/x86/mm/p2m.c > @@ -1808,6 +1808,8 @@ int p2m_mem_paging_prep(struct domain *d > /* Allocate a page if the gfn does not have one yet */ > if ( !mfn_valid(mfn) ) > { > + void *guest_map; > + > /* If the user did not provide a buffer, we disallow */ > ret = -EINVAL; > if ( unlikely(user_ptr == NULL) ) > @@ -1819,22 +1821,16 @@ int p2m_mem_paging_prep(struct domain *d > goto out; > mfn = page_to_mfn(page); > page_extant = 0; > - } > - > - /* If we were given a buffer, now is the time to use it */ > - if ( !page_extant && user_ptr ) > - { > - void *guest_map; > - int rc; > > ASSERT( mfn_valid(mfn) ); I would be tempted to remove this assert also, since you just successfully allocated the page at this point. Thanks, Roger.
On 14.05.2020 17:45, Roger Pau Monné wrote: > On Thu, Apr 23, 2020 at 10:37:06AM +0200, Jan Beulich wrote: >> The condition of the second can be true only if the condition of the >> first was met; the second half of the condition of the second then also >> is redundant with an earlier check. Combine them, drop a pointless >> local variable, and re-flow the affected gdprintk(). >> >> Signed-off-by: Jan Beulich <jbeulich@suse.com> > > Reviewed-by: Roger Pau Monné <roger.pau@citrix.com> Thanks. >> --- a/xen/arch/x86/mm/p2m.c >> +++ b/xen/arch/x86/mm/p2m.c >> @@ -1808,6 +1808,8 @@ int p2m_mem_paging_prep(struct domain *d >> /* Allocate a page if the gfn does not have one yet */ >> if ( !mfn_valid(mfn) ) >> { >> + void *guest_map; >> + >> /* If the user did not provide a buffer, we disallow */ >> ret = -EINVAL; >> if ( unlikely(user_ptr == NULL) ) >> @@ -1819,22 +1821,16 @@ int p2m_mem_paging_prep(struct domain *d >> goto out; >> mfn = page_to_mfn(page); >> page_extant = 0; >> - } >> - >> - /* If we were given a buffer, now is the time to use it */ >> - if ( !page_extant && user_ptr ) >> - { >> - void *guest_map; >> - int rc; >> >> ASSERT( mfn_valid(mfn) ); > > I would be tempted to remove this assert also, since you just > successfully allocated the page at this point. Oh, indeed, good point. Jan
On 23/04/2020 09:37, Jan Beulich wrote: > --- a/xen/arch/x86/mm/p2m.c > +++ b/xen/arch/x86/mm/p2m.c > @@ -1819,22 +1821,16 @@ int p2m_mem_paging_prep(struct domain *d > goto out; > mfn = page_to_mfn(page); > page_extant = 0; > - } > - > - /* If we were given a buffer, now is the time to use it */ > - if ( !page_extant && user_ptr ) > - { > - void *guest_map; > - int rc; > > ASSERT( mfn_valid(mfn) ); > guest_map = map_domain_page(mfn); > - rc = copy_from_user(guest_map, user_ptr, PAGE_SIZE); > + ret = copy_from_user(guest_map, user_ptr, PAGE_SIZE); > unmap_domain_page(guest_map); > - if ( rc ) > + if ( ret ) > { > - gdprintk(XENLOG_ERR, "Failed to load paging-in gfn %lx domain %u " > - "bytes left %d\n", gfn_l, d->domain_id, rc); > + gdprintk(XENLOG_ERR, > + "Failed to load paging-in gfn %lx Dom%d bytes left %d\n", > + gfn_l, d->domain_id, ret); %pd, and "%pd gfn %lx" would be a more natural way to phrase it. That said - I'm not sure how useful the information is. We don't normally print any diagnostics on -EFAULT and I don't see why this case is special. With at least %pd fixed, but preferably with the printk() dropped, Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
--- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -1808,6 +1808,8 @@ int p2m_mem_paging_prep(struct domain *d /* Allocate a page if the gfn does not have one yet */ if ( !mfn_valid(mfn) ) { + void *guest_map; + /* If the user did not provide a buffer, we disallow */ ret = -EINVAL; if ( unlikely(user_ptr == NULL) ) @@ -1819,22 +1821,16 @@ int p2m_mem_paging_prep(struct domain *d goto out; mfn = page_to_mfn(page); page_extant = 0; - } - - /* If we were given a buffer, now is the time to use it */ - if ( !page_extant && user_ptr ) - { - void *guest_map; - int rc; ASSERT( mfn_valid(mfn) ); guest_map = map_domain_page(mfn); - rc = copy_from_user(guest_map, user_ptr, PAGE_SIZE); + ret = copy_from_user(guest_map, user_ptr, PAGE_SIZE); unmap_domain_page(guest_map); - if ( rc ) + if ( ret ) { - gdprintk(XENLOG_ERR, "Failed to load paging-in gfn %lx domain %u " - "bytes left %d\n", gfn_l, d->domain_id, rc); + gdprintk(XENLOG_ERR, + "Failed to load paging-in gfn %lx Dom%d bytes left %d\n", + gfn_l, d->domain_id, ret); ret = -EFAULT; put_page(page); /* Don't leak pages */ goto out;
The condition of the second can be true only if the condition of the first was met; the second half of the condition of the second then also is redundant with an earlier check. Combine them, drop a pointless local variable, and re-flow the affected gdprintk(). Signed-off-by: Jan Beulich <jbeulich@suse.com>