From patchwork Thu May 5 08:22:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ingo Molnar X-Patchwork-Id: 756242 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p458MV7v032264 for ; Thu, 5 May 2011 08:22:32 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752930Ab1EEIW2 (ORCPT ); Thu, 5 May 2011 04:22:28 -0400 Received: from mx3.mail.elte.hu ([157.181.1.138]:35247 "EHLO mx3.mail.elte.hu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753063Ab1EEIWZ (ORCPT ); Thu, 5 May 2011 04:22:25 -0400 Received: from elvis.elte.hu ([157.181.1.14]) by mx3.mail.elte.hu with esmtp (Exim) id 1QHtpB-0007Vd-DO from ; Thu, 05 May 2011 10:22:23 +0200 Received: by elvis.elte.hu (Postfix, from userid 1004) id 943BD3E2526; Thu, 5 May 2011 10:22:15 +0200 (CEST) Date: Thu, 5 May 2011 10:22:15 +0200 From: Ingo Molnar To: Pekka Enberg Cc: Asias He , Sasha Levin , gorcunov@gmail.com, prasadjoshi124@gmail.com, kvm@vger.kernel.org Subject: [PATCH] kvm: Fix 32-bit build of the asm/system.h include Message-ID: <20110505082215.GA20719@elte.hu> References: <1304454487-2539-2-git-send-email-levinsasha928@gmail.com> <20110503204716.GA27887@elte.hu> <1304484063.13143.9.camel@lappy> <4DC1E57B.3060809@gmail.com> <20110505070211.GA13043@elte.hu> <20110505074716.GC14391@elte.hu> <20110505080729.GD14391@elte.hu> <20110505081253.GA20499@elte.hu> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20110505081253.GA20499@elte.hu> User-Agent: Mutt/1.5.20 (2009-08-17) Received-SPF: neutral (mx3: 157.181.1.14 is neither permitted nor denied by domain of elte.hu) client-ip=157.181.1.14; envelope-from=mingo@elte.hu; helo=elvis.elte.hu; X-ELTE-SpamScore: -2.0 X-ELTE-SpamLevel: X-ELTE-SpamCheck: no X-ELTE-SpamVersion: ELTE 2.0 X-ELTE-SpamCheck-Details: score=-2.0 required=5.9 tests=BAYES_00 autolearn=no SpamAssassin version=3.3.1 -2.0 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 05 May 2011 08:22:32 +0000 (UTC) * Ingo Molnar wrote: > * Ingo Molnar wrote: > > > I'm not entirely happy about how it has added dependent includes to virtio.c > > but that's a property of this messy header file. Might be worth adding a > > comment about that. > > This block: > > > +#include > > +#include > > +#include > > #include > > Could be put into a new tools/kvm/include/kvm/barrier.h file, with a comment - > that way the virtio.c inclusion looks very clean. > > Note: i'd not put it into linux/barrier.h, to not clash with any possible > future linux/barrier.h file, and to also make it clear that this is a kvm > specific wrapper. Like the more complete patch below. Build-tested on 32-bit and 64-bit systems, boot tested on a 64-bit box. Thanks, Ingo -------------------> From 5c196bbbe1d5e8c5de8ea5db1f0b274d7f8b7aac Mon Sep 17 00:00:00 2001 From: Ingo Molnar Date: Thu, 5 May 2011 10:00:45 +0200 Subject: [PATCH] kvm: 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 --- tools/kvm/include/asm/hweight.h | 8 ++++++++ tools/kvm/include/kvm/barrier.h | 15 +++++++++++++++ tools/kvm/include/linux/bitops.h | 33 +++++++++++++++++++++++++++++++++ tools/kvm/virtio.c | 4 +++- 4 files changed, 59 insertions(+), 1 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/tools/kvm/include/asm/hweight.h b/tools/kvm/include/asm/hweight.h new file mode 100644 index 0000000..1a43977 --- /dev/null +++ b/tools/kvm/include/asm/hweight.h @@ -0,0 +1,8 @@ +#ifndef _KVM_ASM_HWEIGHT_H_ +#define _KVM_ASM_HWEIGHT_H_ + +#include +unsigned int hweight32(unsigned int w); +unsigned long hweight64(__u64 w); + +#endif /* _KVM_ASM_HWEIGHT_H_ */ diff --git a/tools/kvm/include/kvm/barrier.h b/tools/kvm/include/kvm/barrier.h new file mode 100644 index 0000000..c11a239 --- /dev/null +++ b/tools/kvm/include/kvm/barrier.h @@ -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 +#include +#include +#include + +#endif /* _KVM_BARRIER_H_ */ diff --git a/tools/kvm/include/linux/bitops.h b/tools/kvm/include/linux/bitops.h new file mode 100644 index 0000000..56448b7 --- /dev/null +++ b/tools/kvm/include/linux/bitops.h @@ -0,0 +1,33 @@ +#ifndef _KVM_LINUX_BITOPS_H_ +#define _KVM_LINUX_BITOPS_H_ + +#include +#include +#include + +#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 diff --git a/tools/kvm/virtio.c b/tools/kvm/virtio.c index 266a1b6..4dcd092 100644 --- a/tools/kvm/virtio.c +++ b/tools/kvm/virtio.c @@ -1,7 +1,9 @@ #include #include #include -#include + +#include "kvm/barrier.h" + #include "kvm/kvm.h" #include "kvm/virtio.h"