x86, relocs: Add more per-cpu gold special cases

The "gold" linker doesn't seem to put some additional per-cpu cases in
the right place. Add these to the per-cpu check. Without this, the kASLR
patch series fails to correctly apply relocations, and fails to boot.

Signed-off-by: Michael Davidson <md@google.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: http://lkml.kernel.org/r/20131011013954.GA28902@www.outflux.net
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
x86, boot: Move CPU flags out of cpucheck

Refactor the CPU flags handling out of the cpucheck routines so that
they can be reused by the future ASLR routines (in order to detect CPU
features like RDRAND and RDTSC).

This reworks has_eflag() and has_fpu() to be used on both 32-bit and
64-bit, and refactors the calls to cpuid to make them PIC-safe on 32-bit.

Signed-off-by: Kees Cook <keescook@chromium.org>
Link: http://lkml.kernel.org/r/1381450698-28710-2-git-send-email-keescook@chromium.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
x86, kaslr: Return location from decompress_kernel

This allows decompress_kernel to return a new location for the kernel to
be relocated to. Additionally, enforces CONFIG_PHYSICAL_START as the
minimum relocation position when building with CONFIG_RELOCATABLE.

With CONFIG_RANDOMIZE_BASE set, the choose_kernel_location routine
will select a new location to decompress the kernel, though here it is
presently a no-op. The kernel command line option "nokaslr" is introduced
to bypass these routines.

Signed-off-by: Kees Cook <keescook@chromium.org>
Link: http://lkml.kernel.org/r/1381450698-28710-3-git-send-email-keescook@chromium.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
x86, kaslr: Provide randomness functions

Adds potential sources of randomness: RDRAND, RDTSC, or the i8254.

This moves the pre-alternatives inline rdrand function into the header so
both pieces of code can use it. Availability of RDRAND is then controlled
by CONFIG_ARCH_RANDOM, if someone wants to disable it even for kASLR.

Signed-off-by: Kees Cook <keescook@chromium.org>
Link: http://lkml.kernel.org/r/1381450698-28710-4-git-send-email-keescook@chromium.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
x86, kaslr: Select random position from e820 maps

Counts available alignment positions across all e820 maps, and chooses
one randomly for the new kernel base address, making sure not to collide
with unsafe memory areas.

Signed-off-by: Kees Cook <keescook@chromium.org>
Link: http://lkml.kernel.org/r/1381450698-28710-5-git-send-email-keescook@chromium.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
x86, kaslr: Report kernel offset on panic

When the system panics, include the kernel offset in the report to assist
in debugging.

Signed-off-by: Kees Cook <keescook@chromium.org>
Link: http://lkml.kernel.org/r/1381450698-28710-6-git-send-email-keescook@chromium.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
x86, kaslr: Raise the maximum virtual address to -1 GiB on x86_64

On 64-bit, this raises the maximum location to -1 GiB (from -1.5 GiB),
the upper limit currently, since the kernel fixmap page mappings need
to be moved to use the other 1 GiB (which would be the theoretical
limit when building with -mcmodel=kernel).

Signed-off-by: Kees Cook <keescook@chromium.org>
Link: http://lkml.kernel.org/r/1381450698-28710-7-git-send-email-keescook@chromium.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
x86, boot: Rename get_flags() and check_flags() to *_cpuflags()

When a function is used in more than one file it may not be possible
to immediately tell from context what the intended meaning is.  As
such, it is more important that the naming be self-evident.  Thus,
change get_flags() to get_cpuflags().

For consistency, change check_flags() to check_cpuflags() even though
it is only used in cpucheck.c.

Link: http://lkml.kernel.org/r/1381450698-28710-2-git-send-email-keescook@chromium.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
x86/relocs: Add percpu fixup for GNU ld 2.23

The GNU linker tries to put __per_cpu_load into the percpu area,
resulting in a lack of its relocation. Force this symbol to be
relocated. Seen starting with GNU ld 2.23 and later.

Reported-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: Michael Davidson <md@google.com>
Cc: Cong Ding <dinggnu@gmail.com>
Link: http://lkml.kernel.org/r/20131016064314.GA2739@www.outflux.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
iio: hid-sensors: accelerometer: Add sensitivity

A number of Properties that can be applied to Data Fields are per data
field basis or for all data fields. Adding sensitivity field for all
accelerometer fields, which is most commonly used in currently
available sensor hubs.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
iio: hid-sensors: gyro : Add sensitivity

A number of Properties that can be applied to Data Fields are per data
field basis or for all data fields. Adding sensitivity field for all
gyro fields, which is most commonly used in currently available
sensor hubs.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
iio: hid-sensors: light/als : Add sensitivity

A number of Properties that can be applied to Data Fields are per data
field basis or for all data fields. Adding sensitivity field for all
als fields, which is most commonly used in currently available
sensor hubs.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Merge tag 'v3.12'

Linux 3.12
iio: Drop scan_type from viperboard adc driver

the driver does not support buffering, hence scan_type is not needed

Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Cc: Lars Poeschel <poeschel@lemonage.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
iio: hid-sensors: magnetometer : Add sensitivity

A number of Properties that can be applied to Data Fields are per data
field basis or for all data fields. Adding sensitivity field for all
magnetometer fields, which is most commonly used in currently available
sensor hubs.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
staging: ft1000: STATUS_ defines removed from ft1000_download.c

Two files in the ft1000 usb driver ignore expected Linux error codes,
and instead use two STATUS_SUCCESS 0, and STATUS_FAILURE
0x1001. This patch removes all remaining occurrences of these from the
file ft1000_download.c. All occurrences of STATUS_SUCCESS have been
replaced by 0, and occurrences of STATUS_FAILURE have been replaced by
-1. One occurence of STATUS_FAILURE has been completely removed:
get_handshake collects either a local #define or 0 from its helper
function, check_usb_db, and immediately sets the collecting variable to
STATUS_FAILURE if the #define is returned. check_usb_db has been
modified to return -1 instead of the #define.

Signed-off-by: Kelley Nielsen <kelleynnn@gmail.com>
Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Josh Triplett <josh@joshtriplett.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
staging: ft1000: remove formal function headers from ft1000_hw.c

The file ft1000_hw.c contains formal C99 style function headers that
waste space and convey little to no useful information. This patch
converts the headers to either one line standard /* */ style comments
or shorter standard style headers with parameter lists (if the parameter
list seemed helpful), or eliminates them entirely. Besides needing to be
made of its own accord, this change is in preparation to eliminate the
nonstandard STATUS_* #defines from the driver since they were cited in most
of the headers.

Signed-off-by: Kelley Nielsen <kelleynnn@gmail.com>
Reviewed-by: Josh Triplett <josh@joshtriplett.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
staging: ft1000: STATUS defines completely removed

The ft1000 driver ignores the normal Linux error codes, using its
own macros, STATUS, STATUS_SUCCESS, and STATUS_FAILURE, instead.
Unsigned variables (u16 and u32) are sometimes used to hold them.
This patch converts all occurences of these macros to 0, 0 and -1,
respectively. It also changes the last remaining status variables
(mostly called status and ret) to ints, and removes the declarations
of the macros. This patch does not correct the whitespace issues
in the lines where the changes were made.

Signed-off-by: Kelley Nielsen <kelleynnn@gmail.com>
Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Josh Triplett <josh@joshtriplett.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
staging: ft1000: remove unused variable nxtph

The function ft1000_poll, in ft1000_hw.c, is overly complex, with at
least five different levels of nesting. While preparing to extract one
of the cases to its own function, I discovered that the variable nxtph
is not used. It is declared and assigned a value in ft1000_poll(), then
passed by reference to the helper function ft1000_receive_command(),
which receives it as parameter. pnxtph does not appear in the body of
this function. Remove all occurrences of nxtph and pnxtph.

Signed-off-by: Kelley Nielsen <kelleynnn@gmail.com>
Reviewed-by: Peter P Waskiewicz Jr <peter.p.waskiewicz.jr@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
staging: ft1000: extract dsp_broadcast_msg_id()

The function ft1000_poll, in ft1000_hw.c, is overly complex, with at
least five levels of nesting. Extract the lines in switch case
DSPBCMSGID into their own function, called dsp_broadcast_msg_id(). Pass
one parameter, struct ft1000_usb *dev. Make a copy of struct dpram_blk
*pdpram_blk local to the new function, since it is initialized at the
top of each case in which it appears. Make unsigned long flags local to
the new function. Remove the assignment to struct pseudo_hdr
*ppseudo_hdr, which is otherwise unused in the switch case, and receives
the same assignment at the top of each case in which it appears. Return
an int, 0 for success and -1 for error. Correct style issues in the
extracted lines.

Signed-off-by: Kelley Nielsen <kelleynnn@gmail.com>
Reviewed-by: Peter P Waskiewicz Jr <peter.p.waskiewicz.jr@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>