[PATCH] clk: rockchip: rk3368: fix section mismatches with new child-clocks

2016-02-23 Thread Elaine Zhang
To model the muxes downstream of fractional dividers we introduced the
child property, allowing to describe a direct child clock.
The first implementation seems to cause section warnings, as the core
clock-tree is marked as initdata while the data pointed to from the
child element is not.

While there may be some way to also set that missing property in the
inline notation I didn't find it, so to actually fix the issue for now
move the sub-definitions into separate declarations that can have
their own __initdata properties.

Signed-off-by: Elaine Zhang 
---
 drivers/clk/rockchip/clk-rk3368.c | 97 ---
 1 file changed, 60 insertions(+), 37 deletions(-)

diff --git a/drivers/clk/rockchip/clk-rk3368.c 
b/drivers/clk/rockchip/clk-rk3368.c
index c2b0421..a2bb122 100644
--- a/drivers/clk/rockchip/clk-rk3368.c
+++ b/drivers/clk/rockchip/clk-rk3368.c
@@ -243,6 +243,34 @@ static struct rockchip_cpuclk_rate_table 
rk3368_cpuclkl_rates[] __initdata = {
RK3368_CPUCLKL_RATE( 31200, 1, 1, 1),
 };
 
+static struct rockchip_clk_branch rk3368_i2s_8ch_fracmux __initdata =
+   MUX(0, "i2s_8ch_pre", mux_i2s_8ch_pre_p, CLK_SET_RATE_PARENT,
+   RK3368_CLKSEL_CON(27), 8, 2, MFLAGS);
+
+static struct rockchip_clk_branch rk3368_spdif_8ch_fracmux __initdata =
+   MUX(0, "spdif_8ch_pre", mux_spdif_8ch_p, CLK_SET_RATE_PARENT,
+   RK3368_CLKSEL_CON(31), 8, 2, MFLAGS);
+
+static struct rockchip_clk_branch rk3368_i2s_2ch_fracmux __initdata =
+   MUX(0, "i2s_2ch_pre", mux_i2s_2ch_p, CLK_SET_RATE_PARENT,
+   RK3368_CLKSEL_CON(53), 8, 2, MFLAGS);
+
+static struct rockchip_clk_branch rk3368_uart0_fracmux __initdata =
+   MUX(SCLK_UART0, "sclk_uart0", mux_uart0_p, CLK_SET_RATE_PARENT,
+   RK3368_CLKSEL_CON(33), 8, 2, MFLAGS);
+
+static struct rockchip_clk_branch rk3368_uart1_fracmux __initdata =
+   MUX(SCLK_UART1, "sclk_uart1", mux_uart1_p, CLK_SET_RATE_PARENT,
+   RK3368_CLKSEL_CON(35), 8, 2, MFLAGS);
+
+static struct rockchip_clk_branch rk3368_uart3_fracmux __initdata =
+   MUX(SCLK_UART3, "sclk_uart3", mux_uart3_p, CLK_SET_RATE_PARENT,
+   RK3368_CLKSEL_CON(39), 8, 2, MFLAGS);
+
+static struct rockchip_clk_branch rk3368_uart4_fracmux __initdata =
+   MUX(SCLK_UART4, "sclk_uart4", mux_uart4_p, CLK_SET_RATE_PARENT,
+   RK3368_CLKSEL_CON(41), 8, 2, MFLAGS);
+
 static struct rockchip_clk_branch rk3368_clk_branches[] __initdata = {
/*
 * Clock-Architecture Diagram 2
@@ -339,11 +367,10 @@ static struct rockchip_clk_branch rk3368_clk_branches[] 
__initdata = {
COMPOSITE(0, "i2s_8ch_src", mux_pll_src_cpll_gpll_p, 0,
RK3368_CLKSEL_CON(27), 12, 1, MFLAGS, 0, 7, DFLAGS,
RK3368_CLKGATE_CON(6), 1, GFLAGS),
-   COMPOSITE_FRAC(0, "i2s_8ch_frac", "i2s_8ch_src", CLK_SET_RATE_PARENT,
-   RK3368_CLKSEL_CON(28), 0,
-   RK3368_CLKGATE_CON(6), 2, GFLAGS),
-   MUX(0, "i2s_8ch_pre", mux_i2s_8ch_pre_p, CLK_SET_RATE_PARENT,
-   RK3368_CLKSEL_CON(27), 8, 2, MFLAGS),
+   COMPOSITE_FRACMUX(0, "i2s_8ch_frac", "i2s_8ch_src", CLK_SET_RATE_PARENT,
+ RK3368_CLKSEL_CON(28), 0,
+ RK3368_CLKGATE_CON(6), 2, GFLAGS,
+ &rk3368_i2s_8ch_fracmux),
COMPOSITE_NODIV(SCLK_I2S_8CH_OUT, "i2s_8ch_clkout", 
mux_i2s_8ch_clkout_p, 0,
RK3368_CLKSEL_CON(27), 15, 1, MFLAGS,
RK3368_CLKGATE_CON(6), 0, GFLAGS),
@@ -352,21 +379,21 @@ static struct rockchip_clk_branch rk3368_clk_branches[] 
__initdata = {
COMPOSITE(0, "spdif_8ch_src", mux_pll_src_cpll_gpll_p, 0,
RK3368_CLKSEL_CON(31), 12, 1, MFLAGS, 0, 7, DFLAGS,
RK3368_CLKGATE_CON(6), 4, GFLAGS),
-   COMPOSITE_FRAC(0, "spdif_8ch_frac", "spdif_8ch_src", 
CLK_SET_RATE_PARENT,
-   RK3368_CLKSEL_CON(32), 0,
-   RK3368_CLKGATE_CON(6), 5, GFLAGS),
-   COMPOSITE_NODIV(SCLK_SPDIF_8CH, "sclk_spdif_8ch", mux_spdif_8ch_p, 
CLK_SET_RATE_PARENT,
-   RK3368_CLKSEL_CON(31), 8, 2, MFLAGS,
-   RK3368_CLKGATE_CON(6), 6, GFLAGS),
+   COMPOSITE_FRACMUX(0, "spdif_8ch_frac", "spdif_8ch_src", 
CLK_SET_RATE_PARENT,
+ RK3368_CLKSEL_CON(32), 0,
+ RK3368_CLKGATE_CON(6), 5, GFLAGS,
+ &rk3368_spdif_8ch_fracmux),
+   GATE(SCLK_SPDIF_8CH, "sclk_spdif_8ch", "spdif_8ch_pre", 
CLK_SET_RATE_PARENT,
+RK3368_CLKGATE_CON(6), 6, GFLAGS),
COMPOSITE(0, "i2s_2ch_src", mux_pll_src_cpll_gpll_p, 0,
RK3368_CLKSEL_CON(53), 12, 1, MFLAGS, 0, 7, DFLAGS,
RK3368_CLKGATE_CON(5), 13, GFLAGS),
-   COMPOSITE_FRAC(0, "i2s_2ch_frac", "i2s_2ch_src", CLK_SET_RATE_PARENT,
-   RK3368_CLKSEL_CON(54), 0

[PATCH] ARM: dts: add support for gpio buttons for exynos5422-odroidxu3

2016-02-23 Thread Anand Moon
Add support for gpio-based button on Odroid-XU3 boards
for reboot/poweroff feature.

Signed-off-by: Anand Moon 
---
changes rebase based on linux next-20160222.

Tested on Odroid-XU4

dmesg output.
[3.286068] of_get_named_gpiod_flags: parsed 'gpios' property of node 
'/gpio_keys/power_key[0]' - status (0)
[3.286206] gpio-11 (power key): gpiod_set_debounce: missing set() or 
set_debounce() operations
[3.286600] input: gpio_keys as /devices/platform/gpio_keys/input/input0
---
 arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi 
b/arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi
index 1bd507b..db9770b 100644
--- a/arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi
+++ b/arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi
@@ -11,6 +11,7 @@
 */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -54,6 +55,22 @@
#cooling-cells = <2>;
cooling-levels = <0 130 170 230>;
};
+
+   gpio_keys {
+   compatible = "gpio-keys";
+   pinctrl-names = "default";
+   pinctrl-0 = <&gpio_power_key>;
+
+   power_key {
+   interrupt-parent = <&gpx0>;
+   interrupts = <3 IRQ_TYPE_NONE>;
+   gpios = <&gpx0 3 GPIO_ACTIVE_LOW>;
+   linux,code = ;
+   label = "power key";
+   debounce-interval = <10>;
+   wakeup-source;
+   };
+   };
 };
 
 &clock_audss {
@@ -362,6 +379,11 @@
 };
 
 &pinctrl_0 {
+   gpio_power_key: power_key {
+   samsung,pins = "gpx0-3";
+   samsung,pin-pud = <0>;
+   };
+
hdmi_hpd_irq: hdmi-hpd-irq {
samsung,pins = "gpx3-7";
samsung,pin-function = <0>;
-- 
2.1.4



[PATCH] netfilter: xt_osf: remove unused variable

2016-02-23 Thread Sudip Mukherjee
While building with W=1 we got the warning:
net/netfilter/xt_osf.c:265:9: warning: variable 'loop_cont' set but not used

The local variable loop_cont was only initialized and then assigned a
value but was never used or checked after that.
While removing the variable, the case of OSFOPT_TS was not removed so
that it will serve as a reminder to us that we can do something in that
particular case.

Signed-off-by: Sudip Mukherjee 
---
 net/netfilter/xt_osf.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/net/netfilter/xt_osf.c b/net/netfilter/xt_osf.c
index 4e3c3af..2455b69 100644
--- a/net/netfilter/xt_osf.c
+++ b/net/netfilter/xt_osf.c
@@ -262,7 +262,6 @@ xt_osf_match_packet(const struct sk_buff *skb, struct 
xt_action_param *p)
if (f->opt[optnum].kind == (*optp)) {
__u32 len = f->opt[optnum].length;
const __u8 *optend = optp + len;
-   int loop_cont = 0;
 
fmatch = FMATCH_OK;
 
@@ -275,7 +274,6 @@ xt_osf_match_packet(const struct sk_buff *skb, struct 
xt_action_param *p)
mss = ntohs((__force __be16)mss);
break;
case OSFOPT_TS:
-   loop_cont = 1;
break;
}
 
-- 
1.9.1



[PATCH v5 1/8] dt-bindings: Add a binding for Mediatek Video Processor

2016-02-23 Thread Tiffany Lin
From: Andrew-CT Chen 

Add a DT binding documentation of Video Processor Unit for the
MT8173 SoC from Mediatek.

Signed-off-by: Andrew-CT Chen 
Signed-off-by: Tiffany Lin 
Acked-by: Rob Herring 
---
 .../devicetree/bindings/media/mediatek-vpu.txt |   31 
 1 file changed, 31 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/mediatek-vpu.txt

diff --git a/Documentation/devicetree/bindings/media/mediatek-vpu.txt 
b/Documentation/devicetree/bindings/media/mediatek-vpu.txt
new file mode 100644
index 000..2a5bac3
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/mediatek-vpu.txt
@@ -0,0 +1,31 @@
+* Mediatek Video Processor Unit
+
+Video Processor Unit is a HW video controller. It controls HW Codec including
+H.264/VP8/VP9 Decode, H.264/VP8 Encode and Image Processor (scale/rotate/color 
convert).
+
+Required properties:
+  - compatible: "mediatek,mt8173-vpu"
+  - reg: Must contain an entry for each entry in reg-names.
+  - reg-names: Must include the following entries:
+"tcm": tcm base
+"cfg_reg": Main configuration registers base
+  - interrupts: interrupt number to the cpu.
+  - clocks : clock name from clock manager
+  - clock-names: must be main. It is the main clock of VPU
+
+Optional properties:
+  - memory-region: phandle to a node describing memory (see
+Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt)
+to be used for VPU extended memory; if not present, VPU may be located
+anywhere in the memory
+
+Example:
+   vpu: vpu@1002 {
+   compatible = "mediatek,mt8173-vpu";
+   reg = <0 0x1002 0 0x3>,
+ <0 0x1005 0 0x100>;
+   reg-names = "tcm", "cfg_reg";
+   interrupts = ;
+   clocks = <&topckgen TOP_SCP_SEL>;
+   clock-names = "main";
+   };
-- 
1.7.9.5



[PATCH v5 0/8] Add MT8173 Video Encoder Driver and VPU Driver

2016-02-23 Thread Tiffany Lin
==
 Introduction
==

The purpose of this series is to add the driver for video codec hw embedded in 
the Mediatek's MT8173 SoCs.
Mediatek Video Codec is able to handle video encoding of in a range of formats.

This patch series also include VPU driver. Mediatek Video Codec driver rely on 
VPU driver to load,
communicate with VPU.

Internally the driver uses videobuf2 framework and MTK IOMMU and MTK SMI.
MTK IOMMU[1] and MTK SMI[2] have not yet been merged, but we wanted to start 
discussion about the driver
earlier so it could be merged sooner.

[1]https://patchwork.kernel.org/patch/8335461/
[2]https://patchwork.kernel.org/patch/7596181/

==
 Device interface
==

In principle the driver bases on v4l2 memory-to-memory framework:
it provides a single video node and each opened file handle gets its own 
private context with separate
buffer queues. Each context consist of 2 buffer queues: OUTPUT (for source 
buffers, i.e. raw video
frames) and CAPTURE (for destination buffers, i.e. encoded video frames).

==
 VPU (Video Processor Unit)
==
The VPU driver for hw video codec embedded in Mediatek's MT8173 SOCs.
It is able to handle video decoding/encoding in a range of formats.
The driver provides with VPU firmware download, memory management and the 
communication interface
between CPU and VPU.
For VPU initialization, it will create virtual memory for CPU access and 
physical address for VPU hw device
access. When a decode/encode instance opens a device node, vpu driver will 
download vpu firmware to the device.
A decode/encode instant will decode/encode a frame using VPU interface to 
interrupt vpu to handle
decoding/encoding jobs.

Please have a look at the code and comments will be very much appreciated.
Change in v5:
Vcodec Part
1. Pass checkpatch and v4l2-compliance test
2. Remove unused g/s_selection for now
3. add vidioc_g_parm support
4. add vidioc_create_bufs and vidioc_prepare_buf support
5. Remove instance limitation check in fops_vcodec_open
6. Fix comments for data structure and code
7. Refine venc, venc_lt clock source name in devicetree and binding document
8. Fix Author information and copyright information
9. Refine code according to review comments

VPU Part
1. Modify mtk-vpu driver description
2. Remove unavailable watchdog reset id
3. Modify VPU clock function for watchdog

H264/VP8 driver part
1.code refined about redundant and structrue comments
2.code refined about redundant and add structrue comments

v4l2-compliance test output:
localhost ~ # /usr/bin/v4l2-compliance -d /dev/video1
Driver Info:
Driver name   : mtk-vcodec-enc
Card type : platform:mt8173
Bus info  : platform:mt8173
Driver version: 4.4.0
Capabilities  : 0x84204000
Video Memory-to-Memory Multiplanar
Streaming
Extended Pix Format
Device Capabilities
Device Caps   : 0x04204000
Video Memory-to-Memory Multiplanar
Streaming
Extended Pix Format

Compliance test for device /dev/video1 (not using libv4l2):

Required ioctls:
test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second video open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported)
test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported)
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)

Control ioctls:
test VIDIOC_QUERYCTRL/MENU: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 12 Private Controls: 0

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
test VIDIOC_G/S_PARM: OK
test VI

[PATCH] driver: input :touchscreen : add Raydium I2C touch driver

2016-02-23 Thread jeffrey.lin
This patch is porting Raydium I2C touch driver. Developer can enable raydium 
touch driver by modifying define "CONFIG_TOUCHSCREEN_RM_TS".

Signed-off-by: jeffrey.lin 
---
 drivers/input/touchscreen/Kconfig  |  12 +
 drivers/input/touchscreen/Makefile |   1 +
 drivers/input/touchscreen/raydium_i2c_ts.c | 973 +
 3 files changed, 986 insertions(+)
 create mode 100644 drivers/input/touchscreen/raydium_i2c_ts.c

diff --git a/drivers/input/touchscreen/Kconfig 
b/drivers/input/touchscreen/Kconfig
index 3f3f6ee..ab28721 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -915,6 +915,18 @@ config TOUCHSCREEN_PCAP
  To compile this driver as a module, choose M here: the
  module will be called pcap_ts.
 
+config TOUCHSCREEN_RM_TS
+   tristate "Raydium I2C Touchscreen"
+   depends on I2C
+   help
+ Say Y here if you have Raydium series I2C touchscreen,
+ such as RM31100 , connected to your system.
+
+ If unsure, say N.
+
+ To compile this driver as a module, choose M here: the
+ module will be called raydium_i2c_ts.
+
 config TOUCHSCREEN_ST1232
tristate "Sitronix ST1232 touchscreen controllers"
depends on I2C
diff --git a/drivers/input/touchscreen/Makefile 
b/drivers/input/touchscreen/Makefile
index 4941f2d..99e08cf 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -55,6 +55,7 @@ obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE)   += 
usbtouchscreen.o
 obj-$(CONFIG_TOUCHSCREEN_PCAP) += pcap_ts.o
 obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o
 obj-$(CONFIG_TOUCHSCREEN_PIXCIR)   += pixcir_i2c_ts.o
+obj-$(CONFIG_TOUCHSCREEN_RM_TS)+= raydium_i2c_ts.o
 obj-$(CONFIG_TOUCHSCREEN_S3C2410)  += s3c2410_ts.o
 obj-$(CONFIG_TOUCHSCREEN_ST1232)   += st1232.o
 obj-$(CONFIG_TOUCHSCREEN_STMPE)+= stmpe-ts.o
diff --git a/drivers/input/touchscreen/raydium_i2c_ts.c 
b/drivers/input/touchscreen/raydium_i2c_ts.c
new file mode 100644
index 000..738b2fd
--- /dev/null
+++ b/drivers/input/touchscreen/raydium_i2c_ts.c
@@ -0,0 +1,973 @@
+/*
+ * Raydium touchscreen I2C driver.
+ *
+ * Copyright (C) 2012-2014, Raydium Semiconductor Corporation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2, and only version 2, as published by the
+ * Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * Raydium reserves the right to make changes without further notice
+ * to the materials described herein. Raydium does not assume any
+ * liability arising out of the application described herein.
+ *
+ * Contact Raydium Semiconductor Corporation at www.rad-ic.com
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Device, Driver information */
+#define DEVICE_NAME"raydium_i2c"
+
+/* Slave I2C mode*/
+#define RM_BOOT_BLDR   0x02
+#define RM_BOOT_MAIN   0x03
+
+/*I2C command */
+#define CMD_QUERY_BANK 0x2B
+#define CMD_DATA_BANK  0x4D
+#define CMD_ENTER_SLEEP0x4E
+#define CMD_BOOT_ACK   0x0A
+#define CMD_BOOT_WRT   0x5B
+#define CMD_BOOT_CHK   0x0C
+#define CMD_BANK_SWITCH0xAA
+
+/* Touch relative info */
+#define MAX_RETRIES3
+#define MAX_FW_UPDATE_RETRIES  30
+#define MAX_TOUCH_NUM  10
+#define MAX_PACKET_SIZE128
+#define BOOT_DELAY_MS  100
+
+#define RAYDIUM_FW_PAGESIZE128
+#define RAYDIUM_POWERON_DELAY_USEC 500
+#define RAYDIUM_RESET_DELAY_MSEC   50
+
+#define ADDR_INDEX 0x03
+#define HEADER_SIZE4
+
+enum raydium_boot_mode {
+   RAYDIUM_TS_MAIN,
+   RAYDIUM_TS_BLDR,
+};
+
+struct raydium_info {
+   u32 hw_ver;
+   u8 main_ver;
+   u8 sub_ver;
+   u16 ft_ver;
+   u8 x_num;
+   u8 y_num;
+   u16 x_max;
+   u16 y_max;
+   u8 x_res;   /* units/mm */
+   u8 y_res;   /* units/mm */
+};
+
+struct raydium_abs_info {
+   u8 state;/*1:touch, 0:no touch*/
+   u8 x_pos_lsb;
+   u8 x_pos_msb;
+   u8 y_pos_lsb;
+   u8 y_pos_msb;
+   u8 pressure;
+   u8 x_width;
+   u8 y_width;
+};
+
+struct raydium_object {
+   u32 data_bank_addr;
+   u8 pkg_size;
+};
+
+/* struct raydium_data - represents state of Raydium touchscreen device */
+struct raydium_data {
+   struct i2c_client *client;
+   struct input_dev *input;
+
+   struct regulator *vcc33;
+   struct regulator *vccio;
+ 

[PATCH v5 2/8] [media] VPU: mediatek: support Mediatek VPU

2016-02-23 Thread Tiffany Lin
From: Andrew-CT Chen 

The VPU driver for hw video codec embedded in Mediatek's MT8173 SOCs.
It is able to handle video decoding/encoding of in a range of formats.
The driver provides with VPU firmware download, memory management and
the communication interface between CPU and VPU.
For VPU initialization, it will create virtual memory for CPU access and
IOMMU address for vcodec hw device access. When a decode/encode instance
opens a device node, vpu driver will download vpu firmware to the device.
A decode/encode instant will decode/encode a frame using VPU
interface to interrupt vpu to handle decoding/encoding jobs.

Signed-off-by: Andrew-CT Chen 
Signed-off-by: Tiffany Lin 
---
 drivers/media/platform/Kconfig   |   12 +
 drivers/media/platform/Makefile  |2 +
 drivers/media/platform/mtk-vpu/Makefile  |1 +
 drivers/media/platform/mtk-vpu/mtk_vpu.c |  949 ++
 drivers/media/platform/mtk-vpu/mtk_vpu.h |  163 +
 5 files changed, 1127 insertions(+)
 create mode 100644 drivers/media/platform/mtk-vpu/Makefile
 create mode 100644 drivers/media/platform/mtk-vpu/mtk_vpu.c
 create mode 100644 drivers/media/platform/mtk-vpu/mtk_vpu.h

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index ccbc974..6b59dbc 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -148,6 +148,18 @@ config VIDEO_CODA
   Coda is a range of video codec IPs that supports
   H.264, MPEG-4, and other video formats.
 
+config VIDEO_MEDIATEK_VPU
+   tristate "Mediatek Video Processor Unit"
+   depends on VIDEO_DEV && VIDEO_V4L2 && ARCH_MEDIATEK
+   ---help---
+   This driver provides downloading VPU firmware and
+   communicating with VPU. This driver for hw video
+   codec embedded in Mediatek's MT8173 SOCs. It is able
+   to handle video decoding/encoding in a range of formats.
+
+   To compile this driver as a module, choose M here: the
+   module will be called mtk-vpu.
+
 config VIDEO_MEM2MEM_DEINTERLACE
tristate "Deinterlace support"
depends on VIDEO_DEV && VIDEO_V4L2 && DMA_ENGINE
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index efa0295..e5b19c6 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -55,3 +55,5 @@ obj-$(CONFIG_VIDEO_AM437X_VPFE)   += am437x/
 obj-$(CONFIG_VIDEO_XILINX) += xilinx/
 
 ccflags-y += -I$(srctree)/drivers/media/i2c
+
+obj-$(CONFIG_VIDEO_MEDIATEK_VPU)   += mtk-vpu/
diff --git a/drivers/media/platform/mtk-vpu/Makefile 
b/drivers/media/platform/mtk-vpu/Makefile
new file mode 100644
index 000..d890a66
--- /dev/null
+++ b/drivers/media/platform/mtk-vpu/Makefile
@@ -0,0 +1 @@
+obj-y += mtk_vpu.o
diff --git a/drivers/media/platform/mtk-vpu/mtk_vpu.c 
b/drivers/media/platform/mtk-vpu/mtk_vpu.c
new file mode 100644
index 000..bb4867b
--- /dev/null
+++ b/drivers/media/platform/mtk-vpu/mtk_vpu.c
@@ -0,0 +1,949 @@
+/*
+* Copyright (c) 2016 MediaTek Inc.
+* Author: Andrew-CT Chen 
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 as
+* published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*/
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "mtk_vpu.h"
+
+/**
+ * VPU (video processor unit) is a tiny processor controlling video hardware
+ * related to video codec, scaling and color format converting.
+ * VPU interfaces with other blocks by share memory and interrupt.
+ **/
+
+#define INIT_TIMEOUT_MS2000U
+#define IPI_TIMEOUT_MS 2000U
+#define VPU_FW_VER_LEN 16
+
+/* maximum program/data TCM (Tightly-Coupled Memory) size */
+#define VPU_PTCM_SIZE  (96 * SZ_1K)
+#define VPU_DTCM_SIZE  (32 * SZ_1K)
+/* the offset to get data tcm address */
+#define VPU_DTCM_OFFSET0x18000UL
+/* daynamic allocated maximum extended memory size */
+#define VPU_EXT_P_SIZE SZ_1M
+#define VPU_EXT_D_SIZE SZ_4M
+/* maximum binary firmware size */
+#define VPU_P_FW_SIZE  (VPU_PTCM_SIZE + VPU_EXT_P_SIZE)
+#define VPU_D_FW_SIZE  (VPU_DTCM_SIZE + VPU_EXT_D_SIZE)
+/* the size of share buffer between Host and  VPU */
+#define SHARE_BUF_SIZE 48
+
+/* binary firmware name */
+#define VPU_P_FW   "vpu_p.bin"
+#define VPU_D_FW   "vpu_d.bin"
+
+#define VPU_RESET  0x0
+#define VPU_TCM_CFG0x0008
+#define VPU_PMEM_EXT0_ADDR 0x000C
+#define VPU_PMEM_EXT1_ADDR 0x0010
+#define VPU_TO_HOS

[PATCH v5 5/8] [Media] vcodec: mediatek: Add Mediatek V4L2 Video Encoder Driver

2016-02-23 Thread Tiffany Lin
Add v4l2 layer encoder driver for MT8173

Signed-off-by: Tiffany Lin 
---
 drivers/media/platform/Kconfig |   11 +
 drivers/media/platform/Makefile|2 +
 drivers/media/platform/mtk-vcodec/Makefile |8 +
 drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h |  352 +
 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 1430 
 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.h |   47 +
 .../media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c |  476 +++
 .../media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c  |  132 ++
 .../media/platform/mtk-vcodec/mtk_vcodec_intr.c|  102 ++
 .../media/platform/mtk-vcodec/mtk_vcodec_intr.h|   29 +
 drivers/media/platform/mtk-vcodec/mtk_vcodec_pm.h  |   26 +
 .../media/platform/mtk-vcodec/mtk_vcodec_util.c|  106 ++
 .../media/platform/mtk-vcodec/mtk_vcodec_util.h|   85 ++
 drivers/media/platform/mtk-vcodec/venc_drv_base.h  |   63 +
 drivers/media/platform/mtk-vcodec/venc_drv_if.c|  102 ++
 drivers/media/platform/mtk-vcodec/venc_drv_if.h|  177 +++
 drivers/media/platform/mtk-vcodec/venc_ipi_msg.h   |  227 
 17 files changed, 3375 insertions(+)
 create mode 100644 drivers/media/platform/mtk-vcodec/Makefile
 create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
 create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
 create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.h
 create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
 create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c
 create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.c
 create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.h
 create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_pm.h
 create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c
 create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_util.h
 create mode 100644 drivers/media/platform/mtk-vcodec/venc_drv_base.h
 create mode 100644 drivers/media/platform/mtk-vcodec/venc_drv_if.c
 create mode 100644 drivers/media/platform/mtk-vcodec/venc_drv_if.h
 create mode 100644 drivers/media/platform/mtk-vcodec/venc_ipi_msg.h

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 6b59dbc..a3e9716 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -160,6 +160,17 @@ config VIDEO_MEDIATEK_VPU
To compile this driver as a module, choose M here: the
module will be called mtk-vpu.
 
+config VIDEO_MEDIATEK_VCODEC
+tristate "Mediatek Video Codec driver"
+depends on VIDEO_DEV && VIDEO_V4L2
+depends on ARCH_MEDIATEK || COMPILE_TEST
+select VIDEOBUF2_DMA_CONTIG
+select V4L2_MEM2MEM_DEV
+select VIDEO_MEDIATEK_VPU
+default n
+---help---
+Mediatek video codec driver for V4L2
+
 config VIDEO_MEM2MEM_DEINTERLACE
tristate "Deinterlace support"
depends on VIDEO_DEV && VIDEO_V4L2 && DMA_ENGINE
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index e5b19c6..510e06b 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -57,3 +57,5 @@ obj-$(CONFIG_VIDEO_XILINX)+= xilinx/
 ccflags-y += -I$(srctree)/drivers/media/i2c
 
 obj-$(CONFIG_VIDEO_MEDIATEK_VPU)   += mtk-vpu/
+
+obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC)+= mtk-vcodec/
diff --git a/drivers/media/platform/mtk-vcodec/Makefile 
b/drivers/media/platform/mtk-vcodec/Makefile
new file mode 100644
index 000..ce38689
--- /dev/null
+++ b/drivers/media/platform/mtk-vcodec/Makefile
@@ -0,0 +1,8 @@
+obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += mtk_vcodec_intr.o \
+  mtk_vcodec_util.o \
+  mtk_vcodec_enc_drv.o \
+  mtk_vcodec_enc.o \
+  mtk_vcodec_enc_pm.o \
+  venc_drv_if.o
+
+ccflags-y += -I$(srctree)/drivers/media/platform/mtk-vpu
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
new file mode 100644
index 000..f8b4e9a
--- /dev/null
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
@@ -0,0 +1,352 @@
+/*
+* Copyright (c) 2016 MediaTek Inc.
+* Author: PC Chen 
+*  Tiffany Lin 
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 as
+* published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*/
+
+#ifndef _MTK_VCODEC_DRV_H_
+#define _MTK_VCODEC_DRV_H_
+
+#include 
+#include 
+#i

[PATCH v5 4/8] dt-bindings: Add a binding for Mediatek Video Encoder

2016-02-23 Thread Tiffany Lin
Add a DT binding documentation of Video Encoder for the
MT8173 SoC from Mediatek.

Signed-off-by: Tiffany Lin 
Acked-by: Rob Herring 
---
 .../devicetree/bindings/media/mediatek-vcodec.txt  |   59 
 1 file changed, 59 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/mediatek-vcodec.txt

diff --git a/Documentation/devicetree/bindings/media/mediatek-vcodec.txt 
b/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
new file mode 100644
index 000..c2e8137
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
@@ -0,0 +1,59 @@
+Mediatek Video Codec
+
+Mediatek Video Codec is the video codec hw present in Mediatek SoCs which
+supports high resolution encoding functionalities.
+
+Required properties:
+- compatible : "mediatek,mt8173-vcodec-enc" for encoder
+- reg : Physical base address of the video codec registers and length of
+  memory mapped region.
+- interrupts : interrupt number to the cpu.
+- mediatek,larb : must contain the local arbiters in the current Socs.
+- clocks : list of clock specifiers, corresponding to entries in
+  the clock-names property.
+- clock-names: encoder must contain "venc_sel_src", "venc_sel",
+  "venc_lt_sel_src", "venc_lt_sel".
+- iommus : should point to the respective IOMMU block with master port as
+  argument, see Documentation/devicetree/bindings/iommu/mediatek,iommu.txt
+  for details.
+- mediatek,vpu : the node of video processor unit
+
+Example:
+vcodec_enc: vcodec@0x18002000 {
+compatible = "mediatek,mt8173-vcodec-enc";
+reg = <0 0x18002000 0 0x1000>,/*VENC_SYS*/
+  <0 0x19002000 0 0x1000>;/*VENC_LT_SYS*/
+interrupts = ,
+   ;
+mediatek,larb = <&larb3>,
+   <&larb5>;
+iommus = <&iommu M4U_PORT_VENC_RCPU>,
+ <&iommu M4U_PORT_VENC_REC>,
+ <&iommu M4U_PORT_VENC_BSDMA>,
+ <&iommu M4U_PORT_VENC_SV_COMV>,
+ <&iommu M4U_PORT_VENC_RD_COMV>,
+ <&iommu M4U_PORT_VENC_CUR_LUMA>,
+ <&iommu M4U_PORT_VENC_CUR_CHROMA>,
+ <&iommu M4U_PORT_VENC_REF_LUMA>,
+ <&iommu M4U_PORT_VENC_REF_CHROMA>,
+ <&iommu M4U_PORT_VENC_NBM_RDMA>,
+ <&iommu M4U_PORT_VENC_NBM_WDMA>,
+ <&iommu M4U_PORT_VENC_RCPU_SET2>,
+ <&iommu M4U_PORT_VENC_REC_FRM_SET2>,
+ <&iommu M4U_PORT_VENC_BSDMA_SET2>,
+ <&iommu M4U_PORT_VENC_SV_COMA_SET2>,
+ <&iommu M4U_PORT_VENC_RD_COMA_SET2>,
+ <&iommu M4U_PORT_VENC_CUR_LUMA_SET2>,
+ <&iommu M4U_PORT_VENC_CUR_CHROMA_SET2>,
+ <&iommu M4U_PORT_VENC_REF_LUMA_SET2>,
+ <&iommu M4U_PORT_VENC_REC_CHROMA_SET2>;
+mediatek,vpu = <&vpu>;
+clocks = <&topckgen CLK_TOP_VENCPLL_D2>,
+ <&topckgen CLK_TOP_VENC_SEL>,
+ <&topckgen CLK_TOP_UNIVPLL1_D2>,
+ <&topckgen CLK_TOP_VENC_LT_SEL>;
+clock-names = "venc_sel_src",
+  "venc_sel",
+  "venc_lt_sel_src",
+  "venc_lt_sel";
+  };
-- 
1.7.9.5



[PATCH v5 3/8] arm64: dts: mediatek: Add node for Mediatek Video Processor Unit

2016-02-23 Thread Tiffany Lin
From: Andrew-CT Chen 

Add VPU drivers for MT8173

Signed-off-by: Andrew-CT Chen 
Signed-off-by: Tiffany Lin 
---
 arch/arm64/boot/dts/mediatek/mt8173.dtsi |   23 +++
 1 file changed, 23 insertions(+)

diff --git a/arch/arm64/boot/dts/mediatek/mt8173.dtsi 
b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
index 60a1284..5b0b38a 100644
--- a/arch/arm64/boot/dts/mediatek/mt8173.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
@@ -200,6 +200,18 @@
clock-output-names = "cpum_ck";
};
 
+   reserved-memory {
+   #address-cells = <2>;
+   #size-cells = <2>;
+   ranges;
+   vpu_dma_reserved: vpu_dma_mem_region {
+   compatible = "shared-dma-pool";
+   reg = <0 0xb700 0 0x50>;
+   alignment = <0x1000>;
+   no-map;
+   };
+   };
+
thermal-zones {
cpu_thermal: cpu_thermal {
polling-delay-passive = <1000>; /* milliseconds */
@@ -422,6 +434,17 @@
clocks = <&infracfg CLK_INFRA_CEC>;
};
 
+   vpu: vpu@1002 {
+   compatible = "mediatek,mt8173-vpu";
+   reg = <0 0x1002 0 0x3>,
+ <0 0x1005 0 0x100>;
+   reg-names = "tcm", "cfg_reg";
+   interrupts = ;
+   clocks = <&topckgen CLK_TOP_SCP_SEL>;
+   clock-names = "main";
+   memory-region = <&vpu_dma_reserved>;
+   };
+
sysirq: intpol-controller@10200620 {
compatible = "mediatek,mt8173-sysirq",
 "mediatek,mt6577-sysirq";
-- 
1.7.9.5



[PATCH v5 8/8] arm64: dts: mediatek: Add Video Encoder for MT8173

2016-02-23 Thread Tiffany Lin
Add video encoder node for MT8173

Signed-off-by: Tiffany Lin 
---
 arch/arm64/boot/dts/mediatek/mt8173.dtsi |   39 ++
 1 file changed, 39 insertions(+)

diff --git a/arch/arm64/boot/dts/mediatek/mt8173.dtsi 
b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
index 5b0b38a..26aeffe 100644
--- a/arch/arm64/boot/dts/mediatek/mt8173.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
@@ -1150,6 +1150,45 @@
clock-names = "apb", "smi";
};
 
+   vcodec_enc: vcodec@18002000 {
+   compatible = "mediatek,mt8173-vcodec-enc";
+   reg = <0 0x18002000 0 0x1000>,  /* VENC_SYS */
+ <0 0x19002000 0 0x1000>;  /* VENC_LT_SYS */
+   interrupts = ,
+;
+   mediatek,larb = <&larb3>,
+   <&larb5>;
+   iommus = <&iommu M4U_PORT_VENC_RCPU>,
+<&iommu M4U_PORT_VENC_REC>,
+<&iommu M4U_PORT_VENC_BSDMA>,
+<&iommu M4U_PORT_VENC_SV_COMV>,
+<&iommu M4U_PORT_VENC_RD_COMV>,
+<&iommu M4U_PORT_VENC_CUR_LUMA>,
+<&iommu M4U_PORT_VENC_CUR_CHROMA>,
+<&iommu M4U_PORT_VENC_REF_LUMA>,
+<&iommu M4U_PORT_VENC_REF_CHROMA>,
+<&iommu M4U_PORT_VENC_NBM_RDMA>,
+<&iommu M4U_PORT_VENC_NBM_WDMA>,
+<&iommu M4U_PORT_VENC_RCPU_SET2>,
+<&iommu M4U_PORT_VENC_REC_FRM_SET2>,
+<&iommu M4U_PORT_VENC_BSDMA_SET2>,
+<&iommu M4U_PORT_VENC_SV_COMA_SET2>,
+<&iommu M4U_PORT_VENC_RD_COMA_SET2>,
+<&iommu M4U_PORT_VENC_CUR_LUMA_SET2>,
+<&iommu M4U_PORT_VENC_CUR_CHROMA_SET2>,
+<&iommu M4U_PORT_VENC_REF_LUMA_SET2>,
+<&iommu M4U_PORT_VENC_REC_CHROMA_SET2>;
+   mediatek,vpu = <&vpu>;
+   clocks = <&topckgen CLK_TOP_VENCPLL_D2>,
+<&topckgen CLK_TOP_VENC_SEL>,
+<&topckgen CLK_TOP_UNIVPLL1_D2>,
+<&topckgen CLK_TOP_VENC_LT_SEL>;
+   clock-names = "venc_sel_src",
+ "venc_sel",
+ "venc_lt_sel_src",
+ "venc_lt_sel";
+   };
+
vencltsys: clock-controller@1900 {
compatible = "mediatek,mt8173-vencltsys", "syscon";
reg = <0 0x1900 0 0x1000>;
-- 
1.7.9.5



[PATCH v5 7/8] [media] vcodec: mediatek: Add Mediatek H264 Video Encoder Driver

2016-02-23 Thread Tiffany Lin
From: PoChun Lin 

Add h264 encoder driver for MT8173

Signed-off-by: pochun.lin 
Signed-off-by: Tiffany Lin 
---
 drivers/media/platform/mtk-vcodec/Makefile |3 +-
 .../media/platform/mtk-vcodec/h264_enc/Makefile|6 +
 .../platform/mtk-vcodec/h264_enc/venc_h264_if.c|  526 
 .../platform/mtk-vcodec/h264_enc/venc_h264_if.h|  168 +++
 .../platform/mtk-vcodec/h264_enc/venc_h264_vpu.c   |  309 
 .../platform/mtk-vcodec/h264_enc/venc_h264_vpu.h   |   30 ++
 drivers/media/platform/mtk-vcodec/venc_drv_if.c|3 +
 7 files changed, 1044 insertions(+), 1 deletion(-)
 create mode 100644 drivers/media/platform/mtk-vcodec/h264_enc/Makefile
 create mode 100644 drivers/media/platform/mtk-vcodec/h264_enc/venc_h264_if.c
 create mode 100644 drivers/media/platform/mtk-vcodec/h264_enc/venc_h264_if.h
 create mode 100644 drivers/media/platform/mtk-vcodec/h264_enc/venc_h264_vpu.c
 create mode 100644 drivers/media/platform/mtk-vcodec/h264_enc/venc_h264_vpu.h

diff --git a/drivers/media/platform/mtk-vcodec/Makefile 
b/drivers/media/platform/mtk-vcodec/Makefile
index f4ef502..f47dfc7 100644
--- a/drivers/media/platform/mtk-vcodec/Makefile
+++ b/drivers/media/platform/mtk-vcodec/Makefile
@@ -5,6 +5,7 @@ obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += mtk_vcodec_intr.o \
   mtk_vcodec_enc_pm.o \
   venc_drv_if.o
 
-obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += vp8_enc/
+
+obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += vp8_enc/ h264_enc/
 
 ccflags-y += -I$(srctree)/drivers/media/platform/mtk-vpu
diff --git a/drivers/media/platform/mtk-vcodec/h264_enc/Makefile 
b/drivers/media/platform/mtk-vcodec/h264_enc/Makefile
new file mode 100644
index 000..765b45f
--- /dev/null
+++ b/drivers/media/platform/mtk-vcodec/h264_enc/Makefile
@@ -0,0 +1,6 @@
+obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += venc_h264_if.o venc_h264_vpu.o
+
+ccflags-y += \
+-I$(srctree)/drivers/media/platform/mtk-vcodec/ \
+-I$(srctree)/drivers/media/platform/mtk-vcodec/h264_enc \
+-I$(srctree)/drivers/media/platform/mtk-vpu
diff --git a/drivers/media/platform/mtk-vcodec/h264_enc/venc_h264_if.c 
b/drivers/media/platform/mtk-vcodec/h264_enc/venc_h264_if.c
new file mode 100644
index 000..6a38576
--- /dev/null
+++ b/drivers/media/platform/mtk-vcodec/h264_enc/venc_h264_if.c
@@ -0,0 +1,526 @@
+/*
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Jungchang Tsao 
+ * Daniel Hsiao 
+ * PoChun Lin 
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+
+#include "mtk_vcodec_drv.h"
+#include "mtk_vcodec_util.h"
+#include "mtk_vcodec_intr.h"
+#include "mtk_vcodec_enc.h"
+#include "mtk_vcodec_pm.h"
+#include "mtk_vpu.h"
+
+#include "venc_h264_if.h"
+#include "venc_h264_vpu.h"
+
+#define VENC_PIC_BITSTREAM_BYTE_CNT 0x0098
+
+enum venc_h264_irq_status {
+   H264_IRQ_STATUS_ENC_SPS_INT = (1 << 0),
+   H264_IRQ_STATUS_ENC_PPS_INT = (1 << 1),
+   H264_IRQ_STATUS_ENC_FRM_INT = (1 << 2),
+};
+
+static inline void h264_write_reg(struct venc_h264_inst *inst, u32 addr,
+ u32 val)
+{
+   writel(val, inst->hw_base + addr);
+}
+
+static inline u32 h264_read_reg(struct venc_h264_inst *inst, u32 addr)
+{
+   return readl(inst->hw_base + addr);
+}
+
+static void h264_enc_free_work_buf(struct venc_h264_inst *inst)
+{
+   int i;
+
+   mtk_vcodec_debug_enter(inst);
+
+   /* Except the SKIP_FRAME buffers,
+* other buffers need to be freed by AP.
+*/
+   for (i = 0; i < VENC_H264_VPU_WORK_BUF_MAX; i++) {
+   if (i != VENC_H264_VPU_WORK_BUF_SKIP_FRAME)
+   if (inst->work_bufs[i].va != NULL)
+   mtk_vcodec_mem_free(inst->ctx,
+   &inst->work_bufs[i]);
+   }
+
+   if (inst->pps_buf.va != NULL)
+   mtk_vcodec_mem_free(inst->ctx, &inst->pps_buf);
+
+   mtk_vcodec_debug_leave(inst);
+}
+
+static int h264_enc_alloc_work_buf(struct venc_h264_inst *inst, void *param)
+{
+   int i;
+   int ret = 0;
+   struct venc_h264_vpu_buf *wb = inst->vpu_inst.drv->work_bufs;
+   struct venc_enc_prm *enc_param = param;
+
+   mtk_vcodec_debug_enter(inst);
+
+   for (i = 0; i < VENC_H264_VPU_WORK_BUF_MAX; i++) {
+   /*
+* This 'wb' structure is set by VPU side and shared to AP for
+* buffer allocation and IO virtual addr mapping. For most of
+* the buffers, AP will

[PATCH v5 6/8] [media] vcodec: mediatek: Add Mediatek VP8 Video Encoder Driver

2016-02-23 Thread Tiffany Lin
From: PoChun Lin 

Add vp8 encoder driver for MT8173

Signed-off-by: pochun.lin 
Signed-off-by: Tiffany Lin 
---
 drivers/media/platform/mtk-vcodec/Makefile |2 +
 drivers/media/platform/mtk-vcodec/venc_drv_if.c|3 +
 drivers/media/platform/mtk-vcodec/vp8_enc/Makefile |6 +
 .../platform/mtk-vcodec/vp8_enc/venc_vp8_if.c  |  419 
 .../platform/mtk-vcodec/vp8_enc/venc_vp8_if.h  |  152 +++
 .../platform/mtk-vcodec/vp8_enc/venc_vp8_vpu.c |  240 +++
 .../platform/mtk-vcodec/vp8_enc/venc_vp8_vpu.h |   28 ++
 7 files changed, 850 insertions(+)
 create mode 100644 drivers/media/platform/mtk-vcodec/vp8_enc/Makefile
 create mode 100644 drivers/media/platform/mtk-vcodec/vp8_enc/venc_vp8_if.c
 create mode 100644 drivers/media/platform/mtk-vcodec/vp8_enc/venc_vp8_if.h
 create mode 100644 drivers/media/platform/mtk-vcodec/vp8_enc/venc_vp8_vpu.c
 create mode 100644 drivers/media/platform/mtk-vcodec/vp8_enc/venc_vp8_vpu.h

diff --git a/drivers/media/platform/mtk-vcodec/Makefile 
b/drivers/media/platform/mtk-vcodec/Makefile
index ce38689..f4ef502 100644
--- a/drivers/media/platform/mtk-vcodec/Makefile
+++ b/drivers/media/platform/mtk-vcodec/Makefile
@@ -5,4 +5,6 @@ obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += mtk_vcodec_intr.o \
   mtk_vcodec_enc_pm.o \
   venc_drv_if.o
 
+obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += vp8_enc/
+
 ccflags-y += -I$(srctree)/drivers/media/platform/mtk-vpu
diff --git a/drivers/media/platform/mtk-vcodec/venc_drv_if.c 
b/drivers/media/platform/mtk-vcodec/venc_drv_if.c
index 1675b9e..f631f5d 100644
--- a/drivers/media/platform/mtk-vcodec/venc_drv_if.c
+++ b/drivers/media/platform/mtk-vcodec/venc_drv_if.c
@@ -25,6 +25,7 @@
 #include "mtk_vpu.h"
 
 #include "venc_drv_base.h"
+#include "vp8_enc/venc_vp8_if.h"
 
 int venc_if_create(struct mtk_vcodec_ctx *ctx, unsigned int fourcc)
 {
@@ -35,6 +36,8 @@ int venc_if_create(struct mtk_vcodec_ctx *ctx, unsigned int 
fourcc)
 
switch (fourcc) {
case V4L2_PIX_FMT_VP8:
+   ctx->enc_if = get_vp8_enc_comm_if();
+   break;
case V4L2_PIX_FMT_H264:
default:
return -EINVAL;
diff --git a/drivers/media/platform/mtk-vcodec/vp8_enc/Makefile 
b/drivers/media/platform/mtk-vcodec/vp8_enc/Makefile
new file mode 100644
index 000..0f515c7
--- /dev/null
+++ b/drivers/media/platform/mtk-vcodec/vp8_enc/Makefile
@@ -0,0 +1,6 @@
+obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += venc_vp8_if.o venc_vp8_vpu.o
+
+ccflags-y += \
+-I$(srctree)/drivers/media/platform/mtk-vcodec/ \
+-I$(srctree)/drivers/media/platform/mtk-vcodec/vp8_enc \
+-I$(srctree)/drivers/media/platform/mtk-vpu
diff --git a/drivers/media/platform/mtk-vcodec/vp8_enc/venc_vp8_if.c 
b/drivers/media/platform/mtk-vcodec/vp8_enc/venc_vp8_if.c
new file mode 100644
index 000..b9dcf4d
--- /dev/null
+++ b/drivers/media/platform/mtk-vcodec/vp8_enc/venc_vp8_if.c
@@ -0,0 +1,419 @@
+/*
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Daniel Hsiao 
+ * PoChun Lin 
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+
+#include "mtk_vcodec_drv.h"
+#include "mtk_vcodec_util.h"
+#include "mtk_vcodec_intr.h"
+#include "mtk_vcodec_enc.h"
+#include "mtk_vcodec_pm.h"
+#include "mtk_vpu.h"
+
+#include "venc_vp8_if.h"
+#include "venc_vp8_vpu.h"
+
+#define VENC_PIC_BITSTREAM_BYTE_CNT 0x0098
+#define VENC_PIC_BITSTREAM_BYTE_CNT1 0x00e8
+#define VENC_IRQ_STATUS_ENC_FRM_INT 0x04
+
+#define MAX_AC_TAG_SZ 10
+
+static inline void vp8_enc_write_reg(struct venc_vp8_inst *inst, u32 addr,
+u32 val)
+{
+   writel(val, inst->hw_base + addr);
+}
+
+static inline u32 vp8_enc_read_reg(struct venc_vp8_inst *inst, u32 addr)
+{
+   return readl(inst->hw_base + addr);
+}
+
+static void vp8_enc_free_work_buf(struct venc_vp8_inst *inst)
+{
+   int i;
+
+   mtk_vcodec_debug_enter(inst);
+
+   /* Buffers need to be freed by AP. */
+   for (i = 0; i < VENC_VP8_VPU_WORK_BUF_MAX; i++)
+   if (inst->work_bufs[i].va != NULL)
+   mtk_vcodec_mem_free(inst->ctx,
+   &inst->work_bufs[i]);
+
+   mtk_vcodec_debug_leave(inst);
+}
+
+static int vp8_enc_alloc_work_buf(struct venc_vp8_inst *inst, void *param)
+{
+   int i;
+   int ret = 0;
+   struct venc_vp8_vpu_buf *wb = inst->vpu_inst.drv->work_bufs;
+   struct venc_enc_prm *enc_param = param;
+
+   mtk_vcodec_debug_enter(ins

Re: [PATCH 00/33] Compile-time stack metadata validation

2016-02-23 Thread Ingo Molnar

So I tried out this latest stacktool series and it looks mostly good for an 
upstream merge.

To help this effort move forward I've applied the preparatory/fix patches that 
are 
part of this series to tip:x86/debug - that's 26 out of 31 patches. (I've 
propagated all the acks that the latest submission got into the changelogs.)

I have 5 (easy to address) observations that need to be addressed before we can 
move on with the rest of the merge:

1)

Due to recent changes to x86 exception handling, I get a lot of bogus warnings 
about exception table sizes:

  stacktool: arch/x86/kernel/cpu/mcheck/mce.o: __ex_table size not a multiple 
of 24
  stacktool: arch/x86/kernel/cpu/mtrr/generic.o: __ex_table size not a multiple 
of 24
  stacktool: arch/x86/kernel/cpu/mtrr/cleanup.o: __ex_table size not a multiple 
of 24

this is due to:

  548acf19234d x86/mm: Expand the exception table logic to allow new handling 
options

2)

The fact that 'stacktool' already checks about assembly details like 
__ex_table[] 
shows that my review feedback early iterations of this series, that the 
'stacktool' name is too specific, was correct.

We really need to rename it before it gets upstream and the situation gets 
worse. 
__ex_table[] has obviously nothing to do with the 'stack layout' of binaries.

Another suitable name would be 'asmtool' or 'objtool'. For example the 
following 
would naturally express what it does:

  objtool check kernel/built-in.o

the name expresses that the tool checks object files, independently of the 
existing toolchain. Its primary purpose right now is the checking of stack 
layout 
details, but the tool is not limited to that at all.

3)

There's quite a bit of overhead when running the tool on larger object files, 
most 
prominently in cmd_check():

62.06%  stacktoolstacktool  [.] 
cmd_check
 6.72%  stacktoolstacktool  [.] 
find_rela_by_dest_range

I added -g to the CFLAGS, which made it visible to annotated output of perf top:

0.00 :40430d:   lea0x4(%rdx,%rax,1),%r13
 :  find_instruction():
 :  struct section *sec,
 :  unsigned long 
offset)
 :  {
 :  struct instruction *insn;
 :
 :  list_for_each_entry(insn, &file->insns, list)
0.03 :404312:   mov0x38(%rsp),%rax
0.00 :404317:   cmp%rbp,%rax
0.00 :40431a:   jne404334 
0.00 :40431c:   jmpq   4045ba 
0.00 :404321:   nopl   0x0(%rax)
6.14 :404328:   mov(%rax),%rax
0.00 :40432b:   cmp%rbp,%rax
2.02 :40432e:   je 4045ba 
 :  if (insn->sec == sec && insn->offset == offset)
0.55 :404334:   cmp%r12,0x10(%rax)
   87.91 :404338:   jne404328 
0.00 :40433a:   cmp%r13,0x18(%rax)
3.36 :40433e:   jne404328 
 :  get_jump_destinations():
 :   * later in validate_functions().
 :   */
 :  continue;
 :  }
 :
 :  insn->jump_dest = find_instruction(file, 
dest_sec, dest_off);
0.00 :404340:   mov%rax,0x48(%rbx)
0.00 :404344:   jmpq   4042b0 
0.00 :404349:   nopl   0x0(%rax)
 :  fprintf():
 :
 :  # ifdef __va_arg_pack
 :  __fortify_function int
 :  fprintf (FILE *__restrict __stream, const char *__restrict 
__fmt, ...)
 :  {
 :return __fprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, 
__fmt,

that looks like a linear list search? That would suck with thousands of entries.

(If this is non-trivial to improve then we can delay this optimization to a 
later 
patch.)

4)

I think the various 'STACKTOOL' flags in the kernel source are a bit of a 
misnomer 
- it's not the tool we want to name but the actual property of the code.

So instead of:

  STACKTOOL_IGNORE_FUNC(__bpf_prog_run);

we should do something like:

  STACK_FRAME_NON_STANDARD(__bpf_prog_run);

see how much more expressive it is? It becomes a function attribute independent 
of 
the tooling that makes use of it.

Similarly, for the highest level 'don't check these directories' makefile 
flags, 
I'd suggest, instead of using this rather opaque, tool dependent naming:

  STACKTOOL := n

something more specific, like:

  OBJECT_FILES_NON_STANDARD := y

which makes it clearer what's going on: these are special object files that are 
not the typical kernel object files.

Stacktool (or objtool) would be one consumer of this annotation.

I think Boris made similar observat

Re: [PATCH] ARM: dts: add support for gpio buttons for exynos5422-odroidxu3

2016-02-23 Thread Krzysztof Kozlowski
On 23.02.2016 17:01, Anand Moon wrote:
> Add support for gpio-based button on Odroid-XU3 boards
> for reboot/poweroff feature.
> 
> Signed-off-by: Anand Moon 
> ---
> changes rebase based on linux next-20160222.
> 
> Tested on Odroid-XU4
> 
> dmesg output.
> [3.286068] of_get_named_gpiod_flags: parsed 'gpios' property of node 
> '/gpio_keys/power_key[0]' - status (0)
> [3.286206] gpio-11 (power key): gpiod_set_debounce: missing set() or 
> set_debounce() operations
> [3.286600] input: gpio_keys as /devices/platform/gpio_keys/input/input0
> ---
>  arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi | 22 
> ++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi 
> b/arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi
> index 1bd507b..db9770b 100644
> --- a/arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi
> +++ b/arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi
> @@ -11,6 +11,7 @@
>  */
>  
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -54,6 +55,22 @@
>   #cooling-cells = <2>;
>   cooling-levels = <0 130 170 230>;
>   };
> +
> + gpio_keys {
> + compatible = "gpio-keys";
> + pinctrl-names = "default";
> + pinctrl-0 = <&gpio_power_key>;
> +
> + power_key {
> + interrupt-parent = <&gpx0>;
> + interrupts = <3 IRQ_TYPE_NONE>;

Hmmm why you specify the interrupts?

> + gpios = <&gpx0 3 GPIO_ACTIVE_LOW>;
> + linux,code = ;
> + label = "power key";

Just "power".

> + debounce-interval = <10>;
> + wakeup-source;
> + };
> + };
>  };
>  
>  &clock_audss {
> @@ -362,6 +379,11 @@
>  };
>  
>  &pinctrl_0 {
> + gpio_power_key: power_key {

The naming is mixed... Everything is GPIO here so don't add such prefix.
Underscores only in label, not in name of node.

power_key_irq: power-key-irq {

> + samsung,pins = "gpx0-3";
> + samsung,pin-pud = <0>;

Don't you want to set specific pin function? And what about drive strength?

Best regards,
Krzysztof

> + };
> +
>   hdmi_hpd_irq: hdmi-hpd-irq {
>   samsung,pins = "gpx3-7";
>   samsung,pin-function = <0>;
> 



[PATCH] ASoC: mediatek: remove soft reset and add second I2S clock

2016-02-23 Thread PC Liao
To improve I2S flow, this patch removes soft reset and adds second
I2S clock to use.

Signed-off-by: PC Liao 
---
 sound/soc/mediatek/mtk-afe-pcm.c |   14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/sound/soc/mediatek/mtk-afe-pcm.c b/sound/soc/mediatek/mtk-afe-pcm.c
index 689c51f..3456bfa 100644
--- a/sound/soc/mediatek/mtk-afe-pcm.c
+++ b/sound/soc/mediatek/mtk-afe-pcm.c
@@ -283,20 +283,13 @@ static void mtk_afe_set_i2s_enable(struct mtk_afe *afe, 
bool enable)
 
regmap_read(afe->regmap, AFE_I2S_CON2, &val);
if (!!(val & AFE_I2S_CON2_EN) == enable)
-   return; /* must skip soft reset */
-
-   /* I2S soft reset begin */
-   regmap_update_bits(afe->regmap, AUDIO_TOP_CON1, 0x4, 0x4);
+   return;
 
/* input */
regmap_update_bits(afe->regmap, AFE_I2S_CON2, 0x1, enable);
 
/* output */
regmap_update_bits(afe->regmap, AFE_I2S_CON1, 0x1, enable);
-
-   /* I2S soft reset end */
-   udelay(1);
-   regmap_update_bits(afe->regmap, AUDIO_TOP_CON1, 0x4, 0);
 }
 
 static int mtk_afe_dais_enable_clks(struct mtk_afe *afe,
@@ -365,6 +358,7 @@ static int mtk_afe_i2s_startup(struct snd_pcm_substream 
*substream,
return 0;
 
mtk_afe_dais_enable_clks(afe, afe->clocks[MTK_CLK_I2S1_M], NULL);
+   mtk_afe_dais_enable_clks(afe, afe->clocks[MTK_CLK_I2S2_M], NULL);
regmap_update_bits(afe->regmap, AUDIO_TOP_CON0,
   AUD_TCON0_PDN_22M | AUD_TCON0_PDN_24M, 0);
return 0;
@@ -384,6 +378,7 @@ static void mtk_afe_i2s_shutdown(struct snd_pcm_substream 
*substream,
   AUD_TCON0_PDN_22M | AUD_TCON0_PDN_24M,
   AUD_TCON0_PDN_22M | AUD_TCON0_PDN_24M);
mtk_afe_dais_disable_clks(afe, afe->clocks[MTK_CLK_I2S1_M], NULL);
+   mtk_afe_dais_disable_clks(afe, afe->clocks[MTK_CLK_I2S2_M], NULL);
 }
 
 static int mtk_afe_i2s_prepare(struct snd_pcm_substream *substream,
@@ -397,6 +392,9 @@ static int mtk_afe_i2s_prepare(struct snd_pcm_substream 
*substream,
mtk_afe_dais_set_clks(afe,
  afe->clocks[MTK_CLK_I2S1_M], runtime->rate * 256,
  NULL, 0);
+   mtk_afe_dais_set_clks(afe,
+ afe->clocks[MTK_CLK_I2S2_M], runtime->rate * 256,
+ NULL, 0);
/* config I2S */
ret = mtk_afe_set_i2s(afe, substream->runtime->rate);
if (ret)
-- 
1.7.9.5



Re: [RFC][PATCH v2 3/3] mm/zsmalloc: increase ZS_MAX_PAGES_PER_ZSPAGE

2016-02-23 Thread Minchan Kim
On Mon, Feb 22, 2016 at 07:43:25PM +0900, Sergey Senozhatsky wrote:
> On (02/22/16 13:41), Minchan Kim wrote:
> [..]
> > > oh, sure.
> > > 
> > > so let's keep dynamic page allocation out of sight for now.
> > > I'll do more tests with the increase ORDER and if it's OK then
> > > hopefully we can just merge it, it's quite simple and shouldn't
> > > interfere with any of the changes you are about to introduce.
> > 
> > Thanks.
> > 
> > And as another idea, we could try fallback approach that
> > we couldn't meet nr_pages to minimize wastage so let's fallback
> > to order-0 page like as-is. It will enhance, at least than now
> > with small-amount of code compared to dynmaic page allocation.
> 
> 
> speaking of fallback,
> with bigger ZS_MAX_ZSPAGE_ORDER 'normal' classes also become bigger.
> 
> PATCHED
> 
>  6   128   0196 78  3 
>1
>  7   144   01   256104  9 
>9
>  8   160   01   128 80  5 
>5
>  9   176   01   256 78 11 
>   11
> 10   192   11   128 99  6 
>3
> 11   208   01   256 52 13 
>   13
> 12   224   11   512472 28 
>7
> 13   240   01   256 70 15 
>   15
> 14   256   1164 49  4 
>1
> 15   272   0160 48  4 
>1
> 
> 
> BASE
> 
>  6   128   0196 83  3 
>1
>  7   144   01   170113  6 
>3
>  8   160   01   102 72  4 
>2
>  9   176   1093 75  4 
>4
> 10   192   01   128104  6 
>3
> 11   208   1178 52  4 
>2
> 12   224   11   511475 28 
>4
> 13   240   1185 73  5 
>1
> 14   256   1164 53  4 
>1
> 15   272   1045 43  3 
>1
> 
> 
> _techically_, zsmalloc is correct.
> for instance, in 11 pages we can store 4096 * 11 / 176 == 256 objects.
> 256 * 176 == 45056, which is 4096 * 11. so if zspage for class_size 176 will 
> contain 11
> order-0 pages, we can count on 0 bytes of unused space once zspage will 
> become ZS_FULL.
> 
> but it's ugly, because I think this will introduce bigger internal 
> fragmentation, which,
> in some cases, can be handled by compaction, but I'd prefer to touch only 
> ->huge classes
> and keep the existing behaviour for normal classes.
> 
> so I'm currently thinking of doing something like this
> 
> #define ZS_MAX_ZSPAGE_ORDER   2
> #define ZS_MAX_HUGE_ZSPAGE_ORDER  4
> #define ZS_MAX_PAGES_PER_ZSPAGE (_AC(1, UL) << ZS_MAX_ZSPAGE_ORDER)
> #define ZS_MAX_PAGES_PER_HUGE_ZSPAGE (_AC(1, UL) << ZS_MAX_HUGE_ZSPAGE_ORDER)
> 
> 
> so, normal classes have ORDER of 2. huge classes, however, as a fallback, can 
> grow
> up to ZS_MAX_HUGE_ZSPAGE_ORDER pages.
> 
> 
> extend only ->huge classes: pages == 1 && get_maxobj_per_zspage(class_size, 
> pages) == 1.
> 
> like this:
> 
> static int __get_pages_per_zspage(int class_size, int max_pages)
> {
> int i, max_usedpc = 0;
> /* zspage order which gives maximum used size per KB */
> int max_usedpc_order = 1;
> 
> for (i = 1; i <= max_pages; i++) {
> int zspage_size;
> int waste, usedpc;
> 
> zspage_size = i * PAGE_SIZE;
> waste = zspage_size % class_size;
> usedpc = (zspage_size - waste) * 100 / zspage_size;
> 
> if (usedpc > max_usedpc) {
> max_usedpc = usedpc;
> max_usedpc_order = i;
> }
> }
> 
> return max_usedpc_order;
> }
> 
> static int get_pages_per_zspage(int class_size)
> {
> /* normal class first */
> int pages = __get_pages_per_zspage(class_size,
> ZS_MAX_PAGES_PER_ZSPAGE);
> 
> /* test if the class is ->huge and try to turn it into a normal one */
> if (pages == 1 &&
> get_maxobj_per_zspage(class_size, pages) == 1) {
> pages = __get_pages_per_zspage(class_s

[lkp] [kernel/fs] d57d611505: +54.7% turbostat.%Busy

2016-02-23 Thread kernel test robot
FYI, we noticed the below changes on

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
commit d57d611505d911c6f9f81cd9bd6dbd293d66dd9f ("kernel/fs: fix I/O wait not 
accounted for RW O_DSYNC")


=
compiler/cpufreq_governor/disk/filesize/fs/iterations/kconfig/nr_directories/nr_files_per_directory/nr_threads/rootfs/sync_method/tbox_group/test_size/testcase:
  
gcc-4.9/performance/1HDD/9B/f2fs/1x/x86_64-rhel/16d/256fpd/32t/debian-x86_64-2015-02-07.cgz/fsyncBeforeClose/lkp-ne04/400M/fsmark

commit: 
  09954bad448791ef01202351d437abdd9497a804
  d57d611505d911c6f9f81cd9bd6dbd293d66dd9f

09954bad448791ef d57d611505d911c6f9f81cd9bd 
 -- 
 %stddev %change %stddev
 \  |\  
 14760 ±  1%  +6.3%  15695 ±  1%  
fsmark.time.involuntary_context_switches
 46.00 ±  0%  -8.2%  42.25 ±  1%  
fsmark.time.percent_of_cpu_this_job_got
 26151 ±116% -71.3%   7498 ± 23%  
latency_stats.sum.call_rwsem_down_read_failed.f2fs_mkdir.[f2fs].vfs_mkdir.SyS_mkdir.entry_SYSCALL_64_fastpath
  7418 ± 23% -27.7%   5361 ±  3%  
numa-vmstat.node0.nr_slab_unreclaimable
  1.47 ±  1%  -9.9%   1.33 ±  0%  time.user_time
  1447 ±  4% -29.0%   1028 ±  7%  uptime.idle
  7.75 ± 19%+206.5%  23.75 ±  1%  vmstat.procs.b
 29675 ± 23% -27.7%  21447 ±  3%  numa-meminfo.node0.SUnreclaim
 83099 ±  8% -11.5%  73568 ±  1%  numa-meminfo.node0.Slab
 11.91 ±  1% +54.7%  18.43 ±  1%  turbostat.%Busy
358.00 ±  1% +60.0% 572.75 ±  1%  turbostat.Avg_MHz
 21.54 ±  0% -17.4%  17.79 ±  1%  turbostat.CPU%c1
 24.78 ±  3% +41.1%  34.98 ±  1%  turbostat.CPU%c3
 41.76 ±  1% -31.0%  28.81 ±  1%  turbostat.CPU%c6
  8.53 ±  5% -25.6%   6.34 ± 10%  turbostat.Pkg%pc3
  66312232 ±  0% -68.5%   20910669 ±  4%  cpuidle.C1-NHM.time
  46386272 ±  2% -20.5%   36884085 ±  5%  cpuidle.C1E-NHM.time
  2.79e+08 ±  2% +51.5%  4.226e+08 ±  0%  cpuidle.C3-NHM.time
254315 ±  2% +25.1% 318250 ±  2%  cpuidle.C3-NHM.usage
 7.585e+08 ±  1% -22.2%  5.901e+08 ±  1%  cpuidle.C6-NHM.time
415414 ±  1% -38.1% 257115 ±  1%  cpuidle.C6-NHM.usage
 1.135e+08 ±  1% +77.8%  2.017e+08 ±  2%  cpuidle.POLL.time
102777 ±  1% +36.0% 139811 ±  1%  cpuidle.POLL.usage
  2011 ± 25% -27.1%   1467 ±  2%  sched_debug.cfs_rq:/.exec_clock.2
  1820 ±  3% -12.2%   1597 ±  7%  sched_debug.cfs_rq:/.exec_clock.4
  4297 ±  6% +78.1%   7653 ± 54%  
sched_debug.cfs_rq:/.min_vruntime.12
  4803 ± 18% -16.1%   4028 ± 21%  
sched_debug.cfs_rq:/.min_vruntime.8
  3763 ±  4% -17.0%   3124 ±  7%  
sched_debug.cfs_rq:/.min_vruntime.9
  3408 ±  4% -14.9%   2900 ±  2%  
sched_debug.cfs_rq:/.min_vruntime.min
  4.75 ± 54% -73.7%   1.25 ±173%  
sched_debug.cfs_rq:/.nr_spread_over.2
  1.99 ± 16% +25.5%   2.50 ±  9%  
sched_debug.cfs_rq:/.nr_spread_over.stddev
 -4362 ±-25% -92.7%-318.24 ±-1304%  sched_debug.cfs_rq:/.spread0.12
200.25 ± 47% -48.8% 102.50 ± 22%  sched_debug.cfs_rq:/.util_avg.7
187.75 ± 64% -77.2%  42.75 ± 56%  sched_debug.cfs_rq:/.util_avg.8
  1.41 ± 31% +37.0%   1.93 ± 12%  sched_debug.cpu.clock.stddev
  1.41 ± 31% +37.0%   1.93 ± 12%  sched_debug.cpu.clock_task.stddev
  1.63 ± 67% -53.9%   0.75 ± 38%  sched_debug.cpu.cpu_load[4].stddev
 33822 ± 16% -17.2%  28018 ±  4%  sched_debug.cpu.nr_switches.13
 36824 ±  3% +12.9%  41569 ±  4%  sched_debug.cpu.nr_switches.14
 33117 ±  7% -11.1%  29438 ±  5%  sched_debug.cpu.nr_switches.15
 57634 ±  3%  +8.8%  62716 ±  3%  sched_debug.cpu.nr_switches.4
  1723 ±  7% -11.3%   1527 ±  5%  
sched_debug.cpu.nr_uninterruptible.10
  1378 ±  6%  -8.7%   1258 ±  5%  
sched_debug.cpu.nr_uninterruptible.15
  1232 ± 10% +25.3%   1543 ±  3%  
sched_debug.cpu.nr_uninterruptible.8
 34660 ± 13% -19.1%  28034 ±  4%  sched_debug.cpu.sched_count.13
 37545 ±  2% +18.9%  44629 ±  7%  sched_debug.cpu.sched_count.14
 34003 ±  9% -13.4%  29456 ±  5%  sched_debug.cpu.sched_count.15
 62715 ±  6%  +9.5%  68642 ±  7%  sched_debug.cpu.sched_count.2
 14091 ± 19% -20.4%  11212 ±  5%  sched_debug.cpu.sched_goidle.13
 14175 ±  3% +15.4%  16354 ±  6%  sched_debug.cpu.sched_goidle.14
 13465 ±  9% -12.5%  11782 ±  6%  sched_debug.cpu.sched_goidle.15
 24646 ±  3%  +9.4%  26968 ±  4%  sched_debug.cpu.sched_goidle.4
 15258 ±  6% -22.8%  11773 ±  4%  sched_debug.cpu.ttwu_count.11
 15765 ±  5% +48.1%  23355 ± 15%  sched_debug.cpu.ttwu_co

[PATCH net v3] r8169:fix "rtl_counters_cond == 1 (loop: 1000, delay: 10)" log spam.

2016-02-23 Thread Chunhao Lin
There will be a log spam when there is no cable plugged.
Please refer to following links.
https://bugzilla.kernel.org/show_bug.cgi?id=104351
https://bugzilla.kernel.org/show_bug.cgi?id=107421

This issue is caused by runtime power management. When there is no cable 
plugged, the driver will be suspend (runtime suspend) by OS and NIC will be put 
into the D3 state. During this time, if OS call rtl8169_get_stats64() to dump 
tally counter, because NIC is in D3 state, the register value read by driver 
will return all 0xff. This will let driver think tally counter flag is not 
toggled and then sends the warning  message "rtl_counters_cond == 1 (loop: 1000,
delay: 10)" to kernel log.

For fixing this issue,
1.add checking driver's pm runtime status in rtl8169_get_stats64().
2.dump tally counter before going runtime suspend for counter accuracy in
  runtime suspend.

Signed-off-by: Chunhao Lin 
---
 drivers/net/ethernet/realtek/r8169.c | 15 +--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/realtek/r8169.c 
b/drivers/net/ethernet/realtek/r8169.c
index 537974c..404be51 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -7730,10 +7730,13 @@ rtl8169_get_stats64(struct net_device *dev, struct 
rtnl_link_stats64 *stats)
 {
struct rtl8169_private *tp = netdev_priv(dev);
void __iomem *ioaddr = tp->mmio_addr;
+   struct pci_dev *pdev = tp->pci_dev;
struct rtl8169_counters *counters = tp->counters;
unsigned int start;
 
-   if (netif_running(dev))
+   pm_runtime_get_noresume(&pdev->dev);
+
+   if (netif_running(dev) && pm_runtime_active(&pdev->dev))
rtl8169_rx_missed(dev, ioaddr);
 
do {
@@ -7761,7 +7764,8 @@ rtl8169_get_stats64(struct net_device *dev, struct 
rtnl_link_stats64 *stats)
 * Fetch additonal counter values missing in stats collected by driver
 * from tally counters.
 */
-   rtl8169_update_counters(dev);
+   if (pm_runtime_active(&pdev->dev))
+   rtl8169_update_counters(dev);
 
/*
 * Subtract values fetched during initalization.
@@ -7774,6 +7778,8 @@ rtl8169_get_stats64(struct net_device *dev, struct 
rtnl_link_stats64 *stats)
stats->tx_aborted_errors = le16_to_cpu(counters->tx_aborted) -
le16_to_cpu(tp->tc_offset.tx_aborted);
 
+   pm_runtime_put_noidle(&pdev->dev);
+
return stats;
 }
 
@@ -7853,6 +7859,11 @@ static int rtl8169_runtime_suspend(struct device *device)
 
rtl8169_net_suspend(dev);
 
+   /* Update counters before going runtime suspend */
+   if (netif_running(dev))
+   rtl8169_rx_missed(dev, tp->mmio_addr);
+   rtl8169_update_counters(dev);
+
return 0;
 }
 
-- 
1.9.1



Re: [PATCH v11 2/2] drm/bridge: Add I2C based driver for ps8640 bridge

2016-02-23 Thread kbuild test robot
Hi Jitao,

[auto build test ERROR on drm/drm-next]
[also build test ERROR on v4.5-rc5 next-20160223]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improving the system]

url:
https://github.com/0day-ci/linux/commits/Jitao-Shi/Documentation-bridge-Add-documentation-for-ps8640-DT-properties/20160223-153819
base:   git://people.freedesktop.org/~airlied/linux.git drm-next
config: i386-allmodconfig (attached as .config)
reproduce:
# save the attached .config to linux build tree
make ARCH=i386 

All errors (new ones prefixed by >>):

   drivers/gpu/drm/bridge/parade-ps8640.c: In function 'ps8640_bridge_attach':
>> drivers/gpu/drm/bridge/parade-ps8640.c:435:10: error: implicit declaration 
>> of function 'of_find_mipi_dsi_host_by_node' 
>> [-Werror=implicit-function-declaration]
  host = of_find_mipi_dsi_host_by_node(dsi_node);
 ^
   drivers/gpu/drm/bridge/parade-ps8640.c:435:8: warning: assignment makes 
pointer from integer without a cast [-Wint-conversion]
  host = of_find_mipi_dsi_host_by_node(dsi_node);
   ^
   cc1: some warnings being treated as errors

vim +/of_find_mipi_dsi_host_by_node +435 drivers/gpu/drm/bridge/parade-ps8640.c

   429  if (in_ep) {
   430  dsi_node = 
of_graph_get_remote_port_parent(in_ep);
   431  of_node_put(in_ep);
   432  }
   433  }
   434  if (dsi_node) {
 > 435  host = of_find_mipi_dsi_host_by_node(dsi_node);
   436  of_node_put(dsi_node);
   437  if (!host)
   438  return -ENODEV;

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: Binary data


[PATCH] tty: audit: remove unused variable

2016-02-23 Thread Sudip Mukherjee
While building with W=1 we were getting build warning:
drivers/tty/tty_audit.c:149:16: warning: variable 'sessionid' set but not used

The local variable sessionid was only assigned the value of
current->sessionid but was never reused.

Signed-off-by: Sudip Mukherjee 
---
 drivers/tty/tty_audit.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/tty/tty_audit.c b/drivers/tty/tty_audit.c
index 66d53fc..81fe3fb 100644
--- a/drivers/tty/tty_audit.c
+++ b/drivers/tty/tty_audit.c
@@ -146,10 +146,8 @@ void tty_audit_tiocsti(struct tty_struct *tty, char ch)
 
if (audit_enabled) {
kuid_t auid;
-   unsigned int sessionid;
 
auid = audit_get_loginuid(current);
-   sessionid = audit_get_sessionid(current);
tty_audit_log("ioctl=TIOCSTI", dev, &ch, 1);
}
 }
-- 
1.9.1



Re: [PATCH] ARM: dts: add support for gpio buttons for exynos5422-odroidxu3

2016-02-23 Thread Krzysztof Kozlowski
On 23.02.2016 17:21, Krzysztof Kozlowski wrote:
> On 23.02.2016 17:01, Anand Moon wrote:
>> Add support for gpio-based button on Odroid-XU3 boards
>> for reboot/poweroff feature.
>>
>> Signed-off-by: Anand Moon 
>> ---
>> changes rebase based on linux next-20160222.
>>
>> Tested on Odroid-XU4
>>
>> dmesg output.
>> [3.286068] of_get_named_gpiod_flags: parsed 'gpios' property of node 
>> '/gpio_keys/power_key[0]' - status (0)
>> [3.286206] gpio-11 (power key): gpiod_set_debounce: missing set() or 
>> set_debounce() operations
>> [3.286600] input: gpio_keys as /devices/platform/gpio_keys/input/input0
>> ---
>>  arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi | 22 
>> ++
>>  1 file changed, 22 insertions(+)
>>
>> diff --git a/arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi 
>> b/arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi
>> index 1bd507b..db9770b 100644
>> --- a/arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi
>> +++ b/arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi
>> @@ -11,6 +11,7 @@
>>  */
>>  
>>  #include 
>> +#include 
>>  #include 
>>  #include 
>>  #include 
>> @@ -54,6 +55,22 @@
>>  #cooling-cells = <2>;
>>  cooling-levels = <0 130 170 230>;
>>  };
>> +
>> +gpio_keys {
>> +compatible = "gpio-keys";
>> +pinctrl-names = "default";
>> +pinctrl-0 = <&gpio_power_key>;
>> +
>> +power_key {
>> +interrupt-parent = <&gpx0>;
>> +interrupts = <3 IRQ_TYPE_NONE>;
> 
> Hmmm why you specify the interrupts?
> 
>> +gpios = <&gpx0 3 GPIO_ACTIVE_LOW>;

Please, explain it to me. The SW2 key is connected to PWRON of PMIC.
However you are adding a GPIO key for external interrupt source 3
(XE.INT3)... which comes from PMIC's ONOB.

It's interesting how does it work? The PMIC will generate ONOB
interrupt on PWRON low->high change (when PWRHOLD is high)?

Best regards,
Krzysztof



[PATCH 1/2] usb: dwc2: Move register save and restore functions

2016-02-23 Thread John Youn
Move the register save and restore functions into the host and gadget
specific files.

Signed-off-by: John Youn 
---
 drivers/usb/dwc2/core.c   | 183 --
 drivers/usb/dwc2/core.h   |  13 
 drivers/usb/dwc2/gadget.c | 102 ++
 drivers/usb/dwc2/hcd.c|  64 
 4 files changed, 179 insertions(+), 183 deletions(-)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 3c9c0b2..dc60339 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -56,189 +56,6 @@
 #include "core.h"
 #include "hcd.h"
 
-#if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
-/**
- * dwc2_backup_host_registers() - Backup controller host registers.
- * When suspending usb bus, registers needs to be backuped
- * if controller power is disabled once suspended.
- *
- * @hsotg: Programming view of the DWC_otg controller
- */
-static int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg)
-{
-   struct dwc2_hregs_backup *hr;
-   int i;
-
-   dev_dbg(hsotg->dev, "%s\n", __func__);
-
-   /* Backup Host regs */
-   hr = &hsotg->hr_backup;
-   hr->hcfg = dwc2_readl(hsotg->regs + HCFG);
-   hr->haintmsk = dwc2_readl(hsotg->regs + HAINTMSK);
-   for (i = 0; i < hsotg->core_params->host_channels; ++i)
-   hr->hcintmsk[i] = dwc2_readl(hsotg->regs + HCINTMSK(i));
-
-   hr->hprt0 = dwc2_read_hprt0(hsotg);
-   hr->hfir = dwc2_readl(hsotg->regs + HFIR);
-   hr->valid = true;
-
-   return 0;
-}
-
-/**
- * dwc2_restore_host_registers() - Restore controller host registers.
- * When resuming usb bus, device registers needs to be restored
- * if controller power were disabled.
- *
- * @hsotg: Programming view of the DWC_otg controller
- */
-static int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg)
-{
-   struct dwc2_hregs_backup *hr;
-   int i;
-
-   dev_dbg(hsotg->dev, "%s\n", __func__);
-
-   /* Restore host regs */
-   hr = &hsotg->hr_backup;
-   if (!hr->valid) {
-   dev_err(hsotg->dev, "%s: no host registers to restore\n",
-   __func__);
-   return -EINVAL;
-   }
-   hr->valid = false;
-
-   dwc2_writel(hr->hcfg, hsotg->regs + HCFG);
-   dwc2_writel(hr->haintmsk, hsotg->regs + HAINTMSK);
-
-   for (i = 0; i < hsotg->core_params->host_channels; ++i)
-   dwc2_writel(hr->hcintmsk[i], hsotg->regs + HCINTMSK(i));
-
-   dwc2_writel(hr->hprt0, hsotg->regs + HPRT0);
-   dwc2_writel(hr->hfir, hsotg->regs + HFIR);
-   hsotg->frame_number = 0;
-
-   return 0;
-}
-#else
-static inline int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg)
-{ return 0; }
-
-static inline int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg)
-{ return 0; }
-#endif
-
-#if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
-   IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
-/**
- * dwc2_backup_device_registers() - Backup controller device registers.
- * When suspending usb bus, registers needs to be backuped
- * if controller power is disabled once suspended.
- *
- * @hsotg: Programming view of the DWC_otg controller
- */
-static int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg)
-{
-   struct dwc2_dregs_backup *dr;
-   int i;
-
-   dev_dbg(hsotg->dev, "%s\n", __func__);
-
-   /* Backup dev regs */
-   dr = &hsotg->dr_backup;
-
-   dr->dcfg = dwc2_readl(hsotg->regs + DCFG);
-   dr->dctl = dwc2_readl(hsotg->regs + DCTL);
-   dr->daintmsk = dwc2_readl(hsotg->regs + DAINTMSK);
-   dr->diepmsk = dwc2_readl(hsotg->regs + DIEPMSK);
-   dr->doepmsk = dwc2_readl(hsotg->regs + DOEPMSK);
-
-   for (i = 0; i < hsotg->num_of_eps; i++) {
-   /* Backup IN EPs */
-   dr->diepctl[i] = dwc2_readl(hsotg->regs + DIEPCTL(i));
-
-   /* Ensure DATA PID is correctly configured */
-   if (dr->diepctl[i] & DXEPCTL_DPID)
-   dr->diepctl[i] |= DXEPCTL_SETD1PID;
-   else
-   dr->diepctl[i] |= DXEPCTL_SETD0PID;
-
-   dr->dieptsiz[i] = dwc2_readl(hsotg->regs + DIEPTSIZ(i));
-   dr->diepdma[i] = dwc2_readl(hsotg->regs + DIEPDMA(i));
-
-   /* Backup OUT EPs */
-   dr->doepctl[i] = dwc2_readl(hsotg->regs + DOEPCTL(i));
-
-   /* Ensure DATA PID is correctly configured */
-   if (dr->doepctl[i] & DXEPCTL_DPID)
-   dr->doepctl[i] |= DXEPCTL_SETD1PID;
-   else
-   dr->doepctl[i] |= DXEPCTL_SETD0PID;
-
-   dr->doeptsiz[i] = dwc2_readl(hsotg->regs + DOEPTSIZ(i));
-   dr->doepdma[i] = dwc2_readl(hsotg->regs + DOEPDMA(i));
-   }
-   dr->valid = true;
-   return 0;
-}
-
-/**
- * dwc2_restore_device_registers() - Restore controller device registers.
- * When resuming usb bus, device registers needs to b

[PATCH 0/2] usb: dwc2: Remove host and gadget only code from core

2016-02-23 Thread John Youn
This series moves the host/gadget-specific code from core.c to hcd.c
and gadget.c so that they will be compiled only when their respective
configurations are selected, or in DRD.

This is mostly just a straight move of the code. I have also added
some comments to group related functions together.

Compiled and tested in all three modes.

This should also solve the issue reported here:
http://marc.info/?l=linux-usb&m=145591813410106&w=2

Although I wasn't able to test it... couldn't figure out how to
disable CONFIG_USB and enable DWC2 in gadget mode.

Felipe,

This should be applied after Doug's series on your testing/next
branch.

Regards,
John

John Youn (2):
  usb: dwc2: Move register save and restore functions
  usb: dwc2: Move host-specific core functions into hcd.c

 drivers/usb/dwc2/core.c   | 1959 -
 drivers/usb/dwc2/core.h   |   35 +-
 drivers/usb/dwc2/gadget.c |  102 +++
 drivers/usb/dwc2/hcd.c| 1947 ++--
 drivers/usb/dwc2/hcd.h|   10 +
 5 files changed, 2023 insertions(+), 2030 deletions(-)

-- 
2.6.3



[PATCH] asm-generic/cmpxchg: use BUILD_BUG() when detect unfit, {cmp}xchg size

2016-02-23 Thread Pan Xinhui
From: pan xinhui 

__xchg_called_with_bad_pointer/wrong_size_cmpxchg can't tell us what
codes use {cmp}xchg in incorrect way.  And no error will be reported
until the link stage. To fix such kinds of issues in a easy way, We
use BUILD_BUG().

Signed-off-by: pan xinhui 
---
 include/asm-generic/cmpxchg-local.h | 8 +++-
 include/asm-generic/cmpxchg.h   | 9 ++---
 2 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/include/asm-generic/cmpxchg-local.h 
b/include/asm-generic/cmpxchg-local.h
index 70bef78..6d78291 100644
--- a/include/asm-generic/cmpxchg-local.h
+++ b/include/asm-generic/cmpxchg-local.h
@@ -3,9 +3,7 @@
 
 #include 
 #include 
-
-extern unsigned long wrong_size_cmpxchg(volatile void *ptr)
-   __noreturn;
+#include 
 
 /*
  * Generic version of __cmpxchg_local (disables interrupts). Takes an unsigned
@@ -20,7 +18,7 @@ static inline unsigned long __cmpxchg_local_generic(volatile 
void *ptr,
 * Sanity checking, compile-time.
 */
if (size == 8 && sizeof(unsigned long) != 8)
-   wrong_size_cmpxchg(ptr);
+   BUILD_BUG();
 
raw_local_irq_save(flags);
switch (size) {
@@ -41,7 +39,7 @@ static inline unsigned long __cmpxchg_local_generic(volatile 
void *ptr,
*(u64 *)ptr = (u64)new;
break;
default:
-   wrong_size_cmpxchg(ptr);
+   BUILD_BUG();
}
raw_local_irq_restore(flags);
return prev;
diff --git a/include/asm-generic/cmpxchg.h b/include/asm-generic/cmpxchg.h
index e5f9080..ffaa4ce 100644
--- a/include/asm-generic/cmpxchg.h
+++ b/include/asm-generic/cmpxchg.h
@@ -12,15 +12,10 @@
 
 #include 
 #include 
+#include 
 
 #ifndef xchg
 
-/*
- * This function doesn't exist, so you'll get a linker error if
- * something tries to do an invalidly-sized xchg().
- */
-extern void __xchg_called_with_bad_pointer(void);
-
 static inline
 unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
 {
@@ -74,7 +69,7 @@ unsigned long __xchg(unsigned long x, volatile void *ptr, int 
size)
 #endif /* CONFIG_64BIT */
 
default:
-   __xchg_called_with_bad_pointer();
+   BUILD_BUG();
return x;
}
 }
-- 
2.5.0



Re: [PATCH] Input: pwm-beeper - defer pwm config if pwm can sleep

2016-02-23 Thread Manfred Schlaegl
On 2016-02-22 20:46, Dmitry Torokhov wrote:
> On Wed, Feb 17, 2016 at 02:19:26PM +0100, Manfred Schlaegl wrote:
>> If the pwm can sleep defer actions to it using a worker.
>> A similar approach was used in leds-pwm (c971ff185)
>>
>> Trigger:
>> On a Freescale i.MX53 based board we ran into "BUG: scheduling while
>> atomic" because input_inject_event locks interrupts, but
>> imx_pwm_config_v2 sleeps.
>>
>> Tested on Freescale i.MX53 SoC with 4.5-rc1 and 4.1.
>>
>> Unmodified applicable to
>>  * 4.5-rc4
>>  * 4.4.1 (stable)
>>  * 4.3.5 (stable)
>>  * 4.1.18 (longterm)
>>
>> Modified applicable to
>>  * 3.18.27 (longterm)
>>
>> Signed-off-by: Manfred Schlaegl 
>> ---
>>  drivers/input/misc/pwm-beeper.c | 62 
>> +
>>  1 file changed, 44 insertions(+), 18 deletions(-)
>>
>> diff --git a/drivers/input/misc/pwm-beeper.c 
>> b/drivers/input/misc/pwm-beeper.c
>> index f2261ab..c160b5e 100644
>> --- a/drivers/input/misc/pwm-beeper.c
>> +++ b/drivers/input/misc/pwm-beeper.c
>> @@ -20,21 +20,42 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  
>>  struct pwm_beeper {
>>  struct input_dev *input;
>>  struct pwm_device *pwm;
>> +struct work_struct work;
>>  unsigned long period;
>> +bool can_sleep;
> 
> I wonder if it is not better to always schedule work, regardless of
> whether PWM may sleep or not.
> 
> Thanks.
> 

In my opinion there is no real strong argument to do it this or that way.
I decided to do it this way because of following weaker arguments:
 1. If pwm can not sleep the behavior stays exactly the same as before
 2. The introduced conditions do not really add much complexity to the code
 3. It was successfully done the same way in leds-pwm

Best regards,
Manfred




[PATCH] arch/powerpc: use BUILD_BUG() when detect unfit {cmp}xchg, size

2016-02-23 Thread Pan Xinhui
From: pan xinhui 

__xchg_called_with_bad_pointer() can't tell us what codes use {cmp}xchg
in incorrect way.  And no error will be reported until the link stage.
To fix such kinds of issues in a easy way, we use BUILD_BUG() here.

Signed-off-by: pan xinhui 
---
 arch/powerpc/include/asm/cmpxchg.h | 19 +--
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/arch/powerpc/include/asm/cmpxchg.h 
b/arch/powerpc/include/asm/cmpxchg.h
index d1a8d93..20c0a30 100644
--- a/arch/powerpc/include/asm/cmpxchg.h
+++ b/arch/powerpc/include/asm/cmpxchg.h
@@ -5,6 +5,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /*
  * Atomic exchange
@@ -92,12 +93,6 @@ __xchg_u64_local(volatile void *p, unsigned long val)
 }
 #endif
 
-/*
- * This function doesn't exist, so you'll get a linker error
- * if something tries to do an invalid xchg().
- */
-extern void __xchg_called_with_bad_pointer(void);
-
 static __always_inline unsigned long
 __xchg(volatile void *ptr, unsigned long x, unsigned int size)
 {
@@ -109,7 +104,7 @@ __xchg(volatile void *ptr, unsigned long x, unsigned int 
size)
return __xchg_u64(ptr, x);
 #endif
}
-   __xchg_called_with_bad_pointer();
+   BUILD_BUG();
return x;
 }
 
@@ -124,7 +119,7 @@ __xchg_local(volatile void *ptr, unsigned long x, unsigned 
int size)
return __xchg_u64_local(ptr, x);
 #endif
}
-   __xchg_called_with_bad_pointer();
+   BUILD_BUG();
return x;
 }
 #define xchg(ptr,x) \
@@ -235,10 +230,6 @@ __cmpxchg_u64_local(volatile unsigned long *p, unsigned 
long old,
 }
 #endif
 
-/* This function doesn't exist, so you'll get a linker error
-   if something tries to do an invalid cmpxchg().  */
-extern void __cmpxchg_called_with_bad_pointer(void);
-
 static __always_inline unsigned long
 __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new,
  unsigned int size)
@@ -251,7 +242,7 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned 
long new,
return __cmpxchg_u64(ptr, old, new);
 #endif
}
-   __cmpxchg_called_with_bad_pointer();
+   BUILD_BUG();
return old;
 }
 
@@ -267,7 +258,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, 
unsigned long new,
return __cmpxchg_u64_local(ptr, old, new);
 #endif
}
-   __cmpxchg_called_with_bad_pointer();
+   BUILD_BUG();
return old;
 }
 
-- 
2.5.0



Re: [PATCH v5 0/8] Add MT8173 Video Encoder Driver and VPU Driver

2016-02-23 Thread Hans Verkuil
On 02/23/16 09:11, Tiffany Lin wrote:
> ==
>  Introduction
> ==
> 
> The purpose of this series is to add the driver for video codec hw embedded 
> in the Mediatek's MT8173 SoCs.
> Mediatek Video Codec is able to handle video encoding of in a range of 
> formats.
> 
> This patch series also include VPU driver. Mediatek Video Codec driver rely 
> on VPU driver to load,
> communicate with VPU.
> 
> Internally the driver uses videobuf2 framework and MTK IOMMU and MTK SMI.
> MTK IOMMU[1] and MTK SMI[2] have not yet been merged, but we wanted to start 
> discussion about the driver
> earlier so it could be merged sooner.
> 
> [1]https://patchwork.kernel.org/patch/8335461/
> [2]https://patchwork.kernel.org/patch/7596181/



> v4l2-compliance test output:
> localhost ~ # /usr/bin/v4l2-compliance -d /dev/video1
> Driver Info:
> Driver name   : mtk-vcodec-enc
> Card type : platform:mt8173
> Bus info  : platform:mt8173
> Driver version: 4.4.0
> Capabilities  : 0x84204000
> Video Memory-to-Memory Multiplanar
> Streaming
> Extended Pix Format
> Device Capabilities
> Device Caps   : 0x04204000
> Video Memory-to-Memory Multiplanar
> Streaming
> Extended Pix Format
> 
> Compliance test for device /dev/video1 (not using libv4l2):
> 
> Required ioctls:
> test VIDIOC_QUERYCAP: OK
> 
> Allow for multiple opens:
> test second video open: OK
> test VIDIOC_QUERYCAP: OK
> test VIDIOC_G/S_PRIORITY: OK
> 
> Debug ioctls:
> test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported)
> test VIDIOC_LOG_STATUS: OK (Not Supported)
> 
> Input ioctls:
> test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
> test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
> test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
> test VIDIOC_ENUMAUDIO: OK (Not Supported)
> test VIDIOC_G/S/ENUMINPUT: OK (Not Supported)
> test VIDIOC_G/S_AUDIO: OK (Not Supported)
> Inputs: 0 Audio Inputs: 0 Tuners: 0
> 
> Output ioctls:
> test VIDIOC_G/S_MODULATOR: OK (Not Supported)
> test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
> test VIDIOC_ENUMAUDOUT: OK (Not Supported)
> test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
> test VIDIOC_G/S_AUDOUT: OK (Not Supported)
> Outputs: 0 Audio Outputs: 0 Modulators: 0
> 
> Input/Output configuration ioctls:
> test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
> test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
> test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
> test VIDIOC_G/S_EDID: OK (Not Supported)
> 
> Control ioctls:
> test VIDIOC_QUERYCTRL/MENU: OK
> test VIDIOC_G/S_CTRL: OK
> test VIDIOC_G/S/TRY_EXT_CTRLS: OK
> test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK
> test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
> Standard Controls: 12 Private Controls: 0
> 
> Format ioctls:
> test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
> test VIDIOC_G/S_PARM: OK
> test VIDIOC_G_FBUF: OK (Not Supported)
> test VIDIOC_G_FMT: OK
> test VIDIOC_TRY_FMT: OK
> test VIDIOC_S_FMT: OK
> test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
> 
> Codec ioctls:
> test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported)
> test VIDIOC_G_ENC_INDEX: OK (Not Supported)
> test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)
> 
> Buffer ioctls:
> test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
> test VIDIOC_EXPBUF: OK
> 
> Total: 38, Succeeded: 38, Failed: 0, Warnings: 0

Nice!

Can you try 'v4l2-compliance -s'? Note that this may not work since I know
that v4l2-compliance doesn't work all that well with codecs, but I am
curious what the output is when you try streaming.

Don't bother trying to chase down reported failures, those are likely from
v4l2-compliance itself. It is something I would like to improve, but -ENOTIME.

Regards,

Hans


Re: [PATCH] ARM: dts: add support for gpio buttons for exynos5422-odroidxu3

