Re: [PATCH v2 1/1] irqchip: exynos-combiner: Save IRQ enable set on suspend

2015-06-11 Thread Krzysztof Kozlowski
On 12.06.2015 14:43, Javier Martinez Canillas wrote:
> The Exynos interrupt combiner IP loses its state when the SoC enters
> into a low power state during a Suspend-to-RAM. This means that if a
> IRQ is used as a source, the interrupts for the devices are disabled
> when the system is resumed from a sleep state so are not triggered.
> 
> Save the interrupt enable set register for each combiner group and
> restore it after resume to make sure that the interrupts are enabled.
> 
> Signed-off-by: Javier Martinez Canillas 
> ---
> 
> Hello,
> 
> I noticed this issue because after a S2R, IRQs for some devices didn't
> trigger anymore but others continued working and all of them had lines
> from a GPIO chip as their interrupt source.
> 
> The only difference was that the GPIO pins that were not working after
> a resume, were the ones that had the interrupt combiner as interrupt
> parent.
> 
> With this patch now all perhiperals are working correctly after a resume.
> Tested on an Exynos5250 Snow, Exynos5420 Peach Pit and Exynos5800 Peach Pi
> Chromebooks.
> 
> Best regards,
> Javier
> 
> Changes since v1:
>  - Clear masking bits before of the COMBINER_ENABLE_CLEAR register before
>restore IRQ enable set the Suggested by Chanho Park.
>  - Fixes a typo in the commit message. Suggested by Peter Chubb.

Looks okay,
Reviewed-by: Krzysztof Kozlowski 

Best regards,
Krzysztof
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: iio: what does in_accel_x_thresh_rising_en ?

2015-06-11 Thread Jonathan Cameron


On 11 June 2015 18:34:12 BST, Martin Kepplinger 
 wrote:
>Am 2015-06-10 um 22:49 schrieb Jonathan Cameron:
>> On 09/06/15 17:03, Martin Kepplinger wrote:
>>> hi
>>>
>>> Is the in_accel_thresh_rising_value (or falling) threshold value
>signed
>>> or unsigned?
>>>
>>> In other words: Is a RISING event fired on an absolute growing value
>in
>>> the positive range, and a FALLING event on an absolute growing value
>in
>>> the negative acceleration range (< 0g)?
>>>
>>> Or is a RISING event fired on a signed rising value, no matter if
>the
>>> threshold is positive or negative, and a FALLING event on a
>decreasing
>>> signed value, also when the threshold is positive?
>>>
>>> thanks
>>>
>>> martin
>>>
>> Hi Martin,
>> 
>> The two relevant abi elements are:
>> in_accel_thresh_rising_value and
>> in_accel_mag_rising_value
>> Once you know the second one exists then you can probably work out
>the
>> meaning of thresh ;)
>> 
>> Thresh is the value, mag(nitude) is the absolute value, so if you get
>one
>> that is thresh, then if the channel can go negative, negative values
>are
>> definitely possible.  On an accelerometer, you can get either
>implemented.
>> mag_rising is typically to allow motion detection, thresh_rising
>might
>> be used to detect a change of orientation (put bounds around each
>axis
>> at a particular point in time.
>> 
>> There are also roc (rate of change) type event detectors on some
>accelerometers.
>> 
>> Hope that clear the mud up ;)
>> 
>> Jonathan
>> 
>
>Hi Jonathan,
>
>Oh I overlooked, this is clear now. So
>events/in_accel_x_mag_falling_en for example is
>a classic freefall detection. Would an implementation here just use
>in_accel_mag_falling_value ?
Either that or the one for the particular event (with the x )both are valid 
and
 user space should check for them.
Note some accelerometers use the sum of squares for free fall detection though I
 guess your one doesn't!

 I'm not yet sure how an iio_event_specbit)ould look like in that case. 
Freefall is what I could do in my driver.
Err can't remember exact syntax but you have two entries. One with
 the enable and one with the value part.
Should be other drivers doing this though normally because a single value is 
used
 for multiple separate threshold detectors.
>
>But this was very helpful, thanks for your time!
>
>   martin

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v4 01/11] block: make generic_make_request handle arbitrarily sized bios

2015-06-11 Thread Ming Lin
On Wed, 2015-06-10 at 15:06 -0700, Ming Lin wrote:
> On Wed, Jun 10, 2015 at 2:46 PM, Mike Snitzer  wrote:
> > On Wed, Jun 10 2015 at  5:20pm -0400,
> > Ming Lin  wrote:
> >
> >> On Mon, Jun 8, 2015 at 11:09 PM, Ming Lin  wrote:
> >> > On Thu, 2015-06-04 at 17:06 -0400, Mike Snitzer wrote:
> >> >> We need to test on large HW raid setups like a Netapp filer (or even
> >> >> local SAS drives connected via some SAS controller).  Like a 8+2 drive
> >> >> RAID6 or 8+1 RAID5 setup.  Testing with MD raid on JBOD setups with 8
> >> >> devices is also useful.  It is larger RAID setups that will be more
> >> >> sensitive to IO sizes being properly aligned on RAID stripe and/or chunk
> >> >> size boundaries.
> >> >
> >> > Here are tests results of xfs/ext4/btrfs read/write on HW RAID6/MD 
> >> > RAID6/DM stripe target.
> >> > Each case run 0.5 hour, so it took 36 hours to finish all the tests on 
> >> > 4.1-rc4 and 4.1-rc4-patched kernels.
> >> >
> >> > No performance regressions were introduced.
> >> >
> >> > Test server: Dell R730xd(2 sockets/48 logical cpus/264G memory)
> >> > HW RAID6/MD RAID6/DM stripe target were configured with 10 HDDs, each 
> >> > 280G
> >> > Stripe size 64k and 128k were tested.
> >> >
> >> > devs="/dev/sdb /dev/sdc /dev/sdd /dev/sde /dev/sdf /dev/sdg /dev/sdh 
> >> > /dev/sdi /dev/sdj /dev/sdk"
> >> > spare_devs="/dev/sdl /dev/sdm"
> >> > stripe_size=64 (or 128)
> >> >
> >> > MD RAID6 was created by:
> >> > mdadm --create --verbose /dev/md0 --level=6 --raid-devices=10 $devs 
> >> > --spare-devices=2 $spare_devs -c $stripe_size
> >> >
> >> > DM stripe target was created by:
> >> > pvcreate $devs
> >> > vgcreate striped_vol_group $devs
> >> > lvcreate -i10 -I${stripe_size} -L2T -nstriped_logical_volume 
> >> > striped_vol_group
> >
> > DM had a regression relative to merge_bvec that wasn't fixed until
> > recently (it wasn't in 4.1-rc4), see commit 1c220c69ce0 ("dm: fix
> > casting bug in dm_merge_bvec()").  It was introduced in 4.1.
> >
> > So your 4.1-rc4 DM stripe testing may have effectively been with
> > merge_bvec disabled.
> 
> I'l rebase it to latest Linus tree and re-run DM stripe testing.

Here is the results for 4.1-rc7. Also looks good.

5. DM: stripe size 64k
4.1-rc7 4.1-rc7-patched
--- ---
(MB/s)  (MB/s)
xfs read:   784.0   783.5  -0.06%
xfs write:  751.8   768.8  +2.26%
ext4 read:  837.0   832.3  -0.56%
ext4 write: 806.8   814.3  +0.92%
btrfs read: 787.5   786.1  -0.17%
btrfs write:722.8   718.7  -0.56%


6. DM: stripe size 128k
4.1-rc7 4.1-rc7-patched
--- ---
(MB/s)  (MB/s)
xfs read:   1045.5  1068.8  +2.22%
xfs write:  1058.9  1052.7  -0.58%
ext4 read:  1001.8  1020.7  +1.88%
ext4 write: 1049.9  1053.7  +0.36%
btrfs read: 1082.8  1084.8  +0.18%
btrfs write:948.15  948.74  +0.06%


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] clk: exynos4: Fix wrong clock for Exynos4x12 ADC

2015-06-11 Thread Javier Martinez Canillas
Hello Krzysztof,

On Fri, Jun 12, 2015 at 3:53 AM, Krzysztof Kozlowski
 wrote:
> The TSADC gate clock was used in Exynos4x12 DTSI for exynos-adc driver.
> However TSADC is present only on Exynos4210 so on Trats2 board (with
> Exynos4412 SoC) the exynos-adc driver could not be probed:
>ERROR: could not get clock /adc@126C:adc(0)
>exynos-adc 126c.adc: failed getting clock, err = -2
>exynos-adc: probe of 126c.adc failed with error -2
>
> Instead on Exynos4x12 SoCs the main clock used by Analog to Digital
> Converter is located in different register and it is named in datasheet
> as PCLK_ADC. Regardless of the name the purpose of this PCLK_ADC clock
> is the same as purpose of TSADC from Exynos4210.
>
> The patch adds gate clock for Exynos4x12 using the proper register so
> backward compatibility is preserved. This fixes the probe of exynos-adc
> driver on Exynos4x12 boards and allows accessing sensors connected to it
> on Trats2 board (ntc,ncp15wb473 AP and battery thermistors).
>
> Signed-off-by: Krzysztof Kozlowski 
> Cc: 
> Fixes: c63c57433003 ("ARM: dts: Add ADC's dt data to read raw data for 
> exynos4x12")
> Link: https://lkml.org/lkml/2015/6/11/85
>
> ---
>
> Changes since v1:
> 1. After discussion on LKML this solution was chosen because it smaller,
>simpler, self-contained (one patch to fix issue) and maintains backward
>compatibility. Thanks to Javier Martinez Canillas and Tomasz Figa for
>valuable comments.
> 2. Dropped patch 2/2 because now it is not needed. The clock id "TSADC"
>will be used on all Exynos4 boards.
> 3. Added CC-stable.
> ---
>  drivers/clk/samsung/clk-exynos4.c | 2 ++
>  1 file changed, 2 insertions(+)
>

Patch looks good to me.

Reviewed-by: Javier Martinez Canillas 

Best regards,
Javier
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v7 14/37] bpf tools: Add bpf.c/h for common bpf operations

2015-06-11 Thread Wang Nan
This patch introduces bpf.c and bpf.h, which hold common functions
issuing bpf syscall. The goal of these two files is to hide syscall
completly from user.  Note that bpf.c and bpf.h only deal with kernel
interface. Things like structure of 'map' section in the ELF object is
not cared by of bpf.[ch].

We first introduce bpf_create_map().

Note that, since functions in bpf.[ch] are wrapper of sys_bpf, they
don't use OO style naming.

Signed-off-by: Wang Nan 
Acked-by: Alexei Starovoitov 
---
 tools/lib/bpf/Build |  2 +-
 tools/lib/bpf/bpf.c | 50 ++
 tools/lib/bpf/bpf.h | 16 
 3 files changed, 67 insertions(+), 1 deletion(-)
 create mode 100644 tools/lib/bpf/bpf.c
 create mode 100644 tools/lib/bpf/bpf.h

diff --git a/tools/lib/bpf/Build b/tools/lib/bpf/Build
index a316484..d874975 100644
--- a/tools/lib/bpf/Build
+++ b/tools/lib/bpf/Build
@@ -1 +1 @@
-libbpf-y := libbpf.o
+libbpf-y := libbpf.o bpf.o
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
new file mode 100644
index 000..e424418
--- /dev/null
+++ b/tools/lib/bpf/bpf.c
@@ -0,0 +1,50 @@
+/*
+ * common eBPF ELF operations.
+ *
+ * Copyright (C) 2013-2015 Alexei Starovoitov 
+ * Copyright (C) 2015 Wang Nan 
+ * Copyright (C) 2015 Huawei Inc.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "bpf.h"
+
+/*
+ * When building perf, unistd.h is override. Define __NR_bpf is
+ * required to be defined.
+ */
+#ifndef __NR_bpf
+# if defined(__i386__)
+#  define __NR_bpf 357
+# elif defined(__x86_64__)
+#  define __NR_bpf 321
+# elif defined(__aarch64__)
+#  define __NR_bpf 280
+# else
+#  error __NR_bpf not defined. libbpf does not support your arch.
+# endif
+#endif
+
+static int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr,
+  unsigned int size)
+{
+   return syscall(__NR_bpf, cmd, attr, size);
+}
+
+int bpf_create_map(enum bpf_map_type map_type, int key_size,
+  int value_size, int max_entries)
+{
+   union bpf_attr attr;
+   memset(, '\0', sizeof(attr));
+
+   attr.map_type = map_type;
+   attr.key_size = key_size;
+   attr.value_size = value_size;
+   attr.max_entries = max_entries;
+
+   return sys_bpf(BPF_MAP_CREATE, , sizeof(attr));
+}
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
new file mode 100644
index 000..28f7942
--- /dev/null
+++ b/tools/lib/bpf/bpf.h
@@ -0,0 +1,16 @@
+/*
+ * common eBPF ELF operations.
+ *
+ * Copyright (C) 2013-2015 Alexei Starovoitov 
+ * Copyright (C) 2015 Wang Nan 
+ * Copyright (C) 2015 Huawei Inc.
+ */
+#ifndef __BPF_BPF_H
+#define __BPF_BPF_H
+
+#include 
+
+int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size,
+  int max_entries);
+
+#endif
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v7 16/37] bpf tools: Relocate eBPF programs

2015-06-11 Thread Wang Nan
If an eBPF program accesses a map, LLVM generates a load instruction
which loads an absolute address into a register, like this:

  ld_64   r1, 
  ...
  call2

That ld_64 instruction will be recorded in relocation section.
To enable the usage of that map, relocation must be done by replacing
the immediate value by real map file descriptor so it can be found by
eBPF map functions.

This patch to the relocation work based on information collected by
patch 'bpf tools: Collect relocation sections from SHT_REL sections'.
For each instruction which needs relocation, it inject corresponding
file descriptor to imm field. As a part of protocol, src_reg is set to
BPF_PSEUDO_MAP_FD to notify kernel this is a map loading instruction.

Signed-off-by: Wang Nan 
Acked-by: Alexei Starovoitov 
---
 tools/lib/bpf/libbpf.c | 51 ++
 1 file changed, 51 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 814721a..dbec69f 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -622,6 +622,55 @@ bpf_object__create_maps(struct bpf_object *obj)
return 0;
 }
 
+static int
+bpf_program__relocate(struct bpf_program *prog, int *map_fds)
+{
+   int i;
+
+   if (!prog || !prog->reloc_desc)
+   return 0;
+
+   for (i = 0; i < prog->nr_reloc; i++) {
+   int insn_idx, map_idx;
+   struct bpf_insn *insns = prog->insns;
+
+   insn_idx = prog->reloc_desc[i].insn_idx;
+   map_idx = prog->reloc_desc[i].map_idx;
+
+   if (insn_idx >= (int)prog->insns_cnt) {
+   pr_warning("relocation out of range: '%s'\n",
+  prog->section_name);
+   return -ERANGE;
+   }
+   insns[insn_idx].src_reg = BPF_PSEUDO_MAP_FD;
+   insns[insn_idx].imm = map_fds[map_idx];
+   }
+
+   zfree(>reloc_desc);
+   prog->nr_reloc = 0;
+   return 0;
+}
+
+
+static int
+bpf_object__relocate(struct bpf_object *obj)
+{
+   struct bpf_program *prog;
+   size_t i;
+   int err;
+
+   for (i = 0; i < obj->nr_programs; i++) {
+   prog = >programs[i];
+
+   if ((err = bpf_program__relocate(prog, obj->map_fds))) {
+   pr_warning("failed to relocate '%s'\n",
+  prog->section_name);
+   return err;
+   }
+   }
+   return 0;
+}
+
 static int bpf_object__collect_reloc(struct bpf_object *obj)
 {
int i, err;
@@ -753,6 +802,8 @@ int bpf_object__load(struct bpf_object *obj)
obj->loaded = true;
if (bpf_object__create_maps(obj))
goto out;
+   if (bpf_object__relocate(obj))
+   goto out;
 
return 0;
 out:
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v7 11/37] bpf tools: Collect eBPF programs from their own sections

2015-06-11 Thread Wang Nan
This patch collects all programs in an object file into an array of
'struct bpf_program' for further processing. That structure is for
representing each eBPF program. 'bpf_prog' should be a better name, but
it has been used by linux/filter.h. Although it is a kernel space name,
I still prefer to call it 'bpf_program' to prevent possible confusion.

Signed-off-by: Wang Nan 
Acked-by: Alexei Starovoitov 
---
 tools/lib/bpf/libbpf.c | 107 +
 1 file changed, 107 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 77ad7d3..91b2490 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -78,12 +78,27 @@ void libbpf_set_print(libbpf_print_fn_t warn,
 # define LIBBPF_ELF_C_READ_MMAP ELF_C_READ
 #endif
 
+/*
+ * bpf_prog should be a better name but it has been used in
+ * linux/filter.h.
+ */
+struct bpf_program {
+   /* Index in elf obj file, for relocation use. */
+   int idx;
+   char *section_name;
+   struct bpf_insn *insns;
+   size_t insns_cnt;
+};
+
 struct bpf_object {
char license[64];
u32 kern_version;
void *maps_buf;
size_t maps_buf_sz;
 
+   struct bpf_program *programs;
+   size_t nr_programs;
+
/*
 * Information when doing elf related work. Only valid if fd
 * is valid.
@@ -100,6 +115,74 @@ struct bpf_object {
 };
 #define obj_elf_valid(o)   ((o)->efile.elf)
 
+static void bpf_program__clear(struct bpf_program *prog)
+{
+   if (!prog)
+   return;
+
+   zfree(>section_name);
+   zfree(>insns);
+   prog->insns_cnt = 0;
+   prog->idx = -1;
+}
+
+static struct bpf_program *
+bpf_program__new(struct bpf_object *obj, void *data, size_t size,
+char *name, int idx)
+{
+   struct bpf_program *prog, *progs;
+   int nr_progs;
+
+   if (size < sizeof(struct bpf_insn)) {
+   pr_warning("corrupted section '%s'\n", name);
+   return NULL;
+   }
+
+   progs = obj->programs;
+   nr_progs = obj->nr_programs;
+
+   progs = realloc(progs, sizeof(*prog) * (nr_progs + 1));
+   if (!progs) {
+   /*
+* In this case the original obj->programs
+* is still valid, so don't need special treat for
+* bpf_close_object().
+*/
+   pr_warning("failed to alloc a new program '%s'\n",
+  name);
+   return NULL;
+   }
+
+   obj->programs = progs;
+
+   prog = [nr_progs];
+   bzero(prog, sizeof(*prog));
+
+   obj->nr_programs = nr_progs + 1;
+
+   prog->section_name = strdup(name);
+   if (!prog->section_name) {
+   pr_warning("failed to alloc name for prog %s\n",
+  name);
+   goto out;
+   }
+
+   prog->insns = malloc(size);
+   if (!prog->insns) {
+   pr_warning("failed to alloc insns for %s\n", name);
+   goto out;
+   }
+   prog->insns_cnt = size / sizeof(struct bpf_insn);
+   memcpy(prog->insns, data,
+  prog->insns_cnt * sizeof(struct bpf_insn));
+   prog->idx = idx;
+
+   return prog;
+out:
+   bpf_program__clear(prog);
+   return NULL;
+}
+
 static struct bpf_object *bpf_object__new(const char *path,
  void *obj_buf,
  size_t obj_buf_sz)
@@ -341,6 +424,21 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
err = -EEXIST;
} else
obj->efile.symbols = data;
+   } else if ((sh.sh_type == SHT_PROGBITS) &&
+  (sh.sh_flags & SHF_EXECINSTR) &&
+  (data->d_size > 0)) {
+   struct bpf_program *prog;
+
+   prog = bpf_program__new(obj, data->d_buf,
+   data->d_size, name,
+   idx);
+   if (!prog) {
+   pr_warning("failed to alloc program %s (%s)",
+  name, obj->path);
+   err = -ENOMEM;
+   } else
+   pr_debug("found program %s\n",
+prog->section_name);
}
if (err)
goto out;
@@ -414,11 +512,20 @@ struct bpf_object *bpf_object__open_buffer(void *obj_buf,
 
 void bpf_object__close(struct bpf_object *obj)
 {
+   size_t i;
+
if (!obj)
return;
 
bpf_object__elf_finish(obj);
 
zfree(>maps_buf);
+
+   if (obj->programs && obj->nr_programs) {
+   for (i = 0; i < obj->nr_programs; i++)
+   

[RFC PATCH v7 15/37] bpf tools: Create eBPF maps defined in an object file

2015-06-11 Thread Wang Nan
This patch creates maps based on 'map' section in object file using
bpf_create_map(), and stores the fds into an array in
'struct bpf_object'.

Previous patches parse ELF object file and collecte required data, but
doesn't play with kernel. They belong to 'opening' phase. This patch is
the first patch in 'loading' phase. 'loaded' field is introduced to
'struct bpf_object' to avoid loading one object twice, because loading
phase clears resources collected during opening which become useless
after loading. In this patch, maps_buf is cleared.

Signed-off-by: Wang Nan 
Acked-by: Alexei Starovoitov 
---
 tools/lib/bpf/libbpf.c | 102 +
 tools/lib/bpf/libbpf.h |   4 ++
 2 files changed, 106 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 4ab0ce2..814721a 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -21,6 +21,7 @@
 #include 
 
 #include "libbpf.h"
+#include "bpf.h"
 
 #define __printf(a, b) __attribute__((format(printf, a, b)))
 
@@ -105,6 +106,13 @@ struct bpf_object {
 
struct bpf_program *programs;
size_t nr_programs;
+   int *map_fds;
+   /*
+* This field is required because maps_buf will be freed and
+* maps_buf_sz will be set to 0 after loaded.
+*/
+   size_t nr_map_fds;
+   bool loaded;
 
/*
 * Information when doing elf related work. Only valid if fd
@@ -222,6 +230,7 @@ static struct bpf_object *bpf_object__new(const char *path,
obj->efile.obj_buf = obj_buf;
obj->efile.obj_buf_sz = obj_buf_sz;
 
+   obj->loaded = false;
return obj;
 }
 
@@ -557,6 +566,62 @@ bpf_program__collect_reloc(struct bpf_program *prog,
return 0;
 }
 
+static int
+bpf_object__create_maps(struct bpf_object *obj)
+{
+   unsigned int i;
+   size_t nr_maps;
+   int *pfd;
+
+   nr_maps = obj->maps_buf_sz / sizeof(struct bpf_map_def);
+   if (!obj->maps_buf || !nr_maps) {
+   pr_debug("don't need create maps for %s\n",
+obj->path);
+   return 0;
+   }
+
+   obj->map_fds = malloc(sizeof(int) * nr_maps);
+   if (!obj->map_fds) {
+   pr_warning("realloc perf_bpf_map_fds failed\n");
+   return -ENOMEM;
+   }
+   obj->nr_map_fds = nr_maps;
+
+   /* fill all fd with -1 */
+   memset(obj->map_fds, 0xff, sizeof(int) * nr_maps);
+
+   pfd = obj->map_fds;
+   for (i = 0; i < nr_maps; i++) {
+   struct bpf_map_def def;
+
+   def = *(struct bpf_map_def *)(obj->maps_buf +
+   i * sizeof(struct bpf_map_def));
+
+   *pfd = bpf_create_map(def.type,
+ def.key_size,
+ def.value_size,
+ def.max_entries);
+   if (*pfd < 0) {
+   size_t j;
+   int err = *pfd;
+
+   pr_warning("failed to create map: %s\n",
+  strerror(errno));
+   for (j = 0; j < i; j++)
+   zclose(obj->map_fds[j]);
+   obj->nr_map_fds = 0;
+   zfree(>map_fds);
+   return err;
+   }
+   pr_debug("create map: fd=%d\n", *pfd);
+   pfd ++;
+   }
+
+   zfree(>maps_buf);
+   obj->maps_buf_sz = 0;
+   return 0;
+}
+
 static int bpf_object__collect_reloc(struct bpf_object *obj)
 {
int i, err;
@@ -660,6 +725,42 @@ struct bpf_object *bpf_object__open_buffer(void *obj_buf,
return __bpf_object__open("[buffer]", obj_buf, obj_buf_sz);
 }
 
+int bpf_object__unload(struct bpf_object *obj)
+{
+   size_t i;
+
+   if (!obj)
+   return -EINVAL;
+
+   for (i = 0; i < obj->nr_map_fds; i++)
+   zclose(obj->map_fds[i]);
+   zfree(>map_fds);
+   obj->nr_map_fds = 0;
+
+   return 0;
+}
+
+int bpf_object__load(struct bpf_object *obj)
+{
+   if (!obj)
+   return -EINVAL;
+
+   if (obj->loaded) {
+   pr_warning("object should not be loaded twice\n");
+   return -EINVAL;
+   }
+
+   obj->loaded = true;
+   if (bpf_object__create_maps(obj))
+   goto out;
+
+   return 0;
+out:
+   bpf_object__unload(obj);
+   pr_warning("failed to load object '%s'\n", obj->path);
+   return -EINVAL;
+}
+
 void bpf_object__close(struct bpf_object *obj)
 {
size_t i;
@@ -668,6 +769,7 @@ void bpf_object__close(struct bpf_object *obj)
return;
 
bpf_object__elf_finish(obj);
+   bpf_object__unload(obj);
 
zfree(>maps_buf);
 
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 6e75acd..3e69600 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -30,6 +30,10 @@ struct 

[RFC PATCH v7 10/37] bpf tools: Collect symbol table from SHT_SYMTAB section

2015-06-11 Thread Wang Nan
This patch collects symbols section. This section is useful when
linking ELF maps.

Signed-off-by: Wang Nan 
Acked-by: Alexei Starovoitov 
---
 tools/lib/bpf/libbpf.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 3315f00..77ad7d3 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -94,6 +94,7 @@ struct bpf_object {
size_t obj_buf_sz;
Elf *elf;
GElf_Ehdr ehdr;
+   Elf_Data *symbols;
} efile;
char path[];
 };
@@ -135,6 +136,7 @@ static void bpf_object__elf_finish(struct bpf_object *obj)
elf_end(obj->efile.elf);
obj->efile.elf = NULL;
}
+   obj->efile.symbols = NULL;
zclose(obj->efile.fd);
obj->efile.obj_buf = NULL;
obj->efile.obj_buf_sz = 0;
@@ -332,6 +334,14 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
else if (strcmp(name, "maps") == 0)
err = bpf_object__init_maps(obj, data->d_buf,
data->d_size);
+   else if (sh.sh_type == SHT_SYMTAB) {
+   if (obj->efile.symbols) {
+   pr_warning("bpf: multiple SYMTAB in %s\n",
+  obj->path);
+   err = -EEXIST;
+   } else
+   obj->efile.symbols = data;
+   }
if (err)
goto out;
}
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v7 13/37] bpf tools: Record map accessing instructions for each program

2015-06-11 Thread Wang Nan
This patch records the indics of instructions which are needed to be
relocated. Those information are saved in 'reloc_desc' field in
'struct bpf_program'. In loading phase (this patch takes effect in
opening phase), the collected instructions will be replaced by
map loading instructions.

Since we are going to close the ELF file and clear all data at the end
of 'opening' phase, ELF information will no longer be valid in
'loading' phase. We have to locate the instructions before maps are
loaded, instead of directly modifying the instruction.

'struct bpf_map_def' is introduce in this patch to let us know how many
maps defined in the object.

Signed-off-by: Wang Nan 
Acked-by: Alexei Starovoitov 
---
 tools/lib/bpf/libbpf.c | 124 +
 tools/lib/bpf/libbpf.h |  13 ++
 2 files changed, 137 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 2b7f0f4..4ab0ce2 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -88,6 +89,12 @@ struct bpf_program {
char *section_name;
struct bpf_insn *insns;
size_t insns_cnt;
+
+   struct {
+   int insn_idx;
+   int map_idx;
+   } *reloc_desc;
+   int nr_reloc;
 };
 
 struct bpf_object {
@@ -127,6 +134,9 @@ static void bpf_program__clear(struct bpf_program *prog)
 
zfree(>section_name);
zfree(>insns);
+   zfree(>reloc_desc);
+
+   prog->nr_reloc = 0;
prog->insns_cnt = 0;
prog->idx = -1;
 }
@@ -473,6 +483,118 @@ out:
return err;
 }
 
+static struct bpf_program *
+bpf_object__find_prog_by_idx(struct bpf_object *obj, int idx)
+{
+   struct bpf_program *prog;
+   size_t i;
+
+   for (i = 0; i < obj->nr_programs; i++) {
+   prog = >programs[i];
+   if (prog->idx == idx)
+   return prog;
+   }
+   return NULL;
+}
+
+static int
+bpf_program__collect_reloc(struct bpf_program *prog,
+  size_t nr_maps, GElf_Shdr *shdr,
+  Elf_Data *data, Elf_Data *symbols)
+{
+   int i, nrels;
+
+   pr_debug("collecting relocating info for: '%s'\n",
+prog->section_name);
+   nrels = shdr->sh_size / shdr->sh_entsize;
+
+   prog->reloc_desc = malloc(sizeof(*prog->reloc_desc) * nrels);
+   if (!prog->reloc_desc) {
+   pr_warning("failed to alloc memory in relocation\n");
+   return -ENOMEM;
+   }
+   prog->nr_reloc = nrels;
+
+   for (i = 0; i < nrels; i++) {
+   GElf_Sym sym;
+   GElf_Rel rel;
+   unsigned int insn_idx;
+   struct bpf_insn *insns = prog->insns;
+   size_t map_idx;
+
+   if (!gelf_getrel(data, i, )) {
+   pr_warning("relocation: failed to get %d reloc\n", i);
+   return -EINVAL;
+   }
+
+   insn_idx = rel.r_offset / sizeof(struct bpf_insn);
+   pr_debug("relocation: insn_idx=%u\n", insn_idx);
+
+   if (!gelf_getsym(symbols,
+GELF_R_SYM(rel.r_info),
+)) {
+   pr_warning("relocation: symbol %"PRIx64" not found\n",
+  GELF_R_SYM(rel.r_info));
+   return -EINVAL;
+   }
+
+   if (insns[insn_idx].code != (BPF_LD | BPF_IMM | BPF_DW)) {
+   pr_warning("bpf: relocation: invalid relo for 
insns[%d].code 0x%x\n",
+  insn_idx, insns[insn_idx].code);
+   return -EINVAL;
+   }
+
+   map_idx = sym.st_value / sizeof(struct bpf_map_def);
+   if (map_idx >= nr_maps) {
+   pr_warning("bpf relocation: map_idx %d large than %d\n",
+  (int)map_idx, (int)nr_maps - 1);
+   return -EINVAL;
+   }
+
+   prog->reloc_desc[i].insn_idx = insn_idx;
+   prog->reloc_desc[i].map_idx = map_idx;
+   }
+   return 0;
+}
+
+static int bpf_object__collect_reloc(struct bpf_object *obj)
+{
+   int i, err;
+
+   if (!obj_elf_valid(obj)) {
+   pr_warning("Internal error: elf object is closed\n");
+   return -EINVAL;
+   }
+
+   for (i = 0; i < obj->efile.nr_reloc; i++) {
+   GElf_Shdr *shdr = >efile.reloc[i].shdr;
+   Elf_Data *data = obj->efile.reloc[i].data;
+   int idx = shdr->sh_info;
+   struct bpf_program *prog;
+   size_t nr_maps = obj->maps_buf_sz /
+sizeof(struct bpf_map_def);
+
+   if (shdr->sh_type != SHT_REL) {
+   pr_warning("internal error at %d\n", 

[RFC PATCH v7 12/37] bpf tools: Collect relocation sections from SHT_REL sections

2015-06-11 Thread Wang Nan
This patch collects relocation sections into 'struct object'.
Such sections are used for connecting maps to bpf programs.
'reloc' field in 'struct bpf_object' is introduced for storing
such informations.

This patch simply store the data into 'reloc' field. Following
patch will parse them to know the exact instructions which are
needed to be relocated.

Note that the collected data will be invalid after ELF object file
is closed.

Signed-off-by: Wang Nan 
Acked-by: Alexei Starovoitov 
---
 tools/lib/bpf/libbpf.c | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 91b2490..2b7f0f4 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -110,6 +110,11 @@ struct bpf_object {
Elf *elf;
GElf_Ehdr ehdr;
Elf_Data *symbols;
+   struct {
+   GElf_Shdr shdr;
+   Elf_Data *data;
+   } *reloc;
+   int nr_reloc;
} efile;
char path[];
 };
@@ -220,6 +225,9 @@ static void bpf_object__elf_finish(struct bpf_object *obj)
obj->efile.elf = NULL;
}
obj->efile.symbols = NULL;
+
+   zfree(>efile.reloc);
+   obj->efile.nr_reloc = 0;
zclose(obj->efile.fd);
obj->efile.obj_buf = NULL;
obj->efile.obj_buf_sz = 0;
@@ -439,6 +447,24 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
} else
pr_debug("found program %s\n",
 prog->section_name);
+   } else if (sh.sh_type == SHT_REL) {
+   void *reloc = obj->efile.reloc;
+   int nr_reloc = obj->efile.nr_reloc;
+
+   reloc = realloc(reloc,
+   sizeof(*obj->efile.reloc) * 
(++nr_reloc));
+   if (!reloc) {
+   pr_warning("realloc failed\n");
+   err = -ENOMEM;
+   } else {
+   int n = nr_reloc - 1;
+
+   obj->efile.reloc = reloc;
+   obj->efile.nr_reloc = nr_reloc;
+
+   obj->efile.reloc[n].shdr = sh;
+   obj->efile.reloc[n].data = data;
+   }
}
if (err)
goto out;
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v7 17/37] bpf tools: Introduce bpf_load_program() to bpf.c

2015-06-11 Thread Wang Nan
bpf_load_program() can be used to load bpf program into kernel. To make
loading faster, first try to load without logbuf. Try again with logbuf
if the first try failed.

Signed-off-by: Wang Nan 
Acked-by: Alexei Starovoitov 
---
 tools/lib/bpf/bpf.c | 34 ++
 tools/lib/bpf/bpf.h |  7 +++
 2 files changed, 41 insertions(+)

diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index e424418..6f7f883 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -29,6 +29,11 @@
 # endif
 #endif
 
+static __u64 ptr_to_u64(void *ptr)
+{
+   return (__u64) (unsigned long) ptr;
+}
+
 static int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr,
   unsigned int size)
 {
@@ -48,3 +53,32 @@ int bpf_create_map(enum bpf_map_type map_type, int key_size,
 
return sys_bpf(BPF_MAP_CREATE, , sizeof(attr));
 }
+
+int bpf_load_program(enum bpf_prog_type type, struct bpf_insn *insns,
+size_t insns_cnt, char *license,
+u32 kern_version, char *log_buf, size_t log_buf_sz)
+{
+   int fd;
+   union bpf_attr attr;
+
+   bzero(, sizeof(attr));
+   attr.prog_type = type;
+   attr.insn_cnt = (__u32)insns_cnt;
+   attr.insns = ptr_to_u64(insns);
+   attr.license = ptr_to_u64(license);
+   attr.log_buf = ptr_to_u64(NULL);
+   attr.log_size = 0;
+   attr.log_level = 0;
+   attr.kern_version = kern_version;
+
+   fd = sys_bpf(BPF_PROG_LOAD, , sizeof(attr));
+   if (fd >= 0 || !log_buf || !log_buf_sz)
+   return fd;
+
+   /* Try again with log */
+   attr.log_buf = ptr_to_u64(log_buf);
+   attr.log_size = log_buf_sz;
+   attr.log_level = 1;
+   log_buf[0] = 0;
+   return sys_bpf(BPF_PROG_LOAD, , sizeof(attr));
+}
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index 28f7942..854b736 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -13,4 +13,11 @@
 int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size,
   int max_entries);
 
+/* Recommend log buffer size */
+#define BPF_LOG_BUF_SIZE 65536
+int bpf_load_program(enum bpf_prog_type type, struct bpf_insn *insns,
+size_t insns_cnt, char *license,
+u32 kern_version, char *log_buf,
+size_t log_buf_sz);
+
 #endif
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v7 19/37] bpf tools: Introduce accessors for struct bpf_program

2015-06-11 Thread Wang Nan
This patch introduces accessors for user of libbpf to retrive section
name and fd of a opened/loaded eBPF program. 'struct bpf_prog_handler'
is used for that purpose. Accessors of programs section name and file
descriptor are provided. Set/get private data are also impelmented.

Signed-off-by: Wang Nan 
Acked-by: Alexei Starovoitov 
---
 tools/lib/bpf/libbpf.c | 82 ++
 tools/lib/bpf/libbpf.h | 25 +++
 2 files changed, 107 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 9b56832..acf9190 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -98,6 +98,10 @@ struct bpf_program {
int nr_reloc;
 
int fd;
+
+   struct bpf_object *obj;
+   void *priv;
+   bpf_program_clear_priv_t clear_priv;
 };
 
 struct bpf_object {
@@ -150,6 +154,12 @@ static void bpf_program__clear(struct bpf_program *prog)
if (!prog)
return;
 
+   if (prog->clear_priv)
+   prog->clear_priv(prog, prog->priv);
+
+   prog->priv = NULL;
+   prog->clear_priv = NULL;
+
bpf_program__unload(prog);
zfree(>section_name);
zfree(>insns);
@@ -211,6 +221,7 @@ bpf_program__new(struct bpf_object *obj, void *data, size_t 
size,
   prog->insns_cnt * sizeof(struct bpf_insn));
prog->idx = idx;
prog->fd = -1;
+   prog->obj = obj;
 
return prog;
 out:
@@ -912,3 +923,74 @@ void bpf_object__close(struct bpf_object *obj)
 
free(obj);
 }
