Skip to contentSkip to conversation

Fix access_with_adjusted_size() on big-endian

PATCH Peter Maydell 2 participants 3 messages Oct 2, 2018 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Peter Maydell

author Reviewed-by
#1 lore raw
Quoted 11 lines · Philippe Mathieu-Daudé

Hi,

This series fix a bug I'v been hunting for a long time.

With BE regions, if the guest used smaller access than the region implementation, the shift value is negative, but since access_fn() uses unsigned type for shift, it result in a huge positive value, then accessors shift the value which eventually becomes 0.

The fix is simply to use signed type for the shift, and shift to the opposite direction for negative values.

Series

I guess we don't have very many devices that are BE and that allow the guest to access them with a smaller width than their implemented width...

thanks
-- PMM

#2 lore raw
Quoted 10 lines · Peter Maydell
Quoted 9 lines · Philippe Mathieu-Daudé

Hi,

This series fix a bug I'v been hunting for a long time.

With BE regions, if the guest used smaller access than the region implementation, the shift value is negative, but since access_fn() uses unsigned type for shift, it result in a huge positive value, then accessors shift the value which eventually becomes 0.

Quoted 5 lines
Quoted 2 lines

The fix is simply to use signed type for the shift, and shift to the opposite direction for negative values.

Series

Thanks for reviewing this.

Quoted 3 lines

I guess we don't have very many devices that are BE and that allow the guest to access them with a smaller width than their implemented width...

Do you think is it worth using the '(un)likely()' macros?

#3 lore raw
Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Peter Maydell
Quoted 9 lines · Philippe Mathieu-Daudé

Hi,

This series fix a bug I'v been hunting for a long time.

With BE regions, if the guest used smaller access than the region implementation, the shift value is negative, but since access_fn() uses unsigned type for shift, it result in a huge positive value, then accessors shift the value which eventually becomes 0.

Quoted 5 lines
Quoted 2 lines

The fix is simply to use signed type for the shift, and shift to the opposite direction for negative values.

Series

Quoted 7 lines

Thanks for reviewing this.

Quoted 3 lines

I guess we don't have very many devices that are BE and that allow the guest to access them with a smaller width than their implemented width...

Do you think is it worth using the '(un)likely()' macros?

Probably not; that was just a comment on why we haven't run into the bug sooner.

thanks
-- PMM