Skip to contentSkip to conversation

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

DISCUSSION Dongli Zhang 3 participants 3 messages Oct 28, 2016

lore
Share & tools
lore
#0 lore raw

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
[email protected]
https://lists.xen.org/xen-devel

#1 lore raw
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 28.10.16 at 08:46, <[email protected]> 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.

Quoted 3 lines

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
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw
In reply to Dongli Zhang
Quoted 7 lines · 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?

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

David

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel