kvm tools: Fix 32-bit build of the asm/system.h include

Provide wrappers and other environmental dependencies that the
asm/system.h header file from hell needs to build fine in user-space.

Sidenote: right now alternative() defaults to the compatible, slightly
slower barrier instructions that work on all x86 systems.

If this ever shows up in profiles then kvm could provide an alternatives
patching machinery as well. Right now those instructions are emitted
into special sections and then discarded by the linker harmlessly.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This commit is contained in:
Ingo Molnar
2011-05-05 10:00:45 +02:00
committed by Will Deacon
parent 9490278221
commit 2caa836dc7
4 changed files with 59 additions and 1 deletions
+8
View File
@@ -0,0 +1,8 @@
#ifndef _KVM_ASM_HWEIGHT_H_
#define _KVM_ASM_HWEIGHT_H_
#include <linux/types.h>
unsigned int hweight32(unsigned int w);
unsigned long hweight64(__u64 w);
#endif /* _KVM_ASM_HWEIGHT_H_ */
+15
View File
@@ -0,0 +1,15 @@
#ifndef _KVM_BARRIER_H_
#define _KVM_BARRIER_H_
/*
* asm/system.h cannot be #included standalone on 32-bit x86 yet.
*
* Provide the dependencies here - we can drop these wrappers once
* the header is fixed upstream:
*/
#include <linux/stringify.h>
#include <linux/bitops.h>
#include <asm/alternative.h>
#include <asm/system.h>
#endif /* _KVM_BARRIER_H_ */
+33
View File
@@ -0,0 +1,33 @@
#ifndef _KVM_LINUX_BITOPS_H_
#define _KVM_LINUX_BITOPS_H_
#include <linux/kernel.h>
#include <linux/compiler.h>
#include <asm/hweight.h>
#define BITS_PER_LONG __WORDSIZE
#define BITS_PER_BYTE 8
#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
static inline void set_bit(int nr, unsigned long *addr)
{
addr[nr / BITS_PER_LONG] |= 1UL << (nr % BITS_PER_LONG);
}
static inline void clear_bit(int nr, unsigned long *addr)
{
addr[nr / BITS_PER_LONG] &= ~(1UL << (nr % BITS_PER_LONG));
}
static __always_inline int test_bit(unsigned int nr, const unsigned long *addr)
{
return ((1UL << (nr % BITS_PER_LONG)) &
(((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0;
}
static inline unsigned long hweight_long(unsigned long w)
{
return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
}
#endif
+3 -1
View File
@@ -1,7 +1,9 @@
#include <linux/virtio_ring.h>
#include <stdint.h>
#include <sys/uio.h>
#include <asm/system.h>
#include "kvm/barrier.h"
#include "kvm/kvm.h"
#include "kvm/virtio.h"