Re: [PATCH] KVM: x86: fix undefined behavior in bit shift for __feature_bit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/31/22 21:54, Peter Zijlstra wrote:
PeterZ is contending that this isn't actually undefined behavior given how the
kernel is compiled[*].  That said, I would be in favor of replacing the open-coded
shift with BIT() to make the code a bit more self-documenting, and that would
naturally fix this maybe-undefined-behavior issue.

[*]https://lore.kernel.org/all/Y1%2FAaJOcgIc%2FINtv@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm definitely in favour of updating this code; both your suggestion and
hpa's suggestion look like sane changes. But I do feel that whatever
UBSAN thing generated this warning needs to be fixed too.

I'm fine with the compiler warning about this code -- but it must not
claim undefined behaviour given the compiler flags we use.

Yes, the compiler is buggy here (see old bug report for GCC, now fixed, at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68418).

I cannot even reproduce the problem with the simple userspace testcase

#include <stdlib.h>
int main(int argc) {
	int i = argc << 31;
	exit(i < 0);
}

on either GCC 12 or clang 15.

Paolo




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux