Re: [PATCH 0/3] More code cleanups

2017-11-05 Thread Greg Kroah-Hartman
On Mon, Nov 06, 2017 at 09:41:09AM +0200, Gilad Ben-Yossef wrote:
> On Mon, Nov 6, 2017 at 9:38 AM, Greg Kroah-Hartman
>  wrote:
> > On Mon, Nov 06, 2017 at 06:55:49AM +, Gilad Ben-Yossef wrote:
> >> Additional code readability and simplification patches.
> >> These goes on top the previous patch set sent to the list.
> >
> > Please label your 0/X patches the same way your patches are, with the
> > prefix of the subsystem, otherwise they get dropped from my searches of
> > my inbox at times.
> >
> > For this one, it would be:
> > [PATCH 0/3] staging: ccree: More code cleanups.
> >
> > thanks,
> 
> Oopss.., sorry.
> 
> Writing that subject line is almost the only thing not automated in
> my patch set sending process so of course I mangled it ...
> 
> Do you want to me to resend this patch series?

No, I'll handle it, thanks.

greg k-h


Re: [RFT][PATCH v2 1/2] PM / domains: Rework governor code to be more consistent

2017-11-05 Thread Ramesh Thomas
On 2017-11-04 at 12:24:15 +0100, Rafael J. Wysocki wrote:
> On Sat, Nov 4, 2017 at 3:34 AM, Ramesh Thomas  wrote:
> > On 2017-11-03 at 12:47:20 +0100, Rafael J. Wysocki wrote:
> >> From: Rafael J. Wysocki 
> >>
> >> The genpd governor currently uses negative PM QoS values to indicate
> >> the "no suspend" condition and 0 as "no restriction", but it doesn't
> >> use them consistently.  Moreover, it tries to refresh QoS values for
> >> already suspended devices in a quite questionable way.
> >>
> >> For the above reasons, rework it to be a bit more consistent.
> >>
> >> First off, note that dev_pm_qos_read_value() in
> >> dev_update_qos_constraint() and __default_power_down_ok() is
> >> evaluated for devices in suspend.  Moreover, that only happens if the
> >> effective_constraint_ns value for them is negative (meaning "no
> >> suspend").  It is not evaluated in any other cases, so effectively
> >> the QoS values are only updated for devices in suspend that should
> >> not have been suspended in the first place.  In all of the other
> >> cases, the QoS values taken into account are the effective ones from
> >> the time before the device has been suspended, so generally devices
> >> need to be resumed and suspended again for new QoS values to take
> >> effect anyway.  Thus evaluating dev_update_qos_constraint() in
> >> those two places doesn't make sense at all, so drop it.
> >>
> >> Second, initialize effective_constraint_ns to 0 ("no constraint")
> >> rather than to (-1) ("no suspend"), which makes more sense in
> >> general and in case effective_constraint_ns is never updated
> >> (the device is in suspend all the time or it is never suspended)
> >> it doesn't affect the device's parent and so on.
> >>
> >> Finally, rework default_suspend_ok() to explicitly handle the
> >> "no restriction" special case.
> >>
> >> Signed-off-by: Rafael J. Wysocki 
> >> ---
> 
> [cut]
> 
> > Looks good to me.
> >
> > Acked-by: Ramesh Thomas 
> 
> Thanks!
> 
> Do you actually mean Reviewed-by?

Yes, it should be Reveiewed-by for both patches!

Thanks,
Ramesh



[PATCH] clk: meson: gxbb: fix wrong clock for SARADC/SANA

2017-11-05 Thread Yixun Lan
According to the datasheet, in Meson-GXBB/GXL series,
The clock gate bit for SARADC is HHI_GCLK_MPEG2 bit[22],
while clock gate bit for SANA is HHI_GCLK_MPEG0 bit[10].

Test passed at gxl_skt dev board.

Tested-by: Xingyu Chen 
Signed-off-by: Yixun Lan 

---
I think this error was introduced by a copy & paste from meson8 code?
and we didn't notice them due to the SANA clock is also enabled by
DTS (so SAR_ADC works fine)?
---
 drivers/clk/meson/gxbb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/meson/gxbb.c b/drivers/clk/meson/gxbb.c
index b2d1e8ed7152..92168348ffa6 100644
--- a/drivers/clk/meson/gxbb.c
+++ b/drivers/clk/meson/gxbb.c
@@ -1139,7 +1139,7 @@ static MESON_GATE(gxbb_pl301, HHI_GCLK_MPEG0, 6);
 static MESON_GATE(gxbb_periphs, HHI_GCLK_MPEG0, 7);
 static MESON_GATE(gxbb_spicc, HHI_GCLK_MPEG0, 8);
 static MESON_GATE(gxbb_i2c, HHI_GCLK_MPEG0, 9);
-static MESON_GATE(gxbb_sar_adc, HHI_GCLK_MPEG0, 10);
+static MESON_GATE(gxbb_sana, HHI_GCLK_MPEG0, 10);
 static MESON_GATE(gxbb_smart_card, HHI_GCLK_MPEG0, 11);
 static MESON_GATE(gxbb_rng0, HHI_GCLK_MPEG0, 12);
 static MESON_GATE(gxbb_uart0, HHI_GCLK_MPEG0, 13);
@@ -1190,7 +1190,7 @@ static MESON_GATE(gxbb_usb0_ddr_bridge, HHI_GCLK_MPEG2, 
9);
 static MESON_GATE(gxbb_mmc_pclk, HHI_GCLK_MPEG2, 11);
 static MESON_GATE(gxbb_dvin, HHI_GCLK_MPEG2, 12);
 static MESON_GATE(gxbb_uart2, HHI_GCLK_MPEG2, 15);
-static MESON_GATE(gxbb_sana, HHI_GCLK_MPEG2, 22);
+static MESON_GATE(gxbb_sar_adc, HHI_GCLK_MPEG2, 22);
 static MESON_GATE(gxbb_vpu_intr, HHI_GCLK_MPEG2, 25);
 static MESON_GATE(gxbb_sec_ahb_ahb3_bridge, HHI_GCLK_MPEG2, 26);
 static MESON_GATE(gxbb_clk81_a53, HHI_GCLK_MPEG2, 29);
-- 
2.14.1



Re: [1/2] mm: drop migrate type checks from has_unmovable_pages

2017-11-05 Thread Vlastimil Babka
On 11/05/2017 10:56 PM, Stefan Wahren wrote:
> Hi Michal,
> 
> the dwc2 USB driver on BCM2835 in linux-next is affected by the CMA 
> allocation issue. A quick web search guide me to your patch, which avoid the 
> issue.
> 
> Since the patch wasn't accepted, i want to know is there another solution?

AFAIK it was accepted:
http://www.ozlabs.org/~akpm/mmotm/broken-out/mm-drop-migrate-type-checks-from-has_unmovable_pages.patch

So I'd expect it to be in current linux-next as well.

> Is this an issue in dwc2?
> 
> Best regards
> Stefan
> 



Re: [PATCH 0/3] More code cleanups

2017-11-05 Thread Gilad Ben-Yossef
On Mon, Nov 6, 2017 at 9:38 AM, Greg Kroah-Hartman
 wrote:
> On Mon, Nov 06, 2017 at 06:55:49AM +, Gilad Ben-Yossef wrote:
>> Additional code readability and simplification patches.
>> These goes on top the previous patch set sent to the list.
>
> Please label your 0/X patches the same way your patches are, with the
> prefix of the subsystem, otherwise they get dropped from my searches of
> my inbox at times.
>
> For this one, it would be:
> [PATCH 0/3] staging: ccree: More code cleanups.
>
> thanks,

Oopss.., sorry.

Writing that subject line is almost the only thing not automated in
my patch set sending process so of course I mangled it ...

Do you want to me to resend this patch series?

Gilad



-- 
Gilad Ben-Yossef
Chief Coffee Drinker

"If you take a class in large-scale robotics, can you end up in a
situation where the homework eats your dog?"
 -- Jean-Baptiste Queru


Re: [PATCH RFC v2 4/4] mm/mempolicy: add nodes_empty check in SYSC_migrate_pages

2017-11-05 Thread Vlastimil Babka
On 11/06/2017 02:31 AM, Yisheng Xie wrote:
> Hi Vlastimil,
> 
> On 2017/10/31 17:46, Vlastimil Babka wrote:
>> +CC Andi and Christoph
>>
>> On 10/27/2017 12:14 PM, Yisheng Xie wrote:
>>> As manpage of migrate_pages, the errno should be set to EINVAL when none
>>> of the specified nodes contain memory. However, when new_nodes is null,
>>> i.e. the specified nodes also do not have memory, as the following case:
>>>
>>> new_nodes = 0;
>>> old_nodes = 0xf;
>>> ret = migrate_pages(pid, old_nodes, new_nodes, MAX);
>>>
>>> The ret will be 0 and no errno is set.
>>>
>>> This patch is to add nodes_empty check to fix above case.
>>
>> Hmm, I think we have a bigger problem than "empty set is a subset of
>> anything" here.
>>
>> The existing checks are:
>>
>> task_nodes = cpuset_mems_allowed(task);
>> if (!nodes_subset(*new, task_nodes) && !capable(CAP_SYS_NICE)) {
>> err = -EPERM;
>> goto out_put;
>> }
>>
>> if (!nodes_subset(*new, node_states[N_MEMORY])) {
>> err = -EINVAL;
>> goto out_put;
>> }
>>
>>
>> And manpage says:
>>
>>EINVAL The value specified by maxnode exceeds a kernel-imposed
>> limit.  Or, old_nodes or new_nodes specifies one or more node IDs that
>> are greater than the maximum supported node
>>   ID.  *Or, none of the node IDs specified by new_nodes are
>> on-line and allowed by the process's current cpuset context, or none of
>> the specified nodes contain memory.*
>>
>>EPERM  Insufficient privilege (CAP_SYS_NICE) to move pages of the
>> process specified by pid, or insufficient privilege (CAP_SYS_NICE) to
>> access the specified target nodes.
>>
>> - it says "none ... are allowed", but checking for subset means we check
>> if "all ... are allowed". Shouldn't we be checking for a non-empty
>> intersection?
> 
> You are absolutely right. To follow the manpage, we should check non-empty
> of intersection instead of subset. I mean:
>  nodes_and(*new, *new, task_nodes);
>  if (!node_empty(*new) && !capable(CAP_SYS_NICE)) {
>  err = -EPERM;
>  goto out_put;
>  }
> 
>  nodes_and(*new, *new, node_states[N_MEMORY]);
>  if (!node_empty(*new)) {
>  err = -EINVAL;
>  goto out_put;
>  }

Maybe not exactly like this, see below.

> So finally, we should only migrate the smallest intersection of all the node
> set, right?

That's right.

So if new_nodes AND task_nodes AND node_states[N_MEMORY] is empty, then
EINVAL.

I'm not sure what exactly is the EPERM intention. Should really the
capability of THIS process override the cpuset restriction of the TARGET
process? Maybe yes. Then, does "insufficient privilege (CAP_SYS_NICE) to
access the specified target nodes." mean that at least some nodes must
be allowed, or all of them? Maybe the subset check is after all OK for
the EPERM check, but still wrong for the EINVAL check.

>> - there doesn't seem to be any EINVAL check for "process's current
>> cpuset context", there's just an EPERM check for "target process's
>> cpuset context".
> 
> This also need to be checked as manpage.
> 
> Thanks
> Yisheng Xie
> 



Re: [PATCH 0/3] More code cleanups

2017-11-05 Thread Greg Kroah-Hartman
On Mon, Nov 06, 2017 at 06:55:49AM +, Gilad Ben-Yossef wrote:
> Additional code readability and simplification patches.
> These goes on top the previous patch set sent to the list.

Please label your 0/X patches the same way your patches are, with the
prefix of the subsystem, otherwise they get dropped from my searches of
my inbox at times.

For this one, it would be:
[PATCH 0/3] staging: ccree: More code cleanups.

thanks,

greg k-h


linux-next: Tree for Nov 6

2017-11-05 Thread Stephen Rothwell
Hi all,

Changes since 20171103:

New tree: cpupower

The powerpc tree still had its build failure for which I applied a patch.

The crypto tree gained a build failure so I used the version from
next-20171103.

The regmap tree lost its build failure.

The tip tree gained a conflict against the pm tree.

The kvm-arm tree gained conflicts against Linus' tree.

The scsi tree gained a conflict against Linus' tree.

The nvdimm tree lost its build failure.

The akpm-current tree gained a conflict against the arm64 tree.

The akpm tree lost a patch that turned up elsewhere and gained a build
failure for which I reveretd a commit.

Non-merge commits (relative to Linus' tree): 10807
 10067 files changed, 519168 insertions(+), 241982 deletions(-)



I have created today's linux-next tree at
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
(patches at http://www.kernel.org/pub/linux/kernel/next/ ).  If you
are tracking the linux-next tree using git, you should not use "git pull"
to do so as that will try to merge the new linux-next release with the
old one.  You should use "git fetch" and checkout or reset to the new
master.

You can see which trees have been included by looking in the Next/Trees
file in the source.  There are also quilt-import.log and merge.log
files in the Next directory.  Between each merge, the tree was built
with a ppc64_defconfig for powerpc, an allmodconfig for x86_64, a
multi_v7_defconfig for arm and a native build of tools/perf. After
the final fixups (if any), I do an x86_64 modules_install followed by
builds for x86_64 allnoconfig, powerpc allnoconfig (32 and 64 bit),
ppc44x_defconfig, allyesconfig and pseries_le_defconfig and i386, sparc
and sparc64 defconfig. And finally, a simple boot test of the powerpc
pseries_le_defconfig kernel in qemu (with and without kvm enabled).

Below is a summary of the state of the merge.

I am currently merging 272 trees (counting Linus' and 42 trees of bug
fix patches pending for the current merge release).

Stats about the size of the tree over time can be seen at
http://neuling.org/linux-next-size.html .

Status of my local build tests will be at
http://kisskb.ellerman.id.au/linux-next .  If maintainers want to give
advice about cross compilers/configs that work, we are always open to add
more builds.

Thanks to Randy Dunlap for doing many randconfig builds.  And to Paul
Gortmaker for triage and bug fixes.

-- 
Cheers,
Stephen Rothwell

$ git checkout master
$ git reset --hard stable
Merging origin/master (2d6349944d96 Merge branch 'fixes' of 
git://git.armlinux.org.uk/~rmk/linux-arm)
Merging fixes/master (820bf5c419e4 Merge tag 'scsi-fixes' of 
git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi)
Merging kbuild-current/fixes (bb3f38c3c5b7 kbuild: clang: fix build failures 
with sparse check)
Merging arc-current/for-curr (fdbed19697e1 ARC: unbork module link errors with 
!CONFIG_ARC_HAS_LLSC)
Merging arm-current/fixes (dad4675388fc ARM: add debug ".edata_real" symbol)
Merging m68k-current/for-linus (558d5ad276c9 m68k/mac: Avoid soft-lockup 
warning after mach_power_off)
Merging metag-fixes/fixes (b884a190afce metag/usercopy: Add missing fixups)
Merging powerpc-fixes/fixes (7ecb37f62fe5 powerpc/perf: Fix core-imc hotplug 
callback failure during imc initialization)
Merging sparc/master (23198ddffb6c sparc32: Add cmpxchg64().)
Merging fscrypt-current/for-stable (42d97eb0ade3 fscrypt: fix renaming and 
linking special files)
Merging net/master (d09b9e60e06d tcp: fix DSACK-based undo on non-duplicate ACK)
Merging ipsec/master (cf3796675174 xfrm: do unconditional template resolution 
before pcpu cache check)
Merging netfilter/master (7400bb4b5800 netfilter: nf_reject_ipv4: Fix 
use-after-free in send_reset)
Merging ipvs/master (f7fb77fc1235 netfilter: nft_compat: check extension hook 
mask only if set)
Merging wireless-drivers/master (a6127b4440d1 Merge tag 
'iwlwifi-for-kalle-2017-10-06' of 
git://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/iwlwifi-fixes)
Merging mac80211/master (9618aec3349b Merge tag 'mac80211-for-davem-2017-10-25' 
of git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211)
Merging sound-current/for-linus (f5ce817951f3 ALSA: usb-audio: support new 
Amanero Combo384 firmware version)
Merging pci-current/for-linus (814eae5982cc alpha/PCI: Move 
pci_map_irq()/pci_swizzle() out of initdata)
Merging driver-core.current/driver-core-linus (bb176f67090c Linux 4.14-rc6)
Merging tty.current/tty-linus (8a5776a5f498 Linux 4.14-rc4)
Merging usb.current/usb-linus (bb176f67090c Linux 4.14-rc6)
Merging usb-gadget-fixes/fixes (7c80f9e4a588 usb: usbtest: fix NULL pointer 
dereference)
Merging usb-serial-fixes/usb-linus (0b07194bb55e Linux 4.14-rc7)
Merging usb-chipidea-fixes/ci-for-usb-stable (cbb22ebcfb99 usb: chipidea: core: 
check before accessing ci_role in ci_role_show)
Merging phy/fixes (2fb850092fd9 phy: rockchip-typec: Check for errors from 
tc

Re: [PATCH resend 2/2] userns: control capabilities of some user namespaces

2017-11-05 Thread महेश बंडेवार
On Sat, Nov 4, 2017 at 4:53 PM, Serge E. Hallyn  wrote:
>
> Quoting Mahesh Bandewar (mah...@bandewar.net):
> > Init-user-ns is always uncontrolled and a process that has SYS_ADMIN
> > that belongs to uncontrolled user-ns can create another (child) user-
> > namespace that is uncontrolled. Any other process (that either does
> > not have SYS_ADMIN or belongs to a controlled user-ns) can only
> > create a user-ns that is controlled.
>
> That's a huge change though.  It means that any system that previously
> used unprivileged containers will need new privileged code (which always
> risks more privilege leaks through the new code) to re-enable what was
> possible without privilege before.  That's a regression.
>
I wouldn't call it a regression since the existing behavior is
preserved as it is if the default-mask is not altered. i.e.
uncontrolled process can create user-ns and have full control inside
that user-ns. The only difference is - as an example if 'something'
comes up which makes a specific capability expose ring-0, so admin can
quickly remove the capability in question from the mask, so that no
untrusted code can exploit that capability until either the kernel is
patched or workloads are sanitized keeping in mind what was
discovered. (I have given some real life example vulnerabilities
published recently about CAP_NET_RAW in the cover letter)

> I'm very much interested in what you want to do,  But it seems like
> it would be worth starting with some automated code analysis that shows
> exactly what code becomes accessible to unprivileged users with user
> namespaces which was accessible to unprivileged users before.  Then we
> can reason about classifying that code and perhaps limiting access to
> some of it.
I would like to look at this as 'a tool' that is available to admins
who can quickly take possible-compromise-situation under-control
probably at the cost of some functionality-loss until kernel is
patched and the mask is restored to default value.

I'm not sure if automated tools could discover anything since these
changes should not alter behavior in any way.


[PATCH] iio: mma8452: add power_mode sysfs configuration

2017-11-05 Thread Martin Kepplinger
This adds the power_mode sysfs interface to the device as documented in
sysfs-bus-iio.

---

Note that I explicitely don't sign off on this.

This is a starting point for anybody who can test it and check for correct
API usage, and ABI correctness, as documented in 
Documentation/ABI/testing/sys-bus-iio
(grep it for "power_mode"). The ABI doc probably would need an addition
too, if the 4 power modes here seem generally useful (there are only
 2 listed there)!

So, if you can test this, feel free to set up a proper patch or
two, and I'm happy to review.

Please note that this patch is quite old. It really should be that simple
as far as my understanding back then. We always list the available frequencies
of the given power mode we are in, for example, already, and everything
basically is in place except for the user interface.

thanks
martin



 drivers/iio/accel/mma8452.c | 37 +
 1 file changed, 37 insertions(+)

diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index bfd4bc806fc2..640bbd9872ab 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -1166,6 +1166,41 @@ static struct attribute_group 
mma8452_event_attribute_group = {
.attrs = mma8452_event_attributes,
 };
 
+static const char * const mma8452_power_modes[] = {"normal",
+  "low_noise_low_power",
+  "low_noise",
+  "low_power"};
+
+static int mma8452_get_power_mode_iio_enum(struct iio_dev *indio_dev,
+  const struct iio_chan_spec *chan)
+{
+   struct mma8452_data *data = iio_priv(indio_dev);
+
+   return mma8452_get_power_mode(data);
+}
+
+static int mma8452_set_power_mode_iio_enum(struct iio_dev *indio_dev,
+  const struct iio_chan_spec *chan,
+  unsigned int mode)
+{
+   struct mma8452_data *data = iio_priv(indio_dev);
+
+   return mma8452_set_power_mode(data, mode);
+}
+
+static const struct iio_enum mma8452_power_mode_enum = {
+   .items = mma8452_power_modes,
+   .num_items = ARRAY_SIZE(mma8452_power_modes),
+   .get = mma8452_get_power_mode_iio_enum,
+   .set = mma8452_set_power_mode_iio_enum,
+};
+
+static const struct iio_chan_spec_ext_info mma8452_ext_info[] = {
+   IIO_ENUM("power_mode", true, &mma8452_power_mode_enum),
+   IIO_ENUM_AVAILABLE("power_mode", &mma8452_power_mode_enum),
+   { },
+};
+
 #define MMA8452_FREEFALL_CHANNEL(modifier) { \
.type = IIO_ACCEL, \
.modified = 1, \
@@ -1204,6 +1239,7 @@ static struct attribute_group 
mma8452_event_attribute_group = {
}, \
.event_spec = mma8452_transient_event, \
.num_event_specs = ARRAY_SIZE(mma8452_transient_event), \
+   .ext_info = mma8452_ext_info, \
 }
 
 #define MMA8652_CHANNEL(axis, idx, bits) { \
@@ -1225,6 +1261,7 @@ static struct attribute_group 
mma8452_event_attribute_group = {
}, \
.event_spec = mma8452_motion_event, \
.num_event_specs = ARRAY_SIZE(mma8452_motion_event), \
+   .ext_info = mma8452_ext_info, \
 }
 
 static const struct iio_chan_spec mma8451_channels[] = {
-- 
2.11.0



Re: Re: [PATCH] tty: fix flush_to_ldisc() oops before tty_open is done

2017-11-05 Thread taoyuhong
Hi Greg

>How is things crashing on startup when you are messing with data being sent on 
>shutdown?
>Are you still sending data at startup time?

Yes, I always sending data at startup. Actually I keep sending "reboot" to 
serial port, all the time, no break, regardless of any response from system.
This bug is triggered by serial input at system startup/shutdown. If you don't 
do that then everything is OK. I am not sure is it a mistake for users to send 
serial data at system startup/shutdown.

> I don't remember anymore, did you have a proposed patch/fix for this?
I find a simple way to solve this problem. It may not perfect, but really work. 
Because I am not know tty drivers well, I just saw that problem with linux 
crash tool, and fix it at the point of cause. I have spent a lot of time on 
testing, make sure the problem is gone.
That is the patch 2 weeks ago:
---
From: Yuhong Tao 

When tty_open() is opening a serial tty at the first time, after
alloc_tty_struct() is called, before tty->ops->open() is finished.
Serial driever like pl011 on ARM is ready to setup kworker threads to receive 
data with flush_to_ldisc(). Serial input at this time window can trigger kernel 
oops.
On the other side, flush_to_ldisc() can also oops on a hung-up tty.
It is unknown why flush_to_ldisc() can happen after target tty is hung up. But 
both of these 2 situations come into a same result, look like
that:

[   11.287911] [] n_tty_receive_buf_common+0x58/0xa58
[   11.290161] [] n_tty_receive_buf2+0x10/0x18
[   11.292162] [] tty_ldisc_receive_buf+0x20/0x68
[   11.294318] [] flush_to_ldisc+0xd4/0xe8
[   11.296181] [] process_one_work+0x128/0x2f0
[   11.298166] [] worker_thread+0x54/0x440
[   11.36] [] kthread+0xe4/0xf8
[   11.301642] [] ret_from_fork+0x10/0x50
[   11.303460] Code: b9009fbf f90047a0 d2844c00 8b17 (c8dffc03)

Calltrace may have a bit different behind n_tty_receive_buf_common, that is 
about accessing to uninitialized or realeased data struct.
Serial driver may has problem, but tty driver can easily handle these 2 oops 
problems by:

1. Skip data transfer of hung-up tty, in flush_to_ldisc() 2. Mark hungup to 
tty_struct created by tty_openi(), which will be cleaned
   at the end of tty_open().

This is tested with linux-4.13.9/Debian on ARM virtual machine, whose serial 
chip is pl011. You have a little chance to watch this happen, when keep input 
from keyboard during system start or shutdown. And it happens 100% if a 
msleep() is inserted  before tty->ops->open() is called in tty_open(), after 
tty_struct is created by tty_init_dev().

Signed-off-by: Yuhong Tao 
---
 drivers/tty/pty.c  | 1 +
 drivers/tty/tty_io.c   | 3 +++
 drivers/tty/tty_port.c | 5 +
 3 files changed, 9 insertions(+)

diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c index a6d5164..ad5b075 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -853,6 +853,7 @@ static int ptmx_open(struct inode *inode, struct file *filp)
 
tty_debug_hangup(tty, "opening (count=%d)\n", tty->count);
 
+   clear_bit(TTY_HUPPED, &tty->flags);
tty_unlock(tty);
return 0;
 err_release:
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 10c4038..f3abad0 
100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -1313,6 +1313,9 @@ struct tty_struct *tty_init_dev(struct tty_driver 
*driver, int idx)
 
tty->port->itty = tty;
 
+   set_bit(TTY_HUPPED, &tty->flags);
+   barrier();
+
/*
 * Structures all installed ... call the ldisc open routines.
 * If we fail here just call release_tty to clean up.  No need diff 
--git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c index 6b13719..e43482f 
100644
--- a/drivers/tty/tty_port.c
+++ b/drivers/tty/tty_port.c
@@ -34,6 +34,11 @@ static int tty_port_default_receive_buf(struct tty_port 
*port,
if (!disc)
return 0;
 
+   if (test_bit(TTY_HUPPED, &tty->flags)) {
+   tty_ldisc_deref(disc);
+   return 0;
+   }
+
ret = tty_ldisc_receive_buf(disc, p, (char *)f, count);
 
tty_ldisc_deref(disc);
--
1.8.3.1



Re: [PATCH v10 20/38] x86, mpparse: Use memremap to map the mpf and mpc data

2017-11-05 Thread Tomeu Vizoso
On 3 November 2017 at 16:31, Tom Lendacky  wrote:
> On 11/3/2017 10:12 AM, Tomeu Vizoso wrote:
>>
>> On 17 July 2017 at 23:10, Tom Lendacky  wrote:
>>>
>>> The SMP MP-table is built by UEFI and placed in memory in a decrypted
>>> state. These tables are accessed using a mix of early_memremap(),
>>> early_memunmap(), phys_to_virt() and virt_to_phys(). Change all accesses
>>> to use early_memremap()/early_memunmap(). This allows for proper setting
>>> of the encryption mask so that the data can be successfully accessed when
>>> SME is active.
>>>
>>> Reviewed-by: Borislav Petkov 
>>> Signed-off-by: Tom Lendacky 
>>> ---
>>>   arch/x86/kernel/mpparse.c | 98
>>> +--
>>>   1 file changed, 70 insertions(+), 28 deletions(-)
>>
>>
>> Hi there,
>>
>> today I played a bit with crosvm [0] and noticed that 4.14-rc7 doesn't
>> boot. git-bisect pointed to this patch, and reverting it indeed gets
>> things working again.
>>
>> Anybody has an idea of why this could be?
>
>
> If you send me your kernel config I'll see if I can reproduce the issue
> and debug it.

x86_64_defconfig should be enough. I have pasted my dev env
instructions here in case they help:

http://blog.tomeuvizoso.net/2017/11/experiments-with-crosvm_6.html

Thanks,

Tomeu


Re: [PATCH] crypto: chcr - Replace _manual_ swap with swap macro

2017-11-05 Thread Herbert Xu
On Fri, Nov 03, 2017 at 11:58:23AM -0500, Gustavo A. R. Silva wrote:
> Make use of the swap macro and remove unnecessary variable temp.
> This makes the code easier to read and maintain.
> 
> This code was detected with the help of Coccinelle.
> 
> Signed-off-by: Gustavo A. R. Silva 

Patch applied.  Thanks.
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


RE: [f2fs-dev] [PATCH RESEND] f2fs: modify the procedure of scan free nid

2017-11-05 Thread Fan Li


> -Original Message-
> From: Chao Yu [mailto:c...@kernel.org]
> Sent: Friday, November 03, 2017 9:16 PM
> To: Fan Li; 'Chao Yu'; 'Jaegeuk Kim'
> Cc: linux-kernel@vger.kernel.org; linux-f2fs-de...@lists.sourceforge.net
> Subject: Re: [f2fs-dev] [PATCH RESEND] f2fs: modify the procedure of scan 
> free nid
> 
> On 2017/11/3 18:29, Fan Li wrote:
> >
> >
> >> -Original Message-
> >> From: Chao Yu [mailto:yuch...@huawei.com]
> >> Sent: Friday, November 03, 2017 4:54 PM
> >> To: Fan Li; 'Chao Yu'; 'Jaegeuk Kim'
> >> Cc: linux-kernel@vger.kernel.org;
> >> linux-f2fs-de...@lists.sourceforge.net
> >> Subject: Re: [f2fs-dev] [PATCH RESEND] f2fs: modify the procedure of
> >> scan free nid
> >>
> >> On 2017/11/3 15:31, Fan Li wrote:
> >>> In current version, we preserve 8 pages of nat blocks as free nids,
> >>> we build bitmaps for it and use them to allocate nids until its
> >>> number drops below NAT_ENTRY_PER_BLOCK.
> >>>
> >>> After that, we have a problem, scan_free_nid_bits will scan the same
> >>> 8 pages trying to find more free nids, but in most cases the free
> >>> nids in these bitmaps are already in free list, scan them won't get
> >>> us any new nids.
> >>> Further more, after scan_free_nid_bits, the scan is over if
> >>> nid_cnt[FREE_NID] != 0.
> >>> It causes that we scan the same pages over and over again, and no
> >>> new free nids are found until nid_cnt[FREE_NID]==0. While the
> >>> scanned pages increase, the problem grows worse.
> >>>
> >>> This patch mark the range where new free nids could exist and keep
> >>> scan for free nids until nid_cnt[FREE_NID] >= NAT_ENTRY_PER_BLOCK.
> >>> The new vairable first_scan_block marks the start of the range, it's
> >>> initialized with NEW_ADDR, which means all free nids before
> >>> next_scan_nid are already in free list; and use next_scan_nid as the
> >>> end of the range since all free nids which are scanned in
> >>> scan_free_nid_bits must be smaller next_scan_nid.
> >>
> >> Think over again, IMO, we can add an variable for stating total count
> >> of free nids in bitamp, if there is no free nid, just
> > skipping scanning all
> >> existed bitmap.
> >>
> >> And if there is only few free nid scattered in bitmap, the cost will
> >> be limited because we will skip scanning
> > nm_i::free_nid_bitmap if
> >> nm_i::free_nid_count is zero. Once we find one free nid, let's skip out.
> >>
> >> Since there shouldn't be very heavy overhead for CPU during traveling
> >> nm_i::nat_block_bitmap, I expect below change could be more simple for 
> >> maintaining and being with the same effect.
> >>
> >> How do you think?
> >>
> >
> > I think if you need this to work, check total_bitmap_free_nid may not be 
> > sufficient enough.
> > The problem this patch presents is  that even all the free nids are
> > already in the free list, we still scan all the pages.
> > The scan proceeds once free nid count is below NAT_ENTRY_PER_BLOCK.
> > So in most cases, there are still free nids in the bitmap during the
> > scan, and current codes will check every one of them to see if they are 
> > actually in free list.
> > If only check total_bitmap_free_nid == 0 won't take this overhead away.
> 
> Oh, you could see that, we have added free_nid_count in each NAT block's 
> free_nid_bitmap bitmap, before scan the bitmap, we will
make
> sure there is at least one free nid.
> 
> scan_free_nid_bits()
>   for (i = 0; i < nm_i->nat_blocks; i++) {
>   if (!test_bit_le(i, nm_i->nat_block_bitmap))
>   continue;
>   if (!nm_i->free_nid_count[i])
>   continue;
Do you mean  free_nid_count here?
I thought free_nid_count only represents how many nats are marked free in 
bitmap of one block.

To my understanding, even a nat is already in the free list, it will still have 
a bit marked as free in 
free_nid_bitmap and a count in free_nid_count.
That means if free_nid_count != 0, and there are marked bits in the bitmap, the 
free nats in this
block could still  be all in the free list.
The purpose of scan is to find new nats and add them to free list, go through 
the nats which are
already in the free list isn't what we want.
And in xfstest, under most cases scan_free_nid_bits runs, all free nats are 
indeed in the free list.

>   for (idx = 0; idx < NAT_ENTRY_PER_BLOCK; idx++) {
>   nid_t nid;
> 
>   if (!test_bit_le(idx, nm_i->free_nid_bitmap[i]))
>   continue;
> 
>   nid = i * NAT_ENTRY_PER_BLOCK + idx;
>   add_free_nid(sbi, nid, true);
> 
>   if (nm_i->nid_cnt[FREE_NID] >= MAX_FREE_NIDS)
>   goto out;
>   }
>   }
> 
> And In that diff, we have changed the exiting condition, once we have grabbed 
> one free nid, stop building.
> 
> >> -  if (nm_i->nid_cnt[FREE_NID] >= MAX_FREE_NIDS)
> >> +  if (nm_i->nid_cnt

[PATCH v2 2/4] arm64: dts: qcom: apq8016-sbc: Allow USR4 LED to notify kernel panic

2017-11-05 Thread Amit Kucheria
Blink the LED on a kernel panic.

Signed-off-by: Amit Kucheria 
Acked-by: Manivannan Sadhasivam 
---
 arch/arm64/boot/dts/qcom/apq8016-sbc.dtsi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/boot/dts/qcom/apq8016-sbc.dtsi 
b/arch/arm64/boot/dts/qcom/apq8016-sbc.dtsi
index 1d63e6b..e4a6850 100644
--- a/arch/arm64/boot/dts/qcom/apq8016-sbc.dtsi
+++ b/arch/arm64/boot/dts/qcom/apq8016-sbc.dtsi
@@ -174,6 +174,7 @@
label = "apq8016-sbc:green:user4";
gpios = <&pm8916_gpios 2 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "none";
+   panic-indicator;
default-state = "off";
};
 
-- 
2.7.4



[PATCH v2 3/4] arm64: dts: hisilicon: hi6220-hikey: Allow USR1 LED to notify kernel panic

2017-11-05 Thread Amit Kucheria
Blink the LED on a kernel panic.

Signed-off-by: Amit Kucheria 
Acked-by: Guodong Xu 
Acked-by: Manivannan Sadhasivam 
---
 arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts 
b/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts
index 3aee612..e94fa1a 100644
--- a/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts
+++ b/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts
@@ -359,6 +359,7 @@
user_led1 {
label = "user_led1";
gpios = <&gpio4 3 0>; /* <&gpio_user_led_4>; */
+   panic-indicator;
linux,default-trigger = "cpu0";
};
 
-- 
2.7.4



[PATCH v2 1/4] arm64: defconfig: enable new trigger modes for leds

2017-11-05 Thread Amit Kucheria
Most development boards and devices have one or more LEDs. It is useful
during debugging if they can be wired to show different behaviours such as
disk or cpu activity or a load-average dependent heartbeat. Enable panic
and disk activity triggers so they can be tied to LED activity during
debugging as well.

Signed-off-by: Amit Kucheria 
---
 arch/arm64/configs/defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig
index 34480e9..4ed357f 100644
--- a/arch/arm64/configs/defconfig
+++ b/arch/arm64/configs/defconfig
@@ -460,6 +460,8 @@ CONFIG_LEDS_SYSCON=y
 CONFIG_LEDS_TRIGGER_HEARTBEAT=y
 CONFIG_LEDS_TRIGGER_CPU=y
 CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
+CONFIG_LEDS_TRIGGER_PANIC=y
+CONFIG_LEDS_TRIGGER_DISK=y
 CONFIG_EDAC=y
 CONFIG_RTC_CLASS=y
 CONFIG_RTC_DRV_MAX77686=y
-- 
2.7.4



[PATCH v2 4/4] arm64: dts: hisilicon: hi3660-hikey960: Allow USR4 LED to notify kernel panic

2017-11-05 Thread Amit Kucheria
Blink the LED on a kernel panic.

Signed-off-by: Amit Kucheria 
Acked-by: Guodong Xu 
Tested-by: Manivannan Sadhasivam 
---
 arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts 
b/arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts
index e9f87cb..1cf77ee 100644
--- a/arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts
+++ b/arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts
@@ -109,6 +109,7 @@
label = "user_led4";
/* gpio_190_user_led4 */
gpios = <&gpio23 6 0>;
+   panic-indicator;
linux,default-trigger = "cpu0";
};
 
-- 
2.7.4



[PATCH v2 0/4] arm64: defconfig: enable additional led triggers

2017-11-05 Thread Amit Kucheria
This patchset enables the kernel panic and disk-activity trigger for LEDs
and then enables the panic trigger for three 96Boards - DB410c, Hikey and
Hikey960.

DB410c and Hikey panic behaviour has been tested by triggering a panic
through /proc/sysrq-trigger, while Hikey960 is only compile-tested.


Amit Kucheria (4):
  arm64: defconfig: enable new trigger modes for leds
  arm64: dts: qcom: apq8016-sbc: Allow USR4 LED to notify kernel panic
  arm64: dts: hisilicon: hi6220-hikey: Allow USR1 LED to notify kernel
panic
  arm64: dts: hisilicon: hi3660-hikey960: Allow USR4 LED to notify
kernel panic

 arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts | 1 +
 arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts| 1 +
 arch/arm64/boot/dts/qcom/apq8016-sbc.dtsi | 1 +
 arch/arm64/configs/defconfig  | 2 ++
 4 files changed, 5 insertions(+)

-- 
2.7.4



Re: [RFC PATCH] mm, oom_reaper: gather each vma to prevent leaking TLB entry

2017-11-05 Thread Bob Liu
On Mon, Nov 6, 2017 at 11:36 AM, Wang Nan  wrote:
> tlb_gather_mmu(&tlb, mm, 0, -1) means gathering all virtual memory space.
> In this case, tlb->fullmm is true. Some archs like arm64 doesn't flush
> TLB when tlb->fullmm is true:
>
>   commit 5a7862e83000 ("arm64: tlbflush: avoid flushing when fullmm == 1").
>

CC'ed Will Deacon.

> Which makes leaking of tlb entries. For example, when oom_reaper
> selects a task and reaps its virtual memory space, another thread
> in this task group may still running on another core and access
> these already freed memory through tlb entries.
>
> This patch gather each vma instead of gathering full vm space,
> tlb->fullmm is not true. The behavior of oom reaper become similar
> to munmapping before do_exit, which should be safe for all archs.
>
> Signed-off-by: Wang Nan 
> Cc: Bob Liu 
> Cc: Michal Hocko 
> Cc: Andrew Morton 
> Cc: Michal Hocko 
> Cc: David Rientjes 
> Cc: Ingo Molnar 
> Cc: Roman Gushchin 
> Cc: Konstantin Khlebnikov 
> Cc: Andrea Arcangeli 
> ---
>  mm/oom_kill.c | 7 ---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/mm/oom_kill.c b/mm/oom_kill.c
> index dee0f75..18c5b35 100644
> --- a/mm/oom_kill.c
> +++ b/mm/oom_kill.c
> @@ -532,7 +532,6 @@ static bool __oom_reap_task_mm(struct task_struct *tsk, 
> struct mm_struct *mm)
>  */
> set_bit(MMF_UNSTABLE, &mm->flags);
>
> -   tlb_gather_mmu(&tlb, mm, 0, -1);
> for (vma = mm->mmap ; vma; vma = vma->vm_next) {
> if (!can_madv_dontneed_vma(vma))
> continue;
> @@ -547,11 +546,13 @@ static bool __oom_reap_task_mm(struct task_struct *tsk, 
> struct mm_struct *mm)
>  * we do not want to block exit_mmap by keeping mm ref
>  * count elevated without a good reason.
>  */
> -   if (vma_is_anonymous(vma) || !(vma->vm_flags & VM_SHARED))
> +   if (vma_is_anonymous(vma) || !(vma->vm_flags & VM_SHARED)) {
> +   tlb_gather_mmu(&tlb, mm, vma->vm_start, vma->vm_end);
> unmap_page_range(&tlb, vma, vma->vm_start, 
> vma->vm_end,
>  NULL);
> +   tlb_finish_mmu(&tlb, vma->vm_start, vma->vm_end);
> +   }
> }
> -   tlb_finish_mmu(&tlb, 0, -1);
> pr_info("oom_reaper: reaped process %d (%s), now anon-rss:%lukB, 
> file-rss:%lukB, shmem-rss:%lukB\n",
> task_pid_nr(tsk), tsk->comm,
> K(get_mm_counter(mm, MM_ANONPAGES)),


Re: [PATCH] rtc: omap: Support scratch registers

2017-11-05 Thread Sekhar Nori
On Monday 06 November 2017 12:29 PM, Keerthy wrote:
> 
> 
> On Monday 06 November 2017 12:25 PM, Sekhar Nori wrote:
>> + linux omap list
>>
>> On Tuesday 31 October 2017 09:57 PM, Alexandre Belloni wrote:
>>> Register an nvmem device to expose the 3 scratch registers (total of 12
>>> bytes) to both userspace and kernel space.
>>>
>>> Signed-off-by: Alexandre Belloni 
>>
>> Looks good to me.
>>
>> Reviewed-by: Sekhar Nori 
>>
>> Curious on what you are using these registers for.
> 
> This is in response to this:
> https://patchwork.kernel.org/patch/9684955/

Ah, okay. Makes sense then :)

Regards,
Sekhar


Re: [PATCH] rtc: omap: Support scratch registers

2017-11-05 Thread Keerthy


On Monday 06 November 2017 12:25 PM, Sekhar Nori wrote:
> + linux omap list
> 
> On Tuesday 31 October 2017 09:57 PM, Alexandre Belloni wrote:
>> Register an nvmem device to expose the 3 scratch registers (total of 12
>> bytes) to both userspace and kernel space.
>>
>> Signed-off-by: Alexandre Belloni 
> 
> Looks good to me.
> 
> Reviewed-by: Sekhar Nori 
> 
> Curious on what you are using these registers for.

This is in response to this:
https://patchwork.kernel.org/patch/9684955/


> 
> Thanks,
> Sekhar
> 
>> ---
>>  drivers/rtc/rtc-omap.c | 45 +
>>  1 file changed, 45 insertions(+)
>>
>> diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
>> index d56d937966dc..1d666ac9ef70 100644
>> --- a/drivers/rtc/rtc-omap.c
>> +++ b/drivers/rtc/rtc-omap.c
>> @@ -70,6 +70,10 @@
>>  #define OMAP_RTC_COMP_MSB_REG   0x50
>>  #define OMAP_RTC_OSC_REG0x54
>>  
>> +#define OMAP_RTC_SCRATCH0_REG   0x60
>> +#define OMAP_RTC_SCRATCH1_REG   0x64
>> +#define OMAP_RTC_SCRATCH2_REG   0x68
>> +
>>  #define OMAP_RTC_KICK0_REG  0x6c
>>  #define OMAP_RTC_KICK1_REG  0x70
>>  
>> @@ -667,6 +671,45 @@ static struct pinctrl_desc rtc_pinctrl_desc = {
>>  .owner = THIS_MODULE,
>>  };
>>  
>> +static int omap_rtc_scratch_read(void *priv, unsigned int offset, void 
>> *_val,
>> + size_t bytes)
>> +{
>> +struct omap_rtc *rtc = priv;
>> +u32 *val = _val;
>> +int i;
>> +
>> +for (i = 0; i < bytes / 4; i++)
>> +val[i] = rtc_readl(rtc,
>> +   OMAP_RTC_SCRATCH0_REG + offset + (i * 4));
>> +
>> +return 0;
>> +}
>> +
>> +static int omap_rtc_scratch_write(void *priv, unsigned int offset, void 
>> *_val,
>> +  size_t bytes)
>> +{
>> +struct omap_rtc *rtc = priv;
>> +u32 *val = _val;
>> +int i;
>> +
>> +rtc->type->unlock(rtc);
>> +for (i = 0; i < bytes / 4; i++)
>> +rtc_writel(rtc,
>> +   OMAP_RTC_SCRATCH0_REG + offset + (i * 4), val[i]);
>> +rtc->type->lock(rtc);
>> +
>> +return 0;
>> +}
>> +
>> +static struct nvmem_config omap_rtc_nvmem_config = {
>> +.name = "omap_rtc_scratch",
>> +.word_size = 4,
>> +.stride = 4,
>> +.size = OMAP_RTC_KICK0_REG - OMAP_RTC_SCRATCH0_REG,
>> +.reg_read = omap_rtc_scratch_read,
>> +.reg_write = omap_rtc_scratch_write,
>> +};
>> +
>>  static int omap_rtc_probe(struct platform_device *pdev)
>>  {
>>  struct omap_rtc *rtc;
>> @@ -804,6 +847,8 @@ static int omap_rtc_probe(struct platform_device *pdev)
>>  }
>>  
>>  rtc->rtc->ops = &omap_rtc_ops;
>> +omap_rtc_nvmem_config.priv = rtc;
>> +rtc->rtc->nvmem_config = &omap_rtc_nvmem_config;
>>  
>>  /* handle periodic and alarm irqs */
>>  ret = devm_request_irq(&pdev->dev, rtc->irq_timer, rtc_irq, 0,
>> -- 
>> 2.15.0.rc2
>>
> 


RE: [PATCH v16 5/6] vfio: ABI for mdev display dma-buf operation

2017-11-05 Thread Zhang, Tina


> -Original Message-
> From: intel-gvt-dev [mailto:intel-gvt-dev-boun...@lists.freedesktop.org] On
> Behalf Of Alex Williamson
> Sent: Monday, November 6, 2017 10:39 AM
> To: Zhang, Tina 
> Cc: Tian, Kevin ; Daniel Vetter 
> ;
> intel-...@lists.freedesktop.org; joonas.lahti...@linux.intel.com; linux-
> ker...@vger.kernel.org; zhen...@linux.intel.com; ch...@chris-wilson.co.uk;
> kwankh...@nvidia.com; Lv, Zhiyuan ; dan...@ffwll.ch;
> intel-gvt-...@lists.freedesktop.org; Wang, Zhi A ;
> kra...@redhat.com
> Subject: Re: [PATCH v16 5/6] vfio: ABI for mdev display dma-buf operation
> 
> On Mon,  6 Nov 2017 10:19:17 +0800
> Tina Zhang  wrote:
> 
> > Add VFIO_DEVICE_QUERY_GFX_PLANE ioctl command to let user query and
> > get a plane and its related information. So far, two types of buffers
> > are
> > supported: buffers based on dma-buf and buffers based on region.
> >
> > This ioctl can be invoked with:
> > 1) either DMABUF or REGION flag. Vendor driver returns a plane_info
> > successfully only when the specific kind of buffer is supported.
> > 2) flag PROBE. And at the same time either DMABUF or REGION must be
> > set, so that vendor driver can return success only when the specific
> > kind of buffer is supported.
> >
> > Add VFIO_DEVICE_GET_GFX_DMABUF ioctl command to let user get an
> > exposed dma-buf fd of a specific dmabuf_id which was returned in
> > VFIO_DEVICE_QUERY _GFX_PLANE ioctl command.
> >
> > The life cycle of an exposed MDEV buffer is handled by userspace and
> > tracked by kernel space. The returned dmabuf_id in struct vfio_device_
> > query_gfx_plane can be a new id of a new exposed buffer or an old id
> > of a re-exported buffer. Host user can check the value of dmabuf_id to
> > see if it needs to create new resources according to the new exposed
> > buffer or just re-use the existing resource related to the old buffer.
> >
> > v16:
> > - add x_hot and y_hot fields. (Gerd)
> > - add comments for VFIO_DEVICE_GET_GFX_DMABUF. (Alex)
> > - rebase to 4.14.0-rc6.
> >
> > v15:
> > - add a ioctl to get a dmabuf for a given dmabuf id. (Gerd)
> >
> > v14:
> > - add PROBE, DMABUF and REGION flags. (Alex)
> >
> > v12:
> > - add drm_format_mod back. (Gerd and Zhenyu)
> > - add region_index. (Gerd)
> >
> > v11:
> > - rename plane_type to drm_plane_type. (Gerd)
> > - move fields of vfio_device_query_gfx_plane to vfio_device_gfx_plane_info.
> >   (Gerd)
> > - remove drm_format_mod, start fields. (Daniel)
> > - remove plane_id.
> >
> > v10:
> > - refine the ABI API VFIO_DEVICE_QUERY_GFX_PLANE. (Alex) (Gerd)
> >
> > v3:
> > - add a field gvt_plane_info in the drm_i915_gem_obj structure to save
> >   the decoded plane information to avoid look up while need the plane
> >   info. (Gerd)
> >
> > Signed-off-by: Tina Zhang 
> > Cc: Gerd Hoffmann 
> > Cc: Alex Williamson 
> > Cc: Daniel Vetter 
> > ---
> >  include/uapi/linux/vfio.h | 68
> > +++
> >  1 file changed, 68 insertions(+)
> >
> > diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
> > index ae46105..6c55668 100644
> > --- a/include/uapi/linux/vfio.h
> > +++ b/include/uapi/linux/vfio.h
> > @@ -502,6 +502,74 @@ struct vfio_pci_hot_reset {
> >
> >  #define VFIO_DEVICE_PCI_HOT_RESET  _IO(VFIO_TYPE, VFIO_BASE +
> 13)
> >
> > +/**
> > + * VFIO_DEVICE_QUERY_GFX_PLANE - _IOW(VFIO_TYPE, VFIO_BASE + 14,
> > + *struct vfio_device_query_gfx_plane)
> > + *
> > + * Set the drm_plane_type and flags, then retrieve the gfx plane info.
> > + *
> > + * flags supported:
> > + * - VFIO_GFX_PLANE_TYPE_PROBE and VFIO_GFX_PLANE_TYPE_DMABUF
> are set
> > + *   to ask if the mdev supports dma-buf. 0 on support, -EINVAL on no
> > + *   support for dma-buf.
> > + * - VFIO_GFX_PLANE_TYPE_PROBE and VFIO_GFX_PLANE_TYPE_REGION
> are set
> > + *   to ask if the mdev supports region. 0 on support, -EINVAL on no
> > + *   support for region.
> > + * - VFIO_GFX_PLANE_TYPE_DMABUF or VFIO_GFX_PLANE_TYPE_REGION
> is set
> > + *   with each call to query the plane info.
> > + * - Others are invalid and return -EINVAL.
> > + *
> > + * Return: 0 on success, -ENODEV with all out fields zero on mdev
> > + * device initialization, -errno on other failure.
> > + */
> > +struct vfio_device_gfx_plane_info {
> > +   __u32 argsz;
> > +   __u32 flags;
> > +#define VFIO_GFX_PLANE_TYPE_PROBE (1 << 0) #define
> > +VFIO_GFX_PLANE_TYPE_DMABUF (1 << 1) #define
> > +VFIO_GFX_PLANE_TYPE_REGION (1 << 2)
> > +   /* in */
> > +   __u32 drm_plane_type;   /* type of plane: DRM_PLANE_TYPE_* */
> > +   /* out */
> > +   __u32 drm_format;   /* drm format of plane */
> > +   __u64 drm_format_mod;   /* tiled mode */
> > +   __u32 width;/* width of plane */
> > +   __u32 height;   /* height of plane */
> > +   __u32 stride;   /* stride of plane */
> > +   __u32 size; /* size of plane in bytes, align on page*/
> > +   __u32 x_pos;/* horizontal position of cursor plane */
> > +   __u32 y_pos;/* vertical

Re: [PATCH 3/5] dt-bindings: arm: Document Socionext MB86S71 and Fujitsu F-Cue

2017-11-05 Thread Andreas Färber
Am 05.11.2017 um 04:39 schrieb Ard Biesheuvel:
> On 4 November 2017 at 20:06, Andreas Färber  wrote:
>> Am 04.11.2017 um 23:39 schrieb Ard Biesheuvel:
>>> On 4 November 2017 at 15:30, Andreas Färber  wrote:
 Am 04.11.2017 um 22:57 schrieb Ard Biesheuvel:
> On 4 November 2017 at 13:44, Andreas Färber  wrote:
>> Hi everyone,
>>
>> The non-building clk driver has been removed for 4.14, but this patchset
>> seems stuck on matters of naming and maintenance...
>>
>> Am 30.06.2017 um 01:18 schrieb Masahiro Yamada:
>>> Hi Andreas,
>>>
>>> 2017-06-29 21:53 GMT+09:00 Andreas Färber :
 Hi Masahiro-san,

 Am 29.06.2017 um 14:18 schrieb Masahiro Yamada:
> 2017-06-29 1:46 GMT+09:00 Rob Herring :
>> On Sun, Jun 25, 2017 at 07:00:18PM +0200, Andreas Färber wrote:
>>> For consistency with existing SoC bindings, use "fujitsu,mb86s71" 
>>> but
>>> socionext.txt.
>>>
>>> Signed-off-by: Andreas Färber 
>>> ---
>>>  Documentation/devicetree/bindings/arm/socionext.txt | 17 
>>> +
>>>  1 file changed, 17 insertions(+)
>>>  create mode 100644 
>>> Documentation/devicetree/bindings/arm/socionext.txt
>>
>> Acked-by: Rob Herring 
>> --
>
> I do not mind this, but
> please note there are multiple product lines in Socionext
> because Socionext merged LSI divisions from Panasonic and Fujitsu.
>
> I maintain documents for Socionext UniPhier SoC family
> (which inherits SoC architecture of Panasonic)
> in Documentation/devicetree/bindings/arm/uniphier/.

 Actually you seemed to be lacking bindings beyond the cache controller
 for Uniphier:

 https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/Documentation/devicetree/bindings/arm/uniphier

 The SoC compatible, e.g. "socionext,uniphier-ld11", needs to be defined
 somewhere too, as done here. A git-grep for that particular compatible
 only finds derived clk and reset bindings.
>>>
>>> I can care to send a patch later, but it is off-topic here.
>>
>> [The relevance was that had there been any bindings precedence from
>> UniPhier, it would've influenced my naming choices.]
>>
 Using socionext.txt allows you to add those bindings to a shared file;
 if you prefer to host them separately below uniphier/ or as 
 uniphier.txt
>>>
>>> I was thinking of this way.
>>>
>>> For example, TI has omap/, keystone/, davinci.txt, etc.
>>> in this directory level.
>>>
 do you have a better name suggestion for this one? I was trying to keep
 our options open to later add SC2A11 in socionext.txt, and I also saw
 some mb8ac300 or so (MB86S7x predecessor?) in downstream sources, so I
 don't know a good common name for the non-Panasonic parts. And if we
 take fujitsu.txt for MB86S7x to match the vendor prefix then we will
 need a separate file for the new SC2A11 IIUC.
>>>
>>> I have no idea.
>>> Actually, I am not familiar with those SoCs.
>>>
>>> I am not sure if there exists a common name for those Fujitsu-derived 
>>> SoCs.
>>> I think a SoC family name will be helpful to avoid proliferating
>>> arch/arm/mach-{mb86s7x,mb8ac300, ...}.
>>>
>>> I see some Socionext guys CC'ed in this mail,
>>> somebody might have information about this.
>>>
>>> As I said before, I do not mind adding socionext.txt
>>> and it seems reasonable enough
>>> if there is no common name for those SoCs.
>>>
 Also if you can tell us where the cut between Fujitsu and Socionext
 should be done, we can certainly adapt. NXP is still adding all their
 new SoCs in fsl.txt, it seems.
 (A similar naming issue exists for my not-yet-submitted FM4 patches,
 where it changed owners from Fujitsu to Spansion and then to Cypress.)
>>>
>>> Right, vendor names are not future-proof in some cases.
>>>
>>> We use "uniphier" because it is convenient to
>>> make a group of SoCs with similar architecture,
>>> and it will work even if UniPhier product lines are sold again in the
>>> future.  :-)
>>
>> Summarizing: Masahiro-san only wants to maintain the UniPhier family of
>> Socionext SoCs, not this MB86S71. No one from Socionext or Linaro has
>> volunteered as maintainer for these F-Cue MB86S71 patches - that seems
>> to indicate I'll again have to set up a new repository and start
>> maintaining it myself.
>>
>> Naming it linux-socionext.git wouldn't quite be right due to UniPhier
>> also being Socionext.
>>
>> It's also unclear whether and by whom there may be SC2A11 patches - I
>> hear for now Linaro are 

[PATCH 1/3] staging: ccree: simplify error handling logic

2017-11-05 Thread Gilad Ben-Yossef
Turn the code sites that don't require any special handling
on error return to a simple return.

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/ssi_driver.c | 28 
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/ccree/ssi_driver.c 
b/drivers/staging/ccree/ssi_driver.c
index 1d4c7bb..135a7e2 100644
--- a/drivers/staging/ccree/ssi_driver.c
+++ b/drivers/staging/ccree/ssi_driver.c
@@ -212,10 +212,9 @@ static int init_cc_resources(struct platform_device 
*plat_dev)
int rc = 0;
 
new_drvdata = devm_kzalloc(dev, sizeof(*new_drvdata), GFP_KERNEL);
-   if (!new_drvdata) {
-   rc = -ENOMEM;
-   goto post_drvdata_err;
-   }
+   if (!new_drvdata)
+   return -ENOMEM;
+
platform_set_drvdata(plat_dev, new_drvdata);
new_drvdata->plat_dev = plat_dev;
 
@@ -229,8 +228,7 @@ static int init_cc_resources(struct platform_device 
*plat_dev)
new_drvdata->cc_base = devm_ioremap_resource(dev, req_mem_cc_regs);
if (IS_ERR(new_drvdata->cc_base)) {
dev_err(dev, "Failed to ioremap registers");
-   rc = PTR_ERR(new_drvdata->cc_base);
-   goto post_drvdata_err;
+   return PTR_ERR(new_drvdata->cc_base);
}
 
dev_dbg(dev, "Got MEM resource (%s): %pR\n", req_mem_cc_regs->name,
@@ -244,8 +242,7 @@ static int init_cc_resources(struct platform_device 
*plat_dev)
new_drvdata->irq = platform_get_irq(plat_dev, 0);
if (new_drvdata->irq < 0) {
dev_err(dev, "Failed getting IRQ resource\n");
-   rc = new_drvdata->irq;
-   goto post_drvdata_err;
+   return new_drvdata->irq;
}
 
rc = devm_request_irq(dev, new_drvdata->irq, cc_isr,
@@ -253,7 +250,7 @@ static int init_cc_resources(struct platform_device 
*plat_dev)
if (rc) {
dev_err(dev, "Could not register to interrupt %d\n",
new_drvdata->irq);
-   goto post_drvdata_err;
+   return rc;
}
dev_dbg(dev, "Registered to IRQ: %d\n", new_drvdata->irq);
 
@@ -271,15 +268,16 @@ static int init_cc_resources(struct platform_device 
*plat_dev)
}
 
if (rc) {
-   dev_err(dev, "Error: failed in dma_set_mask, mask=%par\n",
+   dev_err(dev, "Failed in dma_set_mask, mask=%par\n",
&dma_mask);
-   goto post_drvdata_err;
+   return rc;
}
 
rc = cc_clk_on(new_drvdata);
-   if (rc)
-   goto post_drvdata_err;
-
+   if (rc) {
+   dev_err(dev, "Failed to enable clock");
+   return rc;
+   }
 
/* Verify correct mapping */
signature_val = CC_HAL_READ_REGISTER(CC_REG_OFFSET(HOST_RGF, 
HOST_SIGNATURE));
@@ -406,8 +404,6 @@ static int init_cc_resources(struct platform_device 
*plat_dev)
fini_cc_regs(new_drvdata);
 post_clk_err:
cc_clk_off(new_drvdata);
-post_drvdata_err:
-   dev_err(dev, "ccree init error occurred!\n");
return rc;
 }
 
-- 
2.7.4



[PATCH 0/3] More code cleanups

2017-11-05 Thread Gilad Ben-Yossef
Additional code readability and simplification patches.
These goes on top the previous patch set sent to the list.

Gilad Ben-Yossef (3):
  staging: ccree: simplify error handling logic
  staging: ccree: simplify registers access
  staging: ccree: simplify ioread/iowrite

 drivers/staging/ccree/cc_hal.h   | 33 --
 drivers/staging/ccree/cc_regs.h  | 42 --
 drivers/staging/ccree/dx_reg_base_host.h | 25 ---
 drivers/staging/ccree/ssi_driver.c   | 75 ++--
 drivers/staging/ccree/ssi_driver.h   | 20 +++--
 drivers/staging/ccree/ssi_fips.c | 14 +++---
 drivers/staging/ccree/ssi_pm.c   |  4 +-
 drivers/staging/ccree/ssi_request_mgr.c  | 72 +++---
 drivers/staging/ccree/ssi_sysfs.c| 11 +++--
 9 files changed, 98 insertions(+), 198 deletions(-)
 delete mode 100644 drivers/staging/ccree/cc_hal.h
 delete mode 100644 drivers/staging/ccree/cc_regs.h
 delete mode 100644 drivers/staging/ccree/dx_reg_base_host.h

-- 
2.7.4



[PATCH 3/3] staging: ccree: simplify ioread/iowrite

2017-11-05 Thread Gilad Ben-Yossef
Registers ioread/iowrite operations were done via macros,
sometime using a "magical" implicit parameter.

Replace all register access with simple inline macros.

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/cc_hal.h   | 33 --
 drivers/staging/ccree/cc_regs.h  | 35 
 drivers/staging/ccree/dx_reg_base_host.h | 25 --
 drivers/staging/ccree/ssi_driver.c   | 47 --
 drivers/staging/ccree/ssi_driver.h   | 20 +--
 drivers/staging/ccree/ssi_fips.c | 12 +++
 drivers/staging/ccree/ssi_pm.c   |  4 +--
 drivers/staging/ccree/ssi_request_mgr.c  | 57 
 drivers/staging/ccree/ssi_sysfs.c| 11 +++---
 9 files changed, 78 insertions(+), 166 deletions(-)
 delete mode 100644 drivers/staging/ccree/cc_hal.h
 delete mode 100644 drivers/staging/ccree/cc_regs.h
 delete mode 100644 drivers/staging/ccree/dx_reg_base_host.h

diff --git a/drivers/staging/ccree/cc_hal.h b/drivers/staging/ccree/cc_hal.h
deleted file mode 100644
index eecc866..000
--- a/drivers/staging/ccree/cc_hal.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2012-2017 ARM Limited or its affiliates.
- *
- * 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 .
- */
-
-/* pseudo cc_hal.h for cc7x_perf_test_driver (to be able to include code from
- * CC drivers).
- */
-
-#ifndef __CC_HAL_H__
-#define __CC_HAL_H__
-
-#include 
-
-#define READ_REGISTER(_addr) ioread32((_addr))
-#define WRITE_REGISTER(_addr, _data)  iowrite32((_data), (_addr))
-
-#define CC_HAL_WRITE_REGISTER(offset, val) \
-   WRITE_REGISTER(cc_base + (offset), val)
-#define CC_HAL_READ_REGISTER(offset) READ_REGISTER(cc_base + (offset))
-
-#endif
diff --git a/drivers/staging/ccree/cc_regs.h b/drivers/staging/ccree/cc_regs.h
deleted file mode 100644
index 2a8fc73..000
--- a/drivers/staging/ccree/cc_regs.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2012-2017 ARM Limited or its affiliates.
- *
- * 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 .
- */
-
-/*!
- * @file
- * @brief This file contains macro definitions for accessing ARM TrustZone
- *CryptoCell register space.
- */
-
-#ifndef _CC_REGS_H_
-#define _CC_REGS_H_
-
-#include 
-
-#define AXIM_MON_COMP_VALUE GENMASK(DX_AXIM_MON_COMP_VALUE_BIT_SIZE + \
-   DX_AXIM_MON_COMP_VALUE_BIT_SHIFT, \
-   DX_AXIM_MON_COMP_VALUE_BIT_SHIFT)
-
-/* Register name mangling macro */
-#define CC_REG(reg_name) DX_ ## reg_name ## _REG_OFFSET
-
-#endif /*_CC_REGS_H_*/
diff --git a/drivers/staging/ccree/dx_reg_base_host.h 
b/drivers/staging/ccree/dx_reg_base_host.h
deleted file mode 100644
index 47bbadb..000
--- a/drivers/staging/ccree/dx_reg_base_host.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2012-2017 ARM Limited or its affiliates.
- *
- * 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 .
- */
-
-#ifndef __DX_REG_BASE_HOST_H__
-#define __DX_REG_BASE_HOST_H__
-
-#define DX_BASE_CC 0x8000
-#define DX_BASE_HOST_RGF 0x0UL
-#define DX_BASE_CRY_KERNEL 0x0UL
-#define DX_BASE_ROM 0x4000
-
-#endif /*__DX_REG_BASE_HOST_H__*/
diff --git a/drivers/staging/ccree/ssi_driver.c 
b/drivers/staging/ccree/ssi_driver.c
index 1a9b9c9..1a3c481 100644
--- a/drivers/staging/ccree/ssi_driver.c
+++ b/drivers/staging/cc

[PATCH 2/3] staging: ccree: simplify registers access

2017-11-05 Thread Gilad Ben-Yossef
The register offset calculation macro was taking a HW block base
parameter that was not actually used. Simplify the whole thing
by dropping it and rename the macro for better readability.

Signed-off-by: Gilad Ben-Yossef 
---
 drivers/staging/ccree/cc_regs.h | 15 
 drivers/staging/ccree/ssi_driver.c  | 42 -
 drivers/staging/ccree/ssi_fips.c| 10 
 drivers/staging/ccree/ssi_pm.c  |  4 ++--
 drivers/staging/ccree/ssi_request_mgr.c | 33 +-
 drivers/staging/ccree/ssi_sysfs.c   | 10 
 6 files changed, 53 insertions(+), 61 deletions(-)

diff --git a/drivers/staging/ccree/cc_regs.h b/drivers/staging/ccree/cc_regs.h
index 4a893a6..2a8fc73 100644
--- a/drivers/staging/ccree/cc_regs.h
+++ b/drivers/staging/ccree/cc_regs.h
@@ -25,18 +25,11 @@
 
 #include 
 
-#define AXIM_MON_BASE_OFFSET CC_REG_OFFSET(CRY_KERNEL, AXIM_MON_COMP)
 #define AXIM_MON_COMP_VALUE GENMASK(DX_AXIM_MON_COMP_VALUE_BIT_SIZE + \
-   DX_AXIM_MON_COMP_VALUE_BIT_SHIFT, \
-   DX_AXIM_MON_COMP_VALUE_BIT_SHIFT)
+   DX_AXIM_MON_COMP_VALUE_BIT_SHIFT, \
+   DX_AXIM_MON_COMP_VALUE_BIT_SHIFT)
 
-#define AXIM_MON_BASE_OFFSET CC_REG_OFFSET(CRY_KERNEL, AXIM_MON_COMP)
-#define AXIM_MON_COMP_VALUE GENMASK(DX_AXIM_MON_COMP_VALUE_BIT_SIZE + \
-   DX_AXIM_MON_COMP_VALUE_BIT_SHIFT, \
-   DX_AXIM_MON_COMP_VALUE_BIT_SHIFT)
-
-/* Register Offset macro */
-#define CC_REG_OFFSET(unit_name, reg_name)   \
-   (DX_BASE_ ## unit_name + DX_ ## reg_name ## _REG_OFFSET)
+/* Register name mangling macro */
+#define CC_REG(reg_name) DX_ ## reg_name ## _REG_OFFSET
 
 #endif /*_CC_REGS_H_*/
diff --git a/drivers/staging/ccree/ssi_driver.c 
b/drivers/staging/ccree/ssi_driver.c
index 135a7e2..1a9b9c9 100644
--- a/drivers/staging/ccree/ssi_driver.c
+++ b/drivers/staging/ccree/ssi_driver.c
@@ -99,22 +99,22 @@ static irqreturn_t cc_isr(int irq, void *dev_id)
/* STAT_OP_TYPE_GENERIC STAT_PHASE_0: Interrupt */
 
/* read the interrupt status */
-   irr = CC_HAL_READ_REGISTER(CC_REG_OFFSET(HOST_RGF, HOST_IRR));
+   irr = CC_HAL_READ_REGISTER(CC_REG(HOST_IRR));
dev_dbg(dev, "Got IRR=0x%08X\n", irr);
if (unlikely(irr == 0)) { /* Probably shared interrupt line */
dev_err(dev, "Got interrupt with empty IRR\n");
return IRQ_NONE;
}
-   imr = CC_HAL_READ_REGISTER(CC_REG_OFFSET(HOST_RGF, HOST_IMR));
+   imr = CC_HAL_READ_REGISTER(CC_REG(HOST_IMR));
 
/* clear interrupt - must be before processing events */
-   CC_HAL_WRITE_REGISTER(CC_REG_OFFSET(HOST_RGF, HOST_ICR), irr);
+   CC_HAL_WRITE_REGISTER(CC_REG(HOST_ICR), irr);
 
drvdata->irq = irr;
/* Completion interrupt - most probable */
if (likely((irr & SSI_COMP_IRQ_MASK) != 0)) {
/* Mask AXI completion interrupt - will be unmasked in Deferred 
service handler */
-   CC_HAL_WRITE_REGISTER(CC_REG_OFFSET(HOST_RGF, HOST_IMR), imr | 
SSI_COMP_IRQ_MASK);
+   CC_HAL_WRITE_REGISTER(CC_REG(HOST_IMR), imr | 
SSI_COMP_IRQ_MASK);
irr &= ~SSI_COMP_IRQ_MASK;
complete_request(drvdata);
}
@@ -122,7 +122,7 @@ static irqreturn_t cc_isr(int irq, void *dev_id)
/* TEE FIPS interrupt */
if (likely((irr & SSI_GPR0_IRQ_MASK) != 0)) {
/* Mask interrupt - will be unmasked in Deferred service 
handler */
-   CC_HAL_WRITE_REGISTER(CC_REG_OFFSET(HOST_RGF, HOST_IMR), imr | 
SSI_GPR0_IRQ_MASK);
+   CC_HAL_WRITE_REGISTER(CC_REG(HOST_IMR), imr | 
SSI_GPR0_IRQ_MASK);
irr &= ~SSI_GPR0_IRQ_MASK;
fips_handler(drvdata);
}
@@ -132,7 +132,7 @@ static irqreturn_t cc_isr(int irq, void *dev_id)
u32 axi_err;
 
/* Read the AXI error ID */
-   axi_err = CC_HAL_READ_REGISTER(CC_REG_OFFSET(CRY_KERNEL, 
AXIM_MON_ERR));
+   axi_err = CC_HAL_READ_REGISTER(CC_REG(AXIM_MON_ERR));
dev_dbg(dev, "AXI completion error: axim_mon_err=0x%08X\n",
axi_err);
 
@@ -155,43 +155,43 @@ int init_cc_regs(struct ssi_drvdata *drvdata, bool 
is_probe)
struct device *dev = drvdata_to_dev(drvdata);
 
/* Unmask all AXI interrupt sources AXI_CFG1 register */
-   val = CC_HAL_READ_REGISTER(CC_REG_OFFSET(CRY_KERNEL, AXIM_CFG));
-   CC_HAL_WRITE_REGISTER(CC_REG_OFFSET(CRY_KERNEL, AXIM_CFG), val & 
~SSI_AXI_IRQ_MASK);
+   val = CC_HAL_READ_REGISTER(CC_REG(AXIM_CFG));
+   CC_HAL_WRITE_REGISTER(CC_REG(AXIM_CFG), val & ~SSI_AXI_IRQ_MASK);
dev_dbg(dev, "AXIM_CFG=0x%08X\n",
-   CC_HAL_READ_REGISTER(CC_REG_OFFSET(CRY_KERNEL, AXIM_CFG)));
+   CC_HAL_READ_REGISTER(CC_REG(AXIM_CFG)));
 
/* Clear all pending interrupts */
-   val = C

Re: [PATCH] rtc: omap: Support scratch registers

2017-11-05 Thread Sekhar Nori
+ linux omap list

On Tuesday 31 October 2017 09:57 PM, Alexandre Belloni wrote:
> Register an nvmem device to expose the 3 scratch registers (total of 12
> bytes) to both userspace and kernel space.
> 
> Signed-off-by: Alexandre Belloni 

Looks good to me.

Reviewed-by: Sekhar Nori 

Curious on what you are using these registers for.

Thanks,
Sekhar

> ---
>  drivers/rtc/rtc-omap.c | 45 +
>  1 file changed, 45 insertions(+)
> 
> diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
> index d56d937966dc..1d666ac9ef70 100644
> --- a/drivers/rtc/rtc-omap.c
> +++ b/drivers/rtc/rtc-omap.c
> @@ -70,6 +70,10 @@
>  #define OMAP_RTC_COMP_MSB_REG0x50
>  #define OMAP_RTC_OSC_REG 0x54
>  
> +#define OMAP_RTC_SCRATCH0_REG0x60
> +#define OMAP_RTC_SCRATCH1_REG0x64
> +#define OMAP_RTC_SCRATCH2_REG0x68
> +
>  #define OMAP_RTC_KICK0_REG   0x6c
>  #define OMAP_RTC_KICK1_REG   0x70
>  
> @@ -667,6 +671,45 @@ static struct pinctrl_desc rtc_pinctrl_desc = {
>   .owner = THIS_MODULE,
>  };
>  
> +static int omap_rtc_scratch_read(void *priv, unsigned int offset, void *_val,
> +  size_t bytes)
> +{
> + struct omap_rtc *rtc = priv;
> + u32 *val = _val;
> + int i;
> +
> + for (i = 0; i < bytes / 4; i++)
> + val[i] = rtc_readl(rtc,
> +OMAP_RTC_SCRATCH0_REG + offset + (i * 4));
> +
> + return 0;
> +}
> +
> +static int omap_rtc_scratch_write(void *priv, unsigned int offset, void 
> *_val,
> +   size_t bytes)
> +{
> + struct omap_rtc *rtc = priv;
> + u32 *val = _val;
> + int i;
> +
> + rtc->type->unlock(rtc);
> + for (i = 0; i < bytes / 4; i++)
> + rtc_writel(rtc,
> +OMAP_RTC_SCRATCH0_REG + offset + (i * 4), val[i]);
> + rtc->type->lock(rtc);
> +
> + return 0;
> +}
> +
> +static struct nvmem_config omap_rtc_nvmem_config = {
> + .name = "omap_rtc_scratch",
> + .word_size = 4,
> + .stride = 4,
> + .size = OMAP_RTC_KICK0_REG - OMAP_RTC_SCRATCH0_REG,
> + .reg_read = omap_rtc_scratch_read,
> + .reg_write = omap_rtc_scratch_write,
> +};
> +
>  static int omap_rtc_probe(struct platform_device *pdev)
>  {
>   struct omap_rtc *rtc;
> @@ -804,6 +847,8 @@ static int omap_rtc_probe(struct platform_device *pdev)
>   }
>  
>   rtc->rtc->ops = &omap_rtc_ops;
> + omap_rtc_nvmem_config.priv = rtc;
> + rtc->rtc->nvmem_config = &omap_rtc_nvmem_config;
>  
>   /* handle periodic and alarm irqs */
>   ret = devm_request_irq(&pdev->dev, rtc->irq_timer, rtc_irq, 0,
> -- 
> 2.15.0.rc2
> 



linux-next: build failure after merge of the akpm tree

2017-11-05 Thread Stephen Rothwell
Hi Andrew,

After merging the akpm tree, today's linux-next build (arm
multi_v7_defconfig) produced this warning:

lib/cpumask.c: In function 'cpumask_next_and':
lib/cpumask.c:39:9: error: implicit declaration of function 'find_next_and_bit' 
[-Werror=implicit-function-declaration]
  return find_next_and_bit(cpumask_bits(src1p), cpumask_bits(src2p),
 ^
cc1: some warnings being treated as errors

Introduced by commit

  1eae9bb7e6f2 ("lib: optimize cpumask_next_and()")

I have reverted that commit for today.

-- 
Cheers,
Stephen Rothwell


Crypto Fixes for 4.14

2017-11-05 Thread Herbert Xu
Hi Linus: 

This push fixes an unaligned panic in x86/sha-mb and a bug in ccm
that triggers with certain underlying implementations.


Please pull from

git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6.git linus


Andrey Ryabinin (2):
  crypto: x86/sha256-mb - fix panic due to unaligned access
  crypto: x86/sha1-mb - fix panic due to unaligned access

Romain Izard (1):
  crypto: ccm - preserve the IV buffer

 arch/x86/crypto/sha1-mb/sha1_mb_mgr_flush_avx2.S |   12 ++--
 arch/x86/crypto/sha256-mb/sha256_mb_mgr_flush_avx2.S |   12 ++--
 crypto/ccm.c |4 +++-
 3 files changed, 15 insertions(+), 13 deletions(-)

Thanks,
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


Re: [PATCH] lost path_put in perf_fill_ns_link_info

2017-11-05 Thread Vasily Averin
Dear Hari,
I did not found where your patch decreases mnt counter,
it seems for me you have lost path_put in perf_fill_ns_link_info().

Thank you,
Vasily Averin

On 2017-11-06 09:22, Vasily Averin wrote:
> Fixes: commit e422267322cd ("perf: Add PERF_RECORD_NAMESPACES to include 
> namespaces related info")
> Signed-off-by: Vasily Averin 
> ---
>  kernel/events/core.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 10cdb9c..ab5ac84 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -6756,6 +6756,7 @@ static void perf_fill_ns_link_info(struct 
> perf_ns_link_info *ns_link_info,
>   ns_inode = ns_path.dentry->d_inode;
>   ns_link_info->dev = new_encode_dev(ns_inode->i_sb->s_dev);
>   ns_link_info->ino = ns_inode->i_ino;
> + path_put(&ns_path);
>   }
>  }
>  
> 


Re: possible deadlock in generic_file_write_iter

2017-11-05 Thread Dmitry Vyukov
On Mon, Nov 6, 2017 at 6:29 AM, Al Viro  wrote:
> On Sun, Nov 05, 2017 at 02:25:00AM -0800, syzbot wrote:
>
>> loop0/2986 is trying to acquire lock:
>>  (&sb->s_type->i_mutex_key#9){}, at: [] inode_lock
>> include/linux/fs.h:712 [inline]
>>  (&sb->s_type->i_mutex_key#9){}, at: []
>> generic_file_write_iter+0xdc/0x7a0 mm/filemap.c:3151
>>
>> but now in release context of a crosslock acquired at the following:
>>  ((complete)&ret.event){+.+.}, at: []
>> submit_bio_wait+0x15e/0x200 block/bio.c:953
>>
>> which lock already depends on the new lock.
>
> Almost certainly a false positive...  lockdep can't tell ->i_rwsem of
> inode on filesystem that lives on /dev/loop0 and that of inode of
> the backing file of /dev/loop0.
>
> Try and put them on different filesystem types and see if you still
> can reproduce that.  We do have a partial ordering between the filesystems,
> namely "(parts of) hosting device of X live in a file on Y".  It's
> going to be acyclic, or you have a much worse problem.  And that's
> what really orders the things here.


Should we annotate these inodes with different lock types? Or use
nesting annotations?


[PATCH] lost path_put in perf_fill_ns_link_info

2017-11-05 Thread Vasily Averin
Fixes: commit e422267322cd ("perf: Add PERF_RECORD_NAMESPACES to include 
namespaces related info")
Signed-off-by: Vasily Averin 
---
 kernel/events/core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 10cdb9c..ab5ac84 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6756,6 +6756,7 @@ static void perf_fill_ns_link_info(struct 
perf_ns_link_info *ns_link_info,
ns_inode = ns_path.dentry->d_inode;
ns_link_info->dev = new_encode_dev(ns_inode->i_sb->s_dev);
ns_link_info->ino = ns_inode->i_ino;
+   path_put(&ns_path);
}
 }
 
-- 
2.7.4



Re: [PATCH 1/2] drivers: hwmon: Add W83773G driver

2017-11-05 Thread Lei YU
Hi Guenter,

Thanks a lot for the detailed review.

I will try to fix all the comments and send v2 patch.

On Sun, Nov 5, 2017 at 3:30 AM, Guenter Roeck  wrote:
> On 11/01/2017 11:33 PM, Lei YU wrote:
>>
>> Nuvoton W83773G is a hardware monitor IC providing one local
>> temperature and two remote temperature sensors.
>>
>
> I agree that a separate driver for this chip make sense.
> Some work to do, though. This is only an initial review; later versions
> will probably trigger additional feedback.
>
> Please provide a register dump for the chip so I can write a unit test.

The dump of registers:
```
# i2cdump -y 12 0x4c
No size specified (using byte-data access)
 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f0123456789abcdef
00: 1b 17 00 01 05 46 d8 46 d8 ff ff ff ff ff ff ff??.??F?F?...
10: 40 00 00 00 00 00 00 00 00 6e 6e 46 d8 00 00 ff@nnF?...
20: 55 0a ff ff 18 00 ff ff ff ff ff ff ff ff ff ffU?..?...
30: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
40: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
50: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
60: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
70: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
90: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
a0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 00
c0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
e0: 00 00 00 84 84 84 00 00 55 00 00 ff ff ff ff ff...???..U...
f0: 08 00 00 00 84 00 00 17 80 fc 17 83 18 ff 5c 11?...?..??.\?
```
>
>> Signed-off-by: Lei YU 
>> ---
>>   drivers/hwmon/Kconfig   |  11 ++
>>   drivers/hwmon/Makefile  |   1 +
>>   drivers/hwmon/w83773g.c | 276
>> 
>>   3 files changed, 288 insertions(+)
>>   create mode 100644 drivers/hwmon/w83773g.c
>>
>> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
>> index d654314..d148b70 100644
>> --- a/drivers/hwmon/Kconfig
>> +++ b/drivers/hwmon/Kconfig
>> @@ -1710,6 +1710,17 @@ config SENSORS_VT8231
>>   This driver can also be built as a module.  If so, the module
>>   will be called vt8231.
>>   +config SENSORS_W83773G
>> +   tristate "Nuvoton W83773G"
>> +   depends on I2C
>> +   select HWMON_VID
>
>
> Why ?
>
>
>> +   help
>> + If you say yes here you get support for the Nuvoton W83773G
>> hardware
>> + monitoring chip.
>> +
>> + This driver can also be built as a module.  If so, the module
>> + will be called w83773g.
>> +
>>   config SENSORS_W83781D
>> tristate "Winbond W83781D, W83782D, W83783S, Asus AS99127F"
>> depends on I2C
>> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
>> index c84d978..0649ad8 100644
>> --- a/drivers/hwmon/Makefile
>> +++ b/drivers/hwmon/Makefile
>> @@ -13,6 +13,7 @@ obj-$(CONFIG_SENSORS_ATK0110) += asus_atk0110.o
>>   # asb100, then w83781d go first, as they can override other drivers'
>> addresses.
>>   obj-$(CONFIG_SENSORS_ASB100)  += asb100.o
>>   obj-$(CONFIG_SENSORS_W83627HF)+= w83627hf.o
>> +obj-$(CONFIG_SENSORS_W83773G)  += w83773g.o
>>   obj-$(CONFIG_SENSORS_W83792D) += w83792d.o
>>   obj-$(CONFIG_SENSORS_W83793)  += w83793.o
>>   obj-$(CONFIG_SENSORS_W83795)  += w83795.o
>> diff --git a/drivers/hwmon/w83773g.c b/drivers/hwmon/w83773g.c
>> new file mode 100644
>> index 000..16d5fa0
>> --- /dev/null
>> +++ b/drivers/hwmon/w83773g.c
>> @@ -0,0 +1,276 @@
>> +/*
>> + * Copyright (C) 2017 IBM Corp.
>> + *
>
>
> This and the module author note below suggests that the driver was written
> by someone else, yet there is no credit. Do you have permission from IBM
> and from the author to publish this driver ?

Yes. I work for IBM. And this driver is originally written by
Nickolaus Gruendler
based on tmp421.c. He primary works on HW part and has not too much
knowledge about SW.
And I helped tweak the code to make it work. So I think the author
should be him.

Please be noted that I am also new comer for kernel development and really
appreciate your careful review and comments.

>
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License as published by
>> + * the Free Software Foundation; either version 2 of the License, or
>> + * (at your option) any later version.
>> + *
>
> extra comment line
>
>> + */
>> +
>> +/*
>> + * Driver for the Nuvoton W83773G SMBus temperature sensor IC.
>> + * Supported models: W83773G
>
>
> Double comment.
>
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include

[Patch v12 1/4] irqchip/qeic: move qeic driver from drivers/soc/fsl/qe

2017-11-05 Thread Zhao Qiang
move the driver from drivers/soc/fsl/qe to drivers/irqchip,
merge qe_ic.h and qe_ic.c into irq-qeic.c.

Signed-off-by: Zhao Qiang 
---
 MAINTAINERS|   6 ++
 drivers/irqchip/Makefile   |   1 +
 drivers/{soc/fsl/qe/qe_ic.c => irqchip/irq-qeic.c} |  95 ++-
 drivers/soc/fsl/qe/Makefile|   2 +-
 drivers/soc/fsl/qe/qe_ic.h | 103 -
 5 files changed, 100 insertions(+), 107 deletions(-)
 rename drivers/{soc/fsl/qe/qe_ic.c => irqchip/irq-qeic.c} (85%)
 delete mode 100644 drivers/soc/fsl/qe/qe_ic.h

diff --git a/MAINTAINERS b/MAINTAINERS
index af0cb69f6a3e..e872c84e4e37 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5553,6 +5553,12 @@ F:   drivers/soc/fsl/qe/
 F: include/soc/fsl/*qe*.h
 F: include/soc/fsl/*ucc*.h
 
+FREESCALE QEIC DRIVERS
+M: Qiang Zhao 
+L: linux-kernel@vger.kernel.org
+S: Maintained
+F: drivers/irqchip/irq-qeic.c
+
 FREESCALE QUICC ENGINE UCC ETHERNET DRIVER
 M: Li Yang 
 L: net...@vger.kernel.org
diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index 845abc107ad5..77aa4f55a54c 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -79,3 +79,4 @@ obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o 
irq-aspeed-i2c-ic.o
 obj-$(CONFIG_STM32_EXTI)   += irq-stm32-exti.o
 obj-$(CONFIG_QCOM_IRQ_COMBINER)+= qcom-irq-combiner.o
 obj-$(CONFIG_IRQ_UNIPHIER_AIDET)   += irq-uniphier-aidet.o
+obj-$(CONFIG_QUICC_ENGINE) += irq-qeic.o
diff --git a/drivers/soc/fsl/qe/qe_ic.c b/drivers/irqchip/irq-qeic.c
similarity index 85%
rename from drivers/soc/fsl/qe/qe_ic.c
rename to drivers/irqchip/irq-qeic.c
index ec2ca864b0c5..9b4660cf9267 100644
--- a/drivers/soc/fsl/qe/qe_ic.c
+++ b/drivers/irqchip/irq-qeic.c
@@ -1,7 +1,7 @@
 /*
- * arch/powerpc/sysdev/qe_lib/qe_ic.c
+ * drivers/irqchip/irq-qeic.c
  *
- * Copyright (C) 2006 Freescale Semiconductor, Inc.  All rights reserved.
+ * Copyright (C) 2016 Freescale Semiconductor, Inc.  All rights reserved.
  *
  * Author: Li Yang 
  * Based on code from Shlomi Gridish 
@@ -30,7 +30,96 @@
 #include 
 #include 
 
-#include "qe_ic.h"
+#define NR_QE_IC_INTS  64
+
+/* QE IC registers offset */
+#define QEIC_CICR  0x00
+#define QEIC_CIVEC 0x04
+#define QEIC_CRIPNR0x08
+#define QEIC_CIPNR 0x0c
+#define QEIC_CIPXCC0x10
+#define QEIC_CIPYCC0x14
+#define QEIC_CIPWCC0x18
+#define QEIC_CIPZCC0x1c
+#define QEIC_CIMR  0x20
+#define QEIC_CRIMR 0x24
+#define QEIC_CICNR 0x28
+#define QEIC_CIPRTA0x30
+#define QEIC_CIPRTB0x34
+#define QEIC_CRICR 0x3c
+#define QEIC_CHIVEC0x60
+
+/* Interrupt priority registers */
+#define CIPCC_SHIFT_PRI0   29
+#define CIPCC_SHIFT_PRI1   26
+#define CIPCC_SHIFT_PRI2   23
+#define CIPCC_SHIFT_PRI3   20
+#define CIPCC_SHIFT_PRI4   13
+#define CIPCC_SHIFT_PRI5   10
+#define CIPCC_SHIFT_PRI6   7
+#define CIPCC_SHIFT_PRI7   4
+
+/* CICR priority modes */
+#define CICR_GWCC  0x0004
+#define CICR_GXCC  0x0002
+#define CICR_GYCC  0x0001
+#define CICR_GZCC  0x0008
+#define CICR_GRTA  0x0020
+#define CICR_GRTB  0x0040
+#define CICR_HPIT_SHIFT8
+#define CICR_HPIT_MASK 0x0300
+#define CICR_HP_SHIFT  24
+#define CICR_HP_MASK   0x3f00
+
+/* CICNR */
+#define CICNR_WCC1T_SHIFT  20
+#define CICNR_ZCC1T_SHIFT  28
+#define CICNR_YCC1T_SHIFT  12
+#define CICNR_XCC1T_SHIFT  4
+
+/* CRICR */
+#define CRICR_RTA1T_SHIFT  20
+#define CRICR_RTB1T_SHIFT  28
+
+/* Signal indicator */
+#define SIGNAL_MASK3
+#define SIGNAL_HIGH2
+#define SIGNAL_LOW 0
+
+struct qe_ic {
+   /* Control registers offset */
+   u32 __iomem *regs;
+
+   /* The remapper for this QEIC */
+   struct irq_domain *irqhost;
+
+   /* The "linux" controller struct */
+   struct irq_chip hc_irq;
+
+   /* VIRQ numbers of QE high/low irqs */
+   unsigned int virq_high;
+   unsigned int virq_low;
+};
+
+/*
+ * QE interrupt controller internal structure
+ */
+struct qe_ic_info {
+   /* location of this source at the QIMR register. */
+   u32 mask;
+
+   /* Mask register offset */
+   u32 mask_reg;
+
+   /*
+* for grouped interrupts sources - the interrupt
+* code as appears at the group priority register
+*/
+   u8  pri_code;
+
+   /* Group priority register offset */
+   u32 pri_reg;
+};
 
 static DEFINE_RAW_SPINLOCK(qe_ic_lock);
 
diff --git a/drivers/soc/fsl/qe/Makefile b/drivers/soc/fsl/qe/Makefile
index 2031d385bc7e..51e472648bad 100644
--- a

[Patch v12 2/4] irqchip/qeic: merge qeic init code from platforms to a common function

2017-11-05 Thread Zhao Qiang
The codes of qe_ic init from a variety of platforms are redundant,
merge them to a common function and put it to irqchip/irq-qeic.c

For non-p1021_mds mpc85xx_mds boards, use "qe_ic_init(np, 0,
qe_ic_cascade_low_mpic, qe_ic_cascade_high_mpic);" instead of
"qe_ic_init(np, 0, qe_ic_cascade_muxed_mpic, NULL);".

qe_ic_cascade_muxed_mpic was used for boards has the same interrupt
number for low interrupt and high interrupt, qe_ic_init has checked
if "low interrupt == high interrupt"

Signed-off-by: Zhao Qiang 
---
 arch/powerpc/platforms/83xx/misc.c| 15 ---
 arch/powerpc/platforms/85xx/corenet_generic.c |  9 -
 arch/powerpc/platforms/85xx/mpc85xx_mds.c | 14 --
 arch/powerpc/platforms/85xx/mpc85xx_rdb.c | 16 
 arch/powerpc/platforms/85xx/twr_p102x.c   | 14 --
 drivers/irqchip/irq-qeic.c| 13 +
 6 files changed, 13 insertions(+), 68 deletions(-)

diff --git a/arch/powerpc/platforms/83xx/misc.c 
b/arch/powerpc/platforms/83xx/misc.c
index d75c9816a5c9..c09a13532c89 100644
--- a/arch/powerpc/platforms/83xx/misc.c
+++ b/arch/powerpc/platforms/83xx/misc.c
@@ -93,24 +93,9 @@ void __init mpc83xx_ipic_init_IRQ(void)
 }
 
 #ifdef CONFIG_QUICC_ENGINE
-void __init mpc83xx_qe_init_IRQ(void)
-{
-   struct device_node *np;
-
-   np = of_find_compatible_node(NULL, NULL, "fsl,qe-ic");
-   if (!np) {
-   np = of_find_node_by_type(NULL, "qeic");
-   if (!np)
-   return;
-   }
-   qe_ic_init(np, 0, qe_ic_cascade_low_ipic, qe_ic_cascade_high_ipic);
-   of_node_put(np);
-}
-
 void __init mpc83xx_ipic_and_qe_init_IRQ(void)
 {
mpc83xx_ipic_init_IRQ();
-   mpc83xx_qe_init_IRQ();
 }
 #endif /* CONFIG_QUICC_ENGINE */
 
diff --git a/arch/powerpc/platforms/85xx/corenet_generic.c 
b/arch/powerpc/platforms/85xx/corenet_generic.c
index ac191a7a1337..1b385acbf4dd 100644
--- a/arch/powerpc/platforms/85xx/corenet_generic.c
+++ b/arch/powerpc/platforms/85xx/corenet_generic.c
@@ -41,8 +41,6 @@ void __init corenet_gen_pic_init(void)
unsigned int flags = MPIC_BIG_ENDIAN | MPIC_SINGLE_DEST_CPU |
MPIC_NO_RESET;
 
-   struct device_node *np;
-
if (ppc_md.get_irq == mpic_get_coreint_irq)
flags |= MPIC_ENABLE_COREINT;
 
@@ -50,13 +48,6 @@ void __init corenet_gen_pic_init(void)
BUG_ON(mpic == NULL);
 
mpic_init(mpic);
-
-   np = of_find_compatible_node(NULL, NULL, "fsl,qe-ic");
-   if (np) {
-   qe_ic_init(np, 0, qe_ic_cascade_low_mpic,
-   qe_ic_cascade_high_mpic);
-   of_node_put(np);
-   }
 }
 
 /*
diff --git a/arch/powerpc/platforms/85xx/mpc85xx_mds.c 
b/arch/powerpc/platforms/85xx/mpc85xx_mds.c
index d7e440e6dba3..06f34a99152e 100644
--- a/arch/powerpc/platforms/85xx/mpc85xx_mds.c
+++ b/arch/powerpc/platforms/85xx/mpc85xx_mds.c
@@ -283,20 +283,6 @@ static void __init mpc85xx_mds_qeic_init(void)
of_node_put(np);
return;
}
-
-   np = of_find_compatible_node(NULL, NULL, "fsl,qe-ic");
-   if (!np) {
-   np = of_find_node_by_type(NULL, "qeic");
-   if (!np)
-   return;
-   }
-
-   if (machine_is(p1021_mds))
-   qe_ic_init(np, 0, qe_ic_cascade_low_mpic,
-   qe_ic_cascade_high_mpic);
-   else
-   qe_ic_init(np, 0, qe_ic_cascade_muxed_mpic, NULL);
-   of_node_put(np);
 }
 #else
 static void __init mpc85xx_mds_qe_init(void) { }
diff --git a/arch/powerpc/platforms/85xx/mpc85xx_rdb.c 
b/arch/powerpc/platforms/85xx/mpc85xx_rdb.c
index 10069503e39f..000d385933af 100644
--- a/arch/powerpc/platforms/85xx/mpc85xx_rdb.c
+++ b/arch/powerpc/platforms/85xx/mpc85xx_rdb.c
@@ -48,10 +48,6 @@ void __init mpc85xx_rdb_pic_init(void)
 {
struct mpic *mpic;
 
-#ifdef CONFIG_QUICC_ENGINE
-   struct device_node *np;
-#endif
-
if (of_machine_is_compatible("fsl,MPC85XXRDB-CAMP")) {
mpic = mpic_alloc(NULL, 0, MPIC_NO_RESET |
MPIC_BIG_ENDIAN |
@@ -66,18 +62,6 @@ void __init mpc85xx_rdb_pic_init(void)
 
BUG_ON(mpic == NULL);
mpic_init(mpic);
-
-#ifdef CONFIG_QUICC_ENGINE
-   np = of_find_compatible_node(NULL, NULL, "fsl,qe-ic");
-   if (np) {
-   qe_ic_init(np, 0, qe_ic_cascade_low_mpic,
-   qe_ic_cascade_high_mpic);
-   of_node_put(np);
-
-   } else
-   pr_err("%s: Could not find qe-ic node\n", __func__);
-#endif
-
 }
 
 /*
diff --git a/arch/powerpc/platforms/85xx/twr_p102x.c 
b/arch/powerpc/platforms/85xx/twr_p102x.c
index 360f6253e9ff..6be9b337035a 100644
--- a/arch/powerpc/platforms/85xx/twr_p102x.c
+++ b/arch/powerpc/platforms/85xx/twr_p102x.c
@@ -35,26 +35,12 @@ static void __init twr_p1025_pic_init(void)
 {
struct mpic *mpic;
 
-#ifdef CONFIG_Q

[Patch v12 4/4] irqchip/qeic: remove PPCisms for QEIC

2017-11-05 Thread Zhao Qiang
QEIC was supported on PowerPC, and dependent on PPC,
Now it is supported on other platforms, so remove PPCisms.

Signed-off-by: Zhao Qiang 
---
 arch/powerpc/platforms/83xx/km83xx.c  |   1 -
 arch/powerpc/platforms/83xx/misc.c|   1 -
 arch/powerpc/platforms/83xx/mpc832x_mds.c |   1 -
 arch/powerpc/platforms/83xx/mpc832x_rdb.c |   1 -
 arch/powerpc/platforms/83xx/mpc836x_mds.c |   1 -
 arch/powerpc/platforms/83xx/mpc836x_rdk.c |   1 -
 arch/powerpc/platforms/85xx/corenet_generic.c |   1 -
 arch/powerpc/platforms/85xx/mpc85xx_mds.c |   1 -
 arch/powerpc/platforms/85xx/mpc85xx_rdb.c |   1 -
 arch/powerpc/platforms/85xx/twr_p102x.c   |   1 -
 drivers/irqchip/irq-qeic.c| 188 +++---
 include/soc/fsl/qe/qe_ic.h| 132 --
 12 files changed, 80 insertions(+), 250 deletions(-)
 delete mode 100644 include/soc/fsl/qe/qe_ic.h

diff --git a/arch/powerpc/platforms/83xx/km83xx.c 
b/arch/powerpc/platforms/83xx/km83xx.c
index d8642a4afc74..b1cef0ac5507 100644
--- a/arch/powerpc/platforms/83xx/km83xx.c
+++ b/arch/powerpc/platforms/83xx/km83xx.c
@@ -38,7 +38,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include "mpc83xx.h"
 
diff --git a/arch/powerpc/platforms/83xx/misc.c 
b/arch/powerpc/platforms/83xx/misc.c
index c09a13532c89..07a0e6128ad2 100644
--- a/arch/powerpc/platforms/83xx/misc.c
+++ b/arch/powerpc/platforms/83xx/misc.c
@@ -17,7 +17,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 
diff --git a/arch/powerpc/platforms/83xx/mpc832x_mds.c 
b/arch/powerpc/platforms/83xx/mpc832x_mds.c
index bb7b25acf26f..a1cadf4a695b 100644
--- a/arch/powerpc/platforms/83xx/mpc832x_mds.c
+++ b/arch/powerpc/platforms/83xx/mpc832x_mds.c
@@ -37,7 +37,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include "mpc83xx.h"
 
diff --git a/arch/powerpc/platforms/83xx/mpc832x_rdb.c 
b/arch/powerpc/platforms/83xx/mpc832x_rdb.c
index a4539c5accb0..2fb1464a02a7 100644
--- a/arch/powerpc/platforms/83xx/mpc832x_rdb.c
+++ b/arch/powerpc/platforms/83xx/mpc832x_rdb.c
@@ -26,7 +26,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 
diff --git a/arch/powerpc/platforms/83xx/mpc836x_mds.c 
b/arch/powerpc/platforms/83xx/mpc836x_mds.c
index 4fc3051c2b2e..9234d635f5ca 100644
--- a/arch/powerpc/platforms/83xx/mpc836x_mds.c
+++ b/arch/powerpc/platforms/83xx/mpc836x_mds.c
@@ -45,7 +45,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include "mpc83xx.h"
 
diff --git a/arch/powerpc/platforms/83xx/mpc836x_rdk.c 
b/arch/powerpc/platforms/83xx/mpc836x_rdk.c
index 93f024fd9b45..82fa344a9125 100644
--- a/arch/powerpc/platforms/83xx/mpc836x_rdk.c
+++ b/arch/powerpc/platforms/83xx/mpc836x_rdk.c
@@ -21,7 +21,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 
diff --git a/arch/powerpc/platforms/85xx/corenet_generic.c 
b/arch/powerpc/platforms/85xx/corenet_generic.c
index 1b385acbf4dd..9ca27b1403ce 100644
--- a/arch/powerpc/platforms/85xx/corenet_generic.c
+++ b/arch/powerpc/platforms/85xx/corenet_generic.c
@@ -27,7 +27,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include 
 #include 
diff --git a/arch/powerpc/platforms/85xx/mpc85xx_mds.c 
b/arch/powerpc/platforms/85xx/mpc85xx_mds.c
index 06f34a99152e..8102e5f7cb98 100644
--- a/arch/powerpc/platforms/85xx/mpc85xx_mds.c
+++ b/arch/powerpc/platforms/85xx/mpc85xx_mds.c
@@ -49,7 +49,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include "smp.h"
diff --git a/arch/powerpc/platforms/85xx/mpc85xx_rdb.c 
b/arch/powerpc/platforms/85xx/mpc85xx_rdb.c
index 000d385933af..f806b6bbf3a3 100644
--- a/arch/powerpc/platforms/85xx/mpc85xx_rdb.c
+++ b/arch/powerpc/platforms/85xx/mpc85xx_rdb.c
@@ -27,7 +27,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include 
 #include 
diff --git a/arch/powerpc/platforms/85xx/twr_p102x.c 
b/arch/powerpc/platforms/85xx/twr_p102x.c
index 6be9b337035a..4f620f2f9f64 100644
--- a/arch/powerpc/platforms/85xx/twr_p102x.c
+++ b/arch/powerpc/platforms/85xx/twr_p102x.c
@@ -23,7 +23,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include 
 #include 
diff --git a/drivers/irqchip/irq-qeic.c b/drivers/irqchip/irq-qeic.c
index 465009911ce7..9fe961c535bd 100644
--- a/drivers/irqchip/irq-qeic.c
+++ b/drivers/irqchip/irq-qeic.c
@@ -18,8 +18,11 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -27,9 +30,8 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
-#include 
 
 #define NR_QE_IC_INTS  64
 
@@ -87,6 +89,43 @@
 #define SIGNAL_HIGH2
 #define SIGNAL_LOW 0
 
+#define NUM_OF_QE_IC_GROUPS6
+
+/* Flags when we init the QE IC */
+#define QE_IC_SPREADMODE_GRP_W 0x0001
+#define QE_IC_SPREADMODE_GRP_X 0x0002
+#define QE_IC_SPREADMODE_GRP_Y 0x0004
+#define QE_IC_SPREADMODE_GRP_Z 0x0008
+#d

[Patch v12 0/4] This patchset is to remove PPCisms for QEIC

2017-11-05 Thread Zhao Qiang
QEIC is an interrupt controller for QE, was put under drivers/soc/fsl/qe,
and now move to driver/irqchip.
And QEIC is supported more than just powerpc boards, so remove PPCisms.

changelog:
Changes for v8:
- use IRQCHIP_DECLARE() instead of subsys_initcall in qeic driver
- remove include/soc/fsl/qe/qe_ic.h
Changes for v9:
- rebase 
- fix the compile issue when apply the second patch, in fact, there was 
no compile issue 
  when apply all the patches of this patchset
Changes for v10:
- simplify codes, remove duplicated codes 
Changes for v11:
- rebase

Zhao Qiang (4):
  irqchip/qeic: move qeic driver from drivers/soc/fsl/qe
Changes for v2:
- modify the subject and commit msg
Changes for v3:
- merge .h file to .c, rename it with irq-qeic.c
Changes for v4:
- modify comments
Changes for v5:
- disable rename detection
Changes for v6:
- rebase
Changes for v7:
- na

  irqchip/qeic: merge qeic init code from platforms to a common function
Changes for v2:
- modify subject and commit msg
- add check for qeic by type
Changes for v3:
- na
Changes for v4:
- na
Changes for v5:
- na
Changes for v6:
- rebase
Changes for v7:
- na
Changes for v8:
- use IRQCHIP_DECLARE() instead of subsys_initcall

  irqchip/qeic: merge qeic_of_init into qe_ic_init
Changes for v2:
- modify subject and commit msg
- return 0 and add put node when return in qe_ic_init
Changes for v3:
- na
Changes for v4:
- na
Changes for v5:
- na
Changes for v6:
- rebase
Changes for v7:
- na
Changes for v12:
- remove unused code

  irqchip/qeic: remove PPCisms for QEIC
Changes for v6:
- new added
Changes for v7:
- fix warning
Changes for v8:
- remove include/soc/fsl/qe/qe_ic.h

Zhao Qiang (4):
  irqchip/qeic: move qeic driver from drivers/soc/fsl/qe
  irqchip/qeic: merge qeic init code from platforms to a common function
  irqchip/qeic: merge qeic_of_init into qe_ic_init
  irqchip/qeic: remove PPCisms for QEIC

 MAINTAINERS|   6 +
 arch/powerpc/platforms/83xx/km83xx.c   |   1 -
 arch/powerpc/platforms/83xx/misc.c |  16 -
 arch/powerpc/platforms/83xx/mpc832x_mds.c  |   1 -
 arch/powerpc/platforms/83xx/mpc832x_rdb.c  |   1 -
 arch/powerpc/platforms/83xx/mpc836x_mds.c  |   1 -
 arch/powerpc/platforms/83xx/mpc836x_rdk.c  |   1 -
 arch/powerpc/platforms/85xx/corenet_generic.c  |  10 -
 arch/powerpc/platforms/85xx/mpc85xx_mds.c  |  15 -
 arch/powerpc/platforms/85xx/mpc85xx_rdb.c  |  17 -
 arch/powerpc/platforms/85xx/twr_p102x.c|  15 -
 drivers/irqchip/Makefile   |   1 +
 drivers/{soc/fsl/qe/qe_ic.c => irqchip/irq-qeic.c} | 377 +++--
 drivers/soc/fsl/qe/Makefile|   2 +-
 drivers/soc/fsl/qe/qe_ic.h | 103 --
 include/soc/fsl/qe/qe_ic.h | 139 
 16 files changed, 208 insertions(+), 498 deletions(-)
 rename drivers/{soc/fsl/qe/qe_ic.c => irqchip/irq-qeic.c} (56%)
 delete mode 100644 drivers/soc/fsl/qe/qe_ic.h
 delete mode 100644 include/soc/fsl/qe/qe_ic.h

-- 
2.14.1



[Patch v12 3/4] irqchip/qeic: merge qeic_of_init into qe_ic_init

2017-11-05 Thread Zhao Qiang
qeic_of_init just get device_node of qeic from dtb and call qe_ic_init,
pass the device_node to qe_ic_init.
So merge qeic_of_init into qe_ic_init to get the qeic node in
qe_ic_init.

Signed-off-by: Zhao Qiang 
---
 drivers/irqchip/irq-qeic.c | 109 -
 include/soc/fsl/qe/qe_ic.h |   7 ---
 2 files changed, 29 insertions(+), 87 deletions(-)

diff --git a/drivers/irqchip/irq-qeic.c b/drivers/irqchip/irq-qeic.c
index 8287c22d954a..465009911ce7 100644
--- a/drivers/irqchip/irq-qeic.c
+++ b/drivers/irqchip/irq-qeic.c
@@ -407,27 +407,29 @@ unsigned int qe_ic_get_high_irq(struct qe_ic *qe_ic)
return irq_linear_revmap(qe_ic->irqhost, irq);
 }
 
-void __init qe_ic_init(struct device_node *node, unsigned int flags,
-  void (*low_handler)(struct irq_desc *desc),
-  void (*high_handler)(struct irq_desc *desc))
+static int __init qe_ic_init(struct device_node *node, struct device_node 
*parent)
 {
struct qe_ic *qe_ic;
struct resource res;
-   u32 temp = 0, ret, high_active = 0;
+   int ret = 0;
 
ret = of_address_to_resource(node, 0, &res);
-   if (ret)
-   return;
+   if (ret) {
+   ret = -ENODEV;
+   goto err_put_node;
+   }
 
qe_ic = kzalloc(sizeof(*qe_ic), GFP_KERNEL);
-   if (qe_ic == NULL)
-   return;
+   if (qe_ic == NULL) {
+   ret = -ENOMEM;
+   goto err_put_node;
+   }
 
qe_ic->irqhost = irq_domain_add_linear(node, NR_QE_IC_INTS,
   &qe_ic_host_ops, qe_ic);
if (qe_ic->irqhost == NULL) {
-   kfree(qe_ic);
-   return;
+   ret = -ENOMEM;
+   goto err_free_qe_ic;
}
 
qe_ic->regs = ioremap(res.start, resource_size(&res));
@@ -438,42 +440,30 @@ void __init qe_ic_init(struct device_node *node, unsigned 
int flags,
qe_ic->virq_low = irq_of_parse_and_map(node, 1);
 
if (qe_ic->virq_low == NO_IRQ) {
-   printk(KERN_ERR "Failed to map QE_IC low IRQ\n");
-   kfree(qe_ic);
-   return;
-   }
-
-   /* default priority scheme is grouped. If spread mode is*/
-   /* required, configure cicr accordingly.*/
-   if (flags & QE_IC_SPREADMODE_GRP_W)
-   temp |= CICR_GWCC;
-   if (flags & QE_IC_SPREADMODE_GRP_X)
-   temp |= CICR_GXCC;
-   if (flags & QE_IC_SPREADMODE_GRP_Y)
-   temp |= CICR_GYCC;
-   if (flags & QE_IC_SPREADMODE_GRP_Z)
-   temp |= CICR_GZCC;
-   if (flags & QE_IC_SPREADMODE_GRP_RISCA)
-   temp |= CICR_GRTA;
-   if (flags & QE_IC_SPREADMODE_GRP_RISCB)
-   temp |= CICR_GRTB;
-
-   /* choose destination signal for highest priority interrupt */
-   if (flags & QE_IC_HIGH_SIGNAL) {
-   temp |= (SIGNAL_HIGH << CICR_HPIT_SHIFT);
-   high_active = 1;
+   pr_err("Failed to map QE_IC low IRQ\n");
+   ret = -ENOMEM;
+   goto err_domain_remove;
}
 
-   qe_ic_write(qe_ic->regs, QEIC_CICR, temp);
-
irq_set_handler_data(qe_ic->virq_low, qe_ic);
-   irq_set_chained_handler(qe_ic->virq_low, low_handler);
+   irq_set_chained_handler(qe_ic->virq_low, qe_ic_cascade_low_mpic);
 
if (qe_ic->virq_high != NO_IRQ &&
qe_ic->virq_high != qe_ic->virq_low) {
irq_set_handler_data(qe_ic->virq_high, qe_ic);
-   irq_set_chained_handler(qe_ic->virq_high, high_handler);
+   irq_set_chained_handler(qe_ic->virq_high,
+   qe_ic_cascade_high_mpic);
}
+   of_node_put(node);
+   return 0;
+
+err_domain_remove:
+   irq_domain_remove(qe_ic->irqhost);
+err_free_qe_ic:
+   kfree(qe_ic);
+err_put_node:
+   of_node_put(node);
+   return ret;
 }
 
 void qe_ic_set_highest_priority(unsigned int virq, int high)
@@ -570,45 +560,4 @@ int qe_ic_set_high_priority(unsigned int virq, unsigned 
int priority, int high)
return 0;
 }
 
-static struct bus_type qe_ic_subsys = {
-   .name = "qe_ic",
-   .dev_name = "qe_ic",
-};
-
-static struct device device_qe_ic = {
-   .id = 0,
-   .bus = &qe_ic_subsys,
-};
-
-static int __init init_qe_ic_sysfs(void)
-{
-   int rc;
-
-   printk(KERN_DEBUG "Registering qe_ic with sysfs...\n");
-
-   rc = subsys_system_register(&qe_ic_subsys, NULL);
-   if (rc) {
-   printk(KERN_ERR "Failed registering qe_ic sys class\n");
-   return -ENODEV;
-   }
-   rc = device_register(&device_qe_ic);
-   if (rc) {
-   printk(KERN_ERR "Failed registering qe_ic sys device\n");
-   return -ENODEV;
-   }
-   return 0;
-}
-
-static int __init qeic_of_init(struct device_node *node,
-  

Re: [PATCH] Documentation, fix module-signing file reference.

2017-11-05 Thread Rakib Mullick
Ping! Anyone care to take this trivial fix?

On Tue, Oct 31, 2017 at 8:39 PM, Rakib Mullick  wrote:
> Kconfig reference for module-signing.txt file needs to
> be replaced with admin-guide/module-signing.rst.
>
> Signed-off-by: Rakib Mullick 
> ---
>  init/Kconfig | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/init/Kconfig b/init/Kconfig
> index 3c1faaa..1b5e786 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -1752,7 +1752,7 @@ config MODULE_SIG
> help
>   Check modules for valid signatures upon load: the signature
>   is simply appended to the module. For more information see
> - Documentation/module-signing.txt.
> + Documentation/admin-guide/module-signing.rst.
>
>   Note that this option adds the OpenSSL development packages as a
>   kernel build dependency so that the signing tool can use its crypto
> --
> 2.9.3
>


Re: linux-next: build failure after merge of the crypto tree

2017-11-05 Thread Herbert Xu
On Mon, Nov 06, 2017 at 11:25:21AM +1100, Stephen Rothwell wrote:
> Hi Herbert,
> 
> After merging the crypto tree, today's linux-next build (arm
> multi_v7_defconfig) failed like this:
> 
> drivers/crypto/marvell/marvell-cesa: struct platform_device_id is 24 bytes.  
> The last of 1 is:
> 0x6d 0x76 0x5f 0x63 0x72 0x79 0x70 0x74 0x6f 0x00 0x00 0x00 0x00 0x00 0x00 
> 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
> FATAL: drivers/crypto/marvell/marvell-cesa: struct platform_device_id is not 
> terminated with a NULL entry!
> 
> Caused by commit
> 
>   7b0c3d693ce6 ("crypto: marvell - Add a platform_device_id table")
> 
> I have used the crypto tree from next-20171103 for today.

Thanks Stephen.  I've got a patch that should fix this.

Cheers,
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


linux-next: manual merge of the akpm-current tree with the arm64 tree

2017-11-05 Thread Stephen Rothwell
Hi Andrew,

Today's linux-next merge of the akpm-current tree got a conflict in:

  include/uapi/linux/prctl.h

between commit:

  7582e22038a2 ("arm64/sve: Backend logic for setting the vector length")
  2d2123bc7c7f ("arm64/sve: Add prctl controls for userspace vector length 
management")

from the arm64 tree and commit:

  4391ebaac0d6 ("prctl: add PR_[GS]ET_PDEATHSIG_PROC")

from the akpm-current tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc include/uapi/linux/prctl.h
index af5f8c2df87a,5e7068e45126..
--- a/include/uapi/linux/prctl.h
+++ b/include/uapi/linux/prctl.h
@@@ -198,13 -198,8 +198,17 @@@ struct prctl_mm_map 
  # define PR_CAP_AMBIENT_LOWER 3
  # define PR_CAP_AMBIENT_CLEAR_ALL 4
  
+ /* Process-based variant of PDEATHSIG */
+ #define PR_SET_PDEATHSIG_PROC 48
+ #define PR_GET_PDEATHSIG_PROC 49
+ 
 +/* arm64 Scalable Vector Extension controls */
 +/* Flag values must be kept in sync with ptrace NT_ARM_SVE interface */
 +#define PR_SVE_SET_VL 50  /* set task vector length */
 +# define PR_SVE_SET_VL_ONEXEC (1 << 18) /* defer effect until exec */
 +#define PR_SVE_GET_VL 51  /* get task vector length */
 +/* Bits common to PR_SVE_SET_VL and PR_SVE_GET_VL */
 +# define PR_SVE_VL_LEN_MASK   0x
 +# define PR_SVE_VL_INHERIT(1 << 17) /* inherit across exec */
 +
  #endif /* _LINUX_PRCTL_H */


[RESEND PATCH] PM / devfreq: Propagate error from devfreq_add_device()

2017-11-05 Thread Bjorn Andersson
Propagate the error of devfreq_add_device() in devm_devfreq_add_device()
rather than statically returning ENOMEM. This makes it slightly faster
to pinpoint the cause of a returned error.

Fixes: 8cd84092d35e ("PM / devfreq: Add resource-managed function for devfreq 
device")
Cc: sta...@vger.kernel.org
Acked-by: Chanwoo Choi 
Signed-off-by: Bjorn Andersson 
---

Resending with Chanwoo's ack, Fixes and Cc stable

 drivers/devfreq/devfreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index 78fb496ecb4e..99c4021fc33b 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -737,7 +737,7 @@ struct devfreq *devm_devfreq_add_device(struct device *dev,
devfreq = devfreq_add_device(dev, profile, governor_name, data);
if (IS_ERR(devfreq)) {
devres_free(ptr);
-   return ERR_PTR(-ENOMEM);
+   return devfreq;
}
 
*ptr = devfreq;
-- 
2.12.0



[PATCH 0001/0001] format idle IP output func+offset/length

2017-11-05 Thread Liu, Changcheng
kaslr feature is enabled in kernel.
Remove kernel text address when dumping idle IP info

Signed-off-by: Liu Changcheng 
Signed-off-by: Jerry Liu 

diff --git a/lib/nmi_backtrace.c b/lib/nmi_backtrace.c
index 0bc0a35..9cc4178 100644
--- a/lib/nmi_backtrace.c
+++ b/lib/nmi_backtrace.c
@@ -92,7 +92,7 @@ bool nmi_cpu_backtrace(struct pt_regs *regs)
if (cpumask_test_cpu(cpu, to_cpumask(backtrace_mask))) {
arch_spin_lock(&lock);
if (regs && cpu_in_idle(instruction_pointer(regs))) {
-   pr_warn("NMI backtrace for cpu %d skipped: idling at pc 
%#lx\n",
+   pr_warn("NMI backtrace for cpu %d skipped: idling at pc 
%pS\n",
cpu, instruction_pointer(regs));
} else {
pr_warn("NMI backtrace for cpu %d\n", cpu);
-- 
2.7.4



[PATCH v3] scripts: add leaking_addresses.pl

2017-11-05 Thread Tobin C. Harding
Currently we are leaking addresses from the kernel to user space. This
script is an attempt to find some of those leakages. Script parses
`dmesg` output and /proc and /sys files for hex strings that look like
kernel addresses.

Only works for 64 bit kernels, the reason being that kernel addresses
on 64 bit kernels have '' as the leading bit pattern making greping
possible. On 32 kernels we don't have this luxury.

Scripts is _slightly_ smarter than a straight grep, we check for false
positives (all 0's or all 1's, and vsyscall start/finish addresses).

Signed-off-by: Tobin C. Harding 
---

v3:
 - Iterate matches to check for results instead of matching input line against
   false positives i.e catch lines that contain results as well as false
   positives. 

v2:
 - Add regex's to prevent false positives.
 - Clean up white space.

 MAINTAINERS  |   5 +
 scripts/leaking_addresses.pl | 306 +++
 2 files changed, 311 insertions(+)
 create mode 100755 scripts/leaking_addresses.pl

diff --git a/MAINTAINERS b/MAINTAINERS
index e652a3e2929d..c1ad6d133a57 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7745,6 +7745,11 @@ S:   Maintained
 F: Documentation/scsi/53c700.txt
 F: drivers/scsi/53c700*
 
+LEAKING_ADDRESSES
+M: Tobin C. Harding 
+S: Maintained
+F: scripts/leaking_addresses.pl
+
 LED SUBSYSTEM
 M: Richard Purdie 
 M: Jacek Anaszewski 
diff --git a/scripts/leaking_addresses.pl b/scripts/leaking_addresses.pl
new file mode 100755
index ..1487a75cfc52
--- /dev/null
+++ b/scripts/leaking_addresses.pl
@@ -0,0 +1,306 @@
+#!/usr/bin/env perl
+#
+# (c) 2017 Tobin C. Harding 
+# Licensed under the terms of the GNU GPL License version 2
+#
+# leaking_addresses.pl: Scan 64 bit kernel for potential leaking addresses.
+#  - Scans dmesg output.
+#  - Walks directory tree and parses each file (for each directory in @DIRS).
+#
+# You can configure the behaviour of the script;
+#
+#  - By adding paths, for directories you do not want to walk;
+# absolute paths: @skip_walk_dirs_abs
+# directory names: @skip_walk_dirs_any
+#
+#  - By adding paths, for files you do not want to parse;
+# absolute paths: @skip_parse_files_abs
+# file names: @skip_parse_files_any
+#
+# The use of @skip_xxx_xxx_any causes files to be skipped where ever they 
occur.
+# For example adding 'fd' to @skip_walk_dirs_any causes the fd/ directory to be
+# skipped for all PID sub-directories of /proc
+#
+# The same thing can be achieved by passing command line options to --dont-walk
+# and --dont-parse. If absolute paths are supplied to these options they are
+# appended to the @skip_xxx_xxx_abs arrays. If file names are supplied to these
+# options, they are appended to the @skip_xxx_xxx_any arrays.
+#
+# Use --debug to output path before parsing, this is useful to find files that
+# cause the script to choke.
+#
+# You may like to set kptr_restrict=2 before running script
+# (see Documentation/sysctl/kernel.txt).
+
+use warnings;
+use strict;
+use POSIX;
+use File::Basename;
+use File::Spec;
+use Cwd 'abs_path';
+use Term::ANSIColor qw(:constants);
+use Getopt::Long qw(:config no_auto_abbrev);
+
+my $P = $0;
+my $V = '0.01';
+
+# Directories to scan.
+my @DIRS = ('/proc', '/sys');
+
+# Command line options.
+my $help = 0;
+my $debug = 0;
+my @dont_walk = ();
+my @dont_parse = ();
+
+# Do not parse these files (absolute path).
+my @skip_parse_files_abs = ('/proc/kmsg',
+   '/proc/kcore',
+   '/proc/fs/ext4/sdb1/mb_groups',
+   '/proc/1/fd/3',
+   '/sys/kernel/debug/tracing/trace_pipe',
+   '/sys/kernel/security/apparmor/revision');
+
+# Do not parse thes files under any subdirectory.
+my @skip_parse_files_any = ('0',
+   '1',
+   '2',
+   'pagemap',
+   'events',
+   'access',
+   'registers',
+   'snapshot_raw',
+   'trace_pipe_raw',
+   'ptmx',
+   'trace_pipe');
+
+# Do not walk these directories (absolute path).
+my @skip_walk_dirs_abs = ();
+
+# Do not walk these directories under any subdirectory.
+my @skip_walk_dirs_any = ('self',
+ 'thread-self',
+ 'cwd',
+ 'fd',
+ 'stderr',
+ 'stdin',
+ 'stdout');
+
+sub help
+{
+   my ($exitcode) = @_;
+
+   print << "EOM";
+Usage: $P [OPTIONS]
+Version: $V
+
+Options:
+
+   --dont-walk=  Don't walk tree starting at .
+   --dont-parse=Don't parse .
+   -d, --debugDisplay debugging output.
+   -h, --help, --version  Display this help and exit.
+
+If an a

Re: [RFC PATCH] bpf: Add helpers to read useful task_struct members

2017-11-05 Thread Sandipan Das
Hi Alexei, Naveen,

On 11/04/2017 11:01 PM, Naveen N. Rao wrote:
> 
> I think the offsets described in dwarf were incorrect with 
> CONFIG_GCC_PLUGIN_RANDSTRUCT, but I'll let Sandipan confirm that.
> 

I think that the offsets described in dwarf are probably incorrect when
CONFIG_GCC_PLUGIN_RANDSTRUCT is enabled. To verify this, I used perf
to attach a probe to try_to_wake_up() which is the also the function to
which waker() is attached in the previously mentioned kernel sample. So,
if the run the following:

# perf probe "try_to_wake_up" "p->pid"
# perf record -a -e probe:try_to_wake_up
# perf script

The value of p->pid is reported as 0. Similarly, if I try to read
p->comm, it is reported to be an empty string. The same problem is
seen with systemtap as well.

Also, if I do a printk with offsetof(struct task_struct, pid) and
offsetof(struct task_struct, comm) inside the kernel code and then
compare the values with the offsets reported by pahole, they are
completely different.

- Sandipan



Re: [PATCH v4 06/37] ring-buffer: Redefine the unimplemented RINGBUF_TYPE_TIME_STAMP

2017-11-05 Thread Namhyung Kim
Hi Tom,

On Mon, Oct 30, 2017 at 03:51:48PM -0500, Tom Zanussi wrote:
> RINGBUF_TYPE_TIME_STAMP is defined but not used, and from what I can
> gather was reserved for something like an absolute timestamp feature
> for the ring buffer, if not a complete replacement of the current
> time_delta scheme.
> 
> This code redefines RINGBUF_TYPE_TIME_STAMP to implement absolute time
> stamps.  Another way to look at it is that it essentially forces
> extended time_deltas for all events.
> 
> The motivation for doing this is to enable time_deltas that aren't
> dependent on previous events in the ring buffer, making it feasible to
> use the ring_buffer_event timetamps in a more random-access way, for
> purposes other than serial event printing.
> 
> To set/reset this mode, use tracing_set_timestamp_abs() from the
> previous interface patch.
> 
> Signed-off-by: Tom Zanussi 
> ---

[SNIP]
> @@ -2220,13 +2246,16 @@ static void rb_inc_iter(struct ring_buffer_iter *iter)
>  }
>  
>  /* Slow path, do not inline */
> -static noinline struct ring_buffer_event *
> +static struct noinline ring_buffer_event *

struct noinline?  Looks like a mistake..

Thanks,
Namhyung


> -rb_add_time_stamp(struct ring_buffer_event *event, u64 delta)
> +rb_add_time_stamp(struct ring_buffer_event *event, u64 delta, bool abs)
>  {
> - event->type_len = RINGBUF_TYPE_TIME_EXTEND;
> + if (abs)
> + event->type_len = RINGBUF_TYPE_TIME_STAMP;
> + else
> + event->type_len = RINGBUF_TYPE_TIME_EXTEND;
>  
> - /* Not the first event on the page? */
> - if (rb_event_index(event)) {
> + /* Not the first event on the page, or not delta? */
> + if (abs || rb_event_index(event)) {
>   event->time_delta = delta & TS_MASK;
>   event->array[0] = delta >> TS_SHIFT;
>   } else {


Re: [PATCH 3.10 021/139] MIPS: Send SIGILL for BPOSGE32 in `__compute_return_epc_for_insn'

2017-11-05 Thread Willy Tarreau
Hi Huacai,

On Mon, Nov 06, 2017 at 12:41:48PM +0800, Huacai Chen wrote:
> Hi, Willy,
> 
> Does these two patches really needed for 3.10? They are marked for 4.4 and 
> 4.6.
> 
> ext4: avoid deadlock when expanding inode size
> 
> ext4: in ext4_seek_{hole,data}, return -ENXIO for negative offsets

Ted provided stable backports of these patches for older kernels back
to 3.18, thus I understood that they were valid before 4.4/4.6.

Regards,
Willy


Re: [PATCH v4] pci: dwc: dra7xx: Add shutdown handler to cleanly turn off clocks

2017-11-05 Thread Keerthy


On Friday 03 November 2017 08:00 PM, Niklas Cassel wrote:
> dra7xx_pcie_shutdown should be static.
> 
> This patch introduces a new sparse warning.

Thanks Niklas for reporting.

Bjorn,

Should i send a next version or just a fix patch on top of this?

Regards,
Keerthy

> 
> On Wed, Oct 11, 2017 at 9:32 PM, Bjorn Helgaas  wrote:
>> On Wed, Sep 20, 2017 at 10:54:15AM +0530, Keerthy wrote:
>>> Add shutdown handler to cleanly turn off clocks. This will help
>>> in cases of kexec where in a new kernel can boot abruptly.
>>>
>>> Signed-off-by: Keerthy 
>>> Acked-by: Kishon Vijay Abraham I 
>>
>> Applied to pci/host-dra7xx for v4.15, thanks!
>>
>>> ---
>>>
>>> Changes in v4:
>>>
>>>   * Added the missing changes from v2!
>>>
>>> Changes in v3:
>>>
>>>   * Pushed the function outside #ifdef CONFIG_PM_SLEEP.
>>>   * Added more details to commit log.
>>>
>>> Changes in v2:
>>>
>>>   * used a local dev pointer instead of dereferencing dev at multiple 
>>> places.
>>>   * dra7xx_pcie_stop_link before disabling clks in the shutdown path.
>>>
>>>  drivers/pci/dwc/pci-dra7xx.c | 17 +
>>>  1 file changed, 17 insertions(+)
>>>
>>> diff --git a/drivers/pci/dwc/pci-dra7xx.c b/drivers/pci/dwc/pci-dra7xx.c
>>> index 34427a6..d084800 100644
>>> --- a/drivers/pci/dwc/pci-dra7xx.c
>>> +++ b/drivers/pci/dwc/pci-dra7xx.c
>>> @@ -794,6 +794,22 @@ static int dra7xx_pcie_resume_noirq(struct device *dev)
>>>  }
>>>  #endif
>>>
>>> +void dra7xx_pcie_shutdown(struct platform_device *pdev)
>>> +{
>>> + struct device *dev = &pdev->dev;
>>> + struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
>>> + int ret;
>>> +
>>> + dra7xx_pcie_stop_link(dra7xx->pci);
>>> +
>>> + ret = pm_runtime_put_sync(dev);
>>> + if (ret < 0)
>>> + dev_dbg(dev, "pm_runtime_put_sync failed\n");
>>> +
>>> + pm_runtime_disable(dev);
>>> + dra7xx_pcie_disable_phy(dra7xx);
>>> +}
>>> +
>>>  static const struct dev_pm_ops dra7xx_pcie_pm_ops = {
>>>   SET_SYSTEM_SLEEP_PM_OPS(dra7xx_pcie_suspend, dra7xx_pcie_resume)
>>>   SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(dra7xx_pcie_suspend_noirq,
>>> @@ -807,5 +823,6 @@ static int dra7xx_pcie_resume_noirq(struct device *dev)
>>>   .suppress_bind_attrs = true,
>>>   .pm = &dra7xx_pcie_pm_ops,
>>>   },
>>> + .shutdown = dra7xx_pcie_shutdown,
>>>  };
>>>  builtin_platform_driver_probe(dra7xx_pcie_driver, dra7xx_pcie_probe);
>>> --
>>> 1.9.1
>>>


RE: [PATCH v2] scsi: be2iscsi: Use kasprintf

2017-11-05 Thread Jitendra Bhivare
> -Original Message-
> From: Himanshu Jha [mailto:himanshujha199...@gmail.com]
> Sent: Wednesday, October 11, 2017 9:06 PM
> To: j...@linux.vnet.ibm.com
> Cc: martin.peter...@oracle.com; linux-s...@vger.kernel.org; linux-
> ker...@vger.kernel.org; subbu.seethara...@broadcom.com;
> ketan.muka...@broadcom.com; jitendra.bhiv...@broadcom.com;
> Himanshu Jha 
> Subject: [PATCH v2] scsi: be2iscsi: Use kasprintf
>
> Use kasprintf instead of combination of kmalloc and sprintf.
> Also, remove BEISCSI_MSI_NAME macro used to specify size of string as
> kasprintf handles size computations.
>
> Signed-off-by: Himanshu Jha 
> ---
> v2:
>-remove the unnecessary macro BEISCSI_MSI_NAME.
>
>  drivers/scsi/be2iscsi/be_main.c | 12 +---
> drivers/scsi/be2iscsi/be_main.h |  2 --
>  2 files changed, 5 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/scsi/be2iscsi/be_main.c
b/drivers/scsi/be2iscsi/be_main.c
> index b4542e7..6a9ee0e 100644
> --- a/drivers/scsi/be2iscsi/be_main.c
> +++ b/drivers/scsi/be2iscsi/be_main.c
> @@ -803,15 +803,14 @@ static int beiscsi_init_irqs(struct beiscsi_hba
*phba)
>
>   if (pcidev->msix_enabled) {
>   for (i = 0; i < phba->num_cpus; i++) {
> - phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME,
> - GFP_KERNEL);
> + phba->msi_name[i] = kasprintf(GFP_KERNEL,
> +   "beiscsi_%02x_%02x",
> +
phba->shost->host_no, i);
>   if (!phba->msi_name[i]) {
>   ret = -ENOMEM;
>   goto free_msix_irqs;
>   }
>
> - sprintf(phba->msi_name[i], "beiscsi_%02x_%02x",
> - phba->shost->host_no, i);
>   ret = request_irq(pci_irq_vector(pcidev, i),
> be_isr_msix, 0,
phba->msi_name[i],
> &phwi_context->be_eq[i]);
> @@ -824,13 +823,12 @@ static int beiscsi_init_irqs(struct beiscsi_hba
*phba)
>   goto free_msix_irqs;
>   }
>   }
> - phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME,
> GFP_KERNEL);
> + phba->msi_name[i] = kasprintf(GFP_KERNEL,
> "beiscsi_mcc_%02x",
> +   phba->shost->host_no);
>   if (!phba->msi_name[i]) {
>   ret = -ENOMEM;
>   goto free_msix_irqs;
>   }
> - sprintf(phba->msi_name[i], "beiscsi_mcc_%02x",
> - phba->shost->host_no);
>   ret = request_irq(pci_irq_vector(pcidev, i), be_isr_mcc,
0,
> phba->msi_name[i], &phwi_context-
> >be_eq[i]);
>   if (ret) {
> diff --git a/drivers/scsi/be2iscsi/be_main.h
b/drivers/scsi/be2iscsi/be_main.h
> index 81ce3ff..8166de5 100644
> --- a/drivers/scsi/be2iscsi/be_main.h
> +++ b/drivers/scsi/be2iscsi/be_main.h
> @@ -155,8 +155,6 @@
>  #define PAGES_REQUIRED(x) \
>   ((x < PAGE_SIZE) ? 1 :  ((x + PAGE_SIZE - 1) / PAGE_SIZE))
>
> -#define BEISCSI_MSI_NAME 20 /* size of msi_name string */
> -
>  #define MEM_DESCR_OFFSET 8
>  #define BEISCSI_DEFQ_HDR 1
>  #define BEISCSI_DEFQ_DATA 0
> --
> 2.7.4

Looks good.

- Thanks.

Reviewed-by: Jitendra Bhivare 


Re: [PATCH 3.10 021/139] MIPS: Send SIGILL for BPOSGE32 in `__compute_return_epc_for_insn'

2017-11-05 Thread Huacai Chen
Hi, Willy,

Does these two patches really needed for 3.10? They are marked for 4.4 and 4.6.

ext4: avoid deadlock when expanding inode size

ext4: in ext4_seek_{hole,data}, return -ENXIO for negative offsets



Huacai


Re: linux-next: build warning after merge of the regmap tree

2017-11-05 Thread Stephen Rothwell
Hi Mark,

On Mon, 6 Nov 2017 15:21:57 +1100 Stephen Rothwell  
wrote:
>
> On Mon, 6 Nov 2017 11:52:14 +1100 Stephen Rothwell  
> wrote:
> >
> > After merging the regmap tree, today's linux-next build
> > (arm_multi_v7_defconfig) produced this warning:
> > 
> > drivers/gpio/Kconfig:13:error: recursive dependency detected!
> > For a resolution refer to Documentation/kbuild/kconfig-language.txt
> > subsection "Kconfig recursive dependency limitations"
> > drivers/gpio/Kconfig:13:symbol GPIOLIB is selected by PINCTRL_SUNXI
> > For a resolution refer to Documentation/kbuild/kconfig-language.txt
> > subsection "Kconfig recursive dependency limitations"
> > drivers/pinctrl/sunxi/Kconfig:3:symbol PINCTRL_SUNXI is selected by 
> > PINCTRL_SUN6I_A31_R
> > For a resolution refer to Documentation/kbuild/kconfig-language.txt
> > subsection "Kconfig recursive dependency limitations"
> > drivers/pinctrl/sunxi/Kconfig:21:   symbol PINCTRL_SUN6I_A31_R depends on 
> > RESET_CONTROLLER
> > For a resolution refer to Documentation/kbuild/kconfig-language.txt
> > subsection "Kconfig recursive dependency limitations"
> > drivers/reset/Kconfig:4:symbol RESET_CONTROLLER is selected by QCOM_SCM
> > For a resolution refer to Documentation/kbuild/kconfig-language.txt
> > subsection "Kconfig recursive dependency limitations"
> > drivers/firmware/Kconfig:205:   symbol QCOM_SCM is selected by 
> > QCOM_ADSP_PIL
> > For a resolution refer to Documentation/kbuild/kconfig-language.txt
> > subsection "Kconfig recursive dependency limitations"
> > drivers/remoteproc/Kconfig:90:  symbol QCOM_ADSP_PIL depends on 
> > QCOM_SMEM
> > For a resolution refer to Documentation/kbuild/kconfig-language.txt
> > subsection "Kconfig recursive dependency limitations"
> > drivers/soc/qcom/Kconfig:49:symbol QCOM_SMEM depends on HWSPINLOCK
> > For a resolution refer to Documentation/kbuild/kconfig-language.txt
> > subsection "Kconfig recursive dependency limitations"
> > drivers/hwspinlock/Kconfig:5:   symbol HWSPINLOCK is selected by REGMAP
> > For a resolution refer to Documentation/kbuild/kconfig-language.txt
> > subsection "Kconfig recursive dependency limitations"
> > drivers/base/regmap/Kconfig:6:  symbol REGMAP is selected by 
> > PINCTRL_SX150X
> > For a resolution refer to Documentation/kbuild/kconfig-language.txt
> > subsection "Kconfig recursive dependency limitations"
> > drivers/pinctrl/Kconfig:227:symbol PINCTRL_SX150X is selected by 
> > GPIO_SX150X
> > For a resolution refer to Documentation/kbuild/kconfig-language.txt
> > subsection "Kconfig recursive dependency limitations"
> > drivers/gpio/Kconfig:821:   symbol GPIO_SX150X depends on GPIOLIB
> > warning: (ARCH_VEXPRESS) selects MFD_VEXPRESS_SYSREG which has unmet direct 
> > dependencies (HAS_IOMEM && VEXPRESS_CONFIG && GPIOLIB && 
> > !ARCH_USES_GETTIMEOFFSET)
> > warning: (ARCH_NOMADIK && ARCH_U8500) selects PINCTRL_NOMADIK which has 
> > unmet direct dependencies (PINCTRL && (ARCH_U8500 || ARCH_NOMADIK) && OF && 
> > GPIOLIB)
> > warning: (PINCTRL_AT91 && PINCTRL_AT91PIO4 && PINCTRL_MESON && 
> > PINCTRL_OXNAS && PINCTRL_PISTACHIO && PINCTRL_PIC32 && PINCTRL_NOMADIK && 
> > PINCTRL_MTK && GPIO_TB10X) selects OF_GPIO which has unmet direct 
> > dependencies (GPIOLIB && OF && HAS_IOMEM)
> > 
> > Maybe introduced by commit
> > 
> >   f25637a6b89e ("regmap: Add a config option for hwspinlock")  
> 
> Things got worse during the day until config started segfaulting, so I
> reverted this commit.

That necessitated me reverting commits

  8698b9364710 ("regmap: Add hardware spinlock support")
  267f3e4f18f1 ("regmap: Also protect hwspinlock in error handling path")
  e8419c40a5ad ("regmap: Clean up hwspinlock on regmap exit")

as well.
-- 
Cheers,
Stephen Rothwell


[PATCH v6 4/6] perf util: Create function to perform multiple time range checking

2017-11-05 Thread Jin Yao
Previous patch supports the multiple time range.

For example, select the first and second 10% time slices.
perf report --time 10%/1,10%/2

We need a function to check if a timestamp is in the ranges of
[0, 10%) and [10%, 20%].

Note that it includes the last element in [10%, 20%] but it
doesn't include the last element in [0, 10%). It's to avoid
the overlap.

This patch implments a new function perf_time__ranges_skip_sample
for this checking.

Change log:
---
v4: Let perf_time__ranges_skip_sample be compatible with
perf_time__skip_sample when only one time range.

Signed-off-by: Jin Yao 
---
 tools/perf/util/time-utils.c | 28 
 tools/perf/util/time-utils.h |  3 +++
 2 files changed, 31 insertions(+)

diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c
index 79e4281..b380356 100644
--- a/tools/perf/util/time-utils.c
+++ b/tools/perf/util/time-utils.c
@@ -299,6 +299,34 @@ bool perf_time__skip_sample(struct perf_time_interval 
*ptime, u64 timestamp)
return false;
 }
 
+bool perf_time__ranges_skip_sample(struct perf_time_interval *ptime_buf,
+  int num, u64 timestamp)
+{
+   struct perf_time_interval *ptime;
+   int i;
+
+   if ((timestamp == 0) || (num == 0))
+   return false;
+
+   if (num == 1)
+   return perf_time__skip_sample(&ptime_buf[0], timestamp);
+
+   /*
+* start/end of multiple time ranges must be valid.
+*/
+   for (i = 0; i < num; i++) {
+   ptime = &ptime_buf[i];
+
+   if (timestamp >= ptime->start &&
+   ((timestamp < ptime->end && i < num - 1) ||
+(timestamp <= ptime->end && i == num - 1))) {
+   break;
+   }
+   }
+
+   return (i == num) ? true : false;
+}
+
 int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz)
 {
u64  sec = timestamp / NSEC_PER_SEC;
diff --git a/tools/perf/util/time-utils.h b/tools/perf/util/time-utils.h
index fd018e2..de279ea 100644
--- a/tools/perf/util/time-utils.h
+++ b/tools/perf/util/time-utils.h
@@ -17,6 +17,9 @@ int perf_time__percent_parse_str(struct perf_time_interval 
*ptime_buf, int num,
 
 bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp);
 
+bool perf_time__ranges_skip_sample(struct perf_time_interval *ptime_buf,
+  int num, u64 timestamp);
+
 int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz);
 
 int fetch_current_timestamp(char *buf, size_t sz);
-- 
2.7.4



[PATCH v6 2/6] perf record: Get the first sample time and last sample time

2017-11-05 Thread Jin Yao
In perf record, it's walked on all samples yet. So it's very easy to get
the first/last samples and save the time to perf file header via the
function write_sample_time().

In later, perf report/script will fetch the time from perf file header.

Change log:
---
v6: Currently '--buildid-all' is not enabled at default. So the walking
on all samples is the default operation. There is no big overhead
to calculate the timestamp boundary in process_sample_event handler
once we already go through all samples. So the timestamp boundary
calculation is enabled by default when '--buildid-all' is not enabled.

While if '--buildid-all' is enabled, we creates a new option
"--timestamp-boundary" for user to decide if it enables the
timestamp boundary calculation.

v5: There is an issue that the sample walking can only work when
'--buildid-all' is not enabled. So we need to let the walking
be able to work even if '--buildid-all' is enabled and let the
processing skips the dso hit marking for this case.

At first, I want to provide a new option "--record-time-boundaries".
While after consideration, I think a new option is not very
necessary.

v3: Remove the definitions of first_sample_time and last_sample_time
from struct record and directly save them in perf_evlist.

Signed-off-by: Jin Yao 
---
 tools/perf/Documentation/perf-record.txt |  3 +++
 tools/perf/builtin-record.c  | 18 +++---
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/tools/perf/Documentation/perf-record.txt 
b/tools/perf/Documentation/perf-record.txt
index 5a626ef..3eea6de 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -430,6 +430,9 @@ Configure all used events to run in user space.
 --timestamp-filename
 Append timestamp to output file name.
 
+--timestamp-boundary::
+Record timestamp boundary (time of first/last samples).
+
 --switch-output[=mode]::
 Generate multiple perf.data files, timestamp prefixed, switching to a new one
 based on 'mode' value:
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index f4d9fc5..082a0cb 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -78,6 +78,7 @@ struct record {
boolno_buildid_cache_set;
boolbuildid_all;
booltimestamp_filename;
+   booltimestamp_boundary;
struct switch_outputswitch_output;
unsigned long long  samples;
 };
@@ -391,8 +392,15 @@ static int process_sample_event(struct perf_tool *tool,
 {
struct record *rec = container_of(tool, struct record, tool);
 
-   rec->samples++;
+   if (rec->evlist->first_sample_time == 0)
+   rec->evlist->first_sample_time = sample->time;
+
+   rec->evlist->last_sample_time = sample->time;
 
+   if (rec->buildid_all)
+   return 0;
+
+   rec->samples++;
return build_id__mark_dso_hit(tool, event, sample, evsel, machine);
 }
 
@@ -417,9 +425,11 @@ static int process_buildids(struct record *rec)
 
/*
 * If --buildid-all is given, it marks all DSO regardless of hits,
-* so no need to process samples.
+* so no need to process samples. But if timestamp_boundary is enabled,
+* it still needs to walk on all samples to get the timestamps of
+* first/last samples.
 */
-   if (rec->buildid_all)
+   if (rec->buildid_all && !rec->timestamp_boundary)
rec->tool.sample = NULL;
 
return perf_session__process_events(session);
@@ -1579,6 +1589,8 @@ static struct option __record_options[] = {
"Record build-id of all DSOs regardless of hits"),
OPT_BOOLEAN(0, "timestamp-filename", &record.timestamp_filename,
"append timestamp to output filename"),
+   OPT_BOOLEAN(0, "timestamp-boundary", &record.timestamp_boundary,
+   "Record timestamp boundary (time of first/last samples)"),
OPT_STRING_OPTARG_SET(0, "switch-output", &record.switch_output.str,
  &record.switch_output.set, "signal,size,time",
  "Switch output when receive SIGUSR2 or cross 
size,time threshold",
-- 
2.7.4



[PATCH v6 5/6] perf report: support time percent and multiple time ranges

2017-11-05 Thread Jin Yao
perf report has a --time option to limit the time range of output.
It only supports absolute time.

Now this option is extended to support multiple time ranges and
support the percent of time.

For example:

1. Select the first and second 10% time slices
perf report --time 10%/1,10%/2

2. Select from 0% to 10% and 30% to 40% slices
perf report --time 0%-10%,30%-40%

Change log:
---
v6: Fix the merge issue with latest perf/core branch.
No functional changes.

v5: Add checking of first/last sample time to detect if it's recorded
in perf.data. If it's not recorded, returns error message to user.

v4: Remove perf_time__skip_sample, only uses perf_time__ranges_skip_sample

v3: Since the definitions of first_sample_time/last_sample_time
are moved from perf_session to perf_evlist so change the
related code.

Signed-off-by: Jin Yao 
---
 tools/perf/Documentation/perf-report.txt | 16 
 tools/perf/builtin-report.c  | 31 ++-
 2 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/tools/perf/Documentation/perf-report.txt 
b/tools/perf/Documentation/perf-report.txt
index ddde2b5..ed36553 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -402,6 +402,22 @@ OPTIONS
stop time is not given (i.e, time string is 'x.y,') then analysis goes
to end of file.
 
+   Also support time percent with multipe time range. Time string is
+   'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'. The maximum number of slices is 
10.
+
+   For example:
+   Select the second 10% time slice
+   perf report --time 10%/2
+
+   Select from 0% to 10% time slice
+   perf report --time 0%-10%
+
+   Select the first and second 10% time slices
+   perf report --time 10%/1,10%/2
+
+   Select from 0% to 10% and 30% to 40% slices
+   perf report --time 0%-10%,30%-40%
+
 --itrace::
Options for decoding instruction tracing data. The options are:
 
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 3c2d9d4..c43181d 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -51,6 +51,8 @@
 #include 
 #include 
 
+#define PTIME_RANGE_MAX10
+
 struct report {
struct perf_tooltool;
struct perf_session *session;
@@ -68,7 +70,8 @@ struct report {
const char  *cpu_list;
const char  *symbol_filter_str;
const char  *time_str;
-   struct perf_time_interval ptime;
+   struct perf_time_interval ptime_range[PTIME_RANGE_MAX];
+   int range_num;
float   min_percent;
u64 nr_entries;
u64 queue_size;
@@ -185,8 +188,10 @@ static int process_sample_event(struct perf_tool *tool,
};
int ret = 0;
 
-   if (perf_time__skip_sample(&rep->ptime, sample->time))
+   if (perf_time__ranges_skip_sample(rep->ptime_range, rep->range_num,
+ sample->time)) {
return 0;
+   }
 
if (machine__resolve(machine, &al, sample) < 0) {
pr_debug("problem processing %d event, skipping it.\n",
@@ -1073,9 +1078,25 @@ int cmd_report(int argc, const char **argv)
if (symbol__init(&session->header.env) < 0)
goto error;
 
-   if (perf_time__parse_str(&report.ptime, report.time_str) != 0) {
-   pr_err("Invalid time string\n");
-   return -EINVAL;
+   if (perf_time__parse_str(report.ptime_range, report.time_str) != 0) {
+   if (session->evlist->first_sample_time == 0 &&
+   session->evlist->last_sample_time == 0) {
+   pr_err("No first/last sample time in perf data\n");
+   return -EINVAL;
+   }
+
+   report.range_num = perf_time__percent_parse_str(
+   report.ptime_range, PTIME_RANGE_MAX,
+   report.time_str,
+   session->evlist->first_sample_time,
+   session->evlist->last_sample_time);
+
+   if (report.range_num < 0) {
+   pr_err("Invalid time string\n");
+   return -EINVAL;
+   }
+   } else {
+   report.range_num = 1;
}
 
sort__setup_elide(stdout);
-- 
2.7.4



[PATCH v6 1/6] perf header: Record first sample time and last sample time in perf file header

2017-11-05 Thread Jin Yao
perf report/script/... have a --time option to limit the time range
of output. That's very useful to slice large traces, e.g. when processing
the output of perf script for some analysis.

But right now --time only supports absolute time. Also there is no fast
way to get the start/end times of a given trace except for looking at it.
This makes it hard to e.g. only decode the first half of the trace, which
is useful for parallelization of scripts

Another problem is that perf records are variable size and there is no
synchronization mechanism. So the only way to find the last sample reliably
would be to walk all samples. But we want to avoid that in perf report/...
because it is already quite expensive. That is why storing the first sample
time and last sample time in perf record is better.

This patch creates a new header feature type HEADER_SAMPLE_TIME and related
ops. Save the first sample time and the last sample time to the feature
section in perf file header.

Change log:
---
v4: Use perf script time style for timestamp printing. Also add with
the printing of sample duration.

v3: Remove the definitions of first_sample_time/last_sample_time from
perf_session. Just define them in perf_evlist

Signed-off-by: Jin Yao 
---
 tools/perf/Documentation/perf.data-file-format.txt |  4 ++
 tools/perf/util/evlist.h   |  2 +
 tools/perf/util/header.c   | 60 ++
 tools/perf/util/header.h   |  1 +
 4 files changed, 67 insertions(+)

diff --git a/tools/perf/Documentation/perf.data-file-format.txt 
b/tools/perf/Documentation/perf.data-file-format.txt
index e90c59c..d5e3043 100644
--- a/tools/perf/Documentation/perf.data-file-format.txt
+++ b/tools/perf/Documentation/perf.data-file-format.txt
@@ -238,6 +238,10 @@ struct auxtrace_index {
struct auxtrace_index_entry entries[PERF_AUXTRACE_INDEX_ENTRY_COUNT];
 };
 
+   HEADER_SAMPLE_TIME = 21,
+
+Two uint64_t for the time of first sample and the time of last sample.
+
other bits are reserved and should ignored for now
HEADER_FEAT_BITS= 256,
 
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 8c433e9..a08f407 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -50,6 +50,8 @@ struct perf_evlist {
struct perf_evsel *selected;
struct events_stats stats;
struct perf_env *env;
+   u64 first_sample_time;
+   u64 last_sample_time;
 };
 
 struct perf_evsel_str_handler {
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 6e59dcc..fd81c5b1 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "evlist.h"
 #include "evsel.h"
@@ -36,6 +37,7 @@
 #include 
 #include "asm/bug.h"
 #include "tool.h"
+#include "time-utils.h"
 
 #include "sane_ctype.h"
 
@@ -1181,6 +1183,20 @@ static int write_stat(struct feat_fd *ff __maybe_unused,
return 0;
 }
 
+static int write_sample_time(struct feat_fd *ff,
+struct perf_evlist *evlist)
+{
+   int ret;
+
+   ret = do_write(ff, &evlist->first_sample_time,
+  sizeof(evlist->first_sample_time));
+   if (ret < 0)
+   return ret;
+
+   return do_write(ff, &evlist->last_sample_time,
+   sizeof(evlist->last_sample_time));
+}
+
 static void print_hostname(struct feat_fd *ff, FILE *fp)
 {
fprintf(fp, "# hostname : %s\n", ff->ph->env.hostname);
@@ -1506,6 +1522,28 @@ static void print_group_desc(struct feat_fd *ff, FILE 
*fp)
}
 }
 
+static void print_sample_time(struct feat_fd *ff, FILE *fp)
+{
+   struct perf_session *session;
+   char time_buf[32];
+   double d;
+
+   session = container_of(ff->ph, struct perf_session, header);
+
+   timestamp__scnprintf_usec(session->evlist->first_sample_time,
+ time_buf, sizeof(time_buf));
+   fprintf(fp, "# time of first sample : %s\n", time_buf);
+
+   timestamp__scnprintf_usec(session->evlist->last_sample_time,
+ time_buf, sizeof(time_buf));
+   fprintf(fp, "# time of last sample : %s\n", time_buf);
+
+   d = (double)(session->evlist->last_sample_time -
+   session->evlist->first_sample_time) / NSEC_PER_MSEC;
+
+   fprintf(fp, "# sample duration : %10.3f ms\n", d);
+}
+
 static int __event_process_build_id(struct build_id_event *bev,
char *filename,
struct perf_session *session)
@@ -2147,6 +2185,27 @@ static int process_cache(struct feat_fd *ff, void *data 
__maybe_unused)
return -1;
 }
 
+static int process_sample_time(struct feat_fd *ff, void *data __maybe_unused)
+{
+   struct perf_session *session;
+   u64 first_sample_time, last_sample_time;
+   int ret;
+

[PATCH v6 6/6] perf script: support time percent and multiple time ranges

2017-11-05 Thread Jin Yao
perf script has a --time option to limit the time range of output.
It only supports absolute time.

Now this option is extended to support multiple time ranges and
support the percent of time.

For example:

1. Select the first and second 10% time slices
   perf script --time 10%/1,10%/2

2. Select from 0% to 10% and 30% to 40% slices
   perf script --time 0%-10%,30%-40%

Change log:
---
v6: Fix the merge issue with latest perf/core branch.
No functional changes.

v5: Add checking of first/last sample time to detect if it's recorded
in perf.data. If it's not recorded, returns error message to user.

v4: Remove perf_time__skip_sample, only uses perf_time__ranges_skip_sample

v3: Since the definitions of first_sample_time/last_sample_time
are moved from perf_session to perf_evlist so change the
related code.

Signed-off-by: Jin Yao 
---
 tools/perf/Documentation/perf-script.txt | 16 +++
 tools/perf/builtin-script.c  | 34 ++--
 2 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/tools/perf/Documentation/perf-script.txt 
b/tools/perf/Documentation/perf-script.txt
index 2811fcf..5313fd1 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -321,6 +321,22 @@ include::itrace.txt[]
stop time is not given (i.e, time string is 'x.y,') then analysis goes
to end of file.
 
+   Also support time percent with multipe time range. Time string is
+   'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'. The maximum number of slices is 
10.
+
+   For example:
+   Select the second 10% time slice
+   perf script --time 10%/2
+
+   Select from 0% to 10% time slice
+   perf script --time 0%-10%
+
+   Select the first and second 10% time slices
+   perf script --time 10%/1,10%/2
+
+   Select from 0% to 10% and 30% to 40% slices
+   perf script --time 0%-10%,30%-40%
+
 --max-blocks::
Set the maximum number of program blocks to print with brstackasm for
each sample.
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 89975e3..dad548f 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1429,6 +1429,8 @@ static int perf_sample__fprintf_synth(struct perf_sample 
*sample,
return 0;
 }
 
+#define PTIME_RANGE_MAX10
+
 struct perf_script {
struct perf_tooltool;
struct perf_session *session;
@@ -1442,7 +1444,8 @@ struct perf_script {
struct thread_map   *threads;
int name_width;
const char  *time_str;
-   struct perf_time_interval ptime;
+   struct perf_time_interval ptime_range[PTIME_RANGE_MAX];
+   int range_num;
 };
 
 static int perf_evlist__max_name_len(struct perf_evlist *evlist)
@@ -1642,8 +1645,10 @@ static int process_sample_event(struct perf_tool *tool,
struct perf_script *scr = container_of(tool, struct perf_script, tool);
struct addr_location al;
 
-   if (perf_time__skip_sample(&scr->ptime, sample->time))
+   if (perf_time__ranges_skip_sample(scr->ptime_range, scr->range_num,
+ sample->time)) {
return 0;
+   }
 
if (debug_mode) {
if (sample->time < last_timestamp) {
@@ -3252,10 +3257,27 @@ int cmd_script(int argc, const char **argv)
goto out_delete;
 
/* needs to be parsed after looking up reference time */
-   if (perf_time__parse_str(&script.ptime, script.time_str) != 0) {
-   pr_err("Invalid time string\n");
-   err = -EINVAL;
-   goto out_delete;
+   if (perf_time__parse_str(script.ptime_range, script.time_str) != 0) {
+   if (session->evlist->first_sample_time == 0 &&
+   session->evlist->last_sample_time == 0) {
+   pr_err("No first/last sample time in perf data\n");
+   err = -EINVAL;
+   goto out_delete;
+   }
+
+   script.range_num = perf_time__percent_parse_str(
+   script.ptime_range, PTIME_RANGE_MAX,
+   script.time_str,
+   session->evlist->first_sample_time,
+   session->evlist->last_sample_time);
+
+   if (script.range_num < 0) {
+   pr_err("Invalid time string\n");
+   err = -EINVAL;
+   goto out_delete;
+   }
+   } else {
+   script.range_num = 1;
}
 
err = __cmd_script(&script);
-- 
2.7.4



[PATCH v6 0/6] perf report/script: Support percent and multiple range in --time option

2017-11-05 Thread Jin Yao
v6:
---
1. Create a new option "--timestamp-boundary" in perf record.
   
   Currently '--buildid-all' is not enabled by default. So the walking
   on all samples is the default operation. There is no big overhead
   to calculate the timestamp boundary in process_sample_event handler
   once we already go through all samples. So the timestamp boundary
   calculation is enabled by default when '--buildid-all' is not enabled.

   While if '--buildid-all' is enabled, we creates a new option
   "--timestamp-boundary" for user to decide if it enables the
   timestamp boundary calculation.

   Impacted patch:
   ---
   perf record: Get the first sample time and last sample time

2. Fix the merge issue with the latest perf/core branch.
   No functional changes.

   Impacted patch:
   ---
   perf report: support time percent and multiple time ranges
   perf script: support time percent and multiple time ranges

v5:
---
1. There is an issue that the sample walking can only work when
   '--buildid-all' is not enabled. So we need to let the walking
   be able to work even if '--buildid-all' is enabled and let the
   processing skips the dso hit marking for this case.

2. Check if first/last sample time is recorded in perf data file.
   If it's not recorded, return error message to user.

Patched modified in v5:
   perf record: Get the first sample time and last sample time
   perf report: support time percent and multiple time ranges
   perf script: support time percent and multiple time ranges

v4:
---
1. Use perf script time style for timestamp printing. Also add with
   the printing of sample duration. For example:

   perf report --header

   time of first sample : 5276531.323099
   time of last sample : 5276555.345625
   sample duration :  24022.526 ms

2. Fix an invalid time string issue. For example,

   perf script --time 10%/10x12321xsdfdasfdsafdsafdsa

   Now in code, it uses strtol to replace atoi.

3. Remove perf_time__skip_sample, only uses perf_time__ranges_skip_sample
   in perf report/perf script.

v3:
---
1. Move the definitions of first_sample_time/last_sample_time from
   perf_session and struct record to perf_evlist and update the
   related code.

v2:
---
1. This patch creates a new header feature type HEADER_SAMPLE_TIME and related
   ops. Save the first sample time and the last sample time to the feature
   section in perf file header.

2. Add checking for last element in time range.

   For example, select the first and second 10% time slices.
   perf report --time 10%/1,10%/2

   Note that now it includes the last element in [10%, 20%] but it
   doesn't include the last element in [0, 10%). It's to avoid
   the overlap.

Following patches are changed:

   perf header: Record first sample time and last sample time in perf file 
header
   perf record: Get the first sample time and last sample time
   perf util: Create function to perform multiple time range checking

v1: initial post


Current perf report/script/... have a --time option to limit the time
range of output. But it only supports the absolute time.

The patch series extend this option to let it support percent of time
and support the multiple time ranges.

For example:

1. Select the second 10% time slice
   perf report --time 10%/2

2. Select from 0% to 10% time slice
   perf report --time 0%-10%

It also support the multiple time ranges.

3. Select the first and second 10% time slices
   perf report --time 10%/1,10%/2

4. Select from 0% to 10% and 30% to 40% slices
   perf report --time 0%-10%,30%-40%

Jin Yao (6):
  perf header: Record first sample time and last sample time in perf
file header
  perf record: Get the first sample time and last sample time
  perf util: Create function to parse time percent
  perf util: Create function to perform multiple time range checking
  perf report: support time percent and multiple time ranges
  perf script: support time percent and multiple time ranges

 tools/perf/Documentation/perf-record.txt   |   3 +
 tools/perf/Documentation/perf-report.txt   |  16 ++
 tools/perf/Documentation/perf-script.txt   |  16 ++
 tools/perf/Documentation/perf.data-file-format.txt |   4 +
 tools/perf/builtin-record.c|  18 +-
 tools/perf/builtin-report.c|  31 ++-
 tools/perf/builtin-script.c|  34 ++-
 tools/perf/util/evlist.h   |   2 +
 tools/perf/util/header.c   |  60 ++
 tools/perf/util/header.h   |   1 +
 tools/perf/util/time-utils.c   | 233 +++--
 tools/perf/util/time-utils.h   |   6 +
 12 files changed, 398 insertions(+), 26 deletions(-)

-- 
2.7.4



[PATCH v6 3/6] perf util: Create function to parse time percent

2017-11-05 Thread Jin Yao
Current perf report/script/... have a --time option to limit the time
range of output. But right now it only supports absolute time.

For easy using, now it can support a percent of time usage.

For example:

1. Select the second 10% time slice
   perf report --time 10%/2

2. Select from 0% to 10% time slice
   perf report --time 0%-10%

It also support the multiple time ranges.

3. Select the first and second 10% time slices
   perf report --time 10%/1,10%/2

4. Select from 0% to 10% and 30% to 40% slices
   perf report --time 0%-10%,30%-40%

Change log:
---
v4: An issue is found. Following passes.
perf script --time 10%/10x12321xsdfdasfdsafdsafdsa

Now it uses strtol to replace atoi.

Signed-off-by: Jin Yao 
---
 tools/perf/util/time-utils.c | 205 ---
 tools/perf/util/time-utils.h |   3 +
 2 files changed, 196 insertions(+), 12 deletions(-)

diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c
index 5b5d021..79e4281 100644
--- a/tools/perf/util/time-utils.c
+++ b/tools/perf/util/time-utils.c
@@ -5,6 +5,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "perf.h"
 #include "debug.h"
@@ -59,11 +60,10 @@ static int parse_timestr_sec_nsec(struct perf_time_interval 
*ptime,
return 0;
 }
 
-int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr)
+static int split_start_end(char **start, char **end, const char *ostr, char ch)
 {
char *start_str, *end_str;
char *d, *str;
-   int rc = 0;
 
if (ostr == NULL || *ostr == '\0')
return 0;
@@ -73,25 +73,35 @@ int perf_time__parse_str(struct perf_time_interval *ptime, 
const char *ostr)
if (str == NULL)
return -ENOMEM;
 
-   ptime->start = 0;
-   ptime->end = 0;
-
-   /* str has the format: ,
-* variations: ,
-* ,
-* ,
-*/
start_str = str;
-   d = strchr(start_str, ',');
+   d = strchr(start_str, ch);
if (d) {
*d = '\0';
++d;
}
end_str = d;
 
+   *start = start_str;
+   *end = end_str;
+
+   return 0;
+}
+
+int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr)
+{
+   char *start_str = NULL, *end_str;
+   int rc;
+
+   rc = split_start_end(&start_str, &end_str, ostr, ',');
+   if (rc || !start_str)
+   return rc;
+
+   ptime->start = 0;
+   ptime->end = 0;
+
rc = parse_timestr_sec_nsec(ptime, start_str, end_str);
 
-   free(str);
+   free(start_str);
 
/* make sure end time is after start time if it was given */
if (rc == 0 && ptime->end && ptime->end < ptime->start)
@@ -103,6 +113,177 @@ int perf_time__parse_str(struct perf_time_interval 
*ptime, const char *ostr)
return rc;
 }
 
+static int parse_percent(double *pcnt, char *str)
+{
+   char *c;
+
+   c = strchr(str, '%');
+   if (c)
+   *c = '\0';
+   else
+   return -1;
+
+   *pcnt = atof(str) / 100.0;
+
+   return 0;
+}
+
+static int percent_slash_split(char *str, struct perf_time_interval *ptime,
+  u64 start, u64 end)
+{
+   char *p, *end_str;
+   double pcnt, start_pcnt, end_pcnt;
+   u64 total = end - start;
+   int i;
+
+   /*
+* Example:
+* 10%/2: select the second 10% slice and the third 10% slice
+*/
+
+   /* We can modify this string since the original one is copied */
+   p = strchr(str, '/');
+   if (!p)
+   return -1;
+
+   *p = '\0';
+   if (parse_percent(&pcnt, str) < 0)
+   return -1;
+
+   p++;
+   i = (int)strtol(p, &end_str, 10);
+   if (*end_str)
+   return -1;
+
+   if (pcnt <= 0.0)
+   return -1;
+
+   start_pcnt = pcnt * (i - 1);
+   end_pcnt = pcnt * i;
+
+   if (start_pcnt < 0.0 || start_pcnt > 1.0 ||
+   end_pcnt < 0.0 || end_pcnt > 1.0) {
+   return -1;
+   }
+
+   ptime->start = start + round(start_pcnt * total);
+   ptime->end = start + round(end_pcnt * total);
+
+   return 0;
+}
+
+static int percent_dash_split(char *str, struct perf_time_interval *ptime,
+ u64 start, u64 end)
+{
+   char *start_str = NULL, *end_str;
+   double start_pcnt, end_pcnt;
+   u64 total = end - start;
+   int ret;
+
+   /*
+* Example: 0%-10%
+*/
+
+   ret = split_start_end(&start_str, &end_str, str, '-');
+   if (ret || !start_str)
+   return ret;
+
+   if ((parse_percent(&start_pcnt, start_str) != 0) ||
+   (parse_percent(&end_pcnt, end_str) != 0)) {
+   free(start_str);
+   return -1;
+   }
+
+   free(start_str);
+
+   if (start_pcnt < 0.0 || start_pcnt > 1.0 ||
+   end_pcnt < 0.0 || end_pcnt > 1.0 ||

Re: linux-next: build warning after merge of the regmap tree

2017-11-05 Thread Stephen Rothwell
Hi Mark,

On Mon, 6 Nov 2017 11:52:14 +1100 Stephen Rothwell  
wrote:
>
> After merging the regmap tree, today's linux-next build
> (arm_multi_v7_defconfig) produced this warning:
> 
> drivers/gpio/Kconfig:13:error: recursive dependency detected!
> For a resolution refer to Documentation/kbuild/kconfig-language.txt
> subsection "Kconfig recursive dependency limitations"
> drivers/gpio/Kconfig:13:  symbol GPIOLIB is selected by PINCTRL_SUNXI
> For a resolution refer to Documentation/kbuild/kconfig-language.txt
> subsection "Kconfig recursive dependency limitations"
> drivers/pinctrl/sunxi/Kconfig:3:  symbol PINCTRL_SUNXI is selected by 
> PINCTRL_SUN6I_A31_R
> For a resolution refer to Documentation/kbuild/kconfig-language.txt
> subsection "Kconfig recursive dependency limitations"
> drivers/pinctrl/sunxi/Kconfig:21: symbol PINCTRL_SUN6I_A31_R depends on 
> RESET_CONTROLLER
> For a resolution refer to Documentation/kbuild/kconfig-language.txt
> subsection "Kconfig recursive dependency limitations"
> drivers/reset/Kconfig:4:  symbol RESET_CONTROLLER is selected by QCOM_SCM
> For a resolution refer to Documentation/kbuild/kconfig-language.txt
> subsection "Kconfig recursive dependency limitations"
> drivers/firmware/Kconfig:205: symbol QCOM_SCM is selected by QCOM_ADSP_PIL
> For a resolution refer to Documentation/kbuild/kconfig-language.txt
> subsection "Kconfig recursive dependency limitations"
> drivers/remoteproc/Kconfig:90:symbol QCOM_ADSP_PIL depends on 
> QCOM_SMEM
> For a resolution refer to Documentation/kbuild/kconfig-language.txt
> subsection "Kconfig recursive dependency limitations"
> drivers/soc/qcom/Kconfig:49:  symbol QCOM_SMEM depends on HWSPINLOCK
> For a resolution refer to Documentation/kbuild/kconfig-language.txt
> subsection "Kconfig recursive dependency limitations"
> drivers/hwspinlock/Kconfig:5: symbol HWSPINLOCK is selected by REGMAP
> For a resolution refer to Documentation/kbuild/kconfig-language.txt
> subsection "Kconfig recursive dependency limitations"
> drivers/base/regmap/Kconfig:6:symbol REGMAP is selected by 
> PINCTRL_SX150X
> For a resolution refer to Documentation/kbuild/kconfig-language.txt
> subsection "Kconfig recursive dependency limitations"
> drivers/pinctrl/Kconfig:227:  symbol PINCTRL_SX150X is selected by GPIO_SX150X
> For a resolution refer to Documentation/kbuild/kconfig-language.txt
> subsection "Kconfig recursive dependency limitations"
> drivers/gpio/Kconfig:821: symbol GPIO_SX150X depends on GPIOLIB
> warning: (ARCH_VEXPRESS) selects MFD_VEXPRESS_SYSREG which has unmet direct 
> dependencies (HAS_IOMEM && VEXPRESS_CONFIG && GPIOLIB && 
> !ARCH_USES_GETTIMEOFFSET)
> warning: (ARCH_NOMADIK && ARCH_U8500) selects PINCTRL_NOMADIK which has unmet 
> direct dependencies (PINCTRL && (ARCH_U8500 || ARCH_NOMADIK) && OF && GPIOLIB)
> warning: (PINCTRL_AT91 && PINCTRL_AT91PIO4 && PINCTRL_MESON && PINCTRL_OXNAS 
> && PINCTRL_PISTACHIO && PINCTRL_PIC32 && PINCTRL_NOMADIK && PINCTRL_MTK && 
> GPIO_TB10X) selects OF_GPIO which has unmet direct dependencies (GPIOLIB && 
> OF && HAS_IOMEM)
> 
> Maybe introduced by commit
> 
>   f25637a6b89e ("regmap: Add a config option for hwspinlock")

Things got worse during the day until config started segfaulting, so I
reverted this commit.

-- 
Cheers,
Stephen Rothwell


checkpatch potential false positive

2017-11-05 Thread Tobin C. Harding
Hi,

When parsing drivers/staging/unisys/visorbus/visorchipset.c in Greg's
staging tree checkpatch emits

--
visorchipset.c
--
WARNING: char * array declaration might be better as static const
#1050: FILE: visorchipset.c:1050:
+   char *envp[] = { env_cmd, env_id, env_state, env_bus, env_dev,

WARNING: char * array declaration might be better as static const
#1140: FILE: visorchipset.c:1140:
+   char *envp[] = { env_selftest, NULL };

total: 0 errors, 2 warnings, 1694 lines checked

I may be wrong but I think the code in question is clean and
correct. Since checkpatch is saying this _might_ be better ... perhaps
checkpatch could emit CHECK instead of WARNING for this?

Here is the complete function to save finding the file.

/*
 * parahotplug_request_kickoff() - initiate parahotplug request
 * @req: the request to initiate
 *
 * Cause uevent to run the user level script to do the disable/enable specified
 * in the parahotplug_request.
 */
static int parahotplug_request_kickoff(struct parahotplug_request *req)
{
struct controlvm_message_packet *cmd = &req->msg.cmd;
char env_cmd[40], env_id[40], env_state[40], env_bus[40], env_dev[40],
 env_func[40];
char *envp[] = { env_cmd, env_id, env_state, env_bus, env_dev,
 env_func, NULL
};

sprintf(env_cmd, "VISOR_PARAHOTPLUG=1");
sprintf(env_id, "VISOR_PARAHOTPLUG_ID=%d", req->id);
sprintf(env_state, "VISOR_PARAHOTPLUG_STATE=%d",
cmd->device_change_state.state.active);
sprintf(env_bus, "VISOR_PARAHOTPLUG_BUS=%d",
cmd->device_change_state.bus_no);
sprintf(env_dev, "VISOR_PARAHOTPLUG_DEVICE=%d",
cmd->device_change_state.dev_no >> 3);
sprintf(env_func, "VISOR_PARAHOTPLUG_FUNCTION=%d",
cmd->device_change_state.dev_no & 0x7);
return kobject_uevent_env(&chipset_dev->acpi_device->dev.kobj,
  KOBJ_CHANGE, envp);
}

If this is not the sort of bug report you like, could you please (if you
have time) school me on how to better report such things in the future.

thanks,
Tobin.


[PATCH] selftests: futex: fix compilation error

2017-11-05 Thread Lei Yang
I run into below error when building futext
/bin/sh: -c: line 5: syntax error: unexpected end of file

the closing ";" and "\" are necessary.
My OS is "Ubuntu 14.04.5 LTS"

Signed-off-by: Lei Yang 
---
 tools/testing/selftests/futex/Makefile | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/futex/Makefile 
b/tools/testing/selftests/futex/Makefile
index f0c0369..943f3a2 100644
--- a/tools/testing/selftests/futex/Makefile
+++ b/tools/testing/selftests/futex/Makefile
@@ -11,9 +11,9 @@ all:
BUILD_TARGET=$(OUTPUT)/$$DIR;   \
mkdir $$BUILD_TARGET  -p;   \
make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
-   if [ -e $$DIR/$(TEST_PROGS) ]; then
-   rsync -a $$DIR/$(TEST_PROGS) $$BUILD_TARGET/;
-   fi
+   if [ -e $$DIR/$(TEST_PROGS) ]; then \
+   rsync -a $$DIR/$(TEST_PROGS) $$BUILD_TARGET/; \
+   fi \
done
 
 override define RUN_TESTS
-- 
1.9.1



Re: [PATCH v2] cgroup/cpuset: remove circular dependency deadlock

2017-11-05 Thread Prateek Sood
On 10/30/2017 12:46 PM, Prateek Sood wrote:
> Remove circular dependency deadlock in a scenario where hotplug of CPU is
> being done while there is updation in cgroup and cpuset triggered from
> userspace.
> 
> Process A => kthreadd => Process B => Process C => Process A
> 
> Process A
> cpu_subsys_offline();
>   cpu_down();
> _cpu_down();
>   percpu_down_write(&cpu_hotplug_lock); //held
>   cpuhp_invoke_callback();
>workqueue_offline_cpu();
> queue_work_on(); // unbind_work on system_highpri_wq
>__queue_work();
>  insert_work();
> wake_up_worker();
> flush_work();
>wait_for_completion();
> 
> worker_thread();
>manage_workers();
>   create_worker();
>kthread_create_on_node();
>   wake_up_process(kthreadd_task);
> 
> kthreadd
> kthreadd();
>   kernel_thread();
> do_fork();
>   copy_process();
> percpu_down_read(&cgroup_threadgroup_rwsem);
>   __rwsem_down_read_failed_common(); //waiting
> 
> Process B
> kernfs_fop_write();
>   cgroup_file_write();
> cgroup_procs_write();
>   percpu_down_write(&cgroup_threadgroup_rwsem); //held
>   cgroup_attach_task();
> cgroup_migrate();
>   cgroup_migrate_execute();
> cpuset_can_attach();
>   mutex_lock(&cpuset_mutex); //waiting
> 
> Process C
> kernfs_fop_write();
>   cgroup_file_write();
> cpuset_write_resmask();
>   mutex_lock(&cpuset_mutex); //held
>   update_cpumask();
> update_cpumasks_hier();
>   rebuild_sched_domains_locked();
> get_online_cpus();
>   percpu_down_read(&cpu_hotplug_lock); //waiting
> 
> Eliminating deadlock by reversing the locking order for cpuset_mutex and
> cpu_hotplug_lock. After inverting the locking sequence of cpu_hotplug_lock
> and cpuset_mutex, cpuset_hotplug_workfn() related functionality can be
> done synchronously from the context doing cpu hotplug. For memory hotplug
> it still gets queued as a work item.
> 
> Signed-off-by: Prateek Sood 
> ---
>  include/linux/cpuset.h |  6 
>  kernel/cgroup/cpuset.c | 94 
> +++---
>  kernel/power/process.c |  2 --
>  kernel/sched/core.c|  1 -
>  4 files changed, 50 insertions(+), 53 deletions(-)
> 
> diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
> index a1e6a33..e74655d 100644
> --- a/include/linux/cpuset.h
> +++ b/include/linux/cpuset.h
> @@ -51,9 +51,7 @@ static inline void cpuset_dec(void)
>  
>  extern int cpuset_init(void);
>  extern void cpuset_init_smp(void);
> -extern void cpuset_force_rebuild(void);
>  extern void cpuset_update_active_cpus(void);
> -extern void cpuset_wait_for_hotplug(void);
>  extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask);
>  extern void cpuset_cpus_allowed_fallback(struct task_struct *p);
>  extern nodemask_t cpuset_mems_allowed(struct task_struct *p);
> @@ -166,15 +164,11 @@ static inline void set_mems_allowed(nodemask_t nodemask)
>  static inline int cpuset_init(void) { return 0; }
>  static inline void cpuset_init_smp(void) {}
>  
> -static inline void cpuset_force_rebuild(void) { }
> -
>  static inline void cpuset_update_active_cpus(void)
>  {
>   partition_sched_domains(1, NULL, NULL);
>  }
>  
> -static inline void cpuset_wait_for_hotplug(void) { }
> -
>  static inline void cpuset_cpus_allowed(struct task_struct *p,
>  struct cpumask *mask)
>  {
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 4657e29..ec44aaa 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -817,6 +817,18 @@ static int generate_sched_domains(cpumask_var_t 
> **domains,
>   return ndoms;
>  }
>  
> +static void cpuset_sched_change_begin(void)
> +{
> + cpus_read_lock();
> + mutex_lock(&cpuset_mutex);
> +}
> +
> +static void cpuset_sched_change_end(void)
> +{
> + mutex_unlock(&cpuset_mutex);
> + cpus_read_unlock();
> +}
> +
>  /*
>   * Rebuild scheduler domains.
>   *
> @@ -826,16 +838,14 @@ static int generate_sched_domains(cpumask_var_t 
> **domains,
>   * 'cpus' is removed, then call this routine to rebuild the
>   * scheduler's dynamic sched domains.
>   *
> - * Call with cpuset_mutex held.  Takes get_online_cpus().
>   */
> -static void rebuild_sched_domains_locked(void)
> +static void rebuild_sched_domains_cpuslocked(void)
>  {
>   struct sched_domain_attr *attr;
>   cpumask_var_t *doms;
>   int ndoms;
>  
>   lockdep_assert_held(&cpuset_mutex);
> - get_online_cpus();
>  
>   /*
>* We have raced with CPU hotplug. Don't do anything to avoid
> @@ -843,27 +853,25 @@ static void rebuild_sched_domains_locked(void)
>* Anyways, hotplug work item will rebuild sched domains.
>*/
>   if (!cpumask_equal(top_cpuset.effective_cpus, cpu_active_mask))
> - goto out;
> +

RE: [PATCH v2 resend 0/1] Input: add support HiDeep touchscreen.

2017-11-05 Thread Anthony Kim
Hi Dmitry,

Thanks for your mention.

>Hi Anthony,

>On Tue, Oct 31, 2017 at 07:17:56PM +0900, Anthony Kim wrote:
>> Hi,
>> 
>> I remake patch to base on dmitry's modified code.
>> Please refer as follow.
>> http://www.spinics.net/lists/linux-input/msg53724.html
>> 
>> That code is working well almost, but needed to some modified.
>> 
>> - v2
>>   - Our fw binary data is little endian, but our IC protocol
>> for fw update use big endian. So it need to convert to big endian data
>> and I added about it.

>I understand that _currently_ your firmware binary is little endian, however 
>it is easily remedied on your side. I do not understand why you would want to 
>encumber the kernel running on many devices to do that conversion on fly.

As your mention, I will don't convert to another endian again. I didn't know 
whether it affected. Just I hoped our IC work well.
And I will test again using big endian binary. If there need to modify, I will 
send modified patch.

Thanks! 

>Thanks.

>--
>Dmitry


linux-next: manual merge of the scsi tree with Linus' tree

2017-11-05 Thread Stephen Rothwell
Hi James,

Today's linux-next merge of the scsi tree got a conflict in:

  include/scsi/scsi_devinfo.h

between commit:

  28a0bc4120d3 ("scsi: sd: Implement blacklist option for WRITE SAME w/ UNMAP")

from Linus' tree and commit:

  f26aeada0493 ("scsi: scsi_devinfo: Reformat blacklist flags")

from the scsi tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc include/scsi/scsi_devinfo.h
index 3575693bb628,7a2329c026a4..
--- a/include/scsi/scsi_devinfo.h
+++ b/include/scsi/scsi_devinfo.h
@@@ -4,32 -3,55 +4,57 @@@
  /*
   * Flags for SCSI devices that need special treatment
   */
- #define BLIST_NOLUN   0x001   /* Only scan LUN 0 */
- #define BLIST_FORCELUN0x002   /* Known to have LUNs, force scanning,
-  deprecated: Use max_luns=N */
- #define BLIST_BORKEN  0x004   /* Flag for broken handshaking */
- #define BLIST_KEY 0x008   /* unlock by special command */
- #define BLIST_SINGLELUN   0x010   /* Do not use LUNs in parallel */
- #define BLIST_NOTQ0x020   /* Buggy Tagged Command Queuing */
- #define BLIST_SPARSELUN   0x040   /* Non consecutive LUN numbering */
- #define BLIST_MAX5LUN 0x080   /* Avoid LUNS >= 5 */
- #define BLIST_ISROM   0x100   /* Treat as (removable) CD-ROM */
- #define BLIST_LARGELUN0x200   /* LUNs past 7 on a SCSI-2 
device */
- #define BLIST_INQUIRY_36  0x400   /* override additional length field */
- #define BLIST_NOSTARTONADD0x1000  /* do not do automatic start on add */
- #define BLIST_REPORTLUN2  0x2 /* try REPORT_LUNS even for SCSI-2 devs
-  (if HBA supports more than 8 LUNs) */
- #define BLIST_NOREPORTLUN 0x4 /* don't try REPORT_LUNS scan (SCSI-3 
devs) */
- #define BLIST_NOT_LOCKABLE0x8 /* don't use PREVENT-ALLOW commands */
- #define BLIST_NO_ULD_ATTACH   0x10 /* device is actually for RAID config 
*/
- #define BLIST_SELECT_NO_ATN   0x20 /* select without ATN */
- #define BLIST_RETRY_HWERROR   0x40 /* retry HARDWARE_ERROR */
- #define BLIST_MAX_512 0x80 /* maximum 512 sector cdb length */
- #define BLIST_NO_DIF  0x200 /* Disable T10 PI (DIF) */
- #define BLIST_SKIP_VPD_PAGES  0x400 /* Ignore SBC-3 VPD pages */
- #define BLIST_TRY_VPD_PAGES   0x1000 /* Attempt to read VPD pages */
- #define BLIST_NO_RSOC 0x2000 /* don't try to issue RSOC */
- #define BLIST_MAX_10240x4000 /* maximum 1024 sector cdb 
length */
- #define BLIST_UNMAP_LIMIT_WS  0x8000 /* Use UNMAP limit for WRITE SAME */
+ 
+ /* Only scan LUN 0 */
+ #define BLIST_NOLUN   ((__force __u32 __bitwise)(1 << 0))
+ /* Known to have LUNs, force scanning.
+  * DEPRECATED: Use max_luns=N */
+ #define BLIST_FORCELUN((__force __u32 __bitwise)(1 << 1))
+ /* Flag for broken handshaking */
+ #define BLIST_BORKEN  ((__force __u32 __bitwise)(1 << 2))
+ /* unlock by special command */
+ #define BLIST_KEY ((__force __u32 __bitwise)(1 << 3))
+ /* Do not use LUNs in parallel */
+ #define BLIST_SINGLELUN   ((__force __u32 __bitwise)(1 << 4))
+ /* Buggy Tagged Command Queuing */
+ #define BLIST_NOTQ((__force __u32 __bitwise)(1 << 5))
+ /* Non consecutive LUN numbering */
+ #define BLIST_SPARSELUN   ((__force __u32 __bitwise)(1 << 6))
+ /* Avoid LUNS >= 5 */
+ #define BLIST_MAX5LUN ((__force __u32 __bitwise)(1 << 7))
+ /* Treat as (removable) CD-ROM */
+ #define BLIST_ISROM   ((__force __u32 __bitwise)(1 << 8))
+ /* LUNs past 7 on a SCSI-2 device */
+ #define BLIST_LARGELUN((__force __u32 __bitwise)(1 << 9))
+ /* override additional length field */
+ #define BLIST_INQUIRY_36  ((__force __u32 __bitwise)(1 << 10))
+ /* do not do automatic start on add */
+ #define BLIST_NOSTARTONADD((__force __u32 __bitwise)(1 << 12))
+ /* try REPORT_LUNS even for SCSI-2 devs (if HBA supports more than 8 LUNs) */
+ #define BLIST_REPORTLUN2  ((__force __u32 __bitwise)(1 << 17))
+ /* don't try REPORT_LUNS scan (SCSI-3 devs) */
+ #define BLIST_NOREPORTLUN ((__force __u32 __bitwise)(1 << 18))
+ /* don't use PREVENT-ALLOW commands */
+ #define BLIST_NOT_LOCKABLE((__force __u32 __bitwise)(1 << 19))
+ /* device is actually for RAID config */
+ #define BLIST_NO_ULD_ATTACH   ((__force __u32 __bitwise)(1 << 20))
+ /* select without ATN */
+ #define BLIST_SELECT_NO_ATN   ((__force __u32 __bitwise)(1 << 21))
+ /* retry HARDWARE_ERROR */
+ #define BLIST_RETRY_HWERROR   ((__force __u32 __bitwise)(1 <<

[PATCH v2 1/4] x86, build: Factor out fdimage/isoimage generation commands to standalone script

2017-11-05 Thread changbin . du
From: Changbin Du 

The build message for fdimage/isoimage are pretty unstructured. The raw
shell command blocks are printed. We can improve them as regular build
system messages. Besides, writing commands in a shell script is much more
easy than in a Makefile.

See Ingo's suggestion here https://lkml.org/lkml/2017/10/31/124.

This patch factors out the commands used for fdimage/isoimage generation
from arch/x86/boot/Makefile to a new script arch/x86/boot/genimage.sh.
Then it adds the new kbuild command 'genimage' which invokes the new script.
All fdimages/isoimage files are now generated by a call to 'genimage' with
different parameters.

Now 'make isoimage' becomes:
...
Kernel: arch/x86/boot/bzImage is ready  (#30)
  GENIMAGE arch/x86/boot/image.iso
Size of boot image is 4 sectors -> No emulation
 15.37% done, estimate finish Sun Nov  5 23:36:57 2017
 30.68% done, estimate finish Sun Nov  5 23:36:57 2017
 46.04% done, estimate finish Sun Nov  5 23:36:57 2017
 61.35% done, estimate finish Sun Nov  5 23:36:57 2017
 76.69% done, estimate finish Sun Nov  5 23:36:57 2017
 92.00% done, estimate finish Sun Nov  5 23:36:57 2017
Total translation table size: 2048
Total rockridge attributes bytes: 659
Total directory bytes: 0
Path table size(bytes): 10
Max brk space used 0
32608 extents written (63 MB)
Kernel: arch/x86/boot/image.iso is ready

Before:
Kernel: arch/x86/boot/bzImage is ready  (#63)
rm -rf arch/x86/boot/isoimage
mkdir arch/x86/boot/isoimage
for i in lib lib64 share end ; do \
if [ -f /usr/$i/syslinux/isolinux.bin ] ; then \
cp /usr/$i/syslinux/isolinux.bin arch/x86/boot/isoimage ; \
if [ -f /usr/$i/syslinux/ldlinux.c32 ]; then \
cp /usr/$i/syslinux/ldlinux.c32 arch/x86/boot/isoimage 
; \
fi ; \
break ; \
fi ; \
if [ $i = end ] ; then exit 1 ; fi ; \
done
...

Suggested-by: Ingo Molnar 
Signed-off-by: Changbin Du 
Cc: Masahiro Yamada 

---
v2: Fix grammar errors in commit message. (Ingo)
---
 arch/x86/boot/Makefile|  59 +-
 arch/x86/boot/genimage.sh | 105 ++
 2 files changed, 116 insertions(+), 48 deletions(-)
 create mode 100644 arch/x86/boot/genimage.sh

diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
index d88a2fd..9b5adae 100644
--- a/arch/x86/boot/Makefile
+++ b/arch/x86/boot/Makefile
@@ -123,63 +123,26 @@ image_cmdline = default linux $(FDARGS) $(if 
$(FDINITRD),initrd=initrd.img,)
 $(obj)/mtools.conf: $(src)/mtools.conf.in
sed -e 's|@OBJ@|$(obj)|g' < $< > $@
 
+quiet_cmd_genimage = GENIMAGE $3
+cmd_genimage = sh $(srctree)/$(src)/genimage.sh $2 $3 $(obj)/bzImage \
+   $(obj)/mtools.conf '$(image_cmdline)' $(FDINITRD)
+
 # This requires write access to /dev/fd0
 bzdisk: $(obj)/bzImage $(obj)/mtools.conf
-   MTOOLSRC=$(obj)/mtools.conf mformat a:  ; sync
-   syslinux /dev/fd0   ; sync
-   echo '$(image_cmdline)' | \
-   MTOOLSRC=$(src)/mtools.conf mcopy - a:syslinux.cfg
-   if [ -f '$(FDINITRD)' ] ; then \
-   MTOOLSRC=$(obj)/mtools.conf mcopy '$(FDINITRD)' a:initrd.img ; \
-   fi
-   MTOOLSRC=$(obj)/mtools.conf mcopy $(obj)/bzImage a:linux; sync
+   $(call cmd,genimage,bzdisk,/dev/fd0)
 
 # These require being root or having syslinux 2.02 or higher installed
 fdimage fdimage144: $(obj)/bzImage $(obj)/mtools.conf
-   dd if=/dev/zero of=$(obj)/fdimage bs=1024 count=1440
-   MTOOLSRC=$(obj)/mtools.conf mformat v:  ; sync
-   syslinux $(obj)/fdimage ; sync
-   echo '$(image_cmdline)' | \
-   MTOOLSRC=$(obj)/mtools.conf mcopy - v:syslinux.cfg
-   if [ -f '$(FDINITRD)' ] ; then \
-   MTOOLSRC=$(obj)/mtools.conf mcopy '$(FDINITRD)' v:initrd.img ; \
-   fi
-   MTOOLSRC=$(obj)/mtools.conf mcopy $(obj)/bzImage v:linux; sync
+   $(call cmd,genimage,fdimage144,$(obj)/fdimage)
+   @$(kecho) 'Kernel: $(obj)/fdimage is ready'
 
 fdimage288: $(obj)/bzImage $(obj)/mtools.conf
-   dd if=/dev/zero of=$(obj)/fdimage bs=1024 count=2880
-   MTOOLSRC=$(obj)/mtools.conf mformat w:  ; sync
-   syslinux $(obj)/fdimage ; sync
-   echo '$(image_cmdline)' | \
-   MTOOLSRC=$(obj)/mtools.conf mcopy - w:syslinux.cfg
-   if [ -f '$(FDINITRD)' ] ; then \
-   MTOOLSRC=$(obj)/mtools.conf mcopy '$(FDINITRD)' w:initrd.img ; \
-   fi
-   MTOOLSRC=$(obj)/mtools.conf mcopy $(obj)/bzImage w:linux; sync
+   $(call cmd,genimage,fdimage288,$(obj)/fdimage)
+   @$(kecho) 'Kernel: $(obj)/fdimage is ready'
 
 isoimage: $(obj)/bzImage
-   -rm -rf $(obj)/isoimage
-   mkdir $(obj)/isoimage
-   for i in lib lib64 share end ; do \
-   if [ -f /usr/$$i/syslinux/isolin

[PATCH v2 4/4] x86, boot: Add some generated files to the .gitignore file

2017-11-05 Thread changbin . du
From: Changbin Du 

Ignore generated files fdimage,mtools.conf and image.iso.

Signed-off-by: Changbin Du 
---
 arch/x86/boot/.gitignore | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/x86/boot/.gitignore b/arch/x86/boot/.gitignore
index e3cf9f6..09d25dd 100644
--- a/arch/x86/boot/.gitignore
+++ b/arch/x86/boot/.gitignore
@@ -7,3 +7,6 @@ zoffset.h
 setup
 setup.bin
 setup.elf
+fdimage
+mtools.conf
+image.iso
-- 
2.7.4



[PATCH v2 3/4] x86, build: Specify -input-charset=utf-8 for mkisofs

2017-11-05 Thread changbin . du
From: Changbin Du 

It avoids the following warning triggered by newer versions of mkisofs::
I: -input-charset not specified, using utf-8 (detected in locale settings)

Signed-off-by: Changbin Du 
---
 arch/x86/boot/genimage.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/boot/genimage.sh b/arch/x86/boot/genimage.sh
index 6c8100b..628e936 100644
--- a/arch/x86/boot/genimage.sh
+++ b/arch/x86/boot/genimage.sh
@@ -103,8 +103,9 @@ genisoimage() {
if [ -f "$FDINITRD" ] ; then
cp "$FDINITRD" $tmp_dir/initrd.img
fi
-   mkisofs -J -r -o $FIMAGE -b isolinux.bin -c boot.cat \
-   -no-emul-boot -boot-load-size 4 -boot-info-table $tmp_dir
+   mkisofs -J -r -input-charset=utf-8 -o $FIMAGE -b isolinux.bin \
+   -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table \
+   $tmp_dir
isohybrid $FIMAGE 2>/dev/null || true
rm -rf $tmp_dir
 }
-- 
2.7.4



[PATCH v2 0/4] x86, kbuild: Some improvement for fdimage/isoimage generation

2017-11-05 Thread changbin . du
From: Changbin Du 

This serias is a expansion of below original patch after discussion with Ingo
and Yamada.
[PATCH] x86, build: Improve the isolinux searching of isoimage generation

v2: some improvement for commit messages.

Changbin Du (4):
  x86, build: Factor out fdimage/isoimage generation commands to
standalone script
  x86, build: Add new paths for isolinux.bin and ldlinux.c32
  x86, build: Specify -input-charset=utf-8 for mkisofs
  x86, boot: Add some generated files to the .gitignore file

 arch/x86/boot/.gitignore  |   3 ++
 arch/x86/boot/Makefile|  59 +--
 arch/x86/boot/genimage.sh | 119 ++
 3 files changed, 133 insertions(+), 48 deletions(-)
 create mode 100644 arch/x86/boot/genimage.sh

-- 
2.7.4



[PATCH v2 2/4] x86, build: Add new paths for isolinux.bin and ldlinux.c32

2017-11-05 Thread changbin . du
From: Changbin Du 

Recently I failed to build isoimage target, because the path of isolinux.bin
changed to /usr/xxx/ISOLINUX/isolinux.bin, as well as ldlinux.c32 which
changed to /usr/xxx/syslinux/modules/bios/ldlinux.c32.

This patch improves the file search logic:
  - Show a error message instead of silent fail.
  - Add above new paths.

Signed-off-by: Changbin Du 
Cc: Ingo Molnar 

---
v2: Improve description. (Ingo)
---
 arch/x86/boot/genimage.sh | 23 ++-
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/arch/x86/boot/genimage.sh b/arch/x86/boot/genimage.sh
index 75a9de1..6c8100b 100644
--- a/arch/x86/boot/genimage.sh
+++ b/arch/x86/boot/genimage.sh
@@ -76,14 +76,27 @@ genisoimage() {
rm -rf $tmp_dir
mkdir $tmp_dir
for i in lib lib64 share end ; do
-   if [ -f /usr/$i/syslinux/isolinux.bin ] ; then
-   cp /usr/$i/syslinux/isolinux.bin $tmp_dir
-   if [ -f /usr/$i/syslinux/ldlinux.c32 ]; then
-   cp /usr/$i/syslinux/ldlinux.c32 $tmp_dir
+   for j in syslinux ISOLINUX ; do
+   if [ -f /usr/$i/$j/isolinux.bin ] ; then
+   isolinux=/usr/$i/$j/isolinux.bin
+   echo "Using $isolinux"
+   cp $isolinux $tmp_dir
fi
+   done
+   for j in syslinux syslinux/modules/bios ; do
+   if [ -f /usr/$i/$j/ldlinux.c32 ]; then
+   ldlinux=/usr/$i/$j/ldlinux.c32
+   echo "Using $ldlinux"
+   cp $ldlinux $tmp_dir
+   fi
+   done
+   if [ -n "$isolinux" -a -n "$ldlinux" ] ; then
break
fi
-   if [ $i = end ] ; then exit 1 ; fi ;
+   if [ $i = end -a -z "$isolinux" ] ; then
+   echo 'Need an isolinux.bin file, please install 
syslinux/isolinux.'
+   exit 1
+   fi
done
cp $FBZIMAGE $tmp_dir/linux
echo "$KCMDLINE" > $tmp_dir/isolinux.cfg
-- 
2.7.4



[RFC PATCH] mm, oom_reaper: gather each vma to prevent leaking TLB entry

2017-11-05 Thread Wang Nan
tlb_gather_mmu(&tlb, mm, 0, -1) means gathering all virtual memory space.
In this case, tlb->fullmm is true. Some archs like arm64 doesn't flush
TLB when tlb->fullmm is true:

  commit 5a7862e83000 ("arm64: tlbflush: avoid flushing when fullmm == 1").

Which makes leaking of tlb entries. For example, when oom_reaper
selects a task and reaps its virtual memory space, another thread
in this task group may still running on another core and access
these already freed memory through tlb entries.

This patch gather each vma instead of gathering full vm space,
tlb->fullmm is not true. The behavior of oom reaper become similar
to munmapping before do_exit, which should be safe for all archs.

Signed-off-by: Wang Nan 
Cc: Bob Liu 
Cc: Michal Hocko 
Cc: Andrew Morton 
Cc: Michal Hocko 
Cc: David Rientjes 
Cc: Ingo Molnar 
Cc: Roman Gushchin 
Cc: Konstantin Khlebnikov 
Cc: Andrea Arcangeli 
---
 mm/oom_kill.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index dee0f75..18c5b35 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -532,7 +532,6 @@ static bool __oom_reap_task_mm(struct task_struct *tsk, 
struct mm_struct *mm)
 */
set_bit(MMF_UNSTABLE, &mm->flags);
 
-   tlb_gather_mmu(&tlb, mm, 0, -1);
for (vma = mm->mmap ; vma; vma = vma->vm_next) {
if (!can_madv_dontneed_vma(vma))
continue;
@@ -547,11 +546,13 @@ static bool __oom_reap_task_mm(struct task_struct *tsk, 
struct mm_struct *mm)
 * we do not want to block exit_mmap by keeping mm ref
 * count elevated without a good reason.
 */
-   if (vma_is_anonymous(vma) || !(vma->vm_flags & VM_SHARED))
+   if (vma_is_anonymous(vma) || !(vma->vm_flags & VM_SHARED)) {
+   tlb_gather_mmu(&tlb, mm, vma->vm_start, vma->vm_end);
unmap_page_range(&tlb, vma, vma->vm_start, vma->vm_end,
 NULL);
+   tlb_finish_mmu(&tlb, vma->vm_start, vma->vm_end);
+   }
}
-   tlb_finish_mmu(&tlb, 0, -1);
pr_info("oom_reaper: reaped process %d (%s), now anon-rss:%lukB, 
file-rss:%lukB, shmem-rss:%lukB\n",
task_pid_nr(tsk), tsk->comm,
K(get_mm_counter(mm, MM_ANONPAGES)),
-- 
2.10.1



[PATCH 2/2] platform/x86: dell-smbios-wmi: release mutex lock on WMI call failure

2017-11-05 Thread Mario Limonciello
Unbound devices may race with calling this function causing the mutex
to stay locked.  This failure mode should have released the mutex too.

Signed-off-by: Mario Limonciello 
---
 drivers/platform/x86/dell-smbios-wmi.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/dell-smbios-wmi.c 
b/drivers/platform/x86/dell-smbios-wmi.c
index 35c13815..5cf9b13 100644
--- a/drivers/platform/x86/dell-smbios-wmi.c
+++ b/drivers/platform/x86/dell-smbios-wmi.c
@@ -91,8 +91,10 @@ int dell_smbios_wmi_call(struct calling_interface_buffer 
*buffer)
 
mutex_lock(&call_mutex);
priv = get_first_smbios_priv();
-   if (!priv)
-   return -ENODEV;
+   if (!priv) {
+   ret = -ENODEV;
+   goto out_wmi_call;
+   }
 
size = sizeof(struct calling_interface_buffer);
difference = priv->req_buf_size - sizeof(u64) - size;
@@ -101,6 +103,7 @@ int dell_smbios_wmi_call(struct calling_interface_buffer 
*buffer)
memcpy(&priv->buf->std, buffer, size);
ret = run_smbios_call(priv->wdev);
memcpy(buffer, &priv->buf->std, size);
+out_wmi_call:
mutex_unlock(&call_mutex);
 
return ret;
-- 
2.7.4



[PATCH 1/2] platform/x86: wmi: release mutex on module acquistion failure

2017-11-05 Thread Mario Limonciello
This failure mode should have also released the mutex.

Signed-off-by: Mario Limonciello 
---
 drivers/platform/x86/wmi.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
index 8c31ed4..791449a 100644
--- a/drivers/platform/x86/wmi.c
+++ b/drivers/platform/x86/wmi.c
@@ -868,8 +868,10 @@ static long wmi_ioctl(struct file *filp, unsigned int cmd, 
unsigned long arg)
/* let the driver do any filtering and do the call */
wdriver = container_of(wblock->dev.dev.driver,
   struct wmi_driver, driver);
-   if (!try_module_get(wdriver->driver.owner))
-   return -EBUSY;
+   if (!try_module_get(wdriver->driver.owner)) {
+   ret = -EBUSY;
+   goto out_ioctl;
+   }
ret = wdriver->filter_callback(&wblock->dev, cmd, buf);
module_put(wdriver->driver.owner);
if (ret)
-- 
2.7.4



[PATCH 0/2] Correct some errors caught by buildbot

2017-11-05 Thread Mario Limonciello
Some of the failure scenarios weren't releasing acquired mutexes.
Here are some patches that correct them.

Mario Limonciello (2):
  platform/x86: wmi: release mutex on module acquistion failure
  platform/x86: dell-smbios-wmi: release mutex lock on WMI call failure

 drivers/platform/x86/dell-smbios-wmi.c | 7 +--
 drivers/platform/x86/wmi.c | 6 --
 2 files changed, 9 insertions(+), 4 deletions(-)

-- 
2.7.4



Re: [PATCH] powerpc: eeh: stop using do_gettimeofday()

2017-11-05 Thread Russell Currey
On Sat, 2017-11-04 at 22:26 +0100, Arnd Bergmann wrote:
> This interface is inefficient and deprecated because of the y2038
> overflow.
> 
> ktime_get_seconds() is an appropriate replacement here, since it
> has sufficient granularity but is more efficient and uses monotonic
> time.
> 
> Signed-off-by: Arnd Bergmann 

Acked-by: Russell Currey 


Re: possible deadlock in generic_file_write_iter

2017-11-05 Thread Al Viro
On Sun, Nov 05, 2017 at 02:25:00AM -0800, syzbot wrote:

> loop0/2986 is trying to acquire lock:
>  (&sb->s_type->i_mutex_key#9){}, at: [] inode_lock
> include/linux/fs.h:712 [inline]
>  (&sb->s_type->i_mutex_key#9){}, at: []
> generic_file_write_iter+0xdc/0x7a0 mm/filemap.c:3151
> 
> but now in release context of a crosslock acquired at the following:
>  ((complete)&ret.event){+.+.}, at: []
> submit_bio_wait+0x15e/0x200 block/bio.c:953
> 
> which lock already depends on the new lock.

Almost certainly a false positive...  lockdep can't tell ->i_rwsem of
inode on filesystem that lives on /dev/loop0 and that of inode of
the backing file of /dev/loop0.

Try and put them on different filesystem types and see if you still
can reproduce that.  We do have a partial ordering between the filesystems,
namely "(parts of) hosting device of X live in a file on Y".  It's
going to be acyclic, or you have a much worse problem.  And that's
what really orders the things here.


Re: [PATCH] powerpc: eeh: stop using do_gettimeofday()

2017-11-05 Thread Andrew Donnellan

On 05/11/17 08:26, Arnd Bergmann wrote:

This interface is inefficient and deprecated because of the y2038
overflow.

ktime_get_seconds() is an appropriate replacement here, since it
has sufficient granularity but is more efficient and uses monotonic
time.

Signed-off-by: Arnd Bergmann 


Reviewed-by: Andrew Donnellan 


---
  arch/powerpc/include/asm/eeh.h   | 2 +-
  arch/powerpc/kernel/eeh_driver.c | 2 +-
  arch/powerpc/kernel/eeh_pe.c | 8 
  3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/include/asm/eeh.h b/arch/powerpc/include/asm/eeh.h
index cd1df96335e5..5161c37dd039 100644
--- a/arch/powerpc/include/asm/eeh.h
+++ b/arch/powerpc/include/asm/eeh.h
@@ -93,7 +93,7 @@ struct eeh_pe {
struct pci_bus *bus;/* Top PCI bus for bus PE   */
int check_count;/* Times of ignored error   */
int freeze_count;   /* Times of froze up*/
-   struct timeval tstamp;  /* Time on first-time freeze*/
+   time64_t tstamp;/* Time on first-time freeze*/
int false_positives;/* Times of reported #ff's  */
atomic_t pass_dev_cnt;  /* Count of passed through devs */
struct eeh_pe *parent;  /* Parent PE*/
diff --git a/arch/powerpc/kernel/eeh_driver.c b/arch/powerpc/kernel/eeh_driver.c
index 4e1b433f6cb5..4f71e4c9beb7 100644
--- a/arch/powerpc/kernel/eeh_driver.c
+++ b/arch/powerpc/kernel/eeh_driver.c
@@ -623,7 +623,7 @@ static int eeh_reset_device(struct eeh_pe *pe, struct 
pci_bus *bus,
struct eeh_rmv_data *rmv_data)
  {
struct pci_bus *frozen_bus = eeh_pe_bus_get(pe);
-   struct timeval tstamp;
+   time64_t tstamp;
int cnt, rc;
struct eeh_dev *edev;
  
diff --git a/arch/powerpc/kernel/eeh_pe.c b/arch/powerpc/kernel/eeh_pe.c

index 2e8d1b2b5af4..2d4956e97aa9 100644
--- a/arch/powerpc/kernel/eeh_pe.c
+++ b/arch/powerpc/kernel/eeh_pe.c
@@ -526,16 +526,16 @@ int eeh_rmv_from_parent_pe(struct eeh_dev *edev)
   */
  void eeh_pe_update_time_stamp(struct eeh_pe *pe)
  {
-   struct timeval tstamp;
+   time64_t tstamp;
  
  	if (!pe) return;
  
  	if (pe->freeze_count <= 0) {

pe->freeze_count = 0;
-   do_gettimeofday(&pe->tstamp);
+   pe->tstamp = ktime_get_seconds();
} else {
-   do_gettimeofday(&tstamp);
-   if (tstamp.tv_sec - pe->tstamp.tv_sec > 3600) {
+   tstamp = ktime_get_seconds();
+   if (tstamp - pe->tstamp > 3600) {
pe->tstamp = tstamp;
pe->freeze_count = 0;
}



--
Andrew Donnellan  OzLabs, ADL Canberra
andrew.donnel...@au1.ibm.com  IBM Australia Limited



[PATCH] usb:xhci fix panic in xhci_free_virt_devices_depth_first

2017-11-05 Thread Yu Chen
From: Yu Chen 

Check vdev->real_port 0 to avoid panic
[9.261347] [] 
xhci_free_virt_devices_depth_first+0x58/0x108
[9.261352] [] xhci_mem_cleanup+0x1bc/0x570
[9.261355] [] xhci_stop+0x140/0x1c8
[9.261365] [] usb_remove_hcd+0xfc/0x1d0
[9.261369] [] xhci_plat_remove+0x6c/0xa8
[9.261377] [] platform_drv_remove+0x2c/0x70
[9.261384] [] __device_release_driver+0x80/0x108
[9.261387] [] device_release_driver+0x2c/0x40
[9.261392] [] bus_remove_device+0xe0/0x120
[9.261396] [] device_del+0x114/0x210
[9.261399] [] platform_device_del+0x30/0xa0
[9.261403] [] dwc3_otg_work+0x204/0x488
[9.261407] [] event_work+0x304/0x5b8
[9.261414] [] process_one_work+0x148/0x490
[9.261417] [] worker_thread+0x50/0x4a0
[9.261421] [] kthread+0xe8/0x100
[9.261427] [] ret_from_fork+0x10/0x50

The problem can occur if xhci_plat_remove() is called shortly after
xhci_plat_probe(). While xhci_free_virt_devices_depth_first been
called before the device has been setup and get real_port initialized.
The problem occurred on Hikey960 and was reproduced by Guenter Roeck
on Kevin with chromeos-4.4.

Cc: Guenter Roeck 
Signed-off-by: Fan Ning 
Signed-off-by: Li Rui 
Signed-off-by: yangdi 
Signed-off-by: Yu Chen 


---
 drivers/usb/host/xhci-mem.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 2a82c927ded2..295789d993b0 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -947,6 +947,11 @@ void xhci_free_virt_devices_depth_first(struct xhci_hcd 
*xhci, int slot_id)
if (!vdev)
return;
 
+   if (WARN_ON(!vdev->real_port)) {
+   xhci_warn(xhci, "Bad vdev->real_port\n");
+   goto out;
+   }
+
tt_list_head = &(xhci->rh_bw[vdev->real_port - 1].tts);
list_for_each_entry_safe(tt_info, next, tt_list_head, tt_list) {
/* is this a hub device that added a tt_info to the tts list */
@@ -960,6 +965,7 @@ void xhci_free_virt_devices_depth_first(struct xhci_hcd 
*xhci, int slot_id)
}
}
}
+out:
/* we are now at a leaf device */
xhci_free_virt_device(xhci, slot_id);
 }
-- 
2.15.0-rc2



[PATCH 0001/0001] format idle IP output func+offset/length

2017-11-05 Thread Liu, Changcheng
kaslr feature is enabled in kernel.
Remove kernel text address when dumping idle IP info

Signed-off-by: Liu Changcheng 
Signed-off-by: Jerry Liu 

diff --git a/lib/nmi_backtrace.c b/lib/nmi_backtrace.c
index 0bc0a35..9cc4178 100644
--- a/lib/nmi_backtrace.c
+++ b/lib/nmi_backtrace.c
@@ -92,7 +92,7 @@ bool nmi_cpu_backtrace(struct pt_regs *regs)
if (cpumask_test_cpu(cpu, to_cpumask(backtrace_mask))) {
arch_spin_lock(&lock);
if (regs && cpu_in_idle(instruction_pointer(regs))) {
-   pr_warn("NMI backtrace for cpu %d skipped: idling at pc %#lx\n",
+   pr_warn("NMI backtrace for cpu %d skipped: idling at pc %pS\n",
cpu, instruction_pointer(regs));
} else {
pr_warn("NMI backtrace for cpu %d\n", cpu);
-- 
2.7.4


[PATCH] lib/traceevent : clean up clang build warning

2017-11-05 Thread Cheng Jian
The uniform structure filter_arg sets its union based
on the difference of enum filter_arg_type, However,
some functions use implicit type conversion obviously.

warning: implicit conversion from enumeration type 'enum filter_exp_type'
 to different enumeration type 'enum filter_op_type'

warning: implicit conversion from enumeration type 'enum filter_cmp_type'
 to different enumeration type 'enum filter_exp_type'

Signed-off-by: Cheng Jian 
---
 tools/lib/traceevent/parse-filter.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/lib/traceevent/parse-filter.c 
b/tools/lib/traceevent/parse-filter.c
index 7c214ce..315df0a 100644
--- a/tools/lib/traceevent/parse-filter.c
+++ b/tools/lib/traceevent/parse-filter.c
@@ -436,13 +436,13 @@ static void free_events(struct event_list *events)
return NULL;
 
arg->type = FILTER_ARG_EXP;
-   arg->op.type = etype;
+   arg->exp.type = etype;
 
return arg;
 }
 
 static struct filter_arg *
-create_arg_cmp(enum filter_exp_type etype)
+create_arg_cmp(enum filter_cmp_type ctype)
 {
struct filter_arg *arg;
 
@@ -452,7 +452,7 @@ static void free_events(struct event_list *events)
 
/* Use NUM and change if necessary */
arg->type = FILTER_ARG_NUM;
-   arg->op.type = etype;
+   arg->num.type = ctype;
 
return arg;
 }
-- 
1.8.3.1



[PATCH] lib/traceevent : fix some issue in Makefile

2017-11-05 Thread Cheng Jian
From: gatieme 

There are several issues when building plugin_traceevent.

First, We can specify a directory compiled by OUTPUT,
but make clean ignores this and uses the current directory.

Second, It generate a dynamic link library
libtraceevent.so.$(EP_VERSION) with the version
number as a suffix, but it can't clean by the clean rules.

Finaly, The locale specified by the environment affects sort order.

$export LC_ALL=C
$echo "U w W" | tr ' ' '\n' | sort -u

U W w

$export LC_ALL="en_US.UTF-8"
$echo "U w W" | tr ' ' '\n' | sort -u

U w W

It will always show the next message when build on some machine
GEN  libtraceevent-dynamic-list
Either missing one of [ plugin_jbd2.so plugin_hrtimer.so
plugin_kmem.so plugin_kvm.so plugin_mac80211.so
plugin_sched_switch.so plugin_function.so plugin_xen.so
plugin_scsi.so plugin_cfg80211.so] or bad version of nm

So just use the LC_ALL=C (POSIX) default when sort.

Signed-off-by: Cheng Jian 
---
 tools/lib/traceevent/Makefile | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/lib/traceevent/Makefile b/tools/lib/traceevent/Makefile
index 46cd5f8..6ef1e28 100644
--- a/tools/lib/traceevent/Makefile
+++ b/tools/lib/traceevent/Makefile
@@ -259,7 +259,7 @@ endef
 
 define do_generate_dynamic_list_file
symbol_type=`$(NM) -u -D $1 | awk 'NF>1 {print $$1}' | \
-   xargs echo "U W w" | tr ' ' '\n' | sort -u | xargs echo`;\
+   xargs echo "U W w" | tr ' ' '\n' | env LC_ALL=C sort -u | xargs echo`;\
if [ "$$symbol_type" = "U W w" ];then   \
(echo '{';  \
$(NM) -u -D $1 | awk 'NF>1 {print "\t"$$2";"}' | sort -u;\
@@ -289,7 +289,8 @@ install: install_lib
 
 clean:
$(call QUIET_CLEAN, libtraceevent) \
-   $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd \
+   $(RM) $(OUTPUT)*.o *~ $(TARGETS) $(OUTPUT)*.a $(OUTPUT)*.so*
\
+   $(RM) $(VERSION_FILES) $(OUTPUT).*.d $(OUTPUT).*.cmd
\
$(RM) TRACEEVENT-CFLAGS tags TAGS
 
 PHONY += force plugins
-- 
1.8.3.1



Re: [PATCH 2/3] f2fs: trace checkpoint reason in fsync()

2017-11-05 Thread Chao Yu
On 2017/11/6 8:55, Jaegeuk Kim wrote:
> On 11/05, Chao Yu wrote:
>> From: Chao Yu 
>>
>> This patch slightly changes need_do_checkpoint to return the detail
>> info that indicates why we need do checkpoint, then caller could print
>> it with trace message.
>>
>> Signed-off-by: Chao Yu 
>> ---
>>  fs/f2fs/file.c  | 34 ++
>>  include/trace/events/f2fs.h | 12 ++--
>>  2 files changed, 24 insertions(+), 22 deletions(-)
>>
>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
>> index cee0f36ba9a1..d9d8b1c372f8 100644
>> --- a/fs/f2fs/file.c
>> +++ b/fs/f2fs/file.c
>> @@ -141,27 +141,29 @@ static int get_parent_ino(struct inode *inode, nid_t 
>> *pino)
>>  return 1;
>>  }
>>  
>> -static inline bool need_do_checkpoint(struct inode *inode)
>> +static inline int need_do_checkpoint(struct inode *inode)
>>  {
>>  struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
>> -bool need_cp = false;
>> +int cp_reason = 0;
>>  
>> -if (!S_ISREG(inode->i_mode) || inode->i_nlink != 1)
>> -need_cp = true;
>> +if (!S_ISREG(inode->i_mode))
>> +cp_reason = 1;
>> +else if (inode->i_nlink != 1)
>> +cp_reason = 2;
>>  else if (is_sbi_flag_set(sbi, SBI_NEED_CP))
>> -need_cp = true;
>> +cp_reason = 3;
>>  else if (file_wrong_pino(inode))
>> -need_cp = true;
>> +cp_reason = 4;
>>  else if (!space_for_roll_forward(sbi))
>> -need_cp = true;
>> +cp_reason = 5;
>>  else if (!is_checkpointed_node(sbi, F2FS_I(inode)->i_pino))
>> -need_cp = true;
>> +cp_reason = 6;
>>  else if (test_opt(sbi, FASTBOOT))
>> -need_cp = true;
>> +cp_reason = 7;
>>  else if (sbi->active_logs == 2)
>> -need_cp = true;
>> +cp_reason = 8;
> 
> We need to make the numbers by enum so that we could interpret them in 
> tracepoint
> below.

Agreed, could you check v2? :)

Thanks,

> 
> Thanks,
> 
>>  
>> -return need_cp;
>> +return cp_reason;
>>  }
>>  
>>  static bool need_inode_page_update(struct f2fs_sb_info *sbi, nid_t ino)
>> @@ -196,7 +198,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t 
>> start, loff_t end,
>>  struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
>>  nid_t ino = inode->i_ino;
>>  int ret = 0;
>> -bool need_cp = false;
>> +bool cp_reason = 0;
>>  struct writeback_control wbc = {
>>  .sync_mode = WB_SYNC_ALL,
>>  .nr_to_write = LONG_MAX,
>> @@ -215,7 +217,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t 
>> start, loff_t end,
>>  clear_inode_flag(inode, FI_NEED_IPU);
>>  
>>  if (ret) {
>> -trace_f2fs_sync_file_exit(inode, need_cp, datasync, ret);
>> +trace_f2fs_sync_file_exit(inode, cp_reason, datasync, ret);
>>  return ret;
>>  }
>>  
>> @@ -246,10 +248,10 @@ static int f2fs_do_sync_file(struct file *file, loff_t 
>> start, loff_t end,
>>   * sudden-power-off.
>>   */
>>  down_read(&F2FS_I(inode)->i_sem);
>> -need_cp = need_do_checkpoint(inode);
>> +cp_reason = need_do_checkpoint(inode);
>>  up_read(&F2FS_I(inode)->i_sem);
>>  
>> -if (need_cp) {
>> +if (cp_reason) {
>>  /* all the dirty node pages should be flushed for POR */
>>  ret = f2fs_sync_fs(inode->i_sb, 1);
>>  
>> @@ -306,7 +308,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t 
>> start, loff_t end,
>>  }
>>  f2fs_update_time(sbi, REQ_TIME);
>>  out:
>> -trace_f2fs_sync_file_exit(inode, need_cp, datasync, ret);
>> +trace_f2fs_sync_file_exit(inode, cp_reason, datasync, ret);
>>  f2fs_trace_ios(NULL, 1);
>>  return ret;
>>  }
>> diff --git a/include/trace/events/f2fs.h b/include/trace/events/f2fs.h
>> index 009745564214..f1a317e6db79 100644
>> --- a/include/trace/events/f2fs.h
>> +++ b/include/trace/events/f2fs.h
>> @@ -210,14 +210,14 @@ DEFINE_EVENT(f2fs__inode, f2fs_sync_file_enter,
>>  
>>  TRACE_EVENT(f2fs_sync_file_exit,
>>  
>> -TP_PROTO(struct inode *inode, int need_cp, int datasync, int ret),
>> +TP_PROTO(struct inode *inode, int cp_reason, int datasync, int ret),
>>  
>> -TP_ARGS(inode, need_cp, datasync, ret),
>> +TP_ARGS(inode, cp_reason, datasync, ret),
>>  
>>  TP_STRUCT__entry(
>>  __field(dev_t,  dev)
>>  __field(ino_t,  ino)
>> -__field(int,need_cp)
>> +__field(int,cp_reason)
>>  __field(int,datasync)
>>  __field(int,ret)
>>  ),
>> @@ -225,15 +225,15 @@ TRACE_EVENT(f2fs_sync_file_exit,
>>  TP_fast_assign(
>>  __entry->dev= inode->i_sb->s_dev;
>>  __entry->ino= inode->i_ino;
>> -__entry->need_cp= need_cp;
>> +__entry->cp_reason  = cp_reason;
>>  __entry->datasync   = datasync;
>> 

[PATCH v2 2/3] f2fs: trace checkpoint reason in fsync()

2017-11-05 Thread Chao Yu
This patch slightly changes need_do_checkpoint to return the detail
info that indicates why we need do checkpoint, then caller could print
it with trace message.

Signed-off-by: Chao Yu 
---
v2:
- add enum cp_reason_type for interpret detail reason in tracepoint.
 fs/f2fs/f2fs.h  | 12 
 fs/f2fs/file.c  | 34 ++
 include/trace/events/f2fs.h | 24 ++--
 3 files changed, 48 insertions(+), 22 deletions(-)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 05e8803923a5..8df2ce9a1356 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -914,6 +914,18 @@ enum need_lock_type {
LOCK_RETRY,
 };
 
+enum cp_reason_type {
+   CP_NO_NEEDED,
+   CP_NON_REGULAR,
+   CP_HARDLINK,
+   CP_SB_NEED_CP,
+   CP_WRONG_PINO,
+   CP_NO_SPC_ROLL,
+   CP_NODE_NEED_CP,
+   CP_FASTBOOT_MODE,
+   CP_SPEC_LOG_NUM,
+};
+
 enum iostat_type {
APP_DIRECT_IO,  /* app direct IOs */
APP_BUFFERED_IO,/* app buffered IOs */
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 5527cef9b8cb..96018c1ec0a1 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -146,27 +146,29 @@ static int get_parent_ino(struct inode *inode, nid_t 
*pino)
return 1;
 }
 
-static inline bool need_do_checkpoint(struct inode *inode)
+static inline enum cp_reason_type need_do_checkpoint(struct inode *inode)
 {
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
-   bool need_cp = false;
+   enum cp_reason_type cp_reason = CP_NO_NEEDED;
 
-   if (!S_ISREG(inode->i_mode) || inode->i_nlink != 1)
-   need_cp = true;
+   if (!S_ISREG(inode->i_mode))
+   cp_reason = CP_NON_REGULAR;
+   else if (inode->i_nlink != 1)
+   cp_reason = CP_HARDLINK;
else if (is_sbi_flag_set(sbi, SBI_NEED_CP))
-   need_cp = true;
+   cp_reason = CP_SB_NEED_CP;
else if (file_wrong_pino(inode))
-   need_cp = true;
+   cp_reason = CP_WRONG_PINO;
else if (!space_for_roll_forward(sbi))
-   need_cp = true;
+   cp_reason = CP_NO_SPC_ROLL;
else if (!is_checkpointed_node(sbi, F2FS_I(inode)->i_pino))
-   need_cp = true;
+   cp_reason = CP_NODE_NEED_CP;
else if (test_opt(sbi, FASTBOOT))
-   need_cp = true;
+   cp_reason = CP_FASTBOOT_MODE;
else if (sbi->active_logs == 2)
-   need_cp = true;
+   cp_reason = CP_SPEC_LOG_NUM;
 
-   return need_cp;
+   return cp_reason;
 }
 
 static bool need_inode_page_update(struct f2fs_sb_info *sbi, nid_t ino)
@@ -201,7 +203,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t 
start, loff_t end,
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
nid_t ino = inode->i_ino;
int ret = 0;
-   bool need_cp = false;
+   enum cp_reason_type cp_reason = 0;
struct writeback_control wbc = {
.sync_mode = WB_SYNC_ALL,
.nr_to_write = LONG_MAX,
@@ -233,7 +235,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t 
start, loff_t end,
clear_inode_flag(inode, FI_NEED_IPU);
 
if (ret) {
-   trace_f2fs_sync_file_exit(inode, need_cp, datasync, ret);
+   trace_f2fs_sync_file_exit(inode, cp_reason, datasync, ret);
return ret;
}
 
@@ -264,10 +266,10 @@ static int f2fs_do_sync_file(struct file *file, loff_t 
start, loff_t end,
 * sudden-power-off.
 */
down_read(&F2FS_I(inode)->i_sem);
-   need_cp = need_do_checkpoint(inode);
+   cp_reason = need_do_checkpoint(inode);
up_read(&F2FS_I(inode)->i_sem);
 
-   if (need_cp) {
+   if (cp_reason) {
/* all the dirty node pages should be flushed for POR */
time_begin = local_clock();
ret = f2fs_sync_fs(inode->i_sb, 1);
@@ -336,7 +338,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t 
start, loff_t end,
}
f2fs_update_time(sbi, REQ_TIME);
 out:
-   trace_f2fs_sync_file_exit(inode, need_cp, datasync, ret);
+   trace_f2fs_sync_file_exit(inode, cp_reason, datasync, ret);
f2fs_trace_ios(NULL, 1);
return ret;
 }
diff --git a/include/trace/events/f2fs.h b/include/trace/events/f2fs.h
index 009745564214..30d30399db02 100644
--- a/include/trace/events/f2fs.h
+++ b/include/trace/events/f2fs.h
@@ -136,6 +136,18 @@ TRACE_DEFINE_ENUM(CP_TRIMMED);
{ CP_UMOUNT,"Umount" }, \
{ CP_TRIMMED,   "Trimmed" })
 
+#define show_fsync_cpreason(type)  \
+   __print_symbolic(type,  \
+   { CP_NO_NEEDED, "no needed" },  \
+   { CP_NON_REGULAR,   "non regular" },\
+   

Re: [PATCH 2/4] x86, build: Add new paths for isolinux.bin and ldlinux.c32

2017-11-05 Thread Du, Changbin
Hi Ingo,
On Sun, Nov 05, 2017 at 10:33:53AM +0100, Ingo Molnar wrote:
> 
> * changbin...@intel.com  wrote:
> 
> > From: Changbin Du 
> > 
> > Recently I failed to build isoimage target, because the path of isolinux.bin
> > changed to /usr/xxx/ISOLINUX/isolinux.bin, as well as ldlinux.c32 which
> > changed to /usr/xxx/syslinux/modules/bios/ldlinux.c32.
> > 
> > This patch has a improvement of the file search:
> >   - Show a error message instead of silent fail.
> >   - Add above new paths.
> 
> How about:
> 
>   This patch improves the file search logic:
> - Show an error message instead of failing silently
> - Add the new paths listed above.
> 
> 
> > +   if [ $i = end -a -z "$isolinux" ] ; then
> > +   echo 'Need isolinux.bin, please install 
> > syslinux/isolinux'
> 
> How about:
> 
>   echo 'Need an isolinux.bin file, please install 
> syslinux/isolinux'
>
The new description is much better, will update. Thanks.

> Thanks,
> 
>   Ingo

-- 
Thanks,
Changbin Du


signature.asc
Description: PGP signature


Re: [PATCH 1/4] x86, build: Fact out fdimage/isoimage generation commands to standalone script

2017-11-05 Thread Du, Changbin
On Sun, Nov 05, 2017 at 10:32:08AM +0100, Ingo Molnar wrote:
> 
> A few spelling fixes:
> 
> in the title:
> 
> s/Fact out
>  /Factor out
> 
> * changbin...@intel.com  wrote:
> 
> > From: Changbin Du 
> > 
> > The build message for fdimage/isoimage are pretty unstructured. The raw
> > shell command blocks are printed. We can improve them as regular build
> > system messages. Besides, writing commands in shell script is much more
> > easier than in a Makefile.
> 
> s/much more easier
>  /much more easy
> 
> > 
> > See Ingo's suggestion here https://lkml.org/lkml/2017/10/31/124.
> > 
> > This patch fact out the commands used for fdimage/isoimage generation from
> > arch/x86/boot/Makefile to new script arch/x86/boot/genimage.sh. Then add a
> > new kbuild command 'genimage' which invokes the new script. All
> > fdimages/isoimage now is generated by call to 'genimage' with different
> > parameters.
> 
> s/fact out
>  /factors out
> 
> s/to new script
>   to a new script
> 
> s/Then add
>  /Then it adds
> 
> s/a new kbuild command 'genimage'
>  /the new 'genimage' kbuild command
> 
> s/All fdimages/isoimage now is generated by call to
>  /All fdimage/isoimage files are now generated by a call to
> 
Sorry for these grammar errors. I alwyas forgot to write complete sentences in
English. :)

> > +#   $3 - kernel bzImage file
> > +#   $4 - mtool configuration file
> > +#   $5 - kernel cmdline
> > +#   $6 - inird image file
> > +#
> 
> The new script is much easier to read!
> 
> Thanks,
> 
>   Ingo

-- 
Thanks,
Changbin Du


signature.asc
Description: PGP signature


Re: [PATCH v2] dwc: dra7xx: Print link state to console for debug

2017-11-05 Thread Faiz Abbas


On Monday 30 October 2017 02:18 PM, Faiz Abbas wrote:
> 
> 
> On Thursday 26 October 2017 01:29 PM, Faiz Abbas wrote:
>> David,
>>
>> On Thursday 19 October 2017 06:56 PM, David Laight wrote:
>>> From: Faiz Abbas
 Sent: 19 October 2017 14:09
 On Thursday 19 October 2017 06:13 PM, Faiz Abbas wrote:
> Enable support for printing the LTSSM link state for debugging PCI
> when link is down.
>
> Signed-off-by: Faiz Abbas 
> ---
> v2:
>  1. Changed dev_err() to dev_dbg()
>  2. Changed static char array to static const char * const
>  3. format changes
>
>  drivers/pci/dwc/pci-dra7xx.c | 48 
> 
>  1 file changed, 48 insertions(+)
>
> diff --git a/drivers/pci/dwc/pci-dra7xx.c b/drivers/pci/dwc/pci-dra7xx.c
> index 34427a6..0e70e77 100644
> --- a/drivers/pci/dwc/pci-dra7xx.c
> +++ b/drivers/pci/dwc/pci-dra7xx.c
> @@ -98,6 +98,45 @@ struct dra7xx_pcie_of_data {
>
>  #define to_dra7xx_pcie(x)dev_get_drvdata((x)->dev)
>
> +static const char * const state[] = {
> + "DETECT_QUIET",
>>> ...
> + "RCVRY_EQ3"
> +};
> +
>  static inline u32 dra7xx_pcie_readl(struct dra7xx_pcie *pcie, u32 offset)
>  {
>   return readl(pcie->base + offset);
> @@ -118,6 +157,15 @@ static int dra7xx_pcie_link_up(struct dw_pcie *pci)
>  {
>   struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pci);
>   u32 reg = dra7xx_pcie_readl(dra7xx, PCIECTRL_DRA7XX_CONF_PHY_CS);
> + u32 cmd_reg;
> + u32 ltssm_state;
> +
> + if (!(reg & LINK_UP)) {
> + cmd_reg = dra7xx_pcie_readl(dra7xx,
> + PCIECTRL_DRA7XX_CONF_DEVICE_CMD);
> + ltssm_state = (cmd_reg & GENMASK(7, 2)) >> 2;
> + dev_dbg(pci->dev, "Link state:%s\n", state[ltssm_state]);
>>>
>>> Hmmm... GENMASK leaves by hunting header files...> Why not (cmd_reg >> 2) & 
>>> 63 and explicitly define state[64]
>>> to guarantee that you never print anything worse than a NULL
>>> pointer.
>>
>> I'm not sure what you mean. Are you worried we might print something
>> outside the array bounds? How is this easier to decipher than GENMASK?
>>
>>>
> + }
>
>   return !!(reg & LINK_UP);
>  }
>

 I missed David's comment in v1. Will submit a new version. Please ignore.
>>>
>>> I've a 'neat' trick for generating strings that match constants.
>>> You can get the compiler to do all the work for you:
>>> (Assuming I've typed it correctly)
>>>
>>> #define LTSSM_DEFS(x) \
>>>   x(DETECT_QUIET) \
>>>   x(DETECT_ACT) \
>>> (continue for all the names)
>>>
>>> Define an enum with the named constants:
>>> #define X(name) LTSSM_STATE_##name,
>>> enum (LTSSM_DEFS(X) LTSSM_STATE_SIZE=64);
>>> #undef X
>>>
>>> Array of strings:
>>> #define X(name) [LTSSM_STATE_##name] = #name
>>> static const char * const state_names[LTSSM_STATE_SIZE] = { LTSSM_DEFS(X) };
>>> #undef X
>>>
>>> David
>>>
>>
>> So I implemented your idea and it looks like this:
>> http://pastebin.ubuntu.com/25821834/
>>
>> I don't know how much we gained by adding the trick. I still had to be
>> careful not to be off by 1 when writing the list. Plus we are never
>> saying anything like printk("%s", state[LTSSM_STATE_DETECT_QUIET]. Its a
>> register read which is used to index the list array.
>>
>> Thanks,
>> Faiz
>>
> 
> Gentle Ping.
> 
Ping Again.


Re: [PATCH] clk: meson: gxbb: fix wrong clock for SARADC

2017-11-05 Thread Yixun Lan
Hi Neil

On 11/05/17 00:40, Neil Armstrong wrote:
> Hi Yixun,
> 
> Le 04/11/2017 09:41, Yixun Lan a écrit :
>>
>>
>> On 11/04/17 02:17, Yixun Lan wrote:
>>> According to the datasheet, the clock gate bit for
>>> SARADC is bit[22] in Meson-GXBB/GXL series.
>>>
>>> Change-Id: Ic4fa58276d2a9ea273eef0a08541fc213ac5ac89
>>> Signed-off-by: Yixun Lan 
>>> ---
>>>  drivers/clk/meson/gxbb.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/clk/meson/gxbb.c b/drivers/clk/meson/gxbb.c
>>> index b2d1e8ed7152..4f5b535fcd12 100644
>>> --- a/drivers/clk/meson/gxbb.c
>>> +++ b/drivers/clk/meson/gxbb.c
>>> @@ -1139,7 +1139,6 @@ static MESON_GATE(gxbb_pl301, HHI_GCLK_MPEG0, 6);
>>>  static MESON_GATE(gxbb_periphs, HHI_GCLK_MPEG0, 7);
>>>  static MESON_GATE(gxbb_spicc, HHI_GCLK_MPEG0, 8);
>>>  static MESON_GATE(gxbb_i2c, HHI_GCLK_MPEG0, 9);
>>> -static MESON_GATE(gxbb_sar_adc, HHI_GCLK_MPEG0, 10);
>>>  static MESON_GATE(gxbb_smart_card, HHI_GCLK_MPEG0, 11);
>>>  static MESON_GATE(gxbb_rng0, HHI_GCLK_MPEG0, 12);
>>>  static MESON_GATE(gxbb_uart0, HHI_GCLK_MPEG0, 13);
>>> @@ -1149,6 +1148,7 @@ static MESON_GATE(gxbb_async_fifo, HHI_GCLK_MPEG0, 
>>> 16);
>>>  static MESON_GATE(gxbb_sdio, HHI_GCLK_MPEG0, 17);
>>>  static MESON_GATE(gxbb_abuf, HHI_GCLK_MPEG0, 18);
>>>  static MESON_GATE(gxbb_hiu_iface, HHI_GCLK_MPEG0, 19);
>>> +static MESON_GATE(gxbb_sar_adc, HHI_GCLK_MPEG0, 22);
>>>  static MESON_GATE(gxbb_assist_misc, HHI_GCLK_MPEG0, 23);
>>>  static MESON_GATE(gxbb_emmc_a, HHI_GCLK_MPEG0, 24);
>>>  static MESON_GATE(gxbb_emmc_b, HHI_GCLK_MPEG0, 25);
>>>
>> Hi Neil
>>  I assume you will take this via the clk-meson tree..
>> could you amend the commit msg and drop the 'Change-Id'?
>> (for other parts, please feel free to adjust if you see fit)
>>  thanks
> 
> Yes, I will push it as a fix.
> 
> Can you check if the saradc driver is still functional when applied ?
>
sorry, this isn't a correct fix.
please drop this one, and I will push another patch

> Neil
> 
>>
>> Yixun
>>
> 
> .
> 


[PATCH v6 2/2] watchdog: Add Spreadtrum watchdog driver

2017-11-05 Thread Eric Long
This patch adds the watchdog driver for Spreadtrum SC9860 platform.

Signed-off-by: Eric Long 
---
Changes since v5:
 - Modify the "irq" type as int type.
 - Delete unused api sprd_wdt_is_running().

Changes since v4:
 - Remove sprd_wdt_remove().
 - Add devm_add_action() for sprd_wdt_disable().

Changes since v3:
 - Update Kconfig SPRD_WATCHDOG help messages.
 - Correct the wrong spell words.
 - Rename SPRD_WDT_CNT_HIGH_VALUE as SPRD_WDT_CNT_HIGH_SHIFT.
 - Remove unused macor.
 - Update sprd_wdt_set_pretimeout() api.
 - Add wdt->wdd.timeout default value.
 - Use devm_watchdog_register_device() to register wdt device.
 - If module does not support NOWAYOUT, disable wdt when remove this driver.
 - Call sprd_wdt_disable() every wdt suspend.

Changes since v2:
 - Rename all the macors, add SPRD tag at the head of the macro names.
 - Rename SPRD_WDT_CLK as SPRD_WTC_CNT_STEP.
 - Remove the code which check timeout value at the wrong place.
 - Add min/max timeout value limit.
 - Remove set WDOG_HW_RUNNING status at sprd_wdt_enable().
 - Add timeout/pretimeout judgment when set them.
 - Support WATCHDOG_NOWAYOUT status.

Changes since v1:
 - Use pretimeout instead of own implementation.
 - Fix timeout loop when loading timeout values.
 - use the infrastructure to read and set "timeout-sec" property.
 - Add conditions when start or stop watchdog.
 - Change the position of enabling watchdog.
 - Other optimization.
---
 drivers/watchdog/Kconfig|   8 +
 drivers/watchdog/Makefile   |   1 +
 drivers/watchdog/sprd_wdt.c | 399 
 3 files changed, 408 insertions(+)
 create mode 100644 drivers/watchdog/sprd_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index c722cbf..3367a8c 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -787,6 +787,14 @@ config UNIPHIER_WATCHDOG
  To compile this driver as a module, choose M here: the
  module will be called uniphier_wdt.
 
+config SPRD_WATCHDOG
+   tristate "Spreadtrum watchdog support"
+   depends on ARCH_SPRD || COMPILE_TEST
+   select WATCHDOG_CORE
+   help
+ Say Y here to include watchdog timer supported
+ by Spreadtrum system.
+
 # AVR32 Architecture
 
 config AT32AP700X_WDT
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 56adf9f..187cca2 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -87,6 +87,7 @@ obj-$(CONFIG_ASPEED_WATCHDOG) += aspeed_wdt.o
 obj-$(CONFIG_ZX2967_WATCHDOG) += zx2967_wdt.o
 obj-$(CONFIG_STM32_WATCHDOG) += stm32_iwdg.o
 obj-$(CONFIG_UNIPHIER_WATCHDOG) += uniphier_wdt.o
+obj-$(CONFIG_SPRD_WATCHDOG) += sprd_wdt.o
 
 # AVR32 Architecture
 obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o
diff --git a/drivers/watchdog/sprd_wdt.c b/drivers/watchdog/sprd_wdt.c
new file mode 100644
index 000..a8b280f
--- /dev/null
+++ b/drivers/watchdog/sprd_wdt.c
@@ -0,0 +1,399 @@
+/*
+ * Spreadtrum watchdog driver
+ * Copyright (C) 2017 Spreadtrum - http://www.spreadtrum.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define SPRD_WDT_LOAD_LOW  0x0
+#define SPRD_WDT_LOAD_HIGH 0x4
+#define SPRD_WDT_CTRL  0x8
+#define SPRD_WDT_INT_CLR   0xc
+#define SPRD_WDT_INT_RAW   0x10
+#define SPRD_WDT_INT_MSK   0x14
+#define SPRD_WDT_CNT_LOW   0x18
+#define SPRD_WDT_CNT_HIGH  0x1c
+#define SPRD_WDT_LOCK  0x20
+#define SPRD_WDT_IRQ_LOAD_LOW  0x2c
+#define SPRD_WDT_IRQ_LOAD_HIGH 0x30
+
+/* WDT_CTRL */
+#define SPRD_WDT_INT_EN_BITBIT(0)
+#define SPRD_WDT_CNT_EN_BITBIT(1)
+#define SPRD_WDT_NEW_VER_ENBIT(2)
+#define SPRD_WDT_RST_EN_BITBIT(3)
+
+/* WDT_INT_CLR */
+#define SPRD_WDT_INT_CLEAR_BIT BIT(0)
+#define SPRD_WDT_RST_CLEAR_BIT BIT(3)
+
+/* WDT_INT_RAW */
+#define SPRD_WDT_INT_RAW_BIT   BIT(0)
+#define SPRD_WDT_RST_RAW_BIT   BIT(3)
+#define SPRD_WDT_LD_BUSY_BIT   BIT(4)
+
+/* 1s equal to 32768 counter steps */
+#define SPRD_WDT_CNT_STEP  32768
+
+#define SPRD_WDT_UNLOCK_KEY0xe551
+#define SPRD_WDT_MIN_TIMEOUT   3
+#define SPRD_WDT_MAX_TIMEOUT   60
+
+#define SPRD_WDT_CNT_HIGH_SHIFT16
+#define SPRD_WDT_LOW_VALUE_MASKGENMASK(15, 0)
+#define SPRD_WDT_LOAD_TIMEOUT  1000
+
+struct

linux-next: manual merge of the kvm-arm tree with Linus' tree

2017-11-05 Thread Stephen Rothwell
Hi all,

Today's linux-next merge of the kvm-arm tree got a conflict in:

  arch/arm64/kvm/inject_fault.c

between commit:

  fd6c8c206fc5 ("arm/arm64: KVM: set right LR register value for 32 bit guest 
when inject abort")

from Linus' tree and commit:

  00586cdaf597 ("KVM: arm/arm64: Unify 32bit fault injection")

from the kvm-arm tree.

I fixed it up (I just used the latter) and can carry the fix as
necessary. This is now fixed as far as linux-next is concerned, but any
non trivial conflicts should be mentioned to your upstream maintainer
when your tree is submitted for merging.  You may also want to consider
cooperating with the maintainer of the conflicting tree to minimise any
particularly complex conflicts.

-- 
Cheers,
Stephen Rothwell


[PATCH v6 1/2] dt-bindings: watchdog: Add Spreadtrum watchdog documentation

2017-11-05 Thread Eric Long
This patch adds the documentation for Spreadtrum watchdog driver.

Signed-off-by: Eric Long 
Acked-by: Rob Herring 
---
Changes since v5:
- No updates.

Changes since v4:
- No updates.

Changes since v3:
- No updates.

Changes since v2:
- Add acked tag from Rob.

Changes since v1:
- No updates.
---
 .../devicetree/bindings/watchdog/sprd-wdt.txt | 19 +++
 1 file changed, 19 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/watchdog/sprd-wdt.txt

diff --git a/Documentation/devicetree/bindings/watchdog/sprd-wdt.txt 
b/Documentation/devicetree/bindings/watchdog/sprd-wdt.txt
new file mode 100644
index 000..aeaf3e0
--- /dev/null
+++ b/Documentation/devicetree/bindings/watchdog/sprd-wdt.txt
@@ -0,0 +1,19 @@
+Spreadtrum SoCs Watchdog timer
+
+Required properties:
+- compatible : Should be "sprd,sp9860-wdt".
+- reg : Specifies base physical address and size of the registers.
+- interrupts : Exactly one interrupt specifier.
+- timeout-sec : Contain the default watchdog timeout in seconds.
+- clock-names : Contain the input clock names.
+- clocks : Phandles to input clocks.
+
+Example:
+   watchdog: watchdog@4031 {
+   compatible = "sprd,sp9860-wdt";
+   reg = <0 0x4031 0 0x1000>;
+   interrupts = ;
+   timeout-sec = <12>;
+   clock-names = "enable", "rtc_enable";
+   clocks = <&clk_aon_apb_gates1 8>, <&clk_aon_apb_rtc_gates 9>;
+   };
-- 
1.9.1



linux-next: manual merge of the kvm-arm tree with Linus' tree

2017-11-05 Thread Stephen Rothwell
Hi all,

Today's linux-next merge of the kvm-arm tree got a conflict in:

  arch/arm/kvm/emulate.c

between commit:

  fd6c8c206fc5 ("arm/arm64: KVM: set right LR register value for 32 bit guest 
when inject abort")

from Linus' tree and commit:

  00586cdaf597 ("KVM: arm/arm64: Unify 32bit fault injection")

from the kvm-arm tree.

I fixed it up (I just used the latter version) and can carry the fix as
necessary. This is now fixed as far as linux-next is concerned, but any
non trivial conflicts should be mentioned to your upstream maintainer
when your tree is submitted for merging.  You may also want to consider
cooperating with the maintainer of the conflicting tree to minimise any
particularly complex conflicts.

-- 
Cheers,
Stephen Rothwell


Re: [PATCH] x86/kexec: Exclude GART aperture from vmcore

2017-11-05 Thread Baoquan He
Hi Jiri,

On 11/03/17 at 06:28pm, Jiri Bohac wrote:
> On machines where the GART aperture is mapped over physical RAM
> /proc/vmcore contains the remapped range and reading it may
> cause hangs or reboots. This range needs to be excluded from /proc/vmcore.
> 
> This has originally been implemented by commit dd5f726076cc ("kexec:
> support for kexec on panic using new system call").
> 
> The implementation relied on the GART code adding an iomem_resource for
> this range called "GART", as implemented by commit 56dd669a138c ("[PATCH]
> Insert GART region into resource map")
> 
> However, inserting the iomem_resource from the early GART code caused
> resource conflicts with some AGP drivers (bko#72201), which got avoided by
> reverting the patch in commit 707d4eefbdb3 ("Revert [PATCH] Insert GART
> region into resource map"). This revert introduced the /proc/vmcore bug.
> 
> With the "GART" iomem_resource removed, the defunct code in crash.c has
> been removed by commit f296f2634920 ("x86/kexec: Remove walk_iomem_res()
> call with GART type")

Is this reproduced on a machine with GART existing and passing test with
this patch applied? Do you have a /proc/iomem printing about the machine
you are testing on?

If this patch works, then I am wondering how we shold deal with the old
way in which no '-s' is specified. Since no GART information is exported
to /proc/iomem.

Do we have a way to pick GART region away from iomem_resource to not let
the aperture seen from /proc/iomem?

Thanks
Baoquan

> 
> The patch below stores the location of the GART region in two variables
> (named gart_stolen_ram_start and gart_stolen_ram_end) and reverts/adapts
> parts of f296f2634920 to exclude the region from /proc/vmcore.
> 
> Passing the information via an iomem_resource (or by reserving the range
> in the e820, which would propagate into an iomem_resource) would
> reintroduce bko#72201.
> 
> Signed-off-by: Jiri Bohac 
> Fixes: 707d4eefbdb3 ("Revert [PATCH] Insert GART region into resource map")
> 
> diff --git a/arch/x86/include/asm/gart.h b/arch/x86/include/asm/gart.h
> index 1d268098ac2e..324a0a19d166 100644
> --- a/arch/x86/include/asm/gart.h
> +++ b/arch/x86/include/asm/gart.h
> @@ -2,6 +2,7 @@
>  #define _ASM_X86_GART_H
>  
>  #include 
> +#include 
>  
>  extern void set_up_gart_resume(u32, u32);
>  
> @@ -33,6 +34,8 @@ extern int fix_aperture;
>  extern int gart_iommu_aperture;
>  extern int gart_iommu_aperture_allowed;
>  extern int gart_iommu_aperture_disabled;
> +extern u32 gart_stolen_ram_start;
> +extern u32 gart_stolen_ram_end;
>  
>  extern void early_gart_iommu_check(void);
>  extern int gart_iommu_init(void);
> @@ -43,6 +46,8 @@ extern int gart_iommu_hole_init(void);
>  #define gart_iommu_aperture0
>  #define gart_iommu_aperture_allowed0
>  #define gart_iommu_aperture_disabled   1
> +#define gart_stolen_ram_start   0
> +#define gart_stolen_ram_end 0
>  
>  static inline void early_gart_iommu_check(void)
>  {
> diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
> index ef2859f9fcce..bc9a9b5b88e3 100644
> --- a/arch/x86/kernel/aperture_64.c
> +++ b/arch/x86/kernel/aperture_64.c
> @@ -49,6 +49,8 @@
>  int gart_iommu_aperture;
>  int gart_iommu_aperture_disabled __initdata;
>  int gart_iommu_aperture_allowed __initdata;
> +u32 gart_stolen_ram_start;
> +u32 gart_stolen_ram_end;
>  
>  int fallback_aper_order __initdata = 1; /* 64MB */
>  int fallback_aper_force __initdata;
> @@ -87,6 +89,9 @@ static u32 __init allocate_aperture(void)
>   register_nosave_region(addr >> PAGE_SHIFT,
>  (addr+aper_size) >> PAGE_SHIFT);
>  
> + gart_stolen_ram_start = (u32)addr;
> + gart_stolen_ram_end = (u32)addr + aper_size - 1;
> +
>   return (u32)addr;
>  }
>  
> diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
> index 44404e2307bb..ce065d72656d 100644
> --- a/arch/x86/kernel/crash.c
> +++ b/arch/x86/kernel/crash.c
> @@ -37,6 +37,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  /* Alignment required for elf header segment */
>  #define ELF_CORE_HEADER_ALIGN   4096
> @@ -58,7 +59,7 @@ struct crash_elf_data {
>   struct kimage *image;
>   /*
>* Total number of ram ranges we have after various adjustments for
> -  * crash reserved region, etc.
> +  * GART, crash reserved region etc.
>*/
>   unsigned int max_nr_ranges;
>  
> @@ -217,7 +218,6 @@ static int get_nr_ram_ranges_callback(u64 start, u64 end, 
> void *arg)
>   return 0;
>  }
>  
> -
>  /* Gather all the required information to prepare elf headers for ram 
> regions */
>  static void fill_up_crash_elf_data(struct crash_elf_data *ced,
>  struct kimage *image)
> @@ -231,6 +231,15 @@ static void fill_up_crash_elf_data(struct crash_elf_data 
> *ced,
>  
>   ced->max_nr_ranges = nr_ranges;
>  
> + /*
> +  * We don't create ELF headers for GART aperture as an attempt
> +  

Re: [PATCH v16 5/6] vfio: ABI for mdev display dma-buf operation

2017-11-05 Thread Alex Williamson
On Mon,  6 Nov 2017 10:19:17 +0800
Tina Zhang  wrote:

> Add VFIO_DEVICE_QUERY_GFX_PLANE ioctl command to let user query and get
> a plane and its related information. So far, two types of buffers are
> supported: buffers based on dma-buf and buffers based on region.
> 
> This ioctl can be invoked with:
> 1) either DMABUF or REGION flag. Vendor driver returns a plane_info
> successfully only when the specific kind of buffer is supported.
> 2) flag PROBE. And at the same time either DMABUF or REGION must be set,
> so that vendor driver can return success only when the specific kind of
> buffer is supported.
> 
> Add VFIO_DEVICE_GET_GFX_DMABUF ioctl command to let user get an exposed
> dma-buf fd of a specific dmabuf_id which was returned in VFIO_DEVICE_QUERY
> _GFX_PLANE ioctl command.
> 
> The life cycle of an exposed MDEV buffer is handled by userspace and
> tracked by kernel space. The returned dmabuf_id in struct vfio_device_
> query_gfx_plane can be a new id of a new exposed buffer or an old id of
> a re-exported buffer. Host user can check the value of dmabuf_id to see
> if it needs to create new resources according to the new exposed buffer
> or just re-use the existing resource related to the old buffer.
> 
> v16:
> - add x_hot and y_hot fields. (Gerd)
> - add comments for VFIO_DEVICE_GET_GFX_DMABUF. (Alex)
> - rebase to 4.14.0-rc6.
> 
> v15:
> - add a ioctl to get a dmabuf for a given dmabuf id. (Gerd)
> 
> v14:
> - add PROBE, DMABUF and REGION flags. (Alex)
> 
> v12:
> - add drm_format_mod back. (Gerd and Zhenyu)
> - add region_index. (Gerd)
> 
> v11:
> - rename plane_type to drm_plane_type. (Gerd)
> - move fields of vfio_device_query_gfx_plane to vfio_device_gfx_plane_info.
>   (Gerd)
> - remove drm_format_mod, start fields. (Daniel)
> - remove plane_id.
> 
> v10:
> - refine the ABI API VFIO_DEVICE_QUERY_GFX_PLANE. (Alex) (Gerd)
> 
> v3:
> - add a field gvt_plane_info in the drm_i915_gem_obj structure to save
>   the decoded plane information to avoid look up while need the plane
>   info. (Gerd)
> 
> Signed-off-by: Tina Zhang 
> Cc: Gerd Hoffmann 
> Cc: Alex Williamson 
> Cc: Daniel Vetter 
> ---
>  include/uapi/linux/vfio.h | 68 
> +++
>  1 file changed, 68 insertions(+)
> 
> diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
> index ae46105..6c55668 100644
> --- a/include/uapi/linux/vfio.h
> +++ b/include/uapi/linux/vfio.h
> @@ -502,6 +502,74 @@ struct vfio_pci_hot_reset {
>  
>  #define VFIO_DEVICE_PCI_HOT_RESET_IO(VFIO_TYPE, VFIO_BASE + 13)
>  
> +/**
> + * VFIO_DEVICE_QUERY_GFX_PLANE - _IOW(VFIO_TYPE, VFIO_BASE + 14,
> + *struct vfio_device_query_gfx_plane)
> + *
> + * Set the drm_plane_type and flags, then retrieve the gfx plane info.
> + *
> + * flags supported:
> + * - VFIO_GFX_PLANE_TYPE_PROBE and VFIO_GFX_PLANE_TYPE_DMABUF are set
> + *   to ask if the mdev supports dma-buf. 0 on support, -EINVAL on no
> + *   support for dma-buf.
> + * - VFIO_GFX_PLANE_TYPE_PROBE and VFIO_GFX_PLANE_TYPE_REGION are set
> + *   to ask if the mdev supports region. 0 on support, -EINVAL on no
> + *   support for region.
> + * - VFIO_GFX_PLANE_TYPE_DMABUF or VFIO_GFX_PLANE_TYPE_REGION is set
> + *   with each call to query the plane info.
> + * - Others are invalid and return -EINVAL.
> + *
> + * Return: 0 on success, -ENODEV with all out fields zero on mdev
> + * device initialization, -errno on other failure.
> + */
> +struct vfio_device_gfx_plane_info {
> + __u32 argsz;
> + __u32 flags;
> +#define VFIO_GFX_PLANE_TYPE_PROBE (1 << 0)
> +#define VFIO_GFX_PLANE_TYPE_DMABUF (1 << 1)
> +#define VFIO_GFX_PLANE_TYPE_REGION (1 << 2)
> + /* in */
> + __u32 drm_plane_type;   /* type of plane: DRM_PLANE_TYPE_* */
> + /* out */
> + __u32 drm_format;   /* drm format of plane */
> + __u64 drm_format_mod;   /* tiled mode */
> + __u32 width;/* width of plane */
> + __u32 height;   /* height of plane */
> + __u32 stride;   /* stride of plane */
> + __u32 size; /* size of plane in bytes, align on page*/
> + __u32 x_pos;/* horizontal position of cursor plane */
> + __u32 y_pos;/* vertical position of cursor plane*/
> + __u32 x_hot;/* horizontal position of cursor hotspot */
> + __u32 y_hot;/* vertical position of cursor hotspot */
> + union {
> + __u32 region_index; /* region index */
> + __u32 dmabuf_id;/* dma-buf id */
> + };
> +};
> +
> +#define VFIO_DEVICE_QUERY_GFX_PLANE _IO(VFIO_TYPE, VFIO_BASE + 14)
> +
> +/**
> + * VFIO_DEVICE_GET_GFX_DMABUF - _IOW(VFIO_TYPE, VFIO_BASE + 15,
> + *   struct vfio_device_gfx_dmabuf_fd)
> + *
> + * Retrieve dmabuf_fd of an exposed guest framebuffer referenced by dmabuf_id
> + * which is returned from VFIO_DEVICE_QUERY_GFX_PLANE as a token of the
> + * exposed guest framebuffer.
> + *
> + * Return: 0 on success, -errno on failure.

[PATCH v11 06/12] x86/cpufeature: Add User-Mode Instruction Prevention definitions

2017-11-05 Thread Ricardo Neri
User-Mode Instruction Prevention is a security feature present in new
Intel processors that, when set, prevents the execution of a subset of
instructions if such instructions are executed in user mode (CPL > 0).
Attempting to execute such instructions causes a general protection
exception.

The subset of instructions comprises:

 * SGDT - Store Global Descriptor Table
 * SIDT - Store Interrupt Descriptor Table
 * SLDT - Store Local Descriptor Table
 * SMSW - Store Machine Status Word
 * STR  - Store Task Register

This feature is also added to the list of disabled-features to allow
a cleaner handling of build-time configuration.

Cc: Andy Lutomirski 
Cc: Andrew Morton 
Cc: H. Peter Anvin 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chen Yucong 
Cc: Chris Metcalf 
Cc: Dave Hansen 
Cc: Fenghua Yu 
Cc: Huang Rui 
Cc: Jiri Slaby 
Cc: Jonathan Corbet 
Cc: Michael S. Tsirkin 
Cc: Paul Gortmaker 
Cc: Peter Zijlstra 
Cc: Ravi V. Shankar 
Cc: Shuah Khan 
Cc: Vlastimil Babka 
Cc: Tony Luck 
Cc: Paolo Bonzini 
Cc: x...@kernel.org
Reviewed-by: Borislav Petkov 
Signed-off-by: Ricardo Neri 
---
 arch/x86/include/asm/cpufeatures.h  | 1 +
 arch/x86/include/asm/disabled-features.h| 8 +++-
 arch/x86/include/uapi/asm/processor-flags.h | 2 ++
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/cpufeatures.h 
b/arch/x86/include/asm/cpufeatures.h
index cdf5be8..c0b0e9e 100644
--- a/arch/x86/include/asm/cpufeatures.h
+++ b/arch/x86/include/asm/cpufeatures.h
@@ -296,6 +296,7 @@
 
 /* Intel-defined CPU features, CPUID level 0x0007:0 (ECX), word 16 */
 #define X86_FEATURE_AVX512VBMI (16*32+ 1) /* AVX512 Vector Bit 
Manipulation instructions*/
+#define X86_FEATURE_UMIP   (16*32+ 2) /* User Mode Instruction 
Protection */
 #define X86_FEATURE_PKU(16*32+ 3) /* Protection Keys 
for Userspace */
 #define X86_FEATURE_OSPKE  (16*32+ 4) /* OS Protection Keys Enable 
*/
 #define X86_FEATURE_AVX512_VBMI2   (16*32+ 6) /* Additional AVX512 Vector 
Bit Manipulation Instructions */
diff --git a/arch/x86/include/asm/disabled-features.h 
b/arch/x86/include/asm/disabled-features.h
index c10c912..14d6d50 100644
--- a/arch/x86/include/asm/disabled-features.h
+++ b/arch/x86/include/asm/disabled-features.h
@@ -16,6 +16,12 @@
 # define DISABLE_MPX   (1<<(X86_FEATURE_MPX & 31))
 #endif
 
+#ifdef CONFIG_X86_INTEL_UMIP
+# define DISABLE_UMIP  0
+#else
+# define DISABLE_UMIP  (1<<(X86_FEATURE_UMIP & 31))
+#endif
+
 #ifdef CONFIG_X86_64
 # define DISABLE_VME   (1<<(X86_FEATURE_VME & 31))
 # define DISABLE_K6_MTRR   (1<<(X86_FEATURE_K6_MTRR & 31))
@@ -63,7 +69,7 @@
 #define DISABLED_MASK130
 #define DISABLED_MASK140
 #define DISABLED_MASK150
-#define DISABLED_MASK16(DISABLE_PKU|DISABLE_OSPKE|DISABLE_LA57)
+#define DISABLED_MASK16
(DISABLE_PKU|DISABLE_OSPKE|DISABLE_LA57|DISABLE_UMIP)
 #define DISABLED_MASK170
 #define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 18)
 
diff --git a/arch/x86/include/uapi/asm/processor-flags.h 
b/arch/x86/include/uapi/asm/processor-flags.h
index 53b4ca5..7e1e730 100644
--- a/arch/x86/include/uapi/asm/processor-flags.h
+++ b/arch/x86/include/uapi/asm/processor-flags.h
@@ -105,6 +105,8 @@
 #define X86_CR4_OSFXSR _BITUL(X86_CR4_OSFXSR_BIT)
 #define X86_CR4_OSXMMEXCPT_BIT 10 /* enable unmasked SSE exceptions */
 #define X86_CR4_OSXMMEXCPT _BITUL(X86_CR4_OSXMMEXCPT_BIT)
+#define X86_CR4_UMIP_BIT   11 /* enable UMIP support */
+#define X86_CR4_UMIP   _BITUL(X86_CR4_UMIP_BIT)
 #define X86_CR4_LA57_BIT   12 /* enable 5-level page tables */
 #define X86_CR4_LA57   _BITUL(X86_CR4_LA57_BIT)
 #define X86_CR4_VMXE_BIT   13 /* enable VMX virtualization */
-- 
2.7.4



[PATCH v11 01/12] x86/insn-eval: Compute linear address in several utility functions

2017-11-05 Thread Ricardo Neri
Computing a linear address involves several steps. The first step is to
compute the effective address. This requires determining the addressing
mode in use and perform arithmetic operations on the operands. Plus, each
addressing mode has special cases that must be handled.

Once the effective address is known, the base address of the applicable
segment is added to obtain the linear address.

Clearly, this is too much work for a single function. Instead, handle each
addressing mode in a separate utility function. This improves readability
and gives us the opportunity to handler errors better.

At the moment, arithmetic to compute the effective address uses 64-byte
variables. Thus, limit support to 64-bit addresses.

While reworking the function insn_get_addr_ref(), the variable addr_offset
is renamed as regoff to reflect its actual use (i.e., offset, from the
base of pt_regs, of the register used as operand).

Cc: Dave Hansen 
Cc: Adam Buchbinder 
Cc: Colin Ian King 
Cc: Lorenzo Stoakes 
Cc: Qiaowei Ren 
Cc: Arnaldo Carvalho de Melo 
Cc: Masami Hiramatsu 
Cc: Adrian Hunter 
Cc: Kees Cook 
Cc: Thomas Garnier 
Cc: Peter Zijlstra 
Cc: Borislav Petkov 
Cc: Dmitry Vyukov 
Cc: Tony Luck 
Cc: Ravi V. Shankar 
Cc: x...@kernel.org
Suggested-by: Borislav Petkov 
Signed-off-by: Ricardo Neri 
---
 arch/x86/lib/insn-eval.c | 243 ---
 1 file changed, 185 insertions(+), 58 deletions(-)

diff --git a/arch/x86/lib/insn-eval.c b/arch/x86/lib/insn-eval.c
index 91f08aa..a4427b4 100644
--- a/arch/x86/lib/insn-eval.c
+++ b/arch/x86/lib/insn-eval.c
@@ -776,6 +776,182 @@ static int get_seg_base_limit(struct insn *insn, struct 
pt_regs *regs,
return 0;
 }
 
+/**
+ * get_eff_addr_reg() - Obtain effective address from register operand
+ * @insn:  Instruction. Must be valid.
+ * @regs:  Register values as seen when entering kernel mode
+ * @regoff:Obtained operand offset, in pt_regs, with the effective address
+ * @eff_addr:  Obtained effective address
+ *
+ * Obtain the effective address stored in the register operand as indicated by
+ * the ModRM byte. This function is to be used only with register addressing
+ * (i.e.,  ModRM.mod is 3). The effective address is saved in @eff_addr. The
+ * register operand, as an offset from the base of pt_regs, is saved in 
@regoff;
+ * such offset can then be used to resolve the segment associated with the
+ * operand. This function can be used with any of the supported address sizes
+ * in x86.
+ *
+ * Returns:
+ *
+ * 0 on success. @eff_addr will have the effective address stored in the
+ * operand indicated by ModRM. @regoff will have such operand as an offset from
+ * the base of pt_regs.
+ *
+ * -EINVAL on error.
+ */
+static int get_eff_addr_reg(struct insn *insn, struct pt_regs *regs,
+   int *regoff, long *eff_addr)
+{
+   insn_get_modrm(insn);
+
+   if (!insn->modrm.nbytes)
+   return -EINVAL;
+
+   if (X86_MODRM_MOD(insn->modrm.value) != 3)
+   return -EINVAL;
+
+   *regoff = get_reg_offset(insn, regs, REG_TYPE_RM);
+   if (*regoff < 0)
+   return -EINVAL;
+
+   *eff_addr = regs_get_register(regs, *regoff);
+
+   return 0;
+}
+
+/**
+ * get_eff_addr_modrm() - Obtain referenced effective address via ModRM
+ * @insn:  Instruction. Must be valid.
+ * @regs:  Register values as seen when entering kernel mode
+ * @regoff:Obtained operand offset, in pt_regs, associated with segment
+ * @eff_addr:  Obtained effective address
+ *
+ * Obtain the effective address referenced by the ModRM byte of @insn. After
+ * identifying the registers involved in the register-indirect memory 
reference,
+ * its value is obtained from the operands in @regs. The computed address is
+ * stored @eff_addr. Also, the register operand that indicates the associated
+ * segment is stored in @regoff, this parameter can later be used to determine
+ * such segment.
+ *
+ * Returns:
+ *
+ * 0 on success. @eff_addr will have the referenced effective address. @regoff
+ * will have a register, as an offset from the base of pt_regs, that can be 
used
+ * to resolve the associated segment.
+ *
+ * -EINVAL on error.
+ */
+static int get_eff_addr_modrm(struct insn *insn, struct pt_regs *regs,
+ int *regoff, long *eff_addr)
+{
+   long tmp;
+
+   if (insn->addr_bytes != 8)
+   return -EINVAL;
+
+   insn_get_modrm(insn);
+
+   if (!insn->modrm.nbytes)
+   return -EINVAL;
+
+   if (X86_MODRM_MOD(insn->modrm.value) > 2)
+   return -EINVAL;
+
+   *regoff = get_reg_offset(insn, regs, REG_TYPE_RM);
+
+   /*
+* -EDOM means that we must ignore the address_offset. In such a case,
+* in 64-bit mode the effective address relative to the rIP of the
+* following instruction.
+*/
+   if (*regoff == -EDOM) {
+   if (user_64bit_mode(regs))
+

[PATCH v11 02/12] x86/insn-eval: Add support to resolve 32-bit address encodings

2017-11-05 Thread Ricardo Neri
32-bit and 64-bit address encodings are identical. Thus, the same logic
could be used to resolve the effective address. However, there are two key
differences: address size and enforcement of segment limits.

If running a 32-bit process on a 64-bit kernel, it is best to perform
the address calculation using 32-bit data types. In this manner hardware
is used for the arithmetic, including handling of signs and overflows.

32-bit addresses are generally used in protected mode; segment limits are
enforced in this mode. This implementation obtains the limit of the
segment associated with the instruction operands and prefixes. If the
computed address is outside the segment limits, an error is returned. It
is also possible to use 32-bit address in long mode and virtual-8086 mode
by using an address override prefix. In such cases, segment limits are not
enforced.

Support to use 32-bit arithmetic is added to the utility functions that
compute effective addresses. However, the end result is stored in a
variable of type long (which has a width of 8 bytes in 64-bit builds).
Hence, once a 32-bit effective address is computed, the 4 most significant
bytes are masked out to avoid sign extension.

The newly added function get_addr_ref_32() is almost identical to the
existing function insn_get_addr_ref() (used for 64-bit addresses). The only
difference is that it verifies that the effective address is within the
limits of the segment.

Cc: Dave Hansen 
Cc: Adam Buchbinder 
Cc: Colin Ian King 
Cc: Lorenzo Stoakes 
Cc: Qiaowei Ren 
Cc: Arnaldo Carvalho de Melo 
Cc: Masami Hiramatsu 
Cc: Adrian Hunter 
Cc: Kees Cook 
Cc: Thomas Garnier 
Cc: Peter Zijlstra 
Cc: Borislav Petkov 
Cc: Dmitry Vyukov 
Cc: Tony Luck 
Cc: Ravi V. Shankar 
Cc: x...@kernel.org
Signed-off-by: Ricardo Neri 
---
 arch/x86/lib/insn-eval.c | 112 ---
 1 file changed, 106 insertions(+), 6 deletions(-)

diff --git a/arch/x86/lib/insn-eval.c b/arch/x86/lib/insn-eval.c
index a4427b4..e6cb68a 100644
--- a/arch/x86/lib/insn-eval.c
+++ b/arch/x86/lib/insn-eval.c
@@ -814,7 +814,11 @@ static int get_eff_addr_reg(struct insn *insn, struct 
pt_regs *regs,
if (*regoff < 0)
return -EINVAL;
 
-   *eff_addr = regs_get_register(regs, *regoff);
+   /* Ignore bytes that are outside the address size. */
+   if (insn->addr_bytes == 4)
+   *eff_addr = regs_get_register(regs, *regoff) & 0x;
+   else /* 64-bit address */
+   *eff_addr = regs_get_register(regs, *regoff);
 
return 0;
 }
@@ -846,7 +850,7 @@ static int get_eff_addr_modrm(struct insn *insn, struct 
pt_regs *regs,
 {
long tmp;
 
-   if (insn->addr_bytes != 8)
+   if (insn->addr_bytes != 8 && insn->addr_bytes != 4)
return -EINVAL;
 
insn_get_modrm(insn);
@@ -875,7 +879,13 @@ static int get_eff_addr_modrm(struct insn *insn, struct 
pt_regs *regs,
tmp = regs_get_register(regs, *regoff);
}
 
-   *eff_addr = tmp + insn->displacement.value;
+   if (insn->addr_bytes == 4) {
+   int addr32 = (int)(tmp & 0x) + insn->displacement.value;
+
+   *eff_addr = addr32 & 0x;
+   } else {
+   *eff_addr = tmp + insn->displacement.value;
+   }
 
return 0;
 }
@@ -908,7 +918,7 @@ static int get_eff_addr_sib(struct insn *insn, struct 
pt_regs *regs,
long base, indx;
int indx_offset;
 
-   if (insn->addr_bytes != 8)
+   if (insn->addr_bytes != 8 && insn->addr_bytes != 4)
return -EINVAL;
 
insn_get_modrm(insn);
@@ -946,12 +956,102 @@ static int get_eff_addr_sib(struct insn *insn, struct 
pt_regs *regs,
else
indx = regs_get_register(regs, indx_offset);
 
-   *eff_addr = base + indx * (1 << X86_SIB_SCALE(insn->sib.value));
+   if (insn->addr_bytes == 4) {
+   int addr32, base32, idx32;
+
+   base32 = base & 0x;
+   idx32 = indx & 0x;
 
-   *eff_addr += insn->displacement.value;
+   addr32 = base32 + idx32 * (1 << X86_SIB_SCALE(insn->sib.value));
+   addr32 += insn->displacement.value;
+
+   *eff_addr = addr32 & 0x;
+   } else {
+   *eff_addr = base + indx * (1 << X86_SIB_SCALE(insn->sib.value));
+   *eff_addr += insn->displacement.value;
+   }
 
return 0;
 }
+
+/**
+ * get_addr_ref_32() - Obtain a 32-bit linear address
+ * @insn:  Instruction with ModRM, SIB bytes and displacement
+ * @regs:  Register values as seen when entering kernel mode
+ *
+ * This function is to be used with 32-bit address encodings to obtain the
+ * linear memory address referred by the instruction's ModRM, SIB,
+ * displacement bytes and segment base address, as applicable. If in protected
+ * mode, segment limits are enforced.
+ *
+ * Returns:
+ *
+ * Linear address referenced by instruc

[PATCH v11 04/12] x86/insn-eval: Handle 32-bit address encodings in virtual-8086 mode

2017-11-05 Thread Ricardo Neri
It is possible to utilize 32-bit address encodings in virtual-8086 mode via
an address override instruction prefix. However, the range of the
effective address is still limited to [0x-0x]. In such a case, return
error.

Also, linear addresses in virtual-8086 mode are limited to 20 bits. Enforce
such limit by truncating the most significant bytes of the computed linear
address.

Cc: Dave Hansen 
Cc: Adam Buchbinder 
Cc: Colin Ian King 
Cc: Lorenzo Stoakes 
Cc: Qiaowei Ren 
Cc: Arnaldo Carvalho de Melo 
Cc: Masami Hiramatsu 
Cc: Adrian Hunter 
Cc: Kees Cook 
Cc: Thomas Garnier 
Cc: Peter Zijlstra 
Cc: Borislav Petkov 
Cc: Dmitry Vyukov 
Cc: Tony Luck 
Cc: Ravi V. Shankar 
Cc: x...@kernel.org
Signed-off-by: Ricardo Neri 
---
 arch/x86/lib/insn-eval.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/arch/x86/lib/insn-eval.c b/arch/x86/lib/insn-eval.c
index 1ac3973..ef102db 100644
--- a/arch/x86/lib/insn-eval.c
+++ b/arch/x86/lib/insn-eval.c
@@ -1042,12 +1042,23 @@ static void __user *get_addr_ref_32(struct insn *insn, 
struct pt_regs *regs)
goto out;
 
/*
+* Even though 32-bit address encodings are allowed in virtual-8086
+* mode, the address range is still limited to [0x-0x].
+*/
+   if (v8086_mode(regs) && (eff_addr & ~0x))
+   goto out;
+
+   /*
 * Data type long could be 64 bits in size. Ensure that our 32-bit
 * effective address is not sign-extended when computing the linear
 * address.
 */
linear_addr = (unsigned long)(eff_addr & 0x) + seg_base;
 
+   /* Limit linear address to 20 bits */
+   if (v8086_mode(regs))
+   linear_addr &= 0xf;
+
 out:
return (void __user *)linear_addr;
 }
-- 
2.7.4



[PATCH v11 05/12] x86/insn-eval: Add support to resolve 16-bit address encodings

2017-11-05 Thread Ricardo Neri
Tasks running in virtual-8086 mode, in protected mode with code segment
descriptors that specify 16-bit default address sizes via the D bit, or via
an address override prefix will use 16-bit addressing form encodings as
described in the Intel 64 and IA-32 Architecture Software Developer's
Manual Volume 2A Section 2.1.5, Table 2-1.

16-bit addressing encodings differ in several ways from the 32-bit/64-bit
addressing form encodings: ModRM.rm points to different registers and, in
some cases, effective addresses are indicated by the addition of the value
of two registers. Also, there is no support for SIB bytes. Thus, a
separate function is needed to parse this form of addressing.

Three functions are introduced. get_reg_offset_16() obtains the
offset from the base of pt_regs of the registers indicated by the ModRM
byte of the address encoding. get_eff_addr_modrm_16() computes the
effective address from the value of the register operands.
get_addr_ref_16() computes the linear address using the obtained effective
address and the base address of the segment.

Segment limits are enforced when running in protected mode.

Cc: Dave Hansen 
Cc: Adam Buchbinder 
Cc: Colin Ian King 
Cc: Lorenzo Stoakes 
Cc: Qiaowei Ren 
Cc: Arnaldo Carvalho de Melo 
Cc: Masami Hiramatsu 
Cc: Adrian Hunter 
Cc: Kees Cook 
Cc: Thomas Garnier 
Cc: Peter Zijlstra 
Cc: Borislav Petkov 
Cc: Dmitry Vyukov 
Cc: Tony Luck 
Cc: Ravi V. Shankar 
Cc: x...@kernel.org
Signed-off-by: Ricardo Neri 
---
 arch/x86/lib/insn-eval.c | 213 ++-
 1 file changed, 212 insertions(+), 1 deletion(-)

diff --git a/arch/x86/lib/insn-eval.c b/arch/x86/lib/insn-eval.c
index ef102db..35625d2 100644
--- a/arch/x86/lib/insn-eval.c
+++ b/arch/x86/lib/insn-eval.c
@@ -481,6 +481,80 @@ static int get_reg_offset(struct insn *insn, struct 
pt_regs *regs,
 }
 
 /**
+ * get_reg_offset_16() - Obtain offset of register indicated by instruction
+ * @insn:  Instruction containing ModRM byte
+ * @regs:  Register values as seen when entering kernel mode
+ * @offs1: Offset of the first operand register
+ * @offs2: Offset of the second opeand register, if applicable
+ *
+ * Obtain the offset, in pt_regs, of the registers indicated by the ModRM byte
+ * in @insn. This function is to be used with 16-bit address encodings. The
+ * @offs1 and @offs2 will be written with the offset of the two registers
+ * indicated by the instruction. In cases where any of the registers is not
+ * referenced by the instruction, the value will be set to -EDOM.
+ *
+ * Returns:
+ *
+ * 0 on success, -EINVAL on error.
+ */
+static int get_reg_offset_16(struct insn *insn, struct pt_regs *regs,
+int *offs1, int *offs2)
+{
+   /*
+* 16-bit addressing can use one or two registers. Specifics of
+* encodings are given in Table 2-1. "16-Bit Addressing Forms with the
+* ModR/M Byte" of the Intel Software Development Manual.
+*/
+   static const int regoff1[] = {
+   offsetof(struct pt_regs, bx),
+   offsetof(struct pt_regs, bx),
+   offsetof(struct pt_regs, bp),
+   offsetof(struct pt_regs, bp),
+   offsetof(struct pt_regs, si),
+   offsetof(struct pt_regs, di),
+   offsetof(struct pt_regs, bp),
+   offsetof(struct pt_regs, bx),
+   };
+
+   static const int regoff2[] = {
+   offsetof(struct pt_regs, si),
+   offsetof(struct pt_regs, di),
+   offsetof(struct pt_regs, si),
+   offsetof(struct pt_regs, di),
+   -EDOM,
+   -EDOM,
+   -EDOM,
+   -EDOM,
+   };
+
+   if (!offs1 || !offs2)
+   return -EINVAL;
+
+   /* Operand is a register, use the generic function. */
+   if (X86_MODRM_MOD(insn->modrm.value) == 3) {
+   *offs1 = insn_get_modrm_rm_off(insn, regs);
+   *offs2 = -EDOM;
+   return 0;
+   }
+
+   *offs1 = regoff1[X86_MODRM_RM(insn->modrm.value)];
+   *offs2 = regoff2[X86_MODRM_RM(insn->modrm.value)];
+
+   /*
+* If ModRM.mod is 0 and ModRM.rm is 110b, then we use displacement-
+* only addressing. This means that no registers are involved in
+* computing the effective address. Thus, ensure that the first
+* register offset is invalild. The second register offset is already
+* invalid under the aforementioned conditions.
+*/
+   if ((X86_MODRM_MOD(insn->modrm.value) == 0) &&
+   (X86_MODRM_RM(insn->modrm.value) == 6))
+   *offs1 = -EDOM;
+
+   return 0;
+}
+
+/**
  * get_desc() - Obtain pointer to a segment descriptor
  * @sel:   Segment selector
  *
@@ -815,7 +889,9 @@ static int get_eff_addr_reg(struct insn *insn, struct 
pt_regs *regs,
return -EINVAL;
 
/* Ignore bytes that are outside the address size. */
- 

[PATCH v11 07/12] x86: Add emulation code for UMIP instructions

2017-11-05 Thread Ricardo Neri
The feature User-Mode Instruction Prevention present in recent Intel
processor prevents a group of instructions (sgdt, sidt, sldt, smsw, and
str) from being executed with CPL > 0. Otherwise, a general protection
fault is issued.

Rather than relaying to the user space the general protection fault caused
by the UMIP-protected instructions (in the form of a SIGSEGV signal), it
can be trapped and the instruction emulated to provide a dummy result.
This allows to both conserve the current kernel behavior and not reveal the
system resources that UMIP intends to protect (i.e., the locations of the
global descriptor and interrupt descriptor tables, the segment selectors of
the local descriptor table, the value of the task state register and the
contents of the CR0 register).

This emulation is needed because certain applications (e.g., WineHQ and
DOSEMU2) rely on this subset of instructions to function. Given that sldt
and str are not commonly used in programs that run on WineHQ or DOSEMU2,
they are not emulated. Also, emulation is provided only for 32-bit
processes; 64-bit processes that attempt to use the instructions that UMIP
protects will receive the SIGSEGV signal issued as a consequence of the
general protection fault.

The instructions protected by UMIP can be split in two groups. Those which
return a kernel memory address (sgdt and sidt) and those which return a
value (smsw, sldt and str; the last two not emulated).

For the instructions that return a kernel memory address, applications such
as WineHQ rely on the result being located in the kernel memory space, not
the actual location of the table. The result is emulated as a hard-coded
value that lies close to the top of the kernel memory. The limit for the
GDT and the IDT are set to zero.

The instruction smsw is emulated to return the value that the register CR0
has at boot time as set in the head_32.

Care is taken to appropriately emulate the results when segmentation is
used. That is, rather than relying on USER_DS and USER_CS, the function
insn_get_addr_ref() inspects the segment descriptor pointed by the
registers in pt_regs. This ensures that we correctly obtain the segment
base address and the address and operand sizes even if the user space
application uses a local descriptor table.

Cc: Andy Lutomirski 
Cc: Andrew Morton 
Cc: H. Peter Anvin 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Chen Yucong 
Cc: Chris Metcalf 
Cc: Dave Hansen 
Cc: Fenghua Yu 
Cc: Huang Rui 
Cc: Jiri Slaby 
Cc: Jonathan Corbet 
Cc: Michael S. Tsirkin 
Cc: Paul Gortmaker 
Cc: Peter Zijlstra 
Cc: Ravi V. Shankar 
Cc: Shuah Khan 
Cc: Vlastimil Babka 
Cc: Tony Luck 
Cc: Paolo Bonzini 
Cc: x...@kernel.org
Signed-off-by: Ricardo Neri 
---
 arch/x86/include/asm/umip.h |  12 ++
 arch/x86/kernel/Makefile|   1 +
 arch/x86/kernel/umip.c  | 321 
 3 files changed, 334 insertions(+)
 create mode 100644 arch/x86/include/asm/umip.h
 create mode 100644 arch/x86/kernel/umip.c

diff --git a/arch/x86/include/asm/umip.h b/arch/x86/include/asm/umip.h
new file mode 100644
index 000..db43f2a
--- /dev/null
+++ b/arch/x86/include/asm/umip.h
@@ -0,0 +1,12 @@
+#ifndef _ASM_X86_UMIP_H
+#define _ASM_X86_UMIP_H
+
+#include 
+#include 
+
+#ifdef CONFIG_X86_INTEL_UMIP
+bool fixup_umip_exception(struct pt_regs *regs);
+#else
+static inline bool fixup_umip_exception(struct pt_regs *regs) { return false; }
+#endif  /* CONFIG_X86_INTEL_UMIP */
+#endif  /* _ASM_X86_UMIP_H */
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index 295abaa..81bb565 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -127,6 +127,7 @@ obj-$(CONFIG_EFI)   += sysfb_efi.o
 obj-$(CONFIG_PERF_EVENTS)  += perf_regs.o
 obj-$(CONFIG_TRACING)  += tracepoint.o
 obj-$(CONFIG_SCHED_MC_PRIO)+= itmt.o
+obj-$(CONFIG_X86_INTEL_UMIP)   += umip.o
 
 obj-$(CONFIG_UNWINDER_ORC) += unwind_orc.o
 obj-$(CONFIG_UNWINDER_FRAME_POINTER)   += unwind_frame.o
diff --git a/arch/x86/kernel/umip.c b/arch/x86/kernel/umip.c
new file mode 100644
index 000..d80b816
--- /dev/null
+++ b/arch/x86/kernel/umip.c
@@ -0,0 +1,321 @@
+/*
+ * umip.c Emulation for instruction protected by the Intel User-Mode
+ * Instruction Prevention feature
+ *
+ * Copyright (c) 2017, Intel Corporation.
+ * Ricardo Neri 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/** DOC: Emulation for User-Mode Instruction Prevention (UMIP)
+ *
+ * The feature User-Mode Instruction Prevention present in recent Intel
+ * processor prevents a group of instructions (sgdt, sidt, sldt, smsw, and str)
+ * from being executed with CPL > 0. Otherwise, a general protection fault is
+ * issued.
+ *
+ * Rather than relaying to the user space the general protection fault caused 
by
+ * the UMIP-protected instructions (in the form of a SIGSEGV signal), it can be
+ * trapped and emulate the result of such instructions to provide du

  1   2   3   4   >