2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-29 13:27:59 +00:00

6 Commits

Author SHA1 Message Date
Ben Pfaff
320232ec7f dpif-linux: Fix build with certain 64-bit kernel/userspace combinations.
Unix 64-bit ABIs have two 64-bit types: "long" and "long long".  Either of
these is a reasonable choice for uint64_t (the userspace type) and for
__u64 (the kernel type).  Unfortunately, kernel and userspace don't
necessarily agree on the choice, and in fact the choice varies across
kernel versions and architectures.

Now that OVS is actually using kernel types in its kernel header, this
can make a difference: when __u64 and uint64_t differ, passing a pointer
to __u64 to OVS function get_unaligned_u64() yields a compiler warning
or error.

This commit fixes up the problems of this type found in OVS, by making
get_unaligned_u64() accept all 64-bit unsigned integer types, not just
whichever one happens to be uint64_t.  I didn't do the same thing for
put_unaligned_u64() because it is less likely to be a problem in
practice: usually, when userspace writes to kernel data structures it
does so with copies that it knows to be aligned, so that it's not
necessary to use put_unaligned_u64().

This problem won't occur for uint8_t, uint16_t, or uint32_t, since there is
only one reasonable choice of type for each.  It won't occur for ovs_be<N>
because OVS always defines those as aliases for the kernel's __be<N> types
when those are available.

This compiled cleanly for me in Scientific Linux 6.0 x86-64.

Reported-by: Pravin Shelar <pshelar@nicira.com>
2011-10-14 09:39:48 -07:00
Ben Pfaff
6506f45c08 Make the source tree sparse clean.
With this commit, the tree compiles clean with sparse commit 87f4a7fda3d
"Teach 'already_tokenized()' to use the stream name hash table" with patch
"evaluate: Allow sizeof(_Bool) to succeed" available at
http://permalink.gmane.org/gmane.comp.parsers.sparse/2461 applied, as long
as the "include/sparse" directory is included for use by sparse (only),
e.g.:
     make CC="CHECK='sparse -I../include/sparse' cgcc"
2011-05-16 13:45:53 -07:00
Ben Pfaff
7bef2c918a Add types and accessors for working with half-aligned 64-bit values.
Both OpenFlow and Netlink contain 64-bit fields that are only guaranteed
to be aligned on 32-bit boundaries.  This commit introduces types for
representing these fields and functions for working with them.  Followup
commits will make the OpenFlow and Netlink code use these types and
functions.
2011-02-05 13:14:47 -08:00
Ben Pfaff
9ea5d2d58b unaligned: Add unaligned accessors for ovs_be<N> data.
These accessors are semantically identical to the ones for uint<N>_t data,
but the names are more informative to readers, and the types provide
annotations for sparse.
2010-11-29 16:29:11 -08:00
Ben Pfaff
10a24935c9 xtoxll: Rename "byte-order" since it now include more than xtoxll.
Suggested-by: Justin Pettit <jpettit@nicira.com>
2010-10-29 09:48:47 -07:00
Ben Pfaff
afa3a93165 Add header for access to potentially unaligned data.
I had been under the impression that "memcpy" was a valid way to copy
unaligned data into an aligned location for access.  But testing on SPARC
has shown that GCC doesn't always honor that intention.  It seems that, if
GCC can see that there is a pointer of a type that requires alignment to
a given object, then it will access it directly regardless of whether
memcpy() is used to copy it.

This commit adds a new header with functions to access unaligned data.  I
managed to come up with two techniques, one GCC-specific, one generic, that
do avoid the misaligned access in my test case.  The GCC-specific technique
is the same one used by the Linux kernel (although no code has been
literally copied).  The other one seemed obvious but possibly slow
depending on the compiler's ability to optimize.

The following commit adds a user.
2010-05-07 14:36:07 -07:00