Re: [Xen-devel] Why cast to "signed short" before checking the return value of gnttab_claim_grant_reference() in xen-netfront.c?

2016-10-28 Thread David Vrabel
On 28/10/16 07:46, Dongli Zhang wrote:
> Hi,
> 
> Would anyone please help with a question on xen-netfront.c code?
> 
> In xen-netfront.c, the return value of gnttab_claim_grant_reference() is
> checked with "BUG_ON((signed short)ref < 0);". Why we use signed short here
> while the return value is of uint32_t? 

That's wrong.  Please just remove that BUG_ON() it isn't useful.

David

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] Why cast to "signed short" before checking the return value of gnttab_claim_grant_reference() in xen-netfront.c?

2016-10-28 Thread Jan Beulich
>>> On 28.10.16 at 08:46,  wrote:
> Would anyone please help with a question on xen-netfront.c code?
> 
> In xen-netfront.c, the return value of gnttab_claim_grant_reference() is
> checked with "BUG_ON((signed short)ref < 0);". Why we use signed short here
> while the return value is of uint32_t? 

The return value is of type int. The value the return value gets stored
into is of type uint32_t.

> Am I missing anything or can I send a patch to fix this issue? In
> xen-blkfront.c and xen-scsifront.c "BUG_ON(gnt_list_entry->gref == -ENOSPC);"
> is involved to check return value. 

This certainly looks wrong. Special casing -ENOSPC, otoh, isn't the
best approach either - I think you want to use IS_ERR_VALUE()
instead, perhaps together with using another intermediate
variable (or type long) to at once deal with the type mismatch
mentioned above as well as to please the compiler when using
IS_ERR_VALUE() (which casts the value to a pointer).

Jan

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] Why cast to "signed short" before checking the return value of gnttab_claim_grant_reference() in xen-netfront.c?

2016-10-28 Thread Dongli Zhang
Hi,

Would anyone please help with a question on xen-netfront.c code?

In xen-netfront.c, the return value of gnttab_claim_grant_reference() is
checked with "BUG_ON((signed short)ref < 0);". Why we use signed short here
while the return value is of uint32_t? 

Am I missing anything or can I send a patch to fix this issue? In
xen-blkfront.c and xen-scsifront.c "BUG_ON(gnt_list_entry->gref == -ENOSPC);"
is involved to check return value. 

The guest kernel would panic after grant refs reach a very large number (when
guest is attached with large number of devices and live migrated).

Thank you very much!

Dongli Zhang

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel