From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KlNiQ-0004Eg-5E for qemu-devel@nongnu.org; Thu, 02 Oct 2008 08:55:34 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KlNiO-0004EN-MY for qemu-devel@nongnu.org; Thu, 02 Oct 2008 08:55:33 -0400 Received: from [199.232.76.173] (port=46383 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KlNiO-0004EK-Hm for qemu-devel@nongnu.org; Thu, 02 Oct 2008 08:55:32 -0400 Received: from verein.lst.de ([213.95.11.210]:46440) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA1:24) (Exim 4.60) (envelope-from ) id 1KlNiN-0008WC-7k for qemu-devel@nongnu.org; Thu, 02 Oct 2008 08:55:31 -0400 Date: Thu, 2 Oct 2008 14:55:26 +0200 From: Christoph Hellwig Subject: Re: [Qemu-devel] [PATCH 1/4] add byteordered types to qemu. Message-ID: <20081002125526.GA6552@lst.de> References: <1222870375-13489-1-git-send-email-kraxel@redhat.com> <20081002082137.GA25959@lst.de> <48E4C2B1.7010108@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <48E4C2B1.7010108@redhat.com> Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gerd Hoffmann Cc: Christoph Hellwig , qemu-devel@nongnu.org On Thu, Oct 02, 2008 at 02:46:41PM +0200, Gerd Hoffmann wrote: > Christoph Hellwig wrote: > > >> +typedef uint16_t le16; > >> +typedef uint32_t le32; > >> +typedef uint64_t le64; > >> +typedef uint16_t be16; > >> +typedef uint32_t be32; > >> +typedef uint64_t be64; > > > > Any chance you could add sparse __bitwise__ declarations so one could > > use spare to check for using these types correctly? > > Is there any good documentation on that? I don't think so. But I've recently added support for it in the XFS userspace tools, so I have some experience. > > Looking at the linux kernel sources I find the bitwise stuff depend on > the __CHECKER__ and __CHECK_ENDIAN__ defines. I can't find references > to these in the sparse man page and sparse FAQ (sparse 0.4.1 as shipped > by fedora 9). > > I can somehow guess what these two defines do. __CHECKER__ probably is > set by sparse, and __CHECK_ENDIAN__ by the -Wbitwise switch. But I > can't see any obvious reason why include/linux/types.h defines both > __bitwise__ and __bitwise. I'd simply use something along the lines ... Actually __CHECKER__ is set by sparse. __CHECK_ENDIAN__ is set on the make command line when checking for endianess bugs. For xfsprogs I defined the bitwise annotations unconditionally because we made sure to not have any of this warnings left (this was quite easy becaus a lot of the code came from the kernel and was already properly annotated) These are the snipplets from xfsprogs that would be useful for qemu: #ifdef __CHECKER__ #define __bitwise __attribute__((bitwise)) #define __force __attribute__((force)) #else #define __bitwise #define __force #endif The __force is needed for the actual swab macros to turn the __bitwise annotated type back into the normal so it doesn't warn. For XFS these conversion macros looks the same as the kernel ones: #ifdef XFS_NATIVE_HOST #define cpu_to_be16(val) ((__force __be16)(__u16)(val)) #define cpu_to_be32(val) ((__force __be32)(__u32)(val)) #define cpu_to_be64(val) ((__force __be64)(__u64)(val)) #define be16_to_cpu(val) ((__force __u16)(__be16)(val)) #define be32_to_cpu(val) ((__force __u32)(__be32)(val)) #define be64_to_cpu(val) ((__force __u64)(__be64)(val)) #else #define cpu_to_be16(val) ((__force __be16)__swab16((__u16)(val))) #define cpu_to_be32(val) ((__force __be32)__swab32((__u32)(val))) #define cpu_to_be64(val) ((__force __be64)__swab64((__u64)(val))) #define be16_to_cpu(val) (__swab16((__force __u16)(__be16)(val))) #define be32_to_cpu(val) (__swab32((__force __u32)(__be32)(val))) #define be64_to_cpu(val) (__swab64((__force __u64)(__be64)(val))) #endif and then you define the types as __bitwise: typedef __u16 __bitwise __be16; typedef __u32 __bitwise __be32; typedef __u64 __bitwise __be64; for qemu you'll need slight changes in the names, and also little endian variants which we don't have in XFS. Note that the biggest hurdle for xfsprogs was to convince libtool that cgcc, the gcc wrapper for invoking sparse actually is a C compiler, but that should be mood for qemu. Note that sparse will probably complain about a lot of things in qemu, so you'll have to add a lot -Wno-foo options in addition to -Wbitwise.