From: Damjan Marion Date: Thu, 9 Feb 2017 20:49:06 +0000 (+0100) Subject: vhost-user: fix crash when descriptor points to unknown region X-Git-Tag: v17.04-rc1~233 X-Git-Url: https://gerrit.fd.io/r/gitweb?a=commitdiff_plain;h=0b49e2beee343b7f78aea69c64fc919ad0ac397c;p=vpp.git vhost-user: fix crash when descriptor points to unknown region This happens only on when compiled for older microarchitectures, where BSF insutruction is used instead of TZCNT. BSF provides undefined result if operand is 0. Change-Id: I7a13350786a533428168595097ef01a560fde53b Signed-off-by: Damjan Marion --- diff --git a/src/vnet/devices/virtio/vhost-user.c b/src/vnet/devices/virtio/vhost-user.c index 9b8c18882ca..c627dec2aa5 100644 --- a/src/vnet/devices/virtio/vhost-user.c +++ b/src/vnet/devices/virtio/vhost-user.c @@ -237,7 +237,8 @@ map_guest_mem (vhost_user_intf_t * vui, uword addr, u32 * hint) r = _mm_blend_epi16 (r, _mm_and_si128 (rl, rh), 0x88); r = _mm_shuffle_epi8 (r, _mm_set_epi64x (0, 0x0e060c040a020800)); - i = __builtin_ctzll (_mm_movemask_epi8 (r)); + i = __builtin_ctzll (_mm_movemask_epi8 (r) | + (1 << VHOST_MEMORY_MAX_NREGIONS)); if (i < vui->nregions) {