Skip to content

Commit

Permalink
hash: fix reading unaligned bits in Toeplitz hash
Browse files Browse the repository at this point in the history
[ upstream commit 3a54f8de715c29613cf3d34ce3910d2bd27bffb9 ]

Fixes: 28ebff1 ("hash: add predictable RSS")

Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
Acked-by: Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>
  • Loading branch information
vmedvedk authored and kevintraynor committed Jul 12, 2023
1 parent 00c14e2 commit 086b984
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/hash/rte_thash.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ rte_thash_get_gfni_matrices(struct rte_thash_ctx *ctx)
}

static inline uint8_t
read_unaligned_byte(uint8_t *ptr, unsigned int len, unsigned int offset)
read_unaligned_byte(uint8_t *ptr, unsigned int offset)
{
uint8_t ret = 0;

Expand All @@ -682,27 +682,29 @@ read_unaligned_byte(uint8_t *ptr, unsigned int len, unsigned int offset)
(CHAR_BIT - (offset % CHAR_BIT));
}

return ret >> (CHAR_BIT - len);
return ret;
}

static inline uint32_t
read_unaligned_bits(uint8_t *ptr, int len, int offset)
{
uint32_t ret = 0;
int shift;

len = RTE_MAX(len, 0);
len = RTE_MIN(len, (int)(sizeof(uint32_t) * CHAR_BIT));

while (len > 0) {
ret <<= CHAR_BIT;

ret |= read_unaligned_byte(ptr, RTE_MIN(len, CHAR_BIT),
offset);
ret |= read_unaligned_byte(ptr, offset);
offset += CHAR_BIT;
len -= CHAR_BIT;
}

return ret;
shift = (len == 0) ? 0 :
(CHAR_BIT - ((len + CHAR_BIT) % CHAR_BIT));
return ret >> shift;
}

/* returns mask for len bits with given offset inside byte */
Expand Down

0 comments on commit 086b984

Please sign in to comment.