[PATCH v6 0/4] Support accelerometers for veyron_minnie

2019-07-15 Thread Gwendal Grignou
veyron_minnie - ASUS Chromebook Flip C100PA - embedded controller
controls two accelerometers, one in the lid, one in the base.
However, the EC firmware does not follow the new interface that
cros_ec_accel driver use.
Extend the legacy driver used on glimmer - Lenovo ThinkPad 11e
Chromebook - to veyron_minnie.
veyron_minnie being ARM based, issue command over the I2C bus to the EC
instead of relying on the shared registers over LPC.

Gwendal Grignou (4):
  iio: cros_ec: Add sign vector in core for backward compatibility
  iio: cros_ec_accel_legacy: Fix incorrect channel setting
  iio: cros_ec_accel_legacy: Use cros_ec_sensors_core
  iio: cros_ec_accel_legacy: Add support for veyron-minnie

Changes in v5:
- In "Use cros_ec_sensors_core", fix return without unlock on the error
  path properly.

Changes in v5:
- In "Use cros_ec_sensors_core", fix return without unlock on the error
  path.
- Add acked for the last 2 patches.

Changes in v4:
- No change in iio/common/cros_ec_sensors
- Split cros_ec_accel_legacy code in 3:
  - fix an error in channel setting.
  - remove duplicate code in cros_ec_accel, use cros_ec_sensors_core.
  - extend cros_ec_accel to ARM device.
- Define cros_ec_accel_legacy_read_cmd() as static.

Changes in v3:
- Fix commit message, add reviewed-by for first patch.

Changes in v2:
- Readd empty line to reduce amount of change in patch.
- Remove Keywords used by ChromeOS commit queue.


 drivers/iio/accel/Kconfig |   4 +-
 drivers/iio/accel/cros_ec_accel_legacy.c  | 353 --
 .../cros_ec_sensors/cros_ec_sensors_core.c|   4 +
 .../linux/iio/common/cros_ec_sensors_core.h   |   1 +
 4 files changed, 86 insertions(+), 276 deletions(-)

-- 
2.22.0.510.g264f2c817a-goog



[PATCH v6 1/4] iio: cros_ec: Add sign vector in core for backward compatibility

2019-07-15 Thread Gwendal Grignou
To allow cros_ec iio core library to be used with legacy device, add a
vector to rotate sensor data if necessary: legacy devices are not
reporting data in HTML5/Android sensor referential.

Check the data is not rotated on recent chromebooks that use the HTML5
standard to present sensor data.

Signed-off-by: Gwendal Grignou 
Reviewed-by: Douglas Anderson 
---
 drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c | 4 
 include/linux/iio/common/cros_ec_sensors_core.h   | 1 +
 2 files changed, 5 insertions(+)

diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c 
b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
index 719a0df5aeeb..e8a4d78659c8 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
@@ -66,6 +66,9 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
}
state->type = state->resp->info.type;
state->loc = state->resp->info.location;
+
+   /* Set sign vector, only used for backward compatibility. */
+   memset(state->sign, 1, CROS_EC_SENSOR_MAX_AXIS);
}
 
return 0;
@@ -254,6 +257,7 @@ static int cros_ec_sensors_read_data_unsafe(struct iio_dev 
*indio_dev,
if (ret < 0)
return ret;
 
+   *data *= st->sign[i];
data++;
}
 
diff --git a/include/linux/iio/common/cros_ec_sensors_core.h 
b/include/linux/iio/common/cros_ec_sensors_core.h
index ce16445411ac..a1c85ad4df91 100644
--- a/include/linux/iio/common/cros_ec_sensors_core.h
+++ b/include/linux/iio/common/cros_ec_sensors_core.h
@@ -71,6 +71,7 @@ struct cros_ec_sensors_core_state {
enum motionsensor_location loc;
 
s16 calib[CROS_EC_SENSOR_MAX_AXIS];
+   s8 sign[CROS_EC_SENSOR_MAX_AXIS];
 
u8 samples[CROS_EC_SAMPLE_SIZE];
 
-- 
2.22.0.510.g264f2c817a-goog



[PATCH v6 4/4] iio: cros_ec_accel_legacy: Add support for veyron-minnie

2019-07-15 Thread Gwendal Grignou
Veyron minnie embedded controller presents 2 accelerometers using an
older interface. Add function to query the data in cros_ec_accel.

Verify accelerometers on veyron-minnie are presented and working.

Signed-off-by: Gwendal Grignou 
Acked-by: Jonathan Cameron 
---
 drivers/iio/accel/cros_ec_accel_legacy.c | 40 ++--
 1 file changed, 38 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/accel/cros_ec_accel_legacy.c 
b/drivers/iio/accel/cros_ec_accel_legacy.c
index f65578c65a1c..39002cb5605d 100644
--- a/drivers/iio/accel/cros_ec_accel_legacy.c
+++ b/drivers/iio/accel/cros_ec_accel_legacy.c
@@ -5,7 +5,7 @@
  * Copyright 2017 Google, Inc
  *
  * This driver uses the memory mapper cros-ec interface to communicate
- * with the Chrome OS EC about accelerometer data.
+ * with the Chrome OS EC about accelerometer data or older commands.
  * Accelerometer access is presented through iio sysfs.
  */
 
@@ -33,6 +33,39 @@
  */
 #define ACCEL_LEGACY_NSCALE 9586168
 
+static int cros_ec_accel_legacy_read_cmd(struct iio_dev *indio_dev,
+ unsigned long scan_mask, s16 *data)
+{
+   struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
+   int ret;
+   unsigned int i;
+   u8 sensor_num;
+
+   /*
+* Read all sensor data through a command.
+* Save sensor_num, it is assumed to stay.
+*/
+   sensor_num = st->param.info.sensor_num;
+   st->param.cmd = MOTIONSENSE_CMD_DUMP;
+   st->param.dump.max_sensor_count = CROS_EC_SENSOR_LEGACY_NUM;
+   ret = cros_ec_motion_send_host_cmd(st,
+   sizeof(st->resp->dump) + CROS_EC_SENSOR_LEGACY_NUM *
+   sizeof(struct ec_response_motion_sensor_data));
+   st->param.info.sensor_num = sensor_num;
+   if (ret != 0) {
+   dev_warn(_dev->dev, "Unable to read sensor data\n");
+   return ret;
+   }
+
+   for_each_set_bit(i, _mask, indio_dev->masklength) {
+   *data = st->resp->dump.sensor[sensor_num].data[i] *
+   st->sign[i];
+   data++;
+   }
+
+   return 0;
+}
+
 static int cros_ec_accel_legacy_read(struct iio_dev *indio_dev,
 struct iio_chan_spec const *chan,
 int *val, int *val2, long mask)
@@ -150,7 +183,10 @@ static int cros_ec_accel_legacy_probe(struct 
platform_device *pdev)
indio_dev->info = _ec_accel_legacy_info;
state = iio_priv(indio_dev);
 
-   state->read_ec_sensors_data = cros_ec_sensors_read_lpc;
+   if (state->ec->cmd_readmem != NULL)
+   state->read_ec_sensors_data = cros_ec_sensors_read_lpc;
+   else
+   state->read_ec_sensors_data = cros_ec_accel_legacy_read_cmd;
 
indio_dev->channels = cros_ec_accel_legacy_channels;
indio_dev->num_channels = ARRAY_SIZE(cros_ec_accel_legacy_channels);
-- 
2.22.0.510.g264f2c817a-goog



Re: [RFC PATCH, x86]: Disable CPA cache flush for selfsnoop targets

2019-07-15 Thread Andy Lutomirski
On Mon, Jul 15, 2019 at 3:53 PM Andi Kleen  wrote:
>
> > I haven't tested on a real kernel with i915.  Does i915 really hit
> > this code path?  Does it happen more than once or twice at boot?
>
> Yes some workloads allocate/free a lot of write combined memory
> for graphics objects.
>

But where does that memory come from?  If it's from device memory
(i.e. memory that's not in the kernel direct map), then, unless I
missed something, we're never changing the cache mode per se -- we're
just ioremap_wc-ing it, which doesn't require a flush.

IOW I'm wondering if there's any workload where this patch makes a difference.


Re: [RFC PATCH] virtio_ring: Use DMA API if guest memory is encrypted

2019-07-15 Thread Thiago Jung Bauermann


Michael S. Tsirkin  writes:

> On Mon, Jul 15, 2019 at 07:03:03PM -0300, Thiago Jung Bauermann wrote:
>> 
>> Michael S. Tsirkin  writes:
>> 
>> > On Mon, Jul 15, 2019 at 05:29:06PM -0300, Thiago Jung Bauermann wrote:
>> >>
>> >> Michael S. Tsirkin  writes:
>> >>
>> >> > On Sun, Jul 14, 2019 at 02:51:18AM -0300, Thiago Jung Bauermann wrote:
>> >> >>
>> >> >>
>> >> >> Michael S. Tsirkin  writes:
>> >> >>
>> >> >> > So this is what I would call this option:
>> >> >> >
>> >> >> > VIRTIO_F_ACCESS_PLATFORM_IDENTITY_ADDRESS
>> >> >> >
>> >> >> > and the explanation should state that all device
>> >> >> > addresses are translated by the platform to identical
>> >> >> > addresses.
>> >> >> >
>> >> >> > In fact this option then becomes more, not less restrictive
>> >> >> > than VIRTIO_F_ACCESS_PLATFORM - it's a promise
>> >> >> > by guest to only create identity mappings,
>> >> >> > and only before driver_ok is set.
>> >> >> > This option then would always be negotiated together with
>> >> >> > VIRTIO_F_ACCESS_PLATFORM.
>> >> >> >
>> >> >> > Host then must verify that
>> >> >> > 1. full 1:1 mappings are created before driver_ok
>> >> >> > or can we make sure this happens before features_ok?
>> >> >> > that would be ideal as we could require that features_ok fails
>> >> >> > 2. mappings are not modified between driver_ok and reset
>> >> >> > i guess attempts to change them will fail -
>> >> >> > possibly by causing a guest crash
>> >> >> > or some other kind of platform-specific error
>> >> >>
>> >> >> I think VIRTIO_F_ACCESS_PLATFORM_IDENTITY_ADDRESS is good, but 
>> >> >> requiring
>> >> >> it to be accompanied by ACCESS_PLATFORM can be a problem. One reason is
>> >> >> SLOF as I mentioned above, another is that we would be requiring all
>> >> >> guests running on the machine (secure guests or not, since we would use
>> >> >> the same configuration for all guests) to support it. But
>> >> >> ACCESS_PLATFORM is relatively recent so it's a bit early for that. For
>> >> >> instance, Ubuntu 16.04 LTS (which is still supported) doesn't know 
>> >> >> about
>> >> >> it and wouldn't be able to use the device.
>> >> >
>> >> > OK and your target is to enable use with kernel drivers within
>> >> > guests, right?
>> >>
>> >> Right.
>> >>
>> >> > My question is, we are defining a new flag here, I guess old guests
>> >> > then do not set it. How does it help old guests? Or maybe it's
>> >> > not designed to ...
>> >>
>> >> Indeed. The idea is that QEMU can offer the flag, old guests can reject
>> >> it (or even new guests can reject it, if they decide not to convert into
>> >> secure VMs) and the feature negotiation will succeed with the flag
>> >> unset.
>> >
>> > OK. And then what does QEMU do? Assume guest is not encrypted I guess?
>> 
>> There's nothing different that QEMU needs to do, with or without the
>> flag. the perspective of the host, a secure guest and a regular guest
>> work the same way with respect to virtio.
>
> OK. So now let's get back to implementation. What will
> Linux guest driver do? It can't activate DMA API blindly since that
> will assume translation also works, right?

It can on pseries, because we always have a 1:1 window mapping the whole
guest memory.

> Or do we somehow limit it to just a specific platform?

Yes, we want to accept the new flag only on secure pseries guests.

-- 
Thiago Jung Bauermann
IBM Linux Technology Center



[PATCH] dt-bindings: Ensure child nodes are of type 'object'

2019-07-15 Thread Rob Herring
Properties which are child node definitions need to have an explict
type. Otherwise, a matching (DT) property can silently match when an
error is desired. Fix this up tree-wide. Once this is fixed, the
meta-schema will enforce this on any child node definitions.

Cc: Maxime Ripard 
Cc: Chen-Yu Tsai 
Cc: David Woodhouse 
Cc: Brian Norris 
Cc: Marek Vasut 
Cc: Miquel Raynal 
Cc: Richard Weinberger 
Cc: Vignesh Raghavendra 
Cc: Linus Walleij 
Cc: Maxime Coquelin 
Cc: Alexandre Torgue 
Cc: Mark Brown 
Cc: linux-...@lists.infradead.org
Cc: linux-g...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-...@vger.kernel.org
Signed-off-by: Rob Herring 
---
Please ack. I will take this via the DT tree.

Rob

 .../devicetree/bindings/bus/allwinner,sun8i-a23-rsb.yaml   | 1 +
 .../devicetree/bindings/mtd/allwinner,sun4i-a10-nand.yaml  | 1 +
 Documentation/devicetree/bindings/mtd/nand-controller.yaml | 1 +
 .../devicetree/bindings/pinctrl/st,stm32-pinctrl.yaml  | 3 +++
 .../devicetree/bindings/spi/allwinner,sun4i-a10-spi.yaml   | 1 +
 .../devicetree/bindings/spi/allwinner,sun6i-a31-spi.yaml   | 1 +
 6 files changed, 8 insertions(+)

diff --git a/Documentation/devicetree/bindings/bus/allwinner,sun8i-a23-rsb.yaml 
b/Documentation/devicetree/bindings/bus/allwinner,sun8i-a23-rsb.yaml
index fc2f63860cc8..be32f087c529 100644
--- a/Documentation/devicetree/bindings/bus/allwinner,sun8i-a23-rsb.yaml
+++ b/Documentation/devicetree/bindings/bus/allwinner,sun8i-a23-rsb.yaml
@@ -42,6 +42,7 @@ properties:
 
 patternProperties:
   "^.*@[0-9a-fA-F]+$":
+type: object
 properties:
   reg:
 maxItems: 1
diff --git 
a/Documentation/devicetree/bindings/mtd/allwinner,sun4i-a10-nand.yaml 
b/Documentation/devicetree/bindings/mtd/allwinner,sun4i-a10-nand.yaml
index e5a411518be1..b5b3cf5b1ac2 100644
--- a/Documentation/devicetree/bindings/mtd/allwinner,sun4i-a10-nand.yaml
+++ b/Documentation/devicetree/bindings/mtd/allwinner,sun4i-a10-nand.yaml
@@ -55,6 +55,7 @@ patternProperties:
   "^pinctrl-[0-9]+$": true
 
   "^nand@[a-f0-9]+$":
+type: object
 properties:
   reg:
 minimum: 0
diff --git a/Documentation/devicetree/bindings/mtd/nand-controller.yaml 
b/Documentation/devicetree/bindings/mtd/nand-controller.yaml
index 199ba5ac2a06..d261b7096c69 100644
--- a/Documentation/devicetree/bindings/mtd/nand-controller.yaml
+++ b/Documentation/devicetree/bindings/mtd/nand-controller.yaml
@@ -40,6 +40,7 @@ properties:
 
 patternProperties:
   "^nand@[a-f0-9]$":
+type: object
 properties:
   reg:
 description:
diff --git a/Documentation/devicetree/bindings/pinctrl/st,stm32-pinctrl.yaml 
b/Documentation/devicetree/bindings/pinctrl/st,stm32-pinctrl.yaml
index 06c4b66c3ee6..3ac5d2088e49 100644
--- a/Documentation/devicetree/bindings/pinctrl/st,stm32-pinctrl.yaml
+++ b/Documentation/devicetree/bindings/pinctrl/st,stm32-pinctrl.yaml
@@ -55,6 +55,7 @@ properties:
 
 patternProperties:
   '^gpio@[0-9a-f]*$':
+type: object
 properties:
   gpio-controller: true
   '#gpio-cells':
@@ -113,8 +114,10 @@ patternProperties:
   - st,bank-name
 
   '-[0-9]*$':
+type: object
 patternProperties:
   '^pins':
+type: object
 description: |
   A pinctrl node should contain at least one subnode representing the
   pinctrl group available on the machine. Each subnode will list the
diff --git a/Documentation/devicetree/bindings/spi/allwinner,sun4i-a10-spi.yaml 
b/Documentation/devicetree/bindings/spi/allwinner,sun4i-a10-spi.yaml
index c374fd4923a6..6d1329c28170 100644
--- a/Documentation/devicetree/bindings/spi/allwinner,sun4i-a10-spi.yaml
+++ b/Documentation/devicetree/bindings/spi/allwinner,sun4i-a10-spi.yaml
@@ -50,6 +50,7 @@ properties:
 
 patternProperties:
   "^.*@[0-9a-f]+":
+type: object
 properties:
   reg:
 items:
diff --git a/Documentation/devicetree/bindings/spi/allwinner,sun6i-a31-spi.yaml 
b/Documentation/devicetree/bindings/spi/allwinner,sun6i-a31-spi.yaml
index bda7a5befd8b..f36c46d236d7 100644
--- a/Documentation/devicetree/bindings/spi/allwinner,sun6i-a31-spi.yaml
+++ b/Documentation/devicetree/bindings/spi/allwinner,sun6i-a31-spi.yaml
@@ -55,6 +55,7 @@ properties:
 
 patternProperties:
   "^.*@[0-9a-f]+":
+type: object
 properties:
   reg:
 items:
-- 
2.20.1



Re: [PATCH v1 2/2] clk: qcom : dispcc: Add support for display port clocks

2019-07-15 Thread Stephen Boyd
Quoting chand...@codeaurora.org (2019-02-01 16:05:55)
> On 2018-10-29 11:43, Stephen Boyd wrote:
> > Quoting Taniya Das (2018-10-28 03:34:55)
> >> On 2018-10-19 16:04, Taniya Das wrote:
> 
> >> >>
> >> >>> +static struct clk_branch disp_cc_mdss_dp_link_intf_clk = {
> >> >>> +   .halt_reg = 0x2044,
> >> >>> +   .halt_check = BRANCH_HALT,
> >> >>> +   .clkr = {
> >> >>> +   .enable_reg = 0x2044,
> >> >>> +   .enable_mask = BIT(0),
> >> >>> +   .hw.init = &(struct clk_init_data){
> >> >>> +   .name = "disp_cc_mdss_dp_link_intf_clk",
> >> >>> +   .parent_names = (const char *[]){
> >> >>> +   "disp_cc_mdss_dp_link_clk_src",
> >> >>> +   },
> >> >>> +   .num_parents = 1,
> >> >>> +   .flags = CLK_GET_RATE_NOCACHE,
> >> >>
> >> >> Why?
> >> >>
> >> >
> >> > It was a requirement, but let me get back on this too.
> >> >
> >> I had a discussion with the Display Port teams and below is the 
> >> requirement,
> >> 
> >> This flag is required since we reset/power-down the PLL every time 
> >> they
> >> disconnect/connect the DP cable or during suspend/resume.
> >> Only with this flag, the calls to the PLL driver properly.
> > 
> > Ok. So that explains the get rate nocache flag. Can you please add a
> > comment that explains that these clk registers here are lost across
> > suspend/resume of the display device? It really sounds like these
> > display clks are inside of the display power domain and thus they lose
> > their state across the display power domain power down. It would be
> > better if we could properly implement suspend/restore for these clk
> > registers across suspend/resume of the display device so that we don't
> > need this nocache flag and the display code can work together with the
> > clk code here to restore the frequency to the clk.
> 

This patch came again and it didn't have any comments to this effect in
the code around the flag.

> 
> We already handle the suspend/restore for these clk registers
> in Dp PLL domain. Without the "NOCACHE_FLAG", and if we are requesting 
> the same clock rate
> for any of the clocks, the set_rate call never reaches the DP PLL Ops.

So do you restore the frequency of the PLL manually? Or that is done by
calling clk_set_rate() on the leaf clk again?

> 
> I am not clear on what you are suggesting for removing the 
> "NOCACHE_FLAG" for
> the DisplayPort clocks. Are you suggesting design changes in DP PLL 
> driver or in dispcc-driver?
> Can you please provide more details?
> 

I'm suggesting that the clk framework needs to be told that the PLL has
lost the rate and thus should do a save/restore of the registers so that
the clk framework can be back in sync with the clk hardware. Maybe it's
as simple as calling clk_set_rate(, XO_RATE) or clk_set_parent(,
_clk), so that we can recalc the rate down the tree and fix up the
child clk frequencies. Or, maybe we need to add some sort of mechanism
to the clk framework so it can be told that the frequency here has
changed. Or we need to add a hook in the power domain for the DP PLL to
tell the clk framework that the clk has changed rate and thus should
recalc down to the children. Something like this, instead of an obtuse
flag that tells us very little about what's going on.



Re: [PATCH] mm: Proportional memory.{low,min} reclaim

2019-07-15 Thread Chris Down

Hey Andrew,

Andrew Morton writes:

On Mon, 28 Jan 2019 21:52:40 + Roman Gushchin  wrote:


> Hmm, this isn't really a common situation that I'd thought about, but it
> seems reasonable to make the boundaries when in low reclaim to be between
> min and low, rather than 0 and low. I'll add another patch with that. Thanks

It's not a stopper, so I'm perfectly fine with a follow-up patch.


Did this happen?


Yes, that's "mm, memcg: make memory.emin the baseline for utilisation 
determination" :-)



I'm still trying to get this five month old patchset unstuck :(.


Thank you for your help. The patches are stable and proven to do what they're 
intended to do at scale (both shown by the test results, and production use 
inside FB at scale).



I do have a note here that mhocko intended to take a closer look but I
don't recall whether that happened.

I could

a) say what the hell and merge them or
b) sit on them for another cycle or
c) drop them and ask Chris for a resend so we can start again.


Is there any reason to resend? As far as I know these patches are good to go.  
I'm happy to rebase them, as long as it doesn't extend the time they're being 
sat on. I don't see anything changing before the next release, though, and I 
feel any reviews are clearly not coming at this series with any urgency.


Thanks for the poke on this, I appreciate it.


Re: [PATCH V35 23/29] bpf: Restrict bpf when kernel lockdown is in confidentiality mode

2019-07-15 Thread Daniel Borkmann
On 7/15/19 9:59 PM, Matthew Garrett wrote:
> From: David Howells 
> 
> bpf_read() and bpf_read_str() could potentially be abused to (eg) allow
> private keys in kernel memory to be leaked. Disable them if the kernel
> has been locked down in confidentiality mode.
> 
> Suggested-by: Alexei Starovoitov 
> Signed-off-by: Matthew Garrett 
> cc: net...@vger.kernel.org
> cc: Chun-Yi Lee 
> cc: Alexei Starovoitov 
> Cc: Daniel Borkmann 
> ---
>  include/linux/security.h |  1 +
>  kernel/trace/bpf_trace.c | 10 ++
>  security/lockdown/lockdown.c |  1 +
>  3 files changed, 12 insertions(+)
> 
> diff --git a/include/linux/security.h b/include/linux/security.h
> index 987d8427f091..8dd1741a52cd 100644
> --- a/include/linux/security.h
> +++ b/include/linux/security.h
> @@ -118,6 +118,7 @@ enum lockdown_reason {
>   LOCKDOWN_INTEGRITY_MAX,
>   LOCKDOWN_KCORE,
>   LOCKDOWN_KPROBES,
> + LOCKDOWN_BPF_READ,
>   LOCKDOWN_CONFIDENTIALITY_MAX,
>  };
>  
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index ca1255d14576..605908da61c5 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -142,7 +142,12 @@ BPF_CALL_3(bpf_probe_read, void *, dst, u32, size, const 
> void *, unsafe_ptr)
>  {
>   int ret;
>  
> + ret = security_locked_down(LOCKDOWN_BPF_READ);
> + if (ret)
> + goto out;
> +
>   ret = probe_kernel_read(dst, unsafe_ptr, size);
> +out:
>   if (unlikely(ret < 0))
>   memset(dst, 0, size);

Hmm, does security_locked_down() ever return a code > 0 or why do you
have the double check on return code? If not, then for clarity the
ret code from security_locked_down() should be checked as 'ret < 0'
as well and out label should be at the memset directly instead.

> @@ -569,6 +574,10 @@ BPF_CALL_3(bpf_probe_read_str, void *, dst, u32, size,
>  {
>   int ret;
>  
> + ret = security_locked_down(LOCKDOWN_BPF_READ);
> + if (ret)
> + goto out;
> +
>   /*
>* The strncpy_from_unsafe() call will likely not fill the entire
>* buffer, but that's okay in this circumstance as we're probing
> @@ -579,6 +588,7 @@ BPF_CALL_3(bpf_probe_read_str, void *, dst, u32, size,
>* is returned that can be used for bpf_perf_event_output() et al.
>*/
>   ret = strncpy_from_unsafe(dst, unsafe_ptr, size);
> +out:
>   if (unlikely(ret < 0))
>   memset(dst, 0, size);

Ditto.

Thanks,
Daniel


Re: [RFC PATCH, x86]: Disable CPA cache flush for selfsnoop targets

2019-07-15 Thread Andi Kleen
> I haven't tested on a real kernel with i915.  Does i915 really hit
> this code path?  Does it happen more than once or twice at boot?

Yes some workloads allocate/free a lot of write combined memory
for graphics objects.

-Andi


Re: [PATCH v1 2/3] clk: qcom: rcg2: Add support for hardware control mode

2019-07-15 Thread Stephen Boyd
Quoting Taniya Das (2019-05-08 11:24:54)
> diff --git a/drivers/clk/qcom/clk-rcg2.c b/drivers/clk/qcom/clk-rcg2.c
> index 57dbac9..5bb6d45 100644
> --- a/drivers/clk/qcom/clk-rcg2.c
> +++ b/drivers/clk/qcom/clk-rcg2.c
> @@ -289,6 +289,9 @@ static int __clk_rcg2_configure(struct clk_rcg2 *rcg, 
> const struct freq_tbl *f)
> cfg |= rcg->parent_map[index].cfg << CFG_SRC_SEL_SHIFT;
> if (rcg->mnd_width && f->n && (f->m != f->n))
> cfg |= CFG_MODE_DUAL_EDGE;
> +   if (rcg->flags & HW_CLK_CTRL_MODE)
> +   cfg |= CFG_HW_CLK_CTRL_MASK;
> +

Above this we have commit bdc3bbdd40ba ("clk: qcom: Clear hardware clock
control bit of RCG") that clears this bit. Is it possible to always set
this bit and then have an override flag used in sdm845 that says to
_not_ set this bit? Presumably on earlier platforms writing the bit is a
no-op so it's safe to write the bit on those platforms.

This way, if it's going to be the default we can avoid setting the flag
and only set the flag on older platforms where it shouldn't be done for
some reason.

> return regmap_update_bits(rcg->clkr.regmap, RCG_CFG_OFFSET(rcg),
> mask, cfg);
>  }
> --
> Qualcomm INDIA, on behalf of Qualcomm Innovation Center, Inc.is a member
> of the Code Aurora Forum, hosted by the  Linux Foundation.
> 


Re: [PATCH v1 1/3] clk: qcom: rcg: Return failure for RCG update

2019-07-15 Thread Stephen Boyd
Quoting Taniya Das (2019-05-08 11:24:53)
> In case of update config failure, return -EBUSY, so that consumers could
> handle the failure gracefully.
> 
> Signed-off-by: Taniya Das 
> ---

Applied to clk-next



Re: [PATCH v1 3/3] clk: qcom: rcg: update the DFS macro for RCG

2019-07-15 Thread Stephen Boyd
Quoting Taniya Das (2019-05-12 20:44:46)
> On 5/10/2019 11:24 PM, Stephen Boyd wrote:
>  diff --git a/drivers/clk/qcom/clk-rcg.h b/drivers/clk/qcom/clk-rcg.h
>  index 5562f38..e40e8f8 100644
>  --- a/drivers/clk/qcom/clk-rcg.h
>  +++ b/drivers/clk/qcom/clk-rcg.h
>  @@ -171,7 +171,7 @@ struct clk_rcg_dfs_data {
> };
> 
> #define DEFINE_RCG_DFS(r) \
>  -   { .rcg = ##_src, .init = ##_init }
>  +   { .rcg = , .init = ##_init }
> >>>
> >>> Why do we need to rename the init data?
> >>>
> >>
> >> We want to manage the init data as the clock source name, so that we
> >> could manage to auto generate our code. So that we do not have to
> >> re-name the clock init data manually if the DFS source names gets
> >> updated at any point of time.
> >>
> > 
> > Why is the clk name changing to not have a _src after the "root" of the
> > clk name? As long as I can remember, RCGs have a "_src" postfix.
> > 
> 
> Yes, the RCGs would have _src, so we do want the init data also to be
> generated with _src postfix. So that we do not have to manually clean up 
> the generated code.
> 

Please manually cleanup the generated code, or fix the code
generator to do what you want.



Re: [PATCH v2 1/2] clk: qcom: rcg2: Add support for display port clock ops

2019-07-15 Thread Stephen Boyd
Quoting Taniya Das (2019-05-14 21:20:38)
> diff --git a/drivers/clk/qcom/Kconfig b/drivers/clk/qcom/Kconfig
> index 18bdf34..0de080f 100644
> --- a/drivers/clk/qcom/Kconfig
> +++ b/drivers/clk/qcom/Kconfig
> @@ -15,6 +15,7 @@ menuconfig COMMON_CLK_QCOM
> depends on ARCH_QCOM || COMPILE_TEST
> select REGMAP_MMIO
> select RESET_CONTROLLER
> +   select RATIONAL

Make this an alphabetical list of selects please.

> 
>  if COMMON_CLK_QCOM
> 
> diff --git a/drivers/clk/qcom/clk-rcg2.c b/drivers/clk/qcom/clk-rcg2.c
> index 8c02bff..98071c0 100644
> --- a/drivers/clk/qcom/clk-rcg2.c
> +++ b/drivers/clk/qcom/clk-rcg2.c
> @@ -1128,3 +1129,81 @@ int qcom_cc_register_rcg_dfs(struct regmap *regmap,
> return 0;
>  }
>  EXPORT_SYMBOL_GPL(qcom_cc_register_rcg_dfs);
> +
> +static int clk_rcg2_dp_set_rate(struct clk_hw *hw, unsigned long rate,
> +   unsigned long parent_rate)
> +{
> +   struct clk_rcg2 *rcg = to_clk_rcg2(hw);
> +   struct freq_tbl f = { 0 };
> +   u32 mask = BIT(rcg->hid_width) - 1;
> +   u32 hid_div, cfg;
> +   int i, num_parents = clk_hw_get_num_parents(hw);
> +   unsigned long num, den;
> +
> +   rational_best_approximation(parent_rate, rate,
> +   GENMASK(rcg->mnd_width - 1, 0),
> +   GENMASK(rcg->mnd_width - 1, 0), , );
> +
> +   if (!num || !den) {
> +   pr_err("Invalid MN values derived for requested rate %lu\n",

Does this ever happen? I worry that this printk could happen many times
if a driver gets into a bad state and starts selecting invalid
frequencies over and over again for each frame (every 16ms). Maybe just
return -EINVAL instead of printing anything.

> +   rate);
> +   return -EINVAL;
> +   }
> +
> +   regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG, );
> +   hid_div = cfg;
> +   cfg &= CFG_SRC_SEL_MASK;
> +   cfg >>= CFG_SRC_SEL_SHIFT;
> +
> +   for (i = 0; i < num_parents; i++)
> +   if (cfg == rcg->parent_map[i].cfg) {
> +   f.src = rcg->parent_map[i].src;
> +   break;
> +   }

Weird indent for this brace. Please fix and put a brace on the for
statement too.

> +
> +   f.pre_div = hid_div;
> +   f.pre_div >>= CFG_SRC_DIV_SHIFT;
> +   f.pre_div &= mask;
> +
> +   if (num == den) {
> +   f.m = 0;
> +   f.n = 0;

Isn't this the default? So just have if (num != den) here.

> +   } else {
> +   f.m = num;
> +   f.n = den;
> +   }
> +
> +   return clk_rcg2_configure(rcg, );
> +}
> +
> +static int clk_rcg2_dp_set_rate_and_parent(struct clk_hw *hw,
> +   unsigned long rate, unsigned long parent_rate, u8 index)
> +{
> +   return clk_rcg2_dp_set_rate(hw, rate, parent_rate);
> +}

Does this need to be implemented? The parent index isn't passed to
clk_rcg2_dp_set_rate() so I suspect the parent index doesn't matter?
Does the parent change?

> +
> +static int clk_rcg2_dp_determine_rate(struct clk_hw *hw,
> +   struct clk_rate_request *req)
> +{
> +   struct clk_rate_request parent_req = *req;
> +   int ret;
> +
> +   ret = __clk_determine_rate(clk_hw_get_parent(hw), _req);
> +   if (ret)
> +   return ret;
> +
> +   req->best_parent_rate = parent_req.rate;
> +
> +   return 0;
> +}

Do you need this op? It's just calling determine rate on the parent, so
we already do that if the proper flag is set. I'm confused about this
function.



Re: [PATCH v9] Documentation: filesystem: Convert xfs.txt to ReST

2019-07-15 Thread Sheriff Esseson
Move xfs.txt to admin-guide, convert to ReST and fix broken references.

Signed-off-by: Sheriff Esseson 
---

Changes in v9:
- fix table for "Removed Sysctls".
- "Deprecated Mount Options", just like "Deprecated Sysctls",
  currently needs no table - remove table.  

 Documentation/admin-guide/index.rst   |   1 +
 .../xfs.txt => admin-guide/xfs.rst}   | 136 +-
 Documentation/filesystems/dax.txt |   2 +-
 MAINTAINERS   |   2 +-
 4 files changed, 68 insertions(+), 73 deletions(-)
 rename Documentation/{filesystems/xfs.txt => admin-guide/xfs.rst} (80%)

diff --git a/Documentation/admin-guide/index.rst 
b/Documentation/admin-guide/index.rst
index 24fbe0568eff..0615ea3a744c 100644
--- a/Documentation/admin-guide/index.rst
+++ b/Documentation/admin-guide/index.rst
@@ -70,6 +70,7 @@ configure specific aspects of kernel behavior to your liking.
ras
bcache
ext4
+   xfs
binderfs
pm/index
thunderbolt
diff --git a/Documentation/filesystems/xfs.txt 
b/Documentation/admin-guide/xfs.rst
similarity index 80%
rename from Documentation/filesystems/xfs.txt
rename to Documentation/admin-guide/xfs.rst
index a5cbb5e0e3db..e1b412a3dd29 100644
--- a/Documentation/filesystems/xfs.txt
+++ b/Documentation/admin-guide/xfs.rst
@@ -1,4 +1,6 @@
+.. SPDX-License-Identifier: GPL-2.0
 
+==
 The SGI XFS Filesystem
 ==
 
@@ -18,8 +20,6 @@ Mount Options
 =
 
 When mounting an XFS filesystem, the following options are accepted.
-For boolean mount options, the names with the (*) suffix is the
-default behaviour.
 
   allocsize=size
Sets the buffered I/O end-of-file preallocation size when
@@ -31,46 +31,43 @@ default behaviour.
preallocation size, which uses a set of heuristics to
optimise the preallocation size based on the current
allocation patterns within the file and the access patterns
-   to the file. Specifying a fixed allocsize value turns off
+   to the file. Specifying a fixed ``allocsize`` value turns off
the dynamic behaviour.
 
-  attr2
-  noattr2
+  attr2 or noattr2
The options enable/disable an "opportunistic" improvement to
be made in the way inline extended attributes are stored
on-disk.  When the new form is used for the first time when
-   attr2 is selected (either when setting or removing extended
+   ``attr2`` is selected (either when setting or removing extended
attributes) the on-disk superblock feature bit field will be
updated to reflect this format being in use.
 
The default behaviour is determined by the on-disk feature
-   bit indicating that attr2 behaviour is active. If either
-   mount option it set, then that becomes the new default used
+   bit indicating that ``attr2`` behaviour is active. If either
+   mount option is set, then that becomes the new default used
by the filesystem.
 
-   CRC enabled filesystems always use the attr2 format, and so
-   will reject the noattr2 mount option if it is set.
+   CRC enabled filesystems always use the ``attr2`` format, and so
+   will reject the ``noattr2`` mount option if it is set.
 
-  discard
-  nodiscard (*)
+  discard or nodiscard (default)
Enable/disable the issuing of commands to let the block
device reclaim space freed by the filesystem.  This is
useful for SSD devices, thinly provisioned LUNs and virtual
machine images, but may have a performance impact.
 
-   Note: It is currently recommended that you use the fstrim
-   application to discard unused blocks rather than the discard
+   Note: It is currently recommended that you use the ``fstrim``
+   application to ``discard`` unused blocks rather than the ``discard``
mount option because the performance impact of this option
is quite severe.
 
-  grpid/bsdgroups
-  nogrpid/sysvgroups (*)
+  grpid/bsdgroups or nogrpid/sysvgroups (default)
These options define what group ID a newly created file
-   gets.  When grpid is set, it takes the group ID of the
+   gets.  When ``grpid`` is set, it takes the group ID of the
directory in which it is created; otherwise it takes the
-   fsgid of the current process, unless the directory has the
-   setgid bit set, in which case it takes the gid from the
-   parent directory, and also gets the setgid bit set if it is
+   ``fsgid`` of the current process, unless the directory has the
+   ``setgid`` bit set, in which case it takes the ``gid`` from the
+   parent directory, and also gets the ``setgid`` bit set if it is
a directory itself.
 
   filestreams
@@ -78,46 +75,42 @@ default behaviour.
across the entire filesystem rather than just on directories
configured to use it.
 
-  ikeep
-  noikeep (*)
-   When ikeep is 

Re: [patch v2] crypto: ccp - Fix SEV_VERSION_GREATER_OR_EQUAL

2019-07-15 Thread Gary R Hook
On 7/15/19 12:03 PM, Lendacky, Thomas wrote:
> On 7/12/19 3:41 PM, David Rientjes wrote:
>> SEV_VERSION_GREATER_OR_EQUAL() will fail if upgrading from 2.2 to 3.1, for
>> example, because the minor version is not equal to or greater than the
>> major.
>>
>> Fix this and move to a static inline function for appropriate type
>> checking.
>>
>> Fixes: edd303ff0e9e ("crypto: ccp - Add DOWNLOAD_FIRMWARE SEV command")
>> Reported-by: Cfir Cohen 
>> Signed-off-by: David Rientjes 
> 
> Acked-by: Tom Lendacky 

Acked-by: Gary R Hook 

> 
>> ---
>>   v2: no need to check api_major >= maj after checking api_major > maj
>>   per Thomas
>>
>>   drivers/crypto/ccp/psp-dev.c | 19 ---
>>   1 file changed, 12 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c
>> --- a/drivers/crypto/ccp/psp-dev.c
>> +++ b/drivers/crypto/ccp/psp-dev.c
>> @@ -24,10 +24,6 @@
>>   #include "sp-dev.h"
>>   #include "psp-dev.h"
>>   
>> -#define SEV_VERSION_GREATER_OR_EQUAL(_maj, _min)\
>> -((psp_master->api_major) >= _maj && \
>> - (psp_master->api_minor) >= _min)
>> -
>>   #define DEVICE_NAME"sev"
>>   #define SEV_FW_FILE"amd/sev.fw"
>>   #define SEV_FW_NAME_SIZE   64
>> @@ -47,6 +43,15 @@ MODULE_PARM_DESC(psp_probe_timeout, " default timeout 
>> value, in seconds, during
>>   static bool psp_dead;
>>   static int psp_timeout;
>>   
>> +static inline bool sev_version_greater_or_equal(u8 maj, u8 min)
>> +{
>> +if (psp_master->api_major > maj)
>> +return true;
>> +if (psp_master->api_major == maj && psp_master->api_minor >= min)
>> +return true;
>> +return false;
>> +}
>> +
>>   static struct psp_device *psp_alloc_struct(struct sp_device *sp)
>>   {
>>  struct device *dev = sp->dev;
>> @@ -588,7 +593,7 @@ static int sev_ioctl_do_get_id2(struct sev_issue_cmd 
>> *argp)
>>  int ret;
>>   
>>  /* SEV GET_ID is available from SEV API v0.16 and up */
>> -if (!SEV_VERSION_GREATER_OR_EQUAL(0, 16))
>> +if (!sev_version_greater_or_equal(0, 16))
>>  return -ENOTSUPP;
>>   
>>  if (copy_from_user(, (void __user *)argp->data, sizeof(input)))
>> @@ -651,7 +656,7 @@ static int sev_ioctl_do_get_id(struct sev_issue_cmd 
>> *argp)
>>  int ret;
>>   
>>  /* SEV GET_ID available from SEV API v0.16 and up */
>> -if (!SEV_VERSION_GREATER_OR_EQUAL(0, 16))
>> +if (!sev_version_greater_or_equal(0, 16))
>>  return -ENOTSUPP;
>>   
>>  /* SEV FW expects the buffer it fills with the ID to be
>> @@ -1053,7 +1058,7 @@ void psp_pci_init(void)
>>  psp_master->sev_state = SEV_STATE_UNINIT;
>>  }
>>   
>> -if (SEV_VERSION_GREATER_OR_EQUAL(0, 15) &&
>> +if (sev_version_greater_or_equal(0, 15) &&
>>  sev_update_firmware(psp_master->dev) == 0)
>>  sev_get_api_version();
>>   
>>



Re: [PATCH v2 2/2] clk: qcom : dispcc: Add support for display port clocks

2019-07-15 Thread Stephen Boyd
Quoting Taniya Das (2019-05-14 21:20:39)
> @@ -128,6 +144,82 @@ enum {
> },
>  };
> 
> +static const struct freq_tbl ftbl_disp_cc_mdss_dp_aux_clk_src[] = {
> +   F(1920, P_BI_TCXO, 1, 0, 0),
> +   { }
> +};
> +
> +static struct clk_rcg2 disp_cc_mdss_dp_aux_clk_src = {
> +   .cmd_rcgr = 0x219c,
> +   .mnd_width = 0,
> +   .hid_width = 5,
> +   .parent_map = disp_cc_parent_map_2,
> +   .freq_tbl = ftbl_disp_cc_mdss_dp_aux_clk_src,
> +   .clkr.hw.init = &(struct clk_init_data){
> +   .name = "disp_cc_mdss_dp_aux_clk_src",
> +   .parent_names = disp_cc_parent_names_2,
> +   .num_parents = 2,
> +   .flags = CLK_SET_RATE_PARENT,
> +   .ops = _rcg2_ops,
> +   },
> +};
> +
> +static struct clk_rcg2 disp_cc_mdss_dp_crypto_clk_src = {
> +   .cmd_rcgr = 0x2154,
> +   .mnd_width = 0,
> +   .hid_width = 5,
> +   .parent_map = disp_cc_parent_map_1,
> +   .clkr.hw.init = &(struct clk_init_data){
> +   .name = "disp_cc_mdss_dp_crypto_clk_src",
> +   .parent_names = disp_cc_parent_names_1,
> +   .num_parents = 4,
> +   .flags = CLK_GET_RATE_NOCACHE,

Why do we need this flag on various clks here? I'd prefer this is
removed. If it can't be removed, we need to describe in a code comment
why this must be set.

If it's some sort of problem where the upstream PLL goes into bypass
across a reset, then we probably need to change the display code to
restore that rate across a reset by calling clk_set_rate() on the PLL
directly. And we might need to think about how to inform the framework
that this has happened, so that downstream clks can be notified of the
change in frequency.



Re: [PATCH] mm: Proportional memory.{low,min} reclaim

2019-07-15 Thread Andrew Morton
On Mon, 28 Jan 2019 21:52:40 + Roman Gushchin  wrote:

> > Hmm, this isn't really a common situation that I'd thought about, but it
> > seems reasonable to make the boundaries when in low reclaim to be between
> > min and low, rather than 0 and low. I'll add another patch with that. Thanks
>
> It's not a stopper, so I'm perfectly fine with a follow-up patch.

Did this happen?


I'm still trying to get this five month old patchset unstuck :(.  The
review status is: 

[1/3] mm, memcg: proportional memory.{low,min} reclaim
Acked-by: Johannes
Reviewed-by: Roman

[2/3] mm, memcg: make memory.emin the baseline for utilisation determination
Acked-by: Johannes

[3/3] mm, memcg: make scan aggression always exclude protection
Reviewed-by: Roman


I do have a note here that mhocko intended to take a closer look but I
don't recall whether that happened.

I could

a) say what the hell and merge them or
b) sit on them for another cycle or
c) drop them and ask Chris for a resend so we can start again.


Re: [PATCH 4/6] kvm: lapic: Add apicv activate/deactivate helper function

2019-07-15 Thread Suthikulpanit, Suravee
Jan,

On 5/8/2019 5:27 PM, Jan H. Schönherr wrote:
> On 22/03/2019 12.57, Suthikulpanit, Suravee wrote:
>> Introduce a helper function for setting lapic parameters when
>> activate/deactivate apicv.
>>
>> Signed-off-by: Suravee Suthikulpanit
>> ---
>>   arch/x86/kvm/lapic.c | 23 ++-
>>   arch/x86/kvm/lapic.h |  1 +
>>   2 files changed, 19 insertions(+), 5 deletions(-)
>>
>> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
>> index 95295cf81283..9c5cd1a98928 100644
>> --- a/arch/x86/kvm/lapic.c
>> +++ b/arch/x86/kvm/lapic.c
>> @@ -2126,6 +2126,22 @@ void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 
>> value)
>>
>>   }
>>
>> +void kvm_apic_update_apicv(struct kvm_vcpu *vcpu)
>> +{
>> + struct kvm_lapic *apic = vcpu->arch.apic;
>> + bool active = vcpu->arch.apicv_active;
>> +
>> + if (active) {
>> + /* irr_pending is always true when apicv is activated. */
>> + apic->irr_pending = true;
>> + apic->isr_count = 1;
>> + } else {
>> + apic->irr_pending = !!count_vectors(apic->regs + APIC_IRR);
> What about:
>  apic->irr_pending = apic_search_irr(apic) != -1;
> instead? (more in line with the logic in apic_clear_irr())

Sure, that works also.

> Related to this, I wonder if we need to ensure to execute
> kvm_x86_ops->sync_pir_to_irr() just before apicv_active transitions
> from true to false, so that we don't miss an interrupt and irr_pending
> is set correctly in this function (on Intel at least).

I'm not sure about the PIR on Intel, but AMD since AMD IOMMU hardware
directly updates the vAPIC backing page, the driver should not need
to worry.

> Hmm... there seems to be other stuff as well, that depends on
> vcpu->arch.apicv_active, which is not updated on a transition. For
> example: posted interrupts, 

You are right. We need to also handle the posted-interrupt
activate/deactivate. I am also doing this in V2.

> CR8 intercept, 

When APICv is deactivated, the update_cr8_intercept() should handle
updating of CR8 interception.

> and a potential asymmetry via avic_vcpu_load()/avic_vcpu_put()
> because the bottom half of just one of the two functions may be
> skipped
Not sure if I understand the concern that you mentioned here.
However, once we add the IOMMU activation/deactivation code for
posted-interrupt, we should not need to worry about calling
avic_update_iommu_vcpu_affinity() at the end of the functions
here.

Thanks,
Suravee
> Regards
> Jan
> 


Re: [PATCH] staging: kpc2000: whitespace and line length cleanup

2019-07-15 Thread Joe Perches
On Mon, 2019-07-15 at 14:21 -0700, john.hubb...@gmail.com wrote:
> From: John Hubbard 
> 
> This commit was created by running indent(1):
> `indent -linux`
> 
> ...and then applying some manual corrections and
> cleanup afterward, to keep it sane. No functional changes
> were made.

I don't find many of these whitespace changes "better".

Sometimes, it's just fine to have > 80 char lines.

Alignment formatting was OK before this and now has
many odd uses that make reading for a human harder
rather than simpler or easier.

> diff --git a/drivers/staging/kpc2000/kpc2000_i2c.c 
> b/drivers/staging/kpc2000/kpc2000_i2c.c
[]
> @@ -33,9 +33,9 @@ MODULE_LICENSE("GPL");
>  MODULE_AUTHOR("matt.sick...@daktronics.com");
>  
>  struct i2c_device {
> - unsigned long   smba;
> - struct i2c_adapter  adapter;
> - unsigned intfeatures;
> + unsigned long   smba;
> + struct i2c_adapter  adapter;
> + unsigned intfeatures;

Here the spaces before the identifier are converted to tab aligned 

>  };
>  
>  /*
> @@ -52,9 +52,9 @@ struct i2c_device {
>  #define SMBHSTDAT0(p)   ((5  * REG_SIZE) + (p)->smba)
>  #define SMBHSTDAT1(p)   ((6  * REG_SIZE) + (p)->smba)
>  #define SMBBLKDAT(p)((7  * REG_SIZE) + (p)->smba)
> -#define SMBPEC(p)   ((8  * REG_SIZE) + (p)->smba)   /* ICH3 and later */
> -#define SMBAUXSTS(p)((12 * REG_SIZE) + (p)->smba)   /* ICH4 and later */
> -#define SMBAUXCTL(p)((13 * REG_SIZE) + (p)->smba)   /* ICH4 and later */
> +#define SMBPEC(p)   ((8  * REG_SIZE) + (p)->smba)/* ICH3 and 
> later */
> +#define SMBAUXSTS(p)((12 * REG_SIZE) + (p)->smba)/* ICH4 and 
> later */
> +#define SMBAUXCTL(p)((13 * REG_SIZE) + (p)->smba)/* ICH4 and 
> later */

But here the #define value still has spaces but the comment uses tabs.
Why tab align the comments but not the #define value?

> @@ -136,17 +138,21 @@ static int i801_check_pre(struct i2c_device *priv)
[]
>   status &= STATUS_FLAGS;
>   if (status) {
> - //dev_dbg(>adapter.dev, "Clearing status flags (%02x)\n", 
> status);
> + //dev_dbg(>adapter.dev,
> + //"Clearing status flags (%02x)\n", status);

This was better before.

An improvement might be to add more macros like:

#define i2c_err(priv, fmt, ...)
dev_err(&(priv)->adapter.dev, fmt, ##__VA_ARGS__)
#define i2c_dbg(priv, fmt, ...)
dev_dbg(&(priv)->adapter.dev, fmt, ##__VA_ARGS__)

So all these uses of dev_(>adapter.dev, ...)
become much shorter visually and the line wrapping becomes
rather better.

>   outb_p(status, SMBHSTSTS(priv));
>   status = inb_p(SMBHSTSTS(priv)) & STATUS_FLAGS;
>   if (status) {
> - dev_err(>adapter.dev, "Failed clearing status 
> flags (%02x)\n", status);
> + dev_err(>adapter.dev,
> + "Failed clearing status flags (%02x)\n",
> + status);

e.g.:
i2c_err(priv, "Failed clearing status flags (%02x)\n",
status);

etc...


[]

> @@ -301,7 +322,8 @@ static int i801_block_transaction_byte_by_byte(struct 
> i2c_device *priv, union i2
>   else
>   smbcmd = I801_BLOCK_LAST;
>   } else {
> - if (command == I2C_SMBUS_I2C_BLOCK_DATA && read_write 
> == I2C_SMBUS_READ)
> + if (command == I2C_SMBUS_I2C_BLOCK_DATA
> + && read_write == I2C_SMBUS_READ)

logic continuations should be at EOL.

if (command == I2C_SMBUS_I2C_BLOCK_DATA &&
read_write == I2C_SMBUS_READ)

[]
> @@ -558,13 +614,14 @@ static u32 i801_func(struct i2c_adapter *adapter)
>   I2C_FUNC_SMBUS_WORD_DATA | /* _READ_WORD_DATA  
> _WRITE_WORD_DATA */
>   I2C_FUNC_SMBUS_BLOCK_DATA| /* _READ_BLOCK_DATA  
> _WRITE_BLOCK_DATA */
>   !I2C_FUNC_SMBUS_I2C_BLOCK| /* _READ_I2C_BLOCK  
> _WRITE_I2C_BLOCK */
> - !I2C_FUNC_SMBUS_EMUL;  /* _QUICK  _BYTE  _BYTE_DATA 
>  _WORD_DATA  _PROC_CALL  _WRITE_BLOCK_DATA  _I2C_BLOCK _PEC */
> + /* _QUICK  _BYTE  _BYTE_DATA  _WORD_DATA  _PROC_CALL  
> _WRITE_BLOCK_DATA  _I2C_BLOCK _PEC : */
> + !I2C_FUNC_SMBUS_EMUL;
>   return f;
>  }
>  
>  static const struct i2c_algorithm smbus_algorithm = {
> - .smbus_xfer = i801_access,
> - .functionality  = i801_func,
> + .smbus_xfer = i801_access,
> + .functionality = i801_func,

Many people prefer the aligned function names.

etc...




Re: [PATCH] staging: kpc2000: whitespace and line length cleanup

2019-07-15 Thread John Hubbard
On 7/15/19 3:21 PM, Joe Perches wrote:
> On Mon, 2019-07-15 at 14:21 -0700, john.hubb...@gmail.com wrote:
>> From: John Hubbard 
>>
>> This commit was created by running indent(1):
>> `indent -linux`
>>
>> ...and then applying some manual corrections and
>> cleanup afterward, to keep it sane. No functional changes
>> were made.
> 
> I don't find many of these whitespace changes "better".
> 
> Sometimes, it's just fine to have > 80 char lines.

Definitely agree! :)

> 
> Alignment formatting was OK before this and now has
> many odd uses that make reading for a human harder
> rather than simpler or easier.

OK, I'll accept that. I attempted to pick something that fit
on the screen [much!] better, without making it less readable, but if
people feel that it is a net "worse", then let's just drop
the patch, no problem.

> 
>> diff --git a/drivers/staging/kpc2000/kpc2000_i2c.c 
>> b/drivers/staging/kpc2000/kpc2000_i2c.c
> []
>> @@ -33,9 +33,9 @@ MODULE_LICENSE("GPL");
>>  MODULE_AUTHOR("matt.sick...@daktronics.com");
>>  
>>  struct i2c_device {
>> -unsigned long   smba;
>> -struct i2c_adapter  adapter;
>> -unsigned intfeatures;
>> +unsigned long   smba;
>> +struct i2c_adapter  adapter;
>> +unsigned intfeatures;
> 
> Here the spaces before the identifier are converted to tab aligned 
> 
>>  };
>>  
>>  /*
>> @@ -52,9 +52,9 @@ struct i2c_device {
>>  #define SMBHSTDAT0(p)   ((5  * REG_SIZE) + (p)->smba)
>>  #define SMBHSTDAT1(p)   ((6  * REG_SIZE) + (p)->smba)
>>  #define SMBBLKDAT(p)((7  * REG_SIZE) + (p)->smba)
>> -#define SMBPEC(p)   ((8  * REG_SIZE) + (p)->smba)   /* ICH3 and later */
>> -#define SMBAUXSTS(p)((12 * REG_SIZE) + (p)->smba)   /* ICH4 and later */
>> -#define SMBAUXCTL(p)((13 * REG_SIZE) + (p)->smba)   /* ICH4 and later */
>> +#define SMBPEC(p)   ((8  * REG_SIZE) + (p)->smba)   /* ICH3 and 
>> later */
>> +#define SMBAUXSTS(p)((12 * REG_SIZE) + (p)->smba)   /* ICH4 and 
>> later */
>> +#define SMBAUXCTL(p)((13 * REG_SIZE) + (p)->smba)   /* ICH4 and 
>> later */
> 
> But here the #define value still has spaces but the comment uses tabs.
> Why tab align the comments but not the #define value?
> 
>> @@ -136,17 +138,21 @@ static int i801_check_pre(struct i2c_device *priv)
> []
>>  status &= STATUS_FLAGS;
>>  if (status) {
>> -//dev_dbg(>adapter.dev, "Clearing status flags (%02x)\n", 
>> status);
>> +//dev_dbg(>adapter.dev,
>> +//"Clearing status flags (%02x)\n", status);
> 
> This was better before.
> 
> An improvement might be to add more macros like:
> 
> #define i2c_err(priv, fmt, ...)
>   dev_err(&(priv)->adapter.dev, fmt, ##__VA_ARGS__)
> #define i2c_dbg(priv, fmt, ...)
>   dev_dbg(&(priv)->adapter.dev, fmt, ##__VA_ARGS__)
> 
> So all these uses of dev_(>adapter.dev, ...)
> become much shorter visually and the line wrapping becomes
> rather better.
> 
>>  outb_p(status, SMBHSTSTS(priv));
>>  status = inb_p(SMBHSTSTS(priv)) & STATUS_FLAGS;
>>  if (status) {
>> -dev_err(>adapter.dev, "Failed clearing status 
>> flags (%02x)\n", status);
>> +dev_err(>adapter.dev,
>> +"Failed clearing status flags (%02x)\n",
>> +status);
> 
> e.g.:
>   i2c_err(priv, "Failed clearing status flags (%02x)\n",
>   status);
> 
> etc...
> 
> 
> []
> 
>> @@ -301,7 +322,8 @@ static int i801_block_transaction_byte_by_byte(struct 
>> i2c_device *priv, union i2
>>  else
>>  smbcmd = I801_BLOCK_LAST;
>>  } else {
>> -if (command == I2C_SMBUS_I2C_BLOCK_DATA && read_write 
>> == I2C_SMBUS_READ)
>> +if (command == I2C_SMBUS_I2C_BLOCK_DATA
>> +&& read_write == I2C_SMBUS_READ)
> 
> logic continuations should be at EOL.
> 
>   if (command == I2C_SMBUS_I2C_BLOCK_DATA &&
>   read_write == I2C_SMBUS_READ)
> 
> []
>> @@ -558,13 +614,14 @@ static u32 i801_func(struct i2c_adapter *adapter)
>>  I2C_FUNC_SMBUS_WORD_DATA | /* _READ_WORD_DATA  
>> _WRITE_WORD_DATA */
>>  I2C_FUNC_SMBUS_BLOCK_DATA| /* _READ_BLOCK_DATA  
>> _WRITE_BLOCK_DATA */
>>  !I2C_FUNC_SMBUS_I2C_BLOCK| /* _READ_I2C_BLOCK  
>> _WRITE_I2C_BLOCK */
>> -!I2C_FUNC_SMBUS_EMUL;  /* _QUICK  _BYTE  _BYTE_DATA 
>>  _WORD_DATA  _PROC_CALL  _WRITE_BLOCK_DATA  _I2C_BLOCK _PEC */
>> +/* _QUICK  _BYTE  _BYTE_DATA  _WORD_DATA  _PROC_CALL  
>> _WRITE_BLOCK_DATA  _I2C_BLOCK _PEC : */
>> +!I2C_FUNC_SMBUS_EMUL;
>>  return f;
>>  }
>>  
>>  static const struct i2c_algorithm smbus_algorithm = {
>> -.smbus_xfer = i801_access,
>> -

Re: [v2 PATCH 0/2] mm: mempolicy: fix mbind()'s inconsistent behavior for unmovable pages

2019-07-15 Thread Andrew Morton
On Sat, 22 Jun 2019 08:20:07 +0800 Yang Shi  wrote:

> 
> Changelog
> v2: * Fixed the inconsistent behavior by not aborting !vma_migratable()
>   immediately by a separate patch (patch 1/2), and this is also the
>   preparation for patch 2/2. For the details please see the commit
>   log.  Per Vlastimil.
> * Not abort immediately if unmovable page is met. This should handle
>   non-LRU movable pages and temporary off-LRU pages more friendly.
>   Per Vlastimil and Michal Hocko.
> 
> Yang Shi (2):
>   mm: mempolicy: make the behavior consistent when MPOL_MF_MOVE* and 
> MPOL_MF_STRICT were specified
>   mm: mempolicy: handle vma with unmovable pages mapped correctly in mbind
> 

I'm seeing no evidence of review on these two.  Could we please take a
look?  2/2 fixes a kernel crash so let's please also think about the
-stable situation.

I have a note here that Vlastimil had an issue with [1/2] but I seem to
hae misplaced that email :(



Re: [PATCH v2 1/2] dt-bindings: mmc: Document Aspeed SD controller

2019-07-15 Thread Rob Herring
On Thu, Jul 11, 2019 at 9:32 PM Andrew Jeffery  wrote:
>
> The ASPEED SD/SDIO/eMMC controller exposes two slots implementing the
> SDIO Host Specification v2.00, with 1 or 4 bit data buses, or an 8 bit
> data bus if only a single slot is enabled.
>
> Signed-off-by: Andrew Jeffery 
> ---
> In v2:
>
> * Rename to aspeed,sdhci.yaml
> * Rename sd-controller compatible
> * Add `maxItems: 1` for reg properties
> * Move sdhci subnode description to patternProperties
> * Drop sdhci compatible requirement
> * #address-cells and #size-cells are required
> * Prevent additional properties
> * Implement explicit ranges in example
> * Remove slot property
>
>  .../devicetree/bindings/mmc/aspeed,sdhci.yaml | 90 +++
>  1 file changed, 90 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/mmc/aspeed,sdhci.yaml
>
> diff --git a/Documentation/devicetree/bindings/mmc/aspeed,sdhci.yaml 
> b/Documentation/devicetree/bindings/mmc/aspeed,sdhci.yaml
> new file mode 100644
> index ..67a691c3348c
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mmc/aspeed,sdhci.yaml
> @@ -0,0 +1,90 @@
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/mmc/aspeed,sdhci.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: ASPEED SD/SDIO/eMMC Controller
> +
> +maintainers:
> +  - Andrew Jeffery 
> +  - Ryan Chen 
> +
> +description: |+
> +  The ASPEED SD/SDIO/eMMC controller exposes two slots implementing the SDIO
> +  Host Specification v2.00, with 1 or 4 bit data buses, or an 8 bit data bus 
> if
> +  only a single slot is enabled.
> +
> +  The two slots are supported by a common configuration area. As the SDHCIs 
> for
> +  the slots are dependent on the common configuration area, they are 
> described
> +  as child nodes.
> +
> +properties:
> +  compatible:
> +enum: [ aspeed,ast2400-sd-controller, aspeed,ast2500-sd-controller ]

This is actually a list of 4 strings. Please reformat to 1 per line.

Rob


[PATCH v2] nvmet-file: fix nvmet_file_flush() always returning an error

2019-07-15 Thread Logan Gunthorpe
Presently, nvmet_file_flush() always returns a call to
errno_to_nvme_status() but that helper doesn't take into account the
case when errno=0. So nvmet_file_flush() always returns an error code.

All other callers of errno_to_nvme_status() check for success before
calling it.

To fix this, ensure errno_to_nvme_status() returns success if the
errno is zero. This should prevent future mistakes like this from
happening.

Fixes: c6aa3542e010 ("nvmet: add error log support for file backend")
Signed-off-by: Logan Gunthorpe 
Cc: Chaitanya Kulkarni 
---
 drivers/nvme/target/core.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 7734a6acff85..e1f03cfc6675 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -43,6 +43,9 @@ inline u16 errno_to_nvme_status(struct nvmet_req *req, int 
errno)
u16 status;
 
switch (errno) {
+   case 0:
+   status = NVME_SC_SUCCESS;
+   break;
case -ENOSPC:
req->error_loc = offsetof(struct nvme_rw_command, length);
status = NVME_SC_CAP_EXCEEDED | NVME_SC_DNR;
-- 
2.20.1



Re: [RFC PATCH, x86]: Disable CPA cache flush for selfsnoop targets

2019-07-15 Thread Andy Lutomirski
On Mon, Jul 15, 2019 at 12:38 PM Andi Kleen  wrote:
>
> >
> > That does not answer the question whether it's worthwhile to do that.
>
> It's likely worthwhile for (Intel integrated) graphics.
>
> There was also a recent issue with 3dxp/dax, which uses ioremap in some
> cases.
>


FWIW, I applied this simpler patch:

diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
index 6a9a77a403c9..a933f99b176a 100644
--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -1729,6 +1729,7 @@ static int change_page_attr_set_clr(unsigned
long *addr, int numpages,
 * attributes:
 */
cache = !!pgprot2cachemode(mask_set);
+   WARN_ON(cache);

/*
 * On error; flush everything to be sure.

and booted a VM, including loading a module.  The warning did not
fire.  For the most part, we use PAT for things like ioremap_wc(), but
there's no flush, since there's no preexisting mapping at all.

I haven't tested on a real kernel with i915.  Does i915 really hit
this code path?  Does it happen more than once or twice at boot?

The only case I can think of where this would really matter is DAX, if
anyone uses WT for DAX.


[PATCH] s390: enable detection of kernel version from bzImage

2019-07-15 Thread Vasily Gorbik
Extend "parmarea" to include an offset of the version string, which is
stored as 8-byte big endian value.

To retrieve version string from bzImage reliably, one should check the
presence of "S390EP" ascii string at 0x10008 (available since v3.2),
then read the version string offset from 0x10428 (which has been 0
since v3.2 up to now). The string is null terminated.

Could be retrieved with the following "file" command magic (requires
file v5.34):
8 string 
\x02\x00\x00\x18\x60\x00\x00\x50\x02\x00\x00\x68\x60\x00\x00\x50\x40\x40\x40\x40\x40\x40\x40\x40
 Linux S390
>0x10008   string  S390EP
>>0x10428  bequad  >0
>>>(0x10428.Q) string  >\0 \b, version %s

Signed-off-by: Vasily Gorbik 
---
 arch/s390/boot/Makefile   | 2 +-
 arch/s390/boot/head.S | 1 +
 arch/s390/boot/version.c  | 6 ++
 arch/s390/include/asm/setup.h | 4 +++-
 4 files changed, 11 insertions(+), 2 deletions(-)
 create mode 100644 arch/s390/boot/version.c

diff --git a/arch/s390/boot/Makefile b/arch/s390/boot/Makefile
index 7cba96e7587b..4cf0bddb7d92 100644
--- a/arch/s390/boot/Makefile
+++ b/arch/s390/boot/Makefile
@@ -36,7 +36,7 @@ CFLAGS_sclp_early_core.o += -I$(srctree)/drivers/s390/char
 
 obj-y  := head.o als.o startup.o mem_detect.o ipl_parm.o ipl_report.o
 obj-y  += string.o ebcdic.o sclp_early_core.o mem.o ipl_vmparm.o cmdline.o
-obj-y  += ctype.o text_dma.o
+obj-y  += version.o ctype.o text_dma.o
 obj-$(CONFIG_PROTECTED_VIRTUALIZATION_GUEST)   += uv.o
 obj-$(CONFIG_RELOCATABLE)  += machine_kexec_reloc.o
 obj-$(CONFIG_RANDOMIZE_BASE)   += kaslr.o
diff --git a/arch/s390/boot/head.S b/arch/s390/boot/head.S
index 028aab03a9e7..2087bed6e60f 100644
--- a/arch/s390/boot/head.S
+++ b/arch/s390/boot/head.S
@@ -361,6 +361,7 @@ ENTRY(startup_kdump)
.quad   0   # INITRD_SIZE
.quad   0   # OLDMEM_BASE
.quad   0   # OLDMEM_SIZE
+   .quad   kernel_version  # points to kernel version string
 
.orgCOMMAND_LINE
.byte   "root=/dev/ram0 ro"
diff --git a/arch/s390/boot/version.c b/arch/s390/boot/version.c
new file mode 100644
index ..ea5e49651931
--- /dev/null
+++ b/arch/s390/boot/version.c
@@ -0,0 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0
+#include 
+#include 
+
+const char kernel_version[] = UTS_RELEASE
+   " (" LINUX_COMPILE_BY "@" LINUX_COMPILE_HOST ") " UTS_VERSION;
diff --git a/arch/s390/include/asm/setup.h b/arch/s390/include/asm/setup.h
index 925889d360c1..e5d28a475f76 100644
--- a/arch/s390/include/asm/setup.h
+++ b/arch/s390/include/asm/setup.h
@@ -54,6 +54,7 @@
 #define INITRD_SIZE_OFFSET 0x10410
 #define OLDMEM_BASE_OFFSET 0x10418
 #define OLDMEM_SIZE_OFFSET 0x10420
+#define KERNEL_VERSION_OFFSET  0x10428
 #define COMMAND_LINE_OFFSET0x10480
 
 #ifndef __ASSEMBLY__
@@ -74,7 +75,8 @@ struct parmarea {
unsigned long initrd_size;  /* 0x10410 */
unsigned long oldmem_base;  /* 0x10418 */
unsigned long oldmem_size;  /* 0x10420 */
-   char pad1[0x10480 - 0x10428];   /* 0x10428 - 0x10480 */
+   unsigned long kernel_version;   /* 0x10428 */
+   char pad1[0x10480 - 0x10430];   /* 0x10430 - 0x10480 */
char command_line[ARCH_COMMAND_LINE_SIZE];  /* 0x10480 */
 };
 
-- 
2.21.0



Re: [PATCH 2/2] s390: add Linux banner to the compressed image

2019-07-15 Thread Vasily Gorbik
On Sun, Jul 14, 2019 at 03:52:52PM +, Petr Tesarik wrote:
> On Sun, 14 Jul 2019 16:35:33 +0200
> Vasily Gorbik  wrote:
> 
> > On Fri, Jul 12, 2019 at 07:21:01PM +0200, Petr Tesarik wrote:
> > > Various tools determine the kernel version from a given binary by
> > > scanning for the Linux banner string. This does not work if the
> > > banner string is compressed, but we can link it once more into the
> > > uncompressed portion of bzImage.
> 
> > But even before discussing solutions I would like to understand the
> > problem first. Which specific tools are you referring to? What are they
> > good for? And how do they get the kernel version from other architectures
> > compressed images?
> 
> The tool I'm aware of is called get_kernel_version. It's built as part
> of openSUSE aaa_base and is used at install time. I'm not quite sure
> how it is used, but I have added Raymund Will to Cc; he can provide
> more information. There's also an open bug for it:
> 
>   https://bugzilla.opensuse.org/show_bug.cgi?id=1139939

Oh, I see, found it, thanks. Very interesting tool.
https://github.com/openSUSE/aaa_base/blob/master/get_kernel_version.c

And the only usage of this tool I found is to get the kernel version of
/boot/image (on s390) to run depmod during
yast-installation/src/clients/network_finish.rb

I also see that queries to rpm are already done from
yast-yast2/library/system/src/modules/Kernel.rb
Wouldn't it be more reliable (and portable) to just get the kernel
version from rpm metadata? Without using unreliable tools? Or find some
other solution, since this is the only use case for the tool?
$ rpm -qf --qf '%{VERSION}-%{RELEASE}.%{ARCH}\n' 
/boot/vmlinuz-5.1.17-300.fc30.x86_64
5.1.17-300.fc30.x86_64
[it looks like openSUSE kernel rpms don't have metadata to reconstruct
full kernel version currently, but that could be improved?]

Anyhow, I'm not opposed to an idea to make it possible to detect the
kernel version from bzImage. But it should be reliable. So, see the
follow on patch I'm sending.



Re: [RFC PATCH] virtio_ring: Use DMA API if guest memory is encrypted

2019-07-15 Thread Thiago Jung Bauermann


Michael S. Tsirkin  writes:

> On Mon, Jul 15, 2019 at 05:29:06PM -0300, Thiago Jung Bauermann wrote:
>>
>> Michael S. Tsirkin  writes:
>>
>> > On Sun, Jul 14, 2019 at 02:51:18AM -0300, Thiago Jung Bauermann wrote:
>> >>
>> >>
>> >> Michael S. Tsirkin  writes:
>> >>
>> >> > So this is what I would call this option:
>> >> >
>> >> > VIRTIO_F_ACCESS_PLATFORM_IDENTITY_ADDRESS
>> >> >
>> >> > and the explanation should state that all device
>> >> > addresses are translated by the platform to identical
>> >> > addresses.
>> >> >
>> >> > In fact this option then becomes more, not less restrictive
>> >> > than VIRTIO_F_ACCESS_PLATFORM - it's a promise
>> >> > by guest to only create identity mappings,
>> >> > and only before driver_ok is set.
>> >> > This option then would always be negotiated together with
>> >> > VIRTIO_F_ACCESS_PLATFORM.
>> >> >
>> >> > Host then must verify that
>> >> > 1. full 1:1 mappings are created before driver_ok
>> >> > or can we make sure this happens before features_ok?
>> >> > that would be ideal as we could require that features_ok fails
>> >> > 2. mappings are not modified between driver_ok and reset
>> >> > i guess attempts to change them will fail -
>> >> > possibly by causing a guest crash
>> >> > or some other kind of platform-specific error
>> >>
>> >> I think VIRTIO_F_ACCESS_PLATFORM_IDENTITY_ADDRESS is good, but requiring
>> >> it to be accompanied by ACCESS_PLATFORM can be a problem. One reason is
>> >> SLOF as I mentioned above, another is that we would be requiring all
>> >> guests running on the machine (secure guests or not, since we would use
>> >> the same configuration for all guests) to support it. But
>> >> ACCESS_PLATFORM is relatively recent so it's a bit early for that. For
>> >> instance, Ubuntu 16.04 LTS (which is still supported) doesn't know about
>> >> it and wouldn't be able to use the device.
>> >
>> > OK and your target is to enable use with kernel drivers within
>> > guests, right?
>>
>> Right.
>>
>> > My question is, we are defining a new flag here, I guess old guests
>> > then do not set it. How does it help old guests? Or maybe it's
>> > not designed to ...
>>
>> Indeed. The idea is that QEMU can offer the flag, old guests can reject
>> it (or even new guests can reject it, if they decide not to convert into
>> secure VMs) and the feature negotiation will succeed with the flag
>> unset.
>
> OK. And then what does QEMU do? Assume guest is not encrypted I guess?

There's nothing different that QEMU needs to do, with or without the
flag. the perspective of the host, a secure guest and a regular guest
work the same way with respect to virtio.

--
Thiago Jung Bauermann
IBM Linux Technology Center


Re: [PATCH] staging: kpc2000: Convert put_page() to put_user_page*()

2019-07-15 Thread John Hubbard
On 7/15/19 3:01 PM, John Hubbard wrote:
> On 7/15/19 2:47 PM, Matt Sickler wrote:
...
> I agree: the PageReserved check looks unnecessary here, from my 
> outside-the-kpc_2000-team
> perspective, anyway. Assuming that your analysis above is correct, you could 
> collapse that
> whole think into just:
> 
> @@ -211,17 +209,8 @@ void  transfer_complete_cb(struct aio_cb_data *acd, 
> size_t xfr_count, u32 flags)
> BUG_ON(acd->ldev == NULL);
> BUG_ON(acd->ldev->pldev == NULL);
>  
> -   for (i = 0 ; i < acd->page_count ; i++) {
> -   if (!PageReserved(acd->user_pages[i])) {
> -   set_page_dirty(acd->user_pages[i]);
> -   }
> -   }
> -
> dma_unmap_sg(>ldev->pldev->dev, acd->sgt.sgl, acd->sgt.nents, 
> acd->ldev->dir);
> -
> -   for (i = 0 ; i < acd->page_count ; i++) {
> -   put_page(acd->user_pages[i]);
> -   }
> +   put_user_pages_dirty(>user_pages[i], acd->page_count);

Ahem, I typed too quickly. :) Please make that:

put_user_pages_dirty(acd->user_pages, acd->page_count);

thanks,
-- 
John Hubbard
NVIDIA



Re: [PATCH v9 03/18] kunit: test: add string_stream a std::stream like string builder

2019-07-15 Thread Stephen Boyd
Quoting Brendan Higgins (2019-07-15 14:11:50)
> On Mon, Jul 15, 2019 at 1:43 PM Stephen Boyd  wrote:
> >
> > I also wonder if it would be better to just have a big slop buffer of a
> > 4K page or something so that we almost never have to allocate anything
> > with a string_stream and we can just rely on a reader consuming data
> > while writers are writing. That might work out better, but I don't quite
> > understand the use case for the string stream.
> 
> That makes sense, but might that also waste memory since we will
> almost never need that much memory?

Why do we care? These are unit tests. Having allocations in here makes
things more complicated, whereas it would be simpler to have a pointer
and a spinlock operating on a chunk of memory that gets flushed out
periodically.



[PATCH v5 0/4] Support accelerometers for veyron_minnie

2019-07-15 Thread Gwendal Grignou
veyron_minnie - ASUS Chromebook Flip C100PA - embedded controller
controls two accelerometers, one in the lid, one in the base.
However, the EC firmware does not follow the new interface that
cros_ec_accel driver use.
Extend the legacy driver used on glimmer - Lenovo ThinkPad 11e
Chromebook - to veyron_minnie.
veyron_minnie being ARM based, issue command over the I2C bus to the EC
instead of relying on the shared registers over LPC.

Gwendal Grignou (4):
  iio: cros_ec: Add sign vector in core for backward compatibility
  iio: cros_ec_accel_legacy: Fix incorrect channel setting
  iio: cros_ec_accel_legacy: Use cros_ec_sensors_core
  iio: cros_ec_accel_legacy: Add support for veyron-minnie

Changes in v4:
- In "Use cros_ec_sensors_core", fix return without unlock on the error
  path.
- Add acked for the last 2 patches.

Changes in v4:
- No change in iio/common/cros_ec_sensors
- Split cros_ec_accel_legacy code in 3:
  - fix an error in channel setting.
  - remove duplicate code in cros_ec_accel, use cros_ec_sensors_core.
  - extend cros_ec_accel to ARM device.
- Define cros_ec_accel_legacy_read_cmd() as static.

Changes in v3:
- Fix commit message, add reviewed-by for first patch.

Changes in v2:
- Readd empty line to reduce amount of change in patch.
- Remove Keywords used by ChromeOS commit queue.


 drivers/iio/accel/Kconfig |   4 +-
 drivers/iio/accel/cros_ec_accel_legacy.c  | 352 --
 .../cros_ec_sensors/cros_ec_sensors_core.c|   4 +
 .../linux/iio/common/cros_ec_sensors_core.h   |   1 +
 4 files changed, 85 insertions(+), 276 deletions(-)

-- 
2.22.0.510.g264f2c817a-goog



[PATCH v5 3/4] iio: cros_ec_accel_legacy: Use cros_ec_sensors_core

2019-07-15 Thread Gwendal Grignou
Remove duplicate code in cros-ec-accel-legacy,
use cros-ec-sensors-core functions and structures when possible.

On glimmer, check the 2 accelerometers are presented and working.

Signed-off-by: Gwendal Grignou 
Acked-by: Jonathan Cameron 
---
 drivers/iio/accel/Kconfig|   4 +-
 drivers/iio/accel/cros_ec_accel_legacy.c | 335 ---
 2 files changed, 54 insertions(+), 285 deletions(-)

diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
index 62a970a20219..7d0848f9ea45 100644
--- a/drivers/iio/accel/Kconfig
+++ b/drivers/iio/accel/Kconfig
@@ -201,9 +201,7 @@ config HID_SENSOR_ACCEL_3D
 
 config IIO_CROS_EC_ACCEL_LEGACY
tristate "ChromeOS EC Legacy Accelerometer Sensor"
-   select IIO_BUFFER
-   select IIO_TRIGGERED_BUFFER
-   select CROS_EC_LPC_REGISTER_DEVICE
+   depends on IIO_CROS_EC_SENSORS_CORE
help
  Say yes here to get support for accelerometers on Chromebook using
  legacy EC firmware.
diff --git a/drivers/iio/accel/cros_ec_accel_legacy.c 
b/drivers/iio/accel/cros_ec_accel_legacy.c
index ad19d9c716f4..4d77472e2f72 100644
--- a/drivers/iio/accel/cros_ec_accel_legacy.c
+++ b/drivers/iio/accel/cros_ec_accel_legacy.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -25,191 +26,50 @@
 
 #define DRV_NAME   "cros-ec-accel-legacy"
 
+#define CROS_EC_SENSOR_LEGACY_NUM 2
 /*
  * Sensor scale hard coded at 10 bits per g, computed as:
  * g / (2^10 - 1) = 0.009586168; with g = 9.80665 m.s^-2
  */
 #define ACCEL_LEGACY_NSCALE 9586168
 
-/* Indices for EC sensor values. */
-enum {
-   X,
-   Y,
-   Z,
-   MAX_AXIS,
-};
-
-/* State data for cros_ec_accel_legacy iio driver. */
-struct cros_ec_accel_legacy_state {
-   struct cros_ec_device *ec;
-
-   /*
-* Array holding data from a single capture. 2 bytes per channel
-* for the 3 channels plus the timestamp which is always last and
-* 8-bytes aligned.
-*/
-   s16 capture_data[8];
-   s8 sign[MAX_AXIS];
-   u8 sensor_num;
-};
-
-static int ec_cmd_read_u8(struct cros_ec_device *ec, unsigned int offset,
- u8 *dest)
-{
-   return ec->cmd_readmem(ec, offset, 1, dest);
-}
-
-static int ec_cmd_read_u16(struct cros_ec_device *ec, unsigned int offset,
-  u16 *dest)
-{
-   __le16 tmp;
-   int ret = ec->cmd_readmem(ec, offset, 2, );
-
-   *dest = le16_to_cpu(tmp);
-
-   return ret;
-}
-
-/**
- * read_ec_until_not_busy() - Read from EC status byte until it reads not busy.
- * @st: Pointer to state information for device.
- *
- * This function reads EC status until its busy bit gets cleared. It does not
- * wait indefinitely and returns -EIO if the EC status is still busy after a
- * few hundreds milliseconds.
- *
- * Return: 8-bit status if ok, -EIO on error
- */
-static int read_ec_until_not_busy(struct cros_ec_accel_legacy_state *st)
-{
-   struct cros_ec_device *ec = st->ec;
-   u8 status;
-   int attempts = 0;
-
-   ec_cmd_read_u8(ec, EC_MEMMAP_ACC_STATUS, );
-   while (status & EC_MEMMAP_ACC_STATUS_BUSY_BIT) {
-   /* Give up after enough attempts, return error. */
-   if (attempts++ >= 50)
-   return -EIO;
-
-   /* Small delay every so often. */
-   if (attempts % 5 == 0)
-   msleep(25);
-
-   ec_cmd_read_u8(ec, EC_MEMMAP_ACC_STATUS, );
-   }
-
-   return status;
-}
-
-/**
- * read_ec_accel_data_unsafe() - Read acceleration data from EC shared memory.
- * @st:Pointer to state information for device.
- * @scan_mask: Bitmap of the sensor indices to scan.
- * @data:  Location to store data.
- *
- * This is the unsafe function for reading the EC data. It does not guarantee
- * that the EC will not modify the data as it is being read in.
- */
-static void read_ec_accel_data_unsafe(struct cros_ec_accel_legacy_state *st,
- unsigned long scan_mask, s16 *data)
-{
-   int i = 0;
-   int num_enabled = bitmap_weight(_mask, MAX_AXIS);
-
-   /* Read all sensors enabled in scan_mask. Each value is 2 bytes. */
-   while (num_enabled--) {
-   i = find_next_bit(_mask, MAX_AXIS, i);
-   ec_cmd_read_u16(st->ec,
-   EC_MEMMAP_ACC_DATA +
-   sizeof(s16) *
-   (1 + i + st->sensor_num * MAX_AXIS),
-   data);
-   *data *= st->sign[i];
-   i++;
-   data++;
-   }
-}
-
-/**
- * read_ec_accel_data() - Read acceleration data from EC shared memory.
- * @st:Pointer to state information for device.
- * @scan_mask: Bitmap of the sensor indices to scan.
- * @data:  Location to store data.
- *
- * This is the safe function for reading the EC data. It 

[PATCH v5 1/4] iio: cros_ec: Add sign vector in core for backward compatibility

2019-07-15 Thread Gwendal Grignou
To allow cros_ec iio core library to be used with legacy device, add a
vector to rotate sensor data if necessary: legacy devices are not
reporting data in HTML5/Android sensor referential.

Check the data is not rotated on recent chromebooks that use the HTML5
standard to present sensor data.

Signed-off-by: Gwendal Grignou 
Reviewed-by: Douglas Anderson 
---
 drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c | 4 
 include/linux/iio/common/cros_ec_sensors_core.h   | 1 +
 2 files changed, 5 insertions(+)

diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c 
b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
index 719a0df5aeeb..e8a4d78659c8 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
@@ -66,6 +66,9 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
}
state->type = state->resp->info.type;
state->loc = state->resp->info.location;
+
+   /* Set sign vector, only used for backward compatibility. */
+   memset(state->sign, 1, CROS_EC_SENSOR_MAX_AXIS);
}
 
return 0;
@@ -254,6 +257,7 @@ static int cros_ec_sensors_read_data_unsafe(struct iio_dev 
*indio_dev,
if (ret < 0)
return ret;
 
+   *data *= st->sign[i];
data++;
}
 
diff --git a/include/linux/iio/common/cros_ec_sensors_core.h 
b/include/linux/iio/common/cros_ec_sensors_core.h
index ce16445411ac..a1c85ad4df91 100644
--- a/include/linux/iio/common/cros_ec_sensors_core.h
+++ b/include/linux/iio/common/cros_ec_sensors_core.h
@@ -71,6 +71,7 @@ struct cros_ec_sensors_core_state {
enum motionsensor_location loc;
 
s16 calib[CROS_EC_SENSOR_MAX_AXIS];
+   s8 sign[CROS_EC_SENSOR_MAX_AXIS];
 
u8 samples[CROS_EC_SAMPLE_SIZE];
 
-- 
2.22.0.510.g264f2c817a-goog



[PATCH v5 4/4] iio: cros_ec_accel_legacy: Add support for veyron-minnie

2019-07-15 Thread Gwendal Grignou
Veyron minnie embedded controller presents 2 accelerometers using an
older interface. Add function to query the data in cros_ec_accel.

Verify accelerometers on veyron-minnie are presented and working.

Signed-off-by: Gwendal Grignou 
Acked-by: Jonathan Cameron 
---
 drivers/iio/accel/cros_ec_accel_legacy.c | 40 ++--
 1 file changed, 38 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/accel/cros_ec_accel_legacy.c 
b/drivers/iio/accel/cros_ec_accel_legacy.c
index 4d77472e2f72..545e23f0c033 100644
--- a/drivers/iio/accel/cros_ec_accel_legacy.c
+++ b/drivers/iio/accel/cros_ec_accel_legacy.c
@@ -5,7 +5,7 @@
  * Copyright 2017 Google, Inc
  *
  * This driver uses the memory mapper cros-ec interface to communicate
- * with the Chrome OS EC about accelerometer data.
+ * with the Chrome OS EC about accelerometer data or older commands.
  * Accelerometer access is presented through iio sysfs.
  */
 
@@ -33,6 +33,39 @@
  */
 #define ACCEL_LEGACY_NSCALE 9586168
 
+static int cros_ec_accel_legacy_read_cmd(struct iio_dev *indio_dev,
+ unsigned long scan_mask, s16 *data)
+{
+   struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
+   int ret;
+   unsigned int i;
+   u8 sensor_num;
+
+   /*
+* Read all sensor data through a command.
+* Save sensor_num, it is assumed to stay.
+*/
+   sensor_num = st->param.info.sensor_num;
+   st->param.cmd = MOTIONSENSE_CMD_DUMP;
+   st->param.dump.max_sensor_count = CROS_EC_SENSOR_LEGACY_NUM;
+   ret = cros_ec_motion_send_host_cmd(st,
+   sizeof(st->resp->dump) + CROS_EC_SENSOR_LEGACY_NUM *
+   sizeof(struct ec_response_motion_sensor_data));
+   st->param.info.sensor_num = sensor_num;
+   if (ret != 0) {
+   dev_warn(_dev->dev, "Unable to read sensor data\n");
+   return ret;
+   }
+
+   for_each_set_bit(i, _mask, indio_dev->masklength) {
+   *data = st->resp->dump.sensor[sensor_num].data[i] *
+   st->sign[i];
+   data++;
+   }
+
+   return 0;
+}
+
 static int cros_ec_accel_legacy_read(struct iio_dev *indio_dev,
 struct iio_chan_spec const *chan,
 int *val, int *val2, long mask)
@@ -149,7 +182,10 @@ static int cros_ec_accel_legacy_probe(struct 
platform_device *pdev)
indio_dev->info = _ec_accel_legacy_info;
state = iio_priv(indio_dev);
 
-   state->read_ec_sensors_data = cros_ec_sensors_read_lpc;
+   if (state->ec->cmd_readmem != NULL)
+   state->read_ec_sensors_data = cros_ec_sensors_read_lpc;
+   else
+   state->read_ec_sensors_data = cros_ec_accel_legacy_read_cmd;
 
indio_dev->channels = cros_ec_accel_legacy_channels;
indio_dev->num_channels = ARRAY_SIZE(cros_ec_accel_legacy_channels);
-- 
2.22.0.510.g264f2c817a-goog



[PATCH v5 2/4] iio: cros_ec_accel_legacy: Fix incorrect channel setting

2019-07-15 Thread Gwendal Grignou
INFO_SCALE is set both for each channel and all channels.
iio is using all channel setting, so the error was not user visible.

Signed-off-by: Gwendal Grignou 
---
 drivers/iio/accel/cros_ec_accel_legacy.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/iio/accel/cros_ec_accel_legacy.c 
b/drivers/iio/accel/cros_ec_accel_legacy.c
index 46bb2e421bb9..ad19d9c716f4 100644
--- a/drivers/iio/accel/cros_ec_accel_legacy.c
+++ b/drivers/iio/accel/cros_ec_accel_legacy.c
@@ -319,7 +319,6 @@ static const struct iio_chan_spec_ext_info 
cros_ec_accel_legacy_ext_info[] = {
.modified = 1,  \
.info_mask_separate =   \
BIT(IIO_CHAN_INFO_RAW) |\
-   BIT(IIO_CHAN_INFO_SCALE) |  \
BIT(IIO_CHAN_INFO_CALIBBIAS),   \
.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SCALE),\
.ext_info = cros_ec_accel_legacy_ext_info,  \
-- 
2.22.0.510.g264f2c817a-goog



Re: [PATCH] staging: kpc2000: Convert put_page() to put_user_page*()

2019-07-15 Thread John Hubbard
On 7/15/19 2:47 PM, Matt Sickler wrote:
> It looks like Outlook is going to absolutely trash this email.  Hopefully it 
> comes through okay.
> 
...
>>
>> Because this is a common pattern, and because the code here doesn't likely
>> need to set page dirty before the dma_unmap_sg call, I think the following
>> would be better (it's untested), instead of the above diff hunk:
>>
>> diff --git a/drivers/staging/kpc2000/kpc_dma/fileops.c
>> b/drivers/staging/kpc2000/kpc_dma/fileops.c
>> index 48ca88bc6b0b..d486f9866449 100644
>> --- a/drivers/staging/kpc2000/kpc_dma/fileops.c
>> +++ b/drivers/staging/kpc2000/kpc_dma/fileops.c
>> @@ -211,16 +211,13 @@ void  transfer_complete_cb(struct aio_cb_data
>> *acd, size_t xfr_count, u32 flags)
>>BUG_ON(acd->ldev == NULL);
>>BUG_ON(acd->ldev->pldev == NULL);
>>
>> -   for (i = 0 ; i < acd->page_count ; i++) {
>> -   if (!PageReserved(acd->user_pages[i])) {
>> -   set_page_dirty(acd->user_pages[i]);
>> -   }
>> -   }
>> -
>>dma_unmap_sg(>ldev->pldev->dev, acd->sgt.sgl, acd->sgt.nents, 
>> acd->ldev->dir);
>>
>>for (i = 0 ; i < acd->page_count ; i++) {
>> -   put_page(acd->user_pages[i]);
>> +   if (!PageReserved(acd->user_pages[i])) {
>> +   put_user_pages_dirty(>user_pages[i], 1);
>> +   else
>> +   put_user_page(acd->user_pages[i]);
>>}
>>
>>sg_free_table(>sgt);
> 
> I don't think I ever really knew the right way to do this. 
> 
> The changes Bharath suggested look okay to me.  I'm not sure about the check 
> for PageReserved(), though.  At first glance it appears to be equivalent to 
> what was there before, but maybe I should learn what that Reserved page flag 
> really means.
> From [1], the only comment that seems applicable is
> * - MMIO/DMA pages. Some architectures don't allow to ioremap pages that are
>  *   not marked PG_reserved (as they might be in use by somebody else who does
>  *   not respect the caching strategy).
> 
> These pages should be coming from anonymous (RAM, not file backed) memory in 
> userspace.  Sometimes it comes from hugepage backed memory, though I don't 
> think that makes a difference.  I should note that transfer_complete_cb 
> handles both RAM to device and device to RAM DMAs, if that matters.
> 
> [1] 
> https://elixir.bootlin.com/linux/v5.2/source/include/linux/page-flags.h#L17
> 

I agree: the PageReserved check looks unnecessary here, from my 
outside-the-kpc_2000-team
perspective, anyway. Assuming that your analysis above is correct, you could 
collapse that
whole think into just:

@@ -211,17 +209,8 @@ void  transfer_complete_cb(struct aio_cb_data *acd, size_t 
xfr_count, u32 flags)
BUG_ON(acd->ldev == NULL);
BUG_ON(acd->ldev->pldev == NULL);
 
-   for (i = 0 ; i < acd->page_count ; i++) {
-   if (!PageReserved(acd->user_pages[i])) {
-   set_page_dirty(acd->user_pages[i]);
-   }
-   }
-
dma_unmap_sg(>ldev->pldev->dev, acd->sgt.sgl, acd->sgt.nents, 
acd->ldev->dir);
-
-   for (i = 0 ; i < acd->page_count ; i++) {
-   put_page(acd->user_pages[i]);
-   }
+   put_user_pages_dirty(>user_pages[i], acd->page_count);
 
sg_free_table(>sgt);
 
(Also, Matt, I failed to Cc: you on a semi-related cleanup that I just sent out 
for this
driver, as long as I have your attention:

   https://lore.kernel.org/r/20190715212123.432-1-jhubb...@nvidia.com
)

thanks,
-- 
John Hubbard
NVIDIA


Re: [PATCH 1/6] clk: Sync prototypes for clk_bulk_enable()

2019-07-15 Thread Stephen Boyd
Quoting Andrey Smirnov (2019-07-15 13:12:29)
> No-op version of clk_bulk_enable() should have the same protoype as
> the real implementation, so constify the last argument to make it so.
> 
> Signed-off-by: Andrey Smirnov 
> Cc: Russell King 
> Cc: Chris Healy 
> Cc: linux-...@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---

No cover letter, but I'm inclined to squash these all together into one
patch instead of 6. I'm not sure why each function gets a different
patch.

>  include/linux/clk.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 


Re: [PATCH] mm/hmm: Fix bad subpage pointer in try_to_unmap_one

2019-07-15 Thread Andrew Morton
On Tue, 9 Jul 2019 18:24:57 -0700 Ralph Campbell  wrote:

> 
> On 7/9/19 5:28 PM, Andrew Morton wrote:
> > On Tue, 9 Jul 2019 15:35:56 -0700 Ralph Campbell  
> > wrote:
> > 
> >> When migrating a ZONE device private page from device memory to system
> >> memory, the subpage pointer is initialized from a swap pte which computes
> >> an invalid page pointer. A kernel panic results such as:
> >>
> >> BUG: unable to handle page fault for address: ea1fffc8
> >>
> >> Initialize subpage correctly before calling page_remove_rmap().
> > 
> > I think this is
> > 
> > Fixes:  a5430dda8a3a1c ("mm/migrate: support un-addressable ZONE_DEVICE 
> > page in migration")
> > Cc: stable
> > 
> > yes?
> > 
> 
> Yes. Can you add this or should I send a v2?

I updated the patch.  Could we please have some review input?


From: Ralph Campbell 
Subject: mm/hmm: fix bad subpage pointer in try_to_unmap_one

When migrating a ZONE device private page from device memory to system
memory, the subpage pointer is initialized from a swap pte which computes
an invalid page pointer. A kernel panic results such as:

BUG: unable to handle page fault for address: ea1fffc8

Initialize subpage correctly before calling page_remove_rmap().

Link: http://lkml.kernel.org/r/20190709223556.28908-1-rcampb...@nvidia.com
Fixes: a5430dda8a3a1c ("mm/migrate: support un-addressable ZONE_DEVICE page in 
migration")
Signed-off-by: Ralph Campbell 
Cc: "Jérôme Glisse" 
Cc: "Kirill A. Shutemov" 
Cc: Mike Kravetz 
Cc: Jason Gunthorpe 
Cc: 
Signed-off-by: Andrew Morton 
---

 mm/rmap.c |1 +
 1 file changed, 1 insertion(+)

--- a/mm/rmap.c~mm-hmm-fix-bad-subpage-pointer-in-try_to_unmap_one
+++ a/mm/rmap.c
@@ -1476,6 +1476,7 @@ static bool try_to_unmap_one(struct page
 * No need to invalidate here it will synchronize on
 * against the special swap migration pte.
 */
+   subpage = page;
goto discard;
}
 
_



Re: [PATCH 2/3] iio: imu: st_lsm6dsx: add support for accel/gyro unit of lsm9sd1

2019-07-15 Thread Lorenzo Bianconi
> The LSM9DS1's accelerometer / gyroscope unit and it's magnetometer (separately
> supported in iio/magnetometer/st_magn*) are located on a separate i2c 
> addresses
> on the bus.
> 
> For the datasheet, see https://www.st.com/resource/en/datasheet/lsm9ds1.pdf
> 
> Treat it just like the LSM6* devices and, despite it's name, hook it up
> to the st_lsm6dsx driver, using it's basic functionality.
> 
> Signed-off-by: Martin Kepplinger 
> ---
> 
> What do you think about an addition like this? How confusing is it to support
> an LSM9 module by the lsm6 driver, despite it's name? It requires almost no
> code, so why not think about it, right?

I am fine with (it was on my ToDo list, so thanks for working on this).
I have just posted the following series that will help you adding support for
LSM9DS1
https://patchwork.kernel.org/cover/11045061/
I think you just need to take care of gyro channels allocating iio devices (you
probably need to pass hw_id to st_lsm6dsx_alloc_iiodev())

> 
> Oh, I'm not 100% convinced by my new "if" in probe(), but even that is
> not too confusing I guess.
> 
> thanks,
> 
>martin
> 
> p.s.: todos:
> * hook up the fifo / buffer / trigger functionality,
> * (off-topic a bit) move the (currently strange) gyro-only support
>   for lsm9ds0 to this driver as well.

Regarding FIFO I guess it is enough to set decimator factor to 1 for both accel
and gyro.

Regards,
Lorenzo

> 
> 
> 
>  drivers/iio/imu/st_lsm6dsx/Kconfig   |   3 +-
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h  |   4 +
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 105 ++-
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c  |   5 +
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c  |   5 +
>  5 files changed, 117 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/Kconfig 
> b/drivers/iio/imu/st_lsm6dsx/Kconfig
> index 002a423eae52..0b5a568e4c16 100644
> --- a/drivers/iio/imu/st_lsm6dsx/Kconfig
> +++ b/drivers/iio/imu/st_lsm6dsx/Kconfig
> @@ -10,7 +10,8 @@ config IIO_ST_LSM6DSX
>   help
> Say yes here to build support for STMicroelectronics LSM6DSx imu
> sensor. Supported devices: lsm6ds3, lsm6ds3h, lsm6dsl, lsm6dsm,
> -   ism330dlc, lsm6dso, lsm6dsox, asm330lhh, lsm6dsr
> +   ism330dlc, lsm6dso, lsm6dsox, asm330lhh, lsm6dsr and the
> +   accelerometer/gyroscope of lsm9ds1.
>  
> To compile this driver as a module, choose M here: the module
> will be called st_lsm6dsx.
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h 
> b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> index f072ac14f213..8af9641260fa 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> @@ -22,6 +22,7 @@
>  #define ST_ASM330LHH_DEV_NAME"asm330lhh"
>  #define ST_LSM6DSOX_DEV_NAME "lsm6dsox"
>  #define ST_LSM6DSR_DEV_NAME  "lsm6dsr"
> +#define ST_LSM9DS1_DEV_NAME  "lsm9ds1"
>  
>  enum st_lsm6dsx_hw_id {
>   ST_LSM6DS3_ID,
> @@ -33,6 +34,7 @@ enum st_lsm6dsx_hw_id {
>   ST_ASM330LHH_ID,
>   ST_LSM6DSOX_ID,
>   ST_LSM6DSR_ID,
> + ST_LSM9DS1_ID,
>   ST_LSM6DSX_MAX_ID,
>  };
>  
> @@ -230,6 +232,8 @@ enum st_lsm6dsx_sensor_id {
>   ST_LSM6DSX_ID_EXT0,
>   ST_LSM6DSX_ID_EXT1,
>   ST_LSM6DSX_ID_EXT2,
> + ST_LSM9DSX_ID_GYRO,
> + ST_LSM9DSX_ID_ACC,
>   ST_LSM6DSX_ID_MAX,
>  };
>  
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c 
> b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index 7a4fe70a8f20..6acfe63073de 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -10,6 +10,8 @@
>   * +-125/+-245/+-500/+-1000/+-2000 dps
>   * LSM6DSx series has an integrated First-In-First-Out (FIFO) buffer
>   * allowing dynamic batching of sensor data.
> + * LSM9DSx series is similar but includes an additional magnetometer, handled
> + * by a different driver.
>   *
>   * Supported sensors:
>   * - LSM6DS3:
> @@ -30,6 +32,13 @@
>   *   - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000
>   *   - FIFO size: 3KB
>   *
> + * - LSM9DS1:
> + *   - Accelerometer supported ODR [Hz]: 10, 50, 119, 238, 476, 952
> + *   - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16
> + *   - Gyroscope supported ODR [Hz]: 15, 60, 119, 238, 476, 952
> + *   - Gyroscope supported full-scale [dps]: +-245/+-500/+-2000
> + *   - FIFO size: 32
> + *
>   * Copyright 2016 STMicroelectronics Inc.
>   *
>   * Lorenzo Bianconi 
> @@ -64,6 +73,10 @@
>  #define ST_LSM6DSX_REG_GYRO_OUT_Y_L_ADDR 0x24
>  #define ST_LSM6DSX_REG_GYRO_OUT_Z_L_ADDR 0x26
>  
> +#define ST_LSM9DSX_REG_GYRO_OUT_X_L_ADDR 0x18
> +#define ST_LSM9DSX_REG_GYRO_OUT_Y_L_ADDR 0x1a
> +#define ST_LSM9DSX_REG_GYRO_OUT_Z_L_ADDR 0x1c
> +
>  static const struct st_lsm6dsx_odr_table_entry st_lsm6dsx_odr_table[] = {
>   [ST_LSM6DSX_ID_ACC] = {
>   .reg = {
> @@ -88,6 +101,30 @@ static const struct 

[PATCH v2] staging: kpc2000: Convert put_page() to put_user_page*()

2019-07-15 Thread Bharath Vedartham
There have been issues with get_user_pages and filesystem writeback.
The issues are better described in [1].

The solution being proposed wants to keep track of gup_pinned pages
which will allow to take furthur steps to coordinate between subsystems
using gup.

put_user_page() simply calls put_page inside for now. But the
implementation will change once all call sites of put_page() are
converted.

[1] https://lwn.net/Articles/753027/

Cc: Matt Sickler 
Cc: Greg Kroah-Hartman 
Cc: Jérôme Glisse 
Cc: Ira Weiny 
Cc: John Hubbard 
Cc: linux...@kvack.org
Cc: de...@driverdev.osuosl.org

Reviewed-by: John Hubbard 
Signed-off-by: Bharath Vedartham 
---
Changes since v1
- Added John's reviewed-by tag
- Moved para talking about testing below
the '---'
- Moved logic of set_page_diry below dma_unmap_sg
as per John's suggestion

I currently do not have the driver to test. Could I have some
suggestions to test this code? The solution is currently implemented
in https://github.com/johnhubbard/linux/tree/gup_dma_core and it would be great 
if we could apply the patch on top of the repo and run some 
tests to check if any regressions occur.
---
 drivers/staging/kpc2000/kpc_dma/fileops.c | 17 ++---
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc_dma/fileops.c 
b/drivers/staging/kpc2000/kpc_dma/fileops.c
index 48ca88b..3d1a00a 100644
--- a/drivers/staging/kpc2000/kpc_dma/fileops.c
+++ b/drivers/staging/kpc2000/kpc_dma/fileops.c
@@ -190,9 +190,7 @@ static int kpc_dma_transfer(struct dev_private_data *priv,
sg_free_table(>sgt);
  err_dma_map_sg:
  err_alloc_sg_table:
-   for (i = 0 ; i < acd->page_count ; i++) {
-   put_page(acd->user_pages[i]);
-   }
+   put_user_pages(acd->user_pages, acd->page_count);
  err_get_user_pages:
kfree(acd->user_pages);
  err_alloc_userpages:
@@ -211,16 +209,13 @@ void  transfer_complete_cb(struct aio_cb_data *acd, 
size_t xfr_count, u32 flags)
BUG_ON(acd->ldev == NULL);
BUG_ON(acd->ldev->pldev == NULL);
 
-   for (i = 0 ; i < acd->page_count ; i++) {
-   if (!PageReserved(acd->user_pages[i])) {
-   set_page_dirty(acd->user_pages[i]);
-   }
-   }
-
dma_unmap_sg(>ldev->pldev->dev, acd->sgt.sgl, acd->sgt.nents, 
acd->ldev->dir);
 
-   for (i = 0 ; i < acd->page_count ; i++) {
-   put_page(acd->user_pages[i]);
+   for (i = 0; i < acd->page_count; i++) {
+   if (!PageReserved(acd->user_pages[i])) 
+   put_user_pages_dirty(>user_pages[i], 1);
+   else
+   put_user_page(acd->user_pages[i]);
}
 
sg_free_table(>sgt);
-- 
2.7.4



Re: [PATCH v4] PM / wakeup: show wakeup sources stats in sysfs

2019-07-15 Thread Rafael J. Wysocki
On Mon, Jul 15, 2019 at 11:44 PM Tri Vo  wrote:
>
> Userspace can use wakeup_sources debugfs node to plot history of suspend
> blocking wakeup sources over device's boot cycle. This information can
> then be used (1) for power-specific bug reporting and (2) towards
> attributing battery consumption to specific processes over a period of
> time.
>
> However, debugfs doesn't have stable ABI. For this reason, create a
> 'struct device' to expose wakeup sources statistics in sysfs under
> /sys/class/wakeup//.
>
> Introduce CONFIG_PM_SLEEP_STATS that enables/disables showing wakeup
> source statistics in sysfs.

I'm not sure if this is really needed, but I'll let Greg decide.

Apart from this

Reviewed-by: Rafael J. Wysocki 

>
> Co-developed-by: Greg Kroah-Hartman 
> Signed-off-by: Tri Vo 
> Tested-by: Tri Vo 
> Tested-by: Kalesh Singh 
> ---
>  Documentation/ABI/testing/sysfs-class-wakeup |  70 +
>  drivers/base/power/Makefile  |   1 +
>  drivers/base/power/wakeup.c  |  12 +-
>  drivers/base/power/wakeup_stats.c| 149 +++
>  include/linux/pm_wakeup.h|  19 +++
>  kernel/power/Kconfig |  10 ++
>  kernel/power/wakelock.c  |  10 ++
>  7 files changed, 269 insertions(+), 2 deletions(-)
>  create mode 100644 Documentation/ABI/testing/sysfs-class-wakeup
>  create mode 100644 drivers/base/power/wakeup_stats.c
>
> v2:
> - Updated Documentation/ABI/, as per Greg.
> - Removed locks in attribute functions, as per Greg.
> - Lifetimes of struct wakelock and struck wakeup_source are now different due 
> to
>   the latter embedding a refcounted kobject. Changed it so that struct 
> wakelock
>   only has a pointer to struct wakeup_source, instead of embedding it.
> - Added CONFIG_PM_SLEEP_STATS that enables/disables wakeup source statistics 
> in
>   sysfs.
>
> v3:
> Changes by Greg:
> - Reworked code to use 'struct device' instead of raw kobjects.
> - Updated documentation file.
> - Only link wakeup_stats.o when CONFIG_PM_SLEEP_STATS is enabled.
> Changes by Tri:
> - Reverted changes to kernel/power/wakelock.c. 'struct device' hides kobject
>   operations. So no need to handle lifetimes in wakelock.c
>
> v4:
> - Added 'Co-developed-by:' and 'Tested-by:' fields to commit message.
> - Moved new documentation to a separate file
>   Documentation/ABI/testing/sysfs-class-wakeup, as per Greg.
> - Fixed copyright header in drivers/base/power/wakeup_stats.c, as per Greg.
>
> diff --git a/Documentation/ABI/testing/sysfs-class-wakeup 
> b/Documentation/ABI/testing/sysfs-class-wakeup
> new file mode 100644
> index ..30fb23eb9112
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-class-wakeup
> @@ -0,0 +1,70 @@
> +What:  /sys/class/wakeup/
> +Date:  June 2019
> +Contact:   Tri Vo 
> +Description:
> +   The /sys/class/wakeup/ directory contains pointers to all
> +   wakeup sources in the kernel at that moment in time.
> +
> +What:  /sys/class/wakeup/.../active_count
> +Date:  June 2019
> +Contact:   Tri Vo 
> +Description:
> +   This file contains the number of times the wakeup source was
> +   activated.
> +
> +What:  /sys/class/wakeup/.../event_count
> +Date:  June 2019
> +Contact:   Tri Vo 
> +Description:
> +   This file contains the number of signaled wakeup events
> +   associated with the wakeup source.
> +
> +What:  /sys/class/wakeup/.../wakeup_count
> +Date:  June 2019
> +Contact:   Tri Vo 
> +Description:
> +   This file contains the number of times the wakeup source might
> +   abort suspend.
> +
> +What:  /sys/class/wakeup/.../expire_count
> +Date:  June 2019
> +Contact:   Tri Vo 
> +Description:
> +   This file contains the number of times the wakeup source's
> +   timeout has expired.
> +
> +What:  /sys/class/wakeup/.../active_time_ms
> +Date:  June 2019
> +Contact:   Tri Vo 
> +Description:
> +   This file contains the amount of time the wakeup source has
> +   been continuously active, in milliseconds.  If the wakeup
> +   source is not active, this file contains '0'.
> +
> +What:  /sys/class/wakeup/.../total_time_ms
> +Date:  June 2019
> +Contact:   Tri Vo 
> +Description:
> +   This file contains the total amount of time this wakeup source
> +   has been active, in milliseconds.
> +
> +What:  /sys/class/wakeup/.../max_time_ms
> +Date:  June 2019
> +Contact:   Tri Vo 
> +Description:
> +   This file contains the maximum amount of time this wakeup
> +   source has been continuously active, in milliseconds.
> +
> +What:  /sys/class/wakeup/.../last_change_ms
> +Date:  June 2019
> +Contact:   Tri Vo 
> 

RE: [PATCH] staging: kpc2000: Convert put_page() to put_user_page*()

2019-07-15 Thread Matt Sickler
It looks like Outlook is going to absolutely trash this email.  Hopefully it 
comes through okay.

>> There have been issues with get_user_pages and filesystem writeback.
>> The issues are better described in [1].
>>
>> The solution being proposed wants to keep track of gup_pinned pages
>which will allow to take furthur steps to coordinate between subsystems
>using gup.
>>
>> put_user_page() simply calls put_page inside for now. But the
>implementation will change once all call sites of put_page() are converted.
>>
>> I currently do not have the driver to test. Could I have some suggestions to
>test this code? The solution is currently implemented in [2] and
>> it would be great if we could apply the patch on top of [2] and run some
>tests to check if any regressions occur.
>
>Because this is a common pattern, and because the code here doesn't likely
>need to set page dirty before the dma_unmap_sg call, I think the following
>would be better (it's untested), instead of the above diff hunk:
>
>diff --git a/drivers/staging/kpc2000/kpc_dma/fileops.c
>b/drivers/staging/kpc2000/kpc_dma/fileops.c
>index 48ca88bc6b0b..d486f9866449 100644
>--- a/drivers/staging/kpc2000/kpc_dma/fileops.c
>+++ b/drivers/staging/kpc2000/kpc_dma/fileops.c
>@@ -211,16 +211,13 @@ void  transfer_complete_cb(struct aio_cb_data
>*acd, size_t xfr_count, u32 flags)
>BUG_ON(acd->ldev == NULL);
>BUG_ON(acd->ldev->pldev == NULL);
>
>-   for (i = 0 ; i < acd->page_count ; i++) {
>-   if (!PageReserved(acd->user_pages[i])) {
>-   set_page_dirty(acd->user_pages[i]);
>-   }
>-   }
>-
>dma_unmap_sg(>ldev->pldev->dev, acd->sgt.sgl, acd->sgt.nents, 
> acd->ldev->dir);
>
>for (i = 0 ; i < acd->page_count ; i++) {
>-   put_page(acd->user_pages[i]);
>+   if (!PageReserved(acd->user_pages[i])) {
>+   put_user_pages_dirty(>user_pages[i], 1);
>+   else
>+   put_user_page(acd->user_pages[i]);
>}
>
>sg_free_table(>sgt);

I don't think I ever really knew the right way to do this. 

The changes Bharath suggested look okay to me.  I'm not sure about the check 
for PageReserved(), though.  At first glance it appears to be equivalent to 
what was there before, but maybe I should learn what that Reserved page flag 
really means.
From [1], the only comment that seems applicable is
* - MMIO/DMA pages. Some architectures don't allow to ioremap pages that are
 *   not marked PG_reserved (as they might be in use by somebody else who does
 *   not respect the caching strategy).

These pages should be coming from anonymous (RAM, not file backed) memory in 
userspace.  Sometimes it comes from hugepage backed memory, though I don't 
think that makes a difference.  I should note that transfer_complete_cb handles 
both RAM to device and device to RAM DMAs, if that matters.

[1] https://elixir.bootlin.com/linux/v5.2/source/include/linux/page-flags.h#L17


Re: [PATCH v3] PM / wakeup: show wakeup sources stats in sysfs

2019-07-15 Thread Tri Vo
On Mon, Jul 15, 2019 at 1:37 PM Greg KH  wrote:
>
> On Mon, Jul 15, 2019 at 01:11:16PM -0700, Tri Vo wrote:
> > Userspace can use wakeup_sources debugfs node to plot history of suspend
> > blocking wakeup sources over device's boot cycle. This information can
> > then be used (1) for power-specific bug reporting and (2) towards
> > attributing battery consumption to specific processes over a period of
> > time.
> >
> > However, debugfs doesn't have stable ABI. For this reason, create a
> > 'struct device' to expose wakeup sources statistics in sysfs under
> > /sys/class/wakeup//.
> >
> > Introduce CONFIG_PM_SLEEP_STATS that enables/disables showing wakeup
> > source statistics in sysfs.
> >
> > Suggested-by: Greg Kroah-Hartman 
> > Signed-off-by: Tri Vo 
> > Tested-by: Tri Vo 
>
> Co-Developed-by: Greg Kroah-Hartman 
> perhaps given that I rewrote the whole file last time?  :)

Thanks again for the help!
>
>
> > ---
> >  Documentation/ABI/testing/sysfs-power |  73 -
> >  drivers/base/power/Makefile   |   1 +
> >  drivers/base/power/wakeup.c   |  12 ++-
> >  drivers/base/power/wakeup_stats.c | 148 ++
> >  include/linux/pm_wakeup.h |  19 
> >  kernel/power/Kconfig  |  10 ++
> >  kernel/power/wakelock.c   |  10 ++
> >  7 files changed, 270 insertions(+), 3 deletions(-)
> >  create mode 100644 drivers/base/power/wakeup_stats.c
>
> What changed from v2?  :)

Oops, my bad.

> And I am guessing that you actually tested this all out, and it works
> for you?

Yes, I played around with wakelocks to make sure that wakeup source
stats are added/updated/removed as expected.

> Have you changed Android userspace to use the new api with no
> problems?

Kalesh helped me test this patch (added him in Tested-by: field in
latest patch version). We haven't tested beyond booting and manual
inspection on android devices. Android userspace changes should be
fairly trivial though.


Re: [PATCH 00/22] x86, objtool: several fixes/improvements

2019-07-15 Thread Nick Desaulniers
On Mon, Jul 15, 2019 at 12:38 PM Josh Poimboeuf  wrote:
>
> On Sun, Jul 14, 2019 at 07:36:55PM -0500, Josh Poimboeuf wrote:
> > There have been a lot of objtool bug reports lately, mainly related to
> > Clang and BPF.  As part of fixing those bugs, I added some improvements
> > to objtool which uncovered yet more bugs (some kernel, some objtool).
> >
> > I've given these patches a lot of testing with both GCC and Clang.  More
> > compile testing of objtool would be appreciated, as the kbuild test
> > robot doesn't seem to be paying much attention to my branches lately.
> >
> > There are still at least three outstanding issues:
> >
> > 1) With clang I see:
> >
> >  drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: 
> > .altinstr_replacement+0x88: redundant UACCESS disable

For a defconfig, that's the only issue I see.
(Note that I just landed https://reviews.llvm.org/rL366130 for fixing
up bugs from loop unrolling loops containing asm goto with Clang, so
anyone else testing w/ clang will see fewer objtool warnings with that
patch applied.  A follow up is being worked on in
https://reviews.llvm.org/D64101).

For allmodconfig:
arch/x86/ia32/ia32_signal.o: warning: objtool:
ia32_setup_rt_frame()+0x247: call to memset() with UACCESS enabled
mm/kasan/common.o: warning: objtool: kasan_report()+0x52: call to
__stack_chk_fail() with UACCESS enabled
arch/x86/kernel/signal.o: warning: objtool:
x32_setup_rt_frame()+0x255: call to memset() with UACCESS enabled
arch/x86/kernel/signal.o: warning: objtool: __setup_rt_frame()+0x254:
call to memset() with UACCESS enabled
drivers/ata/sata_dwc_460ex.o: warning: objtool:
sata_dwc_bmdma_start_by_tag()+0x3a0: can't find switch jump table
lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch()+0x88:
call to memset() with UACCESS enabled
lib/ubsan.o: warning: objtool: ubsan_type_mismatch_common()+0x610:
call to __stack_chk_fail() with UACCESS enabled
lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch_v1()+0x88:
call to memset() with UACCESS enabled
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool:
.altinstr_replacement+0x56: redundant UACCESS disable

Without your series, I see them anyways, so I don't consider them
regressions added by this series.  Let's follow up on these maybe in a
new thread?  (Shall I send you these object files?)

So for the series:
Tested-by: Nick Desaulniers 

> >
> >I haven't dug into it yet.
> >
> > 2) There's also an issue in clang where a large switch table had a bunch
> >of unused (bad) entries.  It's not a code correctness issue, but
> >hopefully it can get fixed in clang anyway.  See patch 20/22 for more
> >details.

Thanks for the report, let's follow up on steps for me to reproduce.

> > These patches are also at:
> >   git://git.kernel.org/pub/scm/linux/kernel/git/jpoimboe/linux.git 
> > objtool-many-fixes

Are these the same patches? Some of the commit messages look different, like:
https://git.kernel.org/pub/scm/linux/kernel/git/jpoimboe/linux.git/commit/?h=objtool-many-fixes=3e39561c52c4f0062207d604c972148b7b60c341


--
Thanks,
~Nick Desaulniers


Re: [PATCH v1] clk: Add devm_clk_{prepare,enable,prepare_enable}

2019-07-15 Thread Bjorn Andersson
On Mon 15 Jul 08:34 PDT 2019, Marc Gonzalez wrote:

[..]
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index c0990703ce54..5e85548357c0 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -914,6 +914,18 @@ int clk_prepare(struct clk *clk)
>  }
>  EXPORT_SYMBOL_GPL(clk_prepare);
>  
> +static void unprepare(void *clk)

This deserves a less generic name.

> +{
> + clk_unprepare(clk);
> +}
> +
> +int devm_clk_prepare(struct device *dev, struct clk *clk)
> +{
> + int rc = clk_prepare(clk);
> + return rc ? : devm_add_action_or_reset(dev, unprepare, clk);
> +}
> +EXPORT_SYMBOL_GPL(devm_clk_prepare);
> +
>  static void clk_core_disable(struct clk_core *core)
>  {
>   lockdep_assert_held(_lock);
> @@ -1136,6 +1148,18 @@ int clk_enable(struct clk *clk)
>  }
>  EXPORT_SYMBOL_GPL(clk_enable);
>  
> +static void disable(void *clk)
> +{
> + clk_disable(clk);
> +}
> +
> +int devm_clk_enable(struct device *dev, struct clk *clk)

clk_enable() is used in code that can't sleep, in what scenario do you
envision it being useful to enable a clock from such region until devres
cleans up the associated device?

> +{
> + int rc = clk_enable(clk);
> + return rc ? : devm_add_action_or_reset(dev, disable, clk);

devm_add_action_or_reset() allocates the devres object with GFP_KERNEL,
so this won't work.

> +}
> +EXPORT_SYMBOL_GPL(devm_clk_enable);
> +
>  static int clk_core_prepare_enable(struct clk_core *core)
>  {
>   int ret;
> diff --git a/include/linux/clk.h b/include/linux/clk.h
> index 3c096c7a51dc..d09b5207e3f1 100644
> --- a/include/linux/clk.h
> +++ b/include/linux/clk.h
> @@ -895,6 +895,14 @@ static inline void clk_restore_context(void) {}
>  
>  #endif
>  
> +int devm_clk_prepare(struct device *dev, struct clk *clk);
> +int devm_clk_enable(struct device *dev, struct clk *clk);
> +static inline int devm_clk_prepare_enable(struct device *dev, struct clk 
> *clk)

devm_clk_prepare_enable() sounds very useful, devm_clk_prepare() might
be useful, so keep those and drop devm_clk_enable().

Regards,
Bjorn

> +{
> + int rc = devm_clk_prepare(dev, clk);
> + return rc ? : devm_clk_enable(dev, clk);
> +}
> +
>  /* clk_prepare_enable helps cases using clk_enable in non-atomic context. */
>  static inline int clk_prepare_enable(struct clk *clk)
>  {
> -- 
> 2.17.1


Re: [PATCH 8/9] acpi: Use built-in RCU list checking for acpi_ioremaps list (v1)

2019-07-15 Thread Rafael J. Wysocki
On Mon, Jul 15, 2019 at 4:43 PM Joel Fernandes (Google)
 wrote:
>
> list_for_each_entry_rcu has built-in RCU and lock checking. Make use of
> it for acpi_ioremaps list traversal.
>
> Signed-off-by: Joel Fernandes (Google) 

Acked-by: Rafael J. Wysocki 

> ---
>  drivers/acpi/osl.c | 6 --
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
> index 9c0edf2fc0dd..2f9d0d20b836 100644
> --- a/drivers/acpi/osl.c
> +++ b/drivers/acpi/osl.c
> @@ -14,6 +14,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -80,6 +81,7 @@ struct acpi_ioremap {
>
>  static LIST_HEAD(acpi_ioremaps);
>  static DEFINE_MUTEX(acpi_ioremap_lock);
> +#define acpi_ioremap_lock_held() lock_is_held(_ioremap_lock.dep_map)
>
>  static void __init acpi_request_region (struct acpi_generic_address *gas,
> unsigned int length, char *desc)
> @@ -206,7 +208,7 @@ acpi_map_lookup(acpi_physical_address phys, acpi_size 
> size)
>  {
> struct acpi_ioremap *map;
>
> -   list_for_each_entry_rcu(map, _ioremaps, list)
> +   list_for_each_entry_rcu(map, _ioremaps, list, 
> acpi_ioremap_lock_held())
> if (map->phys <= phys &&
> phys + size <= map->phys + map->size)
> return map;
> @@ -249,7 +251,7 @@ acpi_map_lookup_virt(void __iomem *virt, acpi_size size)
>  {
> struct acpi_ioremap *map;
>
> -   list_for_each_entry_rcu(map, _ioremaps, list)
> +   list_for_each_entry_rcu(map, _ioremaps, list, 
> acpi_ioremap_lock_held())
> if (map->virt <= virt &&
> virt + size <= map->virt + map->size)
> return map;
> --
> 2.22.0.510.g264f2c817a-goog
>


[PATCH v4] PM / wakeup: show wakeup sources stats in sysfs

2019-07-15 Thread Tri Vo
Userspace can use wakeup_sources debugfs node to plot history of suspend
blocking wakeup sources over device's boot cycle. This information can
then be used (1) for power-specific bug reporting and (2) towards
attributing battery consumption to specific processes over a period of
time.

However, debugfs doesn't have stable ABI. For this reason, create a
'struct device' to expose wakeup sources statistics in sysfs under
/sys/class/wakeup//.

Introduce CONFIG_PM_SLEEP_STATS that enables/disables showing wakeup
source statistics in sysfs.

Co-developed-by: Greg Kroah-Hartman 
Signed-off-by: Tri Vo 
Tested-by: Tri Vo 
Tested-by: Kalesh Singh 
---
 Documentation/ABI/testing/sysfs-class-wakeup |  70 +
 drivers/base/power/Makefile  |   1 +
 drivers/base/power/wakeup.c  |  12 +-
 drivers/base/power/wakeup_stats.c| 149 +++
 include/linux/pm_wakeup.h|  19 +++
 kernel/power/Kconfig |  10 ++
 kernel/power/wakelock.c  |  10 ++
 7 files changed, 269 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-wakeup
 create mode 100644 drivers/base/power/wakeup_stats.c

v2:
- Updated Documentation/ABI/, as per Greg.
- Removed locks in attribute functions, as per Greg.
- Lifetimes of struct wakelock and struck wakeup_source are now different due to
  the latter embedding a refcounted kobject. Changed it so that struct wakelock
  only has a pointer to struct wakeup_source, instead of embedding it.
- Added CONFIG_PM_SLEEP_STATS that enables/disables wakeup source statistics in
  sysfs.

v3:
Changes by Greg:
- Reworked code to use 'struct device' instead of raw kobjects.
- Updated documentation file.
- Only link wakeup_stats.o when CONFIG_PM_SLEEP_STATS is enabled.
Changes by Tri:
- Reverted changes to kernel/power/wakelock.c. 'struct device' hides kobject
  operations. So no need to handle lifetimes in wakelock.c

v4:
- Added 'Co-developed-by:' and 'Tested-by:' fields to commit message.
- Moved new documentation to a separate file
  Documentation/ABI/testing/sysfs-class-wakeup, as per Greg.
- Fixed copyright header in drivers/base/power/wakeup_stats.c, as per Greg.

diff --git a/Documentation/ABI/testing/sysfs-class-wakeup 
b/Documentation/ABI/testing/sysfs-class-wakeup
new file mode 100644
index ..30fb23eb9112
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-class-wakeup
@@ -0,0 +1,70 @@
+What:  /sys/class/wakeup/
+Date:  June 2019
+Contact:   Tri Vo 
+Description:
+   The /sys/class/wakeup/ directory contains pointers to all
+   wakeup sources in the kernel at that moment in time.
+
+What:  /sys/class/wakeup/.../active_count
+Date:  June 2019
+Contact:   Tri Vo 
+Description:
+   This file contains the number of times the wakeup source was
+   activated.
+
+What:  /sys/class/wakeup/.../event_count
+Date:  June 2019
+Contact:   Tri Vo 
+Description:
+   This file contains the number of signaled wakeup events
+   associated with the wakeup source.
+
+What:  /sys/class/wakeup/.../wakeup_count
+Date:  June 2019
+Contact:   Tri Vo 
+Description:
+   This file contains the number of times the wakeup source might
+   abort suspend.
+
+What:  /sys/class/wakeup/.../expire_count
+Date:  June 2019
+Contact:   Tri Vo 
+Description:
+   This file contains the number of times the wakeup source's
+   timeout has expired.
+
+What:  /sys/class/wakeup/.../active_time_ms
+Date:  June 2019
+Contact:   Tri Vo 
+Description:
+   This file contains the amount of time the wakeup source has
+   been continuously active, in milliseconds.  If the wakeup
+   source is not active, this file contains '0'.
+
+What:  /sys/class/wakeup/.../total_time_ms
+Date:  June 2019
+Contact:   Tri Vo 
+Description:
+   This file contains the total amount of time this wakeup source
+   has been active, in milliseconds.
+
+What:  /sys/class/wakeup/.../max_time_ms
+Date:  June 2019
+Contact:   Tri Vo 
+Description:
+   This file contains the maximum amount of time this wakeup
+   source has been continuously active, in milliseconds.
+
+What:  /sys/class/wakeup/.../last_change_ms
+Date:  June 2019
+Contact:   Tri Vo 
+Description:
+   This file contains the monotonic clock time when the wakeup
+   source was touched last time, in milliseconds.
+
+What:  /sys/class/wakeup/.../prevent_suspend_time_ms
+Date:  June 2019
+Contact:   Tri Vo 
+Description:
+   The file contains the total amount of time this wakeup source
+   has been preventing autosleep, in 

[PATCH 4/5] MIPS: ingenic: Add support for huge pages

2019-07-15 Thread Paul Cercueil
From: Daniel Silsby 

The Ingenic jz47xx SoC series of 32-bit MIPS CPUs support huge pages.

Signed-off-by: Daniel Silsby 
Signed-off-by: Paul Cercueil 
---
 arch/mips/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 47d50e37faa4..2a5d80c72c4e 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -384,6 +384,7 @@ config MACH_INGENIC
select SYS_SUPPORTS_32BIT_KERNEL
select SYS_SUPPORTS_LITTLE_ENDIAN
select SYS_SUPPORTS_ZBOOT_UART16550
+   select CPU_SUPPORTS_HUGEPAGES
select DMA_NONCOHERENT
select IRQ_MIPS_CPU
select PINCTRL
-- 
2.21.0.593.g511ec345e18



[PATCH 5/5] MIPS: Undefine PMD_ORDER for 32-bit builds

2019-07-15 Thread Paul Cercueil
From: Daniel Silsby 

During an update long ago to conform to 4-level page code, PMD_ORDER was
changed from 0 to 1, despite the fact that a PMD table is not used at
all in a 32-bit MIPS build. PMD_ORDER does not seem to be used in these
builds. Now, it matches PUD_ORDER, a nonsense #define to give a build
failure with informative error.

The older commit that had redefined PMD_ORDER was
commit c6e8b587718c ("Update MIPS to use the 4-level pagetable code
thereby getting rid of the compacrapability headers.")

Signed-off-by: Daniel Silsby 
Signed-off-by: Paul Cercueil 
---
 arch/mips/include/asm/pgtable-32.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/include/asm/pgtable-32.h 
b/arch/mips/include/asm/pgtable-32.h
index b0a78c9b6434..e600570789f4 100644
--- a/arch/mips/include/asm/pgtable-32.h
+++ b/arch/mips/include/asm/pgtable-32.h
@@ -83,7 +83,7 @@ extern int add_temporary_entry(unsigned long entrylo0, 
unsigned long entrylo1,
 
 #define PGD_ORDER  (__PGD_ORDER >= 0 ? __PGD_ORDER : 0)
 #define PUD_ORDER  ai_attempt_to_allocate_pud
-#define PMD_ORDER  1
+#define PMD_ORDER  ai_attempt_to_allocate_pmd
 #define PTE_ORDER  0
 
 #define PTRS_PER_PGD   (USER_PTRS_PER_PGD * 2)
-- 
2.21.0.593.g511ec345e18



[PATCH 1/5] MIPS: Disallow CPU_SUPPORTS_HUGEPAGES for XPA,EVA

2019-07-15 Thread Paul Cercueil
From: Daniel Silsby 

In preparation for 32-bit MIPS huge page support.

EVA,XPA are extended-addressing modes for 32-bit MIPS systems. Because
huge pages aren't currently supported in 32-bit MIPS, this doesn't take
any features away from EVA,XPA-enabled systems. However, the soon-to-
come 32-bit MIPS huge page support doesn't yet support them.

This also disables CPU_SUPPORTS_HUGEPAGES for the small number of 32-bit
MIPS CPUs from Alchemy/Netlogic that support a custom 36-bit extended
addressing. It's unknown if they even support huge pages in hardware.

Signed-off-by: Daniel Silsby 
Signed-off-by: Paul Cercueil 
---
 arch/mips/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index d50fafd7bf3a..ff5f1314241e 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -2110,6 +2110,7 @@ config CPU_SUPPORTS_ADDRWINCFG
bool
 config CPU_SUPPORTS_HUGEPAGES
bool
+   depends on !(32BIT && (ARCH_PHYS_ADDR_T_64BIT || EVA))
 config CPU_SUPPORTS_UNCACHED_ACCELERATED
bool
 config MIPS_PGD_C0_CONTEXT
-- 
2.21.0.593.g511ec345e18



[PATCH 3/5] MIPS: Decouple CPU_SUPPORTS_HUGEPAGES from 64BIT

2019-07-15 Thread Paul Cercueil
From: Daniel Silsby 

We now have partial 32-bit MIPS huge page support, so there's no need
to restrict these config options only to 64-bit systems.

Signed-off-by: Daniel Silsby 
Signed-off-by: Paul Cercueil 
---
 arch/mips/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index ff5f1314241e..47d50e37faa4 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -43,7 +43,7 @@ config MIPS
select HAVE_ARCH_MMAP_RND_COMPAT_BITS if MMU && COMPAT
select HAVE_ARCH_SECCOMP_FILTER
select HAVE_ARCH_TRACEHOOK
-   select HAVE_ARCH_TRANSPARENT_HUGEPAGE if CPU_SUPPORTS_HUGEPAGES && 64BIT
+   select HAVE_ARCH_TRANSPARENT_HUGEPAGE if CPU_SUPPORTS_HUGEPAGES
select HAVE_EBPF_JIT if (!CPU_MICROMIPS)
select HAVE_CONTEXT_TRACKING
select HAVE_COPY_THREAD_TLS
@@ -1223,7 +1223,7 @@ config SYS_SUPPORTS_LITTLE_ENDIAN
 
 config SYS_SUPPORTS_HUGETLBFS
bool
-   depends on CPU_SUPPORTS_HUGEPAGES && 64BIT
+   depends on CPU_SUPPORTS_HUGEPAGES
default y
 
 config MIPS_HUGE_TLB_SUPPORT
-- 
2.21.0.593.g511ec345e18



[PATCH 2/5] MIPS: Add partial 32-bit huge page support

2019-07-15 Thread Paul Cercueil
From: Daniel Silsby 

 This adds initial support for huge pages to 32-bit MIPS systems.
Systems with extended addressing enabled (EVA,XPA,Alchemy/Netlogic)
are not yet supported.
 With huge pages enabled, this implementation will increase page table
memory overhead to match that of a 64-bit MIPS system. However, the
cache-friendliness of page table walks is not affected significantly.

Signed-off-by: Daniel Silsby 
Signed-off-by: Paul Cercueil 
---
 arch/mips/include/asm/pgtable-32.h   | 56 +---
 arch/mips/include/asm/pgtable-bits.h |  4 +-
 arch/mips/mm/pgtable-32.c| 20 ++
 3 files changed, 73 insertions(+), 7 deletions(-)

diff --git a/arch/mips/include/asm/pgtable-32.h 
b/arch/mips/include/asm/pgtable-32.h
index 74afe8c76bdd..b0a78c9b6434 100644
--- a/arch/mips/include/asm/pgtable-32.h
+++ b/arch/mips/include/asm/pgtable-32.h
@@ -23,6 +23,24 @@
 #include 
 #endif
 
+/*
+ * Regarding 32-bit MIPS huge page support (and the tradeoff it entails):
+ *
+ *  We use the same huge page sizes as 64-bit MIPS. Assuming a 4KB page size,
+ * our 2-level table layout would normally have a PGD entry cover a contiguous
+ * 4MB virtual address region (pointing to a 4KB PTE page of 1,024 32-bit pte_t
+ * pointers, each pointing to a 4KB physical page). The problem is that 4MB,
+ * spanning both halves of a TLB EntryLo0,1 pair, requires 2MB hardware page
+ * support, not one of the standard supported sizes (1MB,4MB,16MB,...).
+ *  To correct for this, when huge pages are enabled, we halve the number of
+ * pointers a PTE page holds, making its last half go to waste. 
Correspondingly,
+ * we double the number of PGD pages. Overall, page table memory overhead
+ * increases to match 64-bit MIPS, but PTE lookups remain CPU cache-friendly.
+ *
+ * NOTE: We don't yet support huge pages if extended-addressing is enabled
+ *   (i.e. EVA, XPA, 36-bit Alchemy/Netlogic).
+ */
+
 extern int temp_tlb_entry;
 
 /*
@@ -44,7 +62,12 @@ extern int add_temporary_entry(unsigned long entrylo0, 
unsigned long entrylo1,
  */
 
 /* PGDIR_SHIFT determines what a third-level page table entry can map */
-#define PGDIR_SHIFT(2 * PAGE_SHIFT + PTE_ORDER - PTE_T_LOG2)
+#if defined(CONFIG_MIPS_HUGE_TLB_SUPPORT) && !defined(CONFIG_PHYS_ADDR_T_64BIT)
+# define PGDIR_SHIFT   (2 * PAGE_SHIFT + PTE_ORDER - PTE_T_LOG2 - 1)
+#else
+# define PGDIR_SHIFT   (2 * PAGE_SHIFT + PTE_ORDER - PTE_T_LOG2)
+#endif
+
 #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
 #define PGDIR_MASK (~(PGDIR_SIZE-1))
 
@@ -52,14 +75,23 @@ extern int add_temporary_entry(unsigned long entrylo0, 
unsigned long entrylo1,
  * Entries per page directory level: we use two-level, so
  * we don't really have any PUD/PMD directory physically.
  */
-#define __PGD_ORDER(32 - 3 * PAGE_SHIFT + PGD_T_LOG2 + PTE_T_LOG2)
+#if defined(CONFIG_MIPS_HUGE_TLB_SUPPORT) && !defined(CONFIG_PHYS_ADDR_T_64BIT)
+# define __PGD_ORDER   (32 - 3 * PAGE_SHIFT + PGD_T_LOG2 + PTE_T_LOG2 + 1)
+#else
+# define __PGD_ORDER   (32 - 3 * PAGE_SHIFT + PGD_T_LOG2 + PTE_T_LOG2)
+#endif
+
 #define PGD_ORDER  (__PGD_ORDER >= 0 ? __PGD_ORDER : 0)
 #define PUD_ORDER  ai_attempt_to_allocate_pud
 #define PMD_ORDER  1
 #define PTE_ORDER  0
 
 #define PTRS_PER_PGD   (USER_PTRS_PER_PGD * 2)
-#define PTRS_PER_PTE   ((PAGE_SIZE << PTE_ORDER) / sizeof(pte_t))
+#if defined(CONFIG_MIPS_HUGE_TLB_SUPPORT) && !defined(CONFIG_PHYS_ADDR_T_64BIT)
+# define PTRS_PER_PTE  ((PAGE_SIZE << PTE_ORDER) / sizeof(pte_t) / 2)
+#else
+# define PTRS_PER_PTE  ((PAGE_SIZE << PTE_ORDER) / sizeof(pte_t))
+#endif
 
 #define USER_PTRS_PER_PGD  (0x8000UL/PGDIR_SIZE)
 #define FIRST_USER_ADDRESS 0UL
@@ -87,7 +119,7 @@ extern int add_temporary_entry(unsigned long entrylo0, 
unsigned long entrylo1,
 
 extern void load_pgd(unsigned long pg_dir);
 
-extern pte_t invalid_pte_table[PAGE_SIZE/sizeof(pte_t)];
+extern pte_t invalid_pte_table[PTRS_PER_PTE];
 
 /*
  * Empty pgd/pmd entries point to the invalid_pte_table.
@@ -97,7 +129,19 @@ static inline int pmd_none(pmd_t pmd)
return pmd_val(pmd) == (unsigned long) invalid_pte_table;
 }
 
-#define pmd_bad(pmd)   (pmd_val(pmd) & ~PAGE_MASK)
+static inline int pmd_bad(pmd_t pmd)
+{
+#ifdef CONFIG_MIPS_HUGE_TLB_SUPPORT
+   /* pmd_huge(pmd) but inline */
+   if (unlikely(pmd_val(pmd) & _PAGE_HUGE))
+   return 0;
+#endif
+
+   if (unlikely(pmd_val(pmd) & ~PAGE_MASK))
+   return 1;
+
+   return 0;
+}
 
 static inline int pmd_present(pmd_t pmd)
 {
@@ -146,6 +190,7 @@ static inline pte_t pfn_pte(unsigned long pfn, pgprot_t 
prot)
 #else
 #define pte_pfn(x) ((unsigned long)((x).pte >> _PFN_SHIFT))
 #define pfn_pte(pfn, prot) __pte(((unsigned long long)(pfn) << _PFN_SHIFT) 
| pgprot_val(prot))
+#define pfn_pmd(pfn, prot) __pmd(((unsigned long long)(pfn) << _PFN_SHIFT) 
| pgprot_val(prot))
 #endif
 #endif /* defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32) */
 
@@ 

[PULL REQUEST] i2c for 5.3

2019-07-15 Thread Wolfram Sang
Linus,

new stuff from the I2C world:

* in the core, getting irqs from ACPI is now similar to OF
* new driver for MediaTek MT7621/7628/7688 SoCs
* bcm2835, i801, and tegra drivers got some more attention
* GPIO API cleanups
* cleanups in the core headers
* lots of usual driver updates

There is a trivial merge conflict (SPDX header) in the meson driver.

Please pull.

Thanks,

   Wolfram


The following changes since commit cd6c84d8f0cdc911df435bb075ba22ce3c605b07:

  Linux 5.2-rc2 (2019-05-26 16:49:19 -0700)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/for-5.3

for you to fetch changes up to cc6b9dfb2c5769afeb3335048173c730bdf8dbe1:

  i2c: mt7621: Fix platform_no_drv_owner.cocci warnings (2019-07-06 17:04:32 
+0200)


Ajay Gupta (5):
  i2c: nvidia-gpu: refactor master_xfer
  i2c: nvidia-gpu: add runtime pm support
  usb: typec: ucsi: ccg: enable runtime pm support
  i2c: nvidia-gpu: resume ccgx i2c client
  usb: typec: ucsi: ccg: add runtime pm workaround

Alexander Sverdlin (1):
  i2c: i801: Add Block Write-Block Read Process Call support

Andy Shevchenko (2):
  i2c: i801: Fix kernel crash in is_dell_system_with_lis3lv02d()
  i2c: i801: Use match_string() helper to simplify the code

Annaliese McDermond (3):
  i2c: bcm2835: Model Divider in CCF
  i2c: bcm2835: Move IRQ request after clock code in probe
  i2c: bcm2835: Ensure clock exists when probing

Anson Huang (1):
  i2c: imx: Use __maybe_unused instead of #if CONFIG_PM

Bartosz Golaszewski (3):
  eeprom: at24: use devm_i2c_new_dummy_device()
  eeprom: at24: drop unnecessary label
  eeprom: at24: modify a comment referring to platform data

Bitan Biswas (7):
  i2c: tegra: clean up macros
  i2c: tegra: remove unnecessary variable init
  i2c: tegra: fix alignment and spacing violations
  i2c: tegra: add spinlock definition comment
  i2c: tegra: fix msleep warning
  i2c: tegra: Add suspend-resume support
  i2c: tegra: remove BUG() macro

Charles Keepax (6):
  i2c: core: Allow whole core to use i2c_dev_irq_from_resources
  i2c: acpi: Use available IRQ helper functions
  i2c: acpi: Factor out getting the IRQ from ACPI
  i2c: core: Move ACPI IRQ handling to probe time
  i2c: core: Move ACPI gpio IRQ handling into i2c_acpi_get_irq
  i2c: core: Tidy up handling of init_irq

Fabrice Gasnier (3):
  i2c: stm32f7: fix the get_irq error cases
  i2c: i2c-stm32f7: Add I2C_SMBUS_I2C_BLOCK_DATA support
  dt-bindings: i2c-stm32: document optional dmas

Gustavo A. R. Silva (3):
  eeprom: at24: use struct_size() in devm_kzalloc()
  i2c: mux: Use struct_size() in devm_kzalloc()
  i2c: mux: pinctrl: use flexible-array member and struct_size() helper

Jarkko Nikula (3):
  i2c: i801: Add support for Intel Elkhart Lake
  i2c: i801: Fix PCI ID sorting
  i2c: i801: Add support for Intel Tiger Lake

Jean Delvare (1):
  i2c: i801: Documentation update

Kamal Dasu (1):
  i2c: Allow selecting BCM2835 I2C controllers on ARCH_BRCMSTB

Lee Jones (2):
  i2c: qcom-geni: Signify successful driver probe
  i2c: qcom-geni: Provide support for ACPI

Linus Walleij (4):
  i2c: mux: arb-gpio: Rewrite to use GPIO descriptors
  i2c: s3c2410: Convert to use GPIO descriptors
  i2c: iop: Use GPIO descriptors
  i2c: mux/i801: Switch to use descriptor passing

Maxime Ripard (4):
  dt-bindings: i2c: sun6i-p2wi: Add YAML schemas
  dt-bindings: i2c: mv64xxx: Add YAML schemas
  dt-bindings: i2c: mv64xxx: Fix the example compatible
  dt-bindings: i2c: sun6i-p2wi: Fix the binding example

Neil Armstrong (1):
  i2c: meson: update with SPDX Licence identifier

Oliver O'Halloran (1):
  i2c: fsi: Create busses for all ports

Pali Roh??r (1):
  i2c: i801: Register optional lis3lv02d I2C device on Dell machines

Paul Cercueil (1):
  i2c: jz4780: Drop dependency on MACH_JZ4780

Peter Ujfalusi (1):
  dt-bindings: i2c: omap: Add new compatible for J721E SoCs

Rayagonda Kokatanur (1):
  i2c: iproc: Add multi byte read-write support for slave mode

Ruslan Babayev (1):
  i2c: acpi: export i2c_acpi_find_adapter_by_handle

Sagar Shrikant Kadam (3):
  dt-bindings: i2c: extend existing opencore bindings
  i2c: ocores: add support for i2c device on Sifive FU540-c000 SoC
  i2c: ocores: add polling mode workaround for Sifive FU540-C000 SoC

Stefan Roese (2):
  dt-bindings: i2c: i2c-mt7621: Add bindings for MediaTek MT7621/28/88 I2C
  i2c: mt7621: Add MediaTek MT7621/7628/7688 I2C driver

Thierry Reding (1):
  i2c: tegra: Avoid error message on deferred probe

Vasyl Gomonovych (1):
  i2c: cpm: remove casting dma_alloc

Wolfram Sang (11):
  i2c: headers: don't use 'dev' as adapter variable
  i2c: headers: always have a named variable in 

Re: [PATCH v3 3/5] locking/qspinlock: Introduce CNA into the slow path of qspinlock

2019-07-15 Thread Waiman Long
On 7/15/19 3:25 PM, Alex Kogan wrote:
> In CNA, spinning threads are organized in two queues, a main queue for
> threads running on the same node as the current lock holder, and a
> secondary queue for threads running on other nodes. At the unlock time,
> the lock holder scans the main queue looking for a thread running on
> the same node. If found (call it thread T), all threads in the main queue
> between the current lock holder and T are moved to the end of the
> secondary queue, and the lock is passed to T. If such T is not found, the
> lock is passed to the first node in the secondary queue. Finally, if the
> secondary queue is empty, the lock is passed to the next thread in the
> main queue. For more details, see https://arxiv.org/abs/1810.05600.
>
> Note that this variant of CNA may introduce starvation by continuously
> passing the lock to threads running on the same node. This issue
> will be addressed later in the series.
>
> Enabling CNA is controlled via a new configuration option
> (NUMA_AWARE_SPINLOCKS). The CNA variant is patched in
> at the boot time only if we run a multi-node machine, and the new
> config is enabled. For the time being, the patching requires
> CONFIG_PARAVIRT_SPINLOCKS to be enabled as well.
> However, this should be resolved once static_call() is available.
>
> Signed-off-by: Alex Kogan 
> Reviewed-by: Steve Sistare 
> ---
>  arch/x86/Kconfig |  18 +
>  arch/x86/include/asm/qspinlock.h |   4 +
>  arch/x86/kernel/alternative.c|  12 +++
>  kernel/locking/mcs_spinlock.h|   2 +-
>  kernel/locking/qspinlock.c   |  41 +++---
>  kernel/locking/qspinlock_cna.h   | 164 
> +++
>  6 files changed, 229 insertions(+), 12 deletions(-)
>  create mode 100644 kernel/locking/qspinlock_cna.h
>
> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> index 2bbbd4d1ba31..1d8f80c47687 100644
> --- a/arch/x86/Kconfig
> +++ b/arch/x86/Kconfig
> @@ -1548,6 +1548,24 @@ config NUMA
>  
> Otherwise, you should say N.
>  
> +config NUMA_AWARE_SPINLOCKS
> + bool "Numa-aware spinlocks"
> + depends on NUMA
> + # For now, we depend on PARAVIRT_SPINLOCKS to make the patching work.
> + # This is awkward, but hopefully would be resolved once static_call()
> + # is available.
> + depends on PARAVIRT_SPINLOCKS
> + default y
> + help
> +   Introduce NUMA (Non Uniform Memory Access) awareness into
> +   the slow path of spinlocks.
> +
> +   The kernel will try to keep the lock on the same node,
> +   thus reducing the number of remote cache misses, while
> +   trading some of the short term fairness for better performance.
> +
> +   Say N if you want absolute first come first serve fairness.

You should also add a dependency on QUEUED_SPINLOCKS to highlight the
fact that it is a variant of qspinlock. You should also mention that in
the help text.


> +
>  config AMD_NUMA
>   def_bool y
>   prompt "Old style AMD Opteron NUMA detection"
> diff --git a/arch/x86/include/asm/qspinlock.h 
> b/arch/x86/include/asm/qspinlock.h
> index bd5ac6cc37db..d9b6c34d5eb4 100644
> --- a/arch/x86/include/asm/qspinlock.h
> +++ b/arch/x86/include/asm/qspinlock.h
> @@ -27,6 +27,10 @@ static __always_inline u32 
> queued_fetch_set_pending_acquire(struct qspinlock *lo
>   return val;
>  }
>  
> +#ifdef CONFIG_NUMA_AWARE_SPINLOCKS
> +extern void __cna_queued_spin_lock_slowpath(struct qspinlock *lock, u32 val);
> +#endif
> +
>  #ifdef CONFIG_PARAVIRT_SPINLOCKS
>  extern void native_queued_spin_lock_slowpath(struct qspinlock *lock, u32 
> val);
>  extern void __pv_init_lock_hash(void);
> diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
> index 0d57015114e7..1c25f0505ec0 100644
> --- a/arch/x86/kernel/alternative.c
> +++ b/arch/x86/kernel/alternative.c
> @@ -649,6 +649,18 @@ void __init alternative_instructions(void)
>   (unsigned long)__smp_locks_end);
>  #endif
>  
> +#if defined(CONFIG_NUMA_AWARE_SPINLOCKS)
> + /*
> +  * If we have multiple NUMA nodes, switch from native
> +  * to the NUMA-friendly slow path for spin locks.
> +  */
> + if (nr_node_ids > 1 && pv_ops.lock.queued_spin_lock_slowpath ==
> + native_queued_spin_lock_slowpath) {
> + pv_ops.lock.queued_spin_lock_slowpath =
> + __cna_queued_spin_lock_slowpath;
> + }
> +#endif
> +
>   apply_paravirt(__parainstructions, __parainstructions_end);
>  
>   restart_nmi();
> diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
> index bc6d3244e1af..36b802babc88 100644
> --- a/kernel/locking/mcs_spinlock.h
> +++ b/kernel/locking/mcs_spinlock.h
> @@ -17,7 +17,7 @@
>  
>  struct mcs_spinlock {
>   struct mcs_spinlock *next;
> - int locked; /* 1 if lock acquired */
> + u64 locked; /* 1 if lock acquired */
>   int count;  /* nesting count, see qspinlock.c */
>  };
>  
> diff 

Re: [PATCH v9 01/18] kunit: test: add KUnit test runner core

2019-07-15 Thread Brendan Higgins
On Mon, Jul 15, 2019 at 1:10 PM Stephen Boyd  wrote:
>
> Quoting Brendan Higgins (2019-07-12 01:17:27)
> > Add core facilities for defining unit tests; this provides a common way
> > to define test cases, functions that execute code which is under test
> > and determine whether the code under test behaves as expected; this also
> > provides a way to group together related test cases in test suites (here
> > we call them test_modules).
> >
> > Just define test cases and how to execute them for now; setting
> > expectations on code will be defined later.
> >
> > Signed-off-by: Brendan Higgins 
> > Reviewed-by: Greg Kroah-Hartman 
> > Reviewed-by: Logan Gunthorpe 
> > Reviewed-by: Luis Chamberlain 
>
> Reviewed-by: Stephen Boyd 
>
> Minor nits below.
>
> > diff --git a/kunit/test.c b/kunit/test.c
> > new file mode 100644
> > index 0..571e4c65deb5c
> > --- /dev/null
> > +++ b/kunit/test.c
> > @@ -0,0 +1,189 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Base unit test (KUnit) API.
> > + *
> > + * Copyright (C) 2019, Google LLC.
> > + * Author: Brendan Higgins 
> > + */
> > +
> > +#include 
> > +#include 
> > +
> > +static void kunit_set_failure(struct kunit *test)
> > +{
> > +   WRITE_ONCE(test->success, false);
> > +}
> > +
> [...]
> > +
> > +void kunit_init_test(struct kunit *test, const char *name)
> > +{
> > +   test->name = name;
> > +   test->success = true;
> > +}
> > +
> > +/*
> > + * Performs all logic to run a test case.
> > + */
> > +static void kunit_run_case(struct kunit_suite *suite,
> > +  struct kunit_case *test_case)
> > +{
> > +   struct kunit test;
> > +   int ret = 0;
> > +
> > +   kunit_init_test(, test_case->name);
> > +
> > +   if (suite->init) {
> > +   ret = suite->init();
>
> Can you push the ret definition into this if scope? That way we can
> avoid default initialize to 0 for it.

Sure! I would actually prefer that from a cosmetic standpoint. I just
thought that mixing declarations and code was against the style guide.

> > +   if (ret) {
> > +   kunit_err(, "failed to initialize: %d\n", ret);
> > +   kunit_set_failure();
>
> Do we need to 'test_case->success = test.success' here too? Or is the
> test failure extracted somewhere else?

Er, yes. That's kind of embarrassing. Good catch.

> > +   return;
> > +   }
> > +   }
> > +
> > +   test_case->run_case();
> > +
> > +   if (suite->exit)
> > +   suite->exit();
> > +
> > +   test_case->success = test.success;

Thanks!


Re: [PATCH 2/2] mm,memory_hotplug: Fix shrink_{zone,node}_span

2019-07-15 Thread Oscar Salvador
On Mon, 2019-07-15 at 21:41 +0530, Aneesh Kumar K.V wrote:
> Oscar Salvador  writes:
> 
> > Since [1], shrink_{zone,node}_span work on PAGES_PER_SUBSECTION
> > granularity.
> > The problem is that deactivation of the section occurs later on in
> > sparse_remove_section, so pfn_valid()->pfn_section_valid() will
> > always return
> > true before we deactivate the {sub}section.
> 
> Can you explain this more? The patch doesn't update section_mem_map
> update sequence. So what changed? What is the problem in finding
> pfn_valid() return true there?

I realized that the changelog was quite modest, so a better explanation
 will follow.

Let us analize what shrink_{zone,node}_span does.
We have to remember that shrink_zone_span gets called every time a
section is to be removed.

There can be three possibilites:

1) section to be removed is the first one of the zone
2) section to be removed is the last one of the zone
3) section to be removed falls in the middle
 
For 1) and 2) cases, we will try to find the next section from
bottom/top, and in the third case we will check whether the section
contains only holes.

Now, let us take the example where a ZONE contains only 1 section, and
we remove it.
The last loop of shrink_zone_span, will check for {start_pfn,end_pfn]
PAGES_PER_SECTION block the following:

- section is valid
- pfn relates to the current zone/nid
- section is not the section to be removed

Since we only got 1 section here, the check "start_pfn == pfn" will make us to 
continue the loop and then we are done.

Now, what happens after the patch?

We increment pfn on subsection basis, since "start_pfn == pfn", we jump
to the next sub-section (pfn+512), and call pfn_valid()-
>pfn_section_valid().
Since section has not been yet deactivded, pfn_section_valid() will
return true, and we will repeat this until the end of the loop.

What should happen instead is:

- we deactivate the {sub}-section before calling
shirnk_{zone,node}_span
- calls to pfn_valid() will now return false for the sections that have
been deactivated, and so we will get the pfn from the next activaded
sub-section, or nothing if the section is empty (section do not contain
active sub-sections).

The example relates to the last loop in shrink_zone_span, but the same
applies to find_{smalles,biggest}_section.

Please, note that we could probably do some hack like replacing:

start_pfn == pfn 

with

pfn < end_pfn

But the way to fix this is to 1) deactivate {sub}-section and 2) let
shrink_{node,zone}_span find the next active {sub-section}.

I hope this makes it more clear.


-- 
Oscar Salvador
SUSE L3


Re: list corruption in deferred_split_scan()

2019-07-15 Thread Qian Cai
On Fri, 2019-07-12 at 12:12 -0700, Yang Shi wrote:
> > Another possible lead is that without reverting the those commits below,
> > kdump
> > kernel would always also crash in shrink_slab_memcg() at this line,
> > 
> > map = rcu_dereference_protected(memcg->nodeinfo[nid]->shrinker_map, true);
> 
> This looks a little bit weird. It seems nodeinfo[nid] is NULL? I didn't 
> think of where nodeinfo was freed but memcg was still online. Maybe a 
> check is needed:

Actually, "memcg" is NULL.

> 
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index a0301ed..bacda49 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -602,6 +602,9 @@ static unsigned long shrink_slab_memcg(gfp_t 
> gfp_mask, int nid,
>  if (!mem_cgroup_online(memcg))
>  return 0;
> 
> +   if (!memcg->nodeinfo[nid])
> +   return 0;
> +
>  if (!down_read_trylock(_rwsem))
>  return 0;
> 
> > 
> > [9.072036][T1] BUG: KASAN: null-ptr-deref in shrink_slab+0x111/0x440
> > [9.072036][T1] Read of size 8 at addr 0dc8 by task
> > swapper/0/1
> > [9.072036][T1]
> > [9.072036][T1] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.2.0-next-
> > 20190711+ #10
> > [9.072036][T1] Hardware name: HPE ProLiant DL385 Gen10/ProLiant
> > DL385
> > Gen10, BIOS A40 01/25/2019
> > [9.072036][T1] Call Trace:
> > [9.072036][T1]  dump_stack+0x62/0x9a
> > [9.072036][T1]  __kasan_report.cold.4+0xb0/0xb4
> > [9.072036][T1]  ? unwind_get_return_address+0x40/0x50
> > [9.072036][T1]  ? shrink_slab+0x111/0x440
> > [9.072036][T1]  kasan_report+0xc/0xe
> > [9.072036][T1]  __asan_load8+0x71/0xa0
> > [9.072036][T1]  shrink_slab+0x111/0x440
> > [9.072036][T1]  ? mem_cgroup_iter+0x98/0x840
> > [9.072036][T1]  ? unregister_shrinker+0x110/0x110
> > [9.072036][T1]  ? kasan_check_read+0x11/0x20
> > [9.072036][T1]  ? mem_cgroup_protected+0x39/0x260
> > [9.072036][T1]  shrink_node+0x31e/0xa30
> > [9.072036][T1]  ? shrink_node_memcg+0x1560/0x1560
> > [9.072036][T1]  ? ktime_get+0x93/0x110
> > [9.072036][T1]  do_try_to_free_pages+0x22f/0x820
> > [9.072036][T1]  ? shrink_node+0xa30/0xa30
> > [9.072036][T1]  ? kasan_check_read+0x11/0x20
> > [9.072036][T1]  ? check_chain_key+0x1df/0x2e0
> > [9.072036][T1]  try_to_free_pages+0x242/0x4d0
> > [9.072036][T1]  ? do_try_to_free_pages+0x820/0x820
> > [9.072036][T1]  __alloc_pages_nodemask+0x9ce/0x1bc0
> > [9.072036][T1]  ? gfp_pfmemalloc_allowed+0xc0/0xc0
> > [9.072036][T1]  ? unwind_dump+0x260/0x260
> > [9.072036][T1]  ? kernel_text_address+0x33/0xc0
> > [9.072036][T1]  ? arch_stack_walk+0x8f/0xf0
> > [9.072036][T1]  ? ret_from_fork+0x22/0x40
> > [9.072036][T1]  alloc_page_interleave+0x18/0x130
> > [9.072036][T1]  alloc_pages_current+0xf6/0x110
> > [9.072036][T1]  allocate_slab+0x600/0x11f0
> > [9.072036][T1]  new_slab+0x46/0x70
> > [9.072036][T1]  ___slab_alloc+0x5d4/0x9c0
> > [9.072036][T1]  ? create_object+0x3a/0x3e0
> > [9.072036][T1]  ? fs_reclaim_acquire.part.15+0x5/0x30
> > [9.072036][T1]  ? ___might_sleep+0xab/0xc0
> > [9.072036][T1]  ? create_object+0x3a/0x3e0
> > [9.072036][T1]  __slab_alloc+0x12/0x20
> > [9.072036][T1]  ? __slab_alloc+0x12/0x20
> > [9.072036][T1]  kmem_cache_alloc+0x32a/0x400
> > [9.072036][T1]  create_object+0x3a/0x3e0
> > [9.072036][T1]  kmemleak_alloc+0x71/0xa0
> > [9.072036][T1]  kmem_cache_alloc+0x272/0x400
> > [9.072036][T1]  ? kasan_check_read+0x11/0x20
> > [9.072036][T1]  ? do_raw_spin_unlock+0xa8/0x140
> > [9.072036][T1]  acpi_ps_alloc_op+0x76/0x122
> > [9.072036][T1]  acpi_ds_execute_arguments+0x2f/0x18d
> > [9.072036][T1]  acpi_ds_get_package_arguments+0x7d/0x84
> > [9.072036][T1]  acpi_ns_init_one_package+0x33/0x61
> > [9.072036][T1]  acpi_ns_init_one_object+0xfc/0x189
> > [9.072036][T1]  acpi_ns_walk_namespace+0x114/0x1f2
> > [9.072036][T1]  ? acpi_ns_init_one_package+0x61/0x61
> > [9.072036][T1]  ? acpi_ns_init_one_package+0x61/0x61
> > [9.072036][T1]  acpi_walk_namespace+0x9e/0xcb
> > [9.072036][T1]  ? acpi_sleep_proc_init+0x36/0x36
> > [9.072036][T1]  acpi_ns_initialize_objects+0x99/0xed
> > [9.072036][T1]  ? acpi_ns_find_ini_methods+0xa2/0xa2
> > [9.072036][T1]  ? acpi_tb_load_namespace+0x2dc/0x2eb
> > [9.072036][T1]  acpi_load_tables+0x61/0x80
> > [9.072036][T1]  acpi_init+0x10d/0x44b
> > [9.072036][T1]  ? acpi_sleep_proc_init+0x36/0x36
> > [9.072036][T1]  ? bus_uevent_filter+0x16/0x30
> > [9.072036][T1]  ? kobject_uevent_env+0x109/0x980
> > [9.072036][T1]  ? kernfs_get+0x13/0x20
> > [9.072036][T1]  ? 

Re: [PATCH] mm/z3fold.c: Reinitialize zhdr structs after migration

2019-07-15 Thread Henry Burns
Sorry Vitaly, I had the wrong impression from your email that
INIT_LIST_HEAD() was being ensured directly in migrate and got
confused. (I thought you were saying it happened through the call to
do_compact_page() queued).

That being said, I don't see where in migrate new_zhdr->buddy is being
checked. We do check for new_zhdr.work with
 if (work_pending(>work)) {
...
}

Is that what you were referring to?


[PATCH 0/1] staging: kpc2000: whitespace and line length cleanup

2019-07-15 Thread john . hubbard
From: John Hubbard 

Hi everyone,

This is an easy, drive-by cleanup that I did while reviewing Bharath's
changes to convert over to put_user_page(). It should make the code less
obviously non-conforming, and therefore help future reviews and cleanups.

This is on top of latest linux.git, commit fec88ab0af97 ("Merge tag
'for-linus-hmm' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma"),
and it does NOT have Bharath's patch applied, so it conflicts (but should
be trivial to resolve, regardless of which is applied first, as it's just
whitespace).

Cc: Greg Kroah-Hartman 
Cc: Simon Sandström 
Cc: Geordan Neukum 
Cc: Jeremy Sowden 
Cc: Dan Carpenter 
Cc: Vandana BN 
Cc: de...@driverdev.osuosl.org
Cc: Bharath Vedartham 

John Hubbard (1):
  staging: kpc2000: whitespace and line length cleanup

 drivers/staging/kpc2000/kpc2000_i2c.c | 189 +++--
 drivers/staging/kpc2000/kpc2000_spi.c | 116 +-
 drivers/staging/kpc2000/kpc_dma/dma.c | 109 ++
 drivers/staging/kpc2000/kpc_dma/fileops.c | 199 +++---
 .../staging/kpc2000/kpc_dma/kpc_dma_driver.c  | 113 +-
 .../staging/kpc2000/kpc_dma/kpc_dma_driver.h  | 154 +++---
 6 files changed, 507 insertions(+), 373 deletions(-)

-- 
2.22.0



[PATCH] staging: kpc2000: whitespace and line length cleanup

2019-07-15 Thread john . hubbard
From: John Hubbard 

This commit was created by running indent(1):
`indent -linux`

...and then applying some manual corrections and
cleanup afterward, to keep it sane. No functional changes
were made.

In addition to whitespace changes, some strings were split,
but not strings that were likely to be a grep problem
(in other words, if a user is likely to grep for a string
within the driver, that should still work in most cases).

A few "void * foo" cases were fixed to be "void *foo".

That was enough to make checkpatch.pl run without errors,
although note that there are lots of serious warnings
remaining--but those require functional, not just whitespace
changes. So those are left for a separate patch.

Cc: Greg Kroah-Hartman 
Cc: Simon Sandström 
Cc: Geordan Neukum 
Cc: Jeremy Sowden 
Cc: Dan Carpenter 
Cc: Vandana BN 
Cc: de...@driverdev.osuosl.org
Cc: Bharath Vedartham 
Signed-off-by: John Hubbard 
---
 drivers/staging/kpc2000/kpc2000_i2c.c | 189 +++--
 drivers/staging/kpc2000/kpc2000_spi.c | 116 +-
 drivers/staging/kpc2000/kpc_dma/dma.c | 109 ++
 drivers/staging/kpc2000/kpc_dma/fileops.c | 199 +++---
 .../staging/kpc2000/kpc_dma/kpc_dma_driver.c  | 113 +-
 .../staging/kpc2000/kpc_dma/kpc_dma_driver.h  | 156 +++---
 6 files changed, 509 insertions(+), 373 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000_i2c.c 
b/drivers/staging/kpc2000/kpc2000_i2c.c
index b108da4ac633..93fa1858f6b5 100644
--- a/drivers/staging/kpc2000/kpc2000_i2c.c
+++ b/drivers/staging/kpc2000/kpc2000_i2c.c
@@ -33,9 +33,9 @@ MODULE_LICENSE("GPL");
 MODULE_AUTHOR("matt.sick...@daktronics.com");
 
 struct i2c_device {
-   unsigned long   smba;
-   struct i2c_adapter  adapter;
-   unsigned intfeatures;
+   unsigned long   smba;
+   struct i2c_adapter  adapter;
+   unsigned intfeatures;
 };
 
 /*
@@ -52,9 +52,9 @@ struct i2c_device {
 #define SMBHSTDAT0(p)   ((5  * REG_SIZE) + (p)->smba)
 #define SMBHSTDAT1(p)   ((6  * REG_SIZE) + (p)->smba)
 #define SMBBLKDAT(p)((7  * REG_SIZE) + (p)->smba)
-#define SMBPEC(p)   ((8  * REG_SIZE) + (p)->smba)   /* ICH3 and later */
-#define SMBAUXSTS(p)((12 * REG_SIZE) + (p)->smba)   /* ICH4 and later */
-#define SMBAUXCTL(p)((13 * REG_SIZE) + (p)->smba)   /* ICH4 and later */
+#define SMBPEC(p)   ((8  * REG_SIZE) + (p)->smba)  /* ICH3 and later */
+#define SMBAUXSTS(p)((12 * REG_SIZE) + (p)->smba)  /* ICH4 and later */
+#define SMBAUXCTL(p)((13 * REG_SIZE) + (p)->smba)  /* ICH4 and later */
 
 /* PCI Address Constants */
 #define SMBBAR  4
@@ -74,20 +74,20 @@ struct i2c_device {
 
 /* Other settings */
 #define MAX_RETRIES 400
-#define ENABLE_INT9 0   /* set to 0x01 to enable - untested */
+#define ENABLE_INT9 0  /* set to 0x01 to enable - untested */
 
 /* I801 command constants */
 #define I801_QUICK  0x00
 #define I801_BYTE   0x04
 #define I801_BYTE_DATA  0x08
 #define I801_WORD_DATA  0x0C
-#define I801_PROC_CALL  0x10/* unimplemented */
+#define I801_PROC_CALL  0x10   /* unimplemented */
 #define I801_BLOCK_DATA 0x14
-#define I801_I2C_BLOCK_DATA 0x18/* ICH5 and later */
+#define I801_I2C_BLOCK_DATA 0x18   /* ICH5 and later */
 #define I801_BLOCK_LAST 0x34
-#define I801_I2C_BLOCK_LAST 0x38/* ICH5 and later */
+#define I801_I2C_BLOCK_LAST 0x38   /* ICH5 and later */
 #define I801_START  0x40
-#define I801_PEC_EN 0x80/* ICH3 and later */
+#define I801_PEC_EN 0x80   /* ICH3 and later */
 
 /* I801 Hosts Status register bits */
 #define SMBHSTSTS_BYTE_DONE 0x80
@@ -99,7 +99,9 @@ struct i2c_device {
 #define SMBHSTSTS_INTR  0x02
 #define SMBHSTSTS_HOST_BUSY 0x01
 
-#define STATUS_FLAGS(SMBHSTSTS_BYTE_DONE | SMBHSTSTS_FAILED | 
SMBHSTSTS_BUS_ERR | SMBHSTSTS_DEV_ERR | SMBHSTSTS_INTR)
+#define STATUS_FLAGS \
+   (SMBHSTSTS_BYTE_DONE | SMBHSTSTS_FAILED | SMBHSTSTS_BUS_ERR | \
+SMBHSTSTS_DEV_ERR | SMBHSTSTS_INTR)
 
 /* Older devices have their ID defined in  */
 #define PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS   0x1c22
@@ -136,17 +138,21 @@ static int i801_check_pre(struct i2c_device *priv)
 
status = inb_p(SMBHSTSTS(priv));
if (status & SMBHSTSTS_HOST_BUSY) {
-   dev_err(>adapter.dev, "SMBus is busy, can't use it! 
(status=%x)\n", status);
+   dev_err(>adapter.dev,
+   "SMBus is busy, can't use it! (status=%x)\n", status);
return -EBUSY;
}
 
status &= STATUS_FLAGS;
if (status) {
-   //dev_dbg(>adapter.dev, "Clearing status flags (%02x)\n", 
status);
+   //dev_dbg(>adapter.dev,
+   //"Clearing status flags (%02x)\n", status);

[PATCH 28/28] perf version: Fix segfault due to missing OPT_END()

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Ravi Bangoria 

'perf version' on powerpc segfaults when used with non-supported
option:
  # perf version -a
  Segmentation fault (core dumped)

Fix this.

Signed-off-by: Ravi Bangoria 
Reviewed-by: Kamalesh Babulal 
Tested-by: Mamatha Inamdar 
Cc: Jiri Olsa 
Cc: Kamalesh Babulal 
Link: 
http://lkml.kernel.org/r/20190611030109.20228-1-ravi.bango...@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-version.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/builtin-version.c b/tools/perf/builtin-version.c
index f470144d1a70..bf114ca9ca87 100644
--- a/tools/perf/builtin-version.c
+++ b/tools/perf/builtin-version.c
@@ -19,6 +19,7 @@ static struct version version;
 static struct option version_options[] = {
OPT_BOOLEAN(0, "build-options", _options,
"display the build options"),
+   OPT_END(),
 };
 
 static const char * const version_usage[] = {
-- 
2.21.0



[PATCH 27/28] perf vendor events s390: Add JSON files for machine type 8561

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Thomas Richter 

Add CPU measurement counter facility event description files (JSON) for
IBM machine types 8561 and 8562.

Signed-off-by: Thomas Richter 
Reviewed-by: Vasily Gorbik 
Cc: Heiko Carstens 
Cc: Hendrik Brueckner 
Link: http://lkml.kernel.org/r/20190712123113.100882-1-tmri...@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 .../pmu-events/arch/s390/cf_m8561/basic.json  |  58 +++
 .../pmu-events/arch/s390/cf_m8561/crypto.json | 114 ++
 .../arch/s390/cf_m8561/crypto6.json   |  30 ++
 .../arch/s390/cf_m8561/extended.json  | 373 ++
 tools/perf/pmu-events/arch/s390/mapfile.csv   |   1 +
 5 files changed, 576 insertions(+)
 create mode 100644 tools/perf/pmu-events/arch/s390/cf_m8561/basic.json
 create mode 100644 tools/perf/pmu-events/arch/s390/cf_m8561/crypto.json
 create mode 100644 tools/perf/pmu-events/arch/s390/cf_m8561/crypto6.json
 create mode 100644 tools/perf/pmu-events/arch/s390/cf_m8561/extended.json

diff --git a/tools/perf/pmu-events/arch/s390/cf_m8561/basic.json 
b/tools/perf/pmu-events/arch/s390/cf_m8561/basic.json
new file mode 100644
index ..17fb5241928b
--- /dev/null
+++ b/tools/perf/pmu-events/arch/s390/cf_m8561/basic.json
@@ -0,0 +1,58 @@
+[
+   {
+   "Unit": "CPU-M-CF",
+   "EventCode": "0",
+   "EventName": "CPU_CYCLES",
+   "BriefDescription": "CPU Cycles",
+   "PublicDescription": "Cycle Count"
+   },
+   {
+   "Unit": "CPU-M-CF",
+   "EventCode": "1",
+   "EventName": "INSTRUCTIONS",
+   "BriefDescription": "Instructions",
+   "PublicDescription": "Instruction Count"
+   },
+   {
+   "Unit": "CPU-M-CF",
+   "EventCode": "2",
+   "EventName": "L1I_DIR_WRITES",
+   "BriefDescription": "L1I Directory Writes",
+   "PublicDescription": "Level-1 I-Cache Directory Write Count"
+   },
+   {
+   "Unit": "CPU-M-CF",
+   "EventCode": "3",
+   "EventName": "L1I_PENALTY_CYCLES",
+   "BriefDescription": "L1I Penalty Cycles",
+   "PublicDescription": "Level-1 I-Cache Penalty Cycle Count"
+   },
+   {
+   "Unit": "CPU-M-CF",
+   "EventCode": "4",
+   "EventName": "L1D_DIR_WRITES",
+   "BriefDescription": "L1D Directory Writes",
+   "PublicDescription": "Level-1 D-Cache Directory Write Count"
+   },
+   {
+   "Unit": "CPU-M-CF",
+   "EventCode": "5",
+   "EventName": "L1D_PENALTY_CYCLES",
+   "BriefDescription": "L1D Penalty Cycles",
+   "PublicDescription": "Level-1 D-Cache Penalty Cycle Count"
+   },
+   {
+   "Unit": "CPU-M-CF",
+   "EventCode": "32",
+   "EventName": "PROBLEM_STATE_CPU_CYCLES",
+   "BriefDescription": "Problem-State CPU Cycles",
+   "PublicDescription": "Problem-State Cycle Count"
+   },
+   {
+   "Unit": "CPU-M-CF",
+   "EventCode": "33",
+   "EventName": "PROBLEM_STATE_INSTRUCTIONS",
+   "BriefDescription": "Problem-State Instructions",
+   "PublicDescription": "Problem-State Instruction Count"
+   },
+]
diff --git a/tools/perf/pmu-events/arch/s390/cf_m8561/crypto.json 
b/tools/perf/pmu-events/arch/s390/cf_m8561/crypto.json
new file mode 100644
index ..db286f19e7b6
--- /dev/null
+++ b/tools/perf/pmu-events/arch/s390/cf_m8561/crypto.json
@@ -0,0 +1,114 @@
+[
+   {
+   "Unit": "CPU-M-CF",
+   "EventCode": "64",
+   "EventName": "PRNG_FUNCTIONS",
+   "BriefDescription": "PRNG Functions",
+   "PublicDescription": "Total number of the PRNG functions issued 
by the CPU"
+   },
+   {
+   "Unit": "CPU-M-CF",
+   "EventCode": "65",
+   "EventName": "PRNG_CYCLES",
+   "BriefDescription": "PRNG Cycles",
+   "PublicDescription": "Total number of CPU cycles when the 
DEA/AES coprocessor is busy performing PRNG functions issued by the CPU"
+   },
+   {
+   "Unit": "CPU-M-CF",
+   "EventCode": "66",
+   "EventName": "PRNG_BLOCKED_FUNCTIONS",
+   "BriefDescription": "PRNG Blocked Functions",
+   "PublicDescription": "Total number of the PRNG functions that 
are issued by the CPU and are blocked because the DEA/AES coprocessor is busy 
performing a function issued by another CPU"
+   },
+   {
+   "Unit": "CPU-M-CF",
+   "EventCode": "67",
+   "EventName": "PRNG_BLOCKED_CYCLES",
+   "BriefDescription": "PRNG Blocked Cycles",
+   "PublicDescription": "Total number of CPU cycles blocked for 
the PRNG functions issued 

[PATCH 26/28] perf cs-etm: Return errcode in cs_etm__process_auxtrace_info()

2019-07-15 Thread Arnaldo Carvalho de Melo
From: YueHaibing 

The 'err' variable is set in the error path, but it's not returned to
callers.  Don't always return -EINVAL, return err.

Signed-off-by: YueHaibing 
Reviewed-by: Mathieu Poirier 
Cc: Alexander Shishkin 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Suzuki Poulouse 
Cc: linux-arm-ker...@lists.infradead.org
Fixes: cd8bfd8c973e ("perf tools: Add processing of coresight metadata")
Link: http://lkml.kernel.org/r/20190321023122.21332-3-yuehaib...@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/cs-etm.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 2e9f5bc45550..3d1c34fc4d68 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -2517,8 +2517,10 @@ int cs_etm__process_auxtrace_info(union perf_event 
*event,
session->auxtrace = >auxtrace;
 
etm->unknown_thread = thread__new(9, 9);
-   if (!etm->unknown_thread)
+   if (!etm->unknown_thread) {
+   err = -ENOMEM;
goto err_free_queues;
+   }
 
/*
 * Initialize list node so that at thread__zput() we can avoid
@@ -2530,8 +2532,10 @@ int cs_etm__process_auxtrace_info(union perf_event 
*event,
if (err)
goto err_delete_thread;
 
-   if (thread__init_map_groups(etm->unknown_thread, etm->machine))
+   if (thread__init_map_groups(etm->unknown_thread, etm->machine)) {
+   err = -ENOMEM;
goto err_delete_thread;
+   }
 
if (dump_trace) {
cs_etm__print_auxtrace_info(auxtrace_info->priv, num_cpu);
@@ -2575,5 +2579,5 @@ int cs_etm__process_auxtrace_info(union perf_event *event,
 err_free_hdr:
zfree();
 
-   return -EINVAL;
+   return err;
 }
-- 
2.21.0



[PATCH 25/28] perf cs-etm: Remove errnoeous ERR_PTR() usage in cs_etm__process_auxtrace_info

2019-07-15 Thread Arnaldo Carvalho de Melo
From: YueHaibing 

intlist__findnew() doesn't uses ERR_PTR() as a return mechanism
so its callers shouldn't try to extract the error using PTR_ERR(
ret) from intlist__findnew(), make cs_etm__process_auxtrace_info
return -ENOMEM instead.

Signed-off-by: YueHaibing 
Reviewed-by: Mathieu Poirier 
Cc: Alexander Shishkin 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Suzuki Poulouse 
Cc: linux-arm-ker...@lists.infradead.org
Fixes: cd8bfd8c973e ("perf tools: Add processing of coresight metadata")
Link: http://lkml.kernel.org/r/20190321023122.21332-2-yuehaib...@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/cs-etm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 67b88b599a53..2e9f5bc45550 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -2460,7 +2460,7 @@ int cs_etm__process_auxtrace_info(union perf_event *event,
 
/* Something went wrong, no need to continue */
if (!inode) {
-   err = PTR_ERR(inode);
+   err = -ENOMEM;
goto err_free_metadata;
}
 
-- 
2.21.0



[PATCH 24/28] perf scripts python: export-to-postgresql.py: Export switch events

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

Export switch events to a new table 'context_switches' and create a view
'context_switches_view'. The table and view will show automatically in the
exported-sql-viewer.py script.

If the table ends up empty, then it and the view are dropped.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190710085810.1650-22-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 .../scripts/python/export-to-postgresql.py| 51 +++
 1 file changed, 51 insertions(+)

diff --git a/tools/perf/scripts/python/export-to-postgresql.py 
b/tools/perf/scripts/python/export-to-postgresql.py
index 13205e4e5b3b..7bd73a904b4e 100644
--- a/tools/perf/scripts/python/export-to-postgresql.py
+++ b/tools/perf/scripts/python/export-to-postgresql.py
@@ -482,6 +482,17 @@ do_query(query, 'CREATE TABLE pwrx ('
'last_cstateinteger,'
'wake_reasoninteger)')
 
+do_query(query, 'CREATE TABLE context_switches ('
+   'id bigint  NOT NULL,'
+   'machine_id bigint,'
+   'time   bigint,'
+   'cpuinteger,'
+   'thread_out_id  bigint,'
+   'comm_out_idbigint,'
+   'thread_in_id   bigint,'
+   'comm_in_id bigint,'
+   'flags  integer)')
+
 do_query(query, 'CREATE VIEW machines_view AS '
'SELECT '
'id,'
@@ -695,6 +706,29 @@ do_query(query, 'CREATE VIEW power_events_view AS '
' INNER JOIN selected_events ON selected_events.id = samples.evsel_id'
' ORDER BY samples.id')
 
+do_query(query, 'CREATE VIEW context_switches_view AS '
+   'SELECT '
+   'context_switches.id,'
+   'context_switches.machine_id,'
+   'context_switches.time,'
+   'context_switches.cpu,'
+   'th_out.pid AS pid_out,'
+   'th_out.tid AS tid_out,'
+   'comm_out.comm AS comm_out,'
+   'th_in.pid AS pid_in,'
+   'th_in.tid AS tid_in,'
+   'comm_in.comm AS comm_in,'
+   'CASE WHEN context_switches.flags = 0 THEN \'in\''
+   ' WHEN context_switches.flags = 1 THEN \'out\''
+   ' WHEN context_switches.flags = 3 THEN \'out preempt\''
+   ' ELSE CAST ( context_switches.flags AS VARCHAR(11) )'
+   'END AS flags'
+   ' FROM context_switches'
+   ' INNER JOIN threads AS th_out ON th_out.id   = 
context_switches.thread_out_id'
+   ' INNER JOIN threads AS th_in  ON th_in.id= 
context_switches.thread_in_id'
+   ' INNER JOIN comms AS comm_out ON comm_out.id = 
context_switches.comm_out_id'
+   ' INNER JOIN comms AS comm_in  ON comm_in.id  = 
context_switches.comm_in_id')
+
 file_header = struct.pack("!11sii", b"PGCOPY\n\377\r\n\0", 0, 0)
 file_trailer = b"\377\377"
 
@@ -759,6 +793,7 @@ mwait_file  = open_output_file("mwait_table.bin")
 pwre_file  = open_output_file("pwre_table.bin")
 exstop_file= open_output_file("exstop_table.bin")
 pwrx_file  = open_output_file("pwrx_table.bin")
+context_switches_file  = open_output_file("context_switches_table.bin")
 
 def trace_begin():
printdate("Writing to intermediate files...")
@@ -807,6 +842,7 @@ def trace_end():
copy_output_file(pwre_file, "pwre")
copy_output_file(exstop_file,   "exstop")
copy_output_file(pwrx_file, "pwrx")
+   copy_output_file(context_switches_file, "context_switches")
 
printdate("Removing intermediate files...")
remove_output_file(evsel_file)
@@ -828,6 +864,7 @@ def trace_end():
remove_output_file(pwre_file)
remove_output_file(exstop_file)
remove_output_file(pwrx_file)
+   remove_output_file(context_switches_file)
os.rmdir(output_dir_name)
printdate("Adding primary keys")
do_query(query, 'ALTER TABLE selected_events ADD PRIMARY KEY (id)')
@@ -849,6 +886,7 @@ def trace_end():
do_query(query, 'ALTER TABLE pwreADD PRIMARY KEY (id)')
do_query(query, 'ALTER TABLE exstop  ADD PRIMARY KEY (id)')
do_query(query, 'ALTER TABLE pwrxADD PRIMARY KEY (id)')
+   do_query(query, 'ALTER TABLE context_switches ADD PRIMARY KEY (id)')
 
printdate("Adding foreign keys")
do_query(query, 'ALTER TABLE threads '
@@ -900,6 +938,12 @@ def trace_end():
'ADD CONSTRAINT idfkFOREIGN KEY 
(id)   REFERENCES samples   (id)')
do_query(query, 'ALTER TABLE  pwrx '
'ADD CONSTRAINT idfkFOREIGN KEY 
(id)   REFERENCES samples   (id)')
+   do_query(query, 'ALTER TABLE  context_switches '
+   'ADD CONSTRAINT machinefk   FOREIGN KEY 

[PATCH 23/28] perf scripts python: export-to-sqlite.py: Export switch events

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

Export switch events to a new table 'context_switches' and create a view
'context_switches_view'. The table and view will show automatically in
the exported-sql-viewer.py script.

If the table ends up empty, then it and the view are dropped.

Committer testing:

Use the exported-sql-viewer.py and look at "Tables" ->
"context_switches":

  id  machine_id  time cpu  thread_out_id  comm_out_id  
thread_in_id  comm_in_id  flags
  1   1   187836111885918  71  12   
  2   3
  2   1   187836111889369  71  12   
  2   0
  3   1   187836112464618  72  31   
  1   1
  4   1   187836112465511  72  31   
  1   0

Signed-off-by: Adrian Hunter 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190710085810.1650-21-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/scripts/python/export-to-sqlite.py | 41 +++
 1 file changed, 41 insertions(+)

diff --git a/tools/perf/scripts/python/export-to-sqlite.py 
b/tools/perf/scripts/python/export-to-sqlite.py
index 9156f6a1e5f0..8043a7272a56 100644
--- a/tools/perf/scripts/python/export-to-sqlite.py
+++ b/tools/perf/scripts/python/export-to-sqlite.py
@@ -306,6 +306,17 @@ do_query(query, 'CREATE TABLE pwrx ('
'last_cstateinteger,'
'wake_reasoninteger)')
 
+do_query(query, 'CREATE TABLE context_switches ('
+   'id integer NOT NULLPRIMARY KEY,'
+   'machine_id bigint,'
+   'time   bigint,'
+   'cpuinteger,'
+   'thread_out_id  bigint,'
+   'comm_out_idbigint,'
+   'thread_in_id   bigint,'
+   'comm_in_id bigint,'
+   'flags  integer)')
+
 # printf was added to sqlite in version 3.8.3
 sqlite_has_printf = False
 try:
@@ -530,6 +541,29 @@ do_query(query, 'CREATE VIEW power_events_view AS '
' INNER JOIN selected_events ON selected_events.id = evsel_id'
' WHERE selected_events.name IN 
(\'cbr\',\'mwait\',\'exstop\',\'pwre\',\'pwrx\')')
 
+do_query(query, 'CREATE VIEW context_switches_view AS '
+   'SELECT '
+   'context_switches.id,'
+   'context_switches.machine_id,'
+   'context_switches.time,'
+   'context_switches.cpu,'
+   'th_out.pid AS pid_out,'
+   'th_out.tid AS tid_out,'
+   'comm_out.comm AS comm_out,'
+   'th_in.pid AS pid_in,'
+   'th_in.tid AS tid_in,'
+   'comm_in.comm AS comm_in,'
+   'CASE WHEN context_switches.flags = 0 THEN \'in\''
+   ' WHEN context_switches.flags = 1 THEN \'out\''
+   ' WHEN context_switches.flags = 3 THEN \'out preempt\''
+   ' ELSE context_switches.flags '
+   'END AS flags'
+   ' FROM context_switches'
+   ' INNER JOIN threads AS th_out ON th_out.id   = 
context_switches.thread_out_id'
+   ' INNER JOIN threads AS th_in  ON th_in.id= 
context_switches.thread_in_id'
+   ' INNER JOIN comms AS comm_out ON comm_out.id = 
context_switches.comm_out_id'
+   ' INNER JOIN comms AS comm_in  ON comm_in.id  = 
context_switches.comm_in_id')
+
 do_query(query, 'END TRANSACTION')
 
 evsel_query = QSqlQuery(db)
@@ -571,6 +605,8 @@ exstop_query = QSqlQuery(db)
 exstop_query.prepare("INSERT INTO exstop VALUES (?, ?)")
 pwrx_query = QSqlQuery(db)
 pwrx_query.prepare("INSERT INTO pwrx VALUES (?, ?, ?, ?)")
+context_switch_query = QSqlQuery(db)
+context_switch_query.prepare("INSERT INTO context_switches VALUES (?, ?, ?, ?, 
?, ?, ?, ?, ?)")
 
 def trace_begin():
printdate("Writing records...")
@@ -620,6 +656,8 @@ def trace_end():
drop("pwrx")
if is_table_empty("cbr"):
drop("cbr")
+   if is_table_empty("context_switches"):
+   drop("context_switches")
 
if (unhandled_count):
printdate("Warning: ", unhandled_count, " unhandled events")
@@ -753,3 +791,6 @@ def synth_data(id, config, raw_buf, *x):
pwrx(id, raw_buf)
elif config == 5:
cbr(id, raw_buf)
+
+def context_switch_table(*x):
+   bind_exec(context_switch_query, 9, x)
-- 
2.21.0



[PATCH 19/28] perf scripts python: exported-sql-viewer.py: Use new 'has_calls' column

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

If the new 'has_calls' column is present, use it with the call graph and
call tree to select only comms that have calls.

Committer testing:

Just started the exported-sql-view.py and accessed all the reports, no
backtraces.

Signed-off-by: Adrian Hunter 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190710085810.1650-17-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/scripts/python/exported-sql-viewer.py | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tools/perf/scripts/python/exported-sql-viewer.py 
b/tools/perf/scripts/python/exported-sql-viewer.py
index dbbd7a5d9b60..61b3911d91e6 100755
--- a/tools/perf/scripts/python/exported-sql-viewer.py
+++ b/tools/perf/scripts/python/exported-sql-viewer.py
@@ -623,8 +623,11 @@ class CallGraphRootItem(CallGraphLevelItemBase):
super(CallGraphRootItem, self).__init__(glb, params, 0, None)
self.dbid = 0
self.query_done = True
+   if_has_calls = ""
+   if IsSelectable(glb.db, "comms", columns = "has_calls"):
+   if_has_calls = " WHERE has_calls = TRUE"
query = QSqlQuery(glb.db)
-   QueryExec(query, "SELECT id, comm FROM comms")
+   QueryExec(query, "SELECT id, comm FROM comms" + if_has_calls)
while query.next():
if not query.value(0):
continue
@@ -900,8 +903,11 @@ class CallTreeRootItem(CallGraphLevelItemBase):
super(CallTreeRootItem, self).__init__(glb, params, 0, None)
self.dbid = 0
self.query_done = True
+   if_has_calls = ""
+   if IsSelectable(glb.db, "comms", columns = "has_calls"):
+   if_has_calls = " WHERE has_calls = TRUE"
query = QSqlQuery(glb.db)
-   QueryExec(query, "SELECT id, comm FROM comms")
+   QueryExec(query, "SELECT id, comm FROM comms" + if_has_calls)
while query.next():
if not query.value(0):
continue
-- 
2.21.0



[PATCH 21/28] perf db-export: Factor out db_export__threads()

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

In preparation for exporting switch events, factor out
db_export__threads().

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190710085810.1650-19-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/db-export.c | 82 ++---
 1 file changed, 48 insertions(+), 34 deletions(-)

diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c
index 5057fdd7f62d..e6a9c450133e 100644
--- a/tools/perf/util/db-export.c
+++ b/tools/perf/util/db-export.c
@@ -286,50 +286,32 @@ int db_export__branch_type(struct db_export *dbe, u32 
branch_type,
return 0;
 }
 
-int db_export__sample(struct db_export *dbe, union perf_event *event,
- struct perf_sample *sample, struct perf_evsel *evsel,
- struct addr_location *al)
+static int db_export__threads(struct db_export *dbe, struct thread *thread,
+ struct thread *main_thread,
+ struct machine *machine, struct comm **comm_ptr)
 {
-   struct thread *thread = al->thread;
-   struct export_sample es = {
-   .event = event,
-   .sample = sample,
-   .evsel = evsel,
-   .al = al,
-   };
-   struct thread *main_thread;
struct comm *comm = NULL;
struct comm *curr_comm;
int err;
 
-   err = db_export__evsel(dbe, evsel);
-   if (err)
-   return err;
-
-   err = db_export__machine(dbe, al->machine);
-   if (err)
-   return err;
-
-   main_thread = thread__main_thread(al->machine, thread);
if (main_thread) {
/*
 * A thread has a reference to the main thread, so export the
 * main thread first.
 */
-   err = db_export__thread(dbe, main_thread, al->machine,
-   main_thread);
+   err = db_export__thread(dbe, main_thread, machine, main_thread);
if (err)
-   goto out_put;
+   return err;
/*
 * Export comm before exporting the non-main thread because
 * db_export__comm_thread() can be called further below.
 */
-   comm = machine__thread_exec_comm(al->machine, main_thread);
+   comm = machine__thread_exec_comm(machine, main_thread);
if (comm) {
err = db_export__exec_comm(dbe, comm, main_thread);
if (err)
-   goto out_put;
-   es.comm_db_id = comm->db_id;
+   return err;
+   *comm_ptr = comm;
}
}
 
@@ -340,23 +322,55 @@ int db_export__sample(struct db_export *dbe, union 
perf_event *event,
 */
bool export_comm_thread = comm && !thread->db_id;
 
-   err = db_export__thread(dbe, thread, al->machine, main_thread);
+   err = db_export__thread(dbe, thread, machine, main_thread);
if (err)
-   goto out_put;
+   return err;
 
if (export_comm_thread) {
err = db_export__comm_thread(dbe, comm, thread);
if (err)
-   goto out_put;
+   return err;
}
}
 
curr_comm = thread__comm(thread);
-   if (curr_comm) {
-   err = db_export__comm(dbe, curr_comm, thread);
-   if (err)
-   goto out_put;
-   }
+   if (curr_comm)
+   return db_export__comm(dbe, curr_comm, thread);
+
+   return 0;
+}
+
+int db_export__sample(struct db_export *dbe, union perf_event *event,
+ struct perf_sample *sample, struct perf_evsel *evsel,
+ struct addr_location *al)
+{
+   struct thread *thread = al->thread;
+   struct export_sample es = {
+   .event = event,
+   .sample = sample,
+   .evsel = evsel,
+   .al = al,
+   };
+   struct thread *main_thread;
+   struct comm *comm = NULL;
+   int err;
+
+   err = db_export__evsel(dbe, evsel);
+   if (err)
+   return err;
+
+   err = db_export__machine(dbe, al->machine);
+   if (err)
+   return err;
+
+   main_thread = thread__main_thread(al->machine, thread);
+
+   err = db_export__threads(dbe, thread, main_thread, al->machine, );
+   if (err)
+   goto out_put;
+
+   if (comm)
+   es.comm_db_id = comm->db_id;
 
es.db_id = ++dbe->sample_last_db_id;
 
-- 
2.21.0



[PATCH 22/28] perf db-export: Export switch events

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

Export details of switch events including the threads and their current
comms.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190710085810.1650-20-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/db-export.c   | 89 +++
 tools/perf/util/db-export.h   |  8 ++
 .../scripting-engines/trace-event-python.c| 41 +
 3 files changed, 138 insertions(+)

diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c
index e6a9c450133e..ffbb3e7d3288 100644
--- a/tools/perf/util/db-export.c
+++ b/tools/perf/util/db-export.c
@@ -519,3 +519,92 @@ int db_export__call_return(struct db_export *dbe, struct 
call_return *cr,
 
return 0;
 }
+
+static int db_export__pid_tid(struct db_export *dbe, struct machine *machine,
+ pid_t pid, pid_t tid, u64 *db_id,
+ struct comm **comm_ptr, bool *is_idle)
+{
+   struct thread *thread = machine__find_thread(machine, pid, tid);
+   struct thread *main_thread;
+   int err = 0;
+
+   if (!thread || !thread->comm_set)
+   goto out_put;
+
+   *is_idle = !thread->pid_ && !thread->tid;
+
+   main_thread = thread__main_thread(machine, thread);
+
+   err = db_export__threads(dbe, thread, main_thread, machine, comm_ptr);
+
+   *db_id = thread->db_id;
+
+   thread__put(main_thread);
+out_put:
+   thread__put(thread);
+
+   return err;
+}
+
+int db_export__switch(struct db_export *dbe, union perf_event *event,
+ struct perf_sample *sample, struct machine *machine)
+{
+   bool out = event->header.misc & PERF_RECORD_MISC_SWITCH_OUT;
+   bool out_preempt = out &&
+   (event->header.misc & PERF_RECORD_MISC_SWITCH_OUT_PREEMPT);
+   int flags = out | (out_preempt << 1);
+   bool is_idle_a = false, is_idle_b = false;
+   u64 th_a_id = 0, th_b_id = 0;
+   u64 comm_out_id, comm_in_id;
+   struct comm *comm_a = NULL;
+   struct comm *comm_b = NULL;
+   u64 th_out_id, th_in_id;
+   u64 db_id;
+   int err;
+
+   err = db_export__machine(dbe, machine);
+   if (err)
+   return err;
+
+   err = db_export__pid_tid(dbe, machine, sample->pid, sample->tid,
+_a_id, _a, _idle_a);
+   if (err)
+   return err;
+
+   if (event->header.type == PERF_RECORD_SWITCH_CPU_WIDE) {
+   pid_t pid = event->context_switch.next_prev_pid;
+   pid_t tid = event->context_switch.next_prev_tid;
+
+   err = db_export__pid_tid(dbe, machine, pid, tid, _b_id,
+_b, _idle_b);
+   if (err)
+   return err;
+   }
+
+   /*
+* Do not export if both threads are unknown (i.e. not being traced),
+* or one is unknown and the other is the idle task.
+*/
+   if ((!th_a_id || is_idle_a) && (!th_b_id || is_idle_b))
+   return 0;
+
+   db_id = ++dbe->context_switch_last_db_id;
+
+   if (out) {
+   th_out_id   = th_a_id;
+   th_in_id= th_b_id;
+   comm_out_id = comm_a ? comm_a->db_id : 0;
+   comm_in_id  = comm_b ? comm_b->db_id : 0;
+   } else {
+   th_out_id   = th_b_id;
+   th_in_id= th_a_id;
+   comm_out_id = comm_b ? comm_b->db_id : 0;
+   comm_in_id  = comm_a ? comm_a->db_id : 0;
+   }
+
+   if (dbe->export_context_switch)
+   return dbe->export_context_switch(dbe, db_id, machine, sample,
+ th_out_id, comm_out_id,
+ th_in_id, comm_in_id, flags);
+   return 0;
+}
diff --git a/tools/perf/util/db-export.h b/tools/perf/util/db-export.h
index f5f0865f07e1..ba1f62a5fe10 100644
--- a/tools/perf/util/db-export.h
+++ b/tools/perf/util/db-export.h
@@ -57,6 +57,11 @@ struct db_export {
int (*export_call_path)(struct db_export *dbe, struct call_path *cp);
int (*export_call_return)(struct db_export *dbe,
  struct call_return *cr);
+   int (*export_context_switch)(struct db_export *dbe, u64 db_id,
+struct machine *machine,
+struct perf_sample *sample,
+u64 th_out_id, u64 comm_out_id,
+u64 th_in_id, u64 comm_in_id, int flags);
struct call_return_processor *crp;
struct call_path_root *cpr;
u64 evsel_last_db_id;
@@ -69,6 +74,7 @@ struct db_export {
u64 sample_last_db_id;
u64 call_path_last_db_id;
u64 call_return_last_db_id;
+   u64 context_switch_last_db_id;
 };
 
 int db_export__init(struct db_export *dbe);
@@ -98,5 

[PATCH 20/28] perf script: Add scripting operation process_switch()

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

Add scripting operation process_switch() to process switch events.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190710085810.1650-18-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-script.c   | 8 +++-
 tools/perf/util/trace-event.h | 3 +++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 79367087bd18..8f24865596af 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -2289,6 +2289,12 @@ static int process_switch_event(struct perf_tool *tool,
if (perf_event__process_switch(tool, event, sample, machine) < 0)
return -1;
 
+   if (scripting_ops && scripting_ops->process_switch)
+   scripting_ops->process_switch(event, sample, machine);
+
+   if (!script->show_switch_events)
+   return 0;
+
thread = machine__findnew_thread(machine, sample->pid,
 sample->tid);
if (thread == NULL) {
@@ -2467,7 +2473,7 @@ static int __cmd_script(struct perf_script *script)
script->tool.mmap = process_mmap_event;
script->tool.mmap2 = process_mmap2_event;
}
-   if (script->show_switch_events)
+   if (script->show_switch_events || (scripting_ops && 
scripting_ops->process_switch))
script->tool.context_switch = process_switch_event;
if (script->show_namespace_events)
script->tool.namespaces = process_namespaces_event;
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
index d9b0a942090a..c7002fe11673 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/perf/util/trace-event.h
@@ -81,6 +81,9 @@ struct scripting_ops {
   struct perf_sample *sample,
   struct perf_evsel *evsel,
   struct addr_location *al);
+   void (*process_switch)(union perf_event *event,
+  struct perf_sample *sample,
+  struct machine *machine);
void (*process_stat)(struct perf_stat_config *config,
 struct perf_evsel *evsel, u64 tstamp);
void (*process_stat_interval)(u64 tstamp);
-- 
2.21.0



[PATCH 18/28] perf scripts python: exported-sql-viewer.py: Remove redundant semi-colons

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

Remove redundant semi-colons added inadvertently.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190710085810.1650-16-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 .../scripts/python/exported-sql-viewer.py | 24 +--
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/tools/perf/scripts/python/exported-sql-viewer.py 
b/tools/perf/scripts/python/exported-sql-viewer.py
index 6e7934f2ac9a..dbbd7a5d9b60 100755
--- a/tools/perf/scripts/python/exported-sql-viewer.py
+++ b/tools/perf/scripts/python/exported-sql-viewer.py
@@ -392,7 +392,7 @@ class FindBar():
self.hbox.addWidget(self.close_button)
 
self.bar = QWidget()
-   self.bar.setLayout(self.hbox);
+   self.bar.setLayout(self.hbox)
self.bar.hide()
 
def Widget(self):
@@ -470,7 +470,7 @@ class CallGraphLevelItemBase(object):
self.params = params
self.row = row
self.parent_item = parent_item
-   self.query_done = False;
+   self.query_done = False
self.child_count = 0
self.child_items = []
if parent_item:
@@ -517,7 +517,7 @@ class CallGraphLevelTwoPlusItemBase(CallGraphLevelItemBase):
self.time = time
 
def Select(self):
-   self.query_done = True;
+   self.query_done = True
query = QSqlQuery(self.glb.db)
if self.params.have_ipc:
ipc_str = ", SUM(insn_count), SUM(cyc_count)"
@@ -604,7 +604,7 @@ class CallGraphLevelOneItem(CallGraphLevelItemBase):
self.dbid = comm_id
 
def Select(self):
-   self.query_done = True;
+   self.query_done = True
query = QSqlQuery(self.glb.db)
QueryExec(query, "SELECT thread_id, pid, tid"
" FROM comm_threads"
@@ -622,7 +622,7 @@ class CallGraphRootItem(CallGraphLevelItemBase):
def __init__(self, glb, params):
super(CallGraphRootItem, self).__init__(glb, params, 0, None)
self.dbid = 0
-   self.query_done = True;
+   self.query_done = True
query = QSqlQuery(glb.db)
QueryExec(query, "SELECT id, comm FROM comms")
while query.next():
@@ -793,7 +793,7 @@ class CallTreeLevelTwoPlusItemBase(CallGraphLevelItemBase):
self.time = time
 
def Select(self):
-   self.query_done = True;
+   self.query_done = True
if self.calls_id == 0:
comm_thread = " AND comm_id = " + str(self.comm_id) + " 
AND thread_id = " + str(self.thread_id)
else:
@@ -881,7 +881,7 @@ class CallTreeLevelOneItem(CallGraphLevelItemBase):
self.dbid = comm_id
 
def Select(self):
-   self.query_done = True;
+   self.query_done = True
query = QSqlQuery(self.glb.db)
QueryExec(query, "SELECT thread_id, pid, tid"
" FROM comm_threads"
@@ -899,7 +899,7 @@ class CallTreeRootItem(CallGraphLevelItemBase):
def __init__(self, glb, params):
super(CallTreeRootItem, self).__init__(glb, params, 0, None)
self.dbid = 0
-   self.query_done = True;
+   self.query_done = True
query = QSqlQuery(glb.db)
QueryExec(query, "SELECT id, comm FROM comms")
while query.next():
@@ -971,7 +971,7 @@ class VBox():
 
def __init__(self, w1, w2, w3=None):
self.vbox = QWidget()
-   self.vbox.setLayout(QVBoxLayout());
+   self.vbox.setLayout(QVBoxLayout())
 
self.vbox.layout().setContentsMargins(0, 0, 0, 0)
 
@@ -1391,7 +1391,7 @@ class FetchMoreRecordsBar():
self.hbox.addWidget(self.close_button)
 
self.bar = QWidget()
-   self.bar.setLayout(self.hbox);
+   self.bar.setLayout(self.hbox)
self.bar.show()
 
self.in_progress = False
@@ -2206,7 +2206,7 @@ class ReportDialogBase(QDialog):
self.vbox.addLayout(self.grid)
self.vbox.addLayout(self.hbox)
 
-   self.setLayout(self.vbox);
+   self.setLayout(self.vbox)
 
def Ok(self):
vars = self.report_vars
@@ -3139,7 +3139,7 @@ class AboutDialog(QDialog):
self.vbox = QVBoxLayout()
self.vbox.addWidget(self.text)
 
-   self.setLayout(self.vbox);
+   self.setLayout(self.vbox)
 
 # Font resize
 
-- 
2.21.0



[PATCH 16/28] perf scripts python: export-to-sqlite.py: Add has_calls column to comms table

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

Now that a thread's current comm is exported, it shows up in the call
graph and call tree even if it has no calls. That can happen because the
calls are recorded against the main thread's initial comm.

Add a table column to make it easy for the exported-sql-viewer.py script
to select only comms with calls.

Committer notes:

Running the export-to-sqlite.py worked without warnings and using the
exported-sql-viewer.py worked as before.

Signed-off-by: Adrian Hunter 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190710085810.1650-14-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/scripts/python/export-to-sqlite.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/scripts/python/export-to-sqlite.py 
b/tools/perf/scripts/python/export-to-sqlite.py
index 97aa66dd2fe1..9156f6a1e5f0 100644
--- a/tools/perf/scripts/python/export-to-sqlite.py
+++ b/tools/perf/scripts/python/export-to-sqlite.py
@@ -606,6 +606,8 @@ def trace_end():
if perf_db_export_calls:
do_query(query, 'CREATE INDEX pcpid_idx ON calls 
(parent_call_path_id)')
do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)')
+   do_query(query, 'ALTER TABLE comms ADD has_calls boolean')
+   do_query(query, 'UPDATE comms SET has_calls = 1 WHERE comms.id 
IN (SELECT DISTINCT comm_id FROM calls)')
 
printdate("Dropping unused tables")
if is_table_empty("ptwrite"):
-- 
2.21.0



[PATCH 17/28] perf scripts python: export-to-postgresql.py: Add has_calls column to comms table

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

Now that a thread's current comm is exported, it shows up in the call graph
and call tree even if it has no calls. That can happen because the calls
are recorded against the main thread's initial comm.

Add a table column to make it easy for the exported-sql-viewer.py script to
select only comms with calls.

Committer testing:

  $ rm -f simple-retpoline.db
  $ sudo ~acme/bin/perf script -i simple-retpoline.perf.data --itrace=be -s 
~/libexec/perf-core/scripts/python/export-to-sqlite.py simple-retpoline.db 
branches calls
  2019-07-10 12:25:33.200529 Creating database ...
  2019-07-10 12:25:33.211548 Writing records...
  2019-07-10 12:25:33.549630 Adding indexes
  2019-07-10 12:25:33.560715 Dropping unused tables
  2019-07-10 12:25:33.580201 Done
  $ sha256sum tools/perf/scripts/python/export-to-sqlite.py 
~/libexec/perf-core/scripts/python/export-to-sqlite.py
  2922b642c392004dffa1d8789296478c85904623f5895bcb9b6cbf33e3ca999f  
tools/perf/scripts/python/export-to-sqlite.py
  2922b642c392004dffa1d8789296478c85904623f5895bcb9b6cbf33e3ca999f  
/home/acme/libexec/perf-core/scripts/python/export-to-sqlite.py
  $
  $ sqlite3 simple-retpoline.db
  SQLite version 3.26.0 2018-12-01 12:34:55
  Enter ".help" for usage hints.
  sqlite> .schema comms
  CREATE TABLE comms (id integer NOT NULL PRIMARY KEY,comm 
varchar(16),c_thread_id bigint,c_time bigint,exec_flag boolean, has_calls 
boolean);
  sqlite> select id,has_calls from comms;
  0|1
  1|1
  sqlite> select distinct comm_id from calls;
  0
  1
  sqlite>

Signed-off-by: Adrian Hunter 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190710085810.1650-15-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/scripts/python/export-to-postgresql.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/scripts/python/export-to-postgresql.py 
b/tools/perf/scripts/python/export-to-postgresql.py
index 01f37877f5bb..13205e4e5b3b 100644
--- a/tools/perf/scripts/python/export-to-postgresql.py
+++ b/tools/perf/scripts/python/export-to-postgresql.py
@@ -886,6 +886,8 @@ def trace_end():
'ADD CONSTRAINT parent_call_pathfk 
FOREIGN KEY (parent_call_path_id) REFERENCES call_paths (id)')
do_query(query, 'CREATE INDEX pcpid_idx ON calls 
(parent_call_path_id)')
do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)')
+   do_query(query, 'ALTER TABLE comms ADD has_calls boolean')
+   do_query(query, 'UPDATE comms SET has_calls = TRUE WHERE 
comms.id IN (SELECT DISTINCT comm_id FROM calls)')
do_query(query, 'ALTER TABLE ptwrite '
'ADD CONSTRAINT idfkFOREIGN KEY 
(id)   REFERENCES samples   (id)')
do_query(query, 'ALTER TABLE  cbr '
-- 
2.21.0



[PATCH 15/28] perf db-export: Also export thread's current comm

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

Currently, the initial comm of the main thread is exported. Export also
a thread's current comm. That better supports the tracing of
multi-threaded applications that set different comms for different
threads to make it easier to distinguish them.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190710085810.1650-13-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/db-export.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c
index b1e581c13963..5057fdd7f62d 100644
--- a/tools/perf/util/db-export.c
+++ b/tools/perf/util/db-export.c
@@ -299,6 +299,7 @@ int db_export__sample(struct db_export *dbe, union 
perf_event *event,
};
struct thread *main_thread;
struct comm *comm = NULL;
+   struct comm *curr_comm;
int err;
 
err = db_export__evsel(dbe, evsel);
@@ -350,6 +351,13 @@ int db_export__sample(struct db_export *dbe, union 
perf_event *event,
}
}
 
+   curr_comm = thread__comm(thread);
+   if (curr_comm) {
+   err = db_export__comm(dbe, curr_comm, thread);
+   if (err)
+   goto out_put;
+   }
+
es.db_id = ++dbe->sample_last_db_id;
 
err = db_ids_from_al(dbe, al, _db_id, _db_id, );
-- 
2.21.0



[PATCH 12/28] perf scripts python: export-to-sqlite.py: Export comm details

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

Add table columns for thread id, comm start time and exec flag.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190710085810.1650-10-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/scripts/python/export-to-sqlite.py | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/tools/perf/scripts/python/export-to-sqlite.py 
b/tools/perf/scripts/python/export-to-sqlite.py
index 021326c46285..97aa66dd2fe1 100644
--- a/tools/perf/scripts/python/export-to-sqlite.py
+++ b/tools/perf/scripts/python/export-to-sqlite.py
@@ -177,7 +177,10 @@ do_query(query, 'CREATE TABLE threads ('
'tidinteger)')
 do_query(query, 'CREATE TABLE comms ('
'id integer NOT NULLPRIMARY KEY,'
-   'comm   varchar(16))')
+   'comm   varchar(16),'
+   'c_thread_idbigint,'
+   'c_time bigint,'
+   'exec_flag  boolean)')
 do_query(query, 'CREATE TABLE comm_threads ('
'id integer NOT NULLPRIMARY KEY,'
'comm_idbigint,'
@@ -536,7 +539,7 @@ machine_query.prepare("INSERT INTO machines VALUES (?, ?, 
?)")
 thread_query = QSqlQuery(db)
 thread_query.prepare("INSERT INTO threads VALUES (?, ?, ?, ?, ?)")
 comm_query = QSqlQuery(db)
-comm_query.prepare("INSERT INTO comms VALUES (?, ?)")
+comm_query.prepare("INSERT INTO comms VALUES (?, ?, ?, ?, ?)")
 comm_thread_query = QSqlQuery(db)
 comm_thread_query.prepare("INSERT INTO comm_threads VALUES (?, ?, ?)")
 dso_query = QSqlQuery(db)
@@ -576,7 +579,7 @@ def trace_begin():
evsel_table(0, "unknown")
machine_table(0, 0, "unknown")
thread_table(0, 0, 0, -1, -1)
-   comm_table(0, "unknown")
+   comm_table(0, "unknown", 0, 0, 0)
dso_table(0, 0, "unknown", "unknown", "")
symbol_table(0, 0, 0, 0, 0, "unknown")
sample_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0)
@@ -642,7 +645,7 @@ def thread_table(*x):
bind_exec(thread_query, 5, x)
 
 def comm_table(*x):
-   bind_exec(comm_query, 2, x)
+   bind_exec(comm_query, 5, x)
 
 def comm_thread_table(*x):
bind_exec(comm_thread_query, 3, x)
-- 
2.21.0



[PATCH 14/28] perf db-export: Factor out db_export__comm()

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

In preparation for exporting the current comm for a thread, factor out
db_export__comm().

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190710085810.1650-12-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/db-export.c | 30 +++---
 tools/perf/util/db-export.h |  2 ++
 2 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c
index b0504d3eb130..b1e581c13963 100644
--- a/tools/perf/util/db-export.c
+++ b/tools/perf/util/db-export.c
@@ -78,6 +78,26 @@ int db_export__thread(struct db_export *dbe, struct thread 
*thread,
return 0;
 }
 
+static int __db_export__comm(struct db_export *dbe, struct comm *comm,
+struct thread *thread)
+{
+   comm->db_id = ++dbe->comm_last_db_id;
+
+   if (dbe->export_comm)
+   return dbe->export_comm(dbe, comm, thread);
+
+   return 0;
+}
+
+int db_export__comm(struct db_export *dbe, struct comm *comm,
+   struct thread *thread)
+{
+   if (comm->db_id)
+   return 0;
+
+   return __db_export__comm(dbe, comm, thread);
+}
+
 /*
  * Export the "exec" comm. The "exec" comm is the program / application command
  * name at the time it first executes. It is used to group threads for the same
@@ -92,13 +112,9 @@ int db_export__exec_comm(struct db_export *dbe, struct comm 
*comm,
if (comm->db_id)
return 0;
 
-   comm->db_id = ++dbe->comm_last_db_id;
-
-   if (dbe->export_comm) {
-   err = dbe->export_comm(dbe, comm, main_thread);
-   if (err)
-   return err;
-   }
+   err = __db_export__comm(dbe, comm, main_thread);
+   if (err)
+   return err;
 
/*
 * Record the main thread for this comm. Note that the main thread can
diff --git a/tools/perf/util/db-export.h b/tools/perf/util/db-export.h
index 29f7c3b035a7..f5f0865f07e1 100644
--- a/tools/perf/util/db-export.h
+++ b/tools/perf/util/db-export.h
@@ -77,6 +77,8 @@ int db_export__evsel(struct db_export *dbe, struct perf_evsel 
*evsel);
 int db_export__machine(struct db_export *dbe, struct machine *machine);
 int db_export__thread(struct db_export *dbe, struct thread *thread,
  struct machine *machine, struct thread *main_thread);
+int db_export__comm(struct db_export *dbe, struct comm *comm,
+   struct thread *thread);
 int db_export__exec_comm(struct db_export *dbe, struct comm *comm,
 struct thread *main_thread);
 int db_export__comm_thread(struct db_export *dbe, struct comm *comm,
-- 
2.21.0



[PATCH 13/28] perf scripts python: export-to-postgresql.py: Export comm details

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

Add table columns for thread id, comm start time and exec flag.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190710085810.1650-11-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/scripts/python/export-to-postgresql.py | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/tools/perf/scripts/python/export-to-postgresql.py 
b/tools/perf/scripts/python/export-to-postgresql.py
index 92713d93e956..01f37877f5bb 100644
--- a/tools/perf/scripts/python/export-to-postgresql.py
+++ b/tools/perf/scripts/python/export-to-postgresql.py
@@ -353,7 +353,10 @@ do_query(query, 'CREATE TABLE threads ('
'tidinteger)')
 do_query(query, 'CREATE TABLE comms ('
'id bigint  NOT NULL,'
-   'comm   varchar(16))')
+   'comm   varchar(16),'
+   'c_thread_idbigint,'
+   'c_time bigint,'
+   'exec_flag  boolean)')
 do_query(query, 'CREATE TABLE comm_threads ('
'id bigint  NOT NULL,'
'comm_idbigint,'
@@ -763,7 +766,7 @@ def trace_begin():
evsel_table(0, "unknown")
machine_table(0, 0, "unknown")
thread_table(0, 0, 0, -1, -1)
-   comm_table(0, "unknown")
+   comm_table(0, "unknown", 0, 0, 0)
dso_table(0, 0, "unknown", "unknown", "")
symbol_table(0, 0, 0, 0, 0, "unknown")
sample_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0)
@@ -851,6 +854,8 @@ def trace_end():
do_query(query, 'ALTER TABLE threads '
'ADD CONSTRAINT machinefk  FOREIGN KEY 
(machine_id)   REFERENCES machines   (id),'
'ADD CONSTRAINT processfk  FOREIGN KEY 
(process_id)   REFERENCES threads(id)')
+   do_query(query, 'ALTER TABLE comms '
+   'ADD CONSTRAINT threadfk   FOREIGN KEY 
(c_thread_id)  REFERENCES threads(id)')
do_query(query, 'ALTER TABLE comm_threads '
'ADD CONSTRAINT commfk FOREIGN KEY 
(comm_id)  REFERENCES comms  (id),'
'ADD CONSTRAINT threadfk   FOREIGN KEY 
(thread_id)REFERENCES threads(id)')
@@ -935,11 +940,11 @@ def thread_table(thread_id, machine_id, process_id, pid, 
tid, *x):
value = struct.pack("!hiqiqiq", 5, 8, thread_id, 8, machine_id, 8, 
process_id, 4, pid, 4, tid)
thread_file.write(value)
 
-def comm_table(comm_id, comm_str, *x):
+def comm_table(comm_id, comm_str, thread_id, time, exec_flag, *x):
comm_str = toserverstr(comm_str)
n = len(comm_str)
-   fmt = "!hiqi" + str(n) + "s"
-   value = struct.pack(fmt, 2, 8, comm_id, n, comm_str)
+   fmt = "!hiqi" + str(n) + "s" + "iqiqiB"
+   value = struct.pack(fmt, 5, 8, comm_id, n, comm_str, 8, thread_id, 8, 
time, 1, exec_flag)
comm_file.write(value)
 
 def comm_thread_table(comm_thread_id, comm_id, thread_id, *x):
-- 
2.21.0



[PATCH 07/28] perf db-export: Export main_thread in db_export__sample()

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

Export main_thread in db_export__sample() because it makes the code
easier to understand, and prepares db_export__thread() for further
simplification.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190710085810.1650-5-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/db-export.c | 30 ++
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c
index 14501236c046..63f9edf65eee 100644
--- a/tools/perf/util/db-export.c
+++ b/tools/perf/util/db-export.c
@@ -71,16 +71,10 @@ int db_export__thread(struct db_export *dbe, struct thread 
*thread,
thread->db_id = ++dbe->thread_last_db_id;
 
if (main_thread) {
-   if (main_thread != thread) {
-   err = db_export__thread(dbe, main_thread, machine,
-   comm, main_thread);
+   if (main_thread != thread && comm) {
+   err = db_export__comm_thread(dbe, comm, thread);
if (err)
return err;
-   if (comm) {
-   err = db_export__comm_thread(dbe, comm, thread);
-   if (err)
-   return err;
-   }
}
main_thread_db_id = main_thread->db_id;
}
@@ -308,12 +302,24 @@ int db_export__sample(struct db_export *dbe, union 
perf_event *event,
return err;
 
main_thread = thread__main_thread(al->machine, thread);
-   if (main_thread)
+   if (main_thread) {
comm = machine__thread_exec_comm(al->machine, main_thread);
+   /*
+* A thread has a reference to the main thread, so export the
+* main thread first.
+*/
+   err = db_export__thread(dbe, main_thread, al->machine, comm,
+   main_thread);
+   if (err)
+   goto out_put;
+   }
 
-   err = db_export__thread(dbe, thread, al->machine, comm, main_thread);
-   if (err)
-   goto out_put;
+   if (thread != main_thread) {
+   err = db_export__thread(dbe, thread, al->machine, comm,
+   main_thread);
+   if (err)
+   goto out_put;
+   }
 
if (comm) {
err = db_export__exec_comm(dbe, comm, main_thread);
-- 
2.21.0



[PATCH 11/28] perf db-export: Export comm details

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

In preparation for exporting the current comm for a thread, export comm
thread id, start time and exec flag.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190710085810.1650-9-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/db-export.c| 2 +-
 tools/perf/util/db-export.h| 3 ++-
 tools/perf/util/scripting-engines/trace-event-python.c | 8 ++--
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c
index 2c3a4ad68428..b0504d3eb130 100644
--- a/tools/perf/util/db-export.c
+++ b/tools/perf/util/db-export.c
@@ -95,7 +95,7 @@ int db_export__exec_comm(struct db_export *dbe, struct comm 
*comm,
comm->db_id = ++dbe->comm_last_db_id;
 
if (dbe->export_comm) {
-   err = dbe->export_comm(dbe, comm);
+   err = dbe->export_comm(dbe, comm, main_thread);
if (err)
return err;
}
diff --git a/tools/perf/util/db-export.h b/tools/perf/util/db-export.h
index 811a678a910d..29f7c3b035a7 100644
--- a/tools/perf/util/db-export.h
+++ b/tools/perf/util/db-export.h
@@ -43,7 +43,8 @@ struct db_export {
int (*export_machine)(struct db_export *dbe, struct machine *machine);
int (*export_thread)(struct db_export *dbe, struct thread *thread,
 u64 main_thread_db_id, struct machine *machine);
-   int (*export_comm)(struct db_export *dbe, struct comm *comm);
+   int (*export_comm)(struct db_export *dbe, struct comm *comm,
+  struct thread *thread);
int (*export_comm_thread)(struct db_export *dbe, u64 db_id,
  struct comm *comm, struct thread *thread);
int (*export_dso)(struct db_export *dbe, struct dso *dso,
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c 
b/tools/perf/util/scripting-engines/trace-event-python.c
index c9837f0f0fd6..28167e938cef 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -1011,15 +1011,19 @@ static int python_export_thread(struct db_export *dbe, 
struct thread *thread,
return 0;
 }
 
-static int python_export_comm(struct db_export *dbe, struct comm *comm)
+static int python_export_comm(struct db_export *dbe, struct comm *comm,
+ struct thread *thread)
 {
struct tables *tables = container_of(dbe, struct tables, dbe);
PyObject *t;
 
-   t = tuple_new(2);
+   t = tuple_new(5);
 
tuple_set_u64(t, 0, comm->db_id);
tuple_set_string(t, 1, comm__str(comm));
+   tuple_set_u64(t, 2, thread->db_id);
+   tuple_set_u64(t, 3, comm->start);
+   tuple_set_s32(t, 4, comm->exec);
 
call_object(tables->comm_handler, t, "comm_table");
 
-- 
2.21.0



[PATCH 05/28] perf db-export: Rename db_export__comm() to db_export__exec_comm()

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

Rename db_export__comm() to db_export__exec_comm() to better reflect
what it does and add explanatory comments.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190710085810.1650-3-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/db-export.c | 22 +++---
 tools/perf/util/db-export.h |  4 ++--
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c
index 34cf197fe74f..8fab57f90cbc 100644
--- a/tools/perf/util/db-export.c
+++ b/tools/perf/util/db-export.c
@@ -105,8 +105,14 @@ int db_export__thread(struct db_export *dbe, struct thread 
*thread,
return err;
 }
 
-int db_export__comm(struct db_export *dbe, struct comm *comm,
-   struct thread *main_thread)
+/*
+ * Export the "exec" comm. The "exec" comm is the program / application command
+ * name at the time it first executes. It is used to group threads for the same
+ * program. Note that the main thread pid (or thread group id tgid) cannot be
+ * used because it does not change when a new program is exec'ed.
+ */
+int db_export__exec_comm(struct db_export *dbe, struct comm *comm,
+struct thread *main_thread)
 {
int err;
 
@@ -121,6 +127,16 @@ int db_export__comm(struct db_export *dbe, struct comm 
*comm,
return err;
}
 
+   /*
+* Record the main thread for this comm. Note that the main thread can
+* have many "exec" comms because there will be a new one every time it
+* exec's. An "exec" comm however will only ever have 1 main thread.
+* That is different to any other threads for that same program because
+* exec() will effectively kill them, so the relationship between the
+* "exec" comm and non-main threads is 1-to-1. That is why
+* db_export__comm_thread() is called here for the main thread, but it
+* is called for non-main threads when they are exported.
+*/
return db_export__comm_thread(dbe, comm, main_thread);
 }
 
@@ -313,7 +329,7 @@ int db_export__sample(struct db_export *dbe, union 
perf_event *event,
goto out_put;
 
if (comm) {
-   err = db_export__comm(dbe, comm, main_thread);
+   err = db_export__exec_comm(dbe, comm, main_thread);
if (err)
goto out_put;
es.comm_db_id = comm->db_id;
diff --git a/tools/perf/util/db-export.h b/tools/perf/util/db-export.h
index 261cfece8dee..148a657b1887 100644
--- a/tools/perf/util/db-export.h
+++ b/tools/perf/util/db-export.h
@@ -76,8 +76,8 @@ int db_export__evsel(struct db_export *dbe, struct perf_evsel 
*evsel);
 int db_export__machine(struct db_export *dbe, struct machine *machine);
 int db_export__thread(struct db_export *dbe, struct thread *thread,
  struct machine *machine, struct comm *comm);
-int db_export__comm(struct db_export *dbe, struct comm *comm,
-   struct thread *main_thread);
+int db_export__exec_comm(struct db_export *dbe, struct comm *comm,
+struct thread *main_thread);
 int db_export__comm_thread(struct db_export *dbe, struct comm *comm,
   struct thread *thread);
 int db_export__dso(struct db_export *dbe, struct dso *dso,
-- 
2.21.0



[PATCH 10/28] perf db-export: Fix a white space issue in db_export__sample()

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

Fix a white space issue in db_export__sample()

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190710085810.1650-8-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/db-export.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c
index 78f62a733b9d..2c3a4ad68428 100644
--- a/tools/perf/util/db-export.c
+++ b/tools/perf/util/db-export.c
@@ -274,7 +274,7 @@ int db_export__sample(struct db_export *dbe, union 
perf_event *event,
  struct perf_sample *sample, struct perf_evsel *evsel,
  struct addr_location *al)
 {
-   struct thread* thread = al->thread;
+   struct thread *thread = al->thread;
struct export_sample es = {
.event = event,
.sample = sample,
-- 
2.21.0



[PATCH 02/28] perf test: Auto bump rlimit(MEMLOCK) for BPF test sake

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

I noticed that the 'perf test bpf' was failing:

  # perf test bpf
  41: BPF filter:
  41.1: Basic BPF filtering : Skip
  41.2: BPF pinning : Skip
  41.3: BPF prologue generation : Skip
  41.4: BPF relocation checker  : Skip
  # ulimit -l
  64
  #

Using verbose mode we get just a line bout -EPERF being returned from
libbpf's bpf_load_program_xattr(), that ends up being used in 'perf
test bpf' initial program loading capability query:

  Missing basic BPF support, skip this test: Operation not permitted

Not that informative, but on a separate problem when creating BPF maps
bumping rlimit(MEMLOCK) helped, so I tried it here as well, works:

  # ulimit -l 128
  # perf test bpf
  41: BPF filter:
  41.1: Basic BPF filtering : Ok
  41.2: BPF pinning : Ok
  41.3: BPF prologue generation : Ok
  41.4: BPF relocation checker  : Ok
  #

So use the recently added rlimit__bump_memlock() helper:

  # ulimit -l 64
  # perf test bpf
  41: BPF filter:
  41.1: Basic BPF filtering : Ok
  41.2: BPF pinning : Ok
  41.3: BPF prologue generation : Ok
  41.4: BPF relocation checker  : Ok
  # ulimit -l
  64
  #

I.e. the bumping of memlock is restricted to the 'perf test' instance,
not changing the global value.

Cc: Adrian Hunter 
Cc: Alexei Starovoitov 
Cc: Daniel Borkmann 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-b9fubkhr4jm192lu7y8hg...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/tests/builtin-test.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 66a82badc1d1..c3bec9d2c201 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -21,6 +21,7 @@
 #include 
 #include "string2.h"
 #include "symbol.h"
+#include "util/rlimit.h"
 #include 
 #include 
 #include 
@@ -727,6 +728,11 @@ int cmd_test(int argc, const char **argv)
 
if (skip != NULL)
skiplist = intlist__new(skip);
+   /*
+* Tests that create BPF maps, for instance, need more than the 64K
+* default:
+*/
+   rlimit__bump_memlock();
 
return __cmd_test(argc, argv, skiplist);
 }
-- 
2.21.0



[PATCH 06/28] perf db-export: Pass main_thread to db_export__thread()

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

Calls to db_export__thread() already have main_thread so there is no
reason to get it again, instead pass it as a parameter. Note that one
difference in this approach is that the main thread is not created if it
does not exist. It is better if it is not created because:

   - If main_thread is being traced it will have been created already.

   - If it is not being traced, there will be no other information about
 it, and it will never get deleted because there will be no EXIT event.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190710085810.1650-4-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/db-export.c | 29 -
 tools/perf/util/db-export.h |  3 ++-
 2 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c
index 8fab57f90cbc..14501236c046 100644
--- a/tools/perf/util/db-export.c
+++ b/tools/perf/util/db-export.c
@@ -59,9 +59,9 @@ int db_export__machine(struct db_export *dbe, struct machine 
*machine)
 }
 
 int db_export__thread(struct db_export *dbe, struct thread *thread,
- struct machine *machine, struct comm *comm)
+ struct machine *machine, struct comm *comm,
+ struct thread *main_thread)
 {
-   struct thread *main_thread;
u64 main_thread_db_id = 0;
int err;
 
@@ -70,28 +70,19 @@ int db_export__thread(struct db_export *dbe, struct thread 
*thread,
 
thread->db_id = ++dbe->thread_last_db_id;
 
-   if (thread->pid_ != -1) {
-   if (thread->pid_ == thread->tid) {
-   main_thread = thread;
-   } else {
-   main_thread = machine__findnew_thread(machine,
- thread->pid_,
- thread->pid_);
-   if (!main_thread)
-   return -ENOMEM;
+   if (main_thread) {
+   if (main_thread != thread) {
err = db_export__thread(dbe, main_thread, machine,
-   comm);
+   comm, main_thread);
if (err)
-   goto out_put;
+   return err;
if (comm) {
err = db_export__comm_thread(dbe, comm, thread);
if (err)
-   goto out_put;
+   return err;
}
}
main_thread_db_id = main_thread->db_id;
-   if (main_thread != thread)
-   thread__put(main_thread);
}
 
if (dbe->export_thread)
@@ -99,10 +90,6 @@ int db_export__thread(struct db_export *dbe, struct thread 
*thread,
  machine);
 
return 0;
-
-out_put:
-   thread__put(main_thread);
-   return err;
 }
 
 /*
@@ -324,7 +311,7 @@ int db_export__sample(struct db_export *dbe, union 
perf_event *event,
if (main_thread)
comm = machine__thread_exec_comm(al->machine, main_thread);
 
-   err = db_export__thread(dbe, thread, al->machine, comm);
+   err = db_export__thread(dbe, thread, al->machine, comm, main_thread);
if (err)
goto out_put;
 
diff --git a/tools/perf/util/db-export.h b/tools/perf/util/db-export.h
index 148a657b1887..6e267321594c 100644
--- a/tools/perf/util/db-export.h
+++ b/tools/perf/util/db-export.h
@@ -75,7 +75,8 @@ void db_export__exit(struct db_export *dbe);
 int db_export__evsel(struct db_export *dbe, struct perf_evsel *evsel);
 int db_export__machine(struct db_export *dbe, struct machine *machine);
 int db_export__thread(struct db_export *dbe, struct thread *thread,
- struct machine *machine, struct comm *comm);
+ struct machine *machine, struct comm *comm,
+ struct thread *main_thread);
 int db_export__exec_comm(struct db_export *dbe, struct comm *comm,
 struct thread *main_thread);
 int db_export__comm_thread(struct db_export *dbe, struct comm *comm,
-- 
2.21.0



[PATCH 08/28] perf db-export: Export comm before exporting thread

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

Export comm before exporting the non-main thread because
db_export__thread() also exports the comm_thread.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190710085810.1650-6-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/db-export.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c
index 63f9edf65eee..99ad759561de 100644
--- a/tools/perf/util/db-export.c
+++ b/tools/perf/util/db-export.c
@@ -312,6 +312,12 @@ int db_export__sample(struct db_export *dbe, union 
perf_event *event,
main_thread);
if (err)
goto out_put;
+   if (comm) {
+   err = db_export__exec_comm(dbe, comm, main_thread);
+   if (err)
+   goto out_put;
+   es.comm_db_id = comm->db_id;
+   }
}
 
if (thread != main_thread) {
@@ -321,13 +327,6 @@ int db_export__sample(struct db_export *dbe, union 
perf_event *event,
goto out_put;
}
 
-   if (comm) {
-   err = db_export__exec_comm(dbe, comm, main_thread);
-   if (err)
-   goto out_put;
-   es.comm_db_id = comm->db_id;
-   }
-
es.db_id = ++dbe->sample_last_db_id;
 
err = db_ids_from_al(dbe, al, _db_id, _db_id, );
-- 
2.21.0



[PATCH 09/28] perf db-export: Move export__comm_thread into db_export__sample()

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

Move call to db_export__comm_thread() from db_export__thread() into
db_export__sample() because it makes the code easier to understand, and
add explanatory comments.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190710085810.1650-7-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/db-export.c | 35 +--
 tools/perf/util/db-export.h |  3 +--
 2 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c
index 99ad759561de..78f62a733b9d 100644
--- a/tools/perf/util/db-export.c
+++ b/tools/perf/util/db-export.c
@@ -59,25 +59,17 @@ int db_export__machine(struct db_export *dbe, struct 
machine *machine)
 }
 
 int db_export__thread(struct db_export *dbe, struct thread *thread,
- struct machine *machine, struct comm *comm,
- struct thread *main_thread)
+ struct machine *machine, struct thread *main_thread)
 {
u64 main_thread_db_id = 0;
-   int err;
 
if (thread->db_id)
return 0;
 
thread->db_id = ++dbe->thread_last_db_id;
 
-   if (main_thread) {
-   if (main_thread != thread && comm) {
-   err = db_export__comm_thread(dbe, comm, thread);
-   if (err)
-   return err;
-   }
+   if (main_thread)
main_thread_db_id = main_thread->db_id;
-   }
 
if (dbe->export_thread)
return dbe->export_thread(dbe, thread, main_thread_db_id,
@@ -303,15 +295,19 @@ int db_export__sample(struct db_export *dbe, union 
perf_event *event,
 
main_thread = thread__main_thread(al->machine, thread);
if (main_thread) {
-   comm = machine__thread_exec_comm(al->machine, main_thread);
/*
 * A thread has a reference to the main thread, so export the
 * main thread first.
 */
-   err = db_export__thread(dbe, main_thread, al->machine, comm,
+   err = db_export__thread(dbe, main_thread, al->machine,
main_thread);
if (err)
goto out_put;
+   /*
+* Export comm before exporting the non-main thread because
+* db_export__comm_thread() can be called further below.
+*/
+   comm = machine__thread_exec_comm(al->machine, main_thread);
if (comm) {
err = db_export__exec_comm(dbe, comm, main_thread);
if (err)
@@ -321,10 +317,21 @@ int db_export__sample(struct db_export *dbe, union 
perf_event *event,
}
 
if (thread != main_thread) {
-   err = db_export__thread(dbe, thread, al->machine, comm,
-   main_thread);
+   /*
+* For a non-main thread, db_export__comm_thread() must be
+* called only if thread has not previously been exported.
+*/
+   bool export_comm_thread = comm && !thread->db_id;
+
+   err = db_export__thread(dbe, thread, al->machine, main_thread);
if (err)
goto out_put;
+
+   if (export_comm_thread) {
+   err = db_export__comm_thread(dbe, comm, thread);
+   if (err)
+   goto out_put;
+   }
}
 
es.db_id = ++dbe->sample_last_db_id;
diff --git a/tools/perf/util/db-export.h b/tools/perf/util/db-export.h
index 6e267321594c..811a678a910d 100644
--- a/tools/perf/util/db-export.h
+++ b/tools/perf/util/db-export.h
@@ -75,8 +75,7 @@ void db_export__exit(struct db_export *dbe);
 int db_export__evsel(struct db_export *dbe, struct perf_evsel *evsel);
 int db_export__machine(struct db_export *dbe, struct machine *machine);
 int db_export__thread(struct db_export *dbe, struct thread *thread,
- struct machine *machine, struct comm *comm,
- struct thread *main_thread);
+ struct machine *machine, struct thread *main_thread);
 int db_export__exec_comm(struct db_export *dbe, struct comm *comm,
 struct thread *main_thread);
 int db_export__comm_thread(struct db_export *dbe, struct comm *comm,
-- 
2.21.0



[PATCH 04/28] perf db-export: Get rid of db_export__deferred()

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

db_export__deferred() deferred the export of comms if the comm string
had not been "set" (changed from :) however that problem was fixed
a long time ago by commit e803cf97a4f9 ("perf record: Synthesize COMM
event for a command line workload"), so get rid of
db_export__deferred().

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: http://lkml.kernel.org/r/20190710085810.1650-2-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/db-export.c   | 61 +--
 tools/perf/util/db-export.h   |  2 -
 .../scripting-engines/trace-event-python.c|  4 +-
 3 files changed, 2 insertions(+), 65 deletions(-)

diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c
index 2394c7506abe..34cf197fe74f 100644
--- a/tools/perf/util/db-export.c
+++ b/tools/perf/util/db-export.c
@@ -20,70 +20,14 @@
 #include "db-export.h"
 #include 
 
-struct deferred_export {
-   struct list_head node;
-   struct comm *comm;
-};
-
-static int db_export__deferred(struct db_export *dbe)
-{
-   struct deferred_export *de;
-   int err;
-
-   while (!list_empty(>deferred)) {
-   de = list_entry(dbe->deferred.next, struct deferred_export,
-   node);
-   err = dbe->export_comm(dbe, de->comm);
-   list_del_init(>node);
-   free(de);
-   if (err)
-   return err;
-   }
-
-   return 0;
-}
-
-static void db_export__free_deferred(struct db_export *dbe)
-{
-   struct deferred_export *de;
-
-   while (!list_empty(>deferred)) {
-   de = list_entry(dbe->deferred.next, struct deferred_export,
-   node);
-   list_del_init(>node);
-   free(de);
-   }
-}
-
-static int db_export__defer_comm(struct db_export *dbe, struct comm *comm)
-{
-   struct deferred_export *de;
-
-   de = zalloc(sizeof(struct deferred_export));
-   if (!de)
-   return -ENOMEM;
-
-   de->comm = comm;
-   list_add_tail(>node, >deferred);
-
-   return 0;
-}
-
 int db_export__init(struct db_export *dbe)
 {
memset(dbe, 0, sizeof(struct db_export));
-   INIT_LIST_HEAD(>deferred);
return 0;
 }
 
-int db_export__flush(struct db_export *dbe)
-{
-   return db_export__deferred(dbe);
-}
-
 void db_export__exit(struct db_export *dbe)
 {
-   db_export__free_deferred(dbe);
call_return_processor__free(dbe->crp);
dbe->crp = NULL;
 }
@@ -172,10 +116,7 @@ int db_export__comm(struct db_export *dbe, struct comm 
*comm,
comm->db_id = ++dbe->comm_last_db_id;
 
if (dbe->export_comm) {
-   if (main_thread->comm_set)
-   err = dbe->export_comm(dbe, comm);
-   else
-   err = db_export__defer_comm(dbe, comm);
+   err = dbe->export_comm(dbe, comm);
if (err)
return err;
}
diff --git a/tools/perf/util/db-export.h b/tools/perf/util/db-export.h
index e8a64028a386..261cfece8dee 100644
--- a/tools/perf/util/db-export.h
+++ b/tools/perf/util/db-export.h
@@ -68,11 +68,9 @@ struct db_export {
u64 sample_last_db_id;
u64 call_path_last_db_id;
u64 call_return_last_db_id;
-   struct list_head deferred;
 };
 
 int db_export__init(struct db_export *dbe);
-int db_export__flush(struct db_export *dbe);
 void db_export__exit(struct db_export *dbe);
 int db_export__evsel(struct db_export *dbe, struct perf_evsel *evsel);
 int db_export__machine(struct db_export *dbe, struct machine *machine);
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c 
b/tools/perf/util/scripting-engines/trace-event-python.c
index 112bed65232f..c9837f0f0fd6 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -1620,9 +1620,7 @@ static int python_start_script(const char *script, int 
argc, const char **argv)
 
 static int python_flush_script(void)
 {
-   struct tables *tables = _global;
-
-   return db_export__flush(>dbe);
+   return 0;
 }
 
 /*
-- 
2.21.0



[PATCH 03/28] perf trace: Auto bump rlimit(MEMLOCK) for eBPF maps sake

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

Circa v5.2 this started to fail:

  # perf trace -e /wb/augmented_raw_syscalls.o
  event syntax error: '/wb/augmented_raw_syscalls.o'
   \___ Operation not permitted

  (add -v to see detail)
  Run 'perf list' for a list of valid events

   Usage: perf trace [] []
  or: perf trace [] --  []
  or: perf trace record [] []
  or: perf trace record [] --  []

  -e, --eventevent/syscall selector. use 'perf list' to list 
available events
  #

In verbose mode we some -EPERM when creating a BPF map:

  # perf trace -v -e /wb/augmented_raw_syscalls.o
  
  libbpf: failed to create map (name: '__augmented_syscalls__'): Operation not 
permitted
  libbpf: failed to load object '/wb/augmented_raw_syscalls.o'
  bpf: load objects failed: err=-1: (Operation not permitted)
  event syntax error: '/wb/augmented_raw_syscalls.o'
   \___ Operation not permitted

  (add -v to see detail)
  Run 'perf list' for a list of valid events

   Usage: perf trace [] []
  or: perf trace [] --  []
  or: perf trace record [] []
  or: perf trace record [] --  []

  -e, --eventevent/syscall selector. use 'perf list' to list 
available events
  #

If we bumped 'ulimit -l 128' to get it from the 64k default to double that, it
worked, so use the recently added rlimit__bump_memlock() helper:

  # perf trace -e /wb/augmented_raw_syscalls.o -e open*,*sleep sleep 1
   0.000 ( 0.007 ms): sleep/28042 openat(dfd: CWD, filename: 
"/etc/ld.so.cache", flags: RDONLY|CLOEXEC) = 3
   0.022 ( 0.004 ms): sleep/28042 openat(dfd: CWD, filename: 
"/lib64/libc.so.6", flags: RDONLY|CLOEXEC) = 3
   0.201 ( 0.007 ms): sleep/28042 openat(dfd: CWD, filename: "", flags: 
RDONLY|CLOEXEC) = 3
   0.241 (1000.421 ms): sleep/28042 nanosleep(rqtp: 0x7ffd6c3e6ed0) 
  = 0
  #

Cc: Adrian Hunter 
Cc: Alexei Starovoitov 
Cc: Daniel Borkmann 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-j6f2ioa6hj9dinzpjvlhc...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-trace.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 1aa2ed096f65..4f0bbffee05f 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include "util/bpf_map.h"
+#include "util/rlimit.h"
 #include "builtin.h"
 #include "util/cgroup.h"
 #include "util/color.h"
@@ -3864,6 +3865,15 @@ int cmd_trace(int argc, const char **argv)
goto out;
}
 
+   /*
+* Parsing .perfconfig may entail creating a BPF event, that may need
+* to create BPF maps, so bump RLIM_MEMLOCK as the default 64K setting
+* is too small. This affects just this process, not touching the
+* global setting. If it fails we'll get something in 'perf trace -v'
+* to help diagnose the problem.
+*/
+   rlimit__bump_memlock();
+
err = perf_config(trace__config, );
if (err)
goto out;
-- 
2.21.0



[PATCH 01/28] perf tools: Introduce rlimit__bump_memlock() helper

2019-07-15 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

Just like the BPF guys did when faced with failures with map creation,
etc, i.e. their solution is:

  tools/testing/selftests/bpf/bpf_rlimit.h

For perf use this function in 'perf test' and in 'perf trace'.

Make it bump to 4 times the current value, if it fails twice the current
value and if it still fails, warn that things like BPF map creation may
fail, to help in diagnosing the problem.

Cc: Adrian Hunter 
Cc: Alexei Starovoitov 
Cc: Daniel Borkmann 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-muvqef2i7n6pzqbmu7tn2...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/Build|  1 +
 tools/perf/util/rlimit.c | 29 +
 tools/perf/util/rlimit.h |  6 ++
 3 files changed, 36 insertions(+)
 create mode 100644 tools/perf/util/rlimit.c
 create mode 100644 tools/perf/util/rlimit.h

diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index d7e3b008a613..14f812bb07a7 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -20,6 +20,7 @@ perf-y += parse-events.o
 perf-y += perf_regs.o
 perf-y += path.o
 perf-y += print_binary.o
+perf-y += rlimit.o
 perf-y += argv_split.o
 perf-y += rbtree.o
 perf-y += libstring.o
diff --git a/tools/perf/util/rlimit.c b/tools/perf/util/rlimit.c
new file mode 100644
index ..13521d392a22
--- /dev/null
+++ b/tools/perf/util/rlimit.c
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: LGPL-2.1 */
+
+#include "util/debug.h"
+#include "util/rlimit.h"
+#include 
+#include 
+
+/*
+ * Bump the memlock so that we can get bpf maps of a reasonable size,
+ * like the ones used with 'perf trace' and with 'perf test bpf',
+ * improve this to some specific request if needed.
+ */
+void rlimit__bump_memlock(void)
+{
+   struct rlimit rlim;
+
+   if (getrlimit(RLIMIT_MEMLOCK, ) == 0) {
+   rlim.rlim_cur *= 4;
+   rlim.rlim_max *= 4;
+
+   if (setrlimit(RLIMIT_MEMLOCK, ) < 0) {
+   rlim.rlim_cur /= 2;
+   rlim.rlim_max /= 2;
+
+   if (setrlimit(RLIMIT_MEMLOCK, ) < 0)
+   pr_debug("Couldn't bump rlimit(MEMLOCK), 
failures may take place when creating BPF maps, etc\n");
+   }
+   }
+}
diff --git a/tools/perf/util/rlimit.h b/tools/perf/util/rlimit.h
new file mode 100644
index ..9f59d8e710a3
--- /dev/null
+++ b/tools/perf/util/rlimit.h
@@ -0,0 +1,6 @@
+#ifndef __PERF_RLIMIT_H_
+#define __PERF_RLIMIT_H_
+/* SPDX-License-Identifier: LGPL-2.1 */
+
+void rlimit__bump_memlock(void);
+#endif // __PERF_RLIMIT_H_
-- 
2.21.0



Re: [PATCH v9 03/18] kunit: test: add string_stream a std::stream like string builder

2019-07-15 Thread Brendan Higgins
On Mon, Jul 15, 2019 at 1:43 PM Stephen Boyd  wrote:
>
> Quoting Brendan Higgins (2019-07-12 01:17:29)
> > diff --git a/include/kunit/string-stream.h b/include/kunit/string-stream.h
> > new file mode 100644
> > index 0..0552a05781afe
> > --- /dev/null
> > +++ b/include/kunit/string-stream.h
> > @@ -0,0 +1,49 @@
> > +/* SPDX-License-Identifier: GPL-2.0 */
> > +/*
> > + * C++ stream style string builder used in KUnit for building messages.
> > + *
> > + * Copyright (C) 2019, Google LLC.
> > + * Author: Brendan Higgins 
> > + */
> > +
> > +#ifndef _KUNIT_STRING_STREAM_H
> > +#define _KUNIT_STRING_STREAM_H
> > +
> > +#include 
> > +#include 
> > +#include 
>
> What is this include for? I'd expect to see linux/list.h instead.

Sorry about that. I used to reference count this before I made it a
kunit managed resource.

> > +#include 
> > +
> > +struct string_stream_fragment {
> > +   struct list_head node;
> > +   char *fragment;
> > +};
> > +
> > +struct string_stream {
> > +   size_t length;
> > +   struct list_head fragments;
> > +   /* length and fragments are protected by this lock */
> > +   spinlock_t lock;
> > +};
> > +
> > diff --git a/kunit/string-stream.c b/kunit/string-stream.c
> > new file mode 100644
> > index 0..0463a92dad74b
> > --- /dev/null
> > +++ b/kunit/string-stream.c
> > @@ -0,0 +1,147 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * C++ stream style string builder used in KUnit for building messages.
> > + *
> > + * Copyright (C) 2019, Google LLC.
> > + * Author: Brendan Higgins 
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +int string_stream_vadd(struct string_stream *stream,
> > +  const char *fmt,
> > +  va_list args)
> > +{
> > +   struct string_stream_fragment *frag_container;
> > +   int len;
> > +   va_list args_for_counting;
> > +   unsigned long flags;
> > +
> > +   /* Make a copy because `vsnprintf` could change it */
> > +   va_copy(args_for_counting, args);
> > +
> > +   /* Need space for null byte. */
> > +   len = vsnprintf(NULL, 0, fmt, args_for_counting) + 1;
> > +
> > +   va_end(args_for_counting);
> > +
> > +   frag_container = kmalloc(sizeof(*frag_container), GFP_KERNEL);
>
> This is confusing in that it allocates with GFP_KERNEL but then grabs a
> spinlock to add and remove from the fragment list. Is it ever going to
> be called from a place where it can't sleep? If so, the GFP_KERNEL needs
> to be changed. Otherwise, maybe a mutex would work better to protect
> access to the fragment list.

Right, using a mutex here would be fine. Sorry, I meant to filter for
my usage of them after you asked me to remove them in 01, but
evidently I forgot to do so. Sorry, will fix.

> I also wonder if it would be better to just have a big slop buffer of a
> 4K page or something so that we almost never have to allocate anything
> with a string_stream and we can just rely on a reader consuming data
> while writers are writing. That might work out better, but I don't quite
> understand the use case for the string stream.

That makes sense, but might that also waste memory since we will
almost never need that much memory?

> > +   if (!frag_container)
> > +   return -ENOMEM;
> > +
> > +   frag_container->fragment = kmalloc(len, GFP_KERNEL);
> > +   if (!frag_container->fragment) {
> > +   kfree(frag_container);
> > +   return -ENOMEM;
> > +   }
> > +
> > +   len = vsnprintf(frag_container->fragment, len, fmt, args);
> > +   spin_lock_irqsave(>lock, flags);
> > +   stream->length += len;
> > +   list_add_tail(_container->node, >fragments);
> > +   spin_unlock_irqrestore(>lock, flags);
> > +
> > +   return 0;
> > +}
> > +
> [...]
> > +
> > +bool string_stream_is_empty(struct string_stream *stream)
> > +{
> > +   bool is_empty;
> > +   unsigned long flags;
> > +
> > +   spin_lock_irqsave(>lock, flags);
>
> I'm not sure what benefit grabbing the lock is having here. If the list
> isn't empty after this is called then the race isn't resolved by
> grabbing and releasing the lock. The function is returning stale data in
> that case.

Good point, I didn't realize list_empty was protected by READ_ONCE. Will fix.

> > +   is_empty = list_empty(>fragments);
> > +   spin_unlock_irqrestore(>lock, flags);
> > +
> > +   return is_empty;
> > +}
> > +
> > +static int string_stream_init(struct kunit_resource *res, void *context)
> > +{
> > +   struct string_stream *stream;
> > +
> > +   stream = kzalloc(sizeof(*stream), GFP_KERNEL);
> > +   if (!stream)
> > +   return -ENOMEM;
> > +
> > +   res->allocation = stream;
> > +   INIT_LIST_HEAD(>fragments);
> > +   spin_lock_init(>lock);
> > +
> > +   return 0;
> > +}
> > +
> > +static void string_stream_free(struct kunit_resource *res)
> > +{
> > 

[GIT PULL] perf/core improvements and fixes

2019-07-15 Thread Arnaldo Carvalho de Melo
Hi Ingo,

Please consider pulling,

Best regards,

- Arnaldo

Test results at the end of this message, as usual.

The following changes since commit 323fd749821daab0f327ec86d707c4542963cdb0:

  perf intel-pt: Fix potential NULL pointer dereference found by the smatch 
tool (2019-07-09 10:13:28 -0300)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git 
tags/perf-core-for-mingo-5.3-20190715

for you to fetch changes up to 916c31fff946fae0e05862f9b2435fdb29fd5090:

  perf version: Fix segfault due to missing OPT_END() (2019-07-15 07:59:05 
-0300)


perf/core improvements and fixes:

perf db-export:

  Adrian Hunter:

  - Improvements in how COMM details are exported to databases for
post processing and use in the sql-viewer.py UI.

  - Export switch events to the database.

BPF:

  Arnaldo Carvalho de Melo:

  - Bump rlimit(MEMLOCK) for 'perf test bpf' and 'perf trace', just like
selftests/bpf/bpf_rlimit.h do, which makes errors due to exhaustion of
this limit, which are kinda cryptic (EPERM sometimes) less frequent.

perf version:
  Ravi Bangoria:

  - Fix segfault due to missing OPT_END(), noticed on PowerPC.

perf vendor events:

  Thomas Richter:

  - Add JSON files for IBM s/390 machine type 8561.

perf cs-etm (ARM):

  YueHaibing:

  - Fix two cases of error returns not bing done properly: Invalid ERR_PTR() use
and loss of propagation error codes.

Signed-off-by: Arnaldo Carvalho de Melo 


Adrian Hunter (21):
  perf db-export: Get rid of db_export__deferred()
  perf db-export: Rename db_export__comm() to db_export__exec_comm()
  perf db-export: Pass main_thread to db_export__thread()
  perf db-export: Export main_thread in db_export__sample()
  perf db-export: Export comm before exporting thread
  perf db-export: Move export__comm_thread into db_export__sample()
  perf db-export: Fix a white space issue in db_export__sample()
  perf db-export: Export comm details
  perf scripts python: export-to-sqlite.py: Export comm details
  perf scripts python: export-to-postgresql.py: Export comm details
  perf db-export: Factor out db_export__comm()
  perf db-export: Also export thread's current comm
  perf scripts python: export-to-sqlite.py: Add has_calls column to comms 
table
  perf scripts python: export-to-postgresql.py: Add has_calls column to 
comms table
  perf scripts python: exported-sql-viewer.py: Remove redundant semi-colons
  perf scripts python: exported-sql-viewer.py: Use new 'has_calls' column
  perf script: Add scripting operation process_switch()
  perf db-export: Factor out db_export__threads()
  perf db-export: Export switch events
  perf scripts python: export-to-sqlite.py: Export switch events
  perf scripts python: export-to-postgresql.py: Export switch events

Arnaldo Carvalho de Melo (3):
  perf tools: Introduce rlimit__bump_memlock() helper
  perf test: Auto bump rlimit(MEMLOCK) for BPF test sake
  perf trace: Auto bump rlimit(MEMLOCK) for eBPF maps sake

Ravi Bangoria (1):
  perf version: Fix segfault due to missing OPT_END()

Thomas Richter (1):
  perf vendor events s390: Add JSON files for machine type 8561

YueHaibing (2):
  perf cs-etm: Remove errnoeous ERR_PTR() usage in 
cs_etm__process_auxtrace_info
  perf cs-etm: Return errcode in cs_etm__process_auxtrace_info()

 tools/perf/builtin-script.c|   8 +-
 tools/perf/builtin-trace.c |  10 +
 tools/perf/builtin-version.c   |   1 +
 .../perf/pmu-events/arch/s390/cf_m8561/basic.json  |  58 
 .../perf/pmu-events/arch/s390/cf_m8561/crypto.json | 114 +++
 .../pmu-events/arch/s390/cf_m8561/crypto6.json |  30 ++
 .../pmu-events/arch/s390/cf_m8561/extended.json| 373 +
 tools/perf/pmu-events/arch/s390/mapfile.csv|   1 +
 tools/perf/scripts/python/export-to-postgresql.py  |  68 +++-
 tools/perf/scripts/python/export-to-sqlite.py  |  54 ++-
 tools/perf/scripts/python/exported-sql-viewer.py   |  34 +-
 tools/perf/tests/builtin-test.c|   6 +
 tools/perf/util/Build  |   1 +
 tools/perf/util/cs-etm.c   |  12 +-
 tools/perf/util/db-export.c| 291 ++--
 tools/perf/util/db-export.h|  19 +-
 tools/perf/util/rlimit.c   |  29 ++
 tools/perf/util/rlimit.h   |   6 +
 .../util/scripting-engines/trace-event-python.c|  53 ++-
 tools/perf/util/trace-event.h  |   3 +
 20 files changed, 1029 insertions(+), 142 deletions(-)
 create mode 100644 tools/perf/pmu-events/arch/s390/cf_m8561/basic.json
 create mode 100644 tools/perf/pmu-events

[PATCH v1] net: fec: optionally reset PHY via a reset-controller

2019-07-15 Thread Sven Van Asbroeck
The current fec driver allows the PHY to be reset via a gpio,
specified in the devicetree. However, some PHYs need to be reset
in a more complex way.

To accommodate such PHYs, allow an optional reset controller
in the fec devicetree. If no reset controller is found, the
fec will fall back to the legacy reset behaviour.

Example:
 {
phy-mode = "rgmii";
resets = <_reset>;
reset-names = "phy";
status = "okay";
};

Signed-off-by: Sven Van Asbroeck 
---

Will send a Documentation patch if this receives a positive review.

 drivers/net/ethernet/freescale/fec_main.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/freescale/fec_main.c 
b/drivers/net/ethernet/freescale/fec_main.c
index 38f10f7dcbc3..5a5f3ed6f16d 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -61,6 +61,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -3335,6 +3336,7 @@ static int fec_enet_get_irq_cnt(struct platform_device 
*pdev)
 static int
 fec_probe(struct platform_device *pdev)
 {
+   struct reset_control *phy_reset;
struct fec_enet_private *fep;
struct fec_platform_data *pdata;
struct net_device *ndev;
@@ -3490,7 +3492,9 @@ fec_probe(struct platform_device *pdev)
pm_runtime_set_active(>dev);
pm_runtime_enable(>dev);
 
-   ret = fec_reset_phy(pdev);
+   phy_reset = devm_reset_control_get_exclusive(>dev, "phy");
+   ret = IS_ERR(phy_reset) ? fec_reset_phy(pdev) :
+   reset_control_reset(phy_reset);
if (ret)
goto failed_reset;
 
-- 
2.17.1



Re: [Intel-gfx] screen freeze with 5.2-rc6 Dell XPS-13 skylake i915

2019-07-15 Thread Souza, Jose
Hi James and Paul

So the issue did not happened again with the patch applied?

If you still have the kernel 5.1 installed could you share your
/sys/kernel/debug/dri/0/i915_edp_psr_status with the older kernel?
We want to check if training values changed between kernel versions.

On Fri, 2019-07-12 at 16:28 +0200, Paul Bolle wrote:
> James Bottomley schreef op vr 12-07-2019 om 07:19 [-0700]:
> > It has survived 6h without manifesting the regression.  Starting
> > again
> > to try a whole day.
> 
> And I'm currently at four hours without a screen freeze. Which is
> much, much
> longer than I was able to achieve without the hack applied.
> 
> 
> Paul Bolle
> 


Re: [PATCH] staging: kpc2000: Convert put_page() to put_user_page*()

2019-07-15 Thread Bharath Vedartham
On Mon, Jul 15, 2019 at 01:14:13PM -0700, John Hubbard wrote:
> On 7/15/19 12:52 PM, Bharath Vedartham wrote:
> > There have been issues with get_user_pages and filesystem writeback.
> > The issues are better described in [1].
> > 
> > The solution being proposed wants to keep track of gup_pinned pages which 
> > will allow to take furthur steps to coordinate between subsystems using gup.
> > 
> > put_user_page() simply calls put_page inside for now. But the 
> > implementation will change once all call sites of put_page() are converted.
> > 
> > I currently do not have the driver to test. Could I have some suggestions 
> > to test this code? The solution is currently implemented in [2] and
> > it would be great if we could apply the patch on top of [2] and run some 
> > tests to check if any regressions occur.
> 
> Hi Bharath,
> 
> Process point: the above paragraph, and other meta-questions (about the 
> patch, rather than part of the patch) should be placed either after the 
> "---", or in a cover letter (git-send-email --cover-letter). That way, the 
> patch itself is in a commit-able state.
> 
> One more below:
Will fix that in the next version. 
> > 
> > [1] https://lwn.net/Articles/753027/
> > [2] https://github.com/johnhubbard/linux/tree/gup_dma_core
> > 
> > Cc: Matt Sickler 
> > Cc: Greg Kroah-Hartman 
> > Cc: Jérôme Glisse 
> > Cc: Ira Weiny 
> > Cc: John Hubbard 
> > Cc: linux...@kvack.org
> > Cc: de...@driverdev.osuosl.org
> > 
> > Signed-off-by: Bharath Vedartham 
> > ---
> >  drivers/staging/kpc2000/kpc_dma/fileops.c | 8 ++--
> >  1 file changed, 2 insertions(+), 6 deletions(-)
> > 
> > diff --git a/drivers/staging/kpc2000/kpc_dma/fileops.c 
> > b/drivers/staging/kpc2000/kpc_dma/fileops.c
> > index 6166587..82c70e6 100644
> > --- a/drivers/staging/kpc2000/kpc_dma/fileops.c
> > +++ b/drivers/staging/kpc2000/kpc_dma/fileops.c
> > @@ -198,9 +198,7 @@ int  kpc_dma_transfer(struct dev_private_data *priv, 
> > struct kiocb *kcb, unsigned
> > sg_free_table(>sgt);
> >   err_dma_map_sg:
> >   err_alloc_sg_table:
> > -   for (i = 0 ; i < acd->page_count ; i++){
> > -   put_page(acd->user_pages[i]);
> > -   }
> > +   put_user_pages(acd->user_pages, acd->page_count);
> >   err_get_user_pages:
> > kfree(acd->user_pages);
> >   err_alloc_userpages:
> > @@ -229,9 +227,7 @@ void  transfer_complete_cb(struct aio_cb_data *acd, 
> > size_t xfr_count, u32 flags)
> > 
> > dma_unmap_sg(>ldev->pldev->dev, acd->sgt.sgl, acd->sgt.nents, 
> > acd->ldev->dir);
> > 
> > -   for (i = 0 ; i < acd->page_count ; i++){
> > -   put_page(acd->user_pages[i]);
> > -   }
> > +   put_user_pages(acd->user_pages, acd->page_count);
> > 
> > sg_free_table(>sgt);
> > 
> > 
> 
> Because this is a common pattern, and because the code here doesn't likely 
> need to set page dirty before the dma_unmap_sg call, I think the following 
> would be better (it's untested), instead of the above diff hunk:
>
> diff --git a/drivers/staging/kpc2000/kpc_dma/fileops.c 
> b/drivers/staging/kpc2000/kpc_dma/fileops.c
> index 48ca88bc6b0b..d486f9866449 100644
> --- a/drivers/staging/kpc2000/kpc_dma/fileops.c
> +++ b/drivers/staging/kpc2000/kpc_dma/fileops.c
> @@ -211,16 +211,13 @@ void  transfer_complete_cb(struct aio_cb_data *acd, 
> size_t xfr_count, u32 flags)
> BUG_ON(acd->ldev == NULL);
> BUG_ON(acd->ldev->pldev == NULL);
>  
> -   for (i = 0 ; i < acd->page_count ; i++) {
> -   if (!PageReserved(acd->user_pages[i])) {
> -   set_page_dirty(acd->user_pages[i]);
> -   }
> -   }
> -
> dma_unmap_sg(>ldev->pldev->dev, acd->sgt.sgl, acd->sgt.nents, 
> acd->ldev->dir);
>  
> for (i = 0 ; i < acd->page_count ; i++) {
> -   put_page(acd->user_pages[i]);
> +   if (!PageReserved(acd->user_pages[i])) {
> +   put_user_pages_dirty(>user_pages[i], 1);
> +   else
> +   put_user_page(acd->user_pages[i]);
> }
>  
> sg_free_table(>sgt);
I had my doubts on this. This definitley needs to be looked at by the
driver author. 
> Assuming that you make those two changes, you can add:
> 
> Reviewed-by: John Hubbard 
Great!
> 
> thanks,
> -- 
> John Hubbard
> NVIDIA


Re: [PATCH v9 03/18] kunit: test: add string_stream a std::stream like string builder

2019-07-15 Thread Stephen Boyd
Quoting Brendan Higgins (2019-07-12 01:17:29)
> diff --git a/include/kunit/string-stream.h b/include/kunit/string-stream.h
> new file mode 100644
> index 0..0552a05781afe
> --- /dev/null
> +++ b/include/kunit/string-stream.h
> @@ -0,0 +1,49 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * C++ stream style string builder used in KUnit for building messages.
> + *
> + * Copyright (C) 2019, Google LLC.
> + * Author: Brendan Higgins 
> + */
> +
> +#ifndef _KUNIT_STRING_STREAM_H
> +#define _KUNIT_STRING_STREAM_H
> +
> +#include 
> +#include 
> +#include 

What is this include for? I'd expect to see linux/list.h instead.

> +#include 
> +
> +struct string_stream_fragment {
> +   struct list_head node;
> +   char *fragment;
> +};
> +
> +struct string_stream {
> +   size_t length;
> +   struct list_head fragments;
> +   /* length and fragments are protected by this lock */
> +   spinlock_t lock;
> +};
> +
> diff --git a/kunit/string-stream.c b/kunit/string-stream.c
> new file mode 100644
> index 0..0463a92dad74b
> --- /dev/null
> +++ b/kunit/string-stream.c
> @@ -0,0 +1,147 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * C++ stream style string builder used in KUnit for building messages.
> + *
> + * Copyright (C) 2019, Google LLC.
> + * Author: Brendan Higgins 
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +int string_stream_vadd(struct string_stream *stream,
> +  const char *fmt,
> +  va_list args)
> +{
> +   struct string_stream_fragment *frag_container;
> +   int len;
> +   va_list args_for_counting;
> +   unsigned long flags;
> +
> +   /* Make a copy because `vsnprintf` could change it */
> +   va_copy(args_for_counting, args);
> +
> +   /* Need space for null byte. */
> +   len = vsnprintf(NULL, 0, fmt, args_for_counting) + 1;
> +
> +   va_end(args_for_counting);
> +
> +   frag_container = kmalloc(sizeof(*frag_container), GFP_KERNEL);

This is confusing in that it allocates with GFP_KERNEL but then grabs a
spinlock to add and remove from the fragment list. Is it ever going to
be called from a place where it can't sleep? If so, the GFP_KERNEL needs
to be changed. Otherwise, maybe a mutex would work better to protect
access to the fragment list.

I also wonder if it would be better to just have a big slop buffer of a
4K page or something so that we almost never have to allocate anything
with a string_stream and we can just rely on a reader consuming data
while writers are writing. That might work out better, but I don't quite
understand the use case for the string stream.

> +   if (!frag_container)
> +   return -ENOMEM;
> +
> +   frag_container->fragment = kmalloc(len, GFP_KERNEL);
> +   if (!frag_container->fragment) {
> +   kfree(frag_container);
> +   return -ENOMEM;
> +   }
> +
> +   len = vsnprintf(frag_container->fragment, len, fmt, args);
> +   spin_lock_irqsave(>lock, flags);
> +   stream->length += len;
> +   list_add_tail(_container->node, >fragments);
> +   spin_unlock_irqrestore(>lock, flags);
> +
> +   return 0;
> +}
> +
[...]
> +
> +bool string_stream_is_empty(struct string_stream *stream)
> +{
> +   bool is_empty;
> +   unsigned long flags;
> +
> +   spin_lock_irqsave(>lock, flags);

I'm not sure what benefit grabbing the lock is having here. If the list
isn't empty after this is called then the race isn't resolved by
grabbing and releasing the lock. The function is returning stale data in
that case.

> +   is_empty = list_empty(>fragments);
> +   spin_unlock_irqrestore(>lock, flags);
> +
> +   return is_empty;
> +}
> +
> +static int string_stream_init(struct kunit_resource *res, void *context)
> +{
> +   struct string_stream *stream;
> +
> +   stream = kzalloc(sizeof(*stream), GFP_KERNEL);
> +   if (!stream)
> +   return -ENOMEM;
> +
> +   res->allocation = stream;
> +   INIT_LIST_HEAD(>fragments);
> +   spin_lock_init(>lock);
> +
> +   return 0;
> +}
> +
> +static void string_stream_free(struct kunit_resource *res)
> +{
> +   struct string_stream *stream = res->allocation;
> +
> +   string_stream_clear(stream);
> +   kfree(stream);
> +}
> +
> +struct string_stream *alloc_string_stream(struct kunit *test)
> +{
> +   struct kunit_resource *res;
> +
> +   res = kunit_alloc_resource(test,
> +  string_stream_init,
> +  string_stream_free,
> +  NULL);
> +
> +   if (!res)
> +   return NULL;
> +
> +   return res->allocation;

Maybe kunit_alloc_resource() should just return res->allocation, or
NULL, so that these functions can be simplified to 'return
kunit_alloc_resource()'? Does the caller ever care to do anything with
struct kunit_resource anyway?



Re: [PATCH v2 2/2] leds: Add control of the voltage/current regulator to the LED core

2019-07-15 Thread Jacek Anaszewski
Hi Jean,

Thank you for the patch.

I have one issue. Please refer below.

On 7/15/19 5:56 PM, Jean-Jacques Hiblot wrote:
> A LED is usually powered by a voltage/current regulator. Let the LED core
> know about it. This allows the LED core to turn on or off the power supply
> as needed.
> 
> Signed-off-by: Jean-Jacques Hiblot 
> ---
>  drivers/leds/led-class.c | 15 
>  drivers/leds/led-core.c  | 50 +---
>  drivers/leds/leds.h  |  1 +
>  include/linux/leds.h |  4 
>  4 files changed, 67 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
> index 4793e77808e2..cadd43c30d50 100644
> --- a/drivers/leds/led-class.c
> +++ b/drivers/leds/led-class.c
> @@ -253,6 +253,7 @@ int of_led_classdev_register(struct device *parent, 
> struct device_node *np,
>  {
>   char name[LED_MAX_NAME_SIZE];
>   int ret;
> + struct regulator *regulator;
>  
>   ret = led_classdev_next_name(led_cdev->name, name, sizeof(name));
>   if (ret < 0)
> @@ -272,6 +273,20 @@ int of_led_classdev_register(struct device *parent, 
> struct device_node *np,
>   dev_warn(parent, "Led %s renamed to %s due to name collision",
>   led_cdev->name, dev_name(led_cdev->dev));
>  
> + regulator = devm_regulator_get_optional(led_cdev->dev, "power");
> + if (IS_ERR(regulator)) {
> + if (PTR_ERR(regulator) != -ENODEV) {
> + dev_err(led_cdev->dev, "Cannot get the power supply for 
> %s\n",
> + led_cdev->name);
> + device_unregister(led_cdev->dev);
> + mutex_unlock(_cdev->led_access);
> + return PTR_ERR(regulator);
> + }
> + led_cdev->regulator = NULL;
> + } else {
> + led_cdev->regulator = regulator;
> + }
> +
>   if (led_cdev->flags & LED_BRIGHT_HW_CHANGED) {
>   ret = led_add_brightness_hw_changed(led_cdev);
>   if (ret) {
> diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
> index 7107cd7e87cf..a12b880b0a2f 100644
> --- a/drivers/leds/led-core.c
> +++ b/drivers/leds/led-core.c
> @@ -23,6 +23,33 @@ EXPORT_SYMBOL_GPL(leds_list_lock);
>  LIST_HEAD(leds_list);
>  EXPORT_SYMBOL_GPL(leds_list);
>  
> +static bool __led_need_regulator_update(struct led_classdev *led_cdev,
> + int brightness)
> +{
> + bool new_state = (brightness != LED_OFF);
> +
> + return led_cdev->regulator && led_cdev->regulator_state != new_state;
> +}
> +
> +static int __led_handle_regulator(struct led_classdev *led_cdev,
> + int brightness)
> +{
> + int rc;
> +
> + if (__led_need_regulator_update(led_cdev, brightness)) {
> +
> + if (brightness != LED_OFF)
> + rc = regulator_enable(led_cdev->regulator);
> + else
> + rc = regulator_disable(led_cdev->regulator);
> + if (rc)
> + return rc;
> +
> + led_cdev->regulator_state = (brightness != LED_OFF);
> + }
> + return 0;
> +}
> +
>  static int __led_set_brightness(struct led_classdev *led_cdev,
>   enum led_brightness value)
>  {
> @@ -80,6 +107,7 @@ static void led_timer_function(struct timer_list *t)
>   }
>  
>   led_set_brightness_nosleep(led_cdev, brightness);
> + __led_handle_regulator(led_cdev, brightness);

This cannot be called from atomic context since regulator_enable/disable
use mutex beneath, that can sleep on contention. Therefore this call
has to be made in two places instead:

__led_set_brightness()
__led_set_brightness_blocking()

>  
>   /* Return in next iteration if led is in one-shot mode and we are in
>* the final blink state so that the led is toggled each delay_on +
> @@ -115,6 +143,8 @@ static void set_brightness_delayed(struct work_struct *ws)
>   if (ret == -ENOTSUPP)
>   ret = __led_set_brightness_blocking(led_cdev,
>   led_cdev->delayed_set_value);
> + __led_handle_regulator(led_cdev, led_cdev->delayed_set_value);
> +
>   if (ret < 0 &&
>   /* LED HW might have been unplugged, therefore don't warn */
>   !(ret == -ENODEV && (led_cdev->flags & LED_UNREGISTERING) &&
> @@ -141,6 +171,7 @@ static void led_set_software_blink(struct led_classdev 
> *led_cdev,
>   /* never on - just set to off */
>   if (!delay_on) {
>   led_set_brightness_nosleep(led_cdev, LED_OFF);
> + __led_handle_regulator(led_cdev, LED_OFF);
>   return;
>   }
>  
> @@ -148,6 +179,7 @@ static void led_set_software_blink(struct led_classdev 
> *led_cdev,
>   if (!delay_off) {
>   led_set_brightness_nosleep(led_cdev,
>  led_cdev->blink_brightness);
> + 

Re: PROBLEM: Marvell 88E8040 (sky2) fails after hibernation

2019-07-15 Thread Stephen Hemminger
On Mon, 15 Jul 2019 21:09:44 +0200 (CEST)
Thomas Gleixner  wrote:

> Octavio,
> 
> On Mon, 15 Jul 2019, Octavio Alvarez wrote:
> > If I reboot with sky2.disable_msi=1, then I get IO-APIC and the bug does not
> > occur:
> > 
> >  19:  0  0  0  0   IO-APIC  19-fasteoi eth0
> > 
> > However, if I reboot without sky2.disable_msi=1 it properly starts as 
> > PCI-MSI
> > and then, after re-modprobing it it goes to IO-APIC, but the bug occurs
> > anyway:
> > 
> > $ cat /proc/interrupts | grep eth
> >  27:  0  1  0  0   PCI-MSI 3145728-edge
> > eth0
> > 
> > $ sudo modprobe -r sky2
> > [sudo] password for alvarezp:
> > 
> > $ sudo modprobe sky2 disable_msi=1
> > 
> > $ # hibernating and coming back hibernation
> > 
> > $ cat /proc/interrupts | grep eth
> >  19:  0  0  0  0   IO-APIC  19-fasteoi  eth0
> > 
> >   
> > > Also please check Linus suspicion about the module being reloaded after
> > > hibernation through some distro magic.  
> > 
> > This is not happening. Each time the driver is loaded the message "sky2:
> > driver version 1.30" is shown.
> > 
> > I confirm only 1 line for the sky2.disable_msi=1 from kernel boot and only 2
> > lines for re-modprobing.  
> 
> Odd. I still fail to make a connection to that commit you identified
> which merily restores the behaviour before the big changes.
> 
> As we cannot revert that commit by any means and as the hardware is known
> to have issues with MSI, the only option we have is to avoid MSI on that
> particular machine. I suspect that the fact that it is 'working' on some
> older kernel version does not necessarily mean that it works by design. It
> might as well be a works by chance thing.
> 
> Thanks for all the detective work you put into that and sorry that I can't
> come up with the magic cure for this.
> 
> Thanks,
> 
>   tglx

In the past, I had one ASUS motherboard with broken MSI and updating the
BIOS did fix it.


Re: [net-next 1/2] ipvs: batch __ip_vs_cleanup

2019-07-15 Thread Julian Anastasov


Hello,

On Sat, 13 Jul 2019, Haishuang Yan wrote:

> It's better to batch __ip_vs_cleanup to speedup ipvs
> connections dismantle.
> 
> Signed-off-by: Haishuang Yan 
> ---
>  include/net/ip_vs.h |  2 +-
>  net/netfilter/ipvs/ip_vs_core.c | 29 +
>  net/netfilter/ipvs/ip_vs_ctl.c  | 13 ++---
>  3 files changed, 28 insertions(+), 16 deletions(-)
> 
> diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
> index 3759167..93e7a25 100644
> --- a/include/net/ip_vs.h
> +++ b/include/net/ip_vs.h
> @@ -1324,7 +1324,7 @@ static inline void ip_vs_control_del(struct ip_vs_conn 
> *cp)
>  void ip_vs_control_net_cleanup(struct netns_ipvs *ipvs);
>  void ip_vs_estimator_net_cleanup(struct netns_ipvs *ipvs);
>  void ip_vs_sync_net_cleanup(struct netns_ipvs *ipvs);
> -void ip_vs_service_net_cleanup(struct netns_ipvs *ipvs);
> +void ip_vs_service_nets_cleanup(struct list_head *net_list);
>  
>  /* IPVS application functions
>   * (from ip_vs_app.c)
> diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
> index 46f06f9..b4d79b7 100644
> --- a/net/netfilter/ipvs/ip_vs_core.c
> +++ b/net/netfilter/ipvs/ip_vs_core.c
> @@ -2402,18 +2402,23 @@ static int __net_init __ip_vs_init(struct net *net)
>   return -ENOMEM;
>  }
>  
> -static void __net_exit __ip_vs_cleanup(struct net *net)
> +static void __net_exit __ip_vs_cleanup_batch(struct list_head *net_list)
>  {
> - struct netns_ipvs *ipvs = net_ipvs(net);
> -
> - ip_vs_service_net_cleanup(ipvs);/* ip_vs_flush() with locks */
> - ip_vs_conn_net_cleanup(ipvs);
> - ip_vs_app_net_cleanup(ipvs);
> - ip_vs_protocol_net_cleanup(ipvs);
> - ip_vs_control_net_cleanup(ipvs);
> - ip_vs_estimator_net_cleanup(ipvs);
> - IP_VS_DBG(2, "ipvs netns %d released\n", ipvs->gen);
> - net->ipvs = NULL;
> + struct netns_ipvs *ipvs;
> + struct net *net;
> + LIST_HEAD(list);
> +
> + ip_vs_service_nets_cleanup(net_list);   /* ip_vs_flush() with locks */
> + list_for_each_entry(net, net_list, exit_list) {

How much faster is to replace list_for_each_entry in
ops_exit_list() with this one. IPVS can waste time in calls
such as kthread_stop() and del_timer_sync() but I'm not sure
we can solve it easily. What gain do you see in benchmarks?

> + ipvs = net_ipvs(net);
> + ip_vs_conn_net_cleanup(ipvs);
> + ip_vs_app_net_cleanup(ipvs);
> + ip_vs_protocol_net_cleanup(ipvs);
> + ip_vs_control_net_cleanup(ipvs);
> + ip_vs_estimator_net_cleanup(ipvs);
> + IP_VS_DBG(2, "ipvs netns %d released\n", ipvs->gen);
> + net->ipvs = NULL;
> + }
>  }

Regards

--
Julian Anastasov 


Re: [PATCH v3] PM / wakeup: show wakeup sources stats in sysfs

2019-07-15 Thread Greg KH
On Mon, Jul 15, 2019 at 01:11:16PM -0700, Tri Vo wrote:
> Userspace can use wakeup_sources debugfs node to plot history of suspend
> blocking wakeup sources over device's boot cycle. This information can
> then be used (1) for power-specific bug reporting and (2) towards
> attributing battery consumption to specific processes over a period of
> time.
> 
> However, debugfs doesn't have stable ABI. For this reason, create a
> 'struct device' to expose wakeup sources statistics in sysfs under
> /sys/class/wakeup//.
> 
> Introduce CONFIG_PM_SLEEP_STATS that enables/disables showing wakeup
> source statistics in sysfs.
> 
> Suggested-by: Greg Kroah-Hartman 
> Signed-off-by: Tri Vo 
> Tested-by: Tri Vo 

Co-Developed-by: Greg Kroah-Hartman 
perhaps given that I rewrote the whole file last time?  :)


> ---
>  Documentation/ABI/testing/sysfs-power |  73 -
>  drivers/base/power/Makefile   |   1 +
>  drivers/base/power/wakeup.c   |  12 ++-
>  drivers/base/power/wakeup_stats.c | 148 ++
>  include/linux/pm_wakeup.h |  19 
>  kernel/power/Kconfig  |  10 ++
>  kernel/power/wakelock.c   |  10 ++
>  7 files changed, 270 insertions(+), 3 deletions(-)
>  create mode 100644 drivers/base/power/wakeup_stats.c

What changed from v2?  :)

> diff --git a/Documentation/ABI/testing/sysfs-power 
> b/Documentation/ABI/testing/sysfs-power
> index 18b7dc929234..ef92628e6fc3 100644
> --- a/Documentation/ABI/testing/sysfs-power
> +++ b/Documentation/ABI/testing/sysfs-power
> @@ -300,4 +300,75 @@ Description:
>   attempt.
>  
>   Using this sysfs file will override any values that were
> - set using the kernel command line for disk offset.
> \ No newline at end of file
> + set using the kernel command line for disk offset.
> +
> +What:/sys/class/wakeup/

My fault, this should be a new ABI/testing file, don't use sysfs-power
as it does not make any sense now, right?

> --- /dev/null
> +++ b/drivers/base/power/wakeup_stats.c
> @@ -0,0 +1,148 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Wakeup statistics in sysfs
> + *
> + * Copyright (c) 2019 Linux Foundation 

My fault on the original here, this line should be 2 lines:

> + * Copyright (c) 2019 Linux Foundation
> + * Copyright (c) 2019 Greg Kroah-Hartman 

as those are two different entities that have copyright here on this
file.

> +config PM_SLEEP_STATS
> + bool "Wakeup sources statistics"
> + depends on PM_SLEEP
> + help
> +   Expose wakeup sources statistics to user space via sysfs. Collected
> +   statistics are located under /sys/power/wakeup_sources. For more
> +   information, read .

Filename should be changed.


> +
> +   If in doubt, say N.
> +
>  config DPM_WATCHDOG
>   bool "Device suspend/resume watchdog"
>   depends on PM_DEBUG && PSTORE && EXPERT
> diff --git a/kernel/power/wakelock.c b/kernel/power/wakelock.c
> index 4210152e56f0..32726da3d6e6 100644
> --- a/kernel/power/wakelock.c
> +++ b/kernel/power/wakelock.c
> @@ -122,6 +122,7 @@ static void __wakelocks_gc(struct work_struct *work)
>  
>   if (!active) {
>   wakeup_source_remove(>ws);
> + wakeup_source_sysfs_remove(>ws);
>   rb_erase(>node, _tree);
>   list_del(>lru);
>   kfree(wl->name);
> @@ -153,6 +154,7 @@ static struct wakelock *wakelock_lookup_add(const char 
> *name, size_t len,
>   struct rb_node **node = _tree.rb_node;
>   struct rb_node *parent = *node;
>   struct wakelock *wl;
> + int ret;
>  
>   while (*node) {
>   int diff;
> @@ -189,6 +191,14 @@ static struct wakelock *wakelock_lookup_add(const char 
> *name, size_t len,
>   }
>   wl->ws.name = wl->name;
>   wl->ws.last_time = ktime_get();
> +
> + ret = wakeup_source_sysfs_add(>ws);
> + if (ret) {
> + kfree(wl->name);
> + kfree(wl);
> + return ERR_PTR(ret);
> + }
> +
>   wakeup_source_add(>ws);
>   rb_link_node(>node, parent, node);
>   rb_insert_color(>node, _tree);

Nice, you got rid of the extra change in this file, making this much
simpler.

Can you make these minor tweaks?  If so, I'll be glad to queue this up
after 5.3-rc1 is out.

And I am guessing that you actually tested this all out, and it works
for you?  Have you changed Android userspace to use the new api with no
problems?

thanks,

greg k-h


Re: [PATCH] binder: prevent transactions to context manager from its own process.

2019-07-15 Thread Todd Kjos
On Mon, Jul 15, 2019 at 12:18 PM Hridya Valsaraju  wrote:
>
> Currently, a transaction to context manager from its own process
> is prevented by checking if its binder_proc struct is the same as
> that of the sender. However, this would not catch cases where the
> process opens the binder device again and uses the new fd to send
> a transaction to the context manager.
>
> Reported-by: syzbot+8b3c354d33c4ac78b...@syzkaller.appspotmail.com
> Signed-off-by: Hridya Valsaraju 

Acked-by: Todd Kjos 

> ---
>  drivers/android/binder.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/android/binder.c b/drivers/android/binder.c
> index e4d25ebec5be..89b9cedae088 100644
> --- a/drivers/android/binder.c
> +++ b/drivers/android/binder.c
> @@ -3138,7 +3138,7 @@ static void binder_transaction(struct binder_proc *proc,
> else
> return_error = BR_DEAD_REPLY;
> mutex_unlock(>context_mgr_node_lock);
> -   if (target_node && target_proc == proc) {
> +   if (target_node && target_proc->pid == proc->pid) {
> binder_user_error("%d:%d got transaction to 
> context manager from process owning it\n",
>   proc->pid, thread->pid);
> return_error = BR_FAILED_REPLY;
> --
> 2.22.0.510.g264f2c817a-goog
>


Re: [PATCH RESEND] arm64: dts: meson-g12a-sei510: enable IR controller

2019-07-15 Thread Kevin Hilman
Neil Armstrong  writes:

> Enable the IR receiver controller on the SEI510 board.
>
> Signed-off-by: Neil Armstrong 
> ---

Queued for v5.3-rc,

Kevin



<    1   2   3   4   5   6   7   8   9   10   >