+
+struct bpf_program *
+bpf_program__next(struct bpf_program *prev, struct bpf_object *obj)
+{
+   size_t idx;
+
+   if (!obj->programs)
+   return NULL;
+   /* First handler */
+   if (prev == NULL)
+   return (>programs[0]);
+
+   if (prev->obj != obj) {
+   pr_warning("error: program handler doesn't match object\n");
+   return NULL;
+   }
+
+   idx = (prev - obj->programs) + 1;
+   if (idx >= obj->nr_programs)
+   return NULL;
+   return >programs[idx];
+}
+
+int bpf_program__set_private(struct bpf_program *prog,
+void *priv,
+bpf_program_clear_priv_t clear_priv)
+{
+   if (prog->priv && prog->clear_priv)
+   prog->clear_priv(prog, prog->priv);
+
+   prog->priv = priv;
+   prog->clear_priv = clear_priv;
+   return 0;
+}
+
+int bpf_program__get_private(struct bpf_program *prog, void **ppriv)
+{
+   *ppriv = prog->priv;
+   return 0;
+}
+
+int bpf_program__get_title(struct bpf_program *prog,
+  const char **ptitle, bool dup)
+{
+   const char *title;
+
+   if (!ptitle)
+   return -EINVAL;
+
+   title = prog->section_name;
+   if (dup) {
+   title = strdup(title);
+   if (!title) {
+   pr_warning("failed to strdup program title\n");
+   *ptitle = NULL;
+   return -ENOMEM;
+   }
+   }
+
+   *ptitle = title;
+   return 0;
+}
+
+int bpf_program__get_fd(struct bpf_program *prog, int *pfd)
+{
+   if (!pfd)
+   return -EINVAL;
+
+   *pfd = prog->fd;
+   return 0;
+}
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 3e69600..3c54558 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -9,6 +9,7 @@
 #define __BPF_LIBBPF_H
 
 #include 
+#include 
 
 /*
  * In include/linux/compiler-gcc.h, __printf is defined. However
@@ -34,6 +35,30 @@ void bpf_object__close(struct bpf_object *object);
 int bpf_object__load(struct bpf_object *obj);
 int bpf_object__unload(struct bpf_object *obj);
 
+/* Accessors of bpf_program. */
+struct bpf_program;
+struct bpf_program *bpf_program__next(struct bpf_program *prog,
+ struct bpf_object *obj);
+
+#define bpf_object__for_each_program(pos, obj) \
+   for ((pos) = bpf_program__next(NULL, (obj));\
+(pos) != NULL; \
+(pos) = bpf_program__next((pos), (obj)))
+
+typedef void (*bpf_program_clear_priv_t)(struct bpf_program *,
+void *);
+
+int bpf_program__set_private(struct bpf_program *prog, void *priv,
+bpf_program_clear_priv_t clear_priv);
+
+int bpf_program__get_private(struct bpf_program *prog,
+void **ppriv);
+
+int bpf_program__get_title(struct bpf_program *prog,
+  const char **ptitle, bool dup);
+
+int bpf_program__get_fd(struct bpf_program *prog, int *pfd);
+
 /*
  * We don't need __attribute__((packed)) now since it is
  * unnecessary for 'bpf_map_def' because they are all aligned.
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More 

[PATCH v2 1/1] irqchip: exynos-combiner: Save IRQ enable set on suspend

2015-06-11 Thread Javier Martinez Canillas
The Exynos interrupt combiner IP loses its state when the SoC enters
into a low power state during a Suspend-to-RAM. This means that if a
IRQ is used as a source, the interrupts for the devices are disabled
when the system is resumed from a sleep state so are not triggered.

Save the interrupt enable set register for each combiner group and
restore it after resume to make sure that the interrupts are enabled.

Signed-off-by: Javier Martinez Canillas 
---

Hello,

I noticed this issue because after a S2R, IRQs for some devices didn't
trigger anymore but others continued working and all of them had lines
from a GPIO chip as their interrupt source.

The only difference was that the GPIO pins that were not working after
a resume, were the ones that had the interrupt combiner as interrupt
parent.

With this patch now all perhiperals are working correctly after a resume.
Tested on an Exynos5250 Snow, Exynos5420 Peach Pit and Exynos5800 Peach Pi
Chromebooks.

Best regards,
Javier

Changes since v1:
 - Clear masking bits before of the COMBINER_ENABLE_CLEAR register before
   restore IRQ enable set the Suggested by Chanho Park.
 - Fixes a typo in the commit message. Suggested by Peter Chubb.

 drivers/irqchip/exynos-combiner.c | 64 ---
 1 file changed, 59 insertions(+), 5 deletions(-)

diff --git a/drivers/irqchip/exynos-combiner.c 
b/drivers/irqchip/exynos-combiner.c
index 5945223b73fa..639e59c8eed3 100644
--- a/drivers/irqchip/exynos-combiner.c
+++ b/drivers/irqchip/exynos-combiner.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -34,9 +35,14 @@ struct combiner_chip_data {
unsigned int irq_mask;
void __iomem *base;
unsigned int parent_irq;
+#ifdef CONFIG_PM
+   u32 pm_save;
+#endif
 };
 
+static struct combiner_chip_data *combiner_data;
 static struct irq_domain *combiner_irq_domain;
+static unsigned int max_nr = 20;
 
 static inline void __iomem *combiner_base(struct irq_data *data)
 {
@@ -170,12 +176,10 @@ static struct irq_domain_ops combiner_irq_domain_ops = {
 };
 
 static void __init combiner_init(void __iomem *combiner_base,
-struct device_node *np,
-unsigned int max_nr)
+struct device_node *np)
 {
int i, irq;
unsigned int nr_irq;
-   struct combiner_chip_data *combiner_data;
 
nr_irq = max_nr * IRQ_IN_COMBINER;
 
@@ -201,11 +205,59 @@ static void __init combiner_init(void __iomem 
*combiner_base,
}
 }
 
+#ifdef CONFIG_PM
+
+/**
+ * combiner_suspend - save interrupt combiner state before suspend
+ *
+ * Save the interrupt enable set register for all combiner groups since
+ * the state is lost when the system enters into a sleep state.
+ *
+ */
+static int combiner_suspend(void)
+{
+   int i;
+
+   for (i = 0; i < max_nr; i++)
+   combiner_data[i].pm_save =
+   __raw_readl(combiner_data[i].base + 
COMBINER_ENABLE_SET);
+
+   return 0;
+}
+
+/**
+ * combiner_resume - restore interrupt combiner state after resume
+ *
+ * Restore the interrupt enable set register for all combiner groups since
+ * the state is lost when the system enters into a sleep state on suspend.
+ *
+ */
+static void combiner_resume(void)
+{
+   int i;
+
+   for (i = 0; i < max_nr; i++) {
+   __raw_writel(combiner_data[i].irq_mask,
+combiner_data[i].base + COMBINER_ENABLE_CLEAR);
+   __raw_writel(combiner_data[i].pm_save,
+combiner_data[i].base + COMBINER_ENABLE_SET);
+   }
+}
+
+#else
+#define combiner_suspend   NULL
+#define combiner_resumeNULL
+#endif
+
+static struct syscore_ops combiner_syscore_ops = {
+   .suspend= combiner_suspend,
+   .resume = combiner_resume,
+};
+
 static int __init combiner_of_init(struct device_node *np,
   struct device_node *parent)
 {
void __iomem *combiner_base;
-   unsigned int max_nr = 20;
 
combiner_base = of_iomap(np, 0);
if (!combiner_base) {
@@ -219,7 +271,9 @@ static int __init combiner_of_init(struct device_node *np,
__func__, max_nr);
}
 
-   combiner_init(combiner_base, np, max_nr);
+   combiner_init(combiner_base, np);
+
+   register_syscore_ops(_syscore_ops);
 
return 0;
 }
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v7 20/37] bpf tools: Introduce accessors for struct bpf_object

2015-06-11 Thread Wang Nan
This patch add an accessor which allows caller to get count of programs
in an object file.

Signed-off-by: Wang Nan 
Acked-by: Alexei Starovoitov 
---
 tools/lib/bpf/libbpf.c | 9 +
 tools/lib/bpf/libbpf.h | 3 +++
 2 files changed, 12 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index acf9190..fec1624 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -924,6 +924,15 @@ void bpf_object__close(struct bpf_object *obj)
free(obj);
 }
 
+int bpf_object__get_prog_cnt(struct bpf_object *obj, size_t *pcnt)
+{
+   if (!obj || !pcnt)
+   return -EINVAL;
+
+   *pcnt = obj->nr_programs;
+   return 0;
+}
+
 struct bpf_program *
 bpf_program__next(struct bpf_program *prev, struct bpf_object *obj)
 {
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 3c54558..d11664b 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -35,6 +35,9 @@ void bpf_object__close(struct bpf_object *object);
 int bpf_object__load(struct bpf_object *obj);
 int bpf_object__unload(struct bpf_object *obj);
 
+/* Accessors of bpf_object */
+int bpf_object__get_prog_cnt(struct bpf_object *obj, size_t *pcnt);
+
 /* Accessors of bpf_program. */
 struct bpf_program;
 struct bpf_program *bpf_program__next(struct bpf_program *prog,
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v7 00/37] perf tools: filtering events using eBPF programs

2015-06-11 Thread Wang Nan
This is the 7th version which tries to introduce eBPF programs to perf.
It enables 'perf record' to filter events using eBPF programs like:

 # perf record --event bpf-file.c sleep 1

and

 # perf record --event bpf-file.o sleep 1

This patch series is based on tip/perf/core (028c63b).

Compare with v6 patch, this series totally refactor code for llvm
compiling '.c' into BPF object file using LLVM. Including:

 1. A specific file tools/perf/util/llvm-utils.c is introduced for
holding all llvm/clang related work, instead of putting them into
bpf-loader.c.

 2. Automatically detect kernel include options by embedded shell
script.

 3. Use command line template to generate compiler commands instead of
assemble cmdline with printf, passing variables using environment.
Which enable users to define their own compiler commands.

 4. Introduce '[llvm]' section to perf default config.
5 options can be configured, but all of them can be omitted:

  [llvm]
# Path to clang. If omit, search it from $PATH.
clang-path = "/path/to/clang"

# Cmdline template. Following line shows its default value.
# Environment variable is used to passing options.
clang-bpf-cmd-template = "$CLANG_EXEC $CLANG_OPTIONS 
$KERNEL_INC_OPTIONS -Wno-unused-value -Wno-pointer-sign -working-directory 
$WORKING_DIR  -c $CLANG_SOURCE -target bpf -O2 -o -"

# Option passed to clang, will be passed to cmdline by $CLANG_OPTIONS.
clang-opt = "-Wno-unused-value -Wno-pointer-sign"

# kbuild directory. If not set, use /lib/modules/`uname -r`/build.
# If set to "" deliberately, skip kernel header auto-detector.
kbuild-dir = "/path/to/kernel/build"

# Options passed to 'make' when detecting kernel header options.
kbuild-opts = "ARCH=x86_64"

Command line options '--clang-path' and '--clang-opt' is appended to
'perf record'.

 5. LLVM and BPF opening testcase is adding into 'perf test':

# perf test  37
37: Test LLVM searching and compiling: Ok

 6. Warning and error messages improvement.

 7. Issue clang command suit for newest clang which support
'-target bpf', instead of calling
'clang -emit-llvm | llc -march=bpf' pipe.

Other improvements including:

 1. Add ../lib/bpf into TAG_FOLDERS in tools/perf/Makefile.perf.
 2. Fix dependency problem: when NO_LIBBPF=1 is set don't compile
libbpf.
 3. Suppress misleading messages printed during probing.
 4. In perf record, when bpf__probe failed, goto out_symbol_exit instead
of directly return.

In this series:
  Patch 1/37 adds a feature check to check version of eBPF API.

  Patch 2/37 - 21/37 introduce libbpf, which first parse eBPF object
  files then load maps and programs into kernel. These patches are
  already received 'Acked-by' from Alexei Starovoitov except patch
  5/32, which enables opening a memory-based object file image using
  bpf_object__open_buffer().

  Patch 22/37 - 37/37 are perf related. Patch 23/37 - 27/37 are
  llvm-utils, which does most of new stuffs in this series.
  Patch 29/37 use functions defined previously to dynamically
  compile scriptlets.

  Patch 36/37 suppresses misleading messages printed during probing.

  Patch 37/37 adds new options to 'perf record'.

Wang Nan (37):
  tools build: Add feature check for eBPF API
  bpf tools: Introduce 'bpf' library to tools
  bpf tools: Allow caller to set printing function
  bpf tools: Open eBPF object file and do basic validation
  bpf tools: Read eBPF object from buffer
  bpf tools: Check endianess and make libbpf fail early
  bpf tools: Iterate over ELF sections to collect information
  bpf tools: Collect version and license from ELF sections
  bpf tools: Collect map definitions from 'maps' section
  bpf tools: Collect symbol table from SHT_SYMTAB section
  bpf tools: Collect eBPF programs from their own sections
  bpf tools: Collect relocation sections from SHT_REL sections
  bpf tools: Record map accessing instructions for each program
  bpf tools: Add bpf.c/h for common bpf operations
  bpf tools: Create eBPF maps defined in an object file
  bpf tools: Relocate eBPF programs
  bpf tools: Introduce bpf_load_program() to bpf.c
  bpf tools: Load eBPF programs in object files into kernel
  bpf tools: Introduce accessors for struct bpf_program
  bpf tools: Introduce accessors for struct bpf_object
  bpf tools: Link all bpf objects onto a list
  perf tools: Make perf depend on libbpf
  perf tools: Introduce llvm config options
  perf tools: Call clang to compile C source to object code
  perf tests: Add LLVM test for eBPF on-the-fly compiling
  perf tools: Auto detecting kernel build directory
  perf tools: Auto detecting kernel include options
  perf record: Enable passing bpf object file to --event
  perf record: Compile scriptlets if pass '.c' to --event
  perf tools: Parse probe points of eBPF programs during preparation
  perf probe: 

[RFC PATCH v7 22/37] perf tools: Make perf depend on libbpf

2015-06-11 Thread Wang Nan
By adding libbpf into perf's Makefile, this patch enables perf to
build libbpf during building if libelf is found and neither NO_LIBELF
nor NO_LIBBPF is set. The newly introduced code is similar to libapi
and libtraceevent building in Makefile.perf.

MANIFEST is also updated for 'make perf-*-src-pkg'.

Append make_no_libbpf to tools/perf/tests/make.

Error messages are also updated to notify users about the disable of
BPF support of 'perf record' if libelf is missed or BPF API check
failed.

Signed-off-by: Wang Nan 
---
 tools/perf/MANIFEST|  3 +++
 tools/perf/Makefile.perf   | 19 +--
 tools/perf/config/Makefile | 19 ++-
 tools/perf/tests/make  |  4 +++-
 4 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST
index a0bdd61..1ad2016 100644
--- a/tools/perf/MANIFEST
+++ b/tools/perf/MANIFEST
@@ -17,6 +17,7 @@ tools/build
 tools/arch/x86/include/asm/atomic.h
 tools/arch/x86/include/asm/rmwcc.h
 tools/lib/traceevent
+tools/lib/bpf
 tools/lib/api
 tools/lib/symbol/kallsyms.c
 tools/lib/symbol/kallsyms.h
@@ -71,6 +72,8 @@ include/linux/magic.h
 include/linux/hw_breakpoint.h
 include/linux/rbtree_augmented.h
 include/uapi/linux/perf_event.h
+include/uapi/linux/bpf.h
+include/uapi/linux/bpf_common.h
 include/uapi/linux/const.h
 include/uapi/linux/swab.h
 include/uapi/linux/hw_breakpoint.h
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 3743783..ec2ed6e 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -125,6 +125,7 @@ STRIP   = strip
 
 LIB_DIR  = $(srctree)/tools/lib/api/
 TRACE_EVENT_DIR = $(srctree)/tools/lib/traceevent/
+BPF_DIR = $(srctree)/tools/lib/bpf/
 
 # include config/Makefile by default and rule out
 # non-config cases
@@ -160,6 +161,7 @@ strip-libs = $(filter-out -l%,$(1))
 
 ifneq ($(OUTPUT),)
   TE_PATH=$(OUTPUT)
+  BPF_PATH=$(OUTPUT)
 ifneq ($(subdir),)
   LIB_PATH=$(OUTPUT)/../lib/api/
 else
@@ -168,6 +170,7 @@ endif
 else
   TE_PATH=$(TRACE_EVENT_DIR)
   LIB_PATH=$(LIB_DIR)
+  BPF_PATH=$(BPF_DIR)
 endif
 
 LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
@@ -179,6 +182,8 @@ LDFLAGS += -Xlinker 
--dynamic-list=$(LIBTRACEEVENT_DYNAMIC_LIST)
 LIBAPI = $(LIB_PATH)libapi.a
 export LIBAPI
 
+LIBBPF = $(BPF_PATH)libbpf.a
+
 # python extension build directories
 PYTHON_EXTBUILD := $(OUTPUT)python_ext_build/
 PYTHON_EXTBUILD_LIB := $(PYTHON_EXTBUILD)lib/
@@ -230,6 +235,9 @@ export PERL_PATH
 LIB_FILE=$(OUTPUT)libperf.a
 
 PERFLIBS = $(LIB_FILE) $(LIBAPI) $(LIBTRACEEVENT)
+ifndef NO_LIBBPF
+  PERFLIBS += $(LIBBPF)
+endif
 
 # We choose to avoid "if .. else if .. else .. endif endif"
 # because maintaining the nesting to match is a pain.  If
@@ -398,6 +406,13 @@ $(LIBAPI)-clean:
$(call QUIET_CLEAN, libapi)
$(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null
 
+$(LIBBPF): FORCE
+   $(Q)$(MAKE) -C $(BPF_DIR) O=$(OUTPUT) $(OUTPUT)libbpf.a
+
+$(LIBBPF)-clean:
+   $(call QUIET_CLEAN, libbpf)
+   $(Q)$(MAKE) -C $(BPF_DIR) O=$(OUTPUT) clean >/dev/null
+
 help:
@echo 'Perf make targets:'
@echo '  doc- make *all* documentation (see below)'
@@ -437,7 +452,7 @@ INSTALL_DOC_TARGETS += quick-install-doc quick-install-man 
quick-install-html
 $(DOC_TARGETS):
$(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) $(@:doc=all)
 
-TAG_FOLDERS= . ../lib/traceevent ../lib/api ../lib/symbol
+TAG_FOLDERS= . ../lib/traceevent ../lib/api ../lib/symbol ../lib/bpf
 TAG_FILES= ../../include/uapi/linux/perf_event.h
 
 TAGS:
@@ -540,7 +555,7 @@ config-clean:
$(call QUIET_CLEAN, config)
$(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null
 
-clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean config-clean
+clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean
$(call QUIET_CLEAN, core-objs)  $(RM) $(LIB_FILE) $(OUTPUT)perf-archive 
$(OUTPUT)perf-with-kcore $(LANG_BINDINGS)
$(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name 
'\.*.d' -delete
$(Q)$(RM) .config-detected
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index 317001c..1b387ec 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -106,6 +106,7 @@ ifdef LIBBABELTRACE
   FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) 
-lbabeltrace-ctf
 endif
 
+FEATURE_CHECK_CFLAGS-bpf = -I. -I$(srctree)/tools/include 
-I$(srctree)/arch/$(ARCH)/include/uapi -I$(srctree)/include/uapi
 # include ARCH specific config
 -include $(src-perf)/arch/$(ARCH)/Makefile
 
@@ -233,6 +234,7 @@ ifdef NO_LIBELF
   NO_DEMANGLE := 1
   NO_LIBUNWIND := 1
   NO_LIBDW_DWARF_UNWIND := 1
+  NO_LIBBPF := 1
 else
   ifeq ($(feature-libelf), 0)
 ifeq ($(feature-glibc), 1)
@@ -242,13 +244,14 @@ else
   LIBC_SUPPORT := 1
 endif
 ifeq ($(LIBC_SUPPORT),1)
-  msg := $(warning No libelf found, disables 'probe' tool, please install 
elfutils-libelf-devel/libelf-dev);
+ 

[RFC PATCH v7 18/37] bpf tools: Load eBPF programs in object files into kernel

2015-06-11 Thread Wang Nan
This patch utilizes previous introduced bpf_load_program to load
programs in the ELF file into kernel. Result is stored in 'fd' field
in 'struct bpf_program'.

During loading, it allocs a log buffer and free it before return.
Note that that buffer is not passed to bpf_load_program() if the first
loading try is successful. Doesn't use a statically allocated log
buffer to avoid potention multi-thread problem.

Instructions collected during opening is cleared after loading.

Signed-off-by: Wang Nan 
Acked-by: Alexei Starovoitov 
---
 tools/lib/bpf/libbpf.c | 80 ++
 1 file changed, 80 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index dbec69f..9b56832 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -96,6 +96,8 @@ struct bpf_program {
int map_idx;
} *reloc_desc;
int nr_reloc;
+
+   int fd;
 };
 
 struct bpf_object {
@@ -135,11 +137,20 @@ struct bpf_object {
 };
 #define obj_elf_valid(o)   ((o)->efile.elf)
 
+static void bpf_program__unload(struct bpf_program *prog)
+{
+   if (!prog)
+   return;
+
+   zclose(prog->fd);
+}
+
 static void bpf_program__clear(struct bpf_program *prog)
 {
if (!prog)
return;
 
+   bpf_program__unload(prog);
zfree(>section_name);
zfree(>insns);
zfree(>reloc_desc);
@@ -199,6 +210,7 @@ bpf_program__new(struct bpf_object *obj, void *data, size_t 
size,
memcpy(prog->insns, data,
   prog->insns_cnt * sizeof(struct bpf_insn));
prog->idx = idx;
+   prog->fd = -1;
 
return prog;
 out:
@@ -709,6 +721,69 @@ static int bpf_object__collect_reloc(struct bpf_object 
*obj)
return 0;
 }
 
+static int
+bpf_program__load(struct bpf_program *prog,
+ char *license, u32 kern_version)
+{
+   int fd, err;
+   char *log_buf;
+
+   if (!prog->insns || !prog->insns_cnt)
+   return -EINVAL;
+
+   log_buf = malloc(BPF_LOG_BUF_SIZE);
+   if (!log_buf)
+   pr_warning("Alloc log buffer for bpf loader error, continue 
without log\n");
+
+   fd = bpf_load_program(BPF_PROG_TYPE_KPROBE, prog->insns,
+ prog->insns_cnt, license,
+ kern_version, log_buf,
+ BPF_LOG_BUF_SIZE);
+
+   if (fd >= 0) {
+   prog->fd = fd;
+   pr_debug("load bpf program '%s': fd = %d\n",
+prog->section_name, prog->fd);
+   err = 0;
+   goto out;
+   }
+
+   err = -EINVAL;
+   pr_warning("load bpf program '%s' failed: %s\n",
+  prog->section_name, strerror(errno));
+
+   if (log_buf) {
+   pr_warning("bpf: load: failed to load program '%s':\n",
+  prog->section_name);
+   pr_warning("-- BEGIN DUMP LOG ---\n");
+   pr_warning("%s\n", log_buf);
+   pr_warning("-- END LOG --\n");
+   }
+
+out:
+   zfree(>insns);
+   prog->insns_cnt = 0;
+   free(log_buf);
+   return err;
+}
+
+static int
+bpf_object__load_progs(struct bpf_object *obj)
+{
+   size_t i;
+   int err;
+
+   for (i = 0; i < obj->nr_programs; i++) {
+   err = bpf_program__load(>programs[i],
+   obj->license,
+   obj->kern_version);
+   if (err)
+   return err;
+   }
+   return 0;
+}
+
+
 static int bpf_object__validate(struct bpf_object *obj)
 {
if (obj->kern_version == 0) {
@@ -786,6 +861,9 @@ int bpf_object__unload(struct bpf_object *obj)
zfree(>map_fds);
obj->nr_map_fds = 0;
 
+   for (i = 0; i < obj->nr_programs; i++)
+   bpf_program__unload(>programs[i]);
+
return 0;
 }
 
@@ -804,6 +882,8 @@ int bpf_object__load(struct bpf_object *obj)
goto out;
if (bpf_object__relocate(obj))
goto out;
+   if (bpf_object__load_progs(obj))
+   goto out;
 
return 0;
 out:
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v7 04/37] bpf tools: Open eBPF object file and do basic validation

2015-06-11 Thread Wang Nan
This patch defines basic interface of libbpf. 'struct bpf_object' will
be the handler of each object file. Its internal structure is hide to
user. eBPF object files are compiled by LLVM as ELF format. In this
patch, libelf is used to open those files, read EHDR and do basic
validation according to e_type and e_machine.

All elf related staffs are grouped together and reside in efile field of
'struct bpf_object'. bpf_object__elf_finish() is introduced to clear it.

After all eBPF programs in an object file are loaded, related ELF
information is useless. Close the object file and free those memory.

zfree() and zclose() are introduced to ensure setting NULL pointers and
negative file descriptors after resources are released.

Signed-off-by: Wang Nan 
Acked-by: Alexei Starovoitov 
---
 tools/lib/bpf/libbpf.c | 158 +
 tools/lib/bpf/libbpf.h |   8 +++
 2 files changed, 166 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index ded37a0..197ab5e 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -11,8 +11,12 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
+#include 
+#include 
 
 #include "libbpf.h"
 
@@ -52,3 +56,157 @@ void libbpf_set_print(libbpf_print_fn_t warn,
__pr_info = info;
__pr_debug = debug;
 }
+
+/* Copied from tools/perf/util/util.h */
+#ifndef zfree
+# define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
+#endif
+
+#ifndef zclose
+# define zclose(fd) ({ \
+   int ___err = 0; \
+   if ((fd) >= 0)  \
+   ___err = close((fd));   \
+   fd = -1;\
+   ___err;})
+#endif
+
+#ifdef HAVE_LIBELF_MMAP_SUPPORT
+# define LIBBPF_ELF_C_READ_MMAP ELF_C_READ_MMAP
+#else
+# define LIBBPF_ELF_C_READ_MMAP ELF_C_READ
+#endif
+
+struct bpf_object {
+   /*
+* Information when doing elf related work. Only valid if fd
+* is valid.
+*/
+   struct {
+   int fd;
+   Elf *elf;
+   GElf_Ehdr ehdr;
+   } efile;
+   char path[];
+};
+#define obj_elf_valid(o)   ((o)->efile.elf)
+
+static struct bpf_object *bpf_object__new(const char *path)
+{
+   struct bpf_object *obj;
+
+   obj = calloc(1, sizeof(struct bpf_object) + strlen(path) + 1);
+   if (!obj) {
+   pr_warning("alloc memory failed for %s\n", path);
+   return NULL;
+   }
+
+   strcpy(obj->path, path);
+   obj->efile.fd = -1;
+   return obj;
+}
+
+static void bpf_object__elf_finish(struct bpf_object *obj)
+{
+   if (!obj_elf_valid(obj))
+   return;
+
+   if (obj->efile.elf) {
+   elf_end(obj->efile.elf);
+   obj->efile.elf = NULL;
+   }
+   zclose(obj->efile.fd);
+}
+
+static int bpf_object__elf_init(struct bpf_object *obj)
+{
+   int err = 0;
+   GElf_Ehdr *ep;
+
+   if (obj_elf_valid(obj)) {
+   pr_warning("elf init: internal error\n");
+   return -EEXIST;
+   }
+
+   obj->efile.fd = open(obj->path, O_RDONLY);
+   if (obj->efile.fd < 0) {
+   pr_warning("failed to open %s: %s\n", obj->path,
+   strerror(errno));
+   return -errno;
+   }
+
+   obj->efile.elf = elf_begin(obj->efile.fd,
+LIBBPF_ELF_C_READ_MMAP,
+NULL);
+   if (!obj->efile.elf) {
+   pr_warning("failed to open %s as ELF file\n",
+   obj->path);
+   err = -EINVAL;
+   goto errout;
+   }
+
+   if (!gelf_getehdr(obj->efile.elf, >efile.ehdr)) {
+   pr_warning("failed to get EHDR from %s\n",
+   obj->path);
+   err = -EINVAL;
+   goto errout;
+   }
+   ep = >efile.ehdr;
+
+   if ((ep->e_type != ET_REL) || (ep->e_machine != 0)) {
+   pr_warning("%s is not an eBPF object file\n",
+   obj->path);
+   err = -EINVAL;
+   goto errout;
+   }
+
+   return 0;
+errout:
+   bpf_object__elf_finish(obj);
+   return err;
+}
+
+static struct bpf_object *
+__bpf_object__open(const char *path)
+{
+   struct bpf_object *obj;
+
+   if (elf_version(EV_CURRENT) == EV_NONE) {
+   pr_warning("failed to init libelf for %s\n", path);
+   return NULL;
+   }
+
+   obj = bpf_object__new(path);
+   if (!obj)
+   return NULL;
+
+   if (bpf_object__elf_init(obj))
+   goto out;
+
+   bpf_object__elf_finish(obj);
+   return obj;
+out:
+   bpf_object__close(obj);
+   return NULL;
+}
+
+struct bpf_object *bpf_object__open(const char *path)
+{
+   /* param validation */
+   if (!path)
+   return NULL;
+
+   pr_debug("loading %s\n", path);

[RFC PATCH v7 06/37] bpf tools: Check endianess and make libbpf fail early

2015-06-11 Thread Wang Nan
Check endianess according to EHDR. Code is taken from
tools/perf/util/symbol-elf.c.

Libbpf doesn't magically convert missmatched endianess. Even if we swap
eBPF instructions to correct byte order, we are unable to deal with
endianess in code logical generated by LLVM.

Therefore, libbpf should simply reject missmatched ELF object, and let
LLVM to create good code.

Signed-off-by: Wang Nan 
Acked-by: Alexei Starovoitov 
---
 tools/lib/bpf/libbpf.c | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 8ba6ac6..472b296 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -192,6 +192,34 @@ errout:
return err;
 }
 
+static int
+bpf_object__check_endianess(struct bpf_object *obj)
+{
+   static unsigned int const endian = 1;
+
+   switch (obj->efile.ehdr.e_ident[EI_DATA]) {
+   case ELFDATA2LSB:
+   /* We are big endian, BPF obj is little endian. */
+   if (*(unsigned char const *) != 1)
+   goto mismatch;
+   break;
+
+   case ELFDATA2MSB:
+   /* We are little endian, BPF obj is big endian. */
+   if (*(unsigned char const *) != 0)
+   goto mismatch;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   return 0;
+
+mismatch:
+   pr_warning("Error: endianess mismatch.\n");
+   return -EINVAL;
+}
+
 static struct bpf_object *
 __bpf_object__open(const char *path, void *obj_buf, size_t obj_buf_sz)
 {
@@ -208,6 +236,8 @@ __bpf_object__open(const char *path, void *obj_buf, size_t 
obj_buf_sz)
 
if (bpf_object__elf_init(obj))
goto out;
+   if (bpf_object__check_endianess(obj))
+   goto out;
 
bpf_object__elf_finish(obj);
return obj;
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v7 26/37] perf tools: Auto detecting kernel build directory

2015-06-11 Thread Wang Nan
This patch detects kernel build directory using a embedded shell
script 'kbuild_detector', which does this by checking existance of
include/generated/autoconf.h.

clang working directory is changed to kbuild directory if it is found,
to help user use relative include path. Following patch will detect
kernel include directory, which contains relative include patch so this
workdir changing is needed.

Users are allowed to set 'kbuild-dir = ""' manually to disable this
checking.

Signed-off-by: Wang Nan 
---
 tools/perf/util/llvm-utils.c | 56 +++-
 1 file changed, 55 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index c01decd..7b2217a 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -201,6 +201,51 @@ version_notice(void)
 );
 }
 
+static const char *kbuild_detector =
+"#!/usr/bin/env sh\n"
+"DEFAULT_KBUILD_DIR=/lib/modules/`uname -r`/build\n"
+"if test -z \"$KBUILD_DIR\"\n"
+"then\n"
+"KBUILD_DIR=$DEFAULT_KBUILD_DIR\n"
+"fi\n"
+"if test -f $KBUILD_DIR/include/generated/autoconf.h\n"
+"then\n"
+"  echo -n $KBUILD_DIR\n"
+"  exit 0\n"
+"fi\n"
+"exit -1\n";
+
+static inline void
+get_kbuild_opts(char **kbuild_dir)
+{
+   int err;
+
+   if (!kbuild_dir)
+   return;
+
+   *kbuild_dir = NULL;
+
+   if (llvm_param.kbuild_dir && !llvm_param.kbuild_dir[0]) {
+   pr_debug("[llvm.kbuild-dir] is set to \"\" deliberately.\n");
+   pr_debug("Skip kbuild options detection.\n");
+   return;
+   }
+
+   force_set_env("KBUILD_DIR", llvm_param.kbuild_dir);
+   force_set_env("KBUILD_OPTS",llvm_param.kbuild_opts);
+   err = read_from_pipe(kbuild_detector,
+((void **)kbuild_dir),
+NULL);
+   if (err) {
+   pr_warning(
+"WARNING:\tunable to get correct kernel building directory.\n"
+"Hint:\tSet correct kbuild directory using 'kbuild-dir' option in [llvm]\n"
+" \tsection of ~/.perfconfig or set it to \"\" to suppress kbuild\n"
+" \tdetection.\n\n");
+   return;
+   }
+}
+
 int llvm__compile_bpf(const char *path, void **p_obj_buf,
  size_t *p_obj_buf_sz)
 {
@@ -208,6 +253,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
char clang_path[PATH_MAX];
const char *clang_opt = llvm_param.clang_opt;
const char *template = llvm_param.clang_bpf_cmd_template;
+   char *kbuild_dir = NULL;
void *obj_buf = NULL;
size_t obj_buf_sz;
 
@@ -225,10 +271,16 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
return -ENOENT;
}
 
+   /*
+* This is an optional work. Even it fail we can continue our
+* work. Needn't to check error return.
+*/
+   get_kbuild_opts(_dir);
+
force_set_env("CLANG_EXEC", clang_path);
force_set_env("CLANG_OPTIONS", clang_opt);
force_set_env("KERNEL_INC_OPTIONS", NULL);
-   force_set_env("WORKING_DIR", ".");
+   force_set_env("WORKING_DIR", kbuild_dir ? : ".");
 
/*
 * Since we may reset clang's working dir, path of source file
@@ -249,6 +301,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
goto errout;
}
 
+   free(kbuild_dir);
if (!p_obj_buf)
free(obj_buf);
else
@@ -258,6 +311,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
*p_obj_buf_sz = obj_buf_sz;
return 0;
 errout:
+   free(kbuild_dir);
free(obj_buf);
if (p_obj_buf)
*p_obj_buf = NULL;
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v7 24/37] perf tools: Call clang to compile C source to object code

2015-06-11 Thread Wang Nan
This is the core patch for supporting eBPF on-the-fly compiling, does
the following work:

 1. Search clang compiler using search_program().

 2. Run command template defined in llvm-bpf-cmd-template option in
[llvm] config section using read_from_pipe(). Patch of clang and
source code path is injected into shell command using environment
variable using force_set_env().

Signed-off-by: Wang Nan 
---
 tools/perf/util/llvm-utils.c | 222 +++
 tools/perf/util/llvm-utils.h |   3 +
 2 files changed, 225 insertions(+)

diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index 7dc1f1e..c01decd 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -43,3 +43,225 @@ int perf_llvm_config(const char *var, const char *value)
return -1;
return 0;
 }
+
+static int
+search_program(const char *def, const char *name,
+  char *output)
+{
+   char *env, *path, *tmp;
+   char buf[PATH_MAX];
+   int ret;
+
+   output[0] = '\0';
+   if (def && def[0] != '\0') {
+   if (def[0] == '/') {
+   if (access(def, F_OK) == 0) {
+   strlcpy(output, def, PATH_MAX);
+   return 0;
+   }
+   } else if (def[0] != '\0')
+   name = def;
+   }
+
+   env = getenv("PATH");
+   if (!env)
+   return -1;
+   env = strdup(env);
+   if (!env)
+   return -1;
+
+   ret = -ENOENT;
+   path = strtok_r(env, ":",  );
+   while (path) {
+   scnprintf(buf, sizeof(buf), "%s/%s", path, name);
+   if (access(buf, F_OK) == 0) {
+   strlcpy(output, buf, PATH_MAX);
+   ret = 0;
+   break;
+   }
+   path = strtok_r(NULL, ":", );
+   }
+
+   free(env);
+   return ret;
+}
+
+#define READ_SIZE  4096
+static int
+read_from_pipe(const char *cmd, void **p_buf, size_t *p_read_sz)
+{
+   int err = 0;
+   void *buf = NULL;
+   FILE *file = NULL;
+   size_t read_sz = 0, buf_sz = 0;
+
+   file = popen(cmd, "r");
+   if (!file) {
+   pr_err("ERROR: unable to popen cmd: %s\n",
+  strerror(errno));
+   return -EINVAL;
+   }
+
+   while (!feof(file) && !ferror(file)) {
+   /*
+* Make buf_sz always have obe byte extra space so we
+* can put '\0' there.
+*/
+   if (buf_sz - read_sz < READ_SIZE + 1) {
+   void *new_buf;
+
+   buf_sz = read_sz + READ_SIZE + 1;
+   new_buf = realloc(buf, buf_sz);
+
+   if (!new_buf) {
+   pr_err("ERROR: failed to realloc memory\n");
+   err = -ENOMEM;
+   goto errout;
+   }
+
+   buf = new_buf;
+   }
+   read_sz += fread(buf + read_sz, 1, READ_SIZE, file);
+   }
+
+   if (buf_sz - read_sz < 1) {
+   pr_err("ERROR: internal error\n");
+   err = -EINVAL;
+   goto errout;
+   }
+
+   if (ferror(file)) {
+   pr_err("ERROR: error occured when reading from pipe: %s\n",
+  strerror(errno));
+   err = -EIO;
+   goto errout;
+   }
+
+   err = WEXITSTATUS(pclose(file));
+   file = NULL;
+   if (err) {
+   err = -EINVAL;
+   goto errout;
+   }
+
+   /*
+* If buf is string, give it terminal '\0' to make our life
+* easier. If buf is not string, that '\0' is out of space
+* indicated by read_sz so caller won't even notice it.
+*/
+   ((char *)buf)[read_sz] = '\0';
+
+   if (!p_buf)
+   free(buf);
+   else
+   *p_buf = buf;
+
+   if (p_read_sz)
+   *p_read_sz = read_sz;
+   return 0;
+
+errout:
+   if (file)
+   pclose(file);
+   free(buf);
+   if (p_buf)
+   *p_buf = NULL;
+   if (p_read_sz)
+   *p_read_sz = 0;
+   return err;
+}
+
+static inline void
+force_set_env(const char *var, const char *value)
+{
+   if (value) {
+   setenv(var, value, 1);
+   pr_debug("set env: %s=%s\n", var, value);
+   } else {
+   unsetenv(var);
+   pr_debug("unset env: %s\n", var);
+   }
+}
+
+static void
+version_notice(void)
+{
+   pr_err(
+" \tLLVM 3.7 or newer is required. Which can be found from 
http://llvm.org\n;
+" \tYou may want to try git trunk:\n"
+" \t\tgit clone http://llvm.org/git/llvm.git\n;
+" \t\t and\n"
+" \t\tgit clone http://llvm.org/git/clang.git\n\n;

[RFC PATCH v7 25/37] perf tests: Add LLVM test for eBPF on-the-fly compiling

2015-06-11 Thread Wang Nan
Previous patch introduces llvm__compile_bpf() to compile source file to
eBPF object. This patch adds testcase to test it. It also test libbpf
by opening generated object.

Signed-off-by: Wang Nan 
---
 tools/perf/tests/Build  |  1 +
 tools/perf/tests/builtin-test.c |  4 ++
 tools/perf/tests/llvm.c | 85 +
 tools/perf/tests/tests.h|  1 +
 4 files changed, 91 insertions(+)
 create mode 100644 tools/perf/tests/llvm.c

diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index ee41e70..5d74604 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -31,6 +31,7 @@ perf-y += code-reading.o
 perf-y += sample-parsing.o
 perf-y += parse-no-sample-id-all.o
 perf-y += kmod-path.o
+perf-y += llvm.o
 
 perf-$(CONFIG_X86) += perf-time-to-tsc.o
 
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 87b9961..4d28fd9 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -171,6 +171,10 @@ static struct test {
.func = test__kmod_path__parse,
},
{
+   .desc = "Test LLVM searching and compiling",
+   .func = test__llvm,
+   },
+   {
.func = NULL,
},
 };
diff --git a/tools/perf/tests/llvm.c b/tools/perf/tests/llvm.c
new file mode 100644
index 000..272be1b
--- /dev/null
+++ b/tools/perf/tests/llvm.c
@@ -0,0 +1,85 @@
+#include 
+#include 
+#include 
+#include 
+#include "tests.h"
+#include "debug.h"
+
+static int perf_config_cb(const char *var, const char *val,
+ void *arg __maybe_unused)
+{
+   return perf_default_config(var, val, arg);
+}
+
+/*
+ * Randomly give it a "version" section since we don't really load it
+ * into kernel
+ */
+static const char test_bpf_prog[] =
+   "__attribute__((section(\"do_fork\"), used)) "
+   "int fork(void *ctx) {return 0;} "
+   "char _license[] __attribute__((section(\"license\"), used)) = \"GPL\";"
+   "int _version __attribute__((section(\"version\"), used)) = 0x40100;";
+
+#ifdef HAVE_LIBBPF_SUPPORT
+static int test__bpf_parsing(void *obj_buf, size_t obj_buf_sz)
+{
+   struct bpf_object *obj;
+
+   obj = bpf_object__open_buffer(obj_buf, obj_buf_sz);
+   if (!obj)
+   return -1;
+   bpf_object__close(obj);
+   return 0;
+}
+#else
+static int test__bpf_parsing(void *obj_buf __maybe_unused,
+size_t obj_buf_sz __maybe_unused)
+{
+   fprintf(stderr, " (skip bpf parsing)");
+   return 0;
+}
+#endif
+
+#define new_string(n, fmt, ...) \
+do {   \
+   n##_sz = snprintf(NULL, 0, fmt, __VA_ARGS__);\
+   if (n##_sz == 0)\
+   return -1;  \
+   n##_new = malloc(n##_sz + 1);   \
+   if (!n##_new)   \
+   return -1;  \
+   snprintf(n##_new, n##_sz + 1, fmt, __VA_ARGS__);\
+   n##_new[n##_sz] = '\0'; \
+} while(0)
+
+int test__llvm(void)
+{
+   char *tmpl_new, *clang_opt_new;
+   size_t tmpl_sz, clang_opt_sz;
+   void *obj_buf;
+   size_t obj_buf_sz;
+   int err;
+
+   perf_config(perf_config_cb, NULL);
+
+   if (!llvm_param.clang_bpf_cmd_template)
+   return -1;
+
+   if (!llvm_param.clang_opt)
+   llvm_param.clang_opt = strdup("");
+
+   new_string(tmpl, "echo '%s' | %s", test_bpf_prog,
+  llvm_param.clang_bpf_cmd_template);
+   new_string(clang_opt, "-xc %s", llvm_param.clang_opt);
+
+   llvm_param.clang_bpf_cmd_template = tmpl_new;
+   llvm_param.clang_opt = clang_opt_new;
+   err = llvm__compile_bpf("-", _buf, _buf_sz);
+   if (err)
+   return -1;
+
+   err = test__bpf_parsing(obj_buf, obj_buf_sz);
+   free(obj_buf);
+   return err;
+}
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 8e5038b..5b29796 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -61,6 +61,7 @@ int test__switch_tracking(void);
 int test__fdarray__filter(void);
 int test__fdarray__add(void);
 int test__kmod_path__parse(void);
+int test__llvm(void);
 
 #if defined(__x86_64__) || defined(__i386__) || defined(__arm__) || 
defined(__aarch64__)
 #ifdef HAVE_DWARF_UNWIND_SUPPORT
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v7 02/37] bpf tools: Introduce 'bpf' library to tools

2015-06-11 Thread Wang Nan
This is the first patch of libbpf. The goal of libbpf is to create a
standard way for accessing eBPF object files. This patch creates
'Makefile' and 'Build' for it, allows 'make' to build libbpf.a and
libbpf.so, 'make install' to put them into proper directories.
Most part of Makefile is borrowed from traceevent.

Before building, it checks the existance of libelf in Makefile, and deny
to build if not found. Instead of throwing an error if libelf not found,
the error raises in a phony target "elfdep". This design is to ensure
'make clean' still workable even if libelf is not found.

Kernel BPF API is also checked. "bpfdep" is used for it.

Signed-off-by: Wang Nan 
Acked-by: Alexei Starovoitov 
---
 tools/lib/bpf/.gitignore |   2 +
 tools/lib/bpf/Build  |   1 +
 tools/lib/bpf/Makefile   | 195 +++
 tools/lib/bpf/libbpf.c   |  14 
 tools/lib/bpf/libbpf.h   |  11 +++
 5 files changed, 223 insertions(+)
 create mode 100644 tools/lib/bpf/.gitignore
 create mode 100644 tools/lib/bpf/Build
 create mode 100644 tools/lib/bpf/Makefile
 create mode 100644 tools/lib/bpf/libbpf.c
 create mode 100644 tools/lib/bpf/libbpf.h

diff --git a/tools/lib/bpf/.gitignore b/tools/lib/bpf/.gitignore
new file mode 100644
index 000..812aeed
--- /dev/null
+++ b/tools/lib/bpf/.gitignore
@@ -0,0 +1,2 @@
+libbpf_version.h
+FEATURE-DUMP
diff --git a/tools/lib/bpf/Build b/tools/lib/bpf/Build
new file mode 100644
index 000..a316484
--- /dev/null
+++ b/tools/lib/bpf/Build
@@ -0,0 +1 @@
+libbpf-y := libbpf.o
diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
new file mode 100644
index 000..f68d23a
--- /dev/null
+++ b/tools/lib/bpf/Makefile
@@ -0,0 +1,195 @@
+# Most of this file is copied from tools/lib/traceevent/Makefile
+
+BPF_VERSION = 0
+BPF_PATCHLEVEL = 0
+BPF_EXTRAVERSION = 1
+
+MAKEFLAGS += --no-print-directory
+
+
+# Makefiles suck: This macro sets a default value of $(2) for the
+# variable named by $(1), unless the variable has been set by
+# environment or command line. This is necessary for CC and AR
+# because make sets default values, so the simpler ?= approach
+# won't work as expected.
+define allow-override
+  $(if $(or $(findstring environment,$(origin $(1))),\
+$(findstring command line,$(origin $(1,,\
+$(eval $(1) = $(2)))
+endef
+
+# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
+$(call allow-override,CC,$(CROSS_COMPILE)gcc)
+$(call allow-override,AR,$(CROSS_COMPILE)ar)
+
+INSTALL = install
+
+# Use DESTDIR for installing into a different root directory.
+# This is useful for building a package. The program will be
+# installed in this directory as if it was the root directory.
+# Then the build tool can move it later.
+DESTDIR ?=
+DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
+
+LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)
+ifeq ($(LP64), 1)
+  libdir_relative = lib64
+else
+  libdir_relative = lib
+endif
+
+prefix ?= /usr/local
+libdir = $(prefix)/$(libdir_relative)
+man_dir = $(prefix)/share/man
+man_dir_SQ = '$(subst ','\'',$(man_dir))'
+
+export man_dir man_dir_SQ INSTALL
+export DESTDIR DESTDIR_SQ
+
+include ../../scripts/Makefile.include
+
+# copy a bit from Linux kbuild
+
+ifeq ("$(origin V)", "command line")
+  VERBOSE = $(V)
+endif
+ifndef VERBOSE
+  VERBOSE = 0
+endif
+
+ifeq ($(srctree),)
+srctree := $(patsubst %/,%,$(dir $(shell pwd)))
+srctree := $(patsubst %/,%,$(dir $(srctree)))
+srctree := $(patsubst %/,%,$(dir $(srctree)))
+#$(info Determined 'srctree' to be $(srctree))
+endif
+
+FEATURE_DISPLAY = libelf libelf-getphdrnum libelf-mmap bpf
+FEATURE_TESTS = libelf bpf
+
+INCLUDES = -I. -I$(srctree)/tools/include 
-I$(srctree)/arch/$(ARCH)/include/uapi -I$(srctree)/include/uapi
+FEATURE_CHECK_CFLAGS-bpf = $(INCLUDES)
+
+include $(srctree)/tools/build/Makefile.feature
+
+export prefix libdir src obj
+
+# Shell quotes
+libdir_SQ = $(subst ','\'',$(libdir))
+libdir_relative_SQ = $(subst ','\'',$(libdir_relative))
+plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
+
+LIB_FILE = libbpf.a libbpf.so
+
+VERSION= $(BPF_VERSION)
+PATCHLEVEL = $(BPF_PATCHLEVEL)
+EXTRAVERSION   = $(BPF_EXTRAVERSION)
+
+OBJ= $@
+N  =
+
+LIBBPF_VERSION = $(BPF_VERSION).$(BPF_PATCHLEVEL).$(BPF_EXTRAVERSION)
+
+# Set compile option CFLAGS
+ifdef EXTRA_CFLAGS
+  CFLAGS := $(EXTRA_CFLAGS)
+else
+  CFLAGS := -g -Wall
+endif
+
+ifeq ($(feature-libelf-mmap), 1)
+  override CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
+endif
+
+ifeq ($(feature-libelf-getphdrnum), 1)
+  override CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
+endif
+
+# Append required CFLAGS
+override CFLAGS += $(EXTRA_WARNINGS)
+override CFLAGS += -Werror -Wall
+override CFLAGS += -fPIC
+override CFLAGS += $(INCLUDES)
+
+ifeq ($(VERBOSE),1)
+  Q =
+else
+  Q = @
+endif
+
+# Disable command line variables (CFLAGS) overide from top
+# level Makefile (perf), otherwise build Makefile will get
+# the same command line setup.

[RFC PATCH v7 07/37] bpf tools: Iterate over ELF sections to collect information

2015-06-11 Thread Wang Nan
bpf_obj_elf_collect() is introduced to iterate over each elf sections
to collection informations in eBPF object files. This function will
futher enhanced to collect license, kernel version, programs, configs
and map information.

Signed-off-by: Wang Nan 
Acked-by: Alexei Starovoitov 
---
 tools/lib/bpf/libbpf.c | 53 ++
 1 file changed, 53 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 472b296..1c4da03 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -220,6 +220,57 @@ mismatch:
return -EINVAL;
 }
 
+static int bpf_object__elf_collect(struct bpf_object *obj)
+{
+   Elf *elf = obj->efile.elf;
+   GElf_Ehdr *ep = >efile.ehdr;
+   Elf_Scn *scn = NULL;
+   int idx = 0, err = 0;
+
+   /* Elf is corrupted/truncated, avoid calling elf_strptr. */
+   if (!elf_rawdata(elf_getscn(elf, ep->e_shstrndx), NULL)) {
+   pr_warning("failed to get e_shstrndx from %s\n",
+  obj->path);
+   return -EINVAL;
+   }
+
+   while ((scn = elf_nextscn(elf, scn)) != NULL) {
+   char *name;
+   GElf_Shdr sh;
+   Elf_Data *data;
+
+   idx++;
+   if (gelf_getshdr(scn, ) != ) {
+   pr_warning("failed to get section header from %s\n",
+  obj->path);
+   err = -EINVAL;
+   goto out;
+   }
+
+   name = elf_strptr(elf, ep->e_shstrndx, sh.sh_name);
+   if (!name) {
+   pr_warning("failed to get section name from %s\n",
+  obj->path);
+   err = -EINVAL;
+   goto out;
+   }
+
+   data = elf_getdata(scn, 0);
+   if (!data) {
+   pr_warning("failed to get section data from %s(%s)\n",
+  name, obj->path);
+   err = -EINVAL;
+   goto out;
+   }
+   pr_debug("section %s, size %ld, link %d, flags %lx, type=%d\n",
+name, (unsigned long)data->d_size,
+(int)sh.sh_link, (unsigned long)sh.sh_flags,
+(int)sh.sh_type);
+   }
+out:
+   return err;
+}
+
 static struct bpf_object *
 __bpf_object__open(const char *path, void *obj_buf, size_t obj_buf_sz)
 {
@@ -238,6 +289,8 @@ __bpf_object__open(const char *path, void *obj_buf, size_t 
obj_buf_sz)
goto out;
if (bpf_object__check_endianess(obj))
goto out;
+   if (bpf_object__elf_collect(obj))
+   goto out;
 
bpf_object__elf_finish(obj);
return obj;
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v7 28/37] perf record: Enable passing bpf object file to --event

2015-06-11 Thread Wang Nan
By introducing new rules in tools/perf/util/parse-events.[ly], this
patch enables 'perf record --event bpf_file.o' to select events by
an eBPF object file. It calls parse_events_load_bpf() to load that
file, which uses bpf__prepare_load() and finally calls
bpf_object__open() for the object files.

Instead of introducing evsel to evlist during parsing, events
selected by eBPF object files are appended separately. The reason
is:

 1. During parsing, the probing points have not been initialized.

 2. Currently we are unable to call add_perf_probe_events() twice,
therefore we have to wait until all such events are collected,
then probe all points by one call.

The real probing and selecting is reside in following patches.

'bpf-loader.[ch]' are introduced in this patch. Which will be the
interface between perf and libbpf. bpf__prepare_load() resides in
bpf-loader.c. Dummy functions should be used because bpf-loader.c is
available only when CONFIG_LIBBPF is on.

Signed-off-by: Wang Nan 
---
 tools/perf/util/Build  |  1 +
 tools/perf/util/bpf-loader.c   | 60 ++
 tools/perf/util/bpf-loader.h   | 24 +
 tools/perf/util/debug.c|  5 
 tools/perf/util/debug.h|  1 +
 tools/perf/util/parse-events.c | 16 +++
 tools/perf/util/parse-events.h |  2 ++
 tools/perf/util/parse-events.l |  3 +++
 tools/perf/util/parse-events.y | 18 -
 9 files changed, 129 insertions(+), 1 deletion(-)
 create mode 100644 tools/perf/util/bpf-loader.c
 create mode 100644 tools/perf/util/bpf-loader.h

diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index edd48b5..5bc8030 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -79,6 +79,7 @@ libperf-y += thread-stack.o
 libperf-$(CONFIG_AUXTRACE) += auxtrace.o
 libperf-y += parse-branch-options.o
 
+libperf-$(CONFIG_LIBBPF) += bpf-loader.o
 libperf-$(CONFIG_LIBELF) += symbol-elf.o
 libperf-$(CONFIG_LIBELF) += probe-event.o
 
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
new file mode 100644
index 000..e950baa
--- /dev/null
+++ b/tools/perf/util/bpf-loader.c
@@ -0,0 +1,60 @@
+/*
+ * bpf-loader.c
+ *
+ * Copyright (C) 2015 Wang Nan 
+ * Copyright (C) 2015 Huawei Inc.
+ */
+
+#include 
+#include "perf.h"
+#include "debug.h"
+#include "bpf-loader.h"
+
+#define DEFINE_PRINT_FN(name, level) \
+static int libbpf_##name(const char *fmt, ...) \
+{  \
+   va_list args;   \
+   int ret;\
+   \
+   va_start(args, fmt);\
+   ret = veprintf(level, verbose, pr_fmt(fmt), args);\
+   va_end(args);   \
+   return ret; \
+}
+
+DEFINE_PRINT_FN(warning, 0)
+DEFINE_PRINT_FN(info, 0)
+DEFINE_PRINT_FN(debug, 1)
+
+static bool libbpf_initialized = false;
+
+int bpf__prepare_load(const char *filename)
+{
+   struct bpf_object *obj;
+
+   if (!libbpf_initialized)
+   libbpf_set_print(libbpf_warning,
+libbpf_info,
+libbpf_debug);
+
+   obj = bpf_object__open(filename);
+   if (!obj) {
+   pr_err("bpf: failed to load %s\n", filename);
+   return -EINVAL;
+   }
+
+   /*
+* Throw object pointer away: it will be retrived using
+* bpf_objects iterater.
+*/
+
+   return 0;
+}
+
+void bpf__clear(void)
+{
+   struct bpf_object *obj, *tmp;
+
+   bpf_object__for_each(obj, tmp)
+   bpf_object__close(obj);
+}
diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h
new file mode 100644
index 000..39d8d1a
--- /dev/null
+++ b/tools/perf/util/bpf-loader.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2015, Wang Nan 
+ * Copyright (C) 2015, Huawei Inc.
+ */
+#ifndef __BPF_LOADER_H
+#define __BPF_LOADER_H
+
+#include 
+#include "debug.h"
+
+#ifdef HAVE_LIBBPF_SUPPORT
+int bpf__prepare_load(const char *filename);
+
+void bpf__clear(void);
+#else
+static inline int bpf__prepare_load(const char *filename __maybe_unused)
+{
+   pr_err("ERROR: eBPF object loading is disabled during compiling.\n");
+   return -1;
+}
+
+static inline void bpf__clear(void) { }
+#endif
+#endif
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c
index 2da5581..86d9c73 100644
--- a/tools/perf/util/debug.c
+++ b/tools/perf/util/debug.c
@@ -36,6 +36,11 @@ static int _eprintf(int level, int var, const char *fmt, 
va_list args)
return ret;
 }
 
+int veprintf(int level, int var, const char *fmt, va_list args)
+{
+   return _eprintf(level, var, fmt, args);
+}
+
 int eprintf(int level, int var, const char *fmt, ...)
 {
va_list args;
diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h
index caac2fd..8b9a088 100644
--- a/tools/perf/util/debug.h
+++ 

[RFC PATCH v7 05/37] bpf tools: Read eBPF object from buffer

2015-06-11 Thread Wang Nan
To support dynamic compiling, this patch allows caller to pass a
in-memory buffer to libbpf by bpf_object__open_buffer(). libbpf
calls elf_memory() to open it as ELF object file.

Because __bpf_object__open() collects all required data and won't need
that buffer anymore, libbpf uses that buffer directly instead of clone
a new buffer. Caller of libbpf can free that buffer or use it do other
things after bpf_object__open_buffer() return.

Signed-off-by: Wang Nan 
---
 tools/lib/bpf/libbpf.c | 62 --
 tools/lib/bpf/libbpf.h |  2 ++
 2 files changed, 52 insertions(+), 12 deletions(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 197ab5e..8ba6ac6 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -84,6 +84,8 @@ struct bpf_object {
 */
struct {
int fd;
+   void *obj_buf;
+   size_t obj_buf_sz;
Elf *elf;
GElf_Ehdr ehdr;
} efile;
@@ -91,7 +93,9 @@ struct bpf_object {
 };
 #define obj_elf_valid(o)   ((o)->efile.elf)
 
-static struct bpf_object *bpf_object__new(const char *path)
+static struct bpf_object *bpf_object__new(const char *path,
+ void *obj_buf,
+ size_t obj_buf_sz)
 {
struct bpf_object *obj;
 
@@ -103,6 +107,16 @@ static struct bpf_object *bpf_object__new(const char *path)
 
strcpy(obj->path, path);
obj->efile.fd = -1;
+
+   /*
+* Caller of this function should also calls
+* bpf_object__elf_finish() after data collection to return
+* obj_buf to user. If not, we should duplicate the buffer to
+* avoid user freeing them before elf finish.
+*/
+   obj->efile.obj_buf = obj_buf;
+   obj->efile.obj_buf_sz = obj_buf_sz;
+
return obj;
 }
 
@@ -116,6 +130,8 @@ static void bpf_object__elf_finish(struct bpf_object *obj)
obj->efile.elf = NULL;
}
zclose(obj->efile.fd);
+   obj->efile.obj_buf = NULL;
+   obj->efile.obj_buf_sz = 0;
 }
 
 static int bpf_object__elf_init(struct bpf_object *obj)
@@ -128,16 +144,26 @@ static int bpf_object__elf_init(struct bpf_object *obj)
return -EEXIST;
}
 
-   obj->efile.fd = open(obj->path, O_RDONLY);
-   if (obj->efile.fd < 0) {
-   pr_warning("failed to open %s: %s\n", obj->path,
-   strerror(errno));
-   return -errno;
+   if (obj->efile.obj_buf_sz > 0) {
+   /*
+* obj_buf should have been validated by
+* bpf_object__open_buffer().
+*/
+   obj->efile.elf = elf_memory(obj->efile.obj_buf,
+   obj->efile.obj_buf_sz);
+   } else {
+   obj->efile.fd = open(obj->path, O_RDONLY);
+   if (obj->efile.fd < 0) {
+   pr_warning("failed to open %s: %s\n", obj->path,
+   strerror(errno));
+   return -errno;
+   }
+
+   obj->efile.elf = elf_begin(obj->efile.fd,
+   LIBBPF_ELF_C_READ_MMAP,
+   NULL);
}
 
-   obj->efile.elf = elf_begin(obj->efile.fd,
-LIBBPF_ELF_C_READ_MMAP,
-NULL);
if (!obj->efile.elf) {
pr_warning("failed to open %s as ELF file\n",
obj->path);
@@ -167,7 +193,7 @@ errout:
 }
 
 static struct bpf_object *
-__bpf_object__open(const char *path)
+__bpf_object__open(const char *path, void *obj_buf, size_t obj_buf_sz)
 {
struct bpf_object *obj;
 
@@ -176,7 +202,7 @@ __bpf_object__open(const char *path)
return NULL;
}
 
-   obj = bpf_object__new(path);
+   obj = bpf_object__new(path, obj_buf, obj_buf_sz);
if (!obj)
return NULL;
 
@@ -198,7 +224,19 @@ struct bpf_object *bpf_object__open(const char *path)
 
pr_debug("loading %s\n", path);
 
-   return __bpf_object__open(path);
+   return __bpf_object__open(path, NULL, 0);
+}
+
+struct bpf_object *bpf_object__open_buffer(void *obj_buf,
+  size_t obj_buf_sz)
+{
+   /* param validation */
+   if (!obj_buf || obj_buf_sz <= 0)
+   return NULL;
+
+   pr_debug("loading object from buffer\n");
+
+   return __bpf_object__open("[buffer]", obj_buf, obj_buf_sz);
 }
 
 void bpf_object__close(struct bpf_object *obj)
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index ec3301c..dc966dd 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -26,6 +26,8 @@ void libbpf_set_print(libbpf_print_fn_t warn,
 struct bpf_object;
 
 struct bpf_object *bpf_object__open(const char *path);
+struct bpf_object 

[RFC PATCH v7 27/37] perf tools: Auto detecting kernel include options

2015-06-11 Thread Wang Nan
To help user find correct kernel include options, this patch extracts
them from kbuild system by an embedded script kinc_fetch_script, which
creates a temporary directory, generates Makefile and an empty dummy.o
then use the Makefile to fetch $(NOSTDINC_FLAGS), $(LINUXINCLUDE) and
$(EXTRA_CFLAGS) options. The result is passed to compiler script using
'KERNEL_INC_OPTIONS' environment variable.

Because options from kbuild contains relative path like
'Iinclude/generated/uapi', the work directory must be changed. This is
done by previous patch.

Signed-off-by: Wang Nan 
---
 tools/perf/util/llvm-utils.c | 59 
 1 file changed, 54 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index 7b2217a..3c43fcf 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -215,15 +215,42 @@ static const char *kbuild_detector =
 "fi\n"
 "exit -1\n";
 
+static const char *kinc_fetch_script =
+"#!/usr/bin/env sh\n"
+"if ! test -d \"$KBUILD_DIR\"\n"
+"then\n"
+"  exit -1\n"
+"fi\n"
+"if ! test -f \"$KBUILD_DIR/include/generated/autoconf.h\"\n"
+"then\n"
+"  exit -1\n"
+"fi\n"
+"TMPDIR=`mktemp -d`\n"
+"if test -z \"$TMPDIR\"\n"
+"then\n"
+"exit -1\n"
+"fi\n"
+"cat << EOF > $TMPDIR/Makefile\n"
+"obj-y := dummy.o\n"
+"\\$(obj)/%.o: \\$(src)/%.c\n"
+"\t@echo -n \"\\$(NOSTDINC_FLAGS) \\$(LINUXINCLUDE) \\$(EXTRA_CFLAGS)\"\n"
+"EOF\n"
+"touch $TMPDIR/dummy.c\n"
+"make -s -C $KBUILD_DIR M=$TMPDIR $KBUILD_OPTS dummy.o 2>/dev/null\n"
+"RET=$?\n"
+"rm -rf $TMPDIR\n"
+"exit $RET\n";
+
 static inline void
-get_kbuild_opts(char **kbuild_dir)
+get_kbuild_opts(char **kbuild_dir, char **kbuild_include_opts)
 {
int err;
 
-   if (!kbuild_dir)
+   if (!kbuild_dir || !kbuild_include_opts)
return;
 
*kbuild_dir = NULL;
+   *kbuild_include_opts = NULL;
 
if (llvm_param.kbuild_dir && !llvm_param.kbuild_dir[0]) {
pr_debug("[llvm.kbuild-dir] is set to \"\" deliberately.\n");
@@ -244,6 +271,26 @@ get_kbuild_opts(char **kbuild_dir)
 " \tdetection.\n\n");
return;
}
+
+   pr_debug("Kernel build dir is set to %s\n", *kbuild_dir);
+   force_set_env("KBUILD_DIR", *kbuild_dir);
+   err = read_from_pipe(kinc_fetch_script,
+(void **)kbuild_include_opts,
+NULL);
+   if (err) {
+   pr_warning(
+"WARNING:\tunable to get kernel include directories from '%s'\n"
+"Hint:\tTry set clang include options using 'clang-bpf-cmd-template'\n"
+" \toption in [llvm] section of ~/.perfconfig and set 'kbuild-dir'\n"
+" \toption in [llvm] to \"\" to suppress this detection.\n\n",
+   *kbuild_dir);
+
+   free(*kbuild_dir);
+   *kbuild_dir = NULL;
+   return;
+   }
+
+   pr_debug("include option is set to %s\n", *kbuild_include_opts);
 }
 
 int llvm__compile_bpf(const char *path, void **p_obj_buf,
@@ -253,7 +300,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
char clang_path[PATH_MAX];
const char *clang_opt = llvm_param.clang_opt;
const char *template = llvm_param.clang_bpf_cmd_template;
-   char *kbuild_dir = NULL;
+   char *kbuild_dir = NULL, *kbuild_include_opts = NULL;
void *obj_buf = NULL;
size_t obj_buf_sz;
 
@@ -275,11 +322,11 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
 * This is an optional work. Even it fail we can continue our
 * work. Needn't to check error return.
 */
-   get_kbuild_opts(_dir);
+   get_kbuild_opts(_dir, _include_opts);
 
force_set_env("CLANG_EXEC", clang_path);
force_set_env("CLANG_OPTIONS", clang_opt);
-   force_set_env("KERNEL_INC_OPTIONS", NULL);
+   force_set_env("KERNEL_INC_OPTIONS", kbuild_include_opts);
force_set_env("WORKING_DIR", kbuild_dir ? : ".");
 
/*
@@ -302,6 +349,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
}
 
free(kbuild_dir);
+   free(kbuild_include_opts);
if (!p_obj_buf)
free(obj_buf);
else
@@ -312,6 +360,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
return 0;
 errout:
free(kbuild_dir);
+   free(kbuild_include_opts);
free(obj_buf);
if (p_obj_buf)
*p_obj_buf = NULL;
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v7 31/37] perf probe: Attach trace_probe_event with perf_probe_event

2015-06-11 Thread Wang Nan
This patch drops struct __event_package structure. Instead, it adds
trace_probe_event into 'struct perf_probe_event'.

trace_probe_event information give further patches a chance to access
actual probe points and actual arguments. Using them, bpf_loader will
be able to attach one bpf program to different probing points of a
inline functions (which has multiple probing points) and glob
functions. Moreover, by reading arguments information, bpf code for
reading those arguments can be generated.

Signed-off-by: Wang Nan 
---
 tools/perf/builtin-probe.c|  2 +-
 tools/perf/util/probe-event.c | 57 +--
 tools/perf/util/probe-event.h |  5 +++-
 3 files changed, 33 insertions(+), 31 deletions(-)

diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 1272559..0218725 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -497,7 +497,7 @@ __cmd_probe(int argc, const char **argv, const char *prefix 
__maybe_unused)
usage_with_options(probe_usage, options);
}
 
-   ret = add_perf_probe_events(params.events, params.nevents);
+   ret = add_perf_probe_events(params.events, params.nevents, 
true);
if (ret < 0) {
pr_err_with_code("  Error: Failed to add events.", ret);
return ret;
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index d4cf50b..1609a5e 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -1878,6 +1878,9 @@ void clear_perf_probe_event(struct perf_probe_event *pev)
struct perf_probe_arg_field *field, *next;
int i;
 
+   if (pev->ntevs)
+   cleanup_perf_probe_event(pev);
+
free(pev->event);
free(pev->group);
free(pev->target);
@@ -2685,56 +2688,52 @@ static int convert_to_probe_trace_events(struct 
perf_probe_event *pev,
return find_probe_trace_events_from_map(pev, tevs);
 }
 
-struct __event_package {
-   struct perf_probe_event *pev;
-   struct probe_trace_event*tevs;
-   int ntevs;
-};
-
-int add_perf_probe_events(struct perf_probe_event *pevs, int npevs)
+int cleanup_perf_probe_event(struct perf_probe_event *pev)
 {
-   int i, j, ret;
-   struct __event_package *pkgs;
+   int i;
 
-   ret = 0;
-   pkgs = zalloc(sizeof(struct __event_package) * npevs);
+   if (!pev || !pev->ntevs)
+   return 0;
 
-   if (pkgs == NULL)
-   return -ENOMEM;
+   for (i = 0; i < pev->ntevs; i++)
+   clear_probe_trace_event(>tevs[i]);
+
+   zfree(>tevs);
+   pev->ntevs = 0;
+   return 0;
+}
+
+int add_perf_probe_events(struct perf_probe_event *pevs, int npevs, bool 
cleanup)
+{
+   int i, ret;
 
ret = init_symbol_maps(pevs->uprobes);
-   if (ret < 0) {
-   free(pkgs);
+   if (ret < 0)
return ret;
-   }
 
/* Loop 1: convert all events */
for (i = 0; i < npevs; i++) {
-   pkgs[i].pev = [i];
/* Convert with or without debuginfo */
-   ret  = convert_to_probe_trace_events(pkgs[i].pev,
-[i].tevs);
-   if (ret < 0)
+   ret  = convert_to_probe_trace_events([i], [i].tevs);
+   if (ret < 0) {
+   cleanup = true;
goto end;
-   pkgs[i].ntevs = ret;
+   }
+   pevs[i].ntevs = ret;
}
 
/* Loop 2: add all events */
for (i = 0; i < npevs; i++) {
-   ret = __add_probe_trace_events(pkgs[i].pev, pkgs[i].tevs,
-  pkgs[i].ntevs,
+   ret = __add_probe_trace_events([i], pevs[i].tevs,
+  pevs[i].ntevs,
   probe_conf.force_add);
if (ret < 0)
break;
}
 end:
/* Loop 3: cleanup and free trace events  */
-   for (i = 0; i < npevs; i++) {
-   for (j = 0; j < pkgs[i].ntevs; j++)
-   clear_probe_trace_event([i].tevs[j]);
-   zfree([i].tevs);
-   }
-   free(pkgs);
+   for (i = 0; cleanup && (i < npevs); i++)
+   cleanup_perf_probe_event([i]);
exit_symbol_maps();
 
return ret;
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index 31db6ee..40dd22b 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -86,6 +86,8 @@ struct perf_probe_event {
booluprobes;/* Uprobe event flag */
char*target;/* Target binary */
struct perf_probe_arg   *args;  /* Arguments */
+   struct 

[RFC PATCH v7 30/37] perf tools: Parse probe points of eBPF programs during preparation

2015-06-11 Thread Wang Nan
This patch parses section name of each program, and creates
corresponding 'struct perf_probe_event' structure.

parse_perf_probe_command() is used to do the main parsing works.
Parsing result is stored into a global array. This is because
add_perf_probe_events() is non-reentrantable. In following patch,
add_perf_probe_events will be introduced to insert kprobes. It accepts
an array of 'struct perf_probe_event' and do all works in one call.

Define PERF_BPF_PROBE_GROUP as "perf_bpf_probe", which will be used
as group name of all eBPF probing points.

This patch utilizes bpf_program__set_private(), bind perf_probe_event
with bpf program by private field.

Signed-off-by: Wang Nan 
---
 tools/perf/util/bpf-loader.c | 124 ++-
 tools/perf/util/bpf-loader.h |   2 +
 2 files changed, 124 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index 1083b3c..a202702 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -10,6 +10,8 @@
 #include "debug.h"
 #include "bpf-loader.h"
 #include "llvm-utils.h"
+#include "probe-event.h"
+#include "probe-finder.h"
 
 #define DEFINE_PRINT_FN(name, level) \
 static int libbpf_##name(const char *fmt, ...) \
@@ -29,9 +31,120 @@ DEFINE_PRINT_FN(debug, 1)
 
 static bool libbpf_initialized = false;
 
+static struct perf_probe_event probe_event_array[MAX_PROBES];
+static size_t nr_probe_events;
+
+static struct perf_probe_event *
+alloc_perf_probe_event(void)
+{
+   struct perf_probe_event *pev;
+   int n = nr_probe_events;
+   if (n >= MAX_PROBES) {
+   pr_err("bpf: too many events, increase MAX_PROBES\n");
+   return NULL;
+   }
+
+   nr_probe_events = n + 1;
+   pev = _event_array[n];
+   bzero(pev, sizeof(*pev));
+   return pev;
+}
+
+struct bpf_prog_priv {
+   struct perf_probe_event *pev;
+};
+
+static void
+bpf_prog_priv__clear(struct bpf_program *prog __maybe_unused,
+ void *_priv)
+{
+   struct bpf_prog_priv *priv = _priv;
+   if (priv->pev)
+   clear_perf_probe_event(priv->pev);
+   free(priv);
+}
+
+static int
+config_bpf_program(struct bpf_program *prog)
+{
+   struct perf_probe_event *pev = alloc_perf_probe_event();
+   struct bpf_prog_priv *priv = NULL;
+   const char *config_str;
+   int err;
+
+   /* pr_err has been done by alloc_perf_probe_event */
+   if (!pev)
+   return -ENOMEM;
+
+   err = bpf_program__get_title(prog, _str, false);
+   if (err || !config_str) {
+   pr_err("bpf: unable to get title for program\n");
+   return -EINVAL;
+   }
+
+   pr_debug("bpf: config program '%s'\n", config_str);
+   err = parse_perf_probe_command(config_str, pev);
+   if (err < 0) {
+   pr_err("bpf: '%s' is not a valid config string\n",
+  config_str);
+   /* parse failed, don't need clear pev. */
+   return -EINVAL;
+   }
+
+   if (pev->group && strcmp(pev->group, PERF_BPF_PROBE_GROUP)) {
+   pr_err("bpf: '%s': group for event is set and not '%s'.\n",
+  config_str, PERF_BPF_PROBE_GROUP);
+   err = -EINVAL;
+   goto errout;
+   } else if (!pev->group)
+   pev->group = strdup(PERF_BPF_PROBE_GROUP);
+
+   if (!pev->group) {
+   pr_err("bpf: strdup failed\n");
+   err = -ENOMEM;
+   goto errout;
+   }
+
+   if (!pev->event) {
+   pr_err("bpf: '%s': event name is missing\n",
+  config_str);
+   err = -EINVAL;
+   goto errout;
+   }
+
+   pr_debug("bpf: config '%s' is ok\n", config_str);
+
+   priv = calloc(1, sizeof(*priv));
+   if (!priv) {
+   pr_err("bpf: failed to alloc memory\n");
+   err = -ENOMEM;
+   goto errout;
+   }
+
+   priv->pev = pev;
+
+   err = bpf_program__set_private(prog, priv,
+  bpf_prog_priv__clear);
+   if (err) {
+   pr_err("bpf: set program private failed\n");
+   err = -ENOMEM;
+   goto errout;
+   }
+   return 0;
+
+errout:
+   if (pev)
+   clear_perf_probe_event(pev);
+   if (priv)
+   free(priv);
+   return err;
+}
+
 int bpf__prepare_load(const char *filename, bool source)
 {
struct bpf_object *obj;
+   struct bpf_program *prog;
+   int err = 0;
 
if (!libbpf_initialized)
libbpf_set_print(libbpf_warning,
@@ -41,7 +154,6 @@ int bpf__prepare_load(const char *filename, bool source)
if (source) {
void *obj_buf;
size_t obj_buf_sz;
-   int err;
 
err = llvm__compile_bpf(filename, _buf, _buf_sz);
if (err)
@@ -56,12 

Re: [PATCH 1/1] staging:f81534 Add F81532/534 Driver

2015-06-11 Thread Peter Hung

Greg KH 於 2015/6/12 下午 12:33 寫道:

Why not just do the work now to clean up the file and get it merged
"properly"?  Why put this in staging at all?



I'll clear up the file and resend it to usb-serial subsystem mail list.
Thanks for your advices.

--
With Best Regards,
Peter Hung
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v7 32/37] perf record: Probe at kprobe points

2015-06-11 Thread Wang Nan
In this patch, kprobe points are created using add_perf_probe_events.
Since all events are already grouped together in an array, calling
add_perf_probe_events() once creates all of them.

probe_conf.max_probes is set to MAX_PROBES to support glob matching.

Signed-off-by: Wang Nan 
---
 tools/perf/builtin-record.c  | 18 -
 tools/perf/util/bpf-loader.c | 48 
 tools/perf/util/bpf-loader.h |  4 
 3 files changed, 69 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index d3731cc..29f7b40 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -29,6 +29,7 @@
 #include "util/data.h"
 #include "util/auxtrace.h"
 #include "util/parse-branch-options.h"
+#include "util/bpf-loader.h"
 
 #include 
 #include 
@@ -1106,7 +1107,21 @@ int cmd_record(int argc, const char **argv, const char 
*prefix __maybe_unused)
if (err)
return err;
 
-   err = -ENOMEM;
+   /*
+* bpf__probe must be called before symbol__init() because we
+* need init_symbol_maps. If called after symbol__init,
+* symbol_conf.sort_by_name won't take effect.
+*
+* bpf__unprobe() is safe even if bpf__probe() failed, and it
+* also calls symbol__init. Therefore, goto out_symbol_exit
+* is safe when probe failed.
+*/
+   err = bpf__probe();
+   if (err) {
+   pr_err("Probing at events in BPF object failed.\n");
+   pr_err("Try perf probe -d '*' to remove existing probe 
events.\n");
+   goto out_symbol_exit;
+   }
 
symbol__init(NULL);
 
@@ -1167,6 +1182,7 @@ out_symbol_exit:
perf_evlist__delete(rec->evlist);
symbol__exit();
auxtrace_record__free(rec->itr);
+   bpf__unprobe();
return err;
 }
 
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index a202702..cb11561 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -191,3 +191,51 @@ void bpf__clear(void)
bpf_object__for_each(obj, tmp)
bpf_object__close(obj);
 }
+
+static bool is_probing = false;
+
+int bpf__unprobe(void)
+{
+   struct strfilter *delfilter;
+   int ret;
+
+   if (!is_probing)
+   return 0;
+
+   delfilter = strfilter__new(PERF_BPF_PROBE_GROUP ":*", NULL);
+   if (!delfilter) {
+   pr_err("Failed to create delfilter when unprobing\n");
+   return -ENOMEM;
+   }
+
+   ret = del_perf_probe_events(delfilter);
+   strfilter__delete(delfilter);
+   if (ret < 0 && is_probing)
+   pr_err("Error: failed to delete events: %s\n",
+   strerror(-ret));
+   else
+   is_probing = false;
+   return ret < 0 ? ret : 0;
+}
+
+int bpf__probe(void)
+{
+   int err;
+
+   if (nr_probe_events <= 0)
+   return 0;
+
+   probe_conf.max_probes = MAX_PROBES;
+   /* Let add_perf_probe_events keeps probe_trace_event */
+   err = add_perf_probe_events(probe_event_array,
+   nr_probe_events,
+   false);
+
+   /* add_perf_probe_events return negative when fail */
+   if (err < 0)
+   pr_err("bpf probe: failed to probe events\n");
+   else
+   is_probing = true;
+
+   return err < 0 ? err : 0;
+}
diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h
index 5a3c954..374aec0 100644
--- a/tools/perf/util/bpf-loader.h
+++ b/tools/perf/util/bpf-loader.h
@@ -12,6 +12,8 @@
 
 #ifdef HAVE_LIBBPF_SUPPORT
 int bpf__prepare_load(const char *filename, bool source);
+int bpf__probe(void);
+int bpf__unprobe(void);
 
 void bpf__clear(void);
 #else
@@ -22,6 +24,8 @@ static inline int bpf__prepare_load(const char *filename 
__maybe_unused,
return -1;
 }
 
+static inline int bpf__probe(void) { return 0; }
+static inline int bpf__unprobe(void) { return 0; }
 static inline void bpf__clear(void) { }
 #endif
 #endif
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v7 23/37] perf tools: Introduce llvm config options

2015-06-11 Thread Wang Nan
This patch introduces [llvm] config section with 5 options. Following
patches will use then to config llvm dynamica compiling.

'llvm-utils.[ch]' is introduced in this patch for holding all
llvm/clang related stuffs.

Example:

  [llvm]
# Path to clang. If omit, search it from $PATH.
clang-path = "/path/to/clang"

# Cmdline template. Following line shows its default value.
# Environment variable is used to passing options.
clang-bpf-cmd-template = "$CLANG_EXEC $CLANG_OPTIONS 
$KERNEL_INC_OPTIONS -Wno-unused-value -Wno-pointer-sign -working-directory 
$WORKING_DIR  -c $CLANG_SOURCE -target bpf -O2 -o -"

# Options passed to clang, will be passed to cmdline by $CLANG_OPTIONS.
clang-opt = "-Wno-unused-value -Wno-pointer-sign"

# kbuild directory. If not set, use /lib/modules/`uname -r`/build.
# If set to "" deliberately, skip kernel header auto-detector.
kbuild-dir = "/path/to/kernel/build"

# Options passed to 'make' when detecting kernel header options.
kbuild-opts = "ARCH=x86_64"

Signed-off-by: Wang Nan 
---
 tools/perf/util/Build|  1 +
 tools/perf/util/config.c |  4 
 tools/perf/util/llvm-utils.c | 45 
 tools/perf/util/llvm-utils.h | 36 +++
 4 files changed, 86 insertions(+)
 create mode 100644 tools/perf/util/llvm-utils.c
 create mode 100644 tools/perf/util/llvm-utils.h

diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 586a59d..edd48b5 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -14,6 +14,7 @@ libperf-y += find_next_bit.o
 libperf-y += help.o
 libperf-y += kallsyms.o
 libperf-y += levenshtein.o
+libperf-y += llvm-utils.o
 libperf-y += parse-options.o
 libperf-y += parse-events.o
 libperf-y += path.o
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index e18f653..2e452ac 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -12,6 +12,7 @@
 #include "cache.h"
 #include "exec_cmd.h"
 #include "util/hist.h"  /* perf_hist_config */
+#include "util/llvm-utils.h"   /* perf_llvm_config */
 
 #define MAXNAME (256)
 
@@ -408,6 +409,9 @@ int perf_default_config(const char *var, const char *value,
if (!prefixcmp(var, "call-graph."))
return perf_callchain_config(var, value);
 
+   if (!prefixcmp(var, "llvm."))
+   return perf_llvm_config(var, value);
+
/* Add other config variables here. */
return 0;
 }
diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
new file mode 100644
index 000..7dc1f1e
--- /dev/null
+++ b/tools/perf/util/llvm-utils.c
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2015, Wang Nan 
+ * Copyright (C) 2015, Huawei Inc.
+ */
+
+#include 
+#include "util.h"
+#include "debug.h"
+#include "llvm-utils.h"
+#include "cache.h"
+
+#define CLANG_BPF_CMD_DEFAULT_TEMPLATE \
+   "$CLANG_EXEC $CLANG_OPTIONS $KERNEL_INC_OPTIONS " \
+   "-Wno-unused-value -Wno-pointer-sign "  \
+   "-working-directory $WORKING_DIR "  \
+   " -c \"$CLANG_SOURCE\" -target bpf -O2 -o -"
+
+struct llvm_param llvm_param = {
+   .clang_path = "clang",
+   .clang_bpf_cmd_template = CLANG_BPF_CMD_DEFAULT_TEMPLATE,
+   .clang_opt = NULL,
+   .kbuild_dir = NULL,
+   .kbuild_opts = NULL,
+};
+
+int perf_llvm_config(const char *var, const char *value)
+{
+   if (prefixcmp(var, "llvm."))
+   return 0;
+   var += sizeof("llvm.") - 1;
+
+   if (!strcmp(var, "clang-path"))
+   llvm_param.clang_path = strdup(value);
+   else if (!strcmp(var, "clang-bpf-cmd-template"))
+   llvm_param.clang_bpf_cmd_template = strdup(value);
+   else if (!strcmp(var, "clang-opt"))
+   llvm_param.clang_opt = strdup(value);
+   else if (!strcmp(var, "kbuild-dir"))
+   llvm_param.kbuild_dir = strdup(value);
+   else if (!strcmp(var, "kbuild-opts"))
+   llvm_param.kbuild_opts = strdup(value);
+   else
+   return -1;
+   return 0;
+}
diff --git a/tools/perf/util/llvm-utils.h b/tools/perf/util/llvm-utils.h
new file mode 100644
index 000..504b799
--- /dev/null
+++ b/tools/perf/util/llvm-utils.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2015, Wang Nan 
+ * Copyright (C) 2015, Huawei Inc.
+ */
+#ifndef __LLVM_UTILS_H
+#define __LLVM_UTILS_H
+
+#include "debug.h"
+
+struct llvm_param {
+   /* Path of clang executable */
+   const char *clang_path;
+   /*
+* Template of clang bpf compiling. 5 env variables
+* can be used:
+*   $CLANG_EXEC:   Path to clang.
+*   $CLANG_OPTIONS:Extra options to clang.
+*   $KERNEL_INC_OPTIONS:   Kernel include directories.
+*   $WORKING_DIR:  Kernel source directory.
+*   

[RFC PATCH v7 29/37] perf record: Compile scriptlets if pass '.c' to --event

2015-06-11 Thread Wang Nan
This patch enables passing source files to --event directly using:

 # perf record --event bpf-file.c command

This patch does following works:
 1) Allow passing '.c' file to '--event'. parse_events_load_bpf() is
expanded to allow caller tell it whether the passed file is source
file or object.

 2) llvm__compile_bpf() is called to compile the '.c' file, the result
is saved into memory. Use bpf_object__open_buffer() to load the
in-memory object.

Signed-off-by: Wang Nan 
---
 tools/perf/util/bpf-loader.c   | 17 +++--
 tools/perf/util/bpf-loader.h   |  5 +++--
 tools/perf/util/parse-events.c |  4 ++--
 tools/perf/util/parse-events.h |  2 +-
 tools/perf/util/parse-events.l |  3 +++
 tools/perf/util/parse-events.y | 15 +--
 6 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index e950baa..1083b3c 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -9,6 +9,7 @@
 #include "perf.h"
 #include "debug.h"
 #include "bpf-loader.h"
+#include "llvm-utils.h"
 
 #define DEFINE_PRINT_FN(name, level) \
 static int libbpf_##name(const char *fmt, ...) \
@@ -28,7 +29,7 @@ DEFINE_PRINT_FN(debug, 1)
 
 static bool libbpf_initialized = false;
 
-int bpf__prepare_load(const char *filename)
+int bpf__prepare_load(const char *filename, bool source)
 {
struct bpf_object *obj;
 
@@ -37,7 +38,19 @@ int bpf__prepare_load(const char *filename)
 libbpf_info,
 libbpf_debug);
 
-   obj = bpf_object__open(filename);
+   if (source) {
+   void *obj_buf;
+   size_t obj_buf_sz;
+   int err;
+
+   err = llvm__compile_bpf(filename, _buf, _buf_sz);
+   if (err)
+   return err;
+   obj = bpf_object__open_buffer(obj_buf, obj_buf_sz);
+   free(obj_buf);
+   } else
+   obj = bpf_object__open(filename);
+
if (!obj) {
pr_err("bpf: failed to load %s\n", filename);
return -EINVAL;
diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h
index 39d8d1a..5566be0 100644
--- a/tools/perf/util/bpf-loader.h
+++ b/tools/perf/util/bpf-loader.h
@@ -9,11 +9,12 @@
 #include "debug.h"
 
 #ifdef HAVE_LIBBPF_SUPPORT
-int bpf__prepare_load(const char *filename);
+int bpf__prepare_load(const char *filename, bool source);
 
 void bpf__clear(void);
 #else
-static inline int bpf__prepare_load(const char *filename __maybe_unused)
+static inline int bpf__prepare_load(const char *filename __maybe_unused,
+   bool source __maybe_unused)
 {
pr_err("ERROR: eBPF object loading is disabled during compiling.\n");
return -1;
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 6f7a7b1..aaee24c 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -475,7 +475,7 @@ int parse_events_add_tracepoint(struct list_head *list, int 
*idx,
 
 int parse_events_load_bpf(struct list_head *list __maybe_unused,
  int *idx __maybe_unused,
- char *bpf_file_name)
+ char *bpf_file_name, bool source)
 {
/*
 * Currently don't link any event to list. BPF object files
@@ -485,7 +485,7 @@ int parse_events_load_bpf(struct list_head *list 
__maybe_unused,
 * problem. After that probe events file by file is possible.
 * However, probing cost is still need to be considered.
 */
-   return bpf__prepare_load(bpf_file_name);
+   return bpf__prepare_load(bpf_file_name, source);
 }
 
 static int
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index 41b962a..5841d4f 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -115,7 +115,7 @@ int parse_events_name(struct list_head *list, char *name);
 int parse_events_add_tracepoint(struct list_head *list, int *idx,
char *sys, char *event);
 int parse_events_load_bpf(struct list_head *list, int *idx,
- char *bpf_file_name);
+ char *bpf_file_name, bool source);
 int parse_events_add_numeric(struct parse_events_evlist *data,
 struct list_head *list,
 u32 type, u64 config,
diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l
index 4acea38..eb821d4 100644
--- a/tools/perf/util/parse-events.l
+++ b/tools/perf/util/parse-events.l
@@ -116,6 +116,7 @@ group   [^,{}/]*[{][^}]*[}][^,{}/]*
 event_pmu  [^,{}/]+[/][^/]*[/][^,{}/]*
 event  [^,{}/]+
 bpf_object .*\.(o|bpf)
+bpf_source .*\.c
 
 num_dec[0-9]+
 num_hex0x[a-fA-F0-9]+
@@ -161,6 +162,7 @@ modifier_bp [rwx]{1,3}
 
 {event_pmu}|
 

[RFC PATCH v7 33/37] perf record: Load all eBPF object into kernel

2015-06-11 Thread Wang Nan
This patch utilizes bpf_load_object() provided by libbpf to load all
objects into kernel.

Signed-off-by: Wang Nan 
---
 tools/perf/builtin-record.c  | 12 
 tools/perf/util/bpf-loader.c | 19 +++
 tools/perf/util/bpf-loader.h |  2 ++
 3 files changed, 33 insertions(+)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 29f7b40..7fcce98 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1123,6 +1123,18 @@ int cmd_record(int argc, const char **argv, const char 
*prefix __maybe_unused)
goto out_symbol_exit;
}
 
+   /*
+* bpf__probe() also calls symbol__init() if there are probe
+* events in bpf objects, so calling symbol_exit when failuer
+* is safe. If there is no probe event, bpf__load() always
+* success.
+*/
+   err = bpf__load();
+   if (err) {
+   pr_err("Loading BPF programs failed\n");
+   goto out_symbol_exit;
+   }
+
symbol__init(NULL);
 
if (symbol_conf.kptr_restrict)
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index cb11561..54bda7e 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -239,3 +239,22 @@ int bpf__probe(void)
 
return err < 0 ? err : 0;
 }
+
+int bpf__load(void)
+{
+   struct bpf_object *obj, *tmp;
+   int err = 0;
+
+   bpf_object__for_each(obj, tmp) {
+   err = bpf_object__load(obj);
+   if (err) {
+   pr_err("bpf: load objects failed\n");
+   goto errout;
+   }
+   }
+   return 0;
+errout:
+   bpf_object__for_each(obj, tmp)
+   bpf_object__unload(obj);
+   return err;
+}
diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h
index 374aec0..ae0dc9b 100644
--- a/tools/perf/util/bpf-loader.h
+++ b/tools/perf/util/bpf-loader.h
@@ -14,6 +14,7 @@
 int bpf__prepare_load(const char *filename, bool source);
 int bpf__probe(void);
 int bpf__unprobe(void);
+int bpf__load(void);
 
 void bpf__clear(void);
 #else
@@ -26,6 +27,7 @@ static inline int bpf__prepare_load(const char *filename 
__maybe_unused,
 
 static inline int bpf__probe(void) { return 0; }
 static inline int bpf__unprobe(void) { return 0; }
+static inline int bpf__load(void) { return 0; }
 static inline void bpf__clear(void) { }
 #endif
 #endif
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v7 36/37] perf tools: Suppress probing messages when probing by BPF loading

2015-06-11 Thread Wang Nan
This patch suppress message output by add_perf_probe_events() and
del_perf_probe_events() if they are triggered by BPF loading. Before
this patch, when using 'perf record' with BPF object/source as event
selector, following message will be output:

 Added new event:
   perf_bpf_probe:lock_page_ret (on __lock_page%return)
You can now use it in all perf tools, such as:
perf record -e perf_bpf_probe:lock_page_ret -aR sleep 1
 ...
 Removed event: perf_bpf_probe:lock_page_ret

Which is misleading, especially 'use it in all perf tools' because they
will be removed after 'pref record' exit.

In this patch, a 'silent' field is appended into probe_conf to control
output. bpf__{,un}probe() set it to true when calling
{add,del}_perf_probe_events().

Signed-off-by: Wang Nan 
---
 tools/perf/util/bpf-loader.c  |  6 ++
 tools/perf/util/probe-event.c | 19 ++-
 tools/perf/util/probe-event.h |  1 +
 3 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index 00fb94f..2936adf 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -197,6 +197,7 @@ static bool is_probing = false;
 int bpf__unprobe(void)
 {
struct strfilter *delfilter;
+   bool old_silent = probe_conf.silent;
int ret;
 
if (!is_probing)
@@ -208,7 +209,9 @@ int bpf__unprobe(void)
return -ENOMEM;
}
 
+   probe_conf.silent = true;
ret = del_perf_probe_events(delfilter);
+   probe_conf.silent = old_silent;
strfilter__delete(delfilter);
if (ret < 0 && is_probing)
pr_err("Error: failed to delete events: %s\n",
@@ -221,15 +224,18 @@ int bpf__unprobe(void)
 int bpf__probe(void)
 {
int err;
+   bool old_silent = probe_conf.silent;
 
if (nr_probe_events <= 0)
return 0;
 
+   probe_conf.silent = true;
probe_conf.max_probes = MAX_PROBES;
/* Let add_perf_probe_events keeps probe_trace_event */
err = add_perf_probe_events(probe_event_array,
nr_probe_events,
false);
+   probe_conf.silent = old_silent;
 
/* add_perf_probe_events return negative when fail */
if (err < 0)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 1609a5e..a46bef3 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -51,7 +51,9 @@
 #define PERFPROBE_GROUP "probe"
 
 bool probe_event_dry_run;  /* Dry run flag */
-struct probe_conf probe_conf;
+struct probe_conf probe_conf = {
+   .silent = false,
+};
 
 #define semantic_error(msg ...) pr_err("Semantic error :" msg)
 
@@ -2416,7 +2418,10 @@ static int __add_probe_trace_events(struct 
perf_probe_event *pev,
 
safename = (pev->point.function && !strisglob(pev->point.function));
ret = 0;
-   pr_info("Added new event%s\n", (ntevs > 1) ? "s:" : ":");
+   if (!probe_conf.silent)
+   pr_info("Added new event%s\n", (ntevs > 1) ? "s:" : ":");
+   else
+   pr_debug("Added new event%s\n", (ntevs > 1) ? "s:" : ":");
for (i = 0; i < ntevs; i++) {
tev = [i];
/* Skip if the symbol is out of .text (marked previously) */
@@ -2466,7 +2471,8 @@ static int __add_probe_trace_events(struct 
perf_probe_event *pev,
group = pev->group;
pev->event = tev->event;
pev->group = tev->group;
-   show_perf_probe_event(pev, tev->point.module);
+   if (!probe_conf.silent)
+   show_perf_probe_event(pev, tev->point.module);
/* Trick here - restore current event/group */
pev->event = (char *)event;
pev->group = (char *)group;
@@ -2483,7 +2489,7 @@ static int __add_probe_trace_events(struct 
perf_probe_event *pev,
warn_uprobe_event_compat(tev);
 
/* Note that it is possible to skip all events because of blacklist */
-   if (ret >= 0 && tev->event) {
+   if (ret >= 0 && tev->event && !probe_conf.silent) {
/* Show how to use the event. */
pr_info("\nYou can now use it in all perf tools, such as:\n\n");
pr_info("\tperf record -e %s:%s -aR sleep 1\n\n", tev->group,
@@ -2766,7 +2772,10 @@ static int __del_trace_probe_event(int fd, struct 
str_node *ent)
goto error;
}
 
-   pr_info("Removed event: %s\n", ent->s);
+   if (!probe_conf.silent)
+   pr_info("Removed event: %s\n", ent->s);
+   else
+   pr_debug("Removed event: %s\n", ent->s);
return 0;
 error:
pr_warning("Failed to delete event: %s\n",
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index 40dd22b..dd7c630 100644
--- a/tools/perf/util/probe-event.h
+++ 

[RFC PATCH v7 01/37] tools build: Add feature check for eBPF API

2015-06-11 Thread Wang Nan
In this patch, eBPF API is checked by compiling a c source file which
uses fields in bpf_attr which will be used by libbpf.

Signed-off-by: Wang Nan 
Acked-by: Alexei Starovoitov 
---
 tools/build/Makefile.feature   |  6 --
 tools/build/feature/Makefile   |  6 +-
 tools/build/feature/test-bpf.c | 18 ++
 3 files changed, 27 insertions(+), 3 deletions(-)
 create mode 100644 tools/build/feature/test-bpf.c

diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
index 2975632..5ec6b37 100644
--- a/tools/build/Makefile.feature
+++ b/tools/build/Makefile.feature
@@ -51,7 +51,8 @@ FEATURE_TESTS ?=  \
timerfd \
libdw-dwarf-unwind  \
zlib\
-   lzma
+   lzma\
+   bpf
 
 FEATURE_DISPLAY ?= \
dwarf   \
@@ -67,7 +68,8 @@ FEATURE_DISPLAY ?=\
libunwind   \
libdw-dwarf-unwind  \
zlib\
-   lzma
+   lzma\
+   bpf
 
 # Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features.
 # If in the future we need per-feature checks/flags for features not
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index 463ed8f..1c0d69f 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -33,7 +33,8 @@ FILES=\
test-compile-32.bin \
test-compile-x32.bin\
test-zlib.bin   \
-   test-lzma.bin
+   test-lzma.bin   \
+   test-bpf.bin
 
 CC := $(CROSS_COMPILE)gcc -MD
 PKG_CONFIG := $(CROSS_COMPILE)pkg-config
@@ -156,6 +157,9 @@ test-zlib.bin:
 test-lzma.bin:
$(BUILD) -llzma
 
+test-bpf.bin:
+   $(BUILD)
+
 -include *.d
 
 ###
diff --git a/tools/build/feature/test-bpf.c b/tools/build/feature/test-bpf.c
new file mode 100644
index 000..a96160b
--- /dev/null
+++ b/tools/build/feature/test-bpf.c
@@ -0,0 +1,18 @@
+#include 
+
+int main()
+{
+   union bpf_attr attr;
+
+   attr.prog_type = BPF_PROG_TYPE_KPROBE;
+   attr.insn_cnt = 0;
+   attr.insns = 0;
+   attr.license = 0;
+   attr.log_buf = 0;
+   attr.log_size = 0;
+   attr.log_level = 0;
+   attr.kern_version = 0;
+
+   attr = attr;
+   return 0;
+}
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v7 35/37] perf tools: Attach eBPF program to perf event

2015-06-11 Thread Wang Nan
In this patch PERF_EVENT_IOC_SET_BPF ioctl is used to attach eBPF
program to a newly created perf event. The file descriptor of the
eBPF program is passed to perf record using previous patches, and
stored into evsel->bpf_fd.

It is possible that different perf event are created for one kprobe
events for different CPUs. In this case, when trying to call the
ioctl, EEXIST will be return. This patch doesn't treat it as an error.

Signed-off-by: Wang Nan 
---
 tools/perf/util/evsel.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index e5cbfcd..4a84630 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1202,6 +1202,22 @@ retry_open:
  err);
goto try_fallback;
}
+
+   if (evsel->bpf_fd >= 0) {
+   int evt_fd = FD(evsel, cpu, thread);
+   int bpf_fd = evsel->bpf_fd;
+
+   err = ioctl(evt_fd,
+   PERF_EVENT_IOC_SET_BPF,
+   bpf_fd);
+   if (err && errno != EEXIST) {
+   pr_err("failed to attach bpf fd %d: 
%s\n",
+  bpf_fd, strerror(errno));
+   err = -EINVAL;
+   goto out_close;
+   }
+   }
+
set_rlimit = NO_CHANGE;
 
/*
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v7 03/37] bpf tools: Allow caller to set printing function

2015-06-11 Thread Wang Nan
By libbpf_set_print(), users of libbpf are allowed to register he/she
own debug, info and warning printing functions. Libbpf will use those
functions to print messages. If not provided, default info and warning
printing functions are fprintf(stderr, ...); default debug printing
is NULL.

This API is designed to be used by perf, enables it to register its own
logging functions to make all logs uniform, instead of separated
logging level control.

Signed-off-by: Wang Nan 
Acked-by: Alexei Starovoitov 
---
 tools/lib/bpf/libbpf.c | 40 
 tools/lib/bpf/libbpf.h | 12 
 2 files changed, 52 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index c08d6bc..ded37a0 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -7,8 +7,48 @@
  */
 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
 #include 
 
 #include "libbpf.h"
+
+#define __printf(a, b) __attribute__((format(printf, a, b)))
+
+__printf(1, 2)
+static int __base_pr(const char *format, ...)
+{
+   va_list args;
+   int err;
+
+   va_start(args, format);
+   err = vfprintf(stderr, format, args);
+   va_end(args);
+   return err;
+}
+
+static __printf(1, 2) libbpf_print_fn_t __pr_warning = __base_pr;
+static __printf(1, 2) libbpf_print_fn_t __pr_info = __base_pr;
+static __printf(1, 2) libbpf_print_fn_t __pr_debug = NULL;
+
+#define __pr(func, fmt, ...)   \
+do {   \
+   if ((func)) \
+   (func)("libbpf: " fmt, ##__VA_ARGS__); \
+} while(0)
+
+#define pr_warning(fmt, ...)   __pr(__pr_warning, fmt, ##__VA_ARGS__)
+#define pr_info(fmt, ...)  __pr(__pr_info, fmt, ##__VA_ARGS__)
+#define pr_debug(fmt, ...) __pr(__pr_debug, fmt, ##__VA_ARGS__)
+
+void libbpf_set_print(libbpf_print_fn_t warn,
+ libbpf_print_fn_t info,
+ libbpf_print_fn_t debug)
+{
+   __pr_warning = warn;
+   __pr_info = info;
+   __pr_debug = debug;
+}
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index a6f46d9..8d1eeba 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -8,4 +8,16 @@
 #ifndef __BPF_LIBBPF_H
 #define __BPF_LIBBPF_H
 
+/*
+ * In include/linux/compiler-gcc.h, __printf is defined. However
+ * it should be better if libbpf.h doesn't depend on Linux header file.
+ * So instead of __printf, here we use gcc attribute directly.
+ */
+typedef int (*libbpf_print_fn_t)(const char *, ...)
+   __attribute__((format(printf, 1, 2)));
+
+void libbpf_set_print(libbpf_print_fn_t warn,
+ libbpf_print_fn_t info,
+ libbpf_print_fn_t debug);
+
 #endif
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v7 34/37] perf tools: Add bpf_fd field to evsel and config it

2015-06-11 Thread Wang Nan
This patch adds a bpf_fd field to 'struct evsel' then introduces method
to config it. In bpf-loader, a bpf__for_each_program() function is added.
Which calls the callback function for each eBPF programs with their event
structure and file descriptors. In evlist.c, perf_evlist__add_bpf()
is added to add all bpf events into evlist. The event names are found
from probe_trace_event structure. 'perf record' calls
perf_evlist__add_bpf().

Since bpf-loader.c will not be built if libbpf is turned off, an empty
bpf__for_each_program() is defined in bpf-loader.h to avoid compiling
error.

Signed-off-by: Wang Nan 
---
 tools/perf/builtin-record.c  |  6 ++
 tools/perf/util/bpf-loader.c | 36 +++
 tools/perf/util/bpf-loader.h | 13 +++
 tools/perf/util/evlist.c | 51 
 tools/perf/util/evlist.h |  1 +
 tools/perf/util/evsel.c  |  1 +
 tools/perf/util/evsel.h  |  1 +
 7 files changed, 109 insertions(+)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 7fcce98..c15865f 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1135,6 +1135,12 @@ int cmd_record(int argc, const char **argv, const char 
*prefix __maybe_unused)
goto out_symbol_exit;
}
 
+   err = perf_evlist__add_bpf(rec->evlist);
+   if (err < 0) {
+   pr_err("Failed to add events from BPF object(s)\n");
+   goto out_symbol_exit;
+   }
+
symbol__init(NULL);
 
if (symbol_conf.kptr_restrict)
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index 54bda7e..00fb94f 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -258,3 +258,39 @@ errout:
bpf_object__unload(obj);
return err;
 }
+
+int
+bpf__for_each_program(bpf_prog_iter_callback_t func,
+ void *arg)
+{
+   struct bpf_object *obj, *tmp;
+   struct bpf_program *prog;
+   int err;
+
+   bpf_object__for_each(obj, tmp) {
+   bpf_object__for_each_program(prog, obj) {
+   struct bpf_prog_priv *priv;
+   int fd;
+
+   err = bpf_program__get_private(prog,
+  (void **));
+   if (err || !priv) {
+   pr_err("bpf: failed to get private field\n");
+   return -EINVAL;
+   }
+   err = bpf_program__get_fd(prog, );
+   if (err || fd < 0) {
+   pr_err("bpf: failed to get file descriptor\n");
+   return -EINVAL;
+   }
+
+   err = func(priv->pev, fd, arg);
+   if (err) {
+   pr_err("bpf: call back failed, stop iterate\n");
+   return err;
+   }
+   }
+   }
+
+   return 0;
+}
diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h
index ae0dc9b..da03e12 100644
--- a/tools/perf/util/bpf-loader.h
+++ b/tools/perf/util/bpf-loader.h
@@ -6,10 +6,14 @@
 #define __BPF_LOADER_H
 
 #include 
+#include "probe-event.h"
 #include "debug.h"
 
 #define PERF_BPF_PROBE_GROUP "perf_bpf_probe"
 
+typedef int (*bpf_prog_iter_callback_t)(struct perf_probe_event *pev,
+   int fd, void *arg);
+
 #ifdef HAVE_LIBBPF_SUPPORT
 int bpf__prepare_load(const char *filename, bool source);
 int bpf__probe(void);
@@ -17,6 +21,8 @@ int bpf__unprobe(void);
 int bpf__load(void);
 
 void bpf__clear(void);
+
+int bpf__for_each_program(bpf_prog_iter_callback_t func, void *arg);
 #else
 static inline int bpf__prepare_load(const char *filename __maybe_unused,
bool source __maybe_unused)
@@ -29,5 +35,12 @@ static inline int bpf__probe(void) { return 0; }
 static inline int bpf__unprobe(void) { return 0; }
 static inline int bpf__load(void) { return 0; }
 static inline void bpf__clear(void) { }
+
+static inline int
+bpf__for_each_program(bpf_prog_iter_callback_t func __maybe_unused,
+ void *arg __maybe_unused)
+{
+   return 0;
+}
 #endif
 #endif
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index dc1dc2c..08863b6 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -14,6 +14,7 @@
 #include "target.h"
 #include "evlist.h"
 #include "evsel.h"
+#include "bpf-loader.h"
 #include "debug.h"
 #include 
 
@@ -194,6 +195,56 @@ error:
return -ENOMEM;
 }
 
+static int add_bpf_event(struct perf_probe_event *pev, int fd,
+void *arg)
+{
+   struct perf_evlist *evlist = arg;
+   struct perf_evsel *pos;
+   struct list_head list;
+   int err, idx, entries, i;
+
+   if (!pev || !pev->ntevs) {
+   

[RFC PATCH v7 37/37] perf record: Add clang options for compiling BPF scripts

2015-06-11 Thread Wang Nan
Although previous patch allows setting BPF compiler related options in
perfconfig, on some ad-hoc situation it still requires passing options
through cmdline. This patch introduces 2 options to 'perf record' for
this propose: --clang-path and --clang-opt.

Signed-off-by: Wang Nan 
---
 tools/perf/builtin-record.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index c15865f..3ec8cee 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -30,6 +30,7 @@
 #include "util/auxtrace.h"
 #include "util/parse-branch-options.h"
 #include "util/bpf-loader.h"
+#include "util/llvm-utils.h"
 
 #include 
 #include 
@@ -1068,6 +1069,12 @@ struct option __record_options[] = {
parse_clockid),
OPT_STRING_OPTARG('S', "snapshot", _snapshot_opts,
  "opts", "AUX area tracing Snapshot Mode", ""),
+#ifdef HAVE_LIBBPF_SUPPORT"
+   OPT_STRING(0, "clang-path", _param.clang_path, "clang path",
+  "clang binary to use for compiling BPF scriptlets"),
+   OPT_STRING(0, "clang-opt", _param.clang_opt, "clang options",
+  "options passed to clang when compiling BPF scriptlets"),
+#endif
OPT_END()
 };
 
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v7 21/37] bpf tools: Link all bpf objects onto a list

2015-06-11 Thread Wang Nan
To prevent caller from creating additional structures to hold
pointers of 'struct bpf_object', this patch link all such
structures onto a list (hidden to user). bpf_object__for_each() is
introduced to allow users iterate over each objects.
bpf_object__for_each() is safe even user close the object during
iteration.

Signed-off-by: Wang Nan 
Acked-by: Alexei Starovoitov 
---
 tools/lib/bpf/libbpf.c | 32 
 tools/lib/bpf/libbpf.h |  7 +++
 2 files changed, 39 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index fec1624..5147a98 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -104,6 +105,8 @@ struct bpf_program {
bpf_program_clear_priv_t clear_priv;
 };
 
+static LIST_HEAD(bpf_objects_list);
+
 struct bpf_object {
char license[64];
u32 kern_version;
@@ -137,6 +140,12 @@ struct bpf_object {
} *reloc;
int nr_reloc;
} efile;
+   /*
+* All loaded bpf_object is linked in a list, which is
+* hidden to caller. bpf_objects__ handlers deal with
+* all objects.
+*/
+   struct list_head list;
char path[];
 };
 #define obj_elf_valid(o)   ((o)->efile.elf)
@@ -254,6 +263,9 @@ static struct bpf_object *bpf_object__new(const char *path,
obj->efile.obj_buf_sz = obj_buf_sz;
 
obj->loaded = false;
+
+   INIT_LIST_HEAD(>list);
+   list_add(>list, _objects_list);
return obj;
 }
 
@@ -921,6 +933,7 @@ void bpf_object__close(struct bpf_object *obj)
}
zfree(>programs);
 
+   list_del(>list);
free(obj);
 }
 
@@ -933,6 +946,25 @@ int bpf_object__get_prog_cnt(struct bpf_object *obj, 
size_t *pcnt)
return 0;
 }
 
+struct bpf_object *
+bpf_object__next(struct bpf_object *prev)
+{
+   struct bpf_object *next;
+
+   if (!prev)
+   next = list_first_entry(_objects_list,
+   struct bpf_object,
+   list);
+   else
+   next = list_next_entry(prev, list);
+
+   /* Empty list is noticed here so don't need checking on entry. */
+   if (>list == _objects_list)
+   return NULL;
+
+   return next;
+}
+
 struct bpf_program *
 bpf_program__next(struct bpf_program *prev, struct bpf_object *obj)
 {
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index d11664b..61ea96d 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -38,6 +38,13 @@ int bpf_object__unload(struct bpf_object *obj);
 /* Accessors of bpf_object */
 int bpf_object__get_prog_cnt(struct bpf_object *obj, size_t *pcnt);
 
+struct bpf_object *bpf_object__next(struct bpf_object *prev);
+#define bpf_object__for_each(pos, tmp) \
+   for ((pos) = bpf_object__next(NULL),\
+   (tmp) = bpf_object__next(pos);  \
+(pos) != NULL; \
+(pos) = (tmp), (tmp) = bpf_object__next(tmp))
+
 /* Accessors of bpf_program. */
 struct bpf_program;
 struct bpf_program *bpf_program__next(struct bpf_program *prog,
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v7 09/37] bpf tools: Collect map definitions from 'maps' section

2015-06-11 Thread Wang Nan
If maps are used by eBPF programs, corresponding object file(s) should
contain a section named 'map'. Which contains map definitions. This
patch copies the data of the whole section. Map data parsing should be
acted just before map loading.

Signed-off-by: Wang Nan 
Acked-by: Alexei Starovoitov 
---
 tools/lib/bpf/libbpf.c | 29 +
 1 file changed, 29 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 3bd183c..3315f00 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -81,6 +81,9 @@ void libbpf_set_print(libbpf_print_fn_t warn,
 struct bpf_object {
char license[64];
u32 kern_version;
+   void *maps_buf;
+   size_t maps_buf_sz;
+
/*
 * Information when doing elf related work. Only valid if fd
 * is valid.
@@ -249,6 +252,28 @@ bpf_object__init_kversion(struct bpf_object *obj,
return 0;
 }
 
+static int
+bpf_object__init_maps(struct bpf_object *obj, void *data,
+ size_t size)
+{
+   if (size == 0) {
+   pr_debug("%s doesn't need map definition\n",
+obj->path);
+   return 0;
+   }
+
+   obj->maps_buf = malloc(size);
+   if (!obj->maps_buf) {
+   pr_warning("malloc maps failed: %s\n", obj->path);
+   return -ENOMEM;
+   }
+
+   obj->maps_buf_sz = size;
+   memcpy(obj->maps_buf, data, size);
+   pr_debug("maps in %s: %ld bytes\n", obj->path, (long)size);
+   return 0;
+}
+
 static int bpf_object__elf_collect(struct bpf_object *obj)
 {
Elf *elf = obj->efile.elf;
@@ -304,6 +329,9 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
err = bpf_object__init_kversion(obj,
data->d_buf,
data->d_size);
+   else if (strcmp(name, "maps") == 0)
+   err = bpf_object__init_maps(obj, data->d_buf,
+   data->d_size);
if (err)
goto out;
}
@@ -381,5 +409,6 @@ void bpf_object__close(struct bpf_object *obj)
 
bpf_object__elf_finish(obj);
 
+   zfree(>maps_buf);
free(obj);
 }
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC PATCH v7 08/37] bpf tools: Collect version and license from ELF sections

2015-06-11 Thread Wang Nan
Expand bpf_obj_elf_collect() to collect license and kernel version
information in eBPF object file. eBPF object file should have a section
named 'license', which contains a string. It should also have a section
named 'version', contains a u32 LINUX_VERSION_CODE.

bpf_obj_validate() is introduced to validate object file after loaded.
Currently it only check existance of 'version' section.

Signed-off-by: Wang Nan 
Acked-by: Alexei Starovoitov 
---
 tools/lib/bpf/libbpf.c | 52 ++
 1 file changed, 52 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 1c4da03..3bd183c 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -78,6 +79,8 @@ void libbpf_set_print(libbpf_print_fn_t warn,
 #endif
 
 struct bpf_object {
+   char license[64];
+   u32 kern_version;
/*
 * Information when doing elf related work. Only valid if fd
 * is valid.
@@ -220,6 +223,32 @@ mismatch:
return -EINVAL;
 }
 
+static int
+bpf_object__init_license(struct bpf_object *obj,
+void *data, size_t size)
+{
+   memcpy(obj->license, data,
+  min(size, sizeof(obj->license) - 1));
+   pr_debug("license of %s is %s\n", obj->path, obj->license);
+   return 0;
+}
+
+static int
+bpf_object__init_kversion(struct bpf_object *obj,
+ void *data, size_t size)
+{
+   u32 kver;
+   if (size != sizeof(kver)) {
+   pr_warning("invalid kver section in %s\n", obj->path);
+   return -EINVAL;
+   }
+   memcpy(, data, sizeof(kver));
+   obj->kern_version = kver;
+   pr_debug("kernel version of %s is %x\n", obj->path,
+obj->kern_version);
+   return 0;
+}
+
 static int bpf_object__elf_collect(struct bpf_object *obj)
 {
Elf *elf = obj->efile.elf;
@@ -266,11 +295,32 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
 name, (unsigned long)data->d_size,
 (int)sh.sh_link, (unsigned long)sh.sh_flags,
 (int)sh.sh_type);
+
+   if (strcmp(name, "license") == 0)
+   err = bpf_object__init_license(obj,
+  data->d_buf,
+  data->d_size);
+   else if (strcmp(name, "version") == 0)
+   err = bpf_object__init_kversion(obj,
+   data->d_buf,
+   data->d_size);
+   if (err)
+   goto out;
}
 out:
return err;
 }
 
+static int bpf_object__validate(struct bpf_object *obj)
+{
+   if (obj->kern_version == 0) {
+   pr_warning("%s doesn't provide kernel version\n",
+  obj->path);
+   return -EINVAL;
+   }
+   return 0;
+}
+
 static struct bpf_object *
 __bpf_object__open(const char *path, void *obj_buf, size_t obj_buf_sz)
 {
@@ -291,6 +341,8 @@ __bpf_object__open(const char *path, void *obj_buf, size_t 
obj_buf_sz)
goto out;
if (bpf_object__elf_collect(obj))
goto out;
+   if (bpf_object__validate(obj))
+   goto out;
 
bpf_object__elf_finish(obj);
return obj;
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH RESEND] sched: prefer an idle cpu vs an idle sibling for BALANCE_WAKE

2015-06-11 Thread Mike Galbraith
On Thu, 2015-05-28 at 13:05 +0200, Peter Zijlstra wrote:

> @@ -5022,22 +5026,28 @@ select_task_rq_fair(struct task_struct *p, int 
> prev_cpu, int sd_flag, int wake_f
>* If both cpu and prev_cpu are part of this domain,
>* cpu is a valid SD_WAKE_AFFINE target.
>*/
> - if (want_affine && (tmp->flags & SD_WAKE_AFFINE) &&
> - cpumask_test_cpu(prev_cpu, sched_domain_span(tmp))) {
> + if (want_affine && !affine_sd &&
> + (tmp->flags & SD_WAKE_AFFINE) &&
> + cpumask_test_cpu(prev_cpu, sched_domain_span(tmp)))
>   affine_sd = tmp;
> - break;
> - }
>  
>   if (tmp->flags & sd_flag)
>   sd = tmp;
> + else if (!want_affine || (want_affine && affine_sd))
> + break;
>   }

Hm, new_cpu == cpu.
 
> - if (affine_sd && cpu != prev_cpu && wake_affine(affine_sd, p, sync))
> + if (affine_sd && cpu != prev_cpu && wake_affine(affine_sd, p, sync)) {
>   prev_cpu = cpu;
> + sd = NULL; /* WAKE_AFFINE trumps BALANCE_WAKE */
> + }

If branch above is not taken, new_cpu remains cpu.
 
>   if (sd_flag & SD_BALANCE_WAKE) {
> - new_cpu = select_idle_sibling(p, prev_cpu);
> - goto unlock;
> + int tmp = select_idle_sibling(p, prev_cpu);
> + if (tmp >= 0) {
> + new_cpu = tmp;
> + goto unlock;
> + }
>   }

If select_idle_sibling() returns -1, new_cpu remains cpu.

>  
>   while (sd) {

If sd == NULL, we fall through and try to pull wakee despite nacked-by
tsk_cpus_allowed() or wake_affine().

-Mike

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] w1: masters: omap_hdq: Add support for 1-wire mode

2015-06-11 Thread Vignesh R
Hi,

On Thursday 11 June 2015 09:04 PM, Evgeniy Polyakov wrote:
> Hi
> 
> 25.05.2015, 08:15, "Vignesh R" :
>>>  HDQ mode remains unchanged.
>>>
>>>  Signed-off-by: Vignesh R 
> 
> I have no experience with omap_hdq platform, but there are quite a few 
> questions
> related to IO - you never check whether write was successful or read returned 
> actually
> valid data, is it ok? I mean is it correct to assume that read can not return 
> 0xff for example
> and it is a sign that something is wrong, or this can not happen?
> 

Referring to AM437x TRM SPRUHL7C
(www.ti.com/lit/ug/spruhl7c/spruhl7c.pdf) section 23.3.5.4, Successful
or failed completion is not indicated for write operation, so there is
no way to verify whether write succeeded (though TX_COMPLETE interrupt
bit is set on transaction completion). But, as for as read operation is
concerned, the TRM says, if RX_COMPLETE bit is set, then read is
successful and I think that implies valid data is present in RX reg. My
patch does look for TX/RX_COMPLETE bits to be set after write/read
operations.

> As for me, I have no objection, but this patch must go via omap tree imo.
> 

Andrew Morton has already picked this patch (its on linux-next).
Although he has a minor comment on use of mutex_lock_interruptible. But
that comment applies to many places in the existing driver code. I plan
to cleanup all those mutex calls in near future.

Regards
Vignesh
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/2] staging: rtl8188eu: remove unused variables

2015-06-11 Thread Sudip Mukherjee
On Thu, Jun 11, 2015 at 06:39:09PM +0530, Sudip Mukherjee wrote:
> These variables were being set but not used afterwards.
> 

> --- a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> +++ b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> @@ -147,18 +147,14 @@ inline struct sta_info 
> *rtw_get_stainfo_by_offset(struct sta_priv *stapriv, int
>  static void rtw_mfree_all_stainfo(struct sta_priv *pstapriv)
>  {
>   struct list_head *plist, *phead;
> - struct sta_info *psta = NULL;
> -
>  
>   spin_lock_bh(>sta_hash_lock);
>  
>   phead = get_list_head(>free_sta_queue);
>   plist = phead->next;
>  
> - while (phead != plist) {
> - psta = container_of(plist, struct sta_info, list);
> + while (phead != plist)
>   plist = plist->next;
> - }
>  
>   spin_unlock_bh(>sta_hash_lock);
I am checking my own patch ... :)
looks like this function is not doing anything. its just getting the lock,
traversing the list, unlocking and returning.
I am guessing by the function name that the function was supposed to free
something.

Greg - please drop this series. I will try to find if something can be
freed else I will remove this function.

regards
sudip
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH perf/core 4/4] [BUGFIX] perf probe: Show usage even if the last event is skipped

2015-06-11 Thread Masami Hiramatsu
When the last part of converted events are blacklisted or out-of-text,
those are skipped and perf probe doesn't show usage examples.
This fixes it to show the example even if the last part of event list
is skipped.

E.g. without this patch, events are added, but suddenly end;
  
  # perf probe vfs_*
  vfs_caches_init_early is out of .text, skip it.
  vfs_caches_init is out of .text, skip it.
  Added new events:
probe:vfs_fallocate  (on vfs_*)
probe:vfs_open   (on vfs_*)
  ...
probe:vfs_dentry_acceptable (on vfs_*)
probe:vfs_load_quota_inode (on vfs_*)
  #
  
With this fix;
  
  # perf probe vfs_*
  vfs_caches_init_early is out of .text, skip it.
  vfs_caches_init is out of .text, skip it.
  Added new events:
probe:vfs_fallocate  (on vfs_*)
  ...
probe:vfs_load_quota_inode (on vfs_*)

  You can now use it in all perf tools, such as:

perf record -e probe:vfs_load_quota_inode -aR sleep 1

  #
  

Signed-off-by: Masami Hiramatsu 
---
 tools/perf/util/probe-event.c |   35 +--
 1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index aa2479e..626bc6c5 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -2157,7 +2157,8 @@ static bool kprobe_blacklist__listed(unsigned long 
address)
return !!kprobe_blacklist__find_by_address(_blacklist, address);
 }
 
-static int perf_probe_event__sprintf(struct perf_probe_event *pev,
+static int perf_probe_event__sprintf(const char *group, const char *event,
+struct perf_probe_event *pev,
 const char *module,
 struct strbuf *result)
 {
@@ -2170,7 +2171,7 @@ static int perf_probe_event__sprintf(struct 
perf_probe_event *pev,
if (!place)
return -EINVAL;
 
-   ret = e_snprintf(buf, 128, "%s:%s", pev->group, pev->event);
+   ret = e_snprintf(buf, 128, "%s:%s", group, event);
if (ret < 0)
goto out;
 
@@ -2195,13 +2196,14 @@ out:
 }
 
 /* Show an event */
-static int show_perf_probe_event(struct perf_probe_event *pev,
+static int show_perf_probe_event(const char *group, const char *event,
+struct perf_probe_event *pev,
 const char *module, bool use_stdout)
 {
struct strbuf buf = STRBUF_INIT;
int ret;
 
-   ret = perf_probe_event__sprintf(pev, module, );
+   ret = perf_probe_event__sprintf(group, event, pev, module, );
if (ret >= 0) {
if (use_stdout)
printf("%s\n", buf.buf);
@@ -2253,7 +2255,8 @@ static int __show_perf_probe_events(int fd, bool 
is_kprobe,
is_kprobe);
if (ret < 0)
goto next;
-   ret = show_perf_probe_event(, tev.point.module,
+   ret = show_perf_probe_event(pev.group, pev.event,
+   , tev.point.module,
false);
}
 next:
@@ -2438,7 +2441,7 @@ static int __add_probe_trace_events(struct 
perf_probe_event *pev,
int i, fd, ret;
struct probe_trace_event *tev = NULL;
char buf[64];
-   const char *event, *group;
+   const char *event = NULL, *group = NULL;
struct strlist *namelist;
bool safename;
 
@@ -2500,15 +2503,12 @@ static int __add_probe_trace_events(struct 
perf_probe_event *pev,
/* Add added event name to namelist */
strlist__add(namelist, event);
 
-   /* Trick here - save current event/group */
-   event = pev->event;
-   group = pev->group;
-   pev->event = tev->event;
-   pev->group = tev->group;
-   show_perf_probe_event(pev, tev->point.module, true);
-   /* Trick here - restore current event/group */
-   pev->event = (char *)event;
-   pev->group = (char *)group;
+   /* We use tev's name for showing new events */
+   show_perf_probe_event(tev->group, tev->event, pev,
+ tev->point.module, true);
+   /* Save the last valid name */
+   event = tev->event;
+   group = tev->group;
 
/*
 * Probes after the first probe which comes from same
@@ -2522,11 +2522,10 @@ static int __add_probe_trace_events(struct 
perf_probe_event *pev,
warn_uprobe_event_compat(tev);
 
/* Note that it is possible to skip all events because of blacklist */
-   if (ret >= 0 && tev->event) {
+   if (ret >= 0 && event) {
/* Show how to use the event. */

[PATCH perf/core 3/4] [BUGFIX] perf probe: Check non-probe-able symbols when using symbol map

2015-06-11 Thread Masami Hiramatsu
Fix to check both of non-exist symbols and kprobe blacklist symbols at
symbol-map based converting too.

E.g. without this fix, perf-probe failes to write the event.
  
  # perf probe vfs_caches_init_early
  Added new event:
  Failed to write event: Invalid argument
Error: Failed to add events.
  

This fixes it to catch the error before adding probes.
  
  # perf probe vfs_caches_init_early
  vfs_caches_init_early is out of .text, skip it.
Error: Failed to add events.
  

Signed-off-by: Masami Hiramatsu 
---
 tools/perf/util/probe-event.c |  113 ++---
 1 file changed, 71 insertions(+), 42 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 7aa3efe..aa2479e 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -246,6 +246,20 @@ static void clear_probe_trace_events(struct 
probe_trace_event *tevs, int ntevs)
clear_probe_trace_event(tevs + i);
 }
 
+static bool kprobe_blacklist__listed(unsigned long address);
+static bool kprobe_warn_out_range(const char *symbol, unsigned long address)
+{
+   /* Get the address of _etext for checking non-probable text symbol */
+   if (kernel_get_symbol_address_by_name("_etext", false) < address)
+   pr_warning("%s is out of .text, skip it.\n", symbol);
+   else if (kprobe_blacklist__listed(address))
+   pr_warning("%s is blacklisted function, skip it.\n", symbol);
+   else
+   return false;
+
+   return true;
+}
+
 #ifdef HAVE_DWARF_SUPPORT
 
 static int kernel_get_module_dso(const char *module, struct dso **pdso)
@@ -559,7 +573,6 @@ static int post_process_probe_trace_events(struct 
probe_trace_event *tevs,
   bool uprobe)
 {
struct ref_reloc_sym *reloc_sym;
-   u64 etext_addr;
char *tmp;
int i, skipped = 0;
 
@@ -575,31 +588,28 @@ static int post_process_probe_trace_events(struct 
probe_trace_event *tevs,
pr_warning("Relocated base symbol is not found!\n");
return -EINVAL;
}
-   /* Get the address of _etext for checking non-probable text symbol */
-   etext_addr = kernel_get_symbol_address_by_name("_etext", false);
 
for (i = 0; i < ntevs; i++) {
-   if (tevs[i].point.address && !tevs[i].point.retprobe) {
-   /* If we found a wrong one, mark it by NULL symbol */
-   if (etext_addr < tevs[i].point.address) {
-   pr_warning("%s+%lu is out of .text, skip it.\n",
-  tevs[i].point.symbol, tevs[i].point.offset);
-   tmp = NULL;
-   skipped++;
-   } else {
-   tmp = strdup(reloc_sym->name);
-   if (!tmp)
-   return -ENOMEM;
-   }
-   /* If we have no realname, use symbol for it */
-   if (!tevs[i].point.realname)
-   tevs[i].point.realname = tevs[i].point.symbol;
-   else
-   free(tevs[i].point.symbol);
-   tevs[i].point.symbol = tmp;
-   tevs[i].point.offset = tevs[i].point.address -
-  reloc_sym->unrelocated_addr;
+   if (!tevs[i].point.address || tevs[i].point.retprobe)
+   continue;
+   /* If we found a wrong one, mark it by NULL symbol */
+   if (kprobe_warn_out_range(tevs[i].point.symbol,
+ tevs[i].point.address)) {
+   tmp = NULL;
+   skipped++;
+   } else {
+   tmp = strdup(reloc_sym->name);
+   if (!tmp)
+   return -ENOMEM;
}
+   /* If we have no realname, use symbol for it */
+   if (!tevs[i].point.realname)
+   tevs[i].point.realname = tevs[i].point.symbol;
+   else
+   free(tevs[i].point.symbol);
+   tevs[i].point.symbol = tmp;
+   tevs[i].point.offset = tevs[i].point.address -
+  reloc_sym->unrelocated_addr;
}
return skipped;
 }
@@ -2126,6 +2136,27 @@ kprobe_blacklist__find_by_address(struct list_head 
*blacklist,
return NULL;
 }
 
+static LIST_HEAD(kprobe_blacklist);
+
+static void kprobe_blacklist__init(void)
+{
+   if (!list_empty(_blacklist))
+   return;
+
+   if (kprobe_blacklist__load(_blacklist) < 0)
+   pr_debug("No kprobe blacklist support, ignored\n");
+}
+
+static void kprobe_blacklist__release(void)
+{
+   

[PATCH perf/core 0/4] perf-probe bugfixes

2015-06-11 Thread Masami Hiramatsu
Hi Arnaldo,

Here is a series of bugfix patches for perf-probe. I've fixed some
bugs on non-debuginfo environment.
This series fixes below bugs;

 - --list shows the list of probes in stderr.
   (It is refined from https://lkml.org/lkml/2015/5/30/34)
 - failed to probe on gcc optimized symbols which has a postfix.
 - non-probe-able symbols (out of .text) are not checked when
   using symbol maps.
 - usage message is not shown if the last event is skipped.

Thank you,

---

Masami Hiramatsu (4):
  [BUGFIX] perf probe: List probes in stdout
  [BUGFIX] perf probe: Cut off the postfixes from event name
  [BUGFIX] perf probe: Check non-probe-able symbols when using symbol map
  [BUGFIX] perf probe: Show usage even if the last event is skipped


 tools/perf/util/probe-event.c |  192 ++---
 1 file changed, 123 insertions(+), 69 deletions(-)


-- 
Masami HIRAMATSU
Linux Technology Research Center, System Productivity Research Dept.
Center for Technology Innovation - Systems Engineering 
Hitachi, Ltd., Research & Development Group
E-mail: masami.hiramatsu...@hitachi.com

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH perf/core 2/4] [BUGFIX] perf probe: Cut off the postfixes from event name

2015-06-11 Thread Masami Hiramatsu
Cut off the postfixes which gcc added for optimized routines
from the event name automatically generated from symbol name,
since *probe-events doesn't accept it.
Those symbols will be used if we don't use debuginfo to find
target functions.

E.g. without this fix;
  -
  # perf probe -va alloc_buf.isra.23
  probe-definition(0): alloc_buf.isra.23
  symbol:alloc_buf.isra.23 file:(null) line:0 offset:0 return:0 lazy:(null)
  [...]
  Opening /sys/kernel/debug/tracing/kprobe_events write=1
  Added new event:
  Writing event: p:probe/alloc_buf.isra.23 _text+4869328
  Failed to write event: Invalid argument
Error: Failed to add events. Reason: Invalid argument (Code: -22)
  -
With this fix;
  -
  perf probe -va alloc_buf.isra.23
  probe-definition(0): alloc_buf.isra.23
  symbol:alloc_buf.isra.23 file:(null) line:0 offset:0 return:0 lazy:(null)
  [...]
  Opening /sys/kernel/debug/tracing/kprobe_events write=1
  Added new event:
  Writing event: p:probe/alloc_buf _text+4869328
probe:alloc_buf  (on alloc_buf.isra.23)

  You can now use it in all perf tools, such as:

perf record -e probe:alloc_buf -aR sleep 1

  -

Signed-off-by: Masami Hiramatsu 
---
 tools/perf/util/probe-event.c |5 +
 1 file changed, 5 insertions(+)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 710830c..7aa3efe 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -2337,6 +2337,7 @@ static int get_new_event_name(char *buf, size_t len, 
const char *base,
  struct strlist *namelist, bool allow_suffix)
 {
int i, ret;
+   char *p;
 
if (*base == '.')
base++;
@@ -2347,6 +2348,10 @@ static int get_new_event_name(char *buf, size_t len, 
const char *base,
pr_debug("snprintf() failed: %d\n", ret);
return ret;
}
+   /* Cut off the postfixes (e.g. .const, .isra)*/
+   p = strchr(buf, '.');
+   if (p && p != buf)
+   *p = '\0';
if (!strlist__has_entry(namelist, buf))
return 0;
 


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH perf/core 1/4] [BUGFIX] perf probe: List probes in stdout

2015-06-11 Thread Masami Hiramatsu
Since commit 5e17b28f1e24 ("perf probe: Add --quiet option to
suppress output result message") have replaced printf with pr_info,
perf probe -l outputs its result in stderr. However, that is not
what the commit expected.
e.g.
  -
  # perf probe -l > /dev/null
probe:vfs_read   (on vfs_read@ksrc/linux-3/fs/read_write.c)
  -
With this fix,
  -
  # perf probe -l > list
  # cat list
probe:vfs_read   (on vfs_read@ksrc/linux-3/fs/read_write.c)
  -
Of course, --quiet(-q) still works on --add/--del.
  -
  # perf probe -q vfs_write
  # perf probe -l
probe:vfs_read   (on vfs_read@ksrc/linux-3/fs/read_write.c)
probe:vfs_write  (on vfs_write@ksrc/linux-3/fs/read_write.c)
  -

Signed-off-by: Masami Hiramatsu 
Reported-by: Naohiro Aota 
---
 tools/perf/util/probe-event.c |   49 +
 1 file changed, 35 insertions(+), 14 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index d4cf50b..710830c 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -2126,9 +2126,9 @@ kprobe_blacklist__find_by_address(struct list_head 
*blacklist,
return NULL;
 }
 
-/* Show an event */
-static int show_perf_probe_event(struct perf_probe_event *pev,
-const char *module)
+static int perf_probe_event__sprintf(struct perf_probe_event *pev,
+const char *module,
+struct strbuf *result)
 {
int i, ret;
char buf[128];
@@ -2141,27 +2141,47 @@ static int show_perf_probe_event(struct 
perf_probe_event *pev,
 
ret = e_snprintf(buf, 128, "%s:%s", pev->group, pev->event);
if (ret < 0)
-   return ret;
+   goto out;
 
-   pr_info("  %-20s (on %s", buf, place);
+   strbuf_addf(result, "  %-20s (on %s", buf, place);
if (module)
-   pr_info(" in %s", module);
+   strbuf_addf(result, " in %s", module);
 
if (pev->nargs > 0) {
-   pr_info(" with");
+   strbuf_addstr(result, " with");
for (i = 0; i < pev->nargs; i++) {
ret = synthesize_perf_probe_arg(>args[i],
buf, 128);
if (ret < 0)
-   break;
-   pr_info(" %s", buf);
+   goto out;
+   strbuf_addf(result, " %s", buf);
}
}
-   pr_info(")\n");
+   strbuf_addch(result, ')');
+out:
free(place);
return ret;
 }
 
+/* Show an event */
+static int show_perf_probe_event(struct perf_probe_event *pev,
+const char *module, bool use_stdout)
+{
+   struct strbuf buf = STRBUF_INIT;
+   int ret;
+
+   ret = perf_probe_event__sprintf(pev, module, );
+   if (ret >= 0) {
+   if (use_stdout)
+   printf("%s\n", buf.buf);
+   else
+   pr_info("%s\n", buf.buf);
+   }
+   strbuf_release();
+
+   return ret;
+}
+
 static bool filter_probe_trace_event(struct probe_trace_event *tev,
 struct strfilter *filter)
 {
@@ -2200,9 +2220,10 @@ static int __show_perf_probe_events(int fd, bool 
is_kprobe,
goto next;
ret = convert_to_perf_probe_event(, ,
is_kprobe);
-   if (ret >= 0)
-   ret = show_perf_probe_event(,
-   tev.point.module);
+   if (ret < 0)
+   goto next;
+   ret = show_perf_probe_event(, tev.point.module,
+   false);
}
 next:
clear_perf_probe_event();
@@ -2463,7 +2484,7 @@ static int __add_probe_trace_events(struct 
perf_probe_event *pev,
group = pev->group;
pev->event = tev->event;
pev->group = tev->group;
-   show_perf_probe_event(pev, tev->point.module);
+   show_perf_probe_event(pev, tev->point.module, true);
/* Trick here - restore current event/group */
pev->event = (char *)event;
pev->group = (char *)group;


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v14 0/3] ARM: rk3288: Add PM Domain support

2015-06-11 Thread Caesar Wang

Hi Kevin, Heiko

Thanks for your comments.
Sorry for delay reply.

在 2015年04月28日 02:28, Kevin Hilman 写道:

Heiko Stübner  writes:


Am Freitag, 24. April 2015, 16:07:45 schrieb Caesar Wang:

 Add power domain drivers based on generic power domain for
Rockchip platform, and support RK3288.

 Verified on url =
 https://chromium.googlesource.com/chromiumos/third_party/kernel.

 At the moment,there are mass of products are using the driver.
I believe the driver can happy work for next kernel.

I've taken a look at the driver and here are some global remarks:

(1) You provide dt-bindings/power-domain/rk3288.h in patch 3. This breaks
bisectability, as the driver itself in patch 2 also includes the header and
would thus fail to compile if the later patch 3 is missing.
Ideally I think the header addition should be a separate patch itself, so that
we can possibly share it between driver and dts branches.
So 1: binding doc, 2: binding-header, 3: driver, 4: dts-changes.

OK, done.



(2) The dts-changes in patch 3 should also add any necessary power-domain
assignment on devices if they're still missing, so that we don't introduce
regressions. In my case my work-in-progress edp died because the powerdomain
was turned off automatically it seems.

OK, I will list that devices.
At the moment, I don't find the EDP driver for rockchip. (I think the 
EDP driver hasn't a upstream).


Anyway, I will test it on 
https://chromium.googlesource.com/chromiumos/third_party/kernel/+/chromeos-3.14,

Meanwhile work on next-kernel.




(3) more like wondering @Kevin or so, is there some more generic place for a
power-domain driver nowadays?

I think the preference has been to put these under drivers/soc/ for now,
so they can shared across arm32 and arm64.



Interesting. Do you want to put the domain driver into /driver/soc/rockchip?
I guess the efuse driver ...is also do that.

Perhaps, it's a good select in the future.



(4) As Tomasz remarked previously the dts should represent the hardware and
the power-domains are part of the pmu. There is a recent addition from Linus
Walleij, called simple-mfd [a] that is supposed to get added real early for
kernel 4.2. So I'd think the power-domains should use that and the patchset
modified to include the changes shown below [b]?

(5) Keven Hilman and Tomasz had reservations about all the device clocks
being listed in the power-domains itself in the previous versions. I don't see
a comment from them yet changing that view.

Correct.


How about this patch?

https://patchwork.kernel.org/patch/5145241/

I will do that.

Maybe, do you have more suggestions?



Their wish was to get the clocks by reading the clocks from the device nodes,
though I see a problem on how to handle devices that do not have any bindings
at all yet.

Kevin, Tomasz any new thoughts?

I don't see any issues with devices that don't have bindings, as all
that would be needed would be to simple device nodes with a clock
property.  I wouldn't even matter if those devices had device drivers.

Kevin





--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] extcon: Redefine the unique id of supported external connectors without 'enum extcon' type

2015-06-11 Thread Chanwoo Choi
Dear Greg,

On 06/12/2015 01:29 PM, Greg KH wrote:
> On Fri, Jun 12, 2015 at 11:10:06AM +0900, Chanwoo Choi wrote:
>> This patch just redefine the unique id of supported external connectors 
>> without
>> 'enum extcon' type. Because unique id would be used on devictree file(*.dts) 
>> to
>> indicate the specific external connectors like key number of input framework.
>> So, I have the plan to move this definitions to following header file which
>> includes the unique id of supported external connectors.
>> - include/dt-bindings/extcon/extcon.h
> 
> Do we have other such fields in dt-bindings that are not enumerated
> types?

I think that 'integer' type is more appropriate than enumerated type
in header file of includ/dt-bindings/ as following:

- Previous defintions
enum extcon {
/* USB external connector */
EXTCON_USB  = 0x1,
EXTCON_USB_HOST = 0x2,
..
};

- New definitions without specific 'enum extcon' type.
#define EXTCON_USB  1
#define EXTCON_USB_HOST 2
..

> 
> What's wrong with keeping this as-is and not changing to an integer?
> 
>> Fixes: 2a9de9c0f08d ("extcon: Use the unique id for external connector 
>> instead of string")
> 
> How is this a bugfix?

It is my mistake. This patch is not bug fix.

Best Regards,
Chanwoo Choi
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [v4 12/16] KVM: kvm-vfio: implement the VFIO skeleton for VT-d Posted-Interrupts

2015-06-11 Thread Wu, Feng


> -Original Message-
> From: Alex Williamson [mailto:alex.william...@redhat.com]
> Sent: Friday, June 12, 2015 1:15 AM
> To: Wu, Feng
> Cc: k...@vger.kernel.org; linux-kernel@vger.kernel.org; pbonz...@redhat.com;
> mtosa...@redhat.com; eric.au...@linaro.org
> Subject: Re: [v4 12/16] KVM: kvm-vfio: implement the VFIO skeleton for VT-d
> Posted-Interrupts
> 
> On Thu, 2015-06-11 at 18:51 +0800, Feng Wu wrote:
> > This patch adds the kvm-vfio interface for VT-d Posted-Interrupts.
> > When guests update MSI/MSI-x information for an assigned-device,
> > QEMU will use KVM_DEV_VFIO_DEVICE_POST_IRQ attribute to setup
> > IRTE for VT-d PI. Userspace program can also use
> > KVM_DEV_VFIO_DEVICE_UNPOST_IRQ to change back to irq remapping
> mode.
> > This patch implements these IRQ attributes.
> >
> > Signed-off-by: Feng Wu 
> > ---
> >  include/linux/kvm_host.h |  22 +
> >  virt/kvm/vfio.c  | 126
> +++
> >  2 files changed, 148 insertions(+)
> >
> > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> > index f591f7c..69f8711 100644
> > --- a/include/linux/kvm_host.h
> > +++ b/include/linux/kvm_host.h
> > @@ -1073,6 +1073,28 @@ extern struct kvm_device_ops kvm_xics_ops;
> >  extern struct kvm_device_ops kvm_arm_vgic_v2_ops;
> >  extern struct kvm_device_ops kvm_arm_vgic_v3_ops;
> >
> > +#ifdef __KVM_HAVE_ARCH_KVM_VFIO_POST
> > +/*
> > + * kvm_arch_vfio_update_pi_irte - set IRTE for Posted-Interrupts
> > + *
> > + * @kvm: kvm
> > + * @host_irq: host irq of the interrupt
> > + * @guest_irq: gsi of the interrupt
> > + * @set: set or unset PI
> > + * returns 0 on success, < 0 on failure
> > + */
> > +int kvm_arch_vfio_update_pi_irte(struct kvm *kvm, unsigned int host_irq,
> > +uint32_t guest_irq, bool set);
> > +#else
> > +static inline int kvm_arch_vfio_update_pi_irte(struct kvm *kvm,
> > +  unsigned int host_irq,
> > +  uint32_t guest_irq,
> > +  bool set)
> > +{
> > +   return 0;
> > +}
> 
> The code below can't get to this function without
> __KVM_HAVE_ARCH_KVM_VFIO_POST, but this seems like it should return an
> error if not implemented.

kvm_arch_vfio_update_pi_irte() is called by kvm_vfio_control_pi(), if we remove 
the
dummy definition of kvm_arch_vfio_update_pi_irte(), kvm_vfio_control_pi() is 
also
needed to be included in __KVM_HAVE_ARCH_KVM_VFIO_POST, I will handle this
in the next version.

> 
> > +#endif
> > +
> >  #ifdef CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT
> >
> >  static inline void kvm_vcpu_set_in_spin_loop(struct kvm_vcpu *vcpu, bool
> val)
> > diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c
> > index 80a45e4..547fc51 100644
> > --- a/virt/kvm/vfio.c
> > +++ b/virt/kvm/vfio.c
> > @@ -18,6 +18,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> 
> This only exists on x86.   

But in kvm_vfio_has_attr(), we can only return 0 when posted interrupt is 
supported
via calling " irq_remapping_cap(IRQ_POSTING_CAP)" which needs this header file.
Do you think how can I handle this?

> Are we also getting lucky with some of the
> include chains that give us the PCI related defines?  It looks like
> we're implicitly assuming CONFIG_PCI

Yes, I think the PCI related header files are included implicitly here. Anyway
I can add "#include " explicitly.

> >  #include "vfio.h"
> >
> >  struct kvm_vfio_group {
> > @@ -276,12 +277,128 @@ static int kvm_vfio_set_group(struct kvm_device
> *dev, long attr, u64 arg)
> > return -ENXIO;
> >  }
> >
> > +static int kvm_vfio_pci_get_irq_count(struct pci_dev *pdev, int irq_type)
> > +{
> > +   if (irq_type == VFIO_PCI_INTX_IRQ_INDEX) {
> > +   u8 pin;
> > +
> > +   pci_read_config_byte(pdev, PCI_INTERRUPT_PIN, );
> > +   if (pin)
> > +   return 1;
> > +   } else if (irq_type == VFIO_PCI_MSI_IRQ_INDEX) {
> > +   return pci_msi_vec_count(pdev);
> > +   } else if (irq_type == VFIO_PCI_MSIX_IRQ_INDEX) {
> > +   return pci_msix_vec_count(pdev);
> > +   }
> > +
> > +   return 0;
> > +}
> > +
> > +static int kvm_vfio_control_pi(struct kvm_device *kdev,
> > +  int32_t __user *argp, bool set)
> > +{
> > +   struct kvm_vfio_dev_irq pi_info;
> > +   uint32_t *gsi;
> > +   unsigned long minsz;
> > +   struct vfio_device *vdev;
> > +   struct msi_desc *entry;
> > +   struct device *dev;
> > +   struct pci_dev *pdev;
> > +   int i, max, ret;
> > +
> > +   minsz = offsetofend(struct kvm_vfio_dev_irq, count);
> > +
> > +   if (copy_from_user(_info, (void __user *)argp, minsz))
> > +   return -EFAULT;
> > +
> > +   if (pi_info.argsz < minsz || pi_info.index >= VFIO_PCI_NUM_IRQS)
> > +   return -EINVAL;
> 
> Could we also abort on pi_info.count == 0?

Yes, that is a good point.

> 
> > +
> > +   vdev = kvm_vfio_get_vfio_device(pi_info.fd);
> > +   if 

RE: [v4 13/16] KVM: x86: kvm-vfio: VT-d posted-interrupts setup

2015-06-11 Thread Wu, Feng


> -Original Message-
> From: Alex Williamson [mailto:alex.william...@redhat.com]
> Sent: Friday, June 12, 2015 1:16 AM
> To: Wu, Feng
> Cc: k...@vger.kernel.org; linux-kernel@vger.kernel.org; pbonz...@redhat.com;
> mtosa...@redhat.com; eric.au...@linaro.org
> Subject: Re: [v4 13/16] KVM: x86: kvm-vfio: VT-d posted-interrupts setup
> 
> On Thu, 2015-06-11 at 18:51 +0800, Feng Wu wrote:
> > This patch defines macro __KVM_HAVE_ARCH_KVM_VFIO_POST and
> > implement kvm_arch_vfio_update_pi_irte for x86 architecture.
> >
> 
> What's vfio specific in any of this?  It's obviously called from the
> kvm-vfio device interface, but nothing below is vfio related.  This is
> simply the posted interrupt interface to kvm.  Thanks,
> 
> Alex
> 

Oh, yes, maybe I need to move this part to vmx.c.

Thanks,
Feng

> 
> > Signed-off-by: Feng Wu 
> > ---
> >  arch/x86/include/asm/kvm_host.h |  2 +
> >  arch/x86/kvm/Makefile   |  3 +-
> >  arch/x86/kvm/kvm_vfio_x86.c | 85
> +
> >  3 files changed, 89 insertions(+), 1 deletion(-)
> >  create mode 100644 arch/x86/kvm/kvm_vfio_x86.c
> >
> > diff --git a/arch/x86/include/asm/kvm_host.h
> b/arch/x86/include/asm/kvm_host.h
> > index 31a495f..1605bf8 100644
> > --- a/arch/x86/include/asm/kvm_host.h
> > +++ b/arch/x86/include/asm/kvm_host.h
> > @@ -81,6 +81,8 @@ static inline gfn_t gfn_to_index(gfn_t gfn, gfn_t
> base_gfn, int level)
> > (base_gfn >> KVM_HPAGE_GFN_SHIFT(level));
> >  }
> >
> > +#define __KVM_HAVE_ARCH_KVM_VFIO_POST
> > +
> >  #define KVM_PERMILLE_MMU_PAGES 20
> >  #define KVM_MIN_ALLOC_MMU_PAGES 64
> >  #define KVM_MMU_HASH_SHIFT 10
> > diff --git a/arch/x86/kvm/Makefile b/arch/x86/kvm/Makefile
> > index 16e8f96..6bafc89 100644
> > --- a/arch/x86/kvm/Makefile
> > +++ b/arch/x86/kvm/Makefile
> > @@ -12,7 +12,8 @@ kvm-y += $(KVM)/kvm_main.o
> $(KVM)/coalesced_mmio.o \
> >  kvm-$(CONFIG_KVM_ASYNC_PF) += $(KVM)/async_pf.o
> >
> >  kvm-y  += x86.o mmu.o emulate.o i8259.o irq.o lapic.o \
> > -  i8254.o ioapic.o irq_comm.o cpuid.o pmu.o
> > +  i8254.o ioapic.o irq_comm.o cpuid.o pmu.o \
> > +  kvm_vfio_x86.o
> >  kvm-$(CONFIG_KVM_DEVICE_ASSIGNMENT)+= assigned-dev.o iommu.o
> >  kvm-intel-y+= vmx.o
> >  kvm-amd-y  += svm.o
> > diff --git a/arch/x86/kvm/kvm_vfio_x86.c b/arch/x86/kvm/kvm_vfio_x86.c
> > new file mode 100644
> > index 000..a2d74f9
> > --- /dev/null
> > +++ b/arch/x86/kvm/kvm_vfio_x86.c
> > @@ -0,0 +1,85 @@
> > +/*
> > + * Copyright (C) 2014 Intel Corporation.
> > + * Authors: Feng Wu 
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License, version 2, as
> > + * published by the Free Software Foundation.
> > + *
> > + * This program is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + * GNU General Public License for more details.
> > + */
> > +
> > +#include 
> > +#include 
> > +
> > +/*
> > + * kvm_arch_vfio_update_pi_irte - set IRTE for Posted-Interrupts
> > + *
> > + * @kvm: kvm
> > + * @host_irq: host irq of the interrupt
> > + * @guest_irq: gsi of the interrupt
> > + * @set: set or unset PI
> > + * returns 0 on success, < 0 on failure
> > + */
> > +int kvm_arch_vfio_update_pi_irte(struct kvm *kvm, unsigned int host_irq,
> > +uint32_t guest_irq, bool set)
> > +{
> > +   struct kvm_kernel_irq_routing_entry *e;
> > +   struct kvm_irq_routing_table *irq_rt;
> > +   struct kvm_lapic_irq irq;
> > +   struct kvm_vcpu *vcpu;
> > +   struct vcpu_data vcpu_info;
> > +   int idx, ret = -EINVAL;
> > +
> > +   idx = srcu_read_lock(>irq_srcu);
> > +   irq_rt = srcu_dereference(kvm->irq_routing, >irq_srcu);
> > +   BUG_ON(guest_irq >= irq_rt->nr_rt_entries);
> > +
> > +   hlist_for_each_entry(e, _rt->map[guest_irq], link) {
> > +   if (e->type != KVM_IRQ_ROUTING_MSI)
> > +   continue;
> > +   /*
> > +* VT-d PI cannot support posting multicast/broadcast
> > +* interrupts to a VCPU, we still use interrupt remapping
> > +* for these kind of interrupts.
> > +*
> > +* For lowest-priority interrupts, we only support
> > +* those with single CPU as the destination, e.g. user
> > +* configures the interrupts via /proc/irq or uses
> > +* irqbalance to make the interrupts single-CPU.
> > +*
> > +* We will support full lowest-priority interrupt later.
> > +*
> > +*/
> > +
> > +   kvm_set_msi_irq(e, );
> > +   if (!kvm_intr_is_single_vcpu(kvm, , ))
> > +   continue;
> > +
> > +   vcpu_info.pi_desc_addr = 

Re: [PATCH] extcon: Redefine the unique id of supported external connectors without 'enum extcon' type

2015-06-11 Thread Chanwoo Choi
Dear Greg,

On 06/12/2015 01:27 PM, Greg KH wrote:
> On Fri, Jun 12, 2015 at 11:10:06AM +0900, Chanwoo Choi wrote:
>> This patch just redefine the unique id of supported external connectors 
>> without
>> 'enum extcon' type. Because unique id would be used on devictree file(*.dts) 
>> to
>> indicate the specific external connectors like key number of input framework.
>> So, I have the plan to move this definitions to following header file which
>> includes the unique id of supported external connectors.
>> - include/dt-bindings/extcon/extcon.h
>>
>> Fixes: 2a9de9c0f08d ("extcon: Use the unique id for external connector 
>> instead of string")
>> Signed-off-by: Chanwoo Choi 
>> ---
>> Dear Greg,
>>
>> I sent pull-request[1] of extcon for 4.2. This patch[2] in the 
>> pull-request[2]
>> includes the one issue about 'enum extcon'. The 'enum extcon' type is 
>> ambiguous
>> and not clear. So, if you possible, I hope you to pick this patch on 
>> char-misc
>> git repository.
> 
> I don't understand, I took that pull request, right?
> 
> What does that have to do with this patch?

This patch is based on patch[1] and then patch[1] was merged on char-misc-next 
branch (char-misc.git) through pull request.
[1] 2a9de9c0f08d ("extcon: Use the unique id for external connector instead of 
string")

So, after reviewing this patch by you,
if this patch is ok, I hope that this patch will be applied to char-misc-next 
branch.

I'm sorry about un-clear explanation.

Best Regards,
Chanwoo Choi

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/1] staging:f81534 Add F81532/534 Driver

2015-06-11 Thread Greg KH
On Fri, Jun 12, 2015 at 11:43:12AM +0800, Peter Hung wrote:
> This driver is for Fintek F81532/F81534 USB to Serial Ports IC.
> 
> Features:
>   1.  F81534 is 1-to-4 & F81532 is 1-to-2 serial ports IC
>   2.  Support Baudrate from B50 to B150 (excluding B100).
>   3.  The RTS signal can be transformed their behavior with 
> configuration
>   for transceiver (for RS232/RS485/RS422)
>   4.  There are 4x3 GPIOs to control transceiver. It's can be 
> controlled
>   with sysfs
> 
> If had any question, Please send email to
> hpeter+linux_ker...@gmail.com
> peter_h...@fintek.com.tw

Why not just do the work now to clean up the file and get it merged
"properly"?  Why put this in staging at all?

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/1] usb: core: lpm: set lpm_capable for root hub device

2015-06-11 Thread Greg Kroah-Hartman
On Fri, Jun 12, 2015 at 09:29:37AM +0800, Lu Baolu wrote:
> Commit 25cd2882e2fc ("usb/xhci: Change how we indicate a host supports
> Link PM.") removed the code to set lpm_capable for USB 3.0 super-speed
> root hub. The intention of that change was to avoid touching usb core
> internal field, a.k.a. lpm_capable, and let usb core to set it by
> checking U1 and U2 exit latency values in the descriptor.
> 
> Usb core checks and sets lpm_capable in hub_port_init(). Unfortunately,
> root hub is a special usb device as it has no parent. Hub_port_init()
> will never be called for a root hub device. That means lpm_capable will
> by no means be set for the root hub. As the result, lpm isn't functional
> at all in Linux kernel.
> 
> This patch add the code to check and set lpm_capable when registering a
> root hub device. It could be back-ported to kernels as old as v3.15,
> that contains the Commit 25cd2882e2fc ("usb/xhci: Change how we indicate
> a host supports Link PM.").
> 
> Cc: sta...@vger.kernel.org # 3.15
> Reported-by: Kevin Strasser 
> Signed-off-by: Lu Baolu 
> ---
>  drivers/usb/core/hcd.c | 6 ++
>  drivers/usb/core/hub.c | 2 +-
>  drivers/usb/core/usb.h | 1 +
>  3 files changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> index 45a915c..48b208d 100644
> --- a/drivers/usb/core/hcd.c
> +++ b/drivers/usb/core/hcd.c
> @@ -1032,6 +1032,12 @@ static int register_root_hub(struct usb_hcd *hcd)
>   }
>   }
>  
> + if (le16_to_cpu(usb_dev->descriptor.bcdUSB) >= 0x0201) {

Why are you treating a binary coded value as a hex number to compare
against?

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] extcon: Redefine the unique id of supported external connectors without 'enum extcon' type

2015-06-11 Thread Greg KH
On Fri, Jun 12, 2015 at 11:10:06AM +0900, Chanwoo Choi wrote:
> This patch just redefine the unique id of supported external connectors 
> without
> 'enum extcon' type. Because unique id would be used on devictree file(*.dts) 
> to
> indicate the specific external connectors like key number of input framework.
> So, I have the plan to move this definitions to following header file which
> includes the unique id of supported external connectors.
> - include/dt-bindings/extcon/extcon.h

Do we have other such fields in dt-bindings that are not enumerated
types?

What's wrong with keeping this as-is and not changing to an integer?

> Fixes: 2a9de9c0f08d ("extcon: Use the unique id for external connector 
> instead of string")

How is this a bugfix?

confused,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] extcon: Redefine the unique id of supported external connectors without 'enum extcon' type

2015-06-11 Thread Greg KH
On Fri, Jun 12, 2015 at 11:10:06AM +0900, Chanwoo Choi wrote:
> This patch just redefine the unique id of supported external connectors 
> without
> 'enum extcon' type. Because unique id would be used on devictree file(*.dts) 
> to
> indicate the specific external connectors like key number of input framework.
> So, I have the plan to move this definitions to following header file which
> includes the unique id of supported external connectors.
> - include/dt-bindings/extcon/extcon.h
> 
> Fixes: 2a9de9c0f08d ("extcon: Use the unique id for external connector 
> instead of string")
> Signed-off-by: Chanwoo Choi 
> ---
> Dear Greg,
> 
> I sent pull-request[1] of extcon for 4.2. This patch[2] in the pull-request[2]
> includes the one issue about 'enum extcon'. The 'enum extcon' type is 
> ambiguous
> and not clear. So, if you possible, I hope you to pick this patch on char-misc
> git repository.

I don't understand, I took that pull request, right?

What does that have to do with this patch?

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 2/2] x86, mwaitt: introduce mwaix delay with a configurable timer

2015-06-11 Thread Huang Rui
On Thu, Jun 11, 2015 at 10:34:15AM -0700, Andy Lutomirski wrote:
> On Thu, Jun 11, 2015 at 7:14 AM, Huang Rui  wrote:
> > MWAITX can enable a timer and a corresponding timer value specified in SW
> > P0 clocks. The SW P0 frequency is the same with TSC. The timer provides an
> > upper bound on how long the instruction waits before exiting.
> >
> > The implementation of delay function in kernel can lerverage the timer of
> > MWAITX. This patch provides a new method (delay_mwaitx) to measure delay
> > time.
> >
> > Suggested-by: Andy Lutomirski 
> > Suggested-by: Borislav Petkov 
> > Suggested-by: Peter Zijlstra 
> > Signed-off-by: Huang Rui 
> > ---
> >  arch/x86/include/asm/mwait.h | 11 +++
> >  arch/x86/lib/delay.c | 41 -
> >  2 files changed, 51 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h
> > index ece8048..9b41580 100644
> > --- a/arch/x86/include/asm/mwait.h
> > +++ b/arch/x86/include/asm/mwait.h
> > @@ -14,6 +14,8 @@
> >  #define CPUID5_ECX_INTERRUPT_BREAK 0x2
> >
> >  #define MWAIT_ECX_INTERRUPT_BREAK  0x1
> > +#define MWAITX_ECX_TIMER_ENABLEBIT(1)
> > +#define MWAITX_MAX_LOOPS   ((u32)-1)
> >
> >  static inline void __monitor(const void *eax, unsigned long ecx,
> >  unsigned long edx)
> > @@ -80,4 +82,13 @@ static inline void mwait_idle_with_hints(unsigned long 
> > eax, unsigned long ecx)
> > current_clr_polling();
> >  }
> >
> > +static inline void mwaitx(unsigned long eax, unsigned long loops,
> > + bool enable)
> > +{
> > +   if (enable)
> > +   __mwaitx(eax, loops, MWAITX_ECX_TIMER_ENABLE);
> > +   else
> > +   __mwaitx(eax, 0, 0);
> > +}
> 
> What's the purpose of the "enable" parameter?
> 

Enable mwaitx timer. Should I add comments to explain the usage?

Thanks,
Rui
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH non-pretimeout 4/7] Watchdog: introduce ARM SBSA watchdog driver

2015-06-11 Thread Timur Tabi

fu@linaro.org wrote:

+   if (timeout <= gwdt->max_wor_timeout)
+   writel_relaxed(timeout * gwdt->clk,
+  gwdt->control_base + SBSA_GWDT_WOR);
+   else
+   writel_relaxed(gwdt->max_wor_timeout * gwdt->clk,
+  gwdt->control_base + SBSA_GWDT_WOR);


You pre-calculate the maximum timeout possible already, so why do you 
need the if-statement?


Frankly, your non-pretimeout driver is almost identical to mine, which 
was posted weeks ago.  At this point, you're really just copying my 
driver but putting your name on it.


--
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the
Code Aurora Forum, hosted by The Linux Foundation.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: diffs in changelogs

2015-06-11 Thread Joe Perches
On Thu, 2015-06-11 at 20:21 -0700, Andrew Morton wrote:
> On Thu, 11 Jun 2015 20:12:59 -0700 Joe Perches  wrote:
> 
> > On Thu, 2015-06-11 at 13:40 -0700, Andrew Morton wrote:
> > > People often put diff snippets in changelogs.  This causes problems
> > > when one tries to apply a file containing both the changelog and the
> > > diff because patch(1) tries to apply the diff which it found in the
> > > changelog.
> > That 
> > > eg, something like
> > > 
> > >   git show d24a6e1087030b6da | patch -p1
> > > 
> > > will go haywire.
> > > 
> > > So can we please have a checkpatch test warning people away from doing
> > > this?
> > > 
> > > 
> > > patch(1) seems to be really promiscuous in its detection of a patch.  I
> > > haven't had much success searching for "^--- " and similar.  What works
> > > best for me is searching for "^[whitespace]@@ -".
> > 
> > I don't think that's a good test.
> > Coccinelle uses @@
> > 
> > And how did that commit actually get applied?
> 
> Good question.  Maybe `git apply' is smarter about this than patch(1)?

Dunno.  git am failed.
My guess is it was applied normally and then
git commit --amend added the other diff content

> > I tried applying it to a new branch checked out at
> > ce2b3f595e1c56639085645e0130426e443008c0, it fails.
> 
> There are tons of them:
> 
> z:/usr/src/git26> git log | grep "^[]*@@ -"  | wc -l
> 120
> 
> > Anyway, maybe:
> 
> Looks good, thanks.  -ENOCHANGELOG.  Please send it for real when convenient.

RFCPATCH




--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[REGRESSION] NFS is creating a hidden port (left over from xs_bind() )

2015-06-11 Thread Steven Rostedt

I recently upgraded my main server to 4.0.4 from 3.19.5 and rkhunter
started reporting a hidden port on my box.

Running unhide-tcp I see this:

# unhide-tcp 
Unhide-tcp 20121229
Copyright © 2012 Yago Jesus & Patrick Gouin
License GPLv3+ : GNU GPL version 3 or later
http://www.unhide-forensics.info
Used options: 
[*]Starting TCP checking

Found Hidden port that not appears in ss: 946
[*]Starting UDP checking

This scared the hell out of me as I'm thinking that I have got some kind
of NSA backdoor hooked into my server and it is monitoring my plans to
smuggle Kinder Überraschung into the USA from Germany. I panicked!

Well, I wasted the day writing modules to first look at all the sockets
opened by all processes (via their file descriptors) and posted their
port numbers.

  http://rostedt.homelinux.com/private/tasklist.c

But this port wasn't there either.

Then I decided to look at the ports in tcp_hashinfo.

  http://rostedt.homelinux.com/private/portlist.c

This found the port but no file was connected to it, and worse yet,
when I first ran it without using probe_kernel_read(), it crashed my
kernel, because sk->sk_socket pointed to a freed socket!

Note, each boot, the hidden port is different.

Finally, I decided to bring in the big guns, and inserted a
trace_printk() into the bind logic, to see if I could find the culprit.
After fiddling with it a few times, I found a suspect:

   kworker/3:1H-123   [003] ..s.96.696213: inet_bind_hash: add 946

Bah, it's a kernel thread doing it, via a work queue. I then added a
trace_dump_stack() to find what was calling this, and here it is:

kworker/3:1H-123   [003] ..s.96.696222: 
 => inet_csk_get_port
 => inet_addr_type
 => inet_bind
 => xs_bind
 => sock_setsockopt
 => __sock_create
 => xs_create_sock.isra.18
 => xs_tcp_setup_socket
 => process_one_work
 => worker_thread
 => worker_thread
 => kthread
 => kthread
 => ret_from_fork
 => kthread

I rebooted, and examined what happens. I see the kworker binding that
port, and all seems well:

# netstat -tapn |grep 946
tcp0  0 192.168.23.9:946192.168.23.22:55201 ESTABLISHED 
-   

But waiting for a bit, the connection goes into a TIME_WAIT, and then
it just disappears. But the bind to the port does not get released, and
that port is from then on, taken.

This never happened with my 3.19 kernels. I would bisect it but this is
happening on my main server box which I usually only reboot every other
month doing upgrades. It causes too much disturbance for myself (and my
family) as when this box is offline, basically the rest of my machines
are too.

I figured this may be enough information to see if you can fix it.
Otherwise I can try to do the bisect, but that's not going to happen
any time soon. I may just go back to 3.19 for now, such that rkhunter
stops complaining about the hidden port.

If you need anymore information, let me know.

-- Steve
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/1] staging:f81534 Add F81532/534 Driver

2015-06-11 Thread Peter Hung
This driver is for Fintek F81532/F81534 USB to Serial Ports IC.

Features:
1.  F81534 is 1-to-4 & F81532 is 1-to-2 serial ports IC
2.  Support Baudrate from B50 to B150 (excluding B100).
3.  The RTS signal can be transformed their behavior with 
configuration
for transceiver (for RS232/RS485/RS422)
4.  There are 4x3 GPIOs to control transceiver. It's can be 
controlled
with sysfs

If had any question, Please send email to
hpeter+linux_ker...@gmail.com
peter_h...@fintek.com.tw

Patches Welcome :D

Signed-off-by: Peter Hung 
---
 drivers/staging/Kconfig |2 +
 drivers/staging/Makefile|1 +
 drivers/staging/f81534/Kconfig  |   10 +
 drivers/staging/f81534/Makefile |1 +
 drivers/staging/f81534/Readme   |9 +
 drivers/staging/f81534/TODO |   12 +
 drivers/staging/f81534/f81534.c | 3335 +++
 7 files changed, 3370 insertions(+)
 create mode 100644 drivers/staging/f81534/Kconfig
 create mode 100644 drivers/staging/f81534/Makefile
 create mode 100644 drivers/staging/f81534/Readme
 create mode 100644 drivers/staging/f81534/TODO
 create mode 100644 drivers/staging/f81534/f81534.c

diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index 7f6cae5..b7c0bd0 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -112,4 +112,6 @@ source "drivers/staging/fsl-mc/Kconfig"
 
 source "drivers/staging/wilc1000/Kconfig"
 
+source "drivers/staging/f81534/Kconfig"
+
 endif # STAGING
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index 347f647..9d17cb8 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -48,3 +48,4 @@ obj-$(CONFIG_COMMON_CLK_XLNX_CLKWZRD) += clocking-wizard/
 obj-$(CONFIG_FB_TFT)   += fbtft/
 obj-$(CONFIG_FSL_MC_BUS)   += fsl-mc/
 obj-$(CONFIG_WILC1000) += wilc1000/
+obj-$(CONFIG_USB_SERIAL_F8153X)+= f81534/
diff --git a/drivers/staging/f81534/Kconfig b/drivers/staging/f81534/Kconfig
new file mode 100644
index 000..41bf55c
--- /dev/null
+++ b/drivers/staging/f81534/Kconfig
@@ -0,0 +1,10 @@
+#
+# Xilinx Clocking Wizard Driver
+#
+
+config USB_SERIAL_F8153X
+   tristate "F81532/534 USB to Serial Ports Driver"
+   depends on USB_SERIAL
+   default m
+   ---help---
+ Support for Fintek F81532/534 USB to Serial Ports board
diff --git a/drivers/staging/f81534/Makefile b/drivers/staging/f81534/Makefile
new file mode 100644
index 000..d73178d
--- /dev/null
+++ b/drivers/staging/f81534/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_USB_SERIAL_F8153X)+= f81534.o
diff --git a/drivers/staging/f81534/Readme b/drivers/staging/f81534/Readme
new file mode 100644
index 000..00b72b0
--- /dev/null
+++ b/drivers/staging/f81534/Readme
@@ -0,0 +1,9 @@
+This driver is for Fintek F81534/F81532
+
+Features:
+   1.  F81534 is 1-to-4 & F81532 is 1-to-2 serial ports IC
+   2.  Support Baudrate from B50 to B150 (excluding B100).
+   3.  The RTS signal can be transformed their behavior with 
configuration
+   for transceiver (for RS232/RS485/RS422)
+   4.  There are 4x3 GPIOs to control transceiver. It's can be 
controlled with
+   sysfs
\ No newline at end of file
diff --git a/drivers/staging/f81534/TODO b/drivers/staging/f81534/TODO
new file mode 100644
index 000..422bdf2
--- /dev/null
+++ b/drivers/staging/f81534/TODO
@@ -0,0 +1,12 @@
+Current Progress
+   - Functional Test ok (BurninTest 921600bps 4Port / S4 / S5)
+
+TODO:
+   - Code review
+   - checkpatch.pl
+
+Welcome to send patch for F81532/534 If you found a problem.
+
+Patches to:
+   Greg Kroah-Hartman 
+   Peter Hong 
diff --git a/drivers/staging/f81534/f81534.c b/drivers/staging/f81534/f81534.c
new file mode 100644
index 000..f6f5c2b
--- /dev/null
+++ b/drivers/staging/f81534/f81534.c
@@ -0,0 +1,3335 @@
+/*
+ * F81532/F81534 USB to Serial Ports Bridge
+ *
+ * F81532 => 2 Serial Ports
+ * F81534 => 4 Serial Ports
+ *
+ * Copyright (C) 2014 Tom Tsai (tom_t...@fintek.com.tw)
+ *
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Serial Port register Address */
+#define SERIAL_BASE_ADDRESS0x1200
+#define RECEIVE_BUFFER_REGISTER(0x00 + SERIAL_BASE_ADDRESS)
+#define TRANSMIT_HOLDING_REGISTER  (0x00 + SERIAL_BASE_ADDRESS)
+#define INTERRUPT_ENABLE_REGISTER  (0x01 + SERIAL_BASE_ADDRESS)
+#define INTERRUPT_IDENT_REGISTER   (0x02 + SERIAL_BASE_ADDRESS)
+#define FIFO_CONTROL_REGISTER  (0x02 + SERIAL_BASE_ADDRESS)
+#define LINE_CONTROL_REGISTER  (0x03 + SERIAL_BASE_ADDRESS)
+#define MODEM_CONTROL_REGISTER (0x04 + SERIAL_BASE_ADDRESS)
+#define LINE_STATUS_REGISTER   (0x05 + 

Re: [PATCH RESEND] sched: prefer an idle cpu vs an idle sibling for BALANCE_WAKE

2015-06-11 Thread Rik van Riel
On 06/11/2015 04:33 PM, Josef Bacik wrote:

> Ugh I'm sorry, I've been running tests trying to get the numbers to look
> good when I noticed I was getting some inconsistencies in my results.
> Turns out I never actually tested your patch just plain, I had been
> testing it with BALANCE_WAKE, because I was under the assumption that
> was what was best for our workload.  Since then I had fixed all of our
> scripts and such and noticed that it actually super duper sucks for us.
>  So testing with this original patch everything is significantly better
> (this is with the default SD flags set, no changes at all).
> 
> So now that I've wasted a good bit of my time and everybody elses, can
> we go about pushing this patch upstream?  If you are happy with it the
> way it is I'll go ahead and pull it into our kernels and just watch to
> make sure it ends upstream at some point.  Thanks,

FWIW, Jirka has run some tests with the patch as well,
and seen significant performance improvements on
various tests, on various systems.

Merging the patch makes perfect sense to me.

Acked-by: Rik van Riel 

-- 
All rights reversed
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v6 2/3] IB/ipath: add counting for MTRR

2015-06-11 Thread Doug Ledford
On 06/11/2015 03:54 PM, Borislav Petkov wrote:
> On Thu, Jun 11, 2015 at 10:50:01AM -0700, Luis R. Rodriguez wrote:
>> From: "Luis R. Rodriguez" 
>>
>> There is no good reason not to, we eventually delete it as well.
>>
>> Cc: Toshi Kani 
>> Cc: Roland Dreier 
>> Cc: Sean Hefty 
>> Cc: Hal Rosenstock 
>> Cc: Suresh Siddha 
>> Cc: Ingo Molnar 
>> Cc: Thomas Gleixner 
>> Cc: Juergen Gross 
>> Cc: Daniel Vetter 
>> Cc: Andy Lutomirski 
>> Cc: Dave Airlie 
>> Cc: Antonino Daplas 
>> Cc: Jean-Christophe Plagniol-Villard 
>> Cc: Tomi Valkeinen 
>> Cc: infinip...@intel.com
>> Cc: linux-r...@vger.kernel.org
>> Cc: linux-fb...@vger.kernel.org
>> Cc: linux-kernel@vger.kernel.org
>> Signed-off-by: Luis R. Rodriguez 
>> ---
>>  drivers/infiniband/hw/ipath/ipath_wc_x86_64.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/infiniband/hw/ipath/ipath_wc_x86_64.c 
>> b/drivers/infiniband/hw/ipath/ipath_wc_x86_64.c
>> index 4ad0b93..70c1f3a 100644
>> --- a/drivers/infiniband/hw/ipath/ipath_wc_x86_64.c
>> +++ b/drivers/infiniband/hw/ipath/ipath_wc_x86_64.c
>> @@ -127,7 +127,7 @@ int ipath_enable_wc(struct ipath_devdata *dd)
>> "(addr %llx, len=0x%llx)\n",
>> (unsigned long long) pioaddr,
>> (unsigned long long) piolen);
>> -cookie = mtrr_add(pioaddr, piolen, MTRR_TYPE_WRCOMB, 0);
>> +cookie = mtrr_add(pioaddr, piolen, MTRR_TYPE_WRCOMB, 1);
>>  if (cookie < 0) {
>>  {
>>  dev_info(>pcidev->dev,
>> --
> 
> Doug, ack?
> 

Ack.




signature.asc
Description: OpenPGP digital signature


linux-next: manual merge of the l2-mtd tree with the mips tree

2015-06-11 Thread Michael Ellerman
Hi Brian,

Today's linux-next merge of the l2-mtd tree got a conflict in MAINTAINERS
between commit 68c2d21d0126 "MIPS: BCM47xx: Move NVRAM driver to the
drivers/firmware/" from the mips tree and commit 02787daadbda "MAINTAINERS: add
entry for new brcmnand/ directory" from the l2-mtd tree.

I fixed it up (see below) and can carry the fix as necessary (no action
is required).

diff --cc MAINTAINERS
index 85dc5bd76c38,ad9f36875372..d848473e184f
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@@ -2320,12 -2257,12 +2320,18 @@@ S:   Supporte
  F:drivers/gpio/gpio-bcm-kona.c
  F:Documentation/devicetree/bindings/gpio/gpio-bcm-kona.txt
  
 +BROADCOM NVRAM DRIVER
 +M:Rafał Miłecki 
 +L:linux-m...@linux-mips.org
 +S:Maintained
 +F:drivers/firmware/broadcom/*
 +
+ BROADCOM STB NAND FLASH DRIVER
+ M:Brian Norris 
+ L:linux-...@lists.infradead.org
+ S:Maintained
+ F:drivers/mtd/nand/brcmnand/
+ 
  BROADCOM SPECIFIC AMBA DRIVER (BCMA)
  M:Rafał Miłecki 
  L:linux-wirel...@vger.kernel.org

cheers



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] module: make perm const, change BUG_ON to BUILD_BUG_ON

2015-06-11 Thread Dan Streetman
On Thu, Jun 11, 2015 at 9:43 PM, Rusty Russell  wrote:
> Dan Streetman  writes:
>> Change the struct kernel_param.perm field to a const, as it should never
>> be changed.  Add inline functions that return a const value, which are
>> compiled out, for kparam_[un]block_sysfs_r/w() macros to use; and change
>> the BUG_ON() in those macros to BUILD_BUG_ON().
>
> Nice win!
>
> I think it's slightly clearer if we just declare:
>
> static __always_unused const u16 __param_perm_##name = (perm).
>
> And indeed, gcc (at least 4.9) eliminates it correctly.
>
> So, here's your patch with that mod, and the param.c noise removed.
> It's in my pending queue for the moment.
>
> I still am leaning towards just removing these wrappers and exposing
> the (new) per-module mutex though.  Happy for that patch to replace this
> one, if you send it.

sure ok, i'll update it and send it tomorrow.  Thanks!

>
> Thanks,
> Rusty.
>
> From: Dan Streetman 
> Subject: module: make perm const, change BUG_ON to BUILD_BUG_ON
>
> Change the struct kernel_param.perm field to a const, as it should never
> be changed.  Add a static const name for this (which gcc compiles out)
> for kparam_[un]block_sysfs_r/w() macros to use; and change the BUG_ON()
> in those macros to BUILD_BUG_ON().
>
> This will enforce that the kernel_param permissions are never changed,
> and it will fail at build instead of runtime for any misuse of
> sysfs param blocking.
>
> I initially wanted to just use the const param.perm in the block_sysfs
> checks, but unfortunately that also requires the param itself to be
> const, in order to do const folding into a constant compiletime
> condition to BUILD_BUG_ON(), and on some archs the params aren't defined
> as const:
>
> /* On alpha, ia64 and ppc64 relocations to global data cannot go into
>read-only sections (which is part of respective UNIX ABI on these
>platforms). So 'const' makes no sense and even causes compile failures
>with some compilers. */
>
> Signed-off-by: Dan Streetman 
> Signed-off-by: Rusty Russell  (slight tweak)
>
> diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
> index 7e0079936396..347e11f3bc32 100644
> --- a/include/linux/moduleparam.h
> +++ b/include/linux/moduleparam.h
> @@ -68,7 +68,7 @@ enum {
>  struct kernel_param {
> const char *name;
> const struct kernel_param_ops *ops;
> -   u16 perm;
> +   const u16 perm;
> s8 level;
> u8 flags;
> union {
> @@ -215,8 +215,10 @@ struct kparam_array
>  /* This is the fundamental function for registering boot/module
> parameters. */
>  #define __module_param_call(prefix, name, ops, arg, perm, level, flags)  
>   \
> +   /* These allow kparam_block_sysfs_*() to use BUILD_BUG_ON() */  \
> +   static __always_unused const u16 __param_perm_##name = (perm);  \
> /* Default value instead of permissions? */ \
> -   static const char __param_str_##name[] = prefix #name; \
> +   static const char __param_str_##name[] = prefix #name;  \
> static struct kernel_param __moduleparam_const __param_##name   \
> __used  \
>  __attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void * 
> \
> @@ -244,20 +246,20 @@ __check_old_set_param(int (*oldset)(const char *, 
> struct kernel_param *))
>   *
>   * There's no point blocking write on a paramter that isn't writable via 
> sysfs!
>   */
> -#define kparam_block_sysfs_write(name) \
> -   do {\
> -   BUG_ON(!(__param_##name.perm & 0222));  \
> -   __kernel_param_lock();  \
> +#define kparam_block_sysfs_write(name) \
> +   do {\
> +   BUILD_BUG_ON(!(__param_perm_##name & 0222));\
> +   __kernel_param_lock();  \
> } while (0)
>
>  /**
>   * kparam_unblock_sysfs_write - allows sysfs to write to a parameter again.
>   * @name: the name of the parameter
>   */
> -#define kparam_unblock_sysfs_write(name)   \
> -   do {\
> -   BUG_ON(!(__param_##name.perm & 0222));  \
> -   __kernel_param_unlock();\
> +#define kparam_unblock_sysfs_write(name)   \
> +   do {\
> +   BUILD_BUG_ON(!(__param_perm_##name & 0222));\
> +   __kernel_param_unlock();\
> } while (0)
>
>  /**
> @@ -266,20 +268,20 @@ __check_old_set_param(int (*oldset)(const char *, 
> struct kernel_param *))
>   *
>   * This also blocks sysfs writes.
>   */
> -#define kparam_block_sysfs_read(name)  

Re: diffs in changelogs

2015-06-11 Thread Andrew Morton
On Thu, 11 Jun 2015 20:12:59 -0700 Joe Perches  wrote:

> On Thu, 2015-06-11 at 13:40 -0700, Andrew Morton wrote:
> > People often put diff snippets in changelogs.  This causes problems
> > when one tries to apply a file containing both the changelog and the
> > diff because patch(1) tries to apply the diff which it found in the
> > changelog.
> That 
> > eg, something like
> > 
> > git show d24a6e1087030b6da | patch -p1
> > 
> > will go haywire.
> > 
> > So can we please have a checkpatch test warning people away from doing
> > this?
> > 
> > 
> > patch(1) seems to be really promiscuous in its detection of a patch.  I
> > haven't had much success searching for "^--- " and similar.  What works
> > best for me is searching for "^[whitespace]@@ -".
> 
> I don't think that's a good test.
> Coccinelle uses @@
> 
> And how did that commit actually get applied?

Good question.  Maybe `git apply' is smarter about this than patch(1)?

> I tried applying it to a new branch checked out at
> ce2b3f595e1c56639085645e0130426e443008c0, it fails.

There are tons of them:

z:/usr/src/git26> git log | grep "^[]*@@ -"  | wc -l
120

> Anyway, maybe:

Looks good, thanks.  -ENOCHANGELOG.  Please send it for real when convenient.


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH tip/perf/core] tools lib traceevent: Fix python/perf.so compiling error

2015-06-11 Thread Wang Nan
'make build-test' finds an error that make_python_perf_so fails due to
missing of libtraceevent-dynamic-list:

 '.../python2' util/setup.py \
   --quiet build_ext; \
   mkdir -p python && \
   cp python_ext_build/lib/perf.so python/
   /path/to/ld: cannot open linker script file 
/path/to/kernel/tools/lib/traceevent/libtraceevent-dynamic-list: No such file 
or directory
   collect2: error: ld returned 1 exit status
   error: command 'x86_64-linux-gcc' failed with exit status 1
   cp: cannot stat 'python_ext_build/lib/perf.so': No such file or directory
   make[3]: *** [python/perf.so] Error 1
   make[2]: *** [python/perf.so] Error 2
 test: test -f ./python/perf.so
 make[1]: *** [make_python_perf_so] Error 1
 make: *** [build-test] Error 2
 make: Leaving directory `/path/to/kernel/tools/perf'

This is caused by commit e3d09ec8126fe2c9a3ade661e2126e215ca27a80
("tools lib traceevent: Export dynamic symbols used by traceevent
plugins") that, it adds the list file to LDFLAGS but forgot to add it
to dependency list of python/perf.so.

This patch fixes this problem.

Signed-off-by: Wang Nan 
---
 tools/perf/Makefile.perf | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 280c4c6..ec2ed6e 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -195,7 +195,7 @@ python-clean := $(call QUIET_CLEAN, python) $(RM) -r 
$(PYTHON_EXTBUILD) $(OUTPUT
 PYTHON_EXT_SRCS := $(shell grep -v ^\# util/python-ext-sources)
 PYTHON_EXT_DEPS := util/python-ext-sources util/setup.py $(LIBTRACEEVENT) 
$(LIBAPI)
 
-$(OUTPUT)python/perf.so: $(PYTHON_EXT_SRCS) $(PYTHON_EXT_DEPS)
+$(OUTPUT)python/perf.so: $(PYTHON_EXT_SRCS) $(PYTHON_EXT_DEPS) 
$(LIBTRACEEVENT_DYNAMIC_LIST)
$(QUIET_GEN)CFLAGS='$(CFLAGS)' $(PYTHON_WORD) util/setup.py \
  --quiet build_ext; \
mkdir -p $(OUTPUT)python && \
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] kernel/params.c: make use of unused but set variable

2015-06-11 Thread Louis Langholtz
Hi Tejun,

On Jun 10, 2015, at 7:54 PM, Tejun Heo  wrote:

> Hey, Louis.
> 
> On Wed, Jun 10, 2015 at 11:05:21AM -0600, Louis Langholtz wrote:
>> The underlying code for sysfs_create_file does call WARN to warn about
>> any errors. So it's not like the code is totally silent anyway. Then the 
>> unused
> 
> Not any errors.  It triggers warning on missing ops and dup file
> names.

Ah... I see now that the underlying code doesn't warn about all errors.
Specifically that code doesn't warn about __kernfs_create_file() returning
any error code other than EEXIST. So it's quiet on a few other error codes
it can return (like ENOMEM or ENOENT). Warnings are generated when
sysfs_create_file() returns EINVAL or EEXIST.

> The former is a pretty fundamental usage error and we've had
> too many of the latter unhandled despite of __must_check.

Admittedly the preconditions for sysfs_create_file() seem obscure to me.
Perhaps that's contributed to the problem you've described (some
comment documentation for the sysfs_create_file function I think
would be useful). And what should be done after this function returns?
Having this __must_check says its return value must be used. But how
should it be used? More on this question after next quote block...

> 
>> ...
>> Having functions marked __must_check seems to make more sense when
>> their return values are *always* necessary for calling code to have any
>> business calling them. Like when there's one or more future calls to 
>> functions
>> that have to be made (or not made) for the given resource (the kobject) that
>> depend on that function's return value (such that the return value state is
>> always a later conditional). That doesn't appear to be the case however for
>> sysfs_create_file().
> 
> I don't know.  Sounds like a weird rule.  We had __must_check, still
> had certain error types unhandled so people added explicit WARN to
> force people to look into those issues and that means __must_check
> should go away?

Taken in light of the sysfs_create_file function the rule seems (at least for
the moment) helpful in addressing what should be done about the return
value of sysfs_create_file().

Should the caller WARN about all errors returned from sysfs_create_file()?
Even those already reported (like when sysfs_create_file() returns EINVAL
or EEXIST)? If all errors should be WARNed (by code somewhere) then
would it be better to have the code underlying sysfs_create_file() do that?
If the code underlying sysfs_create_file() warns about all errors, then no
caller needs to duplicate that code. Alternatively the caller could just warn
when the return code isn't one that's already be warned about. But as the
code is now, that relies on how sysfs_create_file() underlying code is coded
to know what's already been warned and breaks as soon as someone
changes what sysfs_create_file() warns about without updating what the
callers warn about. That solution seems unnecessarily fragile.

What else should always be done besides provide WARN for errors? If
nothing else should always be done and errors are logged by the
underlying code, then what point is left for sysfs_create_file() being
marked __must_check? It shouldn't be - at least by this offered rule -
since its return value isn't always necessary for the caller to still have
business in calling it given that it has a worthwhile side-effect (when it
succeeds).

> Sure, if it warns on all errors and can return void
> then there's nothing to discuss but that's not the case.  Here, an
> error return indicates userland visible behavior difference.  I'd
> venture to say that the return value is pretty darn important.

I don't mean to diminish the significance of userland visible behavior
difference. These are significant. And I don't want sysfs_create_file()
to return void. But if there's no clear things that callers of 
sysfs_create_file()
should do based on its return value then marking it __must_check seems
wrong. I'm guessing (based on the commit log message) that Andrew
originally established the precedent for this marking though to help get
rid of cases where callers needed to do something different than they
were when errors occurred because their code was blindly assuming
success.

The return value of kmalloc I'd argue meanwhile should always be used.
Oddly it's not marked __must_check. But based on this rule, it makes more
sense to. What business would a caller have in calling kmalloc if it's not
going to use the return value? There is a side-effect of using up memory
but I don't know of a reason that's ever desirable for a properly running
kernel if the memory is not used (or at least passed to the free function).
Fortunately I don't see any callers that aren't using the return value and
marking it __must_check only helps to reaffirm what callers already know.

> ...
>> Adding __must_check probably made it easier for developers to identify 
>> calling
>> code that was depending on success from these functions. At the same 

[PATCH v3 1/3] NTP: rtc: Add CONFIG_RTC_SYSTOHC_DEVICE for NTP synchronization

2015-06-11 Thread Xunlei Pang
From: Xunlei Pang 

Currently, CONFIG_RTC_SYSTOHC uses CONFIG_RTC_HCTOSYS_DEVICE which
is originally used by CONFIG_RTC_HCTOSYS, but this rtc device has
some limiations, for example, it must be battery-backed, be able
to work with irq off and through system suspension, etc.

So add CONFIG_RTC_SYSTOHC_DEVICE used exclusively for CONFIG_RTC_SYSTOHC,
it is more lenient compared to CONFIG_RTC_HCTOSYS_DEVICE, and could
be assigned any available RTC in the system.

Default value is CONFIG_RTC_HCTOSYS_DEVICE which is "rtc0" by default.
After this patch, NTP will sync up "rtc0" by default.

Cc: Paul Bolle 
Signed-off-by: Xunlei Pang 
---
 drivers/rtc/Kconfig   | 28 +++-
 drivers/rtc/systohc.c |  2 +-
 2 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 0fe4ad8..1dcfab4 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -25,17 +25,9 @@ config RTC_HCTOSYS
  the value read from a specified RTC device. This is useful to avoid
  unnecessary fsck runs at boot time, and to network better.
 
-config RTC_SYSTOHC
-   bool "Set the RTC time based on NTP synchronization"
-   default y
-   help
- If you say yes here, the system time (wall clock) will be stored
- in the RTC specified by RTC_HCTOSYS_DEVICE approximately every 11
- minutes if userspace reports synchronized NTP status.
-
 config RTC_HCTOSYS_DEVICE
string "RTC used to set the system time"
-   depends on RTC_HCTOSYS = y || RTC_SYSTOHC = y
+   depends on RTC_HCTOSYS
default "rtc0"
help
  The RTC device that will be used to (re)initialize the system
@@ -56,6 +48,24 @@ config RTC_HCTOSYS_DEVICE
  sleep states. Do not specify an RTC here unless it stays powered
  during all this system's supported sleep states.
 
+config RTC_SYSTOHC
+   bool "Set the RTC time based on NTP synchronization"
+   default y
+   help
+ If you say yes here, the system time (wall clock) will be stored
+ in the RTC specified by RTC_HCTOSYS_DEVICE approximately every 11
+ minutes if userspace reports synchronized NTP status.
+
+config RTC_SYSTOHC_DEVICE
+   string "RTC used to synchronize NTP adjustment"
+   depends on RTC_SYSTOHC
+   default RTC_HCTOSYS_DEVICE
+   help
+ The RTC device used for NTP synchronization. The main difference
+ between RTC_HCTOSYS_DEVICE and RTC_SYSTOHC_DEVICE is that this
+ one can sleep when setting time, because it runs in the workqueue
+ context.
+
 config RTC_DEBUG
bool "RTC debug support"
help
diff --git a/drivers/rtc/systohc.c b/drivers/rtc/systohc.c
index 7728d5e..b4a68ff 100644
--- a/drivers/rtc/systohc.c
+++ b/drivers/rtc/systohc.c
@@ -31,7 +31,7 @@ int rtc_set_ntp_time(struct timespec64 now)
else
rtc_time64_to_tm(now.tv_sec + 1, );
 
-   rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);
+   rtc = rtc_class_open(CONFIG_RTC_SYSTOHC_DEVICE);
if (rtc) {
/* rtc_hctosys exclusively uses UTC, so we call set_time here,
 * not set_mmss. */
-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 6/6] regulator: qcom-spmi: Add vendor specific configuration

2015-06-11 Thread Rob Herring
On Thu, Jun 11, 2015 at 7:37 PM, Stephen Boyd  wrote:
> Add support for over current protection (OCP), pin control
> selection, soft start and soft start strength, auto-mode, input
> current limiting, and pull down.
>
> Cc: 
> Signed-off-by: Stephen Boyd 
> ---
>
> Changes from v1:
> * New patch split from original SPMI regulator driver
>
>  .../bindings/regulator/qcom,spmi-regulator.txt |  62 +
>  drivers/regulator/qcom_spmi-regulator.c| 298 
> -
>  2 files changed, 358 insertions(+), 2 deletions(-)
>
> diff --git 
> a/Documentation/devicetree/bindings/regulator/qcom,spmi-regulator.txt 
> b/Documentation/devicetree/bindings/regulator/qcom,spmi-regulator.txt
> index 75b4604bad07..ab01a152e930 100644
> --- a/Documentation/devicetree/bindings/regulator/qcom,spmi-regulator.txt
> +++ b/Documentation/devicetree/bindings/regulator/qcom,spmi-regulator.txt
> @@ -99,6 +99,68 @@ see regulator.txt - with additional custom properties 
> described below:
> soft start are active all the time. 0 = Set initial mode 
> to
> low power mode (LPM).
>
> +- qcom,auto-mode-enable:

Auto regulator modes are fairly common. Can't we have a common property here?

> +   Usage: optional
> +   Value type: 

This can be bool. Unless we want to have a mode property with "auto"
being one possible value.

> +   Description: 1 = Enable automatic hardware selection of regulator
> +mode (HPM vs LPM); not available on boost type
> +regulators. 0 = Disable auto mode selection.
> +
> +- qcom,ocp-enable:
> +   Usage: optional
> +   Value type: 
> +   Description: 1 = Allow over current protection (OCP) to be enabled for
> +voltage switch type regulators so that they latch off
> +automatically when over current is detected. OCP is
> +enabled when in HPM or auto mode.  0 = Disable OCP.

This seems common too.

> +
> +- qcom,ocp-max-retries:
> +   Usage: optional
> +   Value type: 
> +   Description: Maximum number of times to try toggling a voltage switch
> +off and back on as a result of consecutive over current
> +events.
> +
> +- qcom,ocp-retry-delay:
> +   Usage: optional
> +   Value type: 
> +   Description: Time to delay in milliseconds between each voltage switch
> +toggle after an over current event takes place.

These 2 are perhaps less common. I hope I don't have a device that does this. :)

Rob
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 2/3] sparc: time: Replace update_persistent_clock() with CONFIG_RTC_SYSTOHC

2015-06-11 Thread Xunlei Pang
From: Xunlei Pang 

On Sparc systems, update_persistent_clock() uses RTC drivers to do
the job, it makes more sense to hand it over to CONFIG_RTC_SYSTOHC.

In the long run, all the update_persistent_clock() should migrate to
proper class RTC drivers if any and use CONFIG_RTC_SYSTOHC instead.

Signed-off-by: Xunlei Pang 
---
 arch/sparc/Kconfig  |  2 +-
 arch/sparc/kernel/time_32.c | 21 -
 arch/sparc/kernel/time_64.c | 14 --
 3 files changed, 1 insertion(+), 36 deletions(-)

diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index e49502a..56442d2 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -25,6 +25,7 @@ config SPARC
select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
select RTC_CLASS
select RTC_DRV_M48T59
+   select RTC_SYSTOHC
select HAVE_DMA_ATTRS
select HAVE_DMA_API_DEBUG
select HAVE_ARCH_JUMP_LABEL if SPARC64
@@ -35,7 +36,6 @@ config SPARC
select HAVE_BPF_JIT
select HAVE_DEBUG_BUGVERBOSE
select GENERIC_SMP_IDLE_THREAD
-   select GENERIC_CMOS_UPDATE
select GENERIC_CLOCKEVENTS
select GENERIC_STRNCPY_FROM_USER
select GENERIC_STRNLEN_USER
diff --git a/arch/sparc/kernel/time_32.c b/arch/sparc/kernel/time_32.c
index 8caf45e..c9692f3 100644
--- a/arch/sparc/kernel/time_32.c
+++ b/arch/sparc/kernel/time_32.c
@@ -23,7 +23,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -65,8 +64,6 @@ DEFINE_PER_CPU(struct clock_event_device, sparc32_clockevent);
 DEFINE_SPINLOCK(rtc_lock);
 EXPORT_SYMBOL(rtc_lock);
 
-static int set_rtc_mmss(unsigned long);
-
 unsigned long profile_pc(struct pt_regs *regs)
 {
extern char __copy_user_begin[], __copy_user_end[];
@@ -87,11 +84,6 @@ EXPORT_SYMBOL(profile_pc);
 
 volatile u32 __iomem *master_l10_counter;
 
-int update_persistent_clock(struct timespec now)
-{
-   return set_rtc_mmss(now.tv_sec);
-}
-
 irqreturn_t notrace timer_interrupt(int dummy, void *dev_id)
 {
if (timer_cs_enabled) {
@@ -362,16 +354,3 @@ void __init time_init(void)
sbus_time_init();
 }
 
-
-static int set_rtc_mmss(unsigned long secs)
-{
-   struct rtc_device *rtc = rtc_class_open("rtc0");
-   int err = -1;
-
-   if (rtc) {
-   err = rtc_set_mmss(rtc, secs);
-   rtc_class_close(rtc);
-   }
-
-   return err;
-}
diff --git a/arch/sparc/kernel/time_64.c b/arch/sparc/kernel/time_64.c
index edbbeb1..2e6035c 100644
--- a/arch/sparc/kernel/time_64.c
+++ b/arch/sparc/kernel/time_64.c
@@ -28,7 +28,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -394,19 +393,6 @@ static struct sparc64_tick_ops hbtick_operations 
__read_mostly = {
 
 static unsigned long timer_ticks_per_nsec_quotient __read_mostly;
 
-int update_persistent_clock(struct timespec now)
-{
-   struct rtc_device *rtc = rtc_class_open("rtc0");
-   int err = -1;
-
-   if (rtc) {
-   err = rtc_set_mmss(rtc, now.tv_sec);
-   rtc_class_close(rtc);
-   }
-
-   return err;
-}
-
 unsigned long cmos_regs;
 EXPORT_SYMBOL(cmos_regs);
 
-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 3/3] drivers/rtc/interface.c: Remove rtc_set_mmss()

2015-06-11 Thread Xunlei Pang
From: Xunlei Pang 

Now rtc_set_mmss() has no users, just remove it.

We still have rtc_set_time() doing similar things.

Signed-off-by: Xunlei Pang 
---
 drivers/rtc/interface.c | 45 -
 include/linux/rtc.h |  1 -
 2 files changed, 46 deletions(-)

diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 166fc60..b511aa1 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -91,51 +91,6 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
 }
 EXPORT_SYMBOL_GPL(rtc_set_time);
 
-int rtc_set_mmss(struct rtc_device *rtc, unsigned long secs)
-{
-   int err;
-
-   err = mutex_lock_interruptible(>ops_lock);
-   if (err)
-   return err;
-
-   if (!rtc->ops)
-   err = -ENODEV;
-   else if (rtc->ops->set_mmss64)
-   err = rtc->ops->set_mmss64(rtc->dev.parent, secs);
-   else if (rtc->ops->set_mmss)
-   err = rtc->ops->set_mmss(rtc->dev.parent, secs);
-   else if (rtc->ops->read_time && rtc->ops->set_time) {
-   struct rtc_time new, old;
-
-   err = rtc->ops->read_time(rtc->dev.parent, );
-   if (err == 0) {
-   rtc_time64_to_tm(secs, );
-
-   /*
-* avoid writing when we're going to change the day of
-* the month. We will retry in the next minute. This
-* basically means that if the RTC must not drift
-* by more than 1 minute in 11 minutes.
-*/
-   if (!((old.tm_hour == 23 && old.tm_min == 59) ||
-   (new.tm_hour == 23 && new.tm_min == 59)))
-   err = rtc->ops->set_time(rtc->dev.parent,
-   );
-   }
-   } else {
-   err = -EINVAL;
-   }
-
-   pm_stay_awake(rtc->dev.parent);
-   mutex_unlock(>ops_lock);
-   /* A timer might have just expired */
-   schedule_work(>irqwork);
-
-   return err;
-}
-EXPORT_SYMBOL_GPL(rtc_set_mmss);
-
 static int rtc_read_alarm_internal(struct rtc_device *rtc, struct rtc_wkalrm 
*alarm)
 {
int err;
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index f46f765..f9c76a8 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -169,7 +169,6 @@ extern void devm_rtc_device_unregister(struct device *dev,
 
 extern int rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm);
 extern int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm);
-extern int rtc_set_mmss(struct rtc_device *rtc, unsigned long secs);
 extern int rtc_set_ntp_time(struct timespec64 now);
 int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm);
 extern int rtc_read_alarm(struct rtc_device *rtc,
-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: diffs in changelogs

2015-06-11 Thread Joe Perches
On Thu, 2015-06-11 at 13:40 -0700, Andrew Morton wrote:
> People often put diff snippets in changelogs.  This causes problems
> when one tries to apply a file containing both the changelog and the
> diff because patch(1) tries to apply the diff which it found in the
> changelog.
That 
> eg, something like
> 
>   git show d24a6e1087030b6da | patch -p1
> 
> will go haywire.
> 
> So can we please have a checkpatch test warning people away from doing
> this?
> 
> 
> patch(1) seems to be really promiscuous in its detection of a patch.  I
> haven't had much success searching for "^--- " and similar.  What works
> best for me is searching for "^[whitespace]@@ -".

I don't think that's a good test.
Coccinelle uses @@

And how did that commit actually get applied?

I tried applying it to a new branch checked out at
ce2b3f595e1c56639085645e0130426e443008c0, it fails.

Anyway, maybe:
---
 scripts/checkpatch.pl | 12 
 1 file changed, 12 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 69c4716..2d87e37 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2399,6 +2399,18 @@ sub process {
$in_commit_log = 1;
}
 
+# Check if the commit log has a diff which confuse patch
+
+   print("icl: <$in_commit_log> line: <$line>\n");
+   if ($in_commit_log &&
+   (($line =~ m@^\s+diff\b.*a/[\w/]+@ &&
+ $line =~ m@^\s+diff\b.*a/([\w/]+)\s+b/$1\b@) ||
+$line =~ m@^\s*(?:\-\-\-\s+a/|\+\+\+\s+b/)@ ||
+$line =~ m/^\s*\@\@ \-\d+,\d+ \+\d+,\d+ \@\@/)) {
+   ERROR("DIFF_IN_COMMIT_MSG",
+ "It seems a diff exists in the commit message. 
This can confuse patch\n" . $herecurr);
+   }
+
 # Check if there is UTF-8 in a commit log when a mail header has explicitly
 # declined it, i.e defined some charset where it is missing.
if ($in_header_lines &&


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


perf: aux area related crash and warnings

2015-06-11 Thread Vince Weaver

The fuzzer turned these up (this is 4.1-rc7 with the fasync patch 
applied) on a Haswell.  I'm listing the crash first, but the warning
happened earlier, not sure if it is related.

[36298.986117] BUG: spinlock recursion on CPU#4, perf_fuzzer/3410
[36298.992915]  lock: 0x88011edf7cd0, .magic: dead4ead, .owner: 
perf_fuzzer/3410, .owner_cpu: 4
[36299.002919] CPU: 4 PID: 3410 Comm: perf_fuzzer Tainted: GW   
4.1.0-rc7+ #155
[36299.012152] Hardware name: LENOVO 10AM000AUS/SHARKBAY, BIOS FBKT72AUS 
01/26/2014
[36299.020606]  88011edf7cd0 88011eb059a0 816d7229 
0054
[36299.029199]  8800c2f4ac50 88011eb059c0 810c2895 
88011edf7cd0
[36299.037796]  81a1e481 88011eb059e0 810c2916 
88011edf7cd0
[36299.046338] Call Trace:
[36299.049501][] dump_stack+0x45/0x57
[36299.056284]  [] spin_dump+0x85/0xe0
[36299.062282]  [] spin_bug+0x26/0x30
[36299.068111]  [] do_raw_spin_lock+0x13f/0x180
[36299.074897]  [] _raw_spin_lock+0x39/0x40
[36299.081276]  [] ? free_pcppages_bulk+0x39/0x620
[36299.088340]  [] free_pcppages_bulk+0x39/0x620
[36299.095182]  [] ? free_pages_prepare+0x3a4/0x550
[36299.102291]  [] ? kfree_debugcheck+0x16/0x40
[36299.108987]  [] free_hot_cold_page+0x178/0x1a0
[36299.115850]  [] __free_pages+0x37/0x50
[36299.121991]  [] rb_free_aux+0xba/0xf0
[36299.128034]  [] perf_aux_output_end+0xb7/0xf0
[36299.134793]  [] intel_bts_interrupt+0x8e/0xd0
[36299.141543]  [] intel_pmu_handle_irq+0x4f/0x450
[36299.148482]  [] ? check_chain_key+0x128/0x1e0
[36299.155249]  [] perf_event_nmi_handler+0x2b/0x50
[36299.162273]  [] nmi_handle+0xa0/0x150
[36299.168278]  [] ? nmi_handle+0x5/0x150
[36299.174377]  [] default_do_nmi+0x4a/0x140
[36299.180735]  [] do_nmi+0x98/0xe0
[36299.186219]  [] end_repeat_nmi+0x1e/0x2e
[36299.192501]  [] ? __lock_acquire.isra.31+0x27e/0x1000
[36299.199951]  [] ? __lock_acquire.isra.31+0x27e/0x1000
[36299.207410]  [] ? __lock_acquire.isra.31+0x27e/0x1000
[36299.214898]  <>  [] ? 
__lock_acquire.isra.31+0x3b9/0x1000

and while I was trying to cut and paste that, the locked haswell just took 
down the network switch so I can't get the rest until tomorrow.

The warning was
[27716.785131] WARNING: CPU: 2 PID: 17655 at kernel/events/ring_buffer.c:282 
perf_aux_output_begin+0x1ce/0x1f0()

which corresponds to 
/*
 * Nesting is not supported for AUX area, make sure nested
 * writers are caught early
 */
if (WARN_ON_ONCE(local_xchg(>aux_nest, 1)))
goto err_put;

again just lost access to the machine with the serial console, for the 
full backtrace it will have to wait until I'm not remote.

Vince
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH RFC v4 2/4] crypto: add PKE API

2015-06-11 Thread Herbert Xu
On Thu, Jun 11, 2015 at 12:05:44PM -0700, Tadeusz Struk wrote:
>
> +int crypto_akcipher_setkey(struct crypto_akcipher *tfm,
> +const struct public_key *pkey)
> +{
> + if (tfm->pkey)
> + akcipher_free_key(tfm->pkey);
> +
> + return akcipher_clone_key(tfm, pkey);
> +}

No please do not expose the struct public_key crap to the new
API.  The key should be completely opaque to entities outside
of the algorithm.  So make it raw and read out the MPIs from
it.

The contents of the function must go into the algorithm setkey
function, not the crypto API.  So RSA would read out however
many MPIs it needs and verify it, and so on.

Cheers,
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


next-20150610 - repeated hangs at e1000e_phc_gettime+0x2e/0x60

2015-06-11 Thread Valdis Kletnieks
I'm seeing repeated hard lockups on my Dell Latitude E6530.
Helpful info:

0) next-20150603 works, so the problem landed in linux-next in the last week.

1) All 3 times happened while I was at home, using wireless, so
the interface didn't have link and was ifconfig'ed down.

2) Remarkably similar times for it to blow up:

[14513.365378] Kernel panic - not syncing: Watchdog detected hard LOCKUP on cpu 
1
[14482.271716] Kernel panic - not syncing: Watchdog detected hard LOCKUP on cpu 
3
[14479.906820] Kernel panic - not syncing: Watchdog detected hard LOCKUP on cpu 0

(I suspect the offsets were caused by differences in how long it took me
to correctly enter the cryptLUKS passphrase for my encrypted root filesystem)

Oddly enough, I don't see any patches to the e1000e driver in quite some
time... but that's where it keeps locking up.

This ringing any bells?

All 3 traces look like:

[14479.906908] Call Trace:
[14479.906914][] dump_stack+0x50/0xa8
[14479.906930]  [] panic+0xcd/0x1e4
[14479.906940]  [] ? perf_event_task_disable+0xc0/0xc0
[14479.906952]  [] watchdog_overflow_callback+0x9b/0xa0
[14479.906959]  [] __perf_event_overflow+0xc4/0x1f0
[14479.906968]  [] perf_event_overflow+0x14/0x20
[14479.906976]  [] intel_pmu_handle_irq+0x1e1/0x430
[14479.906990]  [] perf_event_nmi_handler+0x26/0x40
[14479.906999]  [] nmi_handle+0x103/0x340
[14479.907005]  [] ? nmi_handle+0x5/0x340
[14479.907017]  [] default_do_nmi+0xc3/0x120
[14479.907032]  [] do_nmi+0xe8/0x130
[14479.907044]  [] end_repeat_nmi+0x1e/0x2e
[14479.907055]  [] ? e1000e_cyclecounter_read+0x16/0xc0
[14479.907061]  [] ? e1000e_cyclecounter_read+0x16/0xc0
[14479.907069]  [] ? e1000e_cyclecounter_read+0x16/0xc0
[14479.907075]  <>  [] timecounter_read+0x19/0x60
[14479.907088]  [] e1000e_phc_gettime+0x2e/0x60
[14479.907098]  [] e1000e_systim_overflow_work+0x31/0x70
[14479.907105]  [] process_one_work+0x3c9/0x980
[14479.907115]  [] ? process_one_work+0x312/0x980
[14479.907125]  [] ? worker_thread+0x78/0x760
[14479.907134]  [] worker_thread+0x2cc/0x760
[14479.907144]  [] ? process_one_work+0x980/0x980
[14479.907154]  [] kthread+0xfe/0x120
[14479.907163]  [] ? finish_task_switch+0x50/0x1c0
[14479.907173]  [] ? kthread_create_on_node+0x270/0x270
[14479.907179]  [] ret_from_fork+0x3f/0x70
[14479.907188]  [] ? kthread_create_on_node+0x270/0x270
[14479.907243] Kernel Offset: 0x3900 from 0x8100 (relocation 
range:


pgp2oRz3mRGqQ.pgp
Description: PGP signature


[PATCH v2 0/3] IRQ/Gic-V3:Support Mbigen interrupt controller

2015-06-11 Thread Ma Jun
This patch set is applied to supprot the mbigen device.

Mbigen means message based interrupt generator.
It locate in ITS or out side of ITS.

In fact, mbigen is a kind of interrupt controller collects
the irq form non-PCI devices and generate msi interrupt.

Hisilicon designed mbigen to reduce the wired interrupt 
number connected to GIC.

In these patches, the interrupts from non-PCI devices are
named as MBI to distiguish between legacy MSI interrupt from
PCI devices.

As a kind of MSI interrupt controller, the mbigen is used as a child 
domain of ITS domain just like PCI devices.

So,in order to support the mbigen interrupt controller, the 
its-gic-v3-its.c and other related files are changed.

Change in v2
---Compared to v1, mbigen domain is used as a child domain of ITS accroding
   to Marc's advice.So, all changed files related with MSI in v1 are removed.
   Now, only its domain related files are changed to support this new interrupt
   controller.



Ma Jun (3):
  Add mbigen driver to support mbigen interrupt controller
  Change arm-gic-its to support the Mbigen interrupt
  dt-binding:Documents the mbigen bindings

 Documentation/devicetree/bindings/arm/mbigen.txt |   59 +++
 drivers/irqchip/Kconfig  |7 +
 drivers/irqchip/Makefile |1 +
 drivers/irqchip/irq-gic-v3-its.c |   66 +++-
 drivers/irqchip/irq-mbigen.c |  579 ++
 include/linux/irq.h  |5 +
 include/linux/mbi.h  |  114 +
 kernel/irq/chip.c|   40 ++-
 8 files changed, 866 insertions(+), 5 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/arm/mbigen.txt
 create mode 100644 drivers/irqchip/irq-mbigen.c
 create mode 100644 include/linux/mbi.h


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 1/3] IRQ/Gic-V3: Add mbigen driver to support mbigen interrupt controller

2015-06-11 Thread Ma Jun
This patch contains the mbigen device driver.

To support Mbigen device, irq-mbigen.c and mbi.h are added.

As a kind of MSI interrupt controller, the mbigen is used as a child 
domain of ITS domain just like PCI devices does.

Change log:
---irq-mbigen.c: the driver of mbigen device.The mbigen irq domain is created 
here
   as child of ITS domain.


Signed-off-by: Ma Jun 
---
 drivers/irqchip/Kconfig  |7 +
 drivers/irqchip/Makefile |1 +
 drivers/irqchip/irq-mbigen.c |  579 ++
 include/linux/mbi.h  |  114 +
 4 files changed, 701 insertions(+), 0 deletions(-)
 create mode 100644 drivers/irqchip/irq-mbigen.c
 create mode 100644 include/linux/mbi.h

diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
index 6de62a9..f6cc4a7 100644
--- a/drivers/irqchip/Kconfig
+++ b/drivers/irqchip/Kconfig
@@ -27,6 +27,13 @@ config ARM_GIC_V3_ITS
bool
select PCI_MSI_IRQ_DOMAIN
 
+config MBIGEN_IRQ_DOMAIN
+   bool "Support mbigen interrupt controller"
+   default y
+   help
+Enable the mbigen interrupt controller used on 
+Hisillicon platform.
+
 config ARM_NVIC
bool
select IRQ_DOMAIN
diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index dda4927..23571c1 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_ARM_GIC) += irq-gic.o 
irq-gic-common.o
 obj-$(CONFIG_ARM_GIC_V2M)  += irq-gic-v2m.o
 obj-$(CONFIG_ARM_GIC_V3)   += irq-gic-v3.o irq-gic-common.o
 obj-$(CONFIG_ARM_GIC_V3_ITS)   += irq-gic-v3-its.o
+obj-$(CONFIG_MBIGEN_IRQ_DOMAIN)+= irq-mbigen.o
 obj-$(CONFIG_ARM_NVIC) += irq-nvic.o
 obj-$(CONFIG_ARM_VIC)  += irq-vic.o
 obj-$(CONFIG_ATMEL_AIC_IRQ)+= irq-atmel-aic-common.o 
irq-atmel-aic.o
diff --git a/drivers/irqchip/irq-mbigen.c b/drivers/irqchip/irq-mbigen.c
new file mode 100644
index 000..6a0f532
--- /dev/null
+++ b/drivers/irqchip/irq-mbigen.c
@@ -0,0 +1,579 @@
+/*
+ * Copyright (C) 2014 Hisilicon Limited, All Rights Reserved.
+ * Author: Yun Wu 
+ * Author: Jun Ma 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "irqchip.h"
+
+/* Register offsets */
+#define MG_IRQ_TYPE0x0
+#define MG_IRQ_CLEAR   0x100
+#define MG_IRQ_STATUS  0x200
+#define MG_MSG_DATA0x300
+
+/* The gap between normal and extended pin region */
+#define MG_EXT_OFST0x10
+
+/* Max number of interrupts supported */
+#define MG_NR_IRQS 640
+
+/* Number of mbigen node supported in one mbigen chip */
+#define MG_NR  6
+
+/*
+ * refer to the mbigen node in a mbigen chip
+ * usually, a mbigen chip includes 4 mbigen nodes,
+ * but some some mbigen chip include 5 or 6 nodes.
+ * The node number depends on the hardware.
+ */
+struct mbigen_node {
+   raw_spinlock_t  lock;
+   struct list_headentry;
+   struct mbigen_chip  *chip;
+   unsigned intnid;
+   unsigned intirqs_used;
+   struct list_headnodes;
+};
+
+/* refer to the devices connected to mbigen node */
+struct mbigen_device {
+   struct list_headentry;
+   struct mbigen_node  *mgn_node;
+   struct device_node  *source;
+   unsigned intirq;
+   unsigned intnr_irqs;
+   unsigned intoffset;
+};
+
+static LIST_HEAD(mbigen_chip_list);
+static DEFINE_SPINLOCK(mbigen_lock);
+
+int get_mbi_offset(int virq)
+{
+   struct irq_data *data;
+   struct mbigen_device *mgn_dev;
+   int offset = 0;
+
+   data = irq_get_irq_data(virq);
+   mgn_dev = data->chip_data;
+
+   offset = mgn_dev->offset;
+   return offset;
+}
+
+/*
+ * Get the irq number that the mbigen node can supported
+ * nid: the mbigen node id.
+ * nid = 0 ~ 3:64 irq supported
+ * nid = 4:128 irqs supported
+ * nid = 5:256 irqs supported
+*/
+static unsigned int mbigen_get_nr_irqs(unsigned int nid)
+{
+   return 1 << (max_t(unsigned int, nid, 3) + 3);
+}
+
+static unsigned int mbigen_get_nid(unsigned long hwirq)
+{
+   unsigned int nid = min_t(unsigned long, hwirq >> 

[PATCH v2 2/3] IRQ/Gic-V3: Change arm-gic-its to support the Mbigen interrupt

2015-06-11 Thread Ma Jun
This patch is applied to support the mbigen interrupt.

As a kind of MSI interrupt controller, the mbigen is used as a child 
domain of ITS domain just like PCI devices.
So the arm-gic-v3-its and related files are changed.

The chip.c is also changed to check irq_ach before it called.

Change log:
---arm-gic-v3-its.c: [1]Create the mbigen irq domain in its_init;
[2] add the irq_compose_mbigen_msg and irq_write_mbigen_msg 
for mbigen using.[3]add its_mbigen_prepare function.
---irq.h: Add 'irq_compose_mbigen_msg' and 'irq_write_mbigen_msg' in
struct irq_chip for mbigen using.
---chip.c: Before the irq_ack callback, check the irq_ack first(chip.c)


Signed-off-by: Ma Jun 
---
 drivers/irqchip/irq-gic-v3-its.c |   66 +-
 include/linux/irq.h  |5 +++
 kernel/irq/chip.c|   40 --
 3 files changed, 106 insertions(+), 5 deletions(-)

diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index 9687f8a..2651f7c 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -61,6 +62,7 @@ struct its_node {
raw_spinlock_t  lock;
struct list_headentry;
struct msi_controller   msi_chip;
+   struct mbigen_chip  mbi_chip;
struct irq_domain   *domain;
void __iomem*base;
unsigned long   phys_base;
@@ -599,7 +601,21 @@ static void its_irq_compose_msi_msg(struct irq_data *d, 
struct msi_msg *msg)
 
msg->address_lo = addr & ((1UL << 32) - 1);
msg->address_hi = addr >> 32;
-   msg->data   = its_get_event_id(d);
+   msg->data   = its_get_event_id(d);
+}
+
+static void its_irq_compose_mbigen_msg(struct irq_data *d,struct mbigen_msg 
*msg)
+{
+   struct its_device *its_dev = irq_data_get_irq_chip_data(d);
+   struct its_node *its;
+   u64 addr;
+
+   its = its_dev->its;
+   addr = its->phys_base + GITS_TRANSLATER;
+
+   msg->address_lo = addr & ((1UL << 32) - 1);
+   msg->address_hi = addr >> 32;
+   msg->data   = its_get_event_id(d);
 }
 
 static struct irq_chip its_irq_chip = {
@@ -609,6 +625,7 @@ static struct irq_chip its_irq_chip = {
.irq_eoi= its_eoi_irq,
.irq_set_affinity   = its_set_affinity,
.irq_compose_msi_msg= its_irq_compose_msi_msg,
+   .irq_compose_mbigen_msg = its_irq_compose_mbigen_msg,
 };
 
 static void its_mask_msi_irq(struct irq_data *d)
@@ -1245,6 +1262,38 @@ static struct msi_domain_info its_pci_msi_domain_info = {
.chip   = _msi_irq_chip,
 };
 
+static int its_mbigen_prepare(struct irq_domain *domain, struct mbi_desc *desc,
+   int hwirq, 
struct mbi_alloc_info *arg)
+{
+   struct its_node *its = domain->parent->host_data;
+   struct its_device *its_dev;
+   u32 dev_id;
+
+   dev_id = desc->msg_id;
+
+   its_dev = its_find_device(its, dev_id);
+   if (!its_dev) {
+   its_dev = its_create_device(its, dev_id, desc->lines);
+   if (!its_dev)
+   return -ENOMEM;
+   }
+
+   arg->scratchpad[0].ptr = its_dev;
+   arg->scratchpad[1].ptr = NULL;
+
+   arg->desc = desc;
+   arg->hwirq = hwirq;
+   return 0;
+}
+
+static struct mbigen_domain_ops its_mbigen_ops = {
+   .mbigen_prepare = its_mbigen_prepare,
+};
+
+static struct mbigen_domain_info its_mbigen_domain_info = {
+   .ops= _mbigen_ops,
+};
+
 static int its_irq_gic_domain_alloc(struct irq_domain *domain,
unsigned int virq,
irq_hw_number_t hwirq)
@@ -1489,6 +1538,18 @@ static int its_probe(struct device_node *node, struct 
irq_domain *parent)
err = of_pci_msi_chip_add(>msi_chip);
if (err)
goto out_free_domains;
+
+   if (IS_ENABLED(CONFIG_MBIGEN_IRQ_DOMAIN)) {
+   its->mbi_chip.domain = 
its_mbigen_create_irq_domain(node,
+   
_mbigen_domain_info,
+   
its->domain);
+
+   if (!its->mbi_chip.domain) {
+   err = -ENOMEM;
+   pr_warn_once("ITS:no mbigen chip found\n");
+   goto out_free_mbigen;
+   }
+   }
}
 
spin_lock(_lock);
@@ -1497,6 +1558,9 @@ static int its_probe(struct device_node *node, struct 
irq_domain *parent)
 
return 0;
 
+out_free_mbigen:
+   if (its->mbi_chip.domain)

[PATCH v2 3/3] dt-binding:Documents the mbigen bindings

2015-06-11 Thread Ma Jun
Add the mbigen msi interrupt controller bindings document

Signed-off-by: Ma Jun 
---
 Documentation/devicetree/bindings/arm/mbigen.txt |   59 ++
 1 files changed, 59 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/arm/mbigen.txt

diff --git a/Documentation/devicetree/bindings/arm/mbigen.txt 
b/Documentation/devicetree/bindings/arm/mbigen.txt
new file mode 100644
index 000..c7c261b
--- /dev/null
+++ b/Documentation/devicetree/bindings/arm/mbigen.txt
@@ -0,0 +1,59 @@
+Hisilicon mbigen device tree bindings.
+===
+
+Mbigen means: message based interrupt generator.
+
+MBI is kind of msi interrupt only used on Non-PCI devices.
+
+To reduce the wired interrupt number connected to GIC,
+Hisilicon designed mbigen to collect and generate interrupt.
+
+
+Non-pci devices can connect to mbigen and gnerate the inteerrupt
+by wirtting ITS register.
+
+The mbigen and devices connect to mbigen have the following properties:
+
+
+Mbigen required properties:
+---
+-compatible: Should be "hisilicon,mbi-gen"
+-msi-parent: should specified the ITS mbigen connected
+-interrupt controller: Identifies the node as an interrupt controller
+- #interrupt-cells : Specifies the number of cells needed to encode an
+  interrupt source. The value is 2 for now.
+
+  The 1st cell is the interrupt number(Hwirq).This value depends on
+  the Soc design.
+
+  The 2nd cell is the interrupt trigger type, encoded as follows:
+   1 = edge triggered
+   4 = level triggered
+
+- reg: Specifies the base physical address and size of the ITS
+  registers.
+
+Examples:
+
+   mbigen_pa: interrupt-controller@4c03 {
+   compatible = "hisilicon,mbi-gen";
+   msi-parent = <_pa>;
+   interrupt-controller;
+   #interrupt-cells = <2>;
+   reg = <0x4c03 0x1>;
+   };
+
+Device connect to mbigen required properties:
+
+-interrupt-parent: Specifies the mbigen node which device connected.
+-interrupts:specifies the interrupt source.The first cell is hwirq num, the
+  second number is trigger type.
+
+Examples:
+   usb0: ehci@a100 {
+   compatible = "generic-ehci";
+   interrupt-parent = <_pa>;
+   reg = <0xa100 0x1>;
+   interrupts = <20 4>;
+   };
+
-- 
1.7.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH RFC v4 2/4] crypto: add PKE API

2015-06-11 Thread Herbert Xu
On Fri, Jun 12, 2015 at 10:42:46AM +0800, Herbert Xu wrote:
> On Fri, Jun 12, 2015 at 03:00:42AM +0200, Stephan Mueller wrote:
> >
> > The testmgr code can mark an entire cipher implementation as fips_allowed=1 
> > as 
> > already done for RSA. However, unlike with the other ciphers, that flag 
> > must 
> > go in conjunction with the used key sizes.
> > 
> > For FIPS mode, the following restrictions apply:
> > 
> > - RSA: 2048/3072
> > 
> > - DSA: L 2048 / N 224; L 2048 / N 256; L 3072 / N 256
> > 
> > - ECDSA: only the NIST curves
> > 
> > Any other key sizes for the given ciphers is not allowed in FIPS mode.
> > 
> > Should that constraint be considered here?
> 
> Yes.  However it should be placed into a helper that everybody
> can call so that future hardware implementations can also make
> the same checks.

Ugh I didn't notice this was the generic API setkey function.
No it should go into the algorithm-specific setkey function and
then be in the form of a helper so that all implementations of
that algorithm can call it.

Cheers,
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH RFC v4 1/4] MPILIB: add mpi_read_buf(), mpi_copy() and mpi_get_size() helpers

2015-06-11 Thread Herbert Xu
On Thu, Jun 11, 2015 at 12:05:38PM -0700, Tadeusz Struk wrote:
>
> +/**
> + * mpi_get_size() - returns max size required to store the number
> + *
> + * @a:   A multi precision integer for which we want to allocate a bufer
> + *
> + * Return: size required to store the number
> + */
> +unsigned int mpi_get_size(MPI a)
> +{
> + return a->nlimbs * BYTES_PER_MPI_LIMB;
> +}
> +EXPORT_SYMBOL_GPL(mpi_get_size);

Perhaps inline this function?
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH RFC v4 2/4] crypto: add PKE API

2015-06-11 Thread Herbert Xu
On Fri, Jun 12, 2015 at 03:00:42AM +0200, Stephan Mueller wrote:
>
> The testmgr code can mark an entire cipher implementation as fips_allowed=1 
> as 
> already done for RSA. However, unlike with the other ciphers, that flag must 
> go in conjunction with the used key sizes.
> 
> For FIPS mode, the following restrictions apply:
> 
> - RSA: 2048/3072
> 
> - DSA: L 2048 / N 224; L 2048 / N 256; L 3072 / N 256
> 
> - ECDSA: only the NIST curves
> 
> Any other key sizes for the given ciphers is not allowed in FIPS mode.
> 
> Should that constraint be considered here?

Yes.  However it should be placed into a helper that everybody
can call so that future hardware implementations can also make
the same checks.

Cheers,
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[lkp] [rcu] cd73ca21cd2: No primary result change, +47.6% aim7.time.involuntary_context_switches

2015-06-11 Thread Huang Ying
T: 80
testcase: aim7
default-monitors:
  wait: pre-test
  uptime: 
  iostat: 
  vmstat: 
  numa-numastat: 
  numa-vmstat: 
  numa-meminfo: 
  proc-vmstat: 
  proc-stat:
interval: 10
  meminfo: 
  slabinfo: 
  interrupts: 
  lock_stat: 
  latency_stats: 
  softirqs: 
  bdi_dev_mapping: 
  diskstats: 
  nfsstat: 
  cpuidle: 
  cpufreq-stats: 
  turbostat: 
  pmeter: 
  sched_debug:
interval: 60
default-watchdogs:
  watch-oom: 
  watchdog: 
cpufreq_governor: performance
commit: 54896f27dd5c7e83c37c85eb1093f14543af2bfa
model: Atom
memory: 8G
ssd_partitions: 
"/dev/disk/by-id/ata-INTEL_SSDSC2CW240A3_CVCV24050155240CGN-part1"
swap_partitions: 
aim7:
  load: 100
  test: fork_test
testbox: lkp-a03
tbox_group: lkp-a03
kconfig: x86_64-rhel
enqueue_time: 2015-06-10 10:56:36.930460647 +08:00
user: lkp
queue: cyclic
compiler: gcc-4.9
head_commit: 54896f27dd5c7e83c37c85eb1093f14543af2bfa
base_commit: d4a4f75cd8f29cd9464a5a32e9224a91571d6649
branch: next/master
kernel: 
"/pkg/linux/x86_64-rhel/gcc-4.9/54896f27dd5c7e83c37c85eb1093f14543af2bfa/vmlinuz-4.1.0-rc7-next-20150610"
rootfs: debian-x86_64-2015-02-07.cgz
result_root: 
"/result/aim7/performance-100-fork_test/lkp-a03/debian-x86_64-2015-02-07.cgz/x86_64-rhel/gcc-4.9/54896f27dd5c7e83c37c85eb1093f14543af2bfa/0"
job_file: 
"/lkp/scheduled/lkp-a03/cyclic_aim7-performance-100-fork_test-x86_64-rhel-CYCLIC_HEAD-54896f27dd5c7e83c37c85eb1093f14543af2bfa-0-20150610-8556-14ms8jq.yaml"
dequeue_time: 2015-06-11 06:19:56.066407390 +08:00
nr_cpu: "$(nproc)"
max_uptime: 1495.8
initrd: "/osimage/debian/debian-x86_64-2015-02-07.cgz"
bootloader_append:
- root=/dev/ram0
- user=lkp
- 
job=/lkp/scheduled/lkp-a03/cyclic_aim7-performance-100-fork_test-x86_64-rhel-CYCLIC_HEAD-54896f27dd5c7e83c37c85eb1093f14543af2bfa-0-20150610-8556-14ms8jq.yaml
- ARCH=x86_64
- kconfig=x86_64-rhel
- branch=next/master
- commit=54896f27dd5c7e83c37c85eb1093f14543af2bfa
- 
BOOT_IMAGE=/pkg/linux/x86_64-rhel/gcc-4.9/54896f27dd5c7e83c37c85eb1093f14543af2bfa/vmlinuz-4.1.0-rc7-next-20150610
- max_uptime=1495
- 
RESULT_ROOT=/result/aim7/performance-100-fork_test/lkp-a03/debian-x86_64-2015-02-07.cgz/x86_64-rhel/gcc-4.9/54896f27dd5c7e83c37c85eb1093f14543af2bfa/0
- LKP_SERVER=inn
- |2-


  earlyprintk=ttyS0,115200 systemd.log_level=err
  debug apic=debug sysrq_always_enabled rcupdate.rcu_cpu_stall_timeout=100
  panic=-1 softlockup_panic=1 nmi_watchdog=panic oops=panic load_ramdisk=2 
prompt_ramdisk=0
  console=ttyS0,115200 console=tty0 vga=normal

  rw
lkp_initrd: "/lkp/lkp/lkp-x86_64.cgz"
modules_initrd: 
"/pkg/linux/x86_64-rhel/gcc-4.9/54896f27dd5c7e83c37c85eb1093f14543af2bfa/modules.cgz"
bm_initrd: 
"/osimage/deps/debian-x86_64-2015-02-07.cgz/lkp.cgz,/osimage/deps/debian-x86_64-2015-02-07.cgz/run-ipconfig.cgz,/osimage/deps/debian-x86_64-2015-02-07.cgz/turbostat.cgz,/lkp/benchmarks/turbostat.cgz,/lkp/benchmarks/aim7-x86_64.cgz"
job_state: finished
loadavg: 76.17 66.16 31.35 1/109 3251
start_time: '1433974860'
end_time: '1433975225'
version: "/lkp/lkp/.src-20150611-021242"
echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo performance > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
echo performance > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor
echo performance > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor


[PATCH 7/7] perf tools: Update MANIFEST per files removed from kernel

2015-06-11 Thread Arnaldo Carvalho de Melo
From: David Ahern 

Building perf out of kernel tree is currently broken because the
MANIFEST file refers to kernel files that have been removed. With this
patch make perf-targz-src-pkg succeeds as does building perf using the
generated tarfile.

Signed-off-by: David Ahern 
Link: 
http://lkml.kernel.org/r/1433526173-172332-1-git-send-email-david.ah...@oracle.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/MANIFEST | 4 
 1 file changed, 4 deletions(-)

diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST
index a0bdd6124583..fe50a1b34aa0 100644
--- a/tools/perf/MANIFEST
+++ b/tools/perf/MANIFEST
@@ -50,24 +50,20 @@ include/asm-generic/bitops/const_hweight.h
 include/asm-generic/bitops/fls64.h
 include/asm-generic/bitops/__fls.h
 include/asm-generic/bitops/fls.h
-include/linux/const.h
 include/linux/perf_event.h
 include/linux/rbtree.h
 include/linux/list.h
 include/linux/hash.h
 include/linux/stringify.h
-lib/find_next_bit.c
 lib/hweight.c
 lib/rbtree.c
 include/linux/swab.h
 arch/*/include/asm/unistd*.h
-arch/*/include/asm/perf_regs.h
 arch/*/include/uapi/asm/unistd*.h
 arch/*/include/uapi/asm/perf_regs.h
 arch/*/lib/memcpy*.S
 arch/*/lib/memset*.S
 include/linux/poison.h
-include/linux/magic.h
 include/linux/hw_breakpoint.h
 include/linux/rbtree_augmented.h
 include/uapi/linux/perf_event.h
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/7] perf record: Amend option summaries

2015-06-11 Thread Arnaldo Carvalho de Melo
From: Peter Zijlstra 

Because there's too many options and I cannot read, I frequently get
confused between -c and -P, and try to do things like:

  perf record -P 5 -- foo

Which does not work; try and make the option description slightly longer
and hopefully less confusing.

Signed-off-by: Peter Zijlstra (Intel) 
Link: 
http://lkml.kernel.org/r/20150610144850.gp19...@twins.programming.kicks-ass.net
[ Do those changes on the man page as well ]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-record.txt | 10 +++---
 tools/perf/builtin-record.c  |  7 +++
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/tools/perf/Documentation/perf-record.txt 
b/tools/perf/Documentation/perf-record.txt
index 280533ebf9df..6fdf78625c51 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -152,12 +152,16 @@ OPTIONS
 
 -d::
 --data::
-   Sample addresses.
+   Record the sample addresses.
 
 -T::
 --timestamp::
-   Sample timestamps. Use it with 'perf report -D' to see the timestamps,
-   for instance.
+   Record the sample timestamps. Use it with 'perf report -D' to see the
+   timestamps, for instance.
+
+-P::
+--period::
+   Record the sample period.
 
 -n::
 --no-samples::
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index d3731cce7c1c..4d6cdeb94fe1 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1027,10 +1027,9 @@ struct option __record_options[] = {
OPT_BOOLEAN('q', "quiet", , "don't print any message"),
OPT_BOOLEAN('s', "stat", _stat,
"per thread counts"),
-   OPT_BOOLEAN('d', "data", _address,
-   "Sample addresses"),
-   OPT_BOOLEAN('T', "timestamp", _time, "Sample 
timestamps"),
-   OPT_BOOLEAN('P', "period", , "Sample period"),
+   OPT_BOOLEAN('d', "data", _address, "Record the 
sample addresses"),
+   OPT_BOOLEAN('T', "timestamp", _time, "Record the 
sample timestamps"),
+   OPT_BOOLEAN('P', "period", , "Record the sample 
period"),
OPT_BOOLEAN('n', "no-samples", _samples,
"don't sample"),
OPT_BOOLEAN('N', "no-buildid-cache", _buildid_cache,
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 4/7] perf stat: Error out unsupported group leader immediately

2015-06-11 Thread Arnaldo Carvalho de Melo
From: Kan Liang 

perf stat ignores the unsupported event and continue to count supported
event. But if the unsupported event is group leader, perf tool will
crash. After applying this patch, the unsupported group leader will
error out immediately.

Without this patch:

  $ perf stat -x, -e '{node-prefetch-refs,cycles}' --  sleep 1
  perf: util/evsel.c:1009: get_group_fd: Assertion `!(fd == -1)' failed.
  Aborted (core dumped)

With this patch:

  $ perf stat -x, -e '{node-prefetch-refs,cycles}' --  sleep 1
  Error:
  The node-prefetch-refs event is not supported.

Commiter note: Here I got a different output, but no core dump:

  [acme@zoo linux]$ perf stat -x, -e '{node-prefetch-refs,cycles}' -- sleep 1
  Error:
  The sys_perf_event_open() syscall returned with 22 (Invalid argument)
  for event (node-prefetch-refs).
  /bin/dmesg may provide additional information.
  No CONFIG_PERF_EVENTS=y kernel support configured?

Signed-off-by: Kan Liang 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Andi Kleen 
Link: 
http://lkml.kernel.org/r/1434004360-8570-1-git-send-email-kan.li...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-stat.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index ff3d25803400..b24ecee95fec 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -549,7 +549,10 @@ static int __run_perf_stat(int argc, const char **argv)
ui__warning("%s event is not supported 
by the kernel.\n",
perf_evsel__name(counter));
counter->supported = false;
-   continue;
+
+   if ((counter->leader != counter) ||
+   !(counter->leader->nr_members > 1))
+   continue;
}
 
perf_evsel__open_strerror(counter, ,
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/7] perf tools: Avoid possible race condition in copyfile()

2015-06-11 Thread Arnaldo Carvalho de Melo
From: Milos Vyletel 

Use unique temporary files when copying to buildid dir to prevent races
in case multiple instances are trying to copy same file. This is done by

- creating template in form /..XX where the suffix is
  used by mkstemp() to create unique file
- change file mode
- copy content
- if successful link temp file to target file
- unlink temp file

At this point the only file left at target path should be the desired
one either created by us or other instance if we raced. This should also
prevent not yet fully copied files to be visible to to other perf
instances that could try to parse them.

On top of that slow_copyfile no longer needs to deal with file mode when
creating file since temporary file is already created and mode is set.

Succesfully tested by myself by running perf record, archive and reading
the data on other system and by running perf buildid-cache on perf
binary itself. I also did revert fix from 0635b0f that to exposes
previously fixed race with EEXIST and recreator test passed sucessfully.

Signed-off-by: Milos Vyletel 
Acked-by: Ingo Molnar 
Cc: Andy Shevchenko 
Cc: Don Zickus 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Link: 
http://lkml.kernel.org/r/1433775018-19868-1-git-send-email-mi...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/util.c | 46 +++---
 1 file changed, 31 insertions(+), 15 deletions(-)

diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 0c264bc685ac..edc2d633b332 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -115,20 +115,17 @@ int rm_rf(char *path)
return rmdir(path);
 }
 
-static int slow_copyfile(const char *from, const char *to, mode_t mode)
+static int slow_copyfile(const char *from, const char *to)
 {
int err = -1;
char *line = NULL;
size_t n;
FILE *from_fp = fopen(from, "r"), *to_fp;
-   mode_t old_umask;
 
if (from_fp == NULL)
goto out;
 
-   old_umask = umask(mode ^ 0777);
to_fp = fopen(to, "w");
-   umask(old_umask);
if (to_fp == NULL)
goto out_fclose_from;
 
@@ -178,29 +175,48 @@ int copyfile_mode(const char *from, const char *to, 
mode_t mode)
int fromfd, tofd;
struct stat st;
int err = -1;
+   char *tmp = NULL, *ptr = NULL;
 
if (stat(from, ))
goto out;
 
-   if (st.st_size == 0) /* /proc? do it slowly... */
-   return slow_copyfile(from, to, mode);
-
-   fromfd = open(from, O_RDONLY);
-   if (fromfd < 0)
+   /* extra 'x' at the end is to reserve space for '.' */
+   if (asprintf(, "%s.XXx", to) < 0) {
+   tmp = NULL;
goto out;
+   }
+   ptr = strrchr(tmp, '/');
+   if (!ptr)
+   goto out;
+   ptr = memmove(ptr + 1, ptr, strlen(ptr) - 1);
+   *ptr = '.';
 
-   tofd = creat(to, mode);
+   tofd = mkstemp(tmp);
if (tofd < 0)
-   goto out_close_from;
+   goto out;
+
+   if (fchmod(tofd, mode))
+   goto out_close_to;
+
+   if (st.st_size == 0) { /* /proc? do it slowly... */
+   err = slow_copyfile(from, tmp);
+   goto out_close_to;
+   }
+
+   fromfd = open(from, O_RDONLY);
+   if (fromfd < 0)
+   goto out_close_to;
 
err = copyfile_offset(fromfd, 0, tofd, 0, st.st_size);
 
-   close(tofd);
-   if (err)
-   unlink(to);
-out_close_from:
close(fromfd);
+out_close_to:
+   close(tofd);
+   if (!err)
+   err = link(tmp, to);
+   unlink(tmp);
 out:
+   free(tmp);
return err;
 }
 
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[GIT PULL 0/7] perf/core improvements and fixes

2015-06-11 Thread Arnaldo Carvalho de Melo
Hi Ingo,

Please consider pulling,

- Arnaldo

The following changes since commit 028c63b56795206464263fa3bc47094704c2a840:

  Merge tag 'perf-core-for-mingo' of 
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core 
(2015-06-09 11:46:04 +0200)

are available in the git repository at:

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

for you to fetch changes up to c8ad7063626406181a7ebab10cb31b4f741b13d4:

  perf tools: Update MANIFEST per files removed from kernel (2015-06-11 
22:54:23 -0300)


perf/core improvements and fixes:

User visible:

- Beautify perf_event_open syscall in 'perf trace'. (Arnaldo Carvalho de Melo)

- Error out unsupported group leader immediately in 'perf stat'. (Kan Liang)

- Amend some 'perf record' option summaries (period, etc) (Peter Zijlstra)

- Avoid possible race condition in copyfile() in 'perf buildid-cache'. (Milos 
Vyletel)

Infrastructure:

- Display 0x for hex values when printing the attribute. (Adrian Hunter)

- Update MANIFEST per files removed from kernel. (David Ahern)

Build fixes:

- Fix PRIu64 printf related failure on 32-bit arch. (He Kuang)

Signed-off-by: Arnaldo Carvalho de Melo 


Adrian Hunter (1):
  perf evsel: Display 0x for hex values when printing the attribute

Arnaldo Carvalho de Melo (1):
  trace: Beautify perf_event_open syscall

David Ahern (1):
  perf tools: Update MANIFEST per files removed from kernel

He Kuang (1):
  perf tools: Fix build failure on 32-bit arch

Kan Liang (1):
  perf stat: Error out unsupported group leader immediately

Milos Vyletel (1):
  perf tools: Avoid possible race condition in copyfile()

Peter Zijlstra (1):
  perf record: Amend option summaries

 tools/perf/Documentation/perf-record.txt | 10 --
 tools/perf/MANIFEST  |  4 ---
 tools/perf/builtin-record.c  |  7 ++--
 tools/perf/builtin-report.c  |  2 +-
 tools/perf/builtin-stat.c|  5 ++-
 tools/perf/builtin-trace.c   | 58 
 tools/perf/util/evsel.c  |  2 +-
 tools/perf/util/session.c|  2 +-
 tools/perf/util/util.c   | 46 -
 9 files changed, 106 insertions(+), 30 deletions(-)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 6/7] trace: Beautify perf_event_open syscall

2015-06-11 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

Syswide tracing and then running 'stat' and 'trace':

 $ perf trace -e perf_event_open
 1034.649 (0.019 ms): perf/6133 perf_event_open(attr_uptr: 0x36f0360, pid: 
16134, cpu: -1, group_fd: -1, flags: FD_CLOEXEC) = -1 EINVAL Invalid argument
 1034.670 (0.008 ms): perf/6133 perf_event_open(attr_uptr: 0x36f0360, pid: 
16134, cpu: -1, group_fd: -1) = -1 EINVAL Invalid argument
 1034.681 (0.007 ms): perf/6133 perf_event_open(attr_uptr: 0x36f0360, pid: 
16134, cpu: -1, group_fd: -1) = -1 EINVAL Invalid argument
 1034.692 (0.007 ms): perf/6133 perf_event_open(attr_uptr: 0x36f0360, pid: 
16134, cpu: -1, group_fd: -1) = -1 EINVAL Invalid argument
 9986.983 (0.014 ms): trace/6139 perf_event_open(attr_uptr: 0x7ffd9c629320, 
pid: -1, group_fd: -1, flags: FD_CLOEXEC) = 3
 9987.026 (0.016 ms): trace/6139 perf_event_open(attr_uptr: 0x37c7e70, pid: -1, 
group_fd: -1, flags: FD_CLOEXEC) = 3
 9987.041 (0.008 ms): trace/6139 perf_event_open(attr_uptr: 0x37c7e70, pid: -1, 
group_fd: -1, flags: FD_CLOEXEC) = 3
 9987.489 (0.092 ms): trace/6139 perf_event_open(attr_uptr: 0x3795ee0, pid: 
16140, group_fd: -1, flags: FD_CLOEXEC) = 3
 9987.536 (0.044 ms): trace/6139 perf_event_open(attr_uptr: 0x3795ee0, pid: 
16140, cpu: 1, group_fd: -1, flags: FD_CLOEXEC) = 4
 9987.580 (0.041 ms): trace/6139 perf_event_open(attr_uptr: 0x3795ee0, pid: 
16140, cpu: 2, group_fd: -1, flags: FD_CLOEXEC) = 5
 9987.620 (0.037 ms): trace/6139 perf_event_open(attr_uptr: 0x3795ee0, pid: 
16140, cpu: 3, group_fd: -1, flags: FD_CLOEXEC) = 7
 9987.659 (0.035 ms): trace/6139 perf_event_open(attr_uptr: 0x37975d0, pid: 
16140, group_fd: -1, flags: FD_CLOEXEC) = 8
 9987.692 (0.031 ms): trace/6139 perf_event_open(attr_uptr: 0x37975d0, pid: 
16140, cpu: 1, group_fd: -1, flags: FD_CLOEXEC) = 9
 9987.727 (0.032 ms): trace/6139 perf_event_open(attr_uptr: 0x37975d0, pid: 
16140, cpu: 2, group_fd: -1, flags: FD_CLOEXEC) = 10
 9987.761 (0.031 ms): trace/6139 perf_event_open(attr_uptr: 0x37975d0, pid: 
16140, cpu: 3, group_fd: -1, flags: FD_CLOEXEC) = 11

Need to intercept perf_copy_attr() with a kprobe or with eBPF...

Cc: Adrian Hunter 
Cc: Borislav Petkov 
Cc: David Ahern 
Cc: Frederic Weisbecker 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: http://lkml.kernel.org/n/tip-njb105hab2i3t5dexym9l...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-trace.c | 58 ++
 1 file changed, 58 insertions(+)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index a05490d06374..4bf805b2fbf6 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -68,6 +68,23 @@
 # define MSG_CMSG_CLOEXEC  0x4000
 #endif
 
+#ifndef PERF_FLAG_FD_NO_GROUP
+# define PERF_FLAG_FD_NO_GROUP (1UL << 0)
+#endif
+
+#ifndef PERF_FLAG_FD_OUTPUT
+# define PERF_FLAG_FD_OUTPUT   (1UL << 1)
+#endif
+
+#ifndef PERF_FLAG_PID_CGROUP
+# define PERF_FLAG_PID_CGROUP  (1UL << 2) /* pid=cgroup id, per-cpu 
mode only */
+#endif
+
+#ifndef PERF_FLAG_FD_CLOEXEC
+# define PERF_FLAG_FD_CLOEXEC  (1UL << 3) /* O_CLOEXEC */
+#endif
+
+
 struct tp_field {
int offset;
union {
@@ -358,6 +375,14 @@ static size_t syscall_arg__scnprintf_hex(char *bf, size_t 
size,
 
 #define SCA_HEX syscall_arg__scnprintf_hex
 
+static size_t syscall_arg__scnprintf_int(char *bf, size_t size,
+struct syscall_arg *arg)
+{
+   return scnprintf(bf, size, "%d", arg->val);
+}
+
+#define SCA_INT syscall_arg__scnprintf_int
+
 static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size,
   struct syscall_arg *arg)
 {
@@ -810,6 +835,34 @@ static size_t syscall_arg__scnprintf_open_flags(char *bf, 
size_t size,
 
 #define SCA_OPEN_FLAGS syscall_arg__scnprintf_open_flags
 
+static size_t syscall_arg__scnprintf_perf_flags(char *bf, size_t size,
+   struct syscall_arg *arg)
+{
+   int printed = 0, flags = arg->val;
+
+   if (flags == 0)
+   return 0;
+
+#defineP_FLAG(n) \
+   if (flags & PERF_FLAG_##n) { \
+   printed += scnprintf(bf + printed, size - printed, "%s%s", 
printed ? "|" : "", #n); \
+   flags &= ~PERF_FLAG_##n; \
+   }
+
+   P_FLAG(FD_NO_GROUP);
+   P_FLAG(FD_OUTPUT);
+   P_FLAG(PID_CGROUP);
+   P_FLAG(FD_CLOEXEC);
+#undef P_FLAG
+
+   if (flags)
+   printed += scnprintf(bf + printed, size - printed, "%s%#x", 
printed ? "|" : "", flags);
+
+   return printed;
+}
+
+#define SCA_PERF_FLAGS syscall_arg__scnprintf_perf_flags
+
 static size_t syscall_arg__scnprintf_eventfd_flags(char *bf, size_t size,
   struct syscall_arg *arg)
 {
@@ -1077,6 +1130,11 @@ static struct syscall_fmt {
{ .name = "openat", .errmsg = true,
  .arg_scnprintf = { [0] = SCA_FDAT, /* dfd */

[PATCH 3/7] perf evsel: Display 0x for hex values when printing the attribute

2015-06-11 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

Need to display '0x' prefix for hex values otherwise it is not obvious
they are hex.

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

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index a3e36fc634dc..d4f9994ae47f 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1058,7 +1058,7 @@ static void __p_read_format(char *buf, size_t size, u64 
value)
 
 #define BUF_SIZE   1024
 
-#define p_hex(val) snprintf(buf, BUF_SIZE, "%"PRIx64, 
(uint64_t)(val))
+#define p_hex(val) snprintf(buf, BUF_SIZE, "%#"PRIx64, 
(uint64_t)(val))
 #define p_unsigned(val)snprintf(buf, BUF_SIZE, "%"PRIu64, 
(uint64_t)(val))
 #define p_signed(val)  snprintf(buf, BUF_SIZE, "%"PRId64, 
(int64_t)(val))
 #define p_sample_type(val) __p_sample_type(buf, BUF_SIZE, val)
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 5/7] perf tools: Fix build failure on 32-bit arch

2015-06-11 Thread Arnaldo Carvalho de Melo
From: He Kuang 

Failed in 32bit arch build like this:

CC   /opt/h00206996/output/perf/arm32/builtin-record.o
  util/session.c: In function ‘perf_session__warn_about_errors’:
  util/session.c:1304:9: error: format ‘%lu’ expects argument of type ‘long 
unsigned int’,
 but argument 2 has type ‘long long unsigned int’ 
[-Werror=format=]

  builtin-report.c: In function ‘perf_evlist__tty_browse_hists’:
  builtin-report.c:323:2: error: format ‘%lu’ expects argument of type ‘long 
unsigned int’,
  but argument 3 has type ‘u64’ [-Werror=format=]

Replace %lu format strings in warning message with PRIu64 for u64
'total_lost_samples' to fix this problem.

Signed-off-by: He Kuang 
Cc: Jiri Olsa 
Cc: Kan Liang 
Cc: Peter Zijlstra 
Cc: Wang Nan 
Link: 
http://lkml.kernel.org/r/1434026664-71642-1-git-send-email-heku...@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-report.c | 2 +-
 tools/perf/util/session.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 628090b478ab..32626ea3e227 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -320,7 +320,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist 
*evlist,
 {
struct perf_evsel *pos;
 
-   fprintf(stdout, "#\n# Total Lost Samples: %lu\n#\n", 
evlist->stats.total_lost_samples);
+   fprintf(stdout, "#\n# Total Lost Samples: %" PRIu64 "\n#\n", 
evlist->stats.total_lost_samples);
evlist__for_each(evlist, pos) {
struct hists *hists = evsel__hists(pos);
const char *evname = perf_evsel__name(pos);
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 88d87bf3049f..f31e024ddf7d 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1299,7 +1299,7 @@ static void perf_session__warn_about_errors(const struct 
perf_session *session)
drop_rate = (double)stats->total_lost_samples /
(double) (stats->nr_events[PERF_RECORD_SAMPLE] + 
stats->total_lost_samples);
if (drop_rate > 0.05) {
-   ui__warning("Processed %lu samples and lost %3.2f%% 
samples!\n\n",
+   ui__warning("Processed %" PRIu64 " samples and lost 
%3.2f%% samples!\n\n",
stats->nr_events[PERF_RECORD_SAMPLE] + 
stats->total_lost_samples,
drop_rate * 100.0);
}
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 2/4] rtc/lib: Introduce rtc_tm_sub() helper function

2015-06-11 Thread Xunlei Pang
From: Xunlei Pang 

There're many sites need comparing the two rtc_time variants for many
rtc drivers, especially in the instances of rtc_class_ops::set_alarm().

So add this common helper function to make things easy.

Suggested-by: Arnd Bergmann 
Signed-off-by: Xunlei Pang 
---
v2->v3:
Respin rtc_tm_subtract() to rtc_tm_sub() using "static inline".

 include/linux/rtc.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index 8dcf682..f46f765 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -24,6 +24,14 @@ extern void rtc_time64_to_tm(time64_t time, struct rtc_time 
*tm);
 ktime_t rtc_tm_to_ktime(struct rtc_time tm);
 struct rtc_time rtc_ktime_to_tm(ktime_t kt);
 
+/*
+ * rtc_tm_sub - Return the difference in seconds.
+ */
+static inline time64_t rtc_tm_sub(struct rtc_time *lhs, struct rtc_time *rhs)
+{
+   return rtc_tm_to_time64(lhs) - rtc_tm_to_time64(rhs);
+}
+
 /**
  * Deprecated. Use rtc_time64_to_tm().
  */
-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] extcon: Redefine the unique id of supported external connectors without 'enum extcon' type

2015-06-11 Thread Chanwoo Choi
This patch just redefine the unique id of supported external connectors without
'enum extcon' type. Because unique id would be used on devictree file(*.dts) to
indicate the specific external connectors like key number of input framework.
So, I have the plan to move this definitions to following header file which
includes the unique id of supported external connectors.
- include/dt-bindings/extcon/extcon.h

Fixes: 2a9de9c0f08d ("extcon: Use the unique id for external connector instead 
of string")
Signed-off-by: Chanwoo Choi 
---
Dear Greg,

I sent pull-request[1] of extcon for 4.2. This patch[2] in the pull-request[2]
includes the one issue about 'enum extcon'. The 'enum extcon' type is ambiguous
and not clear. So, if you possible, I hope you to pick this patch on char-misc
git repository.

[1] http://www.spinics.net/lists/kernel/msg2005098.html
- [GIT PULL] extcon next for 4.2
[2] commit-id: 2a9de9c0f08d61fbe3764a21d22d0b72df97d6ae
- extcon: Use the unique id for external connector instead of string

 drivers/extcon/extcon-adc-jack.c |  2 +-
 drivers/extcon/extcon-arizona.c  |  4 +-
 drivers/extcon/extcon-axp288.c   |  4 +-
 drivers/extcon/extcon-max14577.c |  2 +-
 drivers/extcon/extcon-max77693.c |  4 +-
 drivers/extcon/extcon-max77843.c |  2 +-
 drivers/extcon/extcon-max8997.c  |  2 +-
 drivers/extcon/extcon-palmas.c   |  2 +-
 drivers/extcon/extcon-rt8973a.c  |  4 +-
 drivers/extcon/extcon-sm5502.c   |  4 +-
 drivers/extcon/extcon-usb-gpio.c |  2 +-
 drivers/extcon/extcon.c  | 24 +--
 drivers/usb/phy/phy-tahvo.c  |  2 +-
 include/linux/extcon.h   | 90 +++-
 14 files changed, 71 insertions(+), 77 deletions(-)

diff --git a/drivers/extcon/extcon-adc-jack.c b/drivers/extcon/extcon-adc-jack.c
index 5bf08ec1cacf..7fc0ae1912f8 100644
--- a/drivers/extcon/extcon-adc-jack.c
+++ b/drivers/extcon/extcon-adc-jack.c
@@ -40,7 +40,7 @@
 struct adc_jack_data {
struct extcon_dev *edev;
 
-   const char **cable_names;
+   const unsigned int **cable_names;
struct adc_jack_cond *adc_conditions;
int num_conditions;
 
diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c
index 9262b45a4484..ad87f263056f 100644
--- a/drivers/extcon/extcon-arizona.c
+++ b/drivers/extcon/extcon-arizona.c
@@ -118,7 +118,7 @@ static const int arizona_micd_levels[] = {
1257,
 };
 
-static const enum extcon arizona_cable[] = {
+static const unsigned int arizona_cable[] = {
EXTCON_MECHANICAL,
EXTCON_MICROPHONE,
EXTCON_HEADPHONE,
@@ -552,7 +552,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
struct arizona_extcon_info *info = data;
struct arizona *arizona = info->arizona;
int id_gpio = arizona->pdata.hpdet_id_gpio;
-   enum extcon report = EXTCON_HEADPHONE;
+   unsigned int report = EXTCON_HEADPHONE;
int ret, reading;
bool mic = false;
 
diff --git a/drivers/extcon/extcon-axp288.c b/drivers/extcon/extcon-axp288.c
index 3605aa96c25a..ea962bc547b8 100644
--- a/drivers/extcon/extcon-axp288.c
+++ b/drivers/extcon/extcon-axp288.c
@@ -101,7 +101,7 @@ enum axp288_extcon_irq {
EXTCON_IRQ_END,
 };
 
-static const enum extcon axp288_extcon_cables[] = {
+static const unsigned int axp288_extcon_cables[] = {
EXTCON_SLOW_CHARGER,
EXTCON_CHARGE_DOWNSTREAM,
EXTCON_FAST_CHARGER,
@@ -157,7 +157,7 @@ static void axp288_extcon_log_rsi(struct axp288_extcon_info 
*info)
 static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
 {
static bool notify_otg, notify_charger;
-   static enum extcon cable;
+   static unsigned int cable;
int ret, stat, cfg, pwr_stat;
u8 chrg_type;
bool vbus_attach = false;
diff --git a/drivers/extcon/extcon-max14577.c b/drivers/extcon/extcon-max14577.c
index e7c3edb5bd4b..df0659d98e5a 100644
--- a/drivers/extcon/extcon-max14577.c
+++ b/drivers/extcon/extcon-max14577.c
@@ -148,7 +148,7 @@ enum max14577_muic_acc_type {
MAX14577_MUIC_ADC_OPEN,
 };
 
-static const enum extcon max14577_extcon_cable[] = {
+static const unsigned int max14577_extcon_cable[] = {
EXTCON_USB,
EXTCON_TA,
EXTCON_FAST_CHARGER,
diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c
index 20e796e10e57..f4f3b3d53928 100644
--- a/drivers/extcon/extcon-max77693.c
+++ b/drivers/extcon/extcon-max77693.c
@@ -200,7 +200,7 @@ enum max77693_muic_acc_type {
 /*
  * MAX77693 MUIC device support below list of accessories(external connector)
  */
-static const enum extcon max77693_extcon_cable[] = {
+static const unsigned int max77693_extcon_cable[] = {
EXTCON_USB,
EXTCON_USB_HOST,
EXTCON_TA,
@@ -457,7 +457,7 @@ static int max77693_muic_dock_handler(struct 
max77693_muic_info *info,
int ret = 0;
int vbvolt;
bool cable_attached;
-   enum extcon dock_id;
+   unsigned int dock_id;
 

[PATCH v3 3/4] drivers/rtc/isl1208: Replace deprecated rtc_tm_to_time()

2015-06-11 Thread Xunlei Pang
From: Xunlei Pang 

isl1208_i2c_set_alarm() uses deprecated rtc_tm_to_time(),
which will overflow in year 2106 on 32-bit machines.

This patch solves this by:
 - Replacing rtc_tm_to_time() with rtc_tm_sub()

Cc: Herbert Valerio Riedel 
Signed-off-by: Xunlei Pang 
---
v2->v3:
Rename rtc_tm_subtract() to rtc_tm_sub().

 drivers/rtc/rtc-isl1208.c | 9 +
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/drivers/rtc/rtc-isl1208.c b/drivers/rtc/rtc-isl1208.c
index c3c549d..aa3b8f1 100644
--- a/drivers/rtc/rtc-isl1208.c
+++ b/drivers/rtc/rtc-isl1208.c
@@ -370,22 +370,15 @@ isl1208_i2c_set_alarm(struct i2c_client *client, struct 
rtc_wkalrm *alarm)
struct rtc_time *alarm_tm = >time;
u8 regs[ISL1208_ALARM_SECTION_LEN] = { 0, };
const int offs = ISL1208_REG_SCA;
-   unsigned long rtc_secs, alarm_secs;
struct rtc_time rtc_tm;
int err, enable;
 
err = isl1208_i2c_read_time(client, _tm);
if (err)
return err;
-   err = rtc_tm_to_time(_tm, _secs);
-   if (err)
-   return err;
-   err = rtc_tm_to_time(alarm_tm, _secs);
-   if (err)
-   return err;
 
/* If the alarm time is before the current time disable the alarm */
-   if (!alarm->enabled || alarm_secs <= rtc_secs)
+   if (!alarm->enabled || rtc_tm_sub(alarm_tm, _tm) <= 0)
enable = 0x00;
else
enable = 0x80;
-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


  1   2   3   4   5   6   7   8   9   10   >