2016-02-23 Thread Krzysztof Kozlowski
On 23.02.2016 17:33, Krzysztof Kozlowski wrote:
> On 23.02.2016 17:21, Krzysztof Kozlowski wrote:
>> On 23.02.2016 17:01, Anand Moon wrote:
>>> Add support for gpio-based button on Odroid-XU3 boards
>>> for reboot/poweroff feature.
>>>
>>> Signed-off-by: Anand Moon 
>>> ---
>>> changes rebase based on linux next-20160222.
>>>
>>> Tested on Odroid-XU4
>>>
>>> dmesg output.
>>> [3.286068] of_get_named_gpiod_flags: parsed 'gpios' property of node 
>>> '/gpio_keys/power_key[0]' - status (0)
>>> [3.286206] gpio-11 (power key): gpiod_set_debounce: missing set() or 
>>> set_debounce() operations
>>> [3.286600] input: gpio_keys as /devices/platform/gpio_keys/input/input0
>>> ---
>>>  arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi | 22 
>>> ++
>>>  1 file changed, 22 insertions(+)
>>>
>>> diff --git a/arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi 
>>> b/arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi
>>> index 1bd507b..db9770b 100644
>>> --- a/arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi
>>> +++ b/arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi
>>> @@ -11,6 +11,7 @@
>>>  */
>>>  
>>>  #include 
>>> +#include 
>>>  #include 
>>>  #include 
>>>  #include 
>>> @@ -54,6 +55,22 @@
>>> #cooling-cells = <2>;
>>> cooling-levels = <0 130 170 230>;
>>> };
>>> +
>>> +   gpio_keys {
>>> +   compatible = "gpio-keys";
>>> +   pinctrl-names = "default";
>>> +   pinctrl-0 = <&gpio_power_key>;
>>> +
>>> +   power_key {
>>> +   interrupt-parent = <&gpx0>;
>>> +   interrupts = <3 IRQ_TYPE_NONE>;
>>
>> Hmmm why you specify the interrupts?
>>
>>> +   gpios = <&gpx0 3 GPIO_ACTIVE_LOW>;
> 
> Please, explain it to me. The SW2 key is connected to PWRON of PMIC.
> However you are adding a GPIO key for external interrupt source 3
> (XE.INT3)... which comes from PMIC's ONOB.
> 
> It's interesting how does it work? The PMIC will generate ONOB
> interrupt on PWRON low->high change (when PWRHOLD is high)?

Hmmm... This is not well documented but apparently that is the case. The
PMIC will generate ONOB interrupt (with 16 ms de-bounce for PWRON) on
each PWRON flip.

This looks kind of hacky or indirect usage. Using a GPIO key not for
GPIO itself but for an interrupt generated by PMIC on a key press...

Best regards,
Krzysztof



Re: [PATCH] irqchip/gicv3-its: Don't allow devices whose ID is outside range

2016-02-23 Thread Marc Zyngier
On 23/02/16 03:57, Shanker Donthineni wrote:
> We are not checking whether the requested device identifier fits into
> table or not. The ITS MAPD command fails if 'Device ID' is outside of
> device table range.
> 
> Add a simple validation check to avoid MAPD failures since we are
> not handling ITS command errors. This change also helps to return an
> error -ENOMEM instead of success to caller.
> 

In which circumstances do you see this failing? We allocate memory for
the whole DevID range (as advertised by the ITS), so anything that comes
up outside of that range cannot be handled anyway, and is a HW
integration issue. You might as well pretend that these devices do not
exist.

Thanks,

M.
-- 
Jazz is not dead. It just smells funny...


Re: [PATCH v3 01/11] x86/boot: enumerate documentation for the x86 hardware_subarch

2016-02-23 Thread Ingo Molnar

* Luis R. Rodriguez  wrote:

> Although hardware_subarch has been in place since the x86 boot
> protocol 2.07 it hasn't been used much. Enumerate current possible
> values to avoid misuses and help with semantics later at boot
> time should this be used further.
> 
> v2: fix typos
> 
> Cc: Andy Shevchenko 
> Signed-off-by: Luis R. Rodriguez 
> ---
>  arch/x86/include/uapi/asm/bootparam.h | 31 ++-
>  1 file changed, 30 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/include/uapi/asm/bootparam.h 
> b/arch/x86/include/uapi/asm/bootparam.h
> index 329254373479..50d5009cf276 100644
> --- a/arch/x86/include/uapi/asm/bootparam.h
> +++ b/arch/x86/include/uapi/asm/bootparam.h
> @@ -157,7 +157,36 @@ struct boot_params {
>   __u8  _pad9[276];   /* 0xeec */
>  } __attribute__((packed));
>  
> -enum {
> +/**
> + * enum x86_hardware_subarch - x86 hardware subarchitecture
> + *
> + * The x86 hardware_subarch and hardware_subarch_data were added as of the 
> x86
> + * boot protocol 2.07 to help distinguish and supports custom x86 boot
> + * sequences. This enum represents accepted values for the x86
> + * hardware_subarch. Custom x86 boot sequences (not X86_SUBARCH_PC) do not 
> have
> + * or simply do not make use of natural stubs like BIOS or EFI, the
> + * hardware_subarch can be used on the Linux entry path to revector to a
> + * subarchitecture stub when needed. This subarchitecture stub can be used to
> + * set up Linux boot parameters or for special care to account for 
> nonstandard
> + * handling of page tables.
> + *
> + * KVM and Xen HVM do not have a subarch as these are expected to follow
> + * standard x86 boot entries. If there is a genuine need for "hypervisor" 
> type
> + * that should be considered separately in the future.
> + *
> + * @X86_SUBARCH_PC: Should be used if the hardware is enumerable using 
> standard
> + *   PC mechanisms (PCI, ACPI) and doesn't need a special boot flow.
> + * @X86_SUBARCH_LGUEST: Used for x86 hypervisor demo, lguest
> + * @X86_SUBARCH_XEN: Used for Xen guest types which follow the PV boot path,
> + *   which start at asm startup_xen() entry point and later jump to the C
> + *   xen_start_kernel() entry point.
> + * @X86_SUBARCH_INTEL_MID: Used for Intel MID (Mobile Internet Device) 
> platform
> + *   systems which do not have the PCI legacy interfaces.
> + * @X86_SUBARCH_CE4100: Used for Intel CE media processor (CE4100) SOC for
> + *   for settop boxes and media devices, the use of a subarch for CE4100
> + *   is more of a hack...
> + */
> +enum x86_hardware_subarch {
>   X86_SUBARCH_PC = 0,
>   X86_SUBARCH_LGUEST,
>   X86_SUBARCH_XEN,

No, this is really backwards.

While I agree that we want to get rid of paravirt_enabled(), we _dont_ want to 
spread the use of (arguably broken) boot flags like this! This is one of the 
cases 
where the cure is worse than the disease.

The 'modern' way to handle platform quirks is to have hardware drivers with 
auto-detection, and drivers know how to detect whether the hardware is present 
or 
not. For legacy cases where no auto-detection is possible, we have per hardware 
capability flags to turn it off.

The 'hardware subarch' flag of the bootloader can be used to install certain 
quirks, in a single early bootup function - but that should be all: ideally no 
quirks are needed. We don't want to spread 'subarch flags' into various 
unrelated 
code.

Let's go over your series and see whether and how that principle can be applied:

 - patch #1, #2: should be dropped

 - patch #3, #4: EBDA support.

   The EBDA BIOS signature is an ancient data structure, starting off at
   physical memory 0x40E - which is the very first physical memory page of the
   system.

   We should add an x86_ebda_bios flag that is set to 1 by default, but which
   paravirt bootup can set to 0. That would avoid the reservation of the BIOS 
   area and will save a bit of RAM.

 - patch #5, #6, #7: looks good, does not use a subarch flag

 - patch #8: f00f workaround. Subarch flag use is wrong. The complication with 
   this workaround is that it uses MM tricks to install an IDT. Could you check 
   whether Xen truly needs this quirk? If yes then there should be a new flag, 
   something like x86_idt_readonly, which is set to 0 but Xen can set it to 1. 
If 
   that flag is set then the F00F workaround does not have to be installed.

   Or something like that: the point is to use a specific flag.

 - Patch #9, #10: RTC support. The problem with RTC platform driver is that 
it's 
   not possible to detect the RTC reliably - so we sometimes have to quirk it 
off.

   Instead of using bitflags, add something like x86_platform.rtc_available, 
which 
   defaults to 1. Don't add negation to the name and don't use bitflags - use a 
   byte flag.

 - Patch #11: this patch wants to disable the PNP BIOS code.

   The complication with the PNP BIOS code is that the PNP BIOS is defined 
   in physi

Re: [PATCH] ARM64: dts: Mediatek: mt8173-evb: fix access MMC fail issue

2016-02-23 Thread Matthias Brugger



On 23/02/16 01:32, Kevin Hilman wrote:

Eddie Huang  writes:


MT8173 E1 chip has one bug that if turn off USB power domain, vcore
power will also be off, thus cause modules using vcore power domain
fail, like MMC. The E1 chip only found on MT8173-evb board and this
board only has E1 chip, so implement this as a board specific
workaround.

Pwrapper use vcore power, so add pwrapper using USB power domain to
keep USB power domain not to zero and disabled.

Signed-off-by: Eddie Huang 


Tested-by: Kevin Hilman 



I send the patch in a pull request yesterday, so I won't be able to add 
your tag.

Thanks for testing and reporting this issue!

Matthias


I verified that this gets my mt8173-evb booting again when I enable MMC
support.

Thanks,

Kevin



Re: [lkp] [kernel/fs] d57d611505: +54.7% turbostat.%Busy

2016-02-23 Thread Stephane Gasparini
The increase of this metric is expected as the I/O wait (I/O busy) were not 
accounted on some write operation before this patch and are accounted now.


—
Steph




> On Feb 23, 2016, at 9:26 AM, kernel test robot  
> wrote:
> 
> FYI, we noticed the below changes on
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> commit d57d611505d911c6f9f81cd9bd6dbd293d66dd9f ("kernel/fs: fix I/O wait not 
> accounted for RW O_DSYNC")
> 
> 
> =
> compiler/cpufreq_governor/disk/filesize/fs/iterations/kconfig/nr_directories/nr_files_per_directory/nr_threads/rootfs/sync_method/tbox_group/test_size/testcase:
>  
> gcc-4.9/performance/1HDD/9B/f2fs/1x/x86_64-rhel/16d/256fpd/32t/debian-x86_64-2015-02-07.cgz/fsyncBeforeClose/lkp-ne04/400M/fsmark
> 
> commit: 
>  09954bad448791ef01202351d437abdd9497a804
>  d57d611505d911c6f9f81cd9bd6dbd293d66dd9f
> 
> 09954bad448791ef d57d611505d911c6f9f81cd9bd 
>  -- 
> %stddev %change %stddev
> \  |\  
> 14760 ±  1%  +6.3%  15695 ±  1%  
> fsmark.time.involuntary_context_switches
> 46.00 ±  0%  -8.2%  42.25 ±  1%  
> fsmark.time.percent_of_cpu_this_job_got
> 26151 ±116% -71.3%   7498 ± 23%  
> latency_stats.sum.call_rwsem_down_read_failed.f2fs_mkdir.[f2fs].vfs_mkdir.SyS_mkdir.entry_SYSCALL_64_fastpath
>  7418 ± 23% -27.7%   5361 ±  3%  
> numa-vmstat.node0.nr_slab_unreclaimable
>  1.47 ±  1%  -9.9%   1.33 ±  0%  time.user_time
>  1447 ±  4% -29.0%   1028 ±  7%  uptime.idle
>  7.75 ± 19%+206.5%  23.75 ±  1%  vmstat.procs.b
> 29675 ± 23% -27.7%  21447 ±  3%  numa-meminfo.node0.SUnreclaim
> 83099 ±  8% -11.5%  73568 ±  1%  numa-meminfo.node0.Slab
> 11.91 ±  1% +54.7%  18.43 ±  1%  turbostat.%Busy
>358.00 ±  1% +60.0% 572.75 ±  1%  turbostat.Avg_MHz
> 21.54 ±  0% -17.4%  17.79 ±  1%  turbostat.CPU%c1
> 24.78 ±  3% +41.1%  34.98 ±  1%  turbostat.CPU%c3
> 41.76 ±  1% -31.0%  28.81 ±  1%  turbostat.CPU%c6
>  8.53 ±  5% -25.6%   6.34 ± 10%  turbostat.Pkg%pc3
>  66312232 ±  0% -68.5%   20910669 ±  4%  cpuidle.C1-NHM.time
>  46386272 ±  2% -20.5%   36884085 ±  5%  cpuidle.C1E-NHM.time
>  2.79e+08 ±  2% +51.5%  4.226e+08 ±  0%  cpuidle.C3-NHM.time
>254315 ±  2% +25.1% 318250 ±  2%  cpuidle.C3-NHM.usage
> 7.585e+08 ±  1% -22.2%  5.901e+08 ±  1%  cpuidle.C6-NHM.time
>415414 ±  1% -38.1% 257115 ±  1%  cpuidle.C6-NHM.usage
> 1.135e+08 ±  1% +77.8%  2.017e+08 ±  2%  cpuidle.POLL.time
>102777 ±  1% +36.0% 139811 ±  1%  cpuidle.POLL.usage
>  2011 ± 25% -27.1%   1467 ±  2%  sched_debug.cfs_rq:/.exec_clock.2
>  1820 ±  3% -12.2%   1597 ±  7%  sched_debug.cfs_rq:/.exec_clock.4
>  4297 ±  6% +78.1%   7653 ± 54%  
> sched_debug.cfs_rq:/.min_vruntime.12
>  4803 ± 18% -16.1%   4028 ± 21%  
> sched_debug.cfs_rq:/.min_vruntime.8
>  3763 ±  4% -17.0%   3124 ±  7%  
> sched_debug.cfs_rq:/.min_vruntime.9
>  3408 ±  4% -14.9%   2900 ±  2%  
> sched_debug.cfs_rq:/.min_vruntime.min
>  4.75 ± 54% -73.7%   1.25 ±173%  
> sched_debug.cfs_rq:/.nr_spread_over.2
>  1.99 ± 16% +25.5%   2.50 ±  9%  
> sched_debug.cfs_rq:/.nr_spread_over.stddev
> -4362 ±-25% -92.7%-318.24 ±-1304%  sched_debug.cfs_rq:/.spread0.12
>200.25 ± 47% -48.8% 102.50 ± 22%  sched_debug.cfs_rq:/.util_avg.7
>187.75 ± 64% -77.2%  42.75 ± 56%  sched_debug.cfs_rq:/.util_avg.8
>  1.41 ± 31% +37.0%   1.93 ± 12%  sched_debug.cpu.clock.stddev
>  1.41 ± 31% +37.0%   1.93 ± 12%  sched_debug.cpu.clock_task.stddev
>  1.63 ± 67% -53.9%   0.75 ± 38%  
> sched_debug.cpu.cpu_load[4].stddev
> 33822 ± 16% -17.2%  28018 ±  4%  sched_debug.cpu.nr_switches.13
> 36824 ±  3% +12.9%  41569 ±  4%  sched_debug.cpu.nr_switches.14
> 33117 ±  7% -11.1%  29438 ±  5%  sched_debug.cpu.nr_switches.15
> 57634 ±  3%  +8.8%  62716 ±  3%  sched_debug.cpu.nr_switches.4
>  1723 ±  7% -11.3%   1527 ±  5%  
> sched_debug.cpu.nr_uninterruptible.10
>  1378 ±  6%  -8.7%   1258 ±  5%  
> sched_debug.cpu.nr_uninterruptible.15
>  1232 ± 10% +25.3%   1543 ±  3%  
> sched_debug.cpu.nr_uninterruptible.8
> 34660 ± 13% -19.1%  28034 ±  4%  sched_debug.cpu.sched_count.13
> 37545 ±  2% +18.9%  44629 ±  7%  sched_debug.cpu.sched_count.14
> 34003 ±  9% -13.4%  29456 ±  5%  sched_debug.cpu.sched_count.15
> 62715 ±  6%  +9.5%  68642 ±  7%  sched_debug.cpu.sched_count.2
> 14091 ± 19% -20.4%  11212 ±  5%  sched_debug.cpu.sched_goidle.13
> 14175 ±  3% +15.4%  16

Re: [PATCH] thermal: mediatek: add missing dependencies

2016-02-23 Thread Sascha Hauer
Hi Arnd,

On Fri, Feb 19, 2016 at 11:36:06PM +0100, Arnd Bergmann wrote:
> The newly added mtk_thermal driver uses the generic reset
> and nvmem infrastructure, but lacks a dependency that enforces
> them from actually being present:
> 
> drivers/thermal/mtk_thermal.c: In function 'mtk_thermal_probe':
> drivers/thermal/mtk_thermal.c:560:8: error: implicit declaration of function 
> 'device_reset' [-Werror=implicit-function-declaration]
> drivers/thermal/built-in.o: In function `mtk_thermal_probe':
> mtk_thermal.c:(.text+0x7fb0): undefined reference to `nvmem_cell_get'
> mtk_thermal.c:(.text+0x7fd8): undefined reference to `nvmem_cell_read'
> mtk_thermal.c:(.text+0x7fe4): undefined reference to `nvmem_cell_put'
> 
> Without CONFIG_THERMAL, the driver cannot build, so this needs
> to be a hard dependency.

s/CONFIG_THERMAL/CONFIG_RESET_CONTROLLER/ ?

> 
> For CONFIG_NVMEM, the header file allows building the driver even
> when the subsystem is disabled, but we get the link error above
> when nvmem is built as a module and the thermal driver is built-in,
> so we can allow compile-testing when NVMEM is completely disabled,
> but otherwise require the dependency.
> 
> Signed-off-by: Arnd Bergmann 
> ---
>  drivers/thermal/Kconfig | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
> index 5e7c97a3f1d8..75d164341f0d 100644
> --- a/drivers/thermal/Kconfig
> +++ b/drivers/thermal/Kconfig
> @@ -368,6 +368,8 @@ config INTEL_PCH_THERMAL
>  config MTK_THERMAL
>   tristate "Temperature sensor driver for mediatek SoCs"
>   depends on ARCH_MEDIATEK || COMPILE_TEST
> + depends on NVMEM || (!NVMEM && COMPILE_TEST)

This doesn't work as expected. When NVMEM is off I can still not select
MTK_THERMAL, even when COMPILE_TEST is enabled.

Even if it would work, do we really want this? It raises eyebrows and
without reading the commit messages it's probably not clear what's going
on here. I don't see that much value in it.

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |


Re: [PATCH] bus: imx-weim: Take the 'status' property value into account

2016-02-23 Thread Sascha Hauer
On Mon, Feb 22, 2016 at 09:01:53AM -0300, Fabio Estevam wrote:
> From: Fabio Estevam 
> 
> Currently we have an incorrect behaviour when multiple devices
> are present under the weim node. For example:
> 
> &weim {
>   ...
>   status = "okay";
>   
>   sram@0,0 {
>   ...
>   status = "okay";
>   };
> 
>   mram@0,0 {
>   ...
>   status = "disabled";
>   };
> };
> 
> In this case only the 'sram' device should be probed and not 'mram'.
> 
> However what happens currently is that the status variable is ignored,
> causing the 'sram' device to be disabled and 'mram' to be enabled.  
> 
> Change the weim_parse_dt() function to use
> for_each_available_child_of_node()so that the devices marked with
> 'status = disabled' are not probed.
> 
> Cc: 
> Suggested-by: Wolfgang Netbal 
> Signed-off-by: Fabio Estevam 
> ---
>  drivers/bus/imx-weim.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Seems to be the right thing to do.

Reviewed-by: Sascha Hauer 

Sascha

> 
> diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
> index e98d15e..1827fc4 100644
> --- a/drivers/bus/imx-weim.c
> +++ b/drivers/bus/imx-weim.c
> @@ -150,7 +150,7 @@ static int __init weim_parse_dt(struct platform_device 
> *pdev,
>   return ret;
>   }
>  
> - for_each_child_of_node(pdev->dev.of_node, child) {
> + for_each_available_child_of_node(pdev->dev.of_node, child) {
>   if (!child->name)
>   continue;
>  
> -- 
> 1.9.1
> 
> 

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |


[tip:x86/debug] x86/asm/xen: Create stack frames in xen-asm.S

2016-02-23 Thread tip-bot for Josh Poimboeuf
Commit-ID:  801367b7a77adeecf0f77f25f6e50e91130bd1fb
Gitweb: http://git.kernel.org/tip/801367b7a77adeecf0f77f25f6e50e91130bd1fb
Author: Josh Poimboeuf 
AuthorDate: Thu, 21 Jan 2016 16:49:11 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:03:55 +0100

x86/asm/xen: Create stack frames in xen-asm.S

xen_irq_enable_direct(), xen_restore_fl_direct(), and check_events() are
callable non-leaf functions which don't honor CONFIG_FRAME_POINTER,
which can result in bad stack traces.

Create stack frames for them when CONFIG_FRAME_POINTER is enabled.

Signed-off-by: Josh Poimboeuf 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Bernd Petrovitsch 
Cc: Boris Ostrovsky 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chris J Arges 
Cc: David Vrabel 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Jiri Slaby 
Cc: Konrad Rzeszutek Wilk 
Cc: Linus Torvalds 
Cc: Michal Marek 
Cc: Namhyung Kim 
Cc: Pedro Alves 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: live-patch...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/a8340ad3fc72ba9ed34da9b3af9cdd6f1a896e17.1453405861.git.jpoim...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/xen/xen-asm.S | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/arch/x86/xen/xen-asm.S b/arch/x86/xen/xen-asm.S
index 3e45aa0..eff224d 100644
--- a/arch/x86/xen/xen-asm.S
+++ b/arch/x86/xen/xen-asm.S
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "xen-asm.h"
 
@@ -23,6 +24,7 @@
  * then enter the hypervisor to get them handled.
  */
 ENTRY(xen_irq_enable_direct)
+   FRAME_BEGIN
/* Unmask events */
movb $0, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_mask
 
@@ -39,6 +41,7 @@ ENTRY(xen_irq_enable_direct)
 2: call check_events
 1:
 ENDPATCH(xen_irq_enable_direct)
+   FRAME_END
ret
ENDPROC(xen_irq_enable_direct)
RELOC(xen_irq_enable_direct, 2b+1)
@@ -82,6 +85,7 @@ ENDPATCH(xen_save_fl_direct)
  * enters the hypervisor to get them delivered if so.
  */
 ENTRY(xen_restore_fl_direct)
+   FRAME_BEGIN
 #ifdef CONFIG_X86_64
testw $X86_EFLAGS_IF, %di
 #else
@@ -100,6 +104,7 @@ ENTRY(xen_restore_fl_direct)
 2: call check_events
 1:
 ENDPATCH(xen_restore_fl_direct)
+   FRAME_END
ret
ENDPROC(xen_restore_fl_direct)
RELOC(xen_restore_fl_direct, 2b+1)
@@ -109,7 +114,8 @@ ENDPATCH(xen_restore_fl_direct)
  * Force an event check by making a hypercall, but preserve regs
  * before making the call.
  */
-check_events:
+ENTRY(check_events)
+   FRAME_BEGIN
 #ifdef CONFIG_X86_32
push %eax
push %ecx
@@ -139,4 +145,6 @@ check_events:
pop %rcx
pop %rax
 #endif
+   FRAME_END
ret
+ENDPROC(check_events)


[tip:x86/debug] x86/paravirt: Add stack frame dependency to PVOP inline asm calls

2016-02-23 Thread tip-bot for Josh Poimboeuf
Commit-ID:  48b86d5c38a817ddf718d3ea5369cd2e885f28f3
Gitweb: http://git.kernel.org/tip/48b86d5c38a817ddf718d3ea5369cd2e885f28f3
Author: Josh Poimboeuf 
AuthorDate: Thu, 21 Jan 2016 16:49:12 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:03:55 +0100

x86/paravirt: Add stack frame dependency to PVOP inline asm calls

If a PVOP call macro is inlined at the beginning of a function, gcc can
insert the call instruction before setting up a stack frame, which
breaks frame pointer convention if CONFIG_FRAME_POINTER is enabled and
can result in a bad stack trace.

Force a stack frame to be created if CONFIG_FRAME_POINTER is enabled by
listing the stack pointer as an output operand for the PVOP inline asm
statements.

Signed-off-by: Josh Poimboeuf 
Reviewed-by: Borislav Petkov 
Cc: Alok Kataria 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Bernd Petrovitsch 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chris J Arges 
Cc: Chris Wright 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Jeremy Fitzhardinge 
Cc: Jiri Slaby 
Cc: Linus Torvalds 
Cc: Michal Marek 
Cc: Namhyung Kim 
Cc: Pedro Alves 
Cc: Peter Zijlstra 
Cc: Rusty Russell 
Cc: Thomas Gleixner 
Cc: live-patch...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/6a13e48c5a8cf2de1aa112ae2d4c0ac194096282.1453405861.git.jpoim...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/include/asm/paravirt_types.h | 18 ++
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/arch/x86/include/asm/paravirt_types.h 
b/arch/x86/include/asm/paravirt_types.h
index 77db561..e8c2326 100644
--- a/arch/x86/include/asm/paravirt_types.h
+++ b/arch/x86/include/asm/paravirt_types.h
@@ -466,8 +466,9 @@ int paravirt_disable_iospace(void);
  * makes sure the incoming and outgoing types are always correct.
  */
 #ifdef CONFIG_X86_32
-#define PVOP_VCALL_ARGS\
-   unsigned long __eax = __eax, __edx = __edx, __ecx = __ecx
+#define PVOP_VCALL_ARGS
\
+   unsigned long __eax = __eax, __edx = __edx, __ecx = __ecx;  \
+   register void *__sp asm("esp")
 #define PVOP_CALL_ARGS PVOP_VCALL_ARGS
 
 #define PVOP_CALL_ARG1(x)  "a" ((unsigned long)(x))
@@ -485,9 +486,10 @@ int paravirt_disable_iospace(void);
 #define VEXTRA_CLOBBERS
 #else  /* CONFIG_X86_64 */
 /* [re]ax isn't an arg, but the return val */
-#define PVOP_VCALL_ARGS\
-   unsigned long __edi = __edi, __esi = __esi, \
-   __edx = __edx, __ecx = __ecx, __eax = __eax
+#define PVOP_VCALL_ARGS\
+   unsigned long __edi = __edi, __esi = __esi, \
+   __edx = __edx, __ecx = __ecx, __eax = __eax;\
+   register void *__sp asm("rsp")
 #define PVOP_CALL_ARGS PVOP_VCALL_ARGS
 
 #define PVOP_CALL_ARG1(x)  "D" ((unsigned long)(x))
@@ -526,7 +528,7 @@ int paravirt_disable_iospace(void);
asm volatile(pre\
 paravirt_alt(PARAVIRT_CALL)\
 post   \
-: call_clbr\
+: call_clbr, "+r" (__sp)   \
 : paravirt_type(op),   \
   paravirt_clobber(clbr),  \
   ##__VA_ARGS__\
@@ -536,7 +538,7 @@ int paravirt_disable_iospace(void);
asm volatile(pre\
 paravirt_alt(PARAVIRT_CALL)\
 post   \
-: call_clbr\
+: call_clbr, "+r" (__sp)   \
 : paravirt_type(op),   \
   paravirt_clobber(clbr),  \
   ##__VA_ARGS__\
@@ -563,7 +565,7 @@ int paravirt_disable_iospace(void);
asm volatile(pre\
 paravirt_alt(PARAVIRT_CALL)\
 post   \
-: call_clbr\
+: call_clbr, "+r" (__sp)   \
 : paravirt_type(op),   \
   paravirt_clobber(clbr),  \
   ##__VA_ARGS__\


[tip:x86/debug] x86/amd: Set ELF function type for vide()

2016-02-23 Thread tip-bot for Josh Poimboeuf
Commit-ID:  48740ab9f0e953137ab62891b87f986e36e1bc69
Gitweb: http://git.kernel.org/tip/48740ab9f0e953137ab62891b87f986e36e1bc69
Author: Josh Poimboeuf 
AuthorDate: Thu, 21 Jan 2016 16:49:14 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:03:55 +0100

x86/amd: Set ELF function type for vide()

vide() is a callable function, but is missing the ELF function type,
which confuses tools like stacktool.

Properly annotate it to be a callable function.  The generated code is
unchanged.

Signed-off-by: Josh Poimboeuf 
Reviewed-by: Borislav Petkov 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Bernd Petrovitsch 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chris J Arges 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Jiri Slaby 
Cc: Linus Torvalds 
Cc: Michal Marek 
Cc: Namhyung Kim 
Cc: Pedro Alves 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: live-patch...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/a324095f5c9390ff39b15b4562ea1bbeda1a8282.1453405861.git.jpoim...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/kernel/cpu/amd.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index a07956a..fe2f089 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -75,7 +75,10 @@ static inline int wrmsrl_amd_safe(unsigned msr, unsigned 
long long val)
  */
 
 extern __visible void vide(void);
-__asm__(".globl vide\n\t.align 4\nvide: ret");
+__asm__(".globl vide\n"
+   ".type vide, @function\n"
+   ".align 4\n"
+   "vide: ret\n");
 
 static void init_amd_k5(struct cpuinfo_x86 *c)
 {


[tip:x86/debug] x86/paravirt: Create a stack frame in PV_CALLEE_SAVE_REGS_THUNK

2016-02-23 Thread tip-bot for Josh Poimboeuf
Commit-ID:  c9cc1d72bb0b657de06b8d4be36d94bea0454ee8
Gitweb: http://git.kernel.org/tip/c9cc1d72bb0b657de06b8d4be36d94bea0454ee8
Author: Josh Poimboeuf 
AuthorDate: Thu, 21 Jan 2016 16:49:13 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:03:55 +0100

x86/paravirt: Create a stack frame in PV_CALLEE_SAVE_REGS_THUNK

A function created with the PV_CALLEE_SAVE_REGS_THUNK macro doesn't set
up a new stack frame before the call instruction, which breaks frame
pointer convention if CONFIG_FRAME_POINTER is enabled and can result in
a bad stack trace.  Also, the thunk functions aren't annotated as ELF
callable functions.

Create a stack frame when CONFIG_FRAME_POINTER is enabled and add the
ELF function type.

Signed-off-by: Josh Poimboeuf 
Reviewed-by: Borislav Petkov 
Cc: Alok Kataria 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Bernd Petrovitsch 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chris J Arges 
Cc: Chris Wright 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Jeremy Fitzhardinge 
Cc: Jiri Slaby 
Cc: Linus Torvalds 
Cc: Michal Marek 
Cc: Namhyung Kim 
Cc: Pedro Alves 
Cc: Peter Zijlstra 
Cc: Rusty Russell 
Cc: Thomas Gleixner 
Cc: live-patch...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/a2cad74e87c4aba7fd0f54a1af312e66a824a575.1453405861.git.jpoim...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/include/asm/paravirt.h | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
index f619250..601f1b8 100644
--- a/arch/x86/include/asm/paravirt.h
+++ b/arch/x86/include/asm/paravirt.h
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static inline int paravirt_enabled(void)
 {
@@ -756,15 +757,19 @@ static __always_inline void __ticket_unlock_kick(struct 
arch_spinlock *lock,
  * call. The return value in rax/eax will not be saved, even for void
  * functions.
  */
+#define PV_THUNK_NAME(func) "__raw_callee_save_" #func
 #define PV_CALLEE_SAVE_REGS_THUNK(func)
\
extern typeof(func) __raw_callee_save_##func;   \
\
asm(".pushsection .text;"   \
-   ".globl __raw_callee_save_" #func " ; " \
-   "__raw_callee_save_" #func ": " \
+   ".globl " PV_THUNK_NAME(func) ";"   \
+   ".type " PV_THUNK_NAME(func) ", @function;" \
+   PV_THUNK_NAME(func) ":" \
+   FRAME_BEGIN \
PV_SAVE_ALL_CALLER_REGS \
"call " #func ";"   \
PV_RESTORE_ALL_CALLER_REGS  \
+   FRAME_END   \
"ret;"  \
".popsection")
 


[tip:x86/debug] x86/asm/crypto: Move jump_table to .rodata section

2016-02-23 Thread tip-bot for Josh Poimboeuf
Commit-ID:  c26ac7081af1f1cd05ccfea858d455100255cfd0
Gitweb: http://git.kernel.org/tip/c26ac7081af1f1cd05ccfea858d455100255cfd0
Author: Josh Poimboeuf 
AuthorDate: Thu, 21 Jan 2016 16:49:16 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:03:56 +0100

x86/asm/crypto: Move jump_table to .rodata section

stacktool reports the following warning:

  stacktool: arch/x86/crypto/crc32c-pcl-intel-asm_64.o: crc_pcl()+0x11dd: can't 
decode instruction

It gets confused when trying to decode jump_table data.  Move jump_table
to the .rodata section which is a more appropriate home for read-only
data.

Signed-off-by: Josh Poimboeuf 
Reviewed-by: Borislav Petkov 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Bernd Petrovitsch 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chris J Arges 
Cc: David S. Miller 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Herbert Xu 
Cc: Jiri Slaby 
Cc: Linus Torvalds 
Cc: Michal Marek 
Cc: Namhyung Kim 
Cc: Pedro Alves 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: live-patch...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1dbf80c097bb9d89c0cbddc01a815ada690e3b32.1453405861.git.jpoim...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/crypto/crc32c-pcl-intel-asm_64.S | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S 
b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
index 4fe27e0..dc05f01 100644
--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
@@ -170,8 +170,8 @@ continue_block:
## branch into array
lea jump_table(%rip), bufp
movzxw  (bufp, %rax, 2), len
-   offset=crc_array-jump_table
-   lea offset(bufp, len, 1), bufp
+   lea crc_array(%rip), bufp
+   lea (bufp, len, 1), bufp
jmp *bufp
 

@@ -310,7 +310,9 @@ do_return:
popq%rdi
popq%rbx
 ret
+ENDPROC(crc_pcl)
 
+.section   .rodata, "a", %progbits
 
 ## jump tableTable is 129 entries x 2 bytes each
 
@@ -324,13 +326,11 @@ JMPTBL_ENTRY %i
i=i+1
 .endr
 
-ENDPROC(crc_pcl)
 

## PCLMULQDQ tables
## Table is 128 entries x 2 words (8 bytes) each

-.section   .rodata, "a", %progbits
 .align 8
 K_table:
.long 0x493c7d27, 0x0001


[tip:x86/debug] x86/asm/crypto: Move .Lbswap_mask data to .rodata section

2016-02-23 Thread tip-bot for Josh Poimboeuf
Commit-ID:  999ba9ec9cc3e9435f42dbe926c68921f1f66ef3
Gitweb: http://git.kernel.org/tip/999ba9ec9cc3e9435f42dbe926c68921f1f66ef3
Author: Josh Poimboeuf 
AuthorDate: Thu, 21 Jan 2016 16:49:15 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:03:56 +0100

x86/asm/crypto: Move .Lbswap_mask data to .rodata section

stacktool reports the following warning:

  stacktool: arch/x86/crypto/aesni-intel_asm.o: _aesni_inc_init(): can't find 
starting instruction

stacktool gets confused when it tries to disassemble the following data
in the .text section:

  .Lbswap_mask:
  .byte 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0

Move it to .rodata which is a more appropriate section for read-only
data.

Signed-off-by: Josh Poimboeuf 
Reviewed-by: Borislav Petkov 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Bernd Petrovitsch 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chris J Arges 
Cc: David S. Miller 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Herbert Xu 
Cc: Jiri Slaby 
Cc: Linus Torvalds 
Cc: Michal Marek 
Cc: Namhyung Kim 
Cc: Pedro Alves 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: live-patch...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/b6a2f3f8bda705143e127c025edb2b53c86e6eb4.1453405861.git.jpoim...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/crypto/aesni-intel_asm.S | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/crypto/aesni-intel_asm.S 
b/arch/x86/crypto/aesni-intel_asm.S
index 6bd2c6c..c44cfed 100644
--- a/arch/x86/crypto/aesni-intel_asm.S
+++ b/arch/x86/crypto/aesni-intel_asm.S
@@ -2538,9 +2538,11 @@ ENTRY(aesni_cbc_dec)
 ENDPROC(aesni_cbc_dec)
 
 #ifdef __x86_64__
+.pushsection .rodata
 .align 16
 .Lbswap_mask:
.byte 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
+.popsection
 
 /*
  * _aesni_inc_init:internal ABI


[tip:x86/debug] x86/asm/crypto: Don't use RBP as a scratch register

2016-02-23 Thread tip-bot for Josh Poimboeuf
Commit-ID:  1bd03cf57a9b2e2294143f76c21f386a94e5e6c8
Gitweb: http://git.kernel.org/tip/1bd03cf57a9b2e2294143f76c21f386a94e5e6c8
Author: Josh Poimboeuf 
AuthorDate: Thu, 21 Jan 2016 16:49:18 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:03:57 +0100

x86/asm/crypto: Don't use RBP as a scratch register

The frame pointer (RBP) is getting clobbered in
sha1_mb_mgr_submit_avx2() before a function call, which can mess up
stack traces.  Use R12 instead.

Signed-off-by: Josh Poimboeuf 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Bernd Petrovitsch 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chris J Arges 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Jiri Slaby 
Cc: Linus Torvalds 
Cc: Michal Marek 
Cc: Namhyung Kim 
Cc: Pedro Alves 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: live-patch...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/15a3eb7ebe68e37755927915f45e4f0bde4d18c5.1453405861.git.jpoim...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/crypto/sha-mb/sha1_mb_mgr_submit_avx2.S | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/crypto/sha-mb/sha1_mb_mgr_submit_avx2.S 
b/arch/x86/crypto/sha-mb/sha1_mb_mgr_submit_avx2.S
index a5a14c6..c3b9447 100644
--- a/arch/x86/crypto/sha-mb/sha1_mb_mgr_submit_avx2.S
+++ b/arch/x86/crypto/sha-mb/sha1_mb_mgr_submit_avx2.S
@@ -86,8 +86,8 @@ job_rax = %rax
 len = %rax
 DWORD_len  = %eax
 
-lane= %rbp
-tmp3= %rbp
+lane= %r12
+tmp3= %r12
 
 tmp = %r9
 DWORD_tmp  = %r9d
@@ -99,7 +99,7 @@ lane_data   = %r10
 # arg 2 : rdx : job
 ENTRY(sha1_mb_mgr_submit_avx2)
push%rbx
-   push%rbp
+   push%r12
 
mov _unused_lanes(state), unused_lanes
mov unused_lanes, lane
@@ -190,7 +190,7 @@ len_is_0:
movlDWORD_tmp, _result_digest+1*16(job_rax)
 
 return:
-   pop %rbp
+   pop %r12
pop %rbx
ret
 


[tip:x86/debug] x86/asm/crypto: Simplify stack usage in sha-mb functions

2016-02-23 Thread tip-bot for Josh Poimboeuf
Commit-ID:  c520f61ae153d8b28553d5dd0ea698e0968939d7
Gitweb: http://git.kernel.org/tip/c520f61ae153d8b28553d5dd0ea698e0968939d7
Author: Josh Poimboeuf 
AuthorDate: Thu, 21 Jan 2016 16:49:17 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:03:56 +0100

x86/asm/crypto: Simplify stack usage in sha-mb functions

sha1_mb_mgr_flush_avx2() and sha1_mb_mgr_submit_avx2() both allocate a
lot of stack space which is never used.  Also, many of the registers
being saved aren't being clobbered so there's no need to save them.

Signed-off-by: Josh Poimboeuf 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Bernd Petrovitsch 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chris J Arges 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Jiri Slaby 
Cc: Linus Torvalds 
Cc: Michal Marek 
Cc: Namhyung Kim 
Cc: Pedro Alves 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: live-patch...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/9402e4d87580d6b2376ed95f67b84bdcce3c830e.1453405861.git.jpoim...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/crypto/sha-mb/sha1_mb_mgr_flush_avx2.S  | 32 ++--
 arch/x86/crypto/sha-mb/sha1_mb_mgr_submit_avx2.S | 29 +++--
 2 files changed, 6 insertions(+), 55 deletions(-)

diff --git a/arch/x86/crypto/sha-mb/sha1_mb_mgr_flush_avx2.S 
b/arch/x86/crypto/sha-mb/sha1_mb_mgr_flush_avx2.S
index 85c4e1c..672eaeb 100644
--- a/arch/x86/crypto/sha-mb/sha1_mb_mgr_flush_avx2.S
+++ b/arch/x86/crypto/sha-mb/sha1_mb_mgr_flush_avx2.S
@@ -86,16 +86,6 @@
 #define extra_blocks%arg2
 #define p   %arg2
 
-
-# STACK_SPACE needs to be an odd multiple of 8
-_XMM_SAVE_SIZE  = 10*16
-_GPR_SAVE_SIZE  = 8*8
-_ALIGN_SIZE = 8
-
-_XMM_SAVE   = 0
-_GPR_SAVE   = _XMM_SAVE + _XMM_SAVE_SIZE
-STACK_SPACE = _GPR_SAVE + _GPR_SAVE_SIZE + _ALIGN_SIZE
-
 .macro LABEL prefix n
 \prefix\n\():
 .endm
@@ -113,16 +103,7 @@ offset = \_offset
 # JOB* sha1_mb_mgr_flush_avx2(MB_MGR *state)
 # arg 1 : rcx : state
 ENTRY(sha1_mb_mgr_flush_avx2)
-   mov %rsp, %r10
-   sub $STACK_SPACE, %rsp
-   and $~31, %rsp
-   mov %rbx, _GPR_SAVE(%rsp)
-   mov %r10, _GPR_SAVE+8*1(%rsp) #save rsp
-   mov %rbp, _GPR_SAVE+8*3(%rsp)
-   mov %r12, _GPR_SAVE+8*4(%rsp)
-   mov %r13, _GPR_SAVE+8*5(%rsp)
-   mov %r14, _GPR_SAVE+8*6(%rsp)
-   mov %r15, _GPR_SAVE+8*7(%rsp)
+   push%rbx
 
# If bit (32+3) is set, then all lanes are empty
mov _unused_lanes(state), unused_lanes
@@ -230,16 +211,7 @@ len_is_0:
mov tmp2_w, offset(job_rax)
 
 return:
-
-   mov _GPR_SAVE(%rsp), %rbx
-   mov _GPR_SAVE+8*1(%rsp), %r10 #saved rsp
-   mov _GPR_SAVE+8*3(%rsp), %rbp
-   mov _GPR_SAVE+8*4(%rsp), %r12
-   mov _GPR_SAVE+8*5(%rsp), %r13
-   mov _GPR_SAVE+8*6(%rsp), %r14
-   mov _GPR_SAVE+8*7(%rsp), %r15
-   mov %r10, %rsp
-
+   pop %rbx
ret
 
 return_null:
diff --git a/arch/x86/crypto/sha-mb/sha1_mb_mgr_submit_avx2.S 
b/arch/x86/crypto/sha-mb/sha1_mb_mgr_submit_avx2.S
index 2ab9560..a5a14c6 100644
--- a/arch/x86/crypto/sha-mb/sha1_mb_mgr_submit_avx2.S
+++ b/arch/x86/crypto/sha-mb/sha1_mb_mgr_submit_avx2.S
@@ -94,25 +94,12 @@ DWORD_tmp   = %r9d
 
 lane_data   = %r10
 
-# STACK_SPACE needs to be an odd multiple of 8
-STACK_SPACE = 8*8 + 16*10 + 8
-
 # JOB* submit_mb_mgr_submit_avx2(MB_MGR *state, job_sha1 *job)
 # arg 1 : rcx : state
 # arg 2 : rdx : job
 ENTRY(sha1_mb_mgr_submit_avx2)
-
-   mov %rsp, %r10
-   sub $STACK_SPACE, %rsp
-   and $~31, %rsp
-
-   mov %rbx, (%rsp)
-   mov %r10, 8*2(%rsp) #save old rsp
-   mov %rbp, 8*3(%rsp)
-   mov %r12, 8*4(%rsp)
-   mov %r13, 8*5(%rsp)
-   mov %r14, 8*6(%rsp)
-   mov %r15, 8*7(%rsp)
+   push%rbx
+   push%rbp
 
mov _unused_lanes(state), unused_lanes
mov unused_lanes, lane
@@ -203,16 +190,8 @@ len_is_0:
movlDWORD_tmp, _result_digest+1*16(job_rax)
 
 return:
-
-   mov (%rsp), %rbx
-   mov 8*2(%rsp), %r10 #save old rsp
-   mov 8*3(%rsp), %rbp
-   mov 8*4(%rsp), %r12
-   mov 8*5(%rsp), %r13
-   mov 8*6(%rsp), %r14
-   mov 8*7(%rsp), %r15
-   mov %r10, %rsp
-
+   pop %rbp
+   pop %rbx
ret
 
 return_null:


[tip:x86/debug] x86/asm/entry: Create stack frames in thunk functions

2016-02-23 Thread tip-bot for Josh Poimboeuf
Commit-ID:  b404b2c4a1f98ad34c33f45a254c31d4fca9d91d
Gitweb: http://git.kernel.org/tip/b404b2c4a1f98ad34c33f45a254c31d4fca9d91d
Author: Josh Poimboeuf 
AuthorDate: Thu, 21 Jan 2016 16:49:20 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:03:57 +0100

x86/asm/entry: Create stack frames in thunk functions

Thunk functions are callable non-leaf functions that don't honor
CONFIG_FRAME_POINTER, which can result in bad stack traces.  Also they
aren't annotated as ELF callable functions which can confuse tooling.

Create stack frames for them when CONFIG_FRAME_POINTER is enabled and
add the ELF function type.

Signed-off-by: Josh Poimboeuf 
Reviewed-by: Borislav Petkov 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Bernd Petrovitsch 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chris J Arges 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Jiri Slaby 
Cc: Linus Torvalds 
Cc: Michal Marek 
Cc: Namhyung Kim 
Cc: Pedro Alves 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: live-patch...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/4373e5bff459b9fd66ce5d45bfcc881a5c202643.1453405861.git.jpoim...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/entry/thunk_64.S | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/x86/entry/thunk_64.S b/arch/x86/entry/thunk_64.S
index efb2b93..98df1fa 100644
--- a/arch/x86/entry/thunk_64.S
+++ b/arch/x86/entry/thunk_64.S
@@ -8,11 +8,14 @@
 #include 
 #include "calling.h"
 #include 
+#include 
 
/* rdi: arg1 ... normal C conventions. rax is saved/restored. */
.macro THUNK name, func, put_ret_addr_in_rdi=0
.globl \name
+   .type \name, @function
 \name:
+   FRAME_BEGIN
 
/* this one pushes 9 elems, the next one would be %rIP */
pushq %rdi
@@ -62,6 +65,7 @@ restore:
popq %rdx
popq %rsi
popq %rdi
+   FRAME_END
ret
_ASM_NOKPROBE(restore)
 #endif


[tip:x86/debug] x86/asm/crypto: Create stack frames in crypto functions

2016-02-23 Thread tip-bot for Josh Poimboeuf
Commit-ID:  c24cf96a589107cb29c1d2cfe9c42d43e3f68654
Gitweb: http://git.kernel.org/tip/c24cf96a589107cb29c1d2cfe9c42d43e3f68654
Author: Josh Poimboeuf 
AuthorDate: Thu, 21 Jan 2016 16:49:19 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:03:57 +0100

x86/asm/crypto: Create stack frames in crypto functions

The crypto code has several callable non-leaf functions which don't
honor CONFIG_FRAME_POINTER, which can result in bad stack traces.

Create stack frames for them when CONFIG_FRAME_POINTER is enabled.

Signed-off-by: Josh Poimboeuf 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Bernd Petrovitsch 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chris J Arges 
Cc: David S. Miller 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Herbert Xu 
Cc: Jiri Slaby 
Cc: Linus Torvalds 
Cc: Michal Marek 
Cc: Namhyung Kim 
Cc: Pedro Alves 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: live-patch...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/6c20192bcf1102ae18ae5a242cabf30ce9b29895.1453405861.git.jpoim...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/crypto/aesni-intel_asm.S| 73 +++-
 arch/x86/crypto/camellia-aesni-avx-asm_64.S  | 15 +
 arch/x86/crypto/camellia-aesni-avx2-asm_64.S | 15 +
 arch/x86/crypto/cast5-avx-x86_64-asm_64.S|  9 +++
 arch/x86/crypto/cast6-avx-x86_64-asm_64.S| 13 +
 arch/x86/crypto/ghash-clmulni-intel_asm.S|  5 ++
 arch/x86/crypto/serpent-avx-x86_64-asm_64.S  | 13 +
 arch/x86/crypto/serpent-avx2-asm_64.S| 13 +
 arch/x86/crypto/sha-mb/sha1_mb_mgr_flush_avx2.S  |  3 +
 arch/x86/crypto/sha-mb/sha1_mb_mgr_submit_avx2.S |  3 +
 arch/x86/crypto/twofish-avx-x86_64-asm_64.S  | 13 +
 11 files changed, 148 insertions(+), 27 deletions(-)

diff --git a/arch/x86/crypto/aesni-intel_asm.S 
b/arch/x86/crypto/aesni-intel_asm.S
index c44cfed..383a6f8 100644
--- a/arch/x86/crypto/aesni-intel_asm.S
+++ b/arch/x86/crypto/aesni-intel_asm.S
@@ -31,6 +31,7 @@
 
 #include 
 #include 
+#include 
 
 /*
  * The following macros are used to move an (un)aligned 16 byte value to/from
@@ -1800,11 +1801,12 @@ ENDPROC(_key_expansion_256b)
  *   unsigned int key_len)
  */
 ENTRY(aesni_set_key)
+   FRAME_BEGIN
 #ifndef __x86_64__
pushl KEYP
-   movl 8(%esp), KEYP  # ctx
-   movl 12(%esp), UKEYP# in_key
-   movl 16(%esp), %edx # key_len
+   movl (FRAME_OFFSET+8)(%esp), KEYP   # ctx
+   movl (FRAME_OFFSET+12)(%esp), UKEYP # in_key
+   movl (FRAME_OFFSET+16)(%esp), %edx  # key_len
 #endif
movups (UKEYP), %xmm0   # user key (first 16 bytes)
movaps %xmm0, (KEYP)
@@ -1905,6 +1907,7 @@ ENTRY(aesni_set_key)
 #ifndef __x86_64__
popl KEYP
 #endif
+   FRAME_END
ret
 ENDPROC(aesni_set_key)
 
@@ -1912,12 +1915,13 @@ ENDPROC(aesni_set_key)
  * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
  */
 ENTRY(aesni_enc)
+   FRAME_BEGIN
 #ifndef __x86_64__
pushl KEYP
pushl KLEN
-   movl 12(%esp), KEYP
-   movl 16(%esp), OUTP
-   movl 20(%esp), INP
+   movl (FRAME_OFFSET+12)(%esp), KEYP  # ctx
+   movl (FRAME_OFFSET+16)(%esp), OUTP  # dst
+   movl (FRAME_OFFSET+20)(%esp), INP   # src
 #endif
movl 480(KEYP), KLEN# key length
movups (INP), STATE # input
@@ -1927,6 +1931,7 @@ ENTRY(aesni_enc)
popl KLEN
popl KEYP
 #endif
+   FRAME_END
ret
 ENDPROC(aesni_enc)
 
@@ -2101,12 +2106,13 @@ ENDPROC(_aesni_enc4)
  * void aesni_dec (struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
  */
 ENTRY(aesni_dec)
+   FRAME_BEGIN
 #ifndef __x86_64__
pushl KEYP
pushl KLEN
-   movl 12(%esp), KEYP
-   movl 16(%esp), OUTP
-   movl 20(%esp), INP
+   movl (FRAME_OFFSET+12)(%esp), KEYP  # ctx
+   movl (FRAME_OFFSET+16)(%esp), OUTP  # dst
+   movl (FRAME_OFFSET+20)(%esp), INP   # src
 #endif
mov 480(KEYP), KLEN # key length
add $240, KEYP
@@ -2117,6 +2123,7 @@ ENTRY(aesni_dec)
popl KLEN
popl KEYP
 #endif
+   FRAME_END
ret
 ENDPROC(aesni_dec)
 
@@ -2292,14 +2299,15 @@ ENDPROC(_aesni_dec4)
  *   size_t len)
  */
 ENTRY(aesni_ecb_enc)
+   FRAME_BEGIN
 #ifndef __x86_64__
pushl LEN
pushl KEYP
pushl KLEN
-   movl 16(%esp), KEYP
-   movl 20(%esp), OUTP
-   movl 24(%esp), INP
-   movl 28(%esp), LEN
+   movl (FRAME_OFFSET+16)(%esp), KEYP  # ctx
+   movl (FRAME_OFFSET+20)(%esp), OUTP  # dst
+   movl (FRAME_OFFSET+24)(%esp), INP   # src
+   movl (FRAME_OFFSET+28)(%esp), LEN   # len
 #endif
test LEN, LEN   # check length
jz .Lecb_enc_ret
@@ -2342,6 +2350,7 @@ ENTRY(aesni_ecb_enc)
popl KEYP
popl

[tip:x86/debug] x86/asm/acpi: Create a stack frame in do_suspend_lowlevel()

2016-02-23 Thread tip-bot for Josh Poimboeuf
Commit-ID:  4b0cf693ed225b60aea8835361a1c8f85f9f9041
Gitweb: http://git.kernel.org/tip/4b0cf693ed225b60aea8835361a1c8f85f9f9041
Author: Josh Poimboeuf 
AuthorDate: Thu, 21 Jan 2016 16:49:21 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:03:57 +0100

x86/asm/acpi: Create a stack frame in do_suspend_lowlevel()

do_suspend_lowlevel() is a callable non-leaf function which doesn't
honor CONFIG_FRAME_POINTER, which can result in bad stack traces.

Create a stack frame for it when CONFIG_FRAME_POINTER is enabled.

Signed-off-by: Josh Poimboeuf 
Reviewed-by: Borislav Petkov 
Acked-by: Pavel Machek 
Acked-by: Rafael J. Wysocki 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Bernd Petrovitsch 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chris J Arges 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Jiri Slaby 
Cc: Len Brown 
Cc: Linus Torvalds 
Cc: Michal Marek 
Cc: Namhyung Kim 
Cc: Pedro Alves 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: live-patch...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/7383d87dd40a460e0d757a0793498b9d06a7ee0d.1453405861.git.jpoim...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/kernel/acpi/wakeup_64.S | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/x86/kernel/acpi/wakeup_64.S b/arch/x86/kernel/acpi/wakeup_64.S
index 8c35df4..169963f 100644
--- a/arch/x86/kernel/acpi/wakeup_64.S
+++ b/arch/x86/kernel/acpi/wakeup_64.S
@@ -5,6 +5,7 @@
 #include 
 #include 
 #include 
+#include 
 
 # Copyright 2003 Pavel Machek , distribute under GPLv2
 
@@ -39,6 +40,7 @@ bogus_64_magic:
jmp bogus_64_magic
 
 ENTRY(do_suspend_lowlevel)
+   FRAME_BEGIN
subq$8, %rsp
xorl%eax, %eax
callsave_processor_state
@@ -109,6 +111,7 @@ ENTRY(do_suspend_lowlevel)
 
xorl%eax, %eax
addq$8, %rsp
+   FRAME_END
jmp restore_processor_state
 ENDPROC(do_suspend_lowlevel)
 


[tip:x86/debug] x86/asm: Create stack frames in rwsem functions

2016-02-23 Thread tip-bot for Josh Poimboeuf
Commit-ID:  8576cf762b6ab9d53b444262e2d3ba2a7d381c18
Gitweb: http://git.kernel.org/tip/8576cf762b6ab9d53b444262e2d3ba2a7d381c18
Author: Josh Poimboeuf 
AuthorDate: Thu, 21 Jan 2016 16:49:22 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:03:58 +0100

x86/asm: Create stack frames in rwsem functions

rwsem.S has several callable non-leaf functions which don't honor
CONFIG_FRAME_POINTER, which can result in bad stack traces.

Create stack frames for them when CONFIG_FRAME_POINTER is enabled.

Signed-off-by: Josh Poimboeuf 
Reviewed-by: Borislav Petkov 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Bernd Petrovitsch 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chris J Arges 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Jiri Slaby 
Cc: Linus Torvalds 
Cc: Michal Marek 
Cc: Namhyung Kim 
Cc: Pedro Alves 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: live-patch...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/ad0932bbead975b15f9578e4f2cf2ee5961eb840.1453405861.git.jpoim...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/lib/rwsem.S | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
index 40027db..be110ef 100644
--- a/arch/x86/lib/rwsem.S
+++ b/arch/x86/lib/rwsem.S
@@ -15,6 +15,7 @@
 
 #include 
 #include 
+#include 
 
 #define __ASM_HALF_REG(reg)__ASM_SEL(reg, e##reg)
 #define __ASM_HALF_SIZE(inst)  __ASM_SEL(inst##w, inst##l)
@@ -84,24 +85,29 @@
 
 /* Fix up special calling conventions */
 ENTRY(call_rwsem_down_read_failed)
+   FRAME_BEGIN
save_common_regs
__ASM_SIZE(push,) %__ASM_REG(dx)
movq %rax,%rdi
call rwsem_down_read_failed
__ASM_SIZE(pop,) %__ASM_REG(dx)
restore_common_regs
+   FRAME_END
ret
 ENDPROC(call_rwsem_down_read_failed)
 
 ENTRY(call_rwsem_down_write_failed)
+   FRAME_BEGIN
save_common_regs
movq %rax,%rdi
call rwsem_down_write_failed
restore_common_regs
+   FRAME_END
ret
 ENDPROC(call_rwsem_down_write_failed)
 
 ENTRY(call_rwsem_wake)
+   FRAME_BEGIN
/* do nothing if still outstanding active readers */
__ASM_HALF_SIZE(dec) %__ASM_HALF_REG(dx)
jnz 1f
@@ -109,15 +115,18 @@ ENTRY(call_rwsem_wake)
movq %rax,%rdi
call rwsem_wake
restore_common_regs
-1: ret
+1: FRAME_END
+   ret
 ENDPROC(call_rwsem_wake)
 
 ENTRY(call_rwsem_downgrade_wake)
+   FRAME_BEGIN
save_common_regs
__ASM_SIZE(push,) %__ASM_REG(dx)
movq %rax,%rdi
call rwsem_downgrade_wake
__ASM_SIZE(pop,) %__ASM_REG(dx)
restore_common_regs
+   FRAME_END
ret
 ENDPROC(call_rwsem_downgrade_wake)


[tip:x86/platform] x86/platform/intel/quark: Drop IMR lock bit support

2016-02-23 Thread tip-bot for Bryan O'Donoghue
Commit-ID:  c637fa5294cefeda8be73cce20ba6693d22262dc
Gitweb: http://git.kernel.org/tip/c637fa5294cefeda8be73cce20ba6693d22262dc
Author: Bryan O'Donoghue 
AuthorDate: Tue, 23 Feb 2016 01:29:59 +
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 07:37:23 +0100

x86/platform/intel/quark: Drop IMR lock bit support

Isolated Memory Regions support a lock bit. The lock bit in an IMR prevents
modification of the IMR until the core goes through a warm or cold reset.
The lock bit feature is not useful in the context of the kernel API and is
not really necessary since modification of IMRs is possible only from
ring-zero anyway. This patch drops support for IMR locks bits, it
simplifies the kernel API and removes an unnecessary and needlessly complex
feature.

Suggested-by: Ingo Molnar 
Signed-off-by: Bryan O'Donoghue 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: andriy.shevche...@linux.intel.com
Cc: boon.leong@intel.com
Cc: paul.gortma...@windriver.com
Link: 
http://lkml.kernel.org/r/1456190999-12685-3-git-send-email-pure.lo...@nexus-software.ie
Signed-off-by: Ingo Molnar 
---
 arch/x86/include/asm/imr.h   |  2 +-
 arch/x86/platform/intel-quark/imr.c  | 24 ++--
 arch/x86/platform/intel-quark/imr_selftest.c | 15 +++
 3 files changed, 14 insertions(+), 27 deletions(-)

diff --git a/arch/x86/include/asm/imr.h b/arch/x86/include/asm/imr.h
index cd2ce40..ebea2c9 100644
--- a/arch/x86/include/asm/imr.h
+++ b/arch/x86/include/asm/imr.h
@@ -53,7 +53,7 @@
 #define IMR_MASK   (IMR_ALIGN - 1)
 
 int imr_add_range(phys_addr_t base, size_t size,
- unsigned int rmask, unsigned int wmask, bool lock);
+ unsigned int rmask, unsigned int wmask);
 
 int imr_remove_range(phys_addr_t base, size_t size);
 
diff --git a/arch/x86/platform/intel-quark/imr.c 
b/arch/x86/platform/intel-quark/imr.c
index 740445a..17d6d22 100644
--- a/arch/x86/platform/intel-quark/imr.c
+++ b/arch/x86/platform/intel-quark/imr.c
@@ -134,11 +134,9 @@ static int imr_read(struct imr_device *idev, u32 imr_id, 
struct imr_regs *imr)
  * @idev:  pointer to imr_device structure.
  * @imr_id:IMR entry to write.
  * @imr:   IMR structure representing address and access masks.
- * @lock:  indicates if the IMR lock bit should be applied.
  * @return:0 on success or error code passed from mbi_iosf on failure.
  */
-static int imr_write(struct imr_device *idev, u32 imr_id,
-struct imr_regs *imr, bool lock)
+static int imr_write(struct imr_device *idev, u32 imr_id, struct imr_regs *imr)
 {
unsigned long flags;
u32 reg = imr_id * IMR_NUM_REGS + idev->reg_base;
@@ -162,15 +160,6 @@ static int imr_write(struct imr_device *idev, u32 imr_id,
if (ret)
goto failed;
 
-   /* Lock bit must be set separately to addr_lo address bits. */
-   if (lock) {
-   imr->addr_lo |= IMR_LOCK;
-   ret = iosf_mbi_write(QRK_MBI_UNIT_MM, MBI_REG_WRITE,
-reg - IMR_NUM_REGS, imr->addr_lo);
-   if (ret)
-   goto failed;
-   }
-
local_irq_restore(flags);
return 0;
 failed:
@@ -322,11 +311,10 @@ static inline int imr_address_overlap(phys_addr_t addr, 
struct imr_regs *imr)
  * @size:  physical size of region in bytes must be aligned to 1KiB.
  * @read_mask: read access mask.
  * @write_mask:write access mask.
- * @lock:  indicates whether or not to permanently lock this region.
  * @return:zero on success or negative value indicating error.
  */
 int imr_add_range(phys_addr_t base, size_t size,
- unsigned int rmask, unsigned int wmask, bool lock)
+ unsigned int rmask, unsigned int wmask)
 {
phys_addr_t end;
unsigned int i;
@@ -399,7 +387,7 @@ int imr_add_range(phys_addr_t base, size_t size,
imr.rmask = rmask;
imr.wmask = wmask;
 
-   ret = imr_write(idev, reg, &imr, lock);
+   ret = imr_write(idev, reg, &imr);
if (ret < 0) {
/*
 * In the highly unlikely event iosf_mbi_write failed
@@ -410,7 +398,7 @@ int imr_add_range(phys_addr_t base, size_t size,
imr.addr_hi = 0;
imr.rmask = IMR_READ_ACCESS_ALL;
imr.wmask = IMR_WRITE_ACCESS_ALL;
-   imr_write(idev, reg, &imr, false);
+   imr_write(idev, reg, &imr);
}
 failed:
mutex_unlock(&idev->lock);
@@ -506,7 +494,7 @@ static int __imr_remove_range(int reg, phys_addr_t base, 
size_t size)
imr.rmask = IMR_READ_ACCESS_ALL;
imr.wmask = IMR_WRITE_ACCESS_ALL;
 
-   ret = imr_write(idev, reg, &imr, false);
+   ret = imr_write(idev, reg, &imr);
 
 failed:
mutex_unlock(&idev->lock);
@@ -587,7 +575,7 @@ static void __init imr_fixup_memmap(struct imr_device *idev)
 * We don't round up @siz

[tip:x86/debug] x86/kvm: Add output operand in vmx_handle_external_intr inline asm

2016-02-23 Thread tip-bot for Chris J Arges
Commit-ID:  3aff5415db7e5a5e50f9b05ce1b0b92a4a55e169
Gitweb: http://git.kernel.org/tip/3aff5415db7e5a5e50f9b05ce1b0b92a4a55e169
Author: Chris J Arges 
AuthorDate: Fri, 22 Jan 2016 15:44:38 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:04:01 +0100

x86/kvm: Add output operand in vmx_handle_external_intr inline asm

Stacktool generates the following warning:
  stacktool: arch/x86/kvm/vmx.o: vmx_handle_external_intr()+0x67: call without 
frame pointer save/setup

By adding the stackpointer as an output operand, this patch ensures that a
stack frame is created when CONFIG_FRAME_POINTER is enabled for the inline
assmebly statement.

Signed-off-by: Chris J Arges 
Reviewed-by: Josh Poimboeuf 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: g...@kernel.org
Cc: k...@vger.kernel.org
Cc: live-patch...@vger.kernel.org
Cc: pbonz...@redhat.com
Link: 
http://lkml.kernel.org/r/1453499078-9330-3-git-send-email-chris.j.ar...@canonical.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/kvm/vmx.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index e2951b6..e153522 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -8356,6 +8356,7 @@ static void vmx_complete_atomic_exit(struct vcpu_vmx *vmx)
 static void vmx_handle_external_intr(struct kvm_vcpu *vcpu)
 {
u32 exit_intr_info = vmcs_read32(VM_EXIT_INTR_INFO);
+   register void *__sp asm(_ASM_SP);
 
/*
 * If external interrupt exists, IF bit is set in rflags/eflags on the
@@ -8388,8 +8389,9 @@ static void vmx_handle_external_intr(struct kvm_vcpu 
*vcpu)
"call *%[entry]\n\t"
:
 #ifdef CONFIG_X86_64
-   [sp]"=&r"(tmp)
+   [sp]"=&r"(tmp),
 #endif
+   "+r"(__sp)
:
[entry]"r"(entry),
[ss]"i"(__KERNEL_DS),


[tip:x86/debug] x86/uaccess: Add stack frame output operand in get_user() inline asm

2016-02-23 Thread tip-bot for Chris J Arges
Commit-ID:  5e947b38f8ead33bf6aaecc2af20a0a3a988fd02
Gitweb: http://git.kernel.org/tip/5e947b38f8ead33bf6aaecc2af20a0a3a988fd02
Author: Chris J Arges 
AuthorDate: Thu, 21 Jan 2016 16:49:25 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:03:58 +0100

x86/uaccess: Add stack frame output operand in get_user() inline asm

Numerous 'call without frame pointer save/setup' warnings are introduced
by stacktool because of functions using the get_user() macro. Bad stack
traces could occur due to lack of or misplacement of stack frame setup
code.

This patch forces a stack frame to be created before the inline asm code
if CONFIG_FRAME_POINTER is enabled by listing the stack pointer as an
output operand for the get_user() inline assembly statement.

Signed-off-by: Chris J Arges 
Signed-off-by: Josh Poimboeuf 
Reviewed-by: Borislav Petkov 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Bernd Petrovitsch 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Jiri Slaby 
Cc: Linus Torvalds 
Cc: Michal Marek 
Cc: Namhyung Kim 
Cc: Pedro Alves 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: live-patch...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/bc85501f221ee512670797c7f110022e64b12c81.1453405861.git.jpoim...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/include/asm/uaccess.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
index a4a30e4..9bbb3b2 100644
--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -179,10 +179,11 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 
0ULL, 0UL))
 ({ \
int __ret_gu;   \
register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX);\
+   register void *__sp asm(_ASM_SP);   \
__chk_user_ptr(ptr);\
might_fault();  \
-   asm volatile("call __get_user_%P3"  \
-: "=a" (__ret_gu), "=r" (__val_gu) \
+   asm volatile("call __get_user_%P4"  \
+: "=a" (__ret_gu), "=r" (__val_gu), "+r" (__sp)\
 : "0" (ptr), "i" (sizeof(*(ptr;\
(x) = (__force __typeof__(*(ptr))) __val_gu;\
__builtin_expect(__ret_gu, 0);  \


[tip:efi/core] efi/efistub: Prevent __init annotations from being used

2016-02-23 Thread tip-bot for Ard Biesheuvel
Commit-ID:  07e83dbb75865b016f6493c119a30aac7c25051a
Gitweb: http://git.kernel.org/tip/07e83dbb75865b016f6493c119a30aac7c25051a
Author: Ard Biesheuvel 
AuthorDate: Wed, 17 Feb 2016 12:35:59 +
Committer:  Ingo Molnar 
CommitDate: Mon, 22 Feb 2016 08:26:26 +0100

efi/efistub: Prevent __init annotations from being used

__init annotations should not be used in the EFI stub, since the code is
either included in the decompressor (x86, ARM) where they have no effect,
or the whole stub is __init annotated at the section level (arm64), by
renaming the sections.

In the second case the __init annotations will be redundant, and will
result in section names like .init.init.text, and our linker script does
not expect that.

So un-#define __init so that its inadvertent use will force a build error.

Signed-off-by: Ard Biesheuvel 
Signed-off-by: Matt Fleming 
Acked-by: Mark Rutland 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1455712566-16727-7-git-send-email-m...@codeblueprint.co.uk
Signed-off-by: Ingo Molnar 
---
 drivers/firmware/efi/libstub/efistub.h | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/firmware/efi/libstub/efistub.h 
b/drivers/firmware/efi/libstub/efistub.h
index 6b6548f..86ff7bf 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -5,6 +5,16 @@
 /* error code which can't be mistaken for valid address */
 #define EFI_ERROR  (~0UL)
 
+/*
+ * __init annotations should not be used in the EFI stub, since the code is
+ * either included in the decompressor (x86, ARM) where they have no effect,
+ * or the whole stub is __init annotated at the section level (arm64), by
+ * renaming the sections, in which case the __init annotation will be
+ * redundant, and will result in section names like .init.init.text, and our
+ * linker script does not expect that.
+ */
+#undef __init
+
 void efi_char16_printk(efi_system_table_t *, efi_char16_t *);
 
 efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg, void *__image,


[tip:x86/debug] x86/locking: Create stack frame in PV unlock

2016-02-23 Thread tip-bot for Josh Poimboeuf
Commit-ID:  74d03c501b10e38c54554567933509cec1eb
Gitweb: http://git.kernel.org/tip/74d03c501b10e38c54554567933509cec1eb
Author: Josh Poimboeuf 
AuthorDate: Thu, 21 Jan 2016 16:49:32 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:04:00 +0100

x86/locking: Create stack frame in PV unlock

The assembly PV_UNLOCK function is a callable non-leaf function which
doesn't honor CONFIG_FRAME_POINTER, which can result in bad stack
traces.

Create a stack frame when CONFIG_FRAME_POINTER is enabled.

Signed-off-by: Josh Poimboeuf 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Bernd Petrovitsch 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chris J Arges 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Jiri Slaby 
Cc: Linus Torvalds 
Cc: Michal Marek 
Cc: Namhyung Kim 
Cc: Pedro Alves 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: Waiman Long 
Cc: live-patch...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/6685a72ddbbd0ad3694337cca0af4b4ea09f5f40.1453405861.git.jpoim...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/include/asm/qspinlock_paravirt.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/x86/include/asm/qspinlock_paravirt.h 
b/arch/x86/include/asm/qspinlock_paravirt.h
index 9f92c18..9d55f9b 100644
--- a/arch/x86/include/asm/qspinlock_paravirt.h
+++ b/arch/x86/include/asm/qspinlock_paravirt.h
@@ -36,8 +36,10 @@ PV_CALLEE_SAVE_REGS_THUNK(__pv_queued_spin_unlock_slowpath);
  */
 asm(".pushsection .text;"
".globl " PV_UNLOCK ";"
+   ".type " PV_UNLOCK ", @function;"
".align 4,0x90;"
PV_UNLOCK ": "
+   FRAME_BEGIN
"push  %rdx;"
"mov   $0x1,%eax;"
"xor   %edx,%edx;"
@@ -45,6 +47,7 @@ asm(".pushsection .text;"
"cmp   $0x1,%al;"
"jne   .slowpath;"
"pop   %rdx;"
+   FRAME_END
"ret;"
".slowpath: "
"push   %rsi;"
@@ -52,6 +55,7 @@ asm(".pushsection .text;"
"call " PV_UNLOCK_SLOWPATH ";"
"pop%rsi;"
"pop%rdx;"
+   FRAME_END
"ret;"
".size " PV_UNLOCK ", .-" PV_UNLOCK ";"
".popsection");


[tip:x86/debug] x86/kvm: Make test_cc() always inline

2016-02-23 Thread tip-bot for Josh Poimboeuf
Commit-ID:  dcf6fdbaa99fc3a3e38797e6d596c5241de18b9b
Gitweb: http://git.kernel.org/tip/dcf6fdbaa99fc3a3e38797e6d596c5241de18b9b
Author: Josh Poimboeuf 
AuthorDate: Fri, 22 Jan 2016 10:16:12 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:04:00 +0100

x86/kvm: Make test_cc() always inline

With some configs (including allyesconfig), gcc doesn't inline
test_cc().  When that happens, test_cc() doesn't create a stack frame
before inserting the inline asm call instruction.  This breaks frame
pointer convention if CONFIG_FRAME_POINTER is enabled and can result in
a bad stack trace.

Force it to always be inlined so that its containing function's stack
frame can be used.

Suggested-by: Paolo Bonzini 
Signed-off-by: Josh Poimboeuf 
Acked-by: Paolo Bonzini 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Bernd Petrovitsch 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chris J Arges 
Cc: Denys Vlasenko 
Cc: Gleb Natapov 
Cc: H. Peter Anvin 
Cc: Jiri Slaby 
Cc: Linus Torvalds 
Cc: Michal Marek 
Cc: Namhyung Kim 
Cc: Pedro Alves 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: k...@vger.kernel.org
Cc: live-patch...@vger.kernel.org
Link: http://lkml.kernel.org/r/20160122161612.ge20...@treble.redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/kvm/emulate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index aa4d726..80363eb 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -969,7 +969,7 @@ static int em_bsr_c(struct x86_emulate_ctxt *ctxt)
return fastop(ctxt, em_bsr);
 }
 
-static u8 test_cc(unsigned int condition, unsigned long flags)
+static __always_inline u8 test_cc(unsigned int condition, unsigned long flags)
 {
u8 rc;
void (*fop)(void) = (void *)em_setcc + 4 * (condition & 0xf);


[tip:efi/core] x86/efi: Only map kernel text for EFI mixed mode

2016-02-23 Thread tip-bot for Sai Praneeth
Commit-ID:  2ad510dc372c2caac9aada9ff6dd10e787616e1d
Gitweb: http://git.kernel.org/tip/2ad510dc372c2caac9aada9ff6dd10e787616e1d
Author: Sai Praneeth 
AuthorDate: Wed, 17 Feb 2016 12:36:06 +
Committer:  Ingo Molnar 
CommitDate: Mon, 22 Feb 2016 08:26:28 +0100

x86/efi: Only map kernel text for EFI mixed mode

The correct symbol to use when figuring out the size of the kernel
text is '_etext', not '_end' which is the symbol for the entire kernel
image includes data and debug sections.

Signed-off-by: Sai Praneeth Prakhya 
Signed-off-by: Matt Fleming 
Cc: Ard Biesheuvel 
Cc: Borislav Petkov 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Ravi Shankar 
Cc: Ricardo Neri 
Cc: Thomas Gleixner 
Cc: linux-...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1455712566-16727-14-git-send-email-m...@codeblueprint.co.uk
Signed-off-by: Ingo Molnar 
---
 arch/x86/platform/efi/efi_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
index 40d2f44..49e4dd4 100644
--- a/arch/x86/platform/efi/efi_64.c
+++ b/arch/x86/platform/efi/efi_64.c
@@ -275,7 +275,7 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, 
unsigned num_pages)
efi_scratch.phys_stack = virt_to_phys(page_address(page));
efi_scratch.phys_stack += PAGE_SIZE; /* stack grows down */
 
-   npages = (_end - _text) >> PAGE_SHIFT;
+   npages = (_etext - _text) >> PAGE_SHIFT;
text = __pa(_text);
pfn = text >> PAGE_SHIFT;
 


[tip:x86/debug] x86/asm/efi: Create a stack frame in efi_call()

2016-02-23 Thread tip-bot for Josh Poimboeuf
Commit-ID:  54bb55fa2922da76d3856b465c1b22f242d42daa
Gitweb: http://git.kernel.org/tip/54bb55fa2922da76d3856b465c1b22f242d42daa
Author: Josh Poimboeuf 
AuthorDate: Thu, 21 Jan 2016 16:49:23 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:03:58 +0100

x86/asm/efi: Create a stack frame in efi_call()

efi_call() is a callable non-leaf function which doesn't honor
CONFIG_FRAME_POINTER, which can result in bad stack traces.

Create a stack frame for it when CONFIG_FRAME_POINTER is enabled.

Signed-off-by: Josh Poimboeuf 
Reviewed-by: Matt Fleming 
Reviewed-by: Borislav Petkov 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Bernd Petrovitsch 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chris J Arges 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Jiri Slaby 
Cc: Linus Torvalds 
Cc: Michal Marek 
Cc: Namhyung Kim 
Cc: Pedro Alves 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: live-patch...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/2294b6fad60eea4cc862eddc8e98a1324e6eeeca.1453405861.git.jpoim...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/platform/efi/efi_stub_64.S | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/x86/platform/efi/efi_stub_64.S 
b/arch/x86/platform/efi/efi_stub_64.S
index 86d0f9e..0df2dcc 100644
--- a/arch/x86/platform/efi/efi_stub_64.S
+++ b/arch/x86/platform/efi/efi_stub_64.S
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define SAVE_XMM   \
mov %rsp, %rax; \
@@ -74,6 +75,7 @@
.endm
 
 ENTRY(efi_call)
+   FRAME_BEGIN
SAVE_XMM
mov (%rsp), %rax
mov 8(%rax), %rax
@@ -88,6 +90,7 @@ ENTRY(efi_call)
RESTORE_PGT
addq $48, %rsp
RESTORE_XMM
+   FRAME_END
ret
 ENDPROC(efi_call)
 


[tip:mm/readonly] arch: Introduce post-init read-only memory

2016-02-23 Thread tip-bot for Kees Cook
Commit-ID:  c74ba8b3480da6ddaea17df2263ec09b869ac496
Gitweb: http://git.kernel.org/tip/c74ba8b3480da6ddaea17df2263ec09b869ac496
Author: Kees Cook 
AuthorDate: Wed, 17 Feb 2016 14:41:15 -0800
Committer:  Ingo Molnar 
CommitDate: Mon, 22 Feb 2016 08:51:38 +0100

arch: Introduce post-init read-only memory

One of the easiest ways to protect the kernel from attack is to reduce
the internal attack surface exposed when a "write" flaw is available. By
making as much of the kernel read-only as possible, we reduce the
attack surface.

Many things are written to only during __init, and never changed
again. These cannot be made "const" since the compiler will do the wrong
thing (we do actually need to write to them). Instead, move these items
into a memory region that will be made read-only during mark_rodata_ro()
which happens after all kernel __init code has finished.

This introduces __ro_after_init as a way to mark such memory, and adds
some documentation about the existing __read_mostly marking.

This improves the security of the Linux kernel by marking formerly
read-write memory regions as read-only on a fully booted up system.

Based on work by PaX Team and Brad Spengler.

Signed-off-by: Kees Cook 
Cc: Andy Lutomirski 
Cc: Arnd Bergmann 
Cc: Borislav Petkov 
Cc: Brad Spengler 
Cc: Brian Gerst 
Cc: David Brown 
Cc: Denys Vlasenko 
Cc: Emese Revfy 
Cc: H. Peter Anvin 
Cc: Linus Torvalds 
Cc: Mathias Krause 
Cc: Michael Ellerman 
Cc: PaX Team 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: kernel-harden...@lists.openwall.com
Cc: linux-arch 
Link: 
http://lkml.kernel.org/r/1455748879-21872-5-git-send-email-keesc...@chromium.org
Signed-off-by: Ingo Molnar 
---
 arch/parisc/include/asm/cache.h   |  3 +++
 include/asm-generic/vmlinux.lds.h |  1 +
 include/linux/cache.h | 14 ++
 3 files changed, 18 insertions(+)

diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
index 3d0e17b..df0f52b 100644
--- a/arch/parisc/include/asm/cache.h
+++ b/arch/parisc/include/asm/cache.h
@@ -22,6 +22,9 @@
 
 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
 
+/* Read-only memory is marked before mark_rodata_ro() is called. */
+#define __ro_after_init__read_mostly
+
 void parisc_cache_init(void);  /* initializes cache-flushing */
 void disable_sr_hashing_asm(int); /* low level support for above */
 void disable_sr_hashing(void);   /* turns off space register hashing */
diff --git a/include/asm-generic/vmlinux.lds.h 
b/include/asm-generic/vmlinux.lds.h
index c4bd0e2..772c784 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -256,6 +256,7 @@
.rodata   : AT(ADDR(.rodata) - LOAD_OFFSET) {   \
VMLINUX_SYMBOL(__start_rodata) = .; \
*(.rodata) *(.rodata.*) \
+   *(.data..ro_after_init) /* Read only after init */  \
*(__vermagic)   /* Kernel version magic */  \
. = ALIGN(8);   \
VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
diff --git a/include/linux/cache.h b/include/linux/cache.h
index 17e7e82..1be04f8 100644
--- a/include/linux/cache.h
+++ b/include/linux/cache.h
@@ -12,10 +12,24 @@
 #define SMP_CACHE_BYTES L1_CACHE_BYTES
 #endif
 
+/*
+ * __read_mostly is used to keep rarely changing variables out of frequently
+ * updated cachelines. If an architecture doesn't support it, ignore the
+ * hint.
+ */
 #ifndef __read_mostly
 #define __read_mostly
 #endif
 
+/*
+ * __ro_after_init is used to mark things that are read-only after init (i.e.
+ * after mark_rodata_ro() has been called). These are effectively read-only,
+ * but may get written to during init, so can't live in .rodata (via "const").
+ */
+#ifndef __ro_after_init
+#define __ro_after_init __attribute__((__section__(".data..ro_after_init")))
+#endif
+
 #ifndef cacheline_aligned
 #define cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
 #endif


[tip:x86/debug] x86/asm/power: Create stack frames in hibernate_asm_64.S

2016-02-23 Thread tip-bot for Josh Poimboeuf
Commit-ID:  6f9e5b9ab3161a77ed403af8d7a9ab0a7bab1c88
Gitweb: http://git.kernel.org/tip/6f9e5b9ab3161a77ed403af8d7a9ab0a7bab1c88
Author: Josh Poimboeuf 
AuthorDate: Thu, 21 Jan 2016 16:49:24 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:03:58 +0100

x86/asm/power: Create stack frames in hibernate_asm_64.S

swsusp_arch_suspend() and restore_registers() are callable non-leaf
functions which don't honor CONFIG_FRAME_POINTER, which can result in
bad stack traces.  Also they aren't annotated as ELF callable functions
which can confuse tooling.

Create a stack frame for them when CONFIG_FRAME_POINTER is enabled and
give them proper ELF function annotations.

Signed-off-by: Josh Poimboeuf 
Reviewed-by: Borislav Petkov 
Acked-by: Pavel Machek 
Acked-by: Rafael J. Wysocki 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Bernd Petrovitsch 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chris J Arges 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Jiri Slaby 
Cc: Linus Torvalds 
Cc: Michal Marek 
Cc: Namhyung Kim 
Cc: Pedro Alves 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: live-patch...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/bdad00205897dc707aebe9e9e39757085e2bf999.1453405861.git.jpoim...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/power/hibernate_asm_64.S | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/x86/power/hibernate_asm_64.S 
b/arch/x86/power/hibernate_asm_64.S
index e2386cb..4400a43 100644
--- a/arch/x86/power/hibernate_asm_64.S
+++ b/arch/x86/power/hibernate_asm_64.S
@@ -21,8 +21,10 @@
 #include 
 #include 
 #include 
+#include 
 
 ENTRY(swsusp_arch_suspend)
+   FRAME_BEGIN
movq$saved_context, %rax
movq%rsp, pt_regs_sp(%rax)
movq%rbp, pt_regs_bp(%rax)
@@ -50,7 +52,9 @@ ENTRY(swsusp_arch_suspend)
movq%rax, restore_cr3(%rip)
 
call swsusp_save
+   FRAME_END
ret
+ENDPROC(swsusp_arch_suspend)
 
 ENTRY(restore_image)
/* switch to temporary page tables */
@@ -107,6 +111,7 @@ ENTRY(core_restore_code)
 */
 
 ENTRY(restore_registers)
+   FRAME_BEGIN
/* go back to the original page tables */
movq%rbx, %cr3
 
@@ -147,4 +152,6 @@ ENTRY(restore_registers)
/* tell the hibernation core that we've just restored the memory */
movq%rax, in_suspend(%rip)
 
+   FRAME_END
ret
+ENDPROC(restore_registers)


[tip:efi/core] x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

2016-02-23 Thread tip-bot for Sai Praneeth
Commit-ID:  397630150632639b3ca5b4414accd5011c45e276
Gitweb: http://git.kernel.org/tip/397630150632639b3ca5b4414accd5011c45e276
Author: Sai Praneeth 
AuthorDate: Wed, 17 Feb 2016 12:35:56 +
Committer:  Ingo Molnar 
CommitDate: Mon, 22 Feb 2016 08:26:26 +0100

x86/mm/pat: Use _PAGE_GLOBAL bit for EFI page table mappings

Since EFI page tables can be treated as kernel page tables they should
be global. All the other page mapping functions in pageattr.c set the
_PAGE_GLOBAL bit and we want to avoid inconsistencies when we map a page
in the EFI code paths, for example when that page is split in
__split_large_page(), etc. It also makes it easier to validate that the
EFI region mappings have the correct attributes because there are fewer
differences compared with regular kernel mappings.

Signed-off-by: Sai Praneeth Prakhya 
Signed-off-by: Matt Fleming 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Ard Biesheuvel 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Hugh Dickins 
Cc: Linus Torvalds 
Cc: Luis R. Rodriguez 
Cc: Peter Zijlstra 
Cc: Ravi Shankar 
Cc: Ricardo Neri 
Cc: Thomas Gleixner 
Cc: Toshi Kani 
Cc: linux-...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1455712566-16727-4-git-send-email-m...@codeblueprint.co.uk
Signed-off-by: Ingo Molnar 
---
 arch/x86/mm/pageattr.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
index 632d34d..bf312da 100644
--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -909,6 +909,20 @@ static void populate_pte(struct cpa_data *cpa,
 
pte = pte_offset_kernel(pmd, start);
 
+   /*
+* Set the GLOBAL flags only if the PRESENT flag is
+* set otherwise pte_present will return true even on
+* a non present pte. The canon_pgprot will clear
+* _PAGE_GLOBAL for the ancient hardware that doesn't
+* support it.
+*/
+   if (pgprot_val(pgprot) & _PAGE_PRESENT)
+   pgprot_val(pgprot) |= _PAGE_GLOBAL;
+   else
+   pgprot_val(pgprot) &= ~_PAGE_GLOBAL;
+
+   pgprot = canon_pgprot(pgprot);
+
while (num_pages-- && start < end) {
set_pte(pte, pfn_pte(cpa->pfn, pgprot));
 


[tip:mm/readonly] asm-generic: Consolidate mark_rodata_ro()

2016-02-23 Thread tip-bot for Kees Cook
Commit-ID:  e267d97b83d9cecc16c54825f9f3ac7f72dc1e1e
Gitweb: http://git.kernel.org/tip/e267d97b83d9cecc16c54825f9f3ac7f72dc1e1e
Author: Kees Cook 
AuthorDate: Wed, 17 Feb 2016 14:41:12 -0800
Committer:  Ingo Molnar 
CommitDate: Mon, 22 Feb 2016 08:51:37 +0100

asm-generic: Consolidate mark_rodata_ro()

Instead of defining mark_rodata_ro() in each architecture, consolidate it.

Signed-off-by: Kees Cook 
Acked-by: Will Deacon 
Cc: Andrew Morton 
Cc: Andy Gross 
Cc: Andy Lutomirski 
Cc: Ard Biesheuvel 
Cc: Arnd Bergmann 
Cc: Ashok Kumar 
Cc: Borislav Petkov 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Catalin Marinas 
Cc: Dan Williams 
Cc: David Brown 
Cc: David Hildenbrand 
Cc: Denys Vlasenko 
Cc: Emese Revfy 
Cc: H. Peter Anvin 
Cc: Helge Deller 
Cc: James E.J. Bottomley 
Cc: Linus Torvalds 
Cc: Luis R. Rodriguez 
Cc: Marc Zyngier 
Cc: Mark Rutland 
Cc: Mathias Krause 
Cc: Michael Ellerman 
Cc: Nicolas Pitre 
Cc: PaX Team 
Cc: Paul Gortmaker 
Cc: Peter Zijlstra 
Cc: Ross Zwisler 
Cc: Russell King 
Cc: Rusty Russell 
Cc: Stephen Boyd 
Cc: Thomas Gleixner 
Cc: Toshi Kani 
Cc: kernel-harden...@lists.openwall.com
Cc: linux-arch 
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-par...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1455748879-21872-2-git-send-email-keesc...@chromium.org
Signed-off-by: Ingo Molnar 
---
 arch/arm/include/asm/cacheflush.h| 1 -
 arch/arm64/include/asm/cacheflush.h  | 4 
 arch/parisc/include/asm/cacheflush.h | 4 
 arch/x86/include/asm/cacheflush.h| 1 -
 include/linux/init.h | 4 
 5 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/arch/arm/include/asm/cacheflush.h 
b/arch/arm/include/asm/cacheflush.h
index d5525bf..9156fc3 100644
--- a/arch/arm/include/asm/cacheflush.h
+++ b/arch/arm/include/asm/cacheflush.h
@@ -491,7 +491,6 @@ static inline int set_memory_nx(unsigned long addr, int 
numpages) { return 0; }
 #endif
 
 #ifdef CONFIG_DEBUG_RODATA
-void mark_rodata_ro(void);
 void set_kernel_text_rw(void);
 void set_kernel_text_ro(void);
 #else
diff --git a/arch/arm64/include/asm/cacheflush.h 
b/arch/arm64/include/asm/cacheflush.h
index 7fc294c..22dda61 100644
--- a/arch/arm64/include/asm/cacheflush.h
+++ b/arch/arm64/include/asm/cacheflush.h
@@ -156,8 +156,4 @@ int set_memory_rw(unsigned long addr, int numpages);
 int set_memory_x(unsigned long addr, int numpages);
 int set_memory_nx(unsigned long addr, int numpages);
 
-#ifdef CONFIG_DEBUG_RODATA
-void mark_rodata_ro(void);
-#endif
-
 #endif
diff --git a/arch/parisc/include/asm/cacheflush.h 
b/arch/parisc/include/asm/cacheflush.h
index 845272c..7bd69bd 100644
--- a/arch/parisc/include/asm/cacheflush.h
+++ b/arch/parisc/include/asm/cacheflush.h
@@ -121,10 +121,6 @@ flush_anon_page(struct vm_area_struct *vma, struct page 
*page, unsigned long vma
}
 }
 
-#ifdef CONFIG_DEBUG_RODATA
-void mark_rodata_ro(void);
-#endif
-
 #include 
 
 #define ARCH_HAS_KMAP
diff --git a/arch/x86/include/asm/cacheflush.h 
b/arch/x86/include/asm/cacheflush.h
index e63aa38..c8cff75 100644
--- a/arch/x86/include/asm/cacheflush.h
+++ b/arch/x86/include/asm/cacheflush.h
@@ -92,7 +92,6 @@ void clflush_cache_range(void *addr, unsigned int size);
 #define mmio_flush_range(addr, size) clflush_cache_range(addr, size)
 
 #ifdef CONFIG_DEBUG_RODATA
-void mark_rodata_ro(void);
 extern const int rodata_test_data;
 extern int kernel_set_to_readonly;
 void set_kernel_text_rw(void);
diff --git a/include/linux/init.h b/include/linux/init.h
index b449f37..aedb254 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -142,6 +142,10 @@ void prepare_namespace(void);
 void __init load_default_modules(void);
 int __init init_rootfs(void);
 
+#ifdef CONFIG_DEBUG_RODATA
+void mark_rodata_ro(void);
+#endif
+
 extern void (*late_time_init)(void);
 
 extern bool initcall_debug;


[tip:mm/readonly] ARM/vdso: Mark the vDSO code read-only after init

2016-02-23 Thread tip-bot for David Brown
Commit-ID:  11bf9b865898961cee60a41c483c9f27ec76e12e
Gitweb: http://git.kernel.org/tip/11bf9b865898961cee60a41c483c9f27ec76e12e
Author: David Brown 
AuthorDate: Wed, 17 Feb 2016 14:41:18 -0800
Committer:  Ingo Molnar 
CommitDate: Mon, 22 Feb 2016 08:51:39 +0100

ARM/vdso: Mark the vDSO code read-only after init

Although the ARM vDSO is cleanly separated by code/data with the code
being read-only in userspace mappings, the code page is still writable
from the kernel.

There have been exploits (such as http://itszn.com/blog/?p=21) that
take advantage of this on x86 to go from a bad kernel write to full
root.

Prevent this specific exploit class on ARM as well by putting the vDSO
code page in post-init read-only memory as well.

Before:
vdso: 1 text pages at base 80927000
root@Vexpress:/ cat /sys/kernel/debug/kernel_page_tables
---[ Modules ]---
---[ Kernel Mapping ]---
0x8000-0x8010   1M RW NX SHD
0x8010-0x8060   5M ro x  SHD
0x8060-0x8080   2M ro NX SHD
0x8080-0xbe00 984M RW NX SHD

After:
vdso: 1 text pages at base 8072b000
root@Vexpress:/ cat /sys/kernel/debug/kernel_page_tables
---[ Modules ]---
---[ Kernel Mapping ]---
0x8000-0x8010   1M RW NX SHD
0x8010-0x8060   5M ro x  SHD
0x8060-0x8080   2M ro NX SHD
0x8080-0xbe00 984M RW NX SHD

Inspired by https://lkml.org/lkml/2016/1/19/494 based on work by the
PaX Team, Brad Spengler, and Kees Cook.

Signed-off-by: David Brown 
Signed-off-by: Kees Cook 
Cc: Andy Lutomirski 
Cc: Arnd Bergmann 
Cc: Borislav Petkov 
Cc: Brad Spengler 
Cc: Brian Gerst 
Cc: Denys Vlasenko 
Cc: Emese Revfy 
Cc: H. Peter Anvin 
Cc: Linus Torvalds 
Cc: Mathias Krause 
Cc: Michael Ellerman 
Cc: Nathan Lynch 
Cc: PaX Team 
Cc: Peter Zijlstra 
Cc: Russell King 
Cc: Thomas Gleixner 
Cc: kernel-harden...@lists.openwall.com
Cc: linux-arch 
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1455748879-21872-8-git-send-email-keesc...@chromium.org
Signed-off-by: Ingo Molnar 
---
 arch/arm/vdso/vdso.S | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/arm/vdso/vdso.S b/arch/arm/vdso/vdso.S
index b2b97e3..a62a7b6 100644
--- a/arch/arm/vdso/vdso.S
+++ b/arch/arm/vdso/vdso.S
@@ -23,9 +23,8 @@
 #include 
 #include 
 
-   __PAGE_ALIGNED_DATA
-
.globl vdso_start, vdso_end
+   .section .data..ro_after_init
.balign PAGE_SIZE
 vdso_start:
.incbin "arch/arm/vdso/vdso.so"


[tip:mm/readonly] x86/mm: Always enable CONFIG_DEBUG_RODATA and remove the Kconfig option

2016-02-23 Thread tip-bot for Kees Cook
Commit-ID:  9ccaf77cf05915f51231d158abfd5448aedde758
Gitweb: http://git.kernel.org/tip/9ccaf77cf05915f51231d158abfd5448aedde758
Author: Kees Cook 
AuthorDate: Wed, 17 Feb 2016 14:41:14 -0800
Committer:  Ingo Molnar 
CommitDate: Mon, 22 Feb 2016 08:51:38 +0100

x86/mm: Always enable CONFIG_DEBUG_RODATA and remove the Kconfig option

This removes the CONFIG_DEBUG_RODATA option and makes it always enabled.

This simplifies the code and also makes it clearer that read-only mapped
memory is just as fundamental a security feature in kernel-space as it is
in user-space.

Suggested-by: Ingo Molnar 
Signed-off-by: Kees Cook 
Cc: Andy Lutomirski 
Cc: Arnd Bergmann 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: David Brown 
Cc: Denys Vlasenko 
Cc: Emese Revfy 
Cc: H. Peter Anvin 
Cc: Linus Torvalds 
Cc: Mathias Krause 
Cc: Michael Ellerman 
Cc: PaX Team 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: kernel-harden...@lists.openwall.com
Cc: linux-arch 
Link: 
http://lkml.kernel.org/r/1455748879-21872-4-git-send-email-keesc...@chromium.org
Signed-off-by: Ingo Molnar 
---
 arch/x86/Kconfig  |  3 +++
 arch/x86/Kconfig.debug| 18 +++---
 arch/x86/include/asm/cacheflush.h |  5 -
 arch/x86/include/asm/kvm_para.h   |  7 ---
 arch/x86/include/asm/sections.h   |  2 +-
 arch/x86/kernel/ftrace.c  |  6 +++---
 arch/x86/kernel/kgdb.c|  8 ++--
 arch/x86/kernel/test_nx.c |  2 --
 arch/x86/kernel/test_rodata.c |  2 +-
 arch/x86/kernel/vmlinux.lds.S | 25 +++--
 arch/x86/mm/init_32.c |  3 ---
 arch/x86/mm/init_64.c |  3 ---
 arch/x86/mm/pageattr.c|  2 +-
 13 files changed, 25 insertions(+), 61 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index c46662f..b105105 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -303,6 +303,9 @@ config ARCH_SUPPORTS_UPROBES
 config FIX_EARLYCON_MEM
def_bool y
 
+config DEBUG_RODATA
+   def_bool y
+
 config PGTABLE_LEVELS
int
default 4 if X86_64
diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
index 9b18ed9..7816b7b 100644
--- a/arch/x86/Kconfig.debug
+++ b/arch/x86/Kconfig.debug
@@ -74,28 +74,16 @@ config EFI_PGT_DUMP
  issues with the mapping of the EFI runtime regions into that
  table.
 
-config DEBUG_RODATA
-   bool "Write protect kernel read-only data structures"
-   default y
-   depends on DEBUG_KERNEL
-   ---help---
- Mark the kernel read-only data as write-protected in the pagetables,
- in order to catch accidental (and incorrect) writes to such const
- data. This is recommended so that we can catch kernel bugs sooner.
- If in doubt, say "Y".
-
 config DEBUG_RODATA_TEST
-   bool "Testcase for the DEBUG_RODATA feature"
-   depends on DEBUG_RODATA
+   bool "Testcase for the marking rodata read-only"
default y
---help---
- This option enables a testcase for the DEBUG_RODATA
- feature as well as for the change_page_attr() infrastructure.
+ This option enables a testcase for the setting rodata read-only
+ as well as for the change_page_attr() infrastructure.
  If in doubt, say "N"
 
 config DEBUG_WX
bool "Warn on W+X mappings at boot"
-   depends on DEBUG_RODATA
select X86_PTDUMP_CORE
---help---
  Generate a warning if any W+X mappings are found at boot.
diff --git a/arch/x86/include/asm/cacheflush.h 
b/arch/x86/include/asm/cacheflush.h
index c8cff75..61518cf 100644
--- a/arch/x86/include/asm/cacheflush.h
+++ b/arch/x86/include/asm/cacheflush.h
@@ -91,15 +91,10 @@ void clflush_cache_range(void *addr, unsigned int size);
 
 #define mmio_flush_range(addr, size) clflush_cache_range(addr, size)
 
-#ifdef CONFIG_DEBUG_RODATA
 extern const int rodata_test_data;
 extern int kernel_set_to_readonly;
 void set_kernel_text_rw(void);
 void set_kernel_text_ro(void);
-#else
-static inline void set_kernel_text_rw(void) { }
-static inline void set_kernel_text_ro(void) { }
-#endif
 
 #ifdef CONFIG_DEBUG_RODATA_TEST
 int rodata_test(void);
diff --git a/arch/x86/include/asm/kvm_para.h b/arch/x86/include/asm/kvm_para.h
index c1adf33..bc62e7c 100644
--- a/arch/x86/include/asm/kvm_para.h
+++ b/arch/x86/include/asm/kvm_para.h
@@ -17,15 +17,8 @@ static inline bool kvm_check_and_clear_guest_paused(void)
 }
 #endif /* CONFIG_KVM_GUEST */
 
-#ifdef CONFIG_DEBUG_RODATA
 #define KVM_HYPERCALL \
 ALTERNATIVE(".byte 0x0f,0x01,0xc1", ".byte 0x0f,0x01,0xd9", 
X86_FEATURE_VMMCALL)
-#else
-/* On AMD processors, vmcall will generate a trap that we will
- * then rewrite to the appropriate instruction.
- */
-#define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1"
-#endif
 
 /* For KVM hypercalls, a three-byte sequence of either the vmcall or the 
vmmcall
  * instruction.  The hypervisor may replace it with something else but only the
diff --git a/arch/x86/include/asm/sect

[PATCH 4/5] ARCv2: Elide sending new cross core intr if receiver didn't ack prev

2016-02-23 Thread Vineet Gupta
ARConnect/MCIP IPI sending has a retry-wait loop in case caller had
not seen a previous such interrupt. Turns out that it is not needed at
all. Linux cross core calling allows coalescing multiple IPIs to same
receiver - it is fine as long as there is one.

This logic is built into upper layer already, at a higher level of
abstraction. ipi_send_msg_one() sets the actual msg payload, but it only
calls MCIP IPI sending if msg holder was empty (using
atomic-set-new-and-get-old construct). Thus it is unlikely that the
retry-wait looping was ever getting exercised at all.

Cc: Chuck Jordan 
Cc: Peter Zijlstra 
Signed-off-by: Vineet Gupta 
---
 arch/arc/kernel/mcip.c | 27 ++-
 1 file changed, 10 insertions(+), 17 deletions(-)

diff --git a/arch/arc/kernel/mcip.c b/arch/arc/kernel/mcip.c
index e30d5d428330..7afc3c703ed1 100644
--- a/arch/arc/kernel/mcip.c
+++ b/arch/arc/kernel/mcip.c
@@ -40,26 +40,19 @@ static void mcip_ipi_send(int cpu)
return;
}
 
+   raw_spin_lock_irqsave(&mcip_lock, flags);
+
/*
-* NOTE: We must spin here if the other cpu hasn't yet
-* serviced a previous message. This can burn lots
-* of time, but we MUST follows this protocol or
-* ipi messages can be lost!!!
-* Also, we must release the lock in this loop because
-* the other side may get to this same loop and not
-* be able to ack -- thus causing deadlock.
+* If receiver already has a pending interrupt, elide sending this one.
+* Linux cross core calling works well with concurrent IPIs
+* coalesced into one
+* see arch/arc/kernel/smp.c: ipi_send_msg_one()
 */
+   __mcip_cmd(CMD_INTRPT_READ_STATUS, cpu);
+   ipi_was_pending = read_aux_reg(ARC_REG_MCIP_READBACK);
+   if (!ipi_was_pending)
+   __mcip_cmd(CMD_INTRPT_GENERATE_IRQ, cpu);
 
-   do {
-   raw_spin_lock_irqsave(&mcip_lock, flags);
-   __mcip_cmd(CMD_INTRPT_READ_STATUS, cpu);
-   ipi_was_pending = read_aux_reg(ARC_REG_MCIP_READBACK);
-   if (ipi_was_pending == 0)
-   break; /* break out but keep lock */
-   raw_spin_unlock_irqrestore(&mcip_lock, flags);
-   } while (1);
-
-   __mcip_cmd(CMD_INTRPT_GENERATE_IRQ, cpu);
raw_spin_unlock_irqrestore(&mcip_lock, flags);
 
 #ifdef CONFIG_ARC_IPI_DBG
-- 
2.5.0



[PATCH 1/5] ARCv2: SMP: Emulate IPI to self using software triggered interrupt

2016-02-23 Thread Vineet Gupta
ARConnect/MCIP Inter-Core-Interrupt module can't send interrupt to
local core. So use core intc capability to trigger software
interrupt to self, using an unsued IRQ #21.

This showed up as csd deadlock with LTP trace_sched on a dual core
system. This test acts as scheduler fuzzer, triggering all sorts of
schedulting activity. Trouble starts with IPI to self, which doesn't get
delivered (effectively lost due to H/w capability), but the msg intended
to be sent remain enqueued in per-cpu @ipi_data.

All subsequent IPIs to this core from other cores get elided due to the
IPI coalescing optimization in ipi_send_msg_one() where a pending msg
implies an IPI already sent and assumes other core is yet to ack it.
After the elided IPI, other core simply goes into csd_lock_wait()
but never comes out as this core never sees the interrupt.

Fixes STAR 9001008624

Cc: Peter Zijlstra 
Cc: [4.2]
Signed-off-by: Vineet Gupta 
---
 arch/arc/include/asm/irqflags-arcv2.h | 11 +++
 arch/arc/kernel/mcip.c| 15 +++
 2 files changed, 26 insertions(+)

diff --git a/arch/arc/include/asm/irqflags-arcv2.h 
b/arch/arc/include/asm/irqflags-arcv2.h
index 1fc18ee06cf2..37c2f751eebf 100644
--- a/arch/arc/include/asm/irqflags-arcv2.h
+++ b/arch/arc/include/asm/irqflags-arcv2.h
@@ -22,6 +22,7 @@
 #define AUX_IRQ_CTRL   0x00E
 #define AUX_IRQ_ACT0x043   /* Active Intr across all levels */
 #define AUX_IRQ_LVL_PEND   0x200   /* Pending Intr across all levels */
+#define AUX_IRQ_HINT   0x201   /* For generating Soft Interrupts */
 #define AUX_IRQ_PRIORITY   0x206
 #define ICAUSE 0x40a
 #define AUX_IRQ_SELECT 0x40b
@@ -115,6 +116,16 @@ static inline int arch_irqs_disabled(void)
return arch_irqs_disabled_flags(arch_local_save_flags());
 }
 
+static inline void arc_softirq_trigger(int irq)
+{
+   write_aux_reg(AUX_IRQ_HINT, irq);
+}
+
+static inline void arc_softirq_clear(int irq)
+{
+   write_aux_reg(AUX_IRQ_HINT, 0);
+}
+
 #else
 
 .macro IRQ_DISABLE  scratch
diff --git a/arch/arc/kernel/mcip.c b/arch/arc/kernel/mcip.c
index 002c5fcf8947..9e1bd03b87a6 100644
--- a/arch/arc/kernel/mcip.c
+++ b/arch/arc/kernel/mcip.c
@@ -11,9 +11,12 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
+#define SOFTIRQ_IRQ21
+
 static char smp_cpuinfo_buf[128];
 static int idu_detected;
 
@@ -22,6 +25,7 @@ static DEFINE_RAW_SPINLOCK(mcip_lock);
 static void mcip_setup_per_cpu(int cpu)
 {
smp_ipi_irq_setup(cpu, IPI_IRQ);
+   smp_ipi_irq_setup(cpu, SOFTIRQ_IRQ);
 }
 
 static void mcip_ipi_send(int cpu)
@@ -29,6 +33,12 @@ static void mcip_ipi_send(int cpu)
unsigned long flags;
int ipi_was_pending;
 
+   /* ARConnect can only send IPI to others */
+   if (unlikely(cpu == raw_smp_processor_id())) {
+   arc_softirq_trigger(SOFTIRQ_IRQ);
+   return;
+   }
+
/*
 * NOTE: We must spin here if the other cpu hasn't yet
 * serviced a previous message. This can burn lots
@@ -63,6 +73,11 @@ static void mcip_ipi_clear(int irq)
unsigned long flags;
unsigned int __maybe_unused copy;
 
+   if (unlikely(irq == SOFTIRQ_IRQ)) {
+   arc_softirq_clear(irq);
+   return;
+   }
+
raw_spin_lock_irqsave(&mcip_lock, flags);
 
/* Who sent the IPI */
-- 
2.5.0



[PATCH 2/5] ARC: [intc-compact] Remove IPI setup from ARCompact port

2016-02-23 Thread Vineet Gupta
There is no real ARC700 based SMP SoC so remove IPI definition.
EZChip's SMP ARC700 is going to use a different intc and IPI provider
anyways.

Signed-off-by: Vineet Gupta 
---
 arch/arc/include/asm/irq.h | 1 -
 arch/arc/kernel/intc-compact.c | 3 ---
 2 files changed, 4 deletions(-)

diff --git a/arch/arc/include/asm/irq.h b/arch/arc/include/asm/irq.h
index 4fd7d62a6e30..bc5103637326 100644
--- a/arch/arc/include/asm/irq.h
+++ b/arch/arc/include/asm/irq.h
@@ -16,7 +16,6 @@
 #ifdef CONFIG_ISA_ARCOMPACT
 #define TIMER0_IRQ  3
 #define TIMER1_IRQ  4
-#define IPI_IRQ(NR_CPU_IRQS-1) /* dummy to enable SMP build 
for up hardware */
 #else
 #define TIMER0_IRQ  16
 #define TIMER1_IRQ  17
diff --git a/arch/arc/kernel/intc-compact.c b/arch/arc/kernel/intc-compact.c
index 06bcedf19b62..224d1c3aa9c4 100644
--- a/arch/arc/kernel/intc-compact.c
+++ b/arch/arc/kernel/intc-compact.c
@@ -81,9 +81,6 @@ static int arc_intc_domain_map(struct irq_domain *d, unsigned 
int irq,
 {
switch (irq) {
case TIMER0_IRQ:
-#ifdef CONFIG_SMP
-   case IPI_IRQ:
-#endif
irq_set_chip_and_handler(irq, &onchip_intc, handle_percpu_irq);
break;
default:
-- 
2.5.0



Re: [PATCH 00/61] gpio: Add and use devm_gpiochip_add_data()

2016-02-23 Thread Laxman Dewangan


On Monday 22 February 2016 08:14 PM, Linus Walleij wrote:

On Mon, Feb 22, 2016 at 3:07 PM, Laxman Dewangan  wrote:


Add resource management APIs for gpiochip_add_data() and
gpiochip_remove() and use these APIs from different HW drivers.

This is based on discussion on patch to use the new APIs.
 gpio: Add devm_ apis for gpio_chip_add and remove

Awesome!

Do you have a git I can just pull these off so I don't have to apply
then all one-by-one?



Nop, I do not have the git repo for sharing as of now at this time.
Trying to learn to how to create.



[PATCH 3/5] ARCv2: SMP: Push IPI_IRQ into IPI provider

2016-02-23 Thread Vineet Gupta
Signed-off-by: Vineet Gupta 
---
 arch/arc/include/asm/irq.h | 1 -
 arch/arc/kernel/mcip.c | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arc/include/asm/irq.h b/arch/arc/include/asm/irq.h
index bc5103637326..49014f0ef36d 100644
--- a/arch/arc/include/asm/irq.h
+++ b/arch/arc/include/asm/irq.h
@@ -19,7 +19,6 @@
 #else
 #define TIMER0_IRQ  16
 #define TIMER1_IRQ  17
-#define IPI_IRQ 19
 #endif
 
 #include 
diff --git a/arch/arc/kernel/mcip.c b/arch/arc/kernel/mcip.c
index 9e1bd03b87a6..e30d5d428330 100644
--- a/arch/arc/kernel/mcip.c
+++ b/arch/arc/kernel/mcip.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 
+#define IPI_IRQ19
 #define SOFTIRQ_IRQ21
 
 static char smp_cpuinfo_buf[128];
-- 
2.5.0



[PATCH 5/5] ARC: SMP: No need for CONFIG_ARC_IPI_DBG

2016-02-23 Thread Vineet Gupta
This was more relevant during SMP bringup.

The warning for bogus msg better be visible always.

Signed-off-by: Vineet Gupta 
---
 arch/arc/Kconfig   | 8 
 arch/arc/kernel/mcip.c | 9 +
 arch/arc/kernel/smp.c  | 3 ---
 3 files changed, 1 insertion(+), 19 deletions(-)

diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig
index 4abc81907071..8a188bc1786a 100644
--- a/arch/arc/Kconfig
+++ b/arch/arc/Kconfig
@@ -532,14 +532,6 @@ config ARC_DBG_TLB_MISS_COUNT
  Counts number of I and D TLB Misses and exports them via Debugfs
  The counters can be cleared via Debugfs as well
 
-if SMP
-
-config ARC_IPI_DBG
-   bool "Debug Inter Core interrupts"
-   default n
-
-endif
-
 endif
 
 config ARC_UBOOT_SUPPORT
diff --git a/arch/arc/kernel/mcip.c b/arch/arc/kernel/mcip.c
index 7afc3c703ed1..7b4af70ffd18 100644
--- a/arch/arc/kernel/mcip.c
+++ b/arch/arc/kernel/mcip.c
@@ -65,7 +65,6 @@ static void mcip_ipi_clear(int irq)
 {
unsigned int cpu, c;
unsigned long flags;
-   unsigned int __maybe_unused copy;
 
if (unlikely(irq == SOFTIRQ_IRQ)) {
arc_softirq_clear(irq);
@@ -77,7 +76,7 @@ static void mcip_ipi_clear(int irq)
/* Who sent the IPI */
__mcip_cmd(CMD_INTRPT_CHECK_SOURCE, 0);
 
-   copy = cpu = read_aux_reg(ARC_REG_MCIP_READBACK);   /* 1,2,4,8... */
+   cpu = read_aux_reg(ARC_REG_MCIP_READBACK);  /* 1,2,4,8... */
 
/*
 * In rare case, multiple concurrent IPIs sent to same target can
@@ -91,12 +90,6 @@ static void mcip_ipi_clear(int irq)
} while (cpu);
 
raw_spin_unlock_irqrestore(&mcip_lock, flags);
-
-#ifdef CONFIG_ARC_IPI_DBG
-   if (c != __ffs(copy))
-   pr_info("IPIs from %x coalesced to %x\n",
-   copy, raw_smp_processor_id());
-#endif
 }
 
 static void mcip_probe_n_setup(void)
diff --git a/arch/arc/kernel/smp.c b/arch/arc/kernel/smp.c
index ef6e9e15b82a..424e937da5c8 100644
--- a/arch/arc/kernel/smp.c
+++ b/arch/arc/kernel/smp.c
@@ -336,11 +336,8 @@ irqreturn_t do_IPI(int irq, void *dev_id)
int rc;
 
rc = __do_IPI(msg);
-#ifdef CONFIG_ARC_IPI_DBG
-   /* IPI received but no valid @msg */
if (rc)
pr_info("IPI with bogus msg %ld in %ld\n", msg, copy);
-#endif
pending &= ~(1U << msg);
} while (pending);
 
-- 
2.5.0



Re: [PATCH v9 2/6] clk: hisilicon: add CRG driver for hi3519 soc

2016-02-23 Thread Philipp Zabel
Hi,

Am Montag, den 22.02.2016, 15:47 +0800 schrieb Jiancheng Xue:
> The CRG(Clock and Reset Generator) block provides clock
> and reset signals for other modules in hi3519 soc.
> 
> Signed-off-by: Jiancheng Xue 
> Acked-by: Rob Herring 
[...]
> diff --git a/drivers/clk/hisilicon/reset.c b/drivers/clk/hisilicon/reset.c
> new file mode 100644
> index 000..50e00e7
> --- /dev/null
> +++ b/drivers/clk/hisilicon/reset.c
> @@ -0,0 +1,124 @@
> +/*
> + * Hisilicon Reset Controller Driver
> + *
> + * Copyright (c) 2015-2016 HiSilicon Technologies Co., Ltd.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see .
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define  HISI_RESET_BIT_MASK 0x1f
> +#define  HISI_RESET_OFFSET_SHIFT 8
> +#define  HISI_RESET_OFFSET_MASK  0x00
> +
> +struct hisi_reset_controller {
> + spinlock_t  lock;
> + void __iomem*membase;
> + struct reset_controller_dev rcdev;
> +};
> +
> +
> +#define to_hisi_reset_controller(rcdev)  \
> + container_of(rcdev, struct hisi_reset_controller, rcdev)
> +
> +static int hisi_reset_of_xlate(struct reset_controller_dev *rcdev,
> + const struct of_phandle_args *reset_spec)
> +{
> + u32 offset;
> + u8 bit;
> +
> + if (WARN_ON(reset_spec->args_count != rcdev->of_reset_n_cells))
> + return -EINVAL;

This check now has been moved to the core in e64f5026 ("reset: Move
DT cell size check to the core"). It is not necessary anymore to check
this in the .of_xlate callback.

> + offset = (reset_spec->args[0] << HISI_RESET_OFFSET_SHIFT)
> + & HISI_RESET_OFFSET_MASK;
> + bit = reset_spec->args[1] & HISI_RESET_BIT_MASK;
> + return (offset | bit);
> +}
> +
> +static int hisi_reset_assert(struct reset_controller_dev *rcdev,
> +   unsigned long id)
> +{
> + struct hisi_reset_controller *rstc = to_hisi_reset_controller(rcdev);
> + unsigned long flags;
> + u32 offset, reg;
> + u8 bit;
> +
> + offset = (id & HISI_RESET_OFFSET_MASK) >> HISI_RESET_OFFSET_SHIFT;
> + bit = id & HISI_RESET_BIT_MASK;
> +
> + spin_lock_irqsave(&rstc->lock, flags);
> +
> + reg = readl(rstc->membase + offset);
> + writel(reg | BIT(bit), rstc->membase + offset);
> +
> + spin_unlock_irqrestore(&rstc->lock, flags);
> +
> + return 0;
> +}
> +
> +static int hisi_reset_deassert(struct reset_controller_dev *rcdev,
> + unsigned long id)
> +{
> + struct hisi_reset_controller *rstc = to_hisi_reset_controller(rcdev);
> + unsigned long flags;
> + u32 offset, reg;
> + u8 bit;
> +
> + offset = (id & HISI_RESET_OFFSET_MASK) >> HISI_RESET_OFFSET_SHIFT;
> + bit = id & HISI_RESET_BIT_MASK;
> +
> + spin_lock_irqsave(&rstc->lock, flags);
> +
> + reg = readl(rstc->membase + offset);
> + writel(reg & ~BIT(bit), rstc->membase + offset);
> +
> + spin_unlock_irqrestore(&rstc->lock, flags);
> +
> + return 0;
> +}
> +
> +static struct reset_control_ops hisi_reset_ops = {
> + .assert = hisi_reset_assert,
> + .deassert   = hisi_reset_deassert,
> +};

These can be made const after commit 203d4f347d86 ("reset: Make
reset_control_ops const") is merged. Since this is to be merged through
the clock tree, both change could be made later.

For the reset driver part,
Acked-by: Philipp Zabel 

regards
Philipp



[PATCH 0/5] ARC IPI related fix

2016-02-23 Thread Vineet Gupta
Hi,

This cam eout of debugging a csd deadlock on ARC.
The fix itself is 1/5, rest of patches are additional improvements,
optimizations while we are at it.

Thx,
-Vineet

Vineet Gupta (5):
  ARCv2: SMP: Emulate IPI to self using software triggered interrupt
  ARC: [intc-compact] Remove IPI setup from ARCompact port
  ARCv2: SMP: Push IPI_IRQ into IPI provider
  ARCv2: Elide sending new cross core intr if receiver didn't ack prev
  ARC: SMP: No need for CONFIG_ARC_IPI_DBG

 arch/arc/Kconfig  |  8 --
 arch/arc/include/asm/irq.h|  2 --
 arch/arc/include/asm/irqflags-arcv2.h | 11 
 arch/arc/kernel/intc-compact.c|  3 --
 arch/arc/kernel/mcip.c| 52 ++-
 arch/arc/kernel/smp.c |  3 --
 6 files changed, 38 insertions(+), 41 deletions(-)

-- 
2.5.0



Re: [PATCH] arch/powerpc: use BUILD_BUG() when detect unfit {cmp}xchg, size

2016-02-23 Thread Boqun Feng
On Tue, Feb 23, 2016 at 04:45:16PM +0800, Pan Xinhui wrote:
> From: pan xinhui 
> 
> __xchg_called_with_bad_pointer() can't tell us what codes use {cmp}xchg
> in incorrect way.  And no error will be reported until the link stage.
> To fix such kinds of issues in a easy way, we use BUILD_BUG() here.
> 
> Signed-off-by: pan xinhui 
> ---
>  arch/powerpc/include/asm/cmpxchg.h | 19 +--
>  1 file changed, 5 insertions(+), 14 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/cmpxchg.h 
> b/arch/powerpc/include/asm/cmpxchg.h
> index d1a8d93..20c0a30 100644
> --- a/arch/powerpc/include/asm/cmpxchg.h
> +++ b/arch/powerpc/include/asm/cmpxchg.h
> @@ -5,6 +5,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  /*
>   * Atomic exchange
> @@ -92,12 +93,6 @@ __xchg_u64_local(volatile void *p, unsigned long val)
>  }
>  #endif
>  
> -/*
> - * This function doesn't exist, so you'll get a linker error
> - * if something tries to do an invalid xchg().
> - */
> -extern void __xchg_called_with_bad_pointer(void);
> -
>  static __always_inline unsigned long
>  __xchg(volatile void *ptr, unsigned long x, unsigned int size)
>  {
> @@ -109,7 +104,7 @@ __xchg(volatile void *ptr, unsigned long x, unsigned int 
> size)
>   return __xchg_u64(ptr, x);
>  #endif
>   }
> - __xchg_called_with_bad_pointer();
> + BUILD_BUG();

Maybe we can use BUILD_BUG_ON_MSG(1, "Unsupported size for xchg"), which
could provide more information.

With or without this verbosity:

Acked-by: Boqun Feng 


Regards,
Boqun

>   return x;
>  }
>  
> @@ -124,7 +119,7 @@ __xchg_local(volatile void *ptr, unsigned long x, 
> unsigned int size)
>   return __xchg_u64_local(ptr, x);
>  #endif
>   }
> - __xchg_called_with_bad_pointer();
> + BUILD_BUG();
>   return x;
>  }
>  #define xchg(ptr,x)   \
> @@ -235,10 +230,6 @@ __cmpxchg_u64_local(volatile unsigned long *p, unsigned 
> long old,
>  }
>  #endif
>  
> -/* This function doesn't exist, so you'll get a linker error
> -   if something tries to do an invalid cmpxchg().  */
> -extern void __cmpxchg_called_with_bad_pointer(void);
> -
>  static __always_inline unsigned long
>  __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new,
> unsigned int size)
> @@ -251,7 +242,7 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned 
> long new,
>   return __cmpxchg_u64(ptr, old, new);
>  #endif
>   }
> - __cmpxchg_called_with_bad_pointer();
> + BUILD_BUG();
>   return old;
>  }
>  
> @@ -267,7 +258,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, 
> unsigned long new,
>   return __cmpxchg_u64_local(ptr, old, new);
>  #endif
>   }
> - __cmpxchg_called_with_bad_pointer();
> + BUILD_BUG();
>   return old;
>  }
>  
> -- 
> 2.5.0
> 


signature.asc
Description: PGP signature


[tip:x86/debug] watchdog/hpwdt: Create stack frame in asminline_call()

2016-02-23 Thread tip-bot for Josh Poimboeuf
Commit-ID:  a216c875a01520896c7ed9ea43779a3da4103ee9
Gitweb: http://git.kernel.org/tip/a216c875a01520896c7ed9ea43779a3da4103ee9
Author: Josh Poimboeuf 
AuthorDate: Thu, 21 Jan 2016 16:49:31 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:04:00 +0100

watchdog/hpwdt: Create stack frame in asminline_call()

asminline_call() is a callable non-leaf function which doesn't honor
CONFIG_FRAME_POINTER, which can result in bad stack traces.

Create a stack frame when CONFIG_FRAME_POINTER is enabled.

Signed-off-by: Josh Poimboeuf 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Bernd Petrovitsch 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chris J Arges 
Cc: Denys Vlasenko 
Cc: Guenter Roeck 
Cc: H. Peter Anvin 
Cc: Jiri Slaby 
Cc: Linus Torvalds 
Cc: Michal Marek 
Cc: Namhyung Kim 
Cc: Pedro Alves 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: Wim Van Sebroeck 
Cc: linux-watch...@vger.kernel.org
Cc: live-patch...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/60de3cfb6f16d413bfb923036cc87fec132df735.1453405861.git.jpoim...@redhat.com
Signed-off-by: Ingo Molnar 
---
 drivers/watchdog/hpwdt.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/watchdog/hpwdt.c b/drivers/watchdog/hpwdt.c
index 92443c3..90016db 100644
--- a/drivers/watchdog/hpwdt.c
+++ b/drivers/watchdog/hpwdt.c
@@ -353,10 +353,10 @@ static int detect_cru_service(void)
 
 asm(".text  \n\t"
 ".align 4   \n\t"
-".globl asminline_call \n"
+".globl asminline_call \n\t"
+".type asminline_call, @function \n\t"
 "asminline_call:\n\t"
-"pushq  %rbp\n\t"
-"movq   %rsp, %rbp  \n\t"
+FRAME_BEGIN
 "pushq  %rax\n\t"
 "pushq  %rbx\n\t"
 "pushq  %rdx\n\t"
@@ -386,7 +386,7 @@ asm(".text  \n\t"
 "popq   %rdx\n\t"
 "popq   %rbx\n\t"
 "popq   %rax\n\t"
-"leave  \n\t"
+FRAME_END
 "ret\n\t"
 ".previous");
 


[tip:x86/debug] x86/xen: Add stack frame dependency to hypercall inline asm calls

2016-02-23 Thread tip-bot for Josh Poimboeuf
Commit-ID:  6d2d32c1fdcbf0e054f555fc855b81047734ad3f
Gitweb: http://git.kernel.org/tip/6d2d32c1fdcbf0e054f555fc855b81047734ad3f
Author: Josh Poimboeuf 
AuthorDate: Thu, 21 Jan 2016 16:49:09 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:03:54 +0100

x86/xen: Add stack frame dependency to hypercall inline asm calls

If a hypercall is inlined at the beginning of a function, gcc can insert
the call instruction before setting up a stack frame, which breaks frame
pointer convention if CONFIG_FRAME_POINTER is enabled and can result in
a bad stack trace.

Force a stack frame to be created if CONFIG_FRAME_POINTER is enabled by
listing the stack pointer as an output operand for the hypercall inline
asm statements.

Signed-off-by: Josh Poimboeuf 
Reviewed-by: David Vrabel 
Reviewed-by: Borislav Petkov 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Bernd Petrovitsch 
Cc: Boris Ostrovsky 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chris J Arges 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Jiri Slaby 
Cc: Konrad Rzeszutek Wilk 
Cc: Linus Torvalds 
Cc: Michal Marek 
Cc: Namhyung Kim 
Cc: Pedro Alves 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: live-patch...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/c6face5a46713108bded9c4c103637222abc4528.1453405861.git.jpoim...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/include/asm/xen/hypercall.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/xen/hypercall.h 
b/arch/x86/include/asm/xen/hypercall.h
index 3bcdcc8..a12a047 100644
--- a/arch/x86/include/asm/xen/hypercall.h
+++ b/arch/x86/include/asm/xen/hypercall.h
@@ -110,9 +110,10 @@ extern struct { char _entry[32]; } hypercall_page[];
register unsigned long __arg2 asm(__HYPERCALL_ARG2REG) = __arg2; \
register unsigned long __arg3 asm(__HYPERCALL_ARG3REG) = __arg3; \
register unsigned long __arg4 asm(__HYPERCALL_ARG4REG) = __arg4; \
-   register unsigned long __arg5 asm(__HYPERCALL_ARG5REG) = __arg5;
+   register unsigned long __arg5 asm(__HYPERCALL_ARG5REG) = __arg5; \
+   register void *__sp asm(_ASM_SP);
 
-#define __HYPERCALL_0PARAM "=r" (__res)
+#define __HYPERCALL_0PARAM "=r" (__res), "+r" (__sp)
 #define __HYPERCALL_1PARAM __HYPERCALL_0PARAM, "+r" (__arg1)
 #define __HYPERCALL_2PARAM __HYPERCALL_1PARAM, "+r" (__arg2)
 #define __HYPERCALL_3PARAM __HYPERCALL_2PARAM, "+r" (__arg3)


[tip:efi/core] x86/efi: Map EFI_MEMORY_{XP,RO} memory region bits to EFI page tables

2016-02-23 Thread tip-bot for Sai Praneeth
Commit-ID:  6d0cc887d571e96f928be83f094322451fd4bf6f
Gitweb: http://git.kernel.org/tip/6d0cc887d571e96f928be83f094322451fd4bf6f
Author: Sai Praneeth 
AuthorDate: Wed, 17 Feb 2016 12:36:05 +
Committer:  Ingo Molnar 
CommitDate: Mon, 22 Feb 2016 08:26:28 +0100

x86/efi: Map EFI_MEMORY_{XP,RO} memory region bits to EFI page tables

Now that we have EFI memory region bits that indicate which regions do
not need execute permission or read/write permission in the page tables,
let's use them.

We also check for EFI_NX_PE_DATA and only enforce the restrictive
mappings if it's present (to allow us to ignore buggy firmware that sets
bits it didn't mean to and to preserve backwards compatibility).

Instead of assuming that firmware would set appropriate attributes in
memory descriptor like EFI_MEMORY_RO for code and EFI_MEMORY_XP for
data, we can expect some firmware out there which might only set *type*
in memory descriptor to be EFI_RUNTIME_SERVICES_CODE or
EFI_RUNTIME_SERVICES_DATA leaving away attribute. This will lead to
improper mappings of EFI runtime regions. In order to avoid it, we check
attribute and type of memory descriptor to update mappings and moreover
Windows works this way.

Signed-off-by: Sai Praneeth Prakhya 
Signed-off-by: Matt Fleming 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Ard Biesheuvel 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Lee, Chun-Yi 
Cc: Linus Torvalds 
Cc: Luis R. Rodriguez 
Cc: Peter Zijlstra 
Cc: Ravi Shankar 
Cc: Ricardo Neri 
Cc: Thomas Gleixner 
Cc: Toshi Kani 
Cc: linux-...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1455712566-16727-13-git-send-email-m...@codeblueprint.co.uk
Signed-off-by: Ingo Molnar 
---
 arch/x86/include/asm/efi.h |  2 +-
 arch/x86/platform/efi/efi.c|  9 +++--
 arch/x86/platform/efi/efi_32.c |  2 +-
 arch/x86/platform/efi/efi_64.c | 45 ++
 4 files changed, 50 insertions(+), 8 deletions(-)

diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h
index 8fd9e63..7bb206f 100644
--- a/arch/x86/include/asm/efi.h
+++ b/arch/x86/include/asm/efi.h
@@ -141,7 +141,7 @@ extern int __init efi_setup_page_tables(unsigned long 
pa_memmap, unsigned num_pa
 extern void __init efi_cleanup_page_tables(unsigned long pa_memmap, unsigned 
num_pages);
 extern void __init old_map_region(efi_memory_desc_t *md);
 extern void __init runtime_code_page_mkexec(void);
-extern void __init efi_runtime_mkexec(void);
+extern void __init efi_runtime_update_mappings(void);
 extern void __init efi_dump_pagetable(void);
 extern void __init efi_apply_memmap_quirks(void);
 extern int __init efi_reuse_config(u64 tables, int nr_tables);
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index e80826e..994a7df8 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -934,7 +934,6 @@ static void __init __efi_enter_virtual_mode(void)
}
 
efi_sync_low_kernel_mappings();
-   efi_dump_pagetable();
 
if (efi_is_native()) {
status = phys_efi_set_virtual_address_map(
@@ -972,7 +971,13 @@ static void __init __efi_enter_virtual_mode(void)
 
efi.set_virtual_address_map = NULL;
 
-   efi_runtime_mkexec();
+   /*
+* Apply more restrictive page table mapping attributes now that
+* SVAM() has been called and the firmware has performed all
+* necessary relocation fixups for the new virtual addresses.
+*/
+   efi_runtime_update_mappings();
+   efi_dump_pagetable();
 
/*
 * We mapped the descriptor array into the EFI pagetable above
diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
index 58d669b..338402b 100644
--- a/arch/x86/platform/efi/efi_32.c
+++ b/arch/x86/platform/efi/efi_32.c
@@ -90,7 +90,7 @@ void __init efi_call_phys_epilog(pgd_t *save_pgd)
__flush_tlb_all();
 }
 
-void __init efi_runtime_mkexec(void)
+void __init efi_runtime_update_mappings(void)
 {
if (__supported_pte_mask & _PAGE_NX)
runtime_code_page_mkexec();
diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
index b0965b2..40d2f44 100644
--- a/arch/x86/platform/efi/efi_64.c
+++ b/arch/x86/platform/efi/efi_64.c
@@ -393,13 +393,50 @@ void __init parse_efi_setup(u64 phys_addr, u32 data_len)
efi_setup = phys_addr + sizeof(struct setup_data);
 }
 
-void __init efi_runtime_mkexec(void)
+void __init efi_runtime_update_mappings(void)
 {
-   if (!efi_enabled(EFI_OLD_MEMMAP))
+   unsigned long pfn;
+   pgd_t *pgd = efi_pgd;
+   efi_memory_desc_t *md;
+   void *p;
+
+   if (efi_enabled(EFI_OLD_MEMMAP)) {
+   if (__supported_pte_mask & _PAGE_NX)
+   runtime_code_page_mkexec();
+   return;
+   }
+
+   if (!efi_enabled(EFI_NX_PE_DATA))
return;
 
-   if (__supported_pte_mask & _PAGE_NX)
- 

Re: [PATCH] ARM: dts: add support for gpio buttons for exynos5422-odroidxu3

2016-02-23 Thread Anand Moon
Hi Krzysztof,

On 23 February 2016 at 14:03, Krzysztof Kozlowski
 wrote:
> On 23.02.2016 17:21, Krzysztof Kozlowski wrote:
>> On 23.02.2016 17:01, Anand Moon wrote:
>>> Add support for gpio-based button on Odroid-XU3 boards
>>> for reboot/poweroff feature.
>>>
>>> Signed-off-by: Anand Moon 
>>> ---
>>> changes rebase based on linux next-20160222.
>>>
>>> Tested on Odroid-XU4
>>>
>>> dmesg output.
>>> [3.286068] of_get_named_gpiod_flags: parsed 'gpios' property of node 
>>> '/gpio_keys/power_key[0]' - status (0)
>>> [3.286206] gpio-11 (power key): gpiod_set_debounce: missing set() or 
>>> set_debounce() operations
>>> [3.286600] input: gpio_keys as /devices/platform/gpio_keys/input/input0
>>> ---
>>>  arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi | 22 
>>> ++
>>>  1 file changed, 22 insertions(+)
>>>
>>> diff --git a/arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi 
>>> b/arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi
>>> index 1bd507b..db9770b 100644
>>> --- a/arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi
>>> +++ b/arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi
>>> @@ -11,6 +11,7 @@
>>>  */
>>>
>>>  #include 
>>> +#include 
>>>  #include 
>>>  #include 
>>>  #include 
>>> @@ -54,6 +55,22 @@
>>>  #cooling-cells = <2>;
>>>  cooling-levels = <0 130 170 230>;
>>>  };
>>> +
>>> +gpio_keys {
>>> +compatible = "gpio-keys";
>>> +pinctrl-names = "default";
>>> +pinctrl-0 = <&gpio_power_key>;
>>> +
>>> +power_key {
>>> +interrupt-parent = <&gpx0>;
>>> +interrupts = <3 IRQ_TYPE_NONE>;
>>
>> Hmmm why you specify the interrupts?
>>
>>> +gpios = <&gpx0 3 GPIO_ACTIVE_LOW>;
>
> Please, explain it to me. The SW2 key is connected to PWRON of PMIC.
> However you are adding a GPIO key for external interrupt source 3
> (XE.INT3)... which comes from PMIC's ONOB.
>
> It's interesting how does it work? The PMIC will generate ONOB
> interrupt on PWRON low->high change (when PWRHOLD is high)?
>
> Best regards,
> Krzysztof
>

I have re-base my changes on HK dts.
I could not find much details for the schematic diagram.
I don't know much low level detains on this.

How dose this works: This changes will initial the shudown/reboot on Ubuntu.
I have also tested this similar feature on Odroid U3.

Best Regards.
-Anand Moon


[tip:efi/core] x86/mm/pat: Don't implicitly allow _PAGE_RW in kernel_map_pages_in_pgd()

2016-02-23 Thread tip-bot for Sai Praneeth
Commit-ID:  15f003d20782a4079e078d16df57081ebd1fc150
Gitweb: http://git.kernel.org/tip/15f003d20782a4079e078d16df57081ebd1fc150
Author: Sai Praneeth 
AuthorDate: Wed, 17 Feb 2016 12:36:04 +
Committer:  Ingo Molnar 
CommitDate: Mon, 22 Feb 2016 08:26:28 +0100

x86/mm/pat: Don't implicitly allow _PAGE_RW in kernel_map_pages_in_pgd()

As part of the preparation for the EFI_MEMORY_RO flag added in the UEFI
2.5 specification, we need the ability to map pages in kernel page
tables without _PAGE_RW being set.

Modify kernel_map_pages_in_pgd() to require its callers to pass _PAGE_RW
if the pages need to be mapped read/write. Otherwise, we'll map the
pages as read-only.

Signed-off-by: Sai Praneeth Prakhya 
Signed-off-by: Matt Fleming 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Ard Biesheuvel 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Hugh Dickins 
Cc: Lee, Chun-Yi 
Cc: Linus Torvalds 
Cc: Luis R. Rodriguez 
Cc: Peter Zijlstra 
Cc: Ravi Shankar 
Cc: Ricardo Neri 
Cc: Thomas Gleixner 
Cc: Toshi Kani 
Cc: linux-...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1455712566-16727-12-git-send-email-m...@codeblueprint.co.uk
Signed-off-by: Ingo Molnar 
---
 arch/x86/mm/pageattr.c | 3 +++
 arch/x86/platform/efi/efi_64.c | 8 
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
index bf312da..14c38ae 100644
--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -1971,6 +1971,9 @@ int kernel_map_pages_in_pgd(pgd_t *pgd, u64 pfn, unsigned 
long address,
if (!(page_flags & _PAGE_NX))
cpa.mask_clr = __pgprot(_PAGE_NX);
 
+   if (!(page_flags & _PAGE_RW))
+   cpa.mask_clr = __pgprot(_PAGE_RW);
+
cpa.mask_set = __pgprot(_PAGE_PRESENT | page_flags);
 
retval = __change_page_attr_set_clr(&cpa, 0);
diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
index b492521..b0965b2 100644
--- a/arch/x86/platform/efi/efi_64.c
+++ b/arch/x86/platform/efi/efi_64.c
@@ -233,7 +233,7 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, 
unsigned num_pages)
 * phys_efi_set_virtual_address_map().
 */
pfn = pa_memmap >> PAGE_SHIFT;
-   if (kernel_map_pages_in_pgd(pgd, pfn, pa_memmap, num_pages, _PAGE_NX)) {
+   if (kernel_map_pages_in_pgd(pgd, pfn, pa_memmap, num_pages, _PAGE_NX | 
_PAGE_RW)) {
pr_err("Error ident-mapping new memmap (0x%lx)!\n", pa_memmap);
return 1;
}
@@ -262,7 +262,7 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, 
unsigned num_pages)
pfn = md->phys_addr >> PAGE_SHIFT;
npages = md->num_pages;
 
-   if (kernel_map_pages_in_pgd(pgd, pfn, md->phys_addr, npages, 
0)) {
+   if (kernel_map_pages_in_pgd(pgd, pfn, md->phys_addr, npages, 
_PAGE_RW)) {
pr_err("Failed to map 1:1 memory\n");
return 1;
}
@@ -279,7 +279,7 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, 
unsigned num_pages)
text = __pa(_text);
pfn = text >> PAGE_SHIFT;
 
-   if (kernel_map_pages_in_pgd(pgd, pfn, text, npages, 0)) {
+   if (kernel_map_pages_in_pgd(pgd, pfn, text, npages, _PAGE_RW)) {
pr_err("Failed to map kernel text 1:1\n");
return 1;
}
@@ -294,7 +294,7 @@ void __init efi_cleanup_page_tables(unsigned long 
pa_memmap, unsigned num_pages)
 
 static void __init __map_region(efi_memory_desc_t *md, u64 va)
 {
-   unsigned long flags = 0;
+   unsigned long flags = _PAGE_RW;
unsigned long pfn;
pgd_t *pgd = efi_pgd;
 


Re: [RFC/PATCH 1/1] format-patch: add an option to record base tree info

2016-02-23 Thread Fengguang Wu
Hi Junio and All,

CC more relevant people. FYI this thread starts here:

http://thread.gmane.org/gmane.comp.version-control.git

On Mon, Feb 22, 2016 at 10:54:38PM -0800, Junio C Hamano wrote:
> Fengguang Wu  writes:
> 
> > Hi Junio,
> >
> > On Sun, Feb 21, 2016 at 08:19:56PM -0800, Junio C Hamano wrote:
> >> Xiaolong Ye  writes:
> >> 
> >> > It would be helpful for maintainers or reviewers to know the base tree
> >> > info of the patches created by git format-patch. Teach git format-patch
> >> > a --base-tree-info option to record these info.
> >> >
> >> > Signed-off-by: Xiaolong Ye 
> >> > ---
> >> 
> >> I have a mixed feeling about this one, primarily because this was
> >> already tried quite early in the life of "format-patch" command.
> >> 
> >> http://thread.gmane.org/gmane.comp.version-control.git/9694/focus=9757
> >> 
> >> Only the name is different (it was called "applies-to" and named a
> >> tree object).
> >
> > Either commit or tree object will work for us. We can use it in
> > v2 if you prefer tree object.
> 
> Sorry, I think you misunderstood.  By only the name is different, I
> didn't mean to say that the tree object name should be shown as the
> old proposal did.  What I meant but didn't explicitly say, as I
> thought it was sufficient to point at an old discussion thread, was
> that this was already tried and rejected.  This round uses different
> name but does essentially the same thing as the old proposal, and I
> do not think I heard anything new that supports this patch against
> earlier rejection by Linus.  That is what gave me a mixed feeling.

I can understand the rejection by Linus in development process POV.

However we are facing a new situation: in test robot POV, IMHO there
are values to test exactly the same tree as the patch submitter.
Otherwise the robot risks

- false negative: failing to apply and test some patches
- false positive: sending wrong bug reports due to guessed wrong base tree

> >> Is it your goal to insist on one exact commit the patch is applied
> >> to?
> >
> > Right. Our goal is fully automated patch testing, where the base tree
> > info is required for *reliably* avoid reporting false positives.
> >
> > A clean git-apply does not guarantee the resulted code is logically
> > consistent and hence testable by 3rd party. For a 3rd party tester to
> > provide useful and trustable test reports, he must apply the patch to
> > exactly the same base as the patch submitter.
> 
> The patch submitter (or you as a third party tester) is not in the
> position to dictate the integrator to apply the patch to one
> specific commit and use it from there.  The integrator would pick an
> appropriate base that would be different from the commit where the
> patch was taken from, apply it there, and merge the result to the
> tip of the mainline, or apply the patch directly to the tip of the
> mainline.  Even if the integrator picked the commit the patch was
> taken from, the result would not be used alone without any other
> changes, i.e. before getting merged into the integration branch.

Yeah. Per my understanding the base commit info will be mainly parsed
by test robots instead of integrators.

> So in that sense, any test that is done by the patch submitter and
> the third party tester would not be what will be released to the
> wild *anyway*.  The resulting code will be exercised in a context
> that *is* different from the context the original author had.

That's right. But no worry, when the patch is merged by maintainer,
we'll test it once again in the maintainer tree.

Pre-merge patch testing is useful in 2 ways:

- shift left testing to early review stage

- maintainer trees are typically not rebaseable. When errors are
  discovered there, it's a bit too late: the error will likely remain
  in git history for ever. Which will hurt bisects.

> I can see that recording the exact commit object name allows you to
> claim that you identified the exact commit to apply the patch, and
> that you tested the exact tree contents.  It however is unclear what
> the value of such a claim would be to the project or to the
> integrator.

The value of base commit info is: providing a solid ground to the
tester, to reliably avoid false positive/negatives.

> So I dunno.

FYI, the 0day test robot will be able to work better if provided the
base commit info. It'll work a bit more sophisticated than simply
relying on the base commit info: if it's sure about the tree the patch
is targeted for (or the maintainer would apply to), it'll use that as
base tree[*]; otherwise it'll fall back to using the base commit info
included in the patchset.

[*] For examples,

[PATCH -mm] ...
[PATCH net] ...

For such patches we are sure they are targeted for the well known
mm/net trees.

Anyway the worst case of not adopting the discussed patch is, the 0day
test robot continue to work in current heuristic way.

Thanks,
Fengguang


Re: [PATCH] mm,vmscan: compact memory from kswapd when lots of memory free already

2016-02-23 Thread Vlastimil Babka

On 02/23/2016 04:50 AM, Rik van Riel wrote:

If kswapd is woken up for a higher order allocation, for example
from alloc_skb, but the system already has lots of memory free,
kswapd_shrink_zone will rightfully decide kswapd should not free
any more memory.

However, at that point kswapd should proceed to compact memory, on
behalf of alloc_skb or others.

Currently kswapd will only compact memory if it first freed memory,
leading kswapd to never compact memory when there is already lots of
memory free.

On my home system, that lead to kswapd occasionally using up to 5%
CPU time, with many man wakeups from alloc_skb, and kswapd never
doing anything to relieve the situation that caused it to be woken
up.


Hi,

I've proposed replacing kswapd compaction with kcompactd, so this hunk 
is gone completely in mmotm. This imperfect comparison was indeed one of 
the things I've noted, but it's not all:


http://marc.info/?l=linux-kernel&m=145493881908394&w=2


Going ahead with compaction when kswapd did not attempt to reclaim
any memory, and as a consequence did not reclaim any memory, is the
right thing to do in this situation.

Signed-off-by: Rik van Riel 
---
  mm/vmscan.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 71b1c29948db..9566a04b9759 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -3343,7 +3343,7 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int 
order,
 * Compact if necessary and kswapd is reclaiming at least the
 * high watermark number of pages as requsted
 */
-   if (pgdat_needs_compaction && sc.nr_reclaimed > nr_attempted)
+   if (pgdat_needs_compaction && sc.nr_reclaimed >= nr_attempted)
compact_pgdat(pgdat, order);

/*





[tip:x86/debug] x86/kvm: Set ELF function type for fastop functions

2016-02-23 Thread tip-bot for Josh Poimboeuf
Commit-ID:  1095da24b338ace27160c3a74b66b41a3ba6c58e
Gitweb: http://git.kernel.org/tip/1095da24b338ace27160c3a74b66b41a3ba6c58e
Author: Josh Poimboeuf 
AuthorDate: Thu, 21 Jan 2016 16:49:29 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:04:00 +0100

x86/kvm: Set ELF function type for fastop functions

The callable functions created with the FOP* and FASTOP* macros are
missing ELF function annotations, which confuses tools like stacktool.
Properly annotate them.

This adds some additional labels to the assembly, but the generated
binary code is unchanged (with the exception of instructions which have
embedded references to __LINE__).

Signed-off-by: Josh Poimboeuf 
Acked-by: Paolo Bonzini 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Bernd Petrovitsch 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chris J Arges 
Cc: Denys Vlasenko 
Cc: Gleb Natapov 
Cc: H. Peter Anvin 
Cc: Jiri Slaby 
Cc: Linus Torvalds 
Cc: Michal Marek 
Cc: Namhyung Kim 
Cc: Pedro Alves 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: k...@vger.kernel.org
Cc: live-patch...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/e399651c89ace54906c203c0557f66ed6ea3ce8d.1453405861.git.jpoim...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/kvm/emulate.c | 29 +
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 1505587..aa4d726 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -309,23 +309,29 @@ static void invalidate_registers(struct x86_emulate_ctxt 
*ctxt)
 
 static int fastop(struct x86_emulate_ctxt *ctxt, void (*fop)(struct fastop *));
 
-#define FOP_ALIGN ".align " __stringify(FASTOP_SIZE) " \n\t"
+#define FOP_FUNC(name) \
+   ".align " __stringify(FASTOP_SIZE) " \n\t" \
+   ".type " name ", @function \n\t" \
+   name ":\n\t"
+
 #define FOP_RET   "ret \n\t"
 
 #define FOP_START(op) \
extern void em_##op(struct fastop *fake); \
asm(".pushsection .text, \"ax\" \n\t" \
".global em_" #op " \n\t" \
-FOP_ALIGN \
-   "em_" #op ": \n\t"
+   FOP_FUNC("em_" #op)
 
 #define FOP_END \
".popsection")
 
-#define FOPNOP() FOP_ALIGN FOP_RET
+#define FOPNOP() \
+   FOP_FUNC(__stringify(__UNIQUE_ID(nop))) \
+   FOP_RET
 
 #define FOP1E(op,  dst) \
-   FOP_ALIGN "10: " #op " %" #dst " \n\t" FOP_RET
+   FOP_FUNC(#op "_" #dst) \
+   "10: " #op " %" #dst " \n\t" FOP_RET
 
 #define FOP1EEX(op,  dst) \
FOP1E(op, dst) _ASM_EXTABLE(10b, kvm_fastop_exception)
@@ -357,7 +363,8 @@ static int fastop(struct x86_emulate_ctxt *ctxt, void 
(*fop)(struct fastop *));
FOP_END
 
 #define FOP2E(op,  dst, src)  \
-   FOP_ALIGN #op " %" #src ", %" #dst " \n\t" FOP_RET
+   FOP_FUNC(#op "_" #dst "_" #src) \
+   #op " %" #src ", %" #dst " \n\t" FOP_RET
 
 #define FASTOP2(op) \
FOP_START(op) \
@@ -395,7 +402,8 @@ static int fastop(struct x86_emulate_ctxt *ctxt, void 
(*fop)(struct fastop *));
FOP_END
 
 #define FOP3E(op,  dst, src, src2) \
-   FOP_ALIGN #op " %" #src2 ", %" #src ", %" #dst " \n\t" FOP_RET
+   FOP_FUNC(#op "_" #dst "_" #src "_" #src2) \
+   #op " %" #src2 ", %" #src ", %" #dst " \n\t" FOP_RET
 
 /* 3-operand, word-only, src2=cl */
 #define FASTOP3WCL(op) \
@@ -407,7 +415,12 @@ static int fastop(struct x86_emulate_ctxt *ctxt, void 
(*fop)(struct fastop *));
FOP_END
 
 /* Special case for SETcc - 1 instruction per cc */
-#define FOP_SETCC(op) ".align 4; " #op " %al; ret \n\t"
+#define FOP_SETCC(op) \
+   ".align 4 \n\t" \
+   ".type " #op ", @function \n\t" \
+   #op ": \n\t" \
+   #op " %al \n\t" \
+   FOP_RET
 
 asm(".global kvm_fastop_exception \n"
 "kvm_fastop_exception: xor %esi, %esi; ret");


[tip:x86/debug] x86/asm/xen: Set ELF function type for xen_adjust_exception_frame()

2016-02-23 Thread tip-bot for Josh Poimboeuf
Commit-ID:  755f95c9331ba316ae6533cdd16456e4613dd0dc
Gitweb: http://git.kernel.org/tip/755f95c9331ba316ae6533cdd16456e4613dd0dc
Author: Josh Poimboeuf 
AuthorDate: Thu, 21 Jan 2016 16:49:10 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:03:54 +0100

x86/asm/xen: Set ELF function type for xen_adjust_exception_frame()

xen_adjust_exception_frame() is a callable function, but is missing the
ELF function type, which confuses tools like stacktool.

Properly annotate it to be a callable function.  The generated code is
unchanged.

Signed-off-by: Josh Poimboeuf 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Bernd Petrovitsch 
Cc: Boris Ostrovsky 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chris J Arges 
Cc: David Vrabel 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Jiri Slaby 
Cc: Konrad Rzeszutek Wilk 
Cc: Linus Torvalds 
Cc: Michal Marek 
Cc: Namhyung Kim 
Cc: Pedro Alves 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: live-patch...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/b1851bd17a0986472692a7e3a05290d891382cdd.1453405861.git.jpoim...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/xen/xen-asm_64.S | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/xen/xen-asm_64.S b/arch/x86/xen/xen-asm_64.S
index cc8acc4..c3df431 100644
--- a/arch/x86/xen/xen-asm_64.S
+++ b/arch/x86/xen/xen-asm_64.S
@@ -26,6 +26,7 @@ ENTRY(xen_adjust_exception_frame)
mov 8+0(%rsp), %rcx
mov 8+8(%rsp), %r11
ret $16
+ENDPROC(xen_adjust_exception_frame)
 
 hypercall_iret = hypercall_page + __HYPERVISOR_iret * 32
 /*


Re: [RFCv7 PATCH 01/10] sched: Compute cpu capacity available at current frequency

2016-02-23 Thread Peter Zijlstra
On Tue, Feb 23, 2016 at 02:41:20AM +0100, Rafael J. Wysocki wrote:
> >  /*
> > + * Returns the current capacity of cpu after applying both
> > + * cpu and freq scaling.
> > + */
> > +static unsigned long capacity_curr_of(int cpu)
> > +{
> > +   return cpu_rq(cpu)->cpu_capacity_orig *
> > +  arch_scale_freq_capacity(NULL, cpu)
> 
> What about architectures that don't have this?

They get the 'default' which is a constant SCHED_CAPACITY_SCALE unit.

> Why is that an architecture feature?

Because not all archs can tell the frequency the same way. Some you
program the DVFS state and they really run at this speed, for those you
can simply report back.

For others, x86 for example, you program a DVFS 'hint' and the hardware
does whatever, we'd have to do APERF/MPERF samples to get an idea of the
actual frequency we ran at.

Also, the having of this makes the load tracking slightly more
expensive, instead of compile time constants we get function calls and
actual multiplications. Its not _too_ bad, but still.

> I can easily imagine two x86 platforms using different
> scale_freq_capacity(), for example.

That's up to the arch, if different x86 platforms need different
thingies the arch implementation needs to offer a selector -- this isn't
'hard'.


[tip:mm/readonly] mm/init: Add 'rodata=off' boot cmdline parameter to disable read-only kernel mappings

2016-02-23 Thread tip-bot for Kees Cook
Commit-ID:  d2aa1acad22f1bdd0cfa67b3861800e392254454
Gitweb: http://git.kernel.org/tip/d2aa1acad22f1bdd0cfa67b3861800e392254454
Author: Kees Cook 
AuthorDate: Wed, 17 Feb 2016 14:41:13 -0800
Committer:  Ingo Molnar 
CommitDate: Mon, 22 Feb 2016 08:51:37 +0100

mm/init: Add 'rodata=off' boot cmdline parameter to disable read-only kernel 
mappings

It may be useful to debug writes to the readonly sections of memory,
so provide a cmdline "rodata=off" to allow for this. This can be
expanded in the future to support "log" and "write" modes, but that
will need to be architecture-specific.

This also makes KDB software breakpoints more usable, as read-only
mappings can now be disabled on any kernel.

Suggested-by: H. Peter Anvin 
Signed-off-by: Kees Cook 
Cc: Andy Lutomirski 
Cc: Arnd Bergmann 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: David Brown 
Cc: Denys Vlasenko 
Cc: Emese Revfy 
Cc: Linus Torvalds 
Cc: Mathias Krause 
Cc: Michael Ellerman 
Cc: PaX Team 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: kernel-harden...@lists.openwall.com
Cc: linux-arch 
Link: 
http://lkml.kernel.org/r/1455748879-21872-3-git-send-email-keesc...@chromium.org
Signed-off-by: Ingo Molnar 
---
 Documentation/kernel-parameters.txt |  4 
 init/main.c | 27 +++
 kernel/debug/kdb/kdb_bp.c   |  4 +---
 3 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/Documentation/kernel-parameters.txt 
b/Documentation/kernel-parameters.txt
index 9a53c92..0003367 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -3491,6 +3491,10 @@ bytes respectively. Such letter suffixes can also be 
entirely omitted.
 
ro  [KNL] Mount root device read-only on boot
 
+   rodata= [KNL]
+   on  Mark read-only kernel memory as read-only (default).
+   off Leave read-only kernel memory writable for debugging.
+
root=   [KNL] Root filesystem
See name_to_dev_t comment in init/do_mounts.c.
 
diff --git a/init/main.c b/init/main.c
index 58c9e37..928a343 100644
--- a/init/main.c
+++ b/init/main.c
@@ -93,9 +93,6 @@ static int kernel_init(void *);
 extern void init_IRQ(void);
 extern void fork_init(void);
 extern void radix_tree_init(void);
-#ifndef CONFIG_DEBUG_RODATA
-static inline void mark_rodata_ro(void) { }
-#endif
 
 /*
  * Debug helper: via this flag we know that we are in 'early bootup code'
@@ -929,6 +926,28 @@ static int try_to_run_init_process(const char 
*init_filename)
 
 static noinline void __init kernel_init_freeable(void);
 
+#ifdef CONFIG_DEBUG_RODATA
+static bool rodata_enabled = true;
+static int __init set_debug_rodata(char *str)
+{
+   return strtobool(str, &rodata_enabled);
+}
+__setup("rodata=", set_debug_rodata);
+
+static void mark_readonly(void)
+{
+   if (rodata_enabled)
+   mark_rodata_ro();
+   else
+   pr_info("Kernel memory protection disabled.\n");
+}
+#else
+static inline void mark_readonly(void)
+{
+   pr_warn("This architecture does not have kernel memory protection.\n");
+}
+#endif
+
 static int __ref kernel_init(void *unused)
 {
int ret;
@@ -937,7 +956,7 @@ static int __ref kernel_init(void *unused)
/* need to finish all async __init code before freeing the memory */
async_synchronize_full();
free_initmem();
-   mark_rodata_ro();
+   mark_readonly();
system_state = SYSTEM_RUNNING;
numa_default_policy();
 
diff --git a/kernel/debug/kdb/kdb_bp.c b/kernel/debug/kdb/kdb_bp.c
index e1dbf4a..90ff129 100644
--- a/kernel/debug/kdb/kdb_bp.c
+++ b/kernel/debug/kdb/kdb_bp.c
@@ -153,13 +153,11 @@ static int _kdb_bp_install(struct pt_regs *regs, kdb_bp_t 
*bp)
} else {
kdb_printf("%s: failed to set breakpoint at 0x%lx\n",
   __func__, bp->bp_addr);
-#ifdef CONFIG_DEBUG_RODATA
if (!bp->bp_type) {
kdb_printf("Software breakpoints are unavailable.\n"
-  "  Change the kernel CONFIG_DEBUG_RODATA=n\n"
+  "  Boot the kernel with rodata=off\n"
   "  OR use hw breaks: help bph\n");
}
-#endif
return 1;
}
return 0;


[tip:mm/readonly] lkdtm: Verify that '__ro_after_init' works correctly

2016-02-23 Thread tip-bot for Kees Cook
Commit-ID:  7cca071ccbd2a293ea69168ace6abbcdce53098e
Gitweb: http://git.kernel.org/tip/7cca071ccbd2a293ea69168ace6abbcdce53098e
Author: Kees Cook 
AuthorDate: Wed, 17 Feb 2016 14:41:16 -0800
Committer:  Ingo Molnar 
CommitDate: Mon, 22 Feb 2016 08:51:38 +0100

lkdtm: Verify that '__ro_after_init' works correctly

The new __ro_after_init section should be writable before init, but
not after. Validate that it gets updated at init and can't be written
to afterwards.

Signed-off-by: Kees Cook 
Cc: Andy Lutomirski 
Cc: Arnd Bergmann 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: David Brown 
Cc: Denys Vlasenko 
Cc: Emese Revfy 
Cc: H. Peter Anvin 
Cc: Linus Torvalds 
Cc: Mathias Krause 
Cc: Michael Ellerman 
Cc: PaX Team 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: kernel-harden...@lists.openwall.com
Cc: linux-arch 
Link: 
http://lkml.kernel.org/r/1455748879-21872-6-git-send-email-keesc...@chromium.org
Signed-off-by: Ingo Molnar 
---
 drivers/misc/lkdtm.c | 29 ++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
index 11fdadc..2a6eaf1 100644
--- a/drivers/misc/lkdtm.c
+++ b/drivers/misc/lkdtm.c
@@ -103,6 +103,7 @@ enum ctype {
CT_EXEC_USERSPACE,
CT_ACCESS_USERSPACE,
CT_WRITE_RO,
+   CT_WRITE_RO_AFTER_INIT,
CT_WRITE_KERN,
 };
 
@@ -140,6 +141,7 @@ static char* cp_type[] = {
"EXEC_USERSPACE",
"ACCESS_USERSPACE",
"WRITE_RO",
+   "WRITE_RO_AFTER_INIT",
"WRITE_KERN",
 };
 
@@ -162,6 +164,7 @@ static DEFINE_SPINLOCK(lock_me_up);
 static u8 data_area[EXEC_SIZE];
 
 static const unsigned long rodata = 0xAA55AA55;
+static unsigned long ro_after_init __ro_after_init = 0x55AA5500;
 
 module_param(recur_count, int, 0644);
 MODULE_PARM_DESC(recur_count, " Recursion level for the stack overflow test");
@@ -503,11 +506,28 @@ static void lkdtm_do_action(enum ctype which)
break;
}
case CT_WRITE_RO: {
-   unsigned long *ptr;
+   /* Explicitly cast away "const" for the test. */
+   unsigned long *ptr = (unsigned long *)&rodata;
 
-   ptr = (unsigned long *)&rodata;
+   pr_info("attempting bad rodata write at %p\n", ptr);
+   *ptr ^= 0xabcd1234;
 
-   pr_info("attempting bad write at %p\n", ptr);
+   break;
+   }
+   case CT_WRITE_RO_AFTER_INIT: {
+   unsigned long *ptr = &ro_after_init;
+
+   /*
+* Verify we were written to during init. Since an Oops
+* is considered a "success", a failure is to just skip the
+* real test.
+*/
+   if ((*ptr & 0xAA) != 0xAA) {
+   pr_info("%p was NOT written during init!?\n", ptr);
+   break;
+   }
+
+   pr_info("attempting bad ro_after_init write at %p\n", ptr);
*ptr ^= 0xabcd1234;
 
break;
@@ -817,6 +837,9 @@ static int __init lkdtm_module_init(void)
int n_debugfs_entries = 1; /* Assume only the direct entry */
int i;
 
+   /* Make sure we can write to __ro_after_init values during __init */
+   ro_after_init |= 0xAA;
+
/* Register debugfs interface */
lkdtm_debugfs_root = debugfs_create_dir("provoke-crash", NULL);
if (!lkdtm_debugfs_root) {


[tip:x86/debug] x86/asm/bpf: Create stack frames in bpf_jit.S

2016-02-23 Thread tip-bot for Josh Poimboeuf
Commit-ID:  45670be075ce96566bc6b6ca0b579f17ed6f94f3
Gitweb: http://git.kernel.org/tip/45670be075ce96566bc6b6ca0b579f17ed6f94f3
Author: Josh Poimboeuf 
AuthorDate: Thu, 21 Jan 2016 16:49:27 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:03:59 +0100

x86/asm/bpf: Create stack frames in bpf_jit.S

bpf_jit.S has several callable non-leaf functions which don't honor
CONFIG_FRAME_POINTER, which can result in bad stack traces.

Create a stack frame before the call instructions when
CONFIG_FRAME_POINTER is enabled.

Signed-off-by: Josh Poimboeuf 
Acked-by: Alexei Starovoitov 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Bernd Petrovitsch 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chris J Arges 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Jiri Slaby 
Cc: Linus Torvalds 
Cc: Michal Marek 
Cc: Namhyung Kim 
Cc: Pedro Alves 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: live-patch...@vger.kernel.org
Cc: net...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/fa4c41976b438b51954cb8021f06bceb1d1d66cc.1453405861.git.jpoim...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/net/bpf_jit.S | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
index eb4a3bd..f2a7faf 100644
--- a/arch/x86/net/bpf_jit.S
+++ b/arch/x86/net/bpf_jit.S
@@ -8,6 +8,7 @@
  * of the License.
  */
 #include 
+#include 
 
 /*
  * Calling convention :
@@ -65,16 +66,18 @@ FUNC(sk_load_byte_positive_offset)
 
 /* rsi contains offset and can be scratched */
 #define bpf_slow_path_common(LEN)  \
+   lea -MAX_BPF_STACK + 32(%rbp), %rdx;\
+   FRAME_BEGIN;\
mov %rbx, %rdi; /* arg1 == skb */   \
push%r9;\
pushSKBDATA;\
 /* rsi already has offset */   \
mov $LEN,%ecx;  /* len */   \
-   lea - MAX_BPF_STACK + 32(%rbp),%rdx;\
callskb_copy_bits;  \
test%eax,%eax;  \
pop SKBDATA;\
-   pop %r9;
+   pop %r9;\
+   FRAME_END
 
 
 bpf_slow_path_word:
@@ -99,6 +102,7 @@ bpf_slow_path_byte:
ret
 
 #define sk_negative_common(SIZE)   \
+   FRAME_BEGIN;\
mov %rbx, %rdi; /* arg1 == skb */   \
push%r9;\
pushSKBDATA;\
@@ -108,6 +112,7 @@ bpf_slow_path_byte:
test%rax,%rax;  \
pop SKBDATA;\
pop %r9;\
+   FRAME_END;  \
jz  bpf_error
 
 bpf_slow_path_word_neg:


[tip:x86/debug] x86/asm/bpf: Annotate callable functions

2016-02-23 Thread tip-bot for Josh Poimboeuf
Commit-ID:  ebcc476acbda75cb1a2020677c38b436085173ba
Gitweb: http://git.kernel.org/tip/ebcc476acbda75cb1a2020677c38b436085173ba
Author: Josh Poimboeuf 
AuthorDate: Thu, 21 Jan 2016 16:49:26 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:03:59 +0100

x86/asm/bpf: Annotate callable functions

bpf_jit.S has several functions which can be called from C code.  Give
them proper ELF annotations.

Signed-off-by: Josh Poimboeuf 
Acked-by: Alexei Starovoitov 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Bernd Petrovitsch 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chris J Arges 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Jiri Slaby 
Cc: Linus Torvalds 
Cc: Michal Marek 
Cc: Namhyung Kim 
Cc: Pedro Alves 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: live-patch...@vger.kernel.org
Cc: net...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/bbe1de0c299fecd4fc9a1766bae8be2647bedb01.1453405861.git.jpoim...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/net/bpf_jit.S | 39 ---
 1 file changed, 16 insertions(+), 23 deletions(-)

diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
index 4093216..eb4a3bd 100644
--- a/arch/x86/net/bpf_jit.S
+++ b/arch/x86/net/bpf_jit.S
@@ -22,15 +22,16 @@
32 /* space for rbx,r13,r14,r15 */ + \
8 /* space for skb_copy_bits */)
 
-sk_load_word:
-   .globl  sk_load_word
+#define FUNC(name) \
+   .globl name; \
+   .type name, @function; \
+   name:
 
+FUNC(sk_load_word)
test%esi,%esi
js  bpf_slow_path_word_neg
 
-sk_load_word_positive_offset:
-   .globl  sk_load_word_positive_offset
-
+FUNC(sk_load_word_positive_offset)
mov %r9d,%eax   # hlen
sub %esi,%eax   # hlen - offset
cmp $3,%eax
@@ -39,15 +40,11 @@ sk_load_word_positive_offset:
bswap   %eax/* ntohl() */
ret
 
-sk_load_half:
-   .globl  sk_load_half
-
+FUNC(sk_load_half)
test%esi,%esi
js  bpf_slow_path_half_neg
 
-sk_load_half_positive_offset:
-   .globl  sk_load_half_positive_offset
-
+FUNC(sk_load_half_positive_offset)
mov %r9d,%eax
sub %esi,%eax   #   hlen - offset
cmp $1,%eax
@@ -56,15 +53,11 @@ sk_load_half_positive_offset:
rol $8,%ax  # ntohs()
ret
 
-sk_load_byte:
-   .globl  sk_load_byte
-
+FUNC(sk_load_byte)
test%esi,%esi
js  bpf_slow_path_byte_neg
 
-sk_load_byte_positive_offset:
-   .globl  sk_load_byte_positive_offset
-
+FUNC(sk_load_byte_positive_offset)
cmp %esi,%r9d   /* if (offset >= hlen) goto bpf_slow_path_byte */
jle bpf_slow_path_byte
movzbl  (SKBDATA,%rsi),%eax
@@ -120,8 +113,8 @@ bpf_slow_path_byte:
 bpf_slow_path_word_neg:
cmp SKF_MAX_NEG_OFF, %esi   /* test range */
jl  bpf_error   /* offset lower -> error  */
-sk_load_word_negative_offset:
-   .globl  sk_load_word_negative_offset
+
+FUNC(sk_load_word_negative_offset)
sk_negative_common(4)
mov (%rax), %eax
bswap   %eax
@@ -130,8 +123,8 @@ sk_load_word_negative_offset:
 bpf_slow_path_half_neg:
cmp SKF_MAX_NEG_OFF, %esi
jl  bpf_error
-sk_load_half_negative_offset:
-   .globl  sk_load_half_negative_offset
+
+FUNC(sk_load_half_negative_offset)
sk_negative_common(2)
mov (%rax),%ax
rol $8,%ax
@@ -141,8 +134,8 @@ sk_load_half_negative_offset:
 bpf_slow_path_byte_neg:
cmp SKF_MAX_NEG_OFF, %esi
jl  bpf_error
-sk_load_byte_negative_offset:
-   .globl  sk_load_byte_negative_offset
+
+FUNC(sk_load_byte_negative_offset)
sk_negative_common(1)
movzbl  (%rax), %eax
ret


[tip:mm/readonly] x86/vdso: Mark the vDSO code read-only after init

2016-02-23 Thread tip-bot for Kees Cook
Commit-ID:  018ef8dcf3de5f62e2cc1a9273cc27e1c6ba8de5
Gitweb: http://git.kernel.org/tip/018ef8dcf3de5f62e2cc1a9273cc27e1c6ba8de5
Author: Kees Cook 
AuthorDate: Wed, 17 Feb 2016 14:41:17 -0800
Committer:  Ingo Molnar 
CommitDate: Mon, 22 Feb 2016 08:51:39 +0100

x86/vdso: Mark the vDSO code read-only after init

The vDSO does not need to be writable after __init, so mark it as
__ro_after_init. The result kills the exploit method of writing to the
vDSO from kernel space resulting in userspace executing the modified code,
as shown here to bypass SMEP restrictions: http://itszn.com/blog/?p=21

The memory map (with added vDSO address reporting) shows the vDSO moving
into read-only memory:

Before:
[0.143067] vDSO @ 82004000
[0.143551] vDSO @ 82006000
---[ High Kernel Mapping ]---
0x8000-0x8100  16M 
pmd
0x8100-0x8180   8M   ro PSE GLB x  
pmd
0x8180-0x819f30001996K   ro GLB x  
pte
0x819f3000-0x81a0  52K   ro NX 
pte
0x81a0-0x81e0   4M   ro PSE GLB NX 
pmd
0x81e0-0x81e05000  20K   ro GLB NX 
pte
0x81e05000-0x82002028K   ro NX 
pte
0x8200-0x8214f0001340K   RW GLB NX 
pte
0x8214f000-0x822810001224K   RW NX 
pte
0x82281000-0x82401532K   RW GLB NX 
pte
0x8240-0x8320  14M   RW PSE GLB NX 
pmd
0x8320-0xc000 974M 
pmd

After:
[0.145062] vDSO @ 81da1000
[0.146057] vDSO @ 81da4000
---[ High Kernel Mapping ]---
0x8000-0x8100  16M 
pmd
0x8100-0x8180   8M   ro PSE GLB x  
pmd
0x8180-0x819f30001996K   ro GLB x  
pte
0x819f3000-0x81a0  52K   ro NX 
pte
0x81a0-0x81e0   4M   ro PSE GLB NX 
pmd
0x81e0-0x81e0b000  44K   ro GLB NX 
pte
0x81e0b000-0x82002004K   ro NX 
pte
0x8200-0x8214c0001328K   RW GLB NX 
pte
0x8214c000-0x8227e0001224K   RW NX 
pte
0x8227e000-0x82401544K   RW GLB NX 
pte
0x8240-0x8320  14M   RW PSE GLB NX 
pmd
0x8320-0xc000 974M 
pmd

Based on work by PaX Team and Brad Spengler.

Signed-off-by: Kees Cook 
Acked-by: Andy Lutomirski 
Acked-by: H. Peter Anvin 
Cc: Andy Lutomirski 
Cc: Arnd Bergmann 
Cc: Borislav Petkov 
Cc: Brad Spengler 
Cc: Brian Gerst 
Cc: David Brown 
Cc: Denys Vlasenko 
Cc: Emese Revfy 
Cc: H. Peter Anvin 
Cc: Linus Torvalds 
Cc: Mathias Krause 
Cc: Michael Ellerman 
Cc: PaX Team 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: kernel-harden...@lists.openwall.com
Cc: linux-arch 
Link: 
http://lkml.kernel.org/r/1455748879-21872-7-git-send-email-keesc...@chromium.org
Signed-off-by: Ingo Molnar 
---
 arch/x86/entry/vdso/vdso2c.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/entry/vdso/vdso2c.h b/arch/x86/entry/vdso/vdso2c.h
index 0224987..3f69326 100644
--- a/arch/x86/entry/vdso/vdso2c.h
+++ b/arch/x86/entry/vdso/vdso2c.h
@@ -140,7 +140,7 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
fprintf(outfile, "#include \n");
fprintf(outfile, "\n");
fprintf(outfile,
-   "static unsigned char raw_data[%lu] __page_aligned_data = {",
+   "static unsigned char raw_data[%lu] __ro_after_init 
__aligned(PAGE_SIZE) = {",
mapping_size);
for (j = 0; j < stripped_len; j++) {
if (j % 10 == 0)


[tip:efi/core] efi/arm64: Check for h/w support before booting a >4 KB granular kernel

2016-02-23 Thread tip-bot for Ard Biesheuvel
Commit-ID:  42b55734030c1f724d5f47aeb872e2cccd650d79
Gitweb: http://git.kernel.org/tip/42b55734030c1f724d5f47aeb872e2cccd650d79
Author: Ard Biesheuvel 
AuthorDate: Wed, 17 Feb 2016 12:36:02 +
Committer:  Ingo Molnar 
CommitDate: Mon, 22 Feb 2016 08:26:27 +0100

efi/arm64: Check for h/w support before booting a >4 KB granular kernel

A kernel built with support for a page size that is not supported by the
hardware it runs on cannot boot to a state where it can inform the user
about the failure.

If we happen to be booting via UEFI, we can fail gracefully so check
if the currently configured page size is supported by the hardware before
entering the kernel proper. Note that UEFI mandates support for 4 KB pages,
so in that case, no check is needed.

Tested-by: Suzuki K Poulose 
Signed-off-by: Ard Biesheuvel 
Signed-off-by: Matt Fleming 
Reviewed-by: Jeremy Linton 
Acked-by: Mark Rutland 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1455712566-16727-10-git-send-email-m...@codeblueprint.co.uk
Signed-off-by: Ingo Molnar 
---
 drivers/firmware/efi/libstub/arm64-stub.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/drivers/firmware/efi/libstub/arm64-stub.c 
b/drivers/firmware/efi/libstub/arm64-stub.c
index 9e03427..047fc34 100644
--- a/drivers/firmware/efi/libstub/arm64-stub.c
+++ b/drivers/firmware/efi/libstub/arm64-stub.c
@@ -12,6 +12,26 @@
 #include 
 #include 
 #include 
+#include 
+
+efi_status_t check_platform_features(efi_system_table_t *sys_table_arg)
+{
+   u64 tg;
+
+   /* UEFI mandates support for 4 KB granularity, no need to check */
+   if (IS_ENABLED(CONFIG_ARM64_4K_PAGES))
+   return EFI_SUCCESS;
+
+   tg = (read_cpuid(ID_AA64MMFR0_EL1) >> ID_AA64MMFR0_TGRAN_SHIFT) & 0xf;
+   if (tg != ID_AA64MMFR0_TGRAN_SUPPORTED) {
+   if (IS_ENABLED(CONFIG_ARM64_64K_PAGES))
+   pr_efi_err(sys_table_arg, "This 64 KB granular kernel 
is not supported by your CPU\n");
+   else
+   pr_efi_err(sys_table_arg, "This 16 KB granular kernel 
is not supported by your CPU\n");
+   return EFI_UNSUPPORTED;
+   }
+   return EFI_SUCCESS;
+}
 
 efi_status_t handle_kernel_image(efi_system_table_t *sys_table_arg,
 unsigned long *image_addr,


Re: [RFC/PATCH 1/1] format-patch: add an option to record base tree info

2016-02-23 Thread H. Peter Anvin
On 02/23/16 01:17, Fengguang Wu wrote:
> 
> However we are facing a new situation: in test robot POV, IMHO there
> are values to test exactly the same tree as the patch submitter.
> Otherwise the robot risks
> 
> - false negative: failing to apply and test some patches
> - false positive: sending wrong bug reports due to guessed wrong base tree
> 

Wouldn't the important part here be the git hash, rather than the tree?
 If you have the same hash then it by definition is the same contents?

-hpa




[tip:efi/core] efi: Reformat GUID tables to follow the format in UEFI spec

2016-02-23 Thread tip-bot for Peter Jones
Commit-ID:  662b1d890c593673964758fe5b6f22067bffba7a
Gitweb: http://git.kernel.org/tip/662b1d890c593673964758fe5b6f22067bffba7a
Author: Peter Jones 
AuthorDate: Wed, 17 Feb 2016 12:35:54 +
Committer:  Ingo Molnar 
CommitDate: Mon, 22 Feb 2016 08:26:25 +0100

efi: Reformat GUID tables to follow the format in UEFI spec

This makes it much easier to hunt for typos in the GUID definitions.

It also makes checkpatch complain less about efi.h GUID additions, so
that if you add another one with the same style, checkpatch won't
complain about it.

Signed-off-by: Peter Jones 
Signed-off-by: Matt Fleming 
Cc: Ard Biesheuvel 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1455712566-16727-2-git-send-email-m...@codeblueprint.co.uk
Signed-off-by: Ingo Molnar 
---
 include/linux/efi.h | 63 +++--
 1 file changed, 42 insertions(+), 21 deletions(-)

diff --git a/include/linux/efi.h b/include/linux/efi.h
index 1acd723..42be9c9 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -536,67 +536,88 @@ void efi_native_runtime_setup(void);
  *  EFI Configuration Table and GUID definitions
  */
 #define NULL_GUID \
-EFI_GUID(  0x, 0x, 0x, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00 )
+   EFI_GUID(0x, 0x, 0x, \
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
 
 #define MPS_TABLE_GUID\
-EFI_GUID(  0xeb9d2d2f, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 
0xc1, 0x4d )
+   EFI_GUID(0xeb9d2d2f, 0x2d88, 0x11d3, \
+0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
 
 #define ACPI_TABLE_GUID\
-EFI_GUID(  0xeb9d2d30, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 
0xc1, 0x4d )
+   EFI_GUID(0xeb9d2d30, 0x2d88, 0x11d3, \
+0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
 
 #define ACPI_20_TABLE_GUID\
-EFI_GUID(  0x8868e871, 0xe4f1, 0x11d3, 0xbc, 0x22, 0x0, 0x80, 0xc7, 0x3c, 
0x88, 0x81 )
+   EFI_GUID(0x8868e871, 0xe4f1, 0x11d3, \
+0xbc, 0x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81)
 
 #define SMBIOS_TABLE_GUID\
-EFI_GUID(  0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 
0xc1, 0x4d )
+   EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3, \
+0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
 
 #define SMBIOS3_TABLE_GUID\
-EFI_GUID(  0xf2fd1544, 0x9794, 0x4a2c, 0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 
0xe3, 0x94 )
+   EFI_GUID(0xf2fd1544, 0x9794, 0x4a2c, \
+0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94)
 
 #define SAL_SYSTEM_TABLE_GUID\
-EFI_GUID(  0xeb9d2d32, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 
0xc1, 0x4d )
+   EFI_GUID(0xeb9d2d32, 0x2d88, 0x11d3, \
+0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
 
 #define HCDP_TABLE_GUID\
-EFI_GUID(  0xf951938d, 0x620b, 0x42ef, 0x82, 0x79, 0xa8, 0x4b, 0x79, 0x61, 
0x78, 0x98 )
+   EFI_GUID(0xf951938d, 0x620b, 0x42ef, \
+0x82, 0x79, 0xa8, 0x4b, 0x79, 0x61, 0x78, 0x98)
 
 #define UGA_IO_PROTOCOL_GUID \
-EFI_GUID(  0x61a4d49e, 0x6f68, 0x4f1b, 0xb9, 0x22, 0xa8, 0x6e, 0xed, 0xb, 
0x7, 0xa2 )
+   EFI_GUID(0x61a4d49e, 0x6f68, 0x4f1b, \
+0xb9, 0x22, 0xa8, 0x6e, 0xed, 0x0b, 0x07, 0xa2)
 
 #define EFI_GLOBAL_VARIABLE_GUID \
-EFI_GUID(  0x8be4df61, 0x93ca, 0x11d2, 0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 
0x2b, 0x8c )
+   EFI_GUID(0x8be4df61, 0x93ca, 0x11d2, \
+0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c)
 
 #define UV_SYSTEM_TABLE_GUID \
-EFI_GUID(  0x3b13a7d4, 0x633e, 0x11dd, 0x93, 0xec, 0xda, 0x25, 0x56, 0xd8, 
0x95, 0x93 )
+   EFI_GUID(0x3b13a7d4, 0x633e, 0x11dd, \
+0x93, 0xec, 0xda, 0x25, 0x56, 0xd8, 0x95, 0x93)
 
 #define LINUX_EFI_CRASH_GUID \
-EFI_GUID(  0xcfc8fc79, 0xbe2e, 0x4ddc, 0x97, 0xf0, 0x9f, 0x98, 0xbf, 0xe2, 
0x98, 0xa0 )
+   EFI_GUID(0xcfc8fc79, 0xbe2e, 0x4ddc, \
+0x97, 0xf0, 0x9f, 0x98, 0xbf, 0xe2, 0x98, 0xa0)
 
 #define LOADED_IMAGE_PROTOCOL_GUID \
-EFI_GUID(  0x5b1b31a1, 0x9562, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 
0x72, 0x3b )
+   EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2, \
+0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
 
 #define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \
-EFI_GUID(  0x9042a9de, 0x23dc, 0x4a38, 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 
0x51, 0x6a )
+   EFI_GUID(0x9042a9de, 0x23dc, 0x4a38, \
+0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a)
 
 #define EFI_UGA_PROTOCOL_GUID \
-EFI_GUID(  0x982c298b, 0xf4fa, 0x41cb, 0xb8, 0x38, 0x77, 0xaa, 0x68, 0x8f, 
0xb8, 0x39 )
+   EFI_GUID(0x982c298b, 0xf4fa, 0x41cb, \
+0xb8, 0x38, 0x77, 0xaa, 0x68, 0x8f, 0xb8, 0x39)
 
 #define EFI_PCI_IO_PROTOCOL_GUID \
-EFI_GUID(  0x4cf5b200, 0x68b8, 0x4ca5, 0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 
0x2, 0x9a )
+   EFI_GUID(0x4cf5b200, 

[tip:x86/debug] x86/kprobes: Get rid of kretprobe_trampoline_holder()

2016-02-23 Thread tip-bot for Josh Poimboeuf
Commit-ID:  e3f26d20d60297e4c37999525c020177cc62faac
Gitweb: http://git.kernel.org/tip/e3f26d20d60297e4c37999525c020177cc62faac
Author: Josh Poimboeuf 
AuthorDate: Thu, 21 Jan 2016 16:49:28 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:03:59 +0100

x86/kprobes: Get rid of kretprobe_trampoline_holder()

The kretprobe_trampoline_holder() wrapper around kretprobe_trampoline()
isn't used anywhere and adds some unnecessary frame pointer instructions
which never execute.  Instead, just make kretprobe_trampoline() a proper
ELF function.

Signed-off-by: Josh Poimboeuf 
Acked-by: Masami Hiramatsu 
Cc: Ananth N Mavinakayanahalli 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Anil S Keshavamurthy 
Cc: Arnaldo Carvalho de Melo 
Cc: Bernd Petrovitsch 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chris J Arges 
Cc: David S. Miller 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Jiri Slaby 
Cc: Linus Torvalds 
Cc: Michal Marek 
Cc: Namhyung Kim 
Cc: Pedro Alves 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: live-patch...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/92d921b102fb865a7c254cfde9e4a0a72b9a781e.1453405861.git.jpoim...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/kernel/kprobes/core.c | 57 +-
 1 file changed, 28 insertions(+), 29 deletions(-)

diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
index 1deffe6..5b187df 100644
--- a/arch/x86/kernel/kprobes/core.c
+++ b/arch/x86/kernel/kprobes/core.c
@@ -671,38 +671,37 @@ NOKPROBE_SYMBOL(kprobe_int3_handler);
  * When a retprobed function returns, this code saves registers and
  * calls trampoline_handler() runs, which calls the kretprobe's handler.
  */
-static void __used kretprobe_trampoline_holder(void)
-{
-   asm volatile (
-   ".global kretprobe_trampoline\n"
-   "kretprobe_trampoline: \n"
+asm(
+   ".global kretprobe_trampoline\n"
+   ".type kretprobe_trampoline, @function\n"
+   "kretprobe_trampoline:\n"
 #ifdef CONFIG_X86_64
-   /* We don't bother saving the ss register */
-   "   pushq %rsp\n"
-   "   pushfq\n"
-   SAVE_REGS_STRING
-   "   movq %rsp, %rdi\n"
-   "   call trampoline_handler\n"
-   /* Replace saved sp with true return address. */
-   "   movq %rax, 152(%rsp)\n"
-   RESTORE_REGS_STRING
-   "   popfq\n"
+   /* We don't bother saving the ss register */
+   "   pushq %rsp\n"
+   "   pushfq\n"
+   SAVE_REGS_STRING
+   "   movq %rsp, %rdi\n"
+   "   call trampoline_handler\n"
+   /* Replace saved sp with true return address. */
+   "   movq %rax, 152(%rsp)\n"
+   RESTORE_REGS_STRING
+   "   popfq\n"
 #else
-   "   pushf\n"
-   SAVE_REGS_STRING
-   "   movl %esp, %eax\n"
-   "   call trampoline_handler\n"
-   /* Move flags to cs */
-   "   movl 56(%esp), %edx\n"
-   "   movl %edx, 52(%esp)\n"
-   /* Replace saved flags with true return address. */
-   "   movl %eax, 56(%esp)\n"
-   RESTORE_REGS_STRING
-   "   popf\n"
+   "   pushf\n"
+   SAVE_REGS_STRING
+   "   movl %esp, %eax\n"
+   "   call trampoline_handler\n"
+   /* Move flags to cs */
+   "   movl 56(%esp), %edx\n"
+   "   movl %edx, 52(%esp)\n"
+   /* Replace saved flags with true return address. */
+   "   movl %eax, 56(%esp)\n"
+   RESTORE_REGS_STRING
+   "   popf\n"
 #endif
-   "   ret\n");
-}
-NOKPROBE_SYMBOL(kretprobe_trampoline_holder);
+   "   ret\n"
+   ".size kretprobe_trampoline, .-kretprobe_trampoline\n"
+);
 NOKPROBE_SYMBOL(kretprobe_trampoline);
 
 /*


[tip:efi/core] efi/arm-init: Use read-only early mappings

2016-02-23 Thread tip-bot for Ard Biesheuvel
Commit-ID:  2eec5dedf770dc85c1fdf6b86873165e61bb1fff
Gitweb: http://git.kernel.org/tip/2eec5dedf770dc85c1fdf6b86873165e61bb1fff
Author: Ard Biesheuvel 
AuthorDate: Wed, 17 Feb 2016 12:36:00 +
Committer:  Ingo Molnar 
CommitDate: Mon, 22 Feb 2016 08:26:27 +0100

efi/arm-init: Use read-only early mappings

The early mappings of the EFI system table contents and the UEFI memory
map are read-only from the OS point of view. So map them read-only to
protect them from inadvertent modification.

Tested-by: Mark Rutland 
Signed-off-by: Ard Biesheuvel 
Signed-off-by: Matt Fleming 
Acked-by: Mark Rutland 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1455712566-16727-8-git-send-email-m...@codeblueprint.co.uk
Signed-off-by: Ingo Molnar 
---
 drivers/firmware/efi/arm-init.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/firmware/efi/arm-init.c b/drivers/firmware/efi/arm-init.c
index 9e15d57..aa1f743 100644
--- a/drivers/firmware/efi/arm-init.c
+++ b/drivers/firmware/efi/arm-init.c
@@ -61,8 +61,8 @@ static int __init uefi_init(void)
char vendor[100] = "unknown";
int i, retval;
 
-   efi.systab = early_memremap(efi_system_table,
-   sizeof(efi_system_table_t));
+   efi.systab = early_memremap_ro(efi_system_table,
+  sizeof(efi_system_table_t));
if (efi.systab == NULL) {
pr_warn("Unable to map EFI system table.\n");
return -ENOMEM;
@@ -86,8 +86,8 @@ static int __init uefi_init(void)
efi.systab->hdr.revision & 0x);
 
/* Show what we know for posterity */
-   c16 = early_memremap(efi_to_phys(efi.systab->fw_vendor),
-sizeof(vendor) * sizeof(efi_char16_t));
+   c16 = early_memremap_ro(efi_to_phys(efi.systab->fw_vendor),
+   sizeof(vendor) * sizeof(efi_char16_t));
if (c16) {
for (i = 0; i < (int) sizeof(vendor) - 1 && *c16; ++i)
vendor[i] = c16[i];
@@ -100,8 +100,8 @@ static int __init uefi_init(void)
efi.systab->hdr.revision & 0x, vendor);
 
table_size = sizeof(efi_config_table_64_t) * efi.systab->nr_tables;
-   config_tables = early_memremap(efi_to_phys(efi.systab->tables),
-  table_size);
+   config_tables = early_memremap_ro(efi_to_phys(efi.systab->tables),
+ table_size);
if (config_tables == NULL) {
pr_warn("Unable to map EFI config table array.\n");
retval = -ENOMEM;
@@ -185,7 +185,7 @@ void __init efi_init(void)
efi_system_table = params.system_table;
 
memmap.phys_map = params.mmap;
-   memmap.map = early_memremap(params.mmap, params.mmap_size);
+   memmap.map = early_memremap_ro(params.mmap, params.mmap_size);
if (memmap.map == NULL) {
/*
* If we are booting via UEFI, the UEFI memory map is the only


[tip:efi/core] efi/arm*: Perform hardware compatibility check

2016-02-23 Thread tip-bot for Ard Biesheuvel
Commit-ID:  b9d6769b5678dbd6cb328d20716561d35b2b1510
Gitweb: http://git.kernel.org/tip/b9d6769b5678dbd6cb328d20716561d35b2b1510
Author: Ard Biesheuvel 
AuthorDate: Wed, 17 Feb 2016 12:36:03 +
Committer:  Ingo Molnar 
CommitDate: Mon, 22 Feb 2016 08:26:27 +0100

efi/arm*: Perform hardware compatibility check

Before proceeding with relocating the kernel and parsing the command line,
insert a call to check_platform_features() to allow an arch specific check
to be performed whether the current kernel can execute on the current
hardware.

Tested-by: Suzuki K Poulose 
Signed-off-by: Ard Biesheuvel 
Signed-off-by: Matt Fleming 
Reviewed-by: Jeremy Linton 
Acked-by: Mark Rutland 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1455712566-16727-11-git-send-email-m...@codeblueprint.co.uk
Signed-off-by: Ingo Molnar 
---
 drivers/firmware/efi/libstub/arm-stub.c | 4 
 drivers/firmware/efi/libstub/efistub.h  | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/drivers/firmware/efi/libstub/arm-stub.c 
b/drivers/firmware/efi/libstub/arm-stub.c
index 3397902..6086a87 100644
--- a/drivers/firmware/efi/libstub/arm-stub.c
+++ b/drivers/firmware/efi/libstub/arm-stub.c
@@ -190,6 +190,10 @@ unsigned long efi_entry(void *handle, efi_system_table_t 
*sys_table,
 
pr_efi(sys_table, "Booting Linux Kernel...\n");
 
+   status = check_platform_features(sys_table);
+   if (status != EFI_SUCCESS)
+   goto fail;
+
/*
 * Get a handle to the loaded image protocol.  This is used to get
 * information about the running image, such as size and the command
diff --git a/drivers/firmware/efi/libstub/efistub.h 
b/drivers/firmware/efi/libstub/efistub.h
index 86ff7bf..981c603 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -53,4 +53,6 @@ void efi_get_virtmap(efi_memory_desc_t *memory_map, unsigned 
long map_size,
 unsigned long desc_size, efi_memory_desc_t *runtime_map,
 int *count);
 
+efi_status_t check_platform_features(efi_system_table_t *sys_table_arg);
+
 #endif


[tip:efi/core] efi/arm: Check for LPAE support before booting a LPAE kernel

2016-02-23 Thread tip-bot for Ard Biesheuvel
Commit-ID:  2ec0f0a3a4bfab90eda8b81656f62e07abf2321f
Gitweb: http://git.kernel.org/tip/2ec0f0a3a4bfab90eda8b81656f62e07abf2321f
Author: Ard Biesheuvel 
AuthorDate: Wed, 17 Feb 2016 12:36:01 +
Committer:  Ingo Molnar 
CommitDate: Mon, 22 Feb 2016 08:26:27 +0100

efi/arm: Check for LPAE support before booting a LPAE kernel

A kernel built with support for LPAE cannot boot to a state where it
can inform the user about if it has to fail due to missing LPAE support
in the hardware.

If we happen to be booting via UEFI, we can fail gracefully so check
for LPAE support in the hardware on CONFIG_ARM_LPAE builds before
entering the kernel proper.

Signed-off-by: Ard Biesheuvel 
Signed-off-by: Matt Fleming 
Reviewed-by: Jeremy Linton 
Acked-by: Mark Rutland 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1455712566-16727-9-git-send-email-m...@codeblueprint.co.uk
Signed-off-by: Ingo Molnar 
---
 drivers/firmware/efi/libstub/arm32-stub.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/drivers/firmware/efi/libstub/arm32-stub.c 
b/drivers/firmware/efi/libstub/arm32-stub.c
index 495ebd6..6f42be4 100644
--- a/drivers/firmware/efi/libstub/arm32-stub.c
+++ b/drivers/firmware/efi/libstub/arm32-stub.c
@@ -9,6 +9,23 @@
 #include 
 #include 
 
+efi_status_t check_platform_features(efi_system_table_t *sys_table_arg)
+{
+   int block;
+
+   /* non-LPAE kernels can run anywhere */
+   if (!IS_ENABLED(CONFIG_ARM_LPAE))
+   return EFI_SUCCESS;
+
+   /* LPAE kernels need compatible hardware */
+   block = cpuid_feature_extract(CPUID_EXT_MMFR0, 0);
+   if (block < 5) {
+   pr_efi_err(sys_table_arg, "This LPAE kernel is not supported by 
your CPU\n");
+   return EFI_UNSUPPORTED;
+   }
+   return EFI_SUCCESS;
+}
+
 efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
 unsigned long *image_addr,
 unsigned long *image_size,


Re: [tip:x86/platform] x86/platform/intel/quark: Change the kernel's IMR lock bit to false

2016-02-23 Thread Peter Zijlstra
On Tue, Feb 23, 2016 at 12:54:40AM -0800, 
=?UTF-8?B?InRpcC1ib3QgZm9yIEJyeWFuIE8nRG9ub2dodWUiIDx0aXBib3RAenl0b3IuY28=?=.=?UTF-8?B?bT4=?=@zytor.com
 wrote:

I'm not sure what happened here, but mutt is completely incapable of
viewing this message.

I also tried a GUI mail client, and that too choked on it.


[tip:efi/core] efi/runtime-wrappers: Run UEFI Runtime Services with interrupts enabled

2016-02-23 Thread tip-bot for Ard Biesheuvel
Commit-ID:  fe3244945c47161e2486412d6412c87ba279305d
Gitweb: http://git.kernel.org/tip/fe3244945c47161e2486412d6412c87ba279305d
Author: Ard Biesheuvel 
AuthorDate: Wed, 17 Feb 2016 12:35:55 +
Committer:  Ingo Molnar 
CommitDate: Mon, 22 Feb 2016 08:26:25 +0100

efi/runtime-wrappers: Run UEFI Runtime Services with interrupts enabled

The UEFI spec allows Runtime Services to be invoked with interrupts
enabled. The only reason we were disabling interrupts was to prevent
recursive calls into the services on the same CPU, which will lead to
deadlock. However, the only context where such invocations may occur
legally is from efi-pstore via efivars, and that code has been updated
to call a non-blocking alternative when invoked from a non-interruptible
context.

So instead, update the ordinary, blocking UEFI Runtime Services wrappers
to execute with interrupts enabled. This aims to prevent excessive interrupt
latencies on uniprocessor platforms with slow variable stores.

Note that other OSes such as Windows call UEFI Runtime Services with
interrupts enabled as well.

Signed-off-by: Ard Biesheuvel 
Signed-off-by: Matt Fleming 
Cc: Andy Lutomirski 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Sai Praneeth Prakhya 
Cc: Thomas Gleixner 
Cc: linux-...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1455712566-16727-3-git-send-email-m...@codeblueprint.co.uk
Signed-off-by: Ingo Molnar 
---
 drivers/firmware/efi/runtime-wrappers.c | 71 +
 1 file changed, 28 insertions(+), 43 deletions(-)

diff --git a/drivers/firmware/efi/runtime-wrappers.c 
b/drivers/firmware/efi/runtime-wrappers.c
index 7b8b2f2..de69530 100644
--- a/drivers/firmware/efi/runtime-wrappers.c
+++ b/drivers/firmware/efi/runtime-wrappers.c
@@ -63,23 +63,21 @@ static DEFINE_SPINLOCK(efi_runtime_lock);
 
 static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc)
 {
-   unsigned long flags;
efi_status_t status;
 
-   spin_lock_irqsave(&efi_runtime_lock, flags);
+   spin_lock(&efi_runtime_lock);
status = efi_call_virt(get_time, tm, tc);
-   spin_unlock_irqrestore(&efi_runtime_lock, flags);
+   spin_unlock(&efi_runtime_lock);
return status;
 }
 
 static efi_status_t virt_efi_set_time(efi_time_t *tm)
 {
-   unsigned long flags;
efi_status_t status;
 
-   spin_lock_irqsave(&efi_runtime_lock, flags);
+   spin_lock(&efi_runtime_lock);
status = efi_call_virt(set_time, tm);
-   spin_unlock_irqrestore(&efi_runtime_lock, flags);
+   spin_unlock(&efi_runtime_lock);
return status;
 }
 
@@ -87,23 +85,21 @@ static efi_status_t virt_efi_get_wakeup_time(efi_bool_t 
*enabled,
 efi_bool_t *pending,
 efi_time_t *tm)
 {
-   unsigned long flags;
efi_status_t status;
 
-   spin_lock_irqsave(&efi_runtime_lock, flags);
+   spin_lock(&efi_runtime_lock);
status = efi_call_virt(get_wakeup_time, enabled, pending, tm);
-   spin_unlock_irqrestore(&efi_runtime_lock, flags);
+   spin_unlock(&efi_runtime_lock);
return status;
 }
 
 static efi_status_t virt_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t 
*tm)
 {
-   unsigned long flags;
efi_status_t status;
 
-   spin_lock_irqsave(&efi_runtime_lock, flags);
+   spin_lock(&efi_runtime_lock);
status = efi_call_virt(set_wakeup_time, enabled, tm);
-   spin_unlock_irqrestore(&efi_runtime_lock, flags);
+   spin_unlock(&efi_runtime_lock);
return status;
 }
 
@@ -113,13 +109,12 @@ static efi_status_t virt_efi_get_variable(efi_char16_t 
*name,
  unsigned long *data_size,
  void *data)
 {
-   unsigned long flags;
efi_status_t status;
 
-   spin_lock_irqsave(&efi_runtime_lock, flags);
+   spin_lock(&efi_runtime_lock);
status = efi_call_virt(get_variable, name, vendor, attr, data_size,
   data);
-   spin_unlock_irqrestore(&efi_runtime_lock, flags);
+   spin_unlock(&efi_runtime_lock);
return status;
 }
 
@@ -127,12 +122,11 @@ static efi_status_t virt_efi_get_next_variable(unsigned 
long *name_size,
   efi_char16_t *name,
   efi_guid_t *vendor)
 {
-   unsigned long flags;
efi_status_t status;
 
-   spin_lock_irqsave(&efi_runtime_lock, flags);
+   spin_lock(&efi_runtime_lock);
status = efi_call_virt(get_next_variable, name_size, name, vendor);
-   spin_unlock_irqrestore(&efi_runtime_lock, flags);
+   spin_unlock(&efi_runtime_lock);
return status;
 }
 
@@ -142,13 +136,12 @@ static efi_status_t virt_efi_set_variable(efi_char16_t 
*name,
  unsigned long data_size,
  void *data)
 {
-  

[tip:efi/core] efi/arm64: Drop __init annotation from handle_kernel_image()

2016-02-23 Thread tip-bot for Ard Biesheuvel
Commit-ID:  dae31fd2b74c35cc84128733bc210bf6b26ae408
Gitweb: http://git.kernel.org/tip/dae31fd2b74c35cc84128733bc210bf6b26ae408
Author: Ard Biesheuvel 
AuthorDate: Wed, 17 Feb 2016 12:35:57 +
Committer:  Ingo Molnar 
CommitDate: Mon, 22 Feb 2016 08:26:26 +0100

efi/arm64: Drop __init annotation from handle_kernel_image()

After moving arm64-stub.c to libstub/, all of its sections are emitted
as .init.xxx sections automatically, and the __init annotation of
handle_kernel_image() causes it to end up in .init.init.text, which is
not recognized as an __init section by the linker scripts. So drop the
annotation.

Tested-by: Mark Rutland 
Signed-off-by: Ard Biesheuvel 
Signed-off-by: Matt Fleming 
Acked-by: Will Deacon 
Acked-by: Mark Rutland 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1455712566-16727-5-git-send-email-m...@codeblueprint.co.uk
Signed-off-by: Ingo Molnar 
---
 drivers/firmware/efi/libstub/arm64-stub.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/firmware/efi/libstub/arm64-stub.c 
b/drivers/firmware/efi/libstub/arm64-stub.c
index 78dfbd3..9e03427 100644
--- a/drivers/firmware/efi/libstub/arm64-stub.c
+++ b/drivers/firmware/efi/libstub/arm64-stub.c
@@ -13,13 +13,13 @@
 #include 
 #include 
 
-efi_status_t __init handle_kernel_image(efi_system_table_t *sys_table_arg,
-   unsigned long *image_addr,
-   unsigned long *image_size,
-   unsigned long *reserve_addr,
-   unsigned long *reserve_size,
-   unsigned long dram_base,
-   efi_loaded_image_t *image)
+efi_status_t handle_kernel_image(efi_system_table_t *sys_table_arg,
+unsigned long *image_addr,
+unsigned long *image_size,
+unsigned long *reserve_addr,
+unsigned long *reserve_size,
+unsigned long dram_base,
+efi_loaded_image_t *image)
 {
efi_status_t status;
unsigned long kernel_size, kernel_memsize = 0;


[tip:efi/core] arm64/vmlinux.lds.S: Handle .init.rodata.xxx and .init.bss sections

2016-02-23 Thread tip-bot for Ard Biesheuvel
Commit-ID:  1ce99bf45306ba889faadced6baabebf7770c546
Gitweb: http://git.kernel.org/tip/1ce99bf45306ba889faadced6baabebf7770c546
Author: Ard Biesheuvel 
AuthorDate: Wed, 17 Feb 2016 12:35:58 +
Committer:  Ingo Molnar 
CommitDate: Mon, 22 Feb 2016 08:26:26 +0100

arm64/vmlinux.lds.S: Handle .init.rodata.xxx and .init.bss sections

The EFI stub is typically built into the decompressor (x86, ARM) so none
of its symbols are annotated as __init. However, on arm64, the stub is
linked into the kernel proper, and the code is __init annotated at the
section level by prepending all names of SHF_ALLOC sections with '.init'.

This results in section names like .init.rodata.str1.8 (for string literals)
and .init.bss (which is tiny), both of which can be moved into the .init.data
output section.

Tested-by: Mark Rutland 
Signed-off-by: Ard Biesheuvel 
Signed-off-by: Matt Fleming 
Acked-by: Will Deacon 
Acked-by: Mark Rutland 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1455712566-16727-6-git-send-email-m...@codeblueprint.co.uk
Signed-off-by: Ingo Molnar 
---
 arch/arm64/kernel/vmlinux.lds.S | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
index e3928f5..cbf4db4 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -134,6 +134,7 @@ SECTIONS
CON_INITCALL
SECURITY_INITCALL
INIT_RAM_FS
+   *(.init.rodata.* .init.bss) /* from the EFI stub */
}
.exit.data : {
ARM_EXIT_KEEP(EXIT_DATA)


[tip:x86/debug] sched/x86: Add stack frame dependency to __preempt_schedule[_notrace]()

2016-02-23 Thread tip-bot for Josh Poimboeuf
Commit-ID:  b5429dac54a31359e508add8572ebe8d29b8cbdb
Gitweb: http://git.kernel.org/tip/b5429dac54a31359e508add8572ebe8d29b8cbdb
Author: Josh Poimboeuf 
AuthorDate: Thu, 18 Feb 2016 11:41:58 -0600
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 09:04:01 +0100

sched/x86: Add stack frame dependency to __preempt_schedule[_notrace]()

If __preempt_schedule() or __preempt_schedule_notrace() is referenced at
the beginning of a function, gcc can insert the asm inline "call
___preempt_schedule[_notrace]" instruction before setting up a stack
frame, which breaks frame pointer convention if CONFIG_FRAME_POINTER is
enabled and can result in bad stack traces.

Force a stack frame to be created if CONFIG_FRAME_POINTER is enabled by
listing the stack pointer as an output operand for the inline asm
statements.

Specifically this fixes the following stacktool warnings:

  stacktool: drivers/scsi/hpsa.o: hpsa_scsi_do_simple_cmd.constprop.106()+0x79: 
call without frame pointer save/setup
  stacktool: fs/mbcache.o: mb_cache_entry_find_first()+0x70: call without frame 
pointer save/setup
  stacktool: fs/mbcache.o: mb_cache_entry_find_first()+0x92: call without frame 
pointer save/setup
  stacktool: fs/mbcache.o: mb_cache_entry_free()+0xff: call without frame 
pointer save/setup
  stacktool: fs/mbcache.o: mb_cache_entry_free()+0xf5: call without frame 
pointer save/setup
  stacktool: fs/mbcache.o: mb_cache_entry_free()+0x11a: call without frame 
pointer save/setup
  stacktool: fs/mbcache.o: mb_cache_entry_get()+0x225: call without frame 
pointer save/setup
  stacktool: kernel/locking/percpu-rwsem.o: percpu_up_read()+0x27: call without 
frame pointer save/setup
  stacktool: kernel/profile.o: do_profile_hits.isra.5()+0x139: call without 
frame pointer save/setup
  stacktool: lib/nmi_backtrace.o: nmi_trigger_all_cpu_backtrace()+0x2b6: call 
without frame pointer save/setup
  stacktool: net/rds/ib_cm.o: rds_ib_cq_comp_handler_recv()+0x58: call without 
frame pointer save/setup
  stacktool: net/rds/ib_cm.o: rds_ib_cq_comp_handler_send()+0x58: call without 
frame pointer save/setup
  stacktool: net/rds/ib_recv.o: rds_ib_attempt_ack()+0xc1: call without frame 
pointer save/setup
  stacktool: net/rds/iw_recv.o: rds_iw_attempt_ack()+0xc1: call without frame 
pointer save/setup
  stacktool: net/rds/iw_recv.o: rds_iw_recv_cq_comp_handler()+0x55: call 
without frame pointer save/setup

So it only adds a stack frame to 15 call sites out of ~5000 calls to
___preempt_schedule[_notrace]().  All the others already had stack frames.

Oddly, this change actually seems to make things faster in a lot of
cases.  For many smaller functions it causes the stack frame creation to
get moved out of the common path and into the unlikely path.

For example, here's the original cyc2ns_read_end():

  8101f8c0 :
  8101f8c0: 55  push   %rbp
  8101f8c1: 48 89 e5mov%rsp,%rbp
  8101f8c4: 83 6f 10 01 subl   $0x1,0x10(%rdi)
  8101f8c8: 75 08   jne8101f8d2 

  8101f8ca: 65 48 89 3d e6 5a ffmov
%rdi,%gs:0x7eff5ae6(%rip)# 153b8 
  8101f8d1: 7e
  8101f8d2: 65 ff 0d 77 c4 fe 7edecl   %gs:0x7efec477(%rip) 
   # bd50 <__preempt_count>
  8101f8d9: 74 02   je 8101f8dd 

  8101f8db: 5d  pop%rbp
  8101f8dc: c3  retq
  8101f8dd: e8 1e 37 fe ff  callq  81003000 
<___preempt_schedule>
  8101f8e2: 5d  pop%rbp
  8101f8e3: c3  retq
  8101f8e4: 66 66 66 2e 0f 1f 84data16 data16 nopw 
%cs:0x0(%rax,%rax,1)
  8101f8eb: 00 00 00 00 00

And here's the same function with the patch:

  8101f8c0 :
  8101f8c0: 83 6f 10 01 subl   $0x1,0x10(%rdi)
  8101f8c4: 75 08   jne8101f8ce 

  8101f8c6: 65 48 89 3d ea 5a ffmov
%rdi,%gs:0x7eff5aea(%rip)# 153b8 
  8101f8cd: 7e
  8101f8ce: 65 ff 0d 7b c4 fe 7edecl   %gs:0x7efec47b(%rip) 
   # bd50 <__preempt_count>
  8101f8d5: 74 01   je 8101f8d8 

  8101f8d7: c3  retq
  8101f8d8: 55  push   %rbp
  8101f8d9: 48 89 e5mov%rsp,%rbp
  8101f8dc: e8 1f 37 fe ff  callq  81003000 
<___preempt_schedule>
  8101f8e1: 5d  pop%rbp
  8101f8e2: c3  retq
  8101f8e3: 66 66 66 66 2e 0f 1fdata16 data16 data16 nopw 
%cs:0x0(%rax,%rax,1)
  8101f8ea: 84 00 00 00 00 00

Notice that it moved the frame pointer setup code to the unlikely
___preempt_schedule() call 

[tip:x86/platform] x86/platform/intel/quark: Change the kernel's IMR lock bit to false

2016-02-23 Thread tip-bot for Bryan O'Donoghue
Commit-ID:  dd71a17b1193dd4a4c35ecd0ba227aac3d110836
Gitweb: http://git.kernel.org/tip/dd71a17b1193dd4a4c35ecd0ba227aac3d110836
Author: Bryan O'Donoghue 
AuthorDate: Tue, 23 Feb 2016 01:29:58 +
Committer:  Ingo Molnar 
CommitDate: Tue, 23 Feb 2016 07:35:53 +0100

x86/platform/intel/quark: Change the kernel's IMR lock bit to false

Currently when setting up an IMR around the kernel's .text section we lock
that IMR, preventing further modification. While superficially this appears
to be the right thing to do, in fact this doesn't account for a legitimate
change in the memory map such as when executing a new kernel via kexec.

In such a scenario a second kernel can have a different size and location
to it's predecessor and can view some of the memory occupied by it's
predecessor as legitimately usable DMA RAM. If this RAM were then
subsequently allocated to DMA agents within the system it could conceivably
trigger an IMR violation.

This patch fixes the this potential situation by keeping the kernel's .text
section IMR lock bit false by default.

Suggested-by: Ingo Molnar 
Reported-by: Andy Shevchenko 
Signed-off-by: Bryan O'Donoghue 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: boon.leong@intel.com
Cc: paul.gortma...@windriver.com
Link: 
http://lkml.kernel.org/r/1456190999-12685-2-git-send-email-pure.lo...@nexus-software.ie
Signed-off-by: Ingo Molnar 
---
 arch/x86/platform/intel-quark/imr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/platform/intel-quark/imr.c 
b/arch/x86/platform/intel-quark/imr.c
index c61b6c3..bfadcd0 100644
--- a/arch/x86/platform/intel-quark/imr.c
+++ b/arch/x86/platform/intel-quark/imr.c
@@ -592,14 +592,14 @@ static void __init imr_fixup_memmap(struct imr_device 
*idev)
end = (unsigned long)__end_rodata - 1;
 
/*
-* Setup a locked IMR around the physical extent of the kernel
+* Setup an unlocked IMR around the physical extent of the kernel
 * from the beginning of the .text secton to the end of the
 * .rodata section as one physically contiguous block.
 *
 * We don't round up @size since it is already PAGE_SIZE aligned.
 * See vmlinux.lds.S for details.
 */
-   ret = imr_add_range(base, size, IMR_CPU, IMR_CPU, true);
+   ret = imr_add_range(base, size, IMR_CPU, IMR_CPU, false);
if (ret < 0) {
pr_err("unable to setup IMR for kernel: %zu KiB (%lx - %lx)\n",
size / 1024, start, end);


[PATCH] clk: shmobile: check for failure

2016-02-23 Thread Sudip Mukherjee
We were not checking the return from devm_add_action() which can fail.
Start using the helper devm_add_action_or_reset() and return directly
as we know that the cleanup has been done by this helper.

Signed-off-by: Sudip Mukherjee 
---

I think this will go throuh clk tree, so this doesnot have to wait as
devm_add_action_or_reset() is already in clk tree.

 drivers/clk/shmobile/renesas-cpg-mssr.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/shmobile/renesas-cpg-mssr.c 
b/drivers/clk/shmobile/renesas-cpg-mssr.c
index 9a4d888..925b600 100644
--- a/drivers/clk/shmobile/renesas-cpg-mssr.c
+++ b/drivers/clk/shmobile/renesas-cpg-mssr.c
@@ -568,7 +568,11 @@ static int __init cpg_mssr_probe(struct platform_device 
*pdev)
if (error)
return error;
 
-   devm_add_action(dev, cpg_mssr_del_clk_provider, np);
+   error = devm_add_action_or_reset(dev,
+cpg_mssr_del_clk_provider,
+np);
+   if (error)
+   return error;
 
error = cpg_mssr_add_clk_domain(dev, info->core_pm_clks,
info->num_core_pm_clks);
-- 
1.9.1



Re: [PATCH v3 4/5] ACPI / processor_idle : introduce ARCH_SUPPORTS_ACPI_PROCESSOR_CSTATE

2016-02-23 Thread Sudeep Holla



On 22/02/16 23:28, Rafael J. Wysocki wrote:

On Mon, Feb 22, 2016 at 2:46 PM, Sudeep Holla  wrote:

Hi Rafael,

On 17/02/16 12:21, Sudeep Holla wrote:


[...]



Whatever alternative methods I tried so far ended up much horrible than
this. So any suggestions are much appreciated.


Well, you have to give me some time here, sorry.



Sorry for the nag.


I'm still not done with cpufreq at this point and it's going to
consume some more cycles I'm afraid.



I understand, will wait patiently :)

--
Regards,
Sudeep


  1   2   3   4   5   6   7   8   9   10   >