Re: syzbot rcu/debugobjects warning

2018-03-24 Thread Joel Fernandes
On Fri, Mar 23, 2018 at 1:41 PM, Thomas Gleixner  wrote:
> On Fri, 23 Mar 2018, Joel Fernandes wrote:
>> On Fri, Mar 23, 2018 at 2:11 AM, Thomas Gleixner  wrote:
>> > On Thu, 22 Mar 2018, Joel Fernandes wrote:
>> Sorry. Here is the raw crash log: https://pastebin.com/raw/puvh0cXE
>> (The kernel logs are toward the end with the above).
>
> And that is interesting:
>
> [  150.629667]   [  150.631700]  [] 
> dump_stack+0xc1/0x128
> [  150.637051]  [] ? __debug_object_init+0x526/0xc40
> [  150.643431]  [] panic+0x1bc/0x3a8
> [  150.648416]  [] ? 
> percpu_up_read_preempt_enable.constprop.53+0xd7/0xd7
> [  150.656611]  [] ? load_image_and_restore+0xf9/0xf9
> [  150.663070]  [] ? vprintk_default+0x1d/0x30
> [  150.668925]  [] ? __warn+0x1a9/0x1e0
> [  150.674170]  [] ? __debug_object_init+0x526/0xc40
> [  150.680543]  [] __warn+0x1c4/0x1e0
> [  150.685614]  [] warn_slowpath_null+0x2c/0x40
> [  150.691972]  [] __debug_object_init+0x526/0xc40
> [  150.698174]  [] ? debug_object_fixup+0x30/0x30
> [  150.704283]  [] debug_object_init_on_stack+0x19/0x20
> [  150.710917]  [] __wait_rcu_gp+0x93/0x1b0
> [  150.716508]  [] synchronize_rcu.part.65+0x101/0x110
> [  150.723054]  [] ? rcu_pm_notify+0xc0/0xc0
> [  150.728735]  [] ? __call_rcu.constprop.72+0x910/0x910
> [  150.735459]  [] ? __lock_is_held+0xa1/0xf0
> [  150.741223]  [] synchronize_rcu+0x27/0x90
>
> So this calls synchronize_rcu from a rcu callback. That's a nono. This is
> on the back of an interrupt in softirq context and __wait_rcu_gp() can
> sleep, which is obviously a bad idea in softirq context
>
> Cc'ed netdev 
>
> And that also explains the debug object splat because this is not running
> on the task stack. It's running on the softirq stack 
>
> [  150.746908]  [] __l2tp_session_unhash+0x3d5/0x550
> [  150.753281]  [] ? __l2tp_session_unhash+0x1bf/0x550
> [  150.759828]  [] ? __local_bh_enable_ip+0x6a/0xd0
> [  150.766123]  [] ? l2tp_udp_encap_recv+0xd90/0xd90
> [  150.772497]  [] l2tp_tunnel_closeall+0x1e7/0x3a0
> [  150.778782]  [] l2tp_tunnel_destruct+0x30e/0x5a0
> [  150.785067]  [] ? l2tp_tunnel_destruct+0x1aa/0x5a0
> [  150.791537]  [] ? l2tp_tunnel_del_work+0x460/0x460
> [  150.797997]  [] __sk_destruct+0x53/0x570
> [  150.803588]  [] rcu_process_callbacks+0x898/0x1300
> [  150.810048]  [] ? rcu_process_callbacks+0x977/0x1300
> [  150.816684]  [] ? __sk_dst_check+0x240/0x240
> [  150.822625]  [] __do_softirq+0x206/0x951
> [  150.828223]  [] irq_exit+0x165/0x190
> [  150.833557]  [] smp_apic_timer_interrupt+0x7b/0xa0
> [  150.840018]  [] apic_timer_interrupt+0xa0/0xb0
> [  150.846132]   [  150.848166]  [] ? 
> native_safe_halt+0x6/0x10
> [  150.854036]  [] ? trace_hardirqs_on+0xd/0x10
> [  150.859973]  [] default_idle+0x55/0x360
> [  150.865478]  [] arch_cpu_idle+0xa/0x10
> [  150.870896]  [] default_idle_call+0x36/0x60
> [  150.876751]  [] cpu_startup_entry+0x2b0/0x380
> [  150.882787]  [] ? cpu_in_idle+0x20/0x20
> [  150.888291]  [] ? clockevents_register_device+0x123/0x200
> [  150.895358]  [] start_secondary+0x303/0x3e0
> [  150.901209]  [] ? set_cpu_sibling_map+0x11f0/0x11f0

Thomas, thanks a lot. It appears this issue will not happen on
mainline since from commit  765924e362d1  (subject "l2tp: don't close
sessions in l2tp_tunnel_destruct()"), l2tp_tunnel_closeall is no
longer called from l2tp_tunnel_destruct. From that commit message it
seems one of the motivations is to solve scheduling from atomic issue.

However for this change to be applied to android-4.9 and/or 4.9
stable, it depends on several other l2p patches and they aren't
straight forward cherry-picks from mainline (and I don't have much
background with this driver).

v3.16.56 stable seems to be further along with l2tp than v4.9.89, in
that it atleast has more of the upstream patches adapted for it, that
the above patch depends on. Since this also related to stable, I am
CC'ing Greg kh and Ben.

Here are some of the commits in 3.16 stable that I couldn't find
applied to v4.9 stable. The above fix quotes the below patches as
dependencies so they would need to be stable backported. Also CC'ing
Guillaume since he authored the above mentioned fix.

0c15ddabbcf l2tp: don't register sessions in l2tp_session_create()
a3c5d5b70f4e l2tp: fix race condition in l2tp_tunnel_delete
5b216e8dcda2 l2tp: prevent creation of sessions on terminated tunnels
76ff5e22f1e0 l2tp: hold tunnel while looking up sessions in l2tp_netlink
ceb8f6b23a38 l2tp: define parameters of l2tp_session_get*() as "const"
0295d020b63f l2tp: initialise session's refcount before making it reachable
29a77518927e l2tp: take reference on sessions being dumped
b301c9b7782f l2tp: take a reference on sessions used in genetlink handlers

By the way I think the reason why scheduling while atomic checks
didn't show up is because the debugobjects warning caused a panic
first, before that could happen.

- Joel

PS: There's also 12d656af4e3d2 ("l2tp: Avoid schedule while atomic in
exit_net") which was fixing a call to synchro

Re: linux-next on x60: network manager often complains "network is disabled" after resume

2018-03-24 Thread Pavel Machek
> > > Ok, what does 'nmcli dev' and 'nmcli radio' show?

> > 
> > Broken state.
> > 
> > pavel@amd:~$ nmcli dev
> > DEVICE  TYPE  STATECONNECTION
> > eth1ethernet  unavailable  --
> > lo  loopback  unmanaged--
> > wlan0   wifi  unmanaged--
> 
> If the state is "unmanaged" on resume, that would indicate a problem
> with sleep/wake and likely not a kernel network device issue.
> 
> We should probably move this discussion to the NM lists to debug
> further.  Before you suspend, run "nmcli gen log level trace" to turn
> on full debug logging, then reproduce the issue, and send a pointer to
> those logs (scrubbed for anything you consider sensitive) to the NM
> mailing list.

Hmm :-)

root@amd:/data/pavel# nmcli gen log level trace
Error: Unknown log level 'trace'
root@amd:/data/pavel# nmcli gen log level help
Error: Unknown log level 'help'
root@amd:/data/pavel# nmcli gen log level
Error: value for 'level' argument is required.
root@amd:/data/pavel# nmcli gen log level debug
root@amd:/data/pavel# cat /var/log/sys/log

Where do I get the logs? I don't see much in the syslog...

And.. It seems that it is "every other suspend". One resume results in
broken network, one in working one, one in broken one...

Thanks,
Pavel

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


signature.asc
Description: Digital signature


Re: [PATCH] swiotlb: swiotlb_{alloc,free}_buffer should depend on CONFIG_DMA_DIRECT_OPS

2018-03-24 Thread Konrad Rzeszutek Wilk
On Sat, Mar 24, 2018 at 06:03:51PM +0100, Christoph Hellwig wrote:
> On Fri, Mar 23, 2018 at 02:57:07PM -0400, Konrad Rzeszutek Wilk wrote:
> > On Fri, Mar 23, 2018 at 06:49:30PM +0100, Christoph Hellwig wrote:
> > > Otherwise we might get unused symbol warnings for configs that built
> > > swiotlb.c only for use by xen-swiotlb.c and that don't otherwise select
> > > CONFIG_DMA_DIRECT_OPS, which is possible on arm.
> > > 
> > > Fixes: 16e73adbca76 ("dma/swiotlb: Remove 
> > > swiotlb_{alloc,free}_coherent()")
> > > Reported-by: Stephen Rothwell 
> > > Signed-off-by: Christoph Hellwig 
> > 
> > 
> > Alternatively could we set the Kconfig to slect DMA_DIRECT_OPS?
> 
> 
> IFF we build swiotlb.c only for xen-swiotlb we don't need DMA_DIRECT_OPS.

I don't think there is ever an case where you want a Xen specific build.

> IF you are fine with just requring it as well that would be doable nicely
> only if we consolidate to a single defintion of CONFIG_SWIOTLB instead
> of one per architecture.  Which is something we should do anyway,
> so I'll look into it once I get some time.

Sounds good. Thank you.


Re: [PATCH v1 12/16] rtc: mediatek: cleanup header files to include

2018-03-24 Thread kbuild test robot
Hi Sean,

I love your patch! Yet something to improve:

[auto build test ERROR on abelloni/rtc-next]
[also build test ERROR on v4.16-rc6]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/sean-wang-mediatek-com/Add-support-to-MT6323-RTC-and-its-power-device/20180325-104529
base:   https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git 
rtc-next
config: tile-allmodconfig (attached as .config)
compiler: tilegx-linux-gcc (GCC) 7.2.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=tile 

All errors (new ones prefixed by >>):

   drivers//rtc/rtc-mt6397.c: In function 'mtk_rtc_probe':
>> drivers//rtc/rtc-mt6397.c:270:13: error: implicit declaration of function 
>> 'irq_create_mapping'; did you mean 'page_mapping'? 
>> [-Werror=implicit-function-declaration]
 rtc->irq = irq_create_mapping(mt6397_chip->irq_domain, res->start);
^~
page_mapping
   cc1: some warnings being treated as errors

vim +270 drivers//rtc/rtc-mt6397.c

fc2979118 Tianping Fang  2015-05-06  254  
fc2979118 Tianping Fang  2015-05-06  255  static int mtk_rtc_probe(struct 
platform_device *pdev)
fc2979118 Tianping Fang  2015-05-06  256  {
fc2979118 Tianping Fang  2015-05-06  257struct resource *res;
fc2979118 Tianping Fang  2015-05-06  258struct mt6397_chip *mt6397_chip 
= dev_get_drvdata(pdev->dev.parent);
fc2979118 Tianping Fang  2015-05-06  259struct mt6397_rtc *rtc;
fc2979118 Tianping Fang  2015-05-06  260int ret;
fc2979118 Tianping Fang  2015-05-06  261  
fc2979118 Tianping Fang  2015-05-06  262rtc = devm_kzalloc(&pdev->dev, 
sizeof(struct mt6397_rtc), GFP_KERNEL);
fc2979118 Tianping Fang  2015-05-06  263if (!rtc)
fc2979118 Tianping Fang  2015-05-06  264return -ENOMEM;
fc2979118 Tianping Fang  2015-05-06  265  
fc2979118 Tianping Fang  2015-05-06  266res = 
platform_get_resource(pdev, IORESOURCE_MEM, 0);
fc2979118 Tianping Fang  2015-05-06  267rtc->addr_base = res->start;
fc2979118 Tianping Fang  2015-05-06  268  
fc2979118 Tianping Fang  2015-05-06  269res = 
platform_get_resource(pdev, IORESOURCE_IRQ, 0);
fc2979118 Tianping Fang  2015-05-06 @270rtc->irq = 
irq_create_mapping(mt6397_chip->irq_domain, res->start);
fc2979118 Tianping Fang  2015-05-06  271if (rtc->irq <= 0)
fc2979118 Tianping Fang  2015-05-06  272return -EINVAL;
fc2979118 Tianping Fang  2015-05-06  273  
fc2979118 Tianping Fang  2015-05-06  274rtc->regmap = 
mt6397_chip->regmap;
fc2979118 Tianping Fang  2015-05-06  275rtc->dev = &pdev->dev;
fc2979118 Tianping Fang  2015-05-06  276mutex_init(&rtc->lock);
fc2979118 Tianping Fang  2015-05-06  277  
fc2979118 Tianping Fang  2015-05-06  278platform_set_drvdata(pdev, rtc);
fc2979118 Tianping Fang  2015-05-06  279  
66c231b40 Sean Wang  2018-03-23  280ret = 
devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL,
fc2979118 Tianping Fang  2015-05-06  281
mtk_rtc_irq_handler_thread,
fc2979118 Tianping Fang  2015-05-06  282
IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
fc2979118 Tianping Fang  2015-05-06  283
"mt6397-rtc", rtc);
fc2979118 Tianping Fang  2015-05-06  284if (ret) {
fc2979118 Tianping Fang  2015-05-06  285dev_err(&pdev->dev, 
"Failed to request alarm IRQ: %d: %d\n",
fc2979118 Tianping Fang  2015-05-06  286rtc->irq, ret);
63044753b Sean Wang  2018-03-23  287return ret;
fc2979118 Tianping Fang  2015-05-06  288}
fc2979118 Tianping Fang  2015-05-06  289  
baeca4495 Wei-Ning Huang 2015-07-02  290device_init_wakeup(&pdev->dev, 
1);
baeca4495 Wei-Ning Huang 2015-07-02  291  
66c231b40 Sean Wang  2018-03-23  292rtc->rtc_dev = 
devm_rtc_device_register(&pdev->dev, "mt6397-rtc",
fc2979118 Tianping Fang  2015-05-06  293
&mtk_rtc_ops, THIS_MODULE);
fc2979118 Tianping Fang  2015-05-06  294if (IS_ERR(rtc->rtc_dev)) {
fc2979118 Tianping Fang  2015-05-06  295dev_err(&pdev->dev, 
"register rtc device failed\n");
fc2979118 Tianping Fang  2015-05-06  296ret = 
PTR_ERR(rtc->rtc_dev);
fc2979118 Tianping Fang  2015-05-06  297return ret;
fc2979118 Tianping Fang  2015-05-06  298}
fc2979118 Tianping Fang  2015-05-06  299  
89a68f3c0 Sean Wang  2018-03-23  300return 
devm_of_platform_populate(&pdev->dev);
fc2979118 Tianping Fang  2015-05-06  301  }
fc2979118 Tianping Fang  2015-05-06  302  

:: The code at line 270 was fi

[PATCH 2/2] KVM: X86: Fix disable pv tlb flush when steal time is enabled

2018-03-24 Thread Wanpeng Li
From: Wanpeng Li 

PV TLB FLUSH can be turned on when steal time is enabled. The condition 
reverse when the patch is sent out for several rounds review by mistake. 
This patch fixes it.

Cc: Paolo Bonzini 
Cc: Radim Krčmář 
Signed-off-by: Wanpeng Li 
---
 arch/x86/kernel/kvm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index 31ac585..4f859cc 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -555,7 +555,7 @@ static void __init kvm_guest_init(void)
 
if (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) &&
!kvm_para_has_hint(KVM_HINTS_DEDICATED) &&
-   !kvm_para_has_feature(KVM_FEATURE_STEAL_TIME))
+   kvm_para_has_feature(KVM_FEATURE_STEAL_TIME))
pv_mmu_ops.flush_tlb_others = kvm_flush_tlb_others;
 
if (kvm_para_has_feature(KVM_FEATURE_PV_EOI))
@@ -651,7 +651,7 @@ static __init int kvm_setup_pv_tlb_flush(void)
 
if (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) &&
!kvm_para_has_hint(KVM_HINTS_DEDICATED) &&
-   !kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) {
+   kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) {
for_each_possible_cpu(cpu) {
zalloc_cpumask_var_node(per_cpu_ptr(&__pv_tlb_mask, 
cpu),
GFP_KERNEL, cpu_to_node(cpu));
-- 
2.7.4



Re: [PATCH v1 12/16] rtc: mediatek: cleanup header files to include

2018-03-24 Thread kbuild test robot
Hi Sean,

I love your patch! Yet something to improve:

[auto build test ERROR on abelloni/rtc-next]
[also build test ERROR on v4.16-rc6 next-20180323]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/sean-wang-mediatek-com/Add-support-to-MT6323-RTC-and-its-power-device/20180325-104529
base:   https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git 
rtc-next
config: x86_64-randconfig-x004-201812 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All errors (new ones prefixed by >>):

   drivers//rtc/rtc-mt6397.c: In function 'mtk_rtc_probe':
>> drivers//rtc/rtc-mt6397.c:270:13: error: implicit declaration of function 
>> 'irq_create_mapping'; did you mean 'qid_has_mapping'? 
>> [-Werror=implicit-function-declaration]
 rtc->irq = irq_create_mapping(mt6397_chip->irq_domain, res->start);
^~
qid_has_mapping
   Cyclomatic Complexity 1 include/linux/err.h:PTR_ERR
   Cyclomatic Complexity 1 include/linux/err.h:IS_ERR
   Cyclomatic Complexity 1 include/linux/math64.h:div_s64_rem
   Cyclomatic Complexity 1 include/linux/math64.h:div_s64
   Cyclomatic Complexity 3 include/linux/ktime.h:ktime_compare
   Cyclomatic Complexity 1 include/linux/ktime.h:ktime_add_us
   Cyclomatic Complexity 1 include/linux/device.h:devm_kzalloc
   Cyclomatic Complexity 1 include/linux/pm_wakeup.h:device_set_wakeup_capable
   Cyclomatic Complexity 1 include/linux/pm_wakeup.h:device_set_wakeup_enable
   Cyclomatic Complexity 1 include/linux/pm_wakeup.h:device_init_wakeup
   Cyclomatic Complexity 1 include/linux/device.h:dev_get_drvdata
   Cyclomatic Complexity 1 include/linux/device.h:dev_set_drvdata
   Cyclomatic Complexity 1 include/linux/platform_device.h:platform_set_drvdata
   Cyclomatic Complexity 1 include/linux/of_platform.h:devm_of_platform_populate
   Cyclomatic Complexity 1 drivers//rtc/rtc-mt6397.c:mtk_rtc_driver_init
   Cyclomatic Complexity 5 drivers//rtc/rtc-mt6397.c:mtk_rtc_probe
   Cyclomatic Complexity 11 drivers//rtc/rtc-mt6397.c:mtk_rtc_write_trigger
   Cyclomatic Complexity 6 drivers//rtc/rtc-mt6397.c:mtk_rtc_set_alarm
   Cyclomatic Complexity 2 drivers//rtc/rtc-mt6397.c:mtk_rtc_set_time
   Cyclomatic Complexity 4 drivers//rtc/rtc-mt6397.c:mtk_rtc_read_alarm
   Cyclomatic Complexity 2 drivers//rtc/rtc-mt6397.c:__mtk_rtc_read_time
   Cyclomatic Complexity 3 drivers//rtc/rtc-mt6397.c:mtk_rtc_read_time
   Cyclomatic Complexity 4 drivers//rtc/rtc-mt6397.c:mtk_rtc_irq_handler_thread
   Cyclomatic Complexity 1 drivers//rtc/rtc-mt6397.c:mtk_rtc_driver_exit
   cc1: some warnings being treated as errors

vim +270 drivers//rtc/rtc-mt6397.c

fc2979118 Tianping Fang  2015-05-06  254  
fc2979118 Tianping Fang  2015-05-06  255  static int mtk_rtc_probe(struct 
platform_device *pdev)
fc2979118 Tianping Fang  2015-05-06  256  {
fc2979118 Tianping Fang  2015-05-06  257struct resource *res;
fc2979118 Tianping Fang  2015-05-06  258struct mt6397_chip *mt6397_chip 
= dev_get_drvdata(pdev->dev.parent);
fc2979118 Tianping Fang  2015-05-06  259struct mt6397_rtc *rtc;
fc2979118 Tianping Fang  2015-05-06  260int ret;
fc2979118 Tianping Fang  2015-05-06  261  
fc2979118 Tianping Fang  2015-05-06  262rtc = devm_kzalloc(&pdev->dev, 
sizeof(struct mt6397_rtc), GFP_KERNEL);
fc2979118 Tianping Fang  2015-05-06  263if (!rtc)
fc2979118 Tianping Fang  2015-05-06  264return -ENOMEM;
fc2979118 Tianping Fang  2015-05-06  265  
fc2979118 Tianping Fang  2015-05-06  266res = 
platform_get_resource(pdev, IORESOURCE_MEM, 0);
fc2979118 Tianping Fang  2015-05-06  267rtc->addr_base = res->start;
fc2979118 Tianping Fang  2015-05-06  268  
fc2979118 Tianping Fang  2015-05-06  269res = 
platform_get_resource(pdev, IORESOURCE_IRQ, 0);
fc2979118 Tianping Fang  2015-05-06 @270rtc->irq = 
irq_create_mapping(mt6397_chip->irq_domain, res->start);
fc2979118 Tianping Fang  2015-05-06  271if (rtc->irq <= 0)
fc2979118 Tianping Fang  2015-05-06  272return -EINVAL;
fc2979118 Tianping Fang  2015-05-06  273  
fc2979118 Tianping Fang  2015-05-06  274rtc->regmap = 
mt6397_chip->regmap;
fc2979118 Tianping Fang  2015-05-06  275rtc->dev = &pdev->dev;
fc2979118 Tianping Fang  2015-05-06  276mutex_init(&rtc->lock);
fc2979118 Tianping Fang  2015-05-06  277  
fc2979118 Tianping Fang  2015-05-06  278platform_set_drvdata(pdev, rtc);
fc2979118 Tianping Fang  2015-05-06  279  
66c231b40 Sean Wang  2018-03-23  280ret = 
devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL,
fc2979118 Tianping Fang  2015-05-06  281
mtk_rtc_irq_handler_thread,
fc2979118 Tianping Fang  2015-05-06  282
IRQF_ONESHO

[PATCH 1/2] KVM: X86: Fix setup the virt_spin_lock_key before static key get initialized

2018-03-24 Thread Wanpeng Li
From: Wanpeng Li 

 static_key_disable_cpuslocked(): static key 'virt_spin_lock_key+0x0/0x20' used 
before call to jump_label_init()
 WARNING: CPU: 0 PID: 0 at kernel/jump_label.c:161 
static_key_disable_cpuslocked+0x61/0x80
 RIP: 0010:static_key_disable_cpuslocked+0x61/0x80
 Call Trace:
  static_key_disable+0x16/0x20
  start_kernel+0x192/0x4b3
  secondary_startup_64+0xa5/0xb0

Qspinlock will be choosed when dedicated pCPUs are available, however, the 
static virt_spin_lock_key is set in kvm_spinlock_init() before 
jump_label_init() 
has been called, which will result in a WARN(). This patch fixes it by delaying
the virt_spin_lock_key setup to .smp_prepare_cpus().

Reported-by: Davidlohr Bueso 
Cc: Paolo Bonzini 
Cc: Radim Krčmář 
Cc: Davidlohr Bueso 
Signed-off-by: Wanpeng Li 
---
Note: Peterz pointed out in the IRC we have to audit all the architectures that 
implement smp_prepare_boot_cpu() to see what they depend on if we want to move 
jump_label_init() before smp_prepare_boot_cpu(). So what this patch does is 
similar to the issue which handled in xen ca5d376e.

 arch/x86/kernel/kvm.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index 4ccbff6..747c61b 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -454,6 +454,13 @@ static void __init sev_map_percpu_data(void)
 }
 
 #ifdef CONFIG_SMP
+static void __init kvm_smp_prepare_cpus(unsigned int max_cpus)
+{
+   native_smp_prepare_cpus(max_cpus);
+   if (kvm_para_has_hint(KVM_HINTS_DEDICATED))
+   static_branch_disable(&virt_spin_lock_key);
+}
+
 static void __init kvm_smp_prepare_boot_cpu(void)
 {
/*
@@ -557,6 +564,7 @@ static void __init kvm_guest_init(void)
kvm_setup_vsyscall_timeinfo();
 
 #ifdef CONFIG_SMP
+   smp_ops.smp_prepare_cpus = kvm_smp_prepare_cpus;
smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu;
if (cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "x86/kvm:online",
  kvm_cpu_online, kvm_cpu_down_prepare) < 0)
@@ -737,10 +745,8 @@ void __init kvm_spinlock_init(void)
if (!kvm_para_has_feature(KVM_FEATURE_PV_UNHALT))
return;
 
-   if (kvm_para_has_hint(KVM_HINTS_DEDICATED)) {
-   static_branch_disable(&virt_spin_lock_key);
+   if (kvm_para_has_hint(KVM_HINTS_DEDICATED))
return;
-   }
 
__pv_init_lock_hash();
pv_lock_ops.queued_spin_lock_slowpath = __pv_queued_spin_lock_slowpath;
-- 
2.7.4



Re: [PATCH v1 11/16] rtc: mediatek: move the declaration into a globally visible header file

2018-03-24 Thread Sean Wang
On Sat, 2018-03-24 at 17:00 -0300, Fabio Estevam wrote:
> On Fri, Mar 23, 2018 at 6:15 AM,   wrote:
> 
> > --- /dev/null
> > +++ b/include/linux/rtc/mt6397.h
> > @@ -0,0 +1,72 @@
> > +
> > +// SPDX-License-Identifier: GPL-2.0
> 
> According to Documentation/process/license-rules.rst the SPDX notation
> for C header file should be:
> 
> /* SPDX-License-Identifier: GPL-2.0 */


Thank you, I'll have an improvement according to the license rule.





Re: [v6] usb: ohci: Proper handling of ed_rm_list to handle race condition between usb_kill_urb() and finish_unlinks()

2018-03-24 Thread Jonathan Liu
Hi,

On 25 March 2018 at 12:21, Jonathan Liu  wrote:
> Hi,
>
> On 8 February 2018 at 14:55, Jeffy Chen  wrote:
>> From: AMAN DEEP 
>>
>> There is a race condition between finish_unlinks->finish_urb() function
>> and usb_kill_urb() in ohci controller case. The finish_urb calls
>> spin_unlock(&ohci->lock) before usb_hcd_giveback_urb() function call,
>> then if during this time, usb_kill_urb is called for another endpoint,
>> then new ed will be added to ed_rm_list at beginning for unlink, and
>> ed_rm_list will point to newly added.
>>
>> When finish_urb() is completed in finish_unlinks() and ed->td_list
>> becomes empty as in below code (in finish_unlinks() function):
>>
>> if (list_empty(&ed->td_list)) {
>> *last = ed->ed_next;
>> ed->ed_next = NULL;
>> } else if (ohci->rh_state == OHCI_RH_RUNNING) {
>> *last = ed->ed_next;
>> ed->ed_next = NULL;
>> ed_schedule(ohci, ed);
>> }
>>
>> The *last = ed->ed_next will make ed_rm_list to point to ed->ed_next
>> and previously added ed by usb_kill_urb will be left unreferenced by
>> ed_rm_list. This causes usb_kill_urb() hang forever waiting for
>> finish_unlink to remove added ed from ed_rm_list.
>>
>> The main reason for hang in this race condtion is addition and removal
>> of ed from ed_rm_list in the beginning during usb_kill_urb and later
>> last* is modified in finish_unlinks().
>>
>> As suggested by Alan Stern, the solution for proper handling of
>> ohci->ed_rm_list is to remove ed from the ed_rm_list before finishing
>> any URBs. Then at the end, we can add ed back to the list if necessary.
>>
>> This properly handle the updated ohci->ed_rm_list in usb_kill_urb().
>>
>> Fixes:977dcfdc6031("USB:OHCI:don't lose track of EDs when a controller dies")
>> Acked-by: Alan Stern 
>> CC: 
>> Signed-off-by: Aman Deep 
>> Signed-off-by: Jeffy Chen 
>> ---
>>
>> Changes in v6:
>> This is a resend of Aman Deep's v5 patch [0], which solved the hang we
>> hit [1]. (Thanks Aman :)
>>
>> The v5 has some format issues, so i slightly adjust the commit message.
>>
>> [0] https://www.spinics.net/lists/linux-usb/msg129010.html
>> [1] https://bugs.chromium.org/p/chromium/issues/detail?id=803749
>>
>>  drivers/usb/host/ohci-q.c | 17 ++---
>>  1 file changed, 10 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/usb/host/ohci-q.c b/drivers/usb/host/ohci-q.c
>> index b2ec8c399363..4ccb85a67bb3 100644
>> --- a/drivers/usb/host/ohci-q.c
>> +++ b/drivers/usb/host/ohci-q.c
>> @@ -1019,6 +1019,8 @@ static void finish_unlinks(struct ohci_hcd *ohci)
>>  * have modified this list.  normally it's just prepending
>>  * entries (which we'd ignore), but paranoia won't hurt.
>>  */
>> +   *last = ed->ed_next;
>> +   ed->ed_next = NULL;
>> modified = 0;
>>
>> /* unlink urbs as requested, but rescan the list after
>> @@ -1077,21 +1079,22 @@ static void finish_unlinks(struct ohci_hcd *ohci)
>> goto rescan_this;
>>
>> /*
>> -* If no TDs are queued, take ED off the ed_rm_list.
>> +* If no TDs are queued, ED is now idle.
>>  * Otherwise, if the HC is running, reschedule.
>> -* If not, leave it on the list for further dequeues.
>> +* If the HC isn't running, add ED back to the
>> +* start of the list for later processing.
>>  */
>> if (list_empty(&ed->td_list)) {
>> -   *last = ed->ed_next;
>> -   ed->ed_next = NULL;
>> ed->state = ED_IDLE;
>> list_del(&ed->in_use_list);
>> } else if (ohci->rh_state == OHCI_RH_RUNNING) {
>> -   *last = ed->ed_next;
>> -   ed->ed_next = NULL;
>> ed_schedule(ohci, ed);
>> } else {
>> -   last = &ed->ed_next;
>> +   ed->ed_next = ohci->ed_rm_list;
>> +   ohci->ed_rm_list = ed;
>> +   /* Don't loop on the same ED */
>> +   if (last == &ohci->ed_rm_list)
>> +   last = &ed->ed_next;
>> }
>>
>> if (modified)
>
> I am experiencing a USB function call hang from userspace with OCHI
> (full speed USB device) after updating from Linux 4.14.15 to 4.14.24
> and noticed this commit.
>
> Here is the Linux 4.14.24 kernel stack trace (extracted from SysRq+w
> and amended with addr2line):
> [] (__schedule) from [] (schedule+0x50/0xb4)
> kernel/sched/core.c:2792
> [] (schedule) from []
> (usb_kill_urb.part.3+0x78/0xa8) include/asm-generic/preempt.h:59
> [] (usb_kill_urb.part.3) from []
> (usbdev_ioctl+0x1288/0x1cf0) drivers/usb/core/urb.c:690
> [] (usbdev_ioctl) fro

Re: [RFC PATCH 5/6] sched/fair: Select an energy-efficient CPU on task wake-up

2018-03-24 Thread Quentin Perret
On Wednesday 21 Mar 2018 at 15:35:18 (+), Patrick Bellasi wrote:
> On 20-Mar 09:43, Dietmar Eggemann wrote:
> > From: Quentin Perret 
> 
> [...]
> 
> > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> > index 76bd46502486..65a1bead0773 100644
> > --- a/kernel/sched/fair.c
> > +++ b/kernel/sched/fair.c
> > @@ -6513,6 +6513,60 @@ static unsigned long compute_energy(struct 
> > task_struct *p, int dst_cpu)
> > return energy;
> >  }
> > 
> > +static bool task_fits(struct task_struct *p, int cpu)
> > +{
> > +   unsigned long next_util = cpu_util_next(cpu, p, cpu);
> > +
> > +   return util_fits_capacity(next_util, capacity_orig_of(cpu));
>  ^
> 
> Since here we are at scheduling CFS tasks, should we not better use
> capacity_of() to account for RT/IRQ pressure ?

Yes, definitely. I change this in v2.

> 
> > +}
> > +
> > +static int find_energy_efficient_cpu(struct sched_domain *sd,
> > +   struct task_struct *p, int prev_cpu)
> > +{
> > +   unsigned long cur_energy, prev_energy, best_energy;
> > +   int cpu, best_cpu = prev_cpu;
> > +
> > +   if (!task_util(p))
> 
> We are still waking up a task... what if the task was previously
> running on a big CPU which is now idle?
> 
> I understand that from a _relative_ energy_diff standpoint there is
> not much to do for a 0 utilization task. However, for those tasks we
> can still try to return the most energy efficient CPU among the ones
> in their cpus_allowed mask.
> 
> It should be a relatively low overhead (maybe contained in a fallback
> most_energy_efficient_cpu() kind of function) which allows, for
> example on ARM big.LITTLE systems, to consolidate those tasks on
> LITTLE CPUs instead for example keep running them on a big CPU.

H so the difficult thing about a task with 0 util is that you don't
know if this is really a small task, or a big task with a very long
period. The only useful thing you know for sure about the task is where
it ran last time, so I guess that makes sense to use that information
rather than make assumptions. There is no perfect solution using the
util_avg of the task.

Now, UTIL_EST is changing the game here. If we use it for task placement
(which I think is the right thing to do), this issue should be a lot
easier to solve. What do you think ?

Thanks,
Quentin


Re: [RFC PATCH 5/6] sched/fair: Select an energy-efficient CPU on task wake-up

2018-03-24 Thread Quentin Perret
On Friday 23 Mar 2018 at 16:00:59 (+), Morten Rasmussen wrote:
> On Thu, Mar 22, 2018 at 09:27:43AM -0700, Joel Fernandes wrote:
> > Hi,
> > 
> > On Tue, Mar 20, 2018 at 2:43 AM, Dietmar Eggemann
> >  wrote:

[...]

> > Is it possible that before the wakeup, the task's affinity is changed
> > so that p->cpus_allowed no longer contains prev_cpu ? In that case
> > prev_energy wouldn't matter since previous CPU is no longer an option?
> 
> It is possible to wake-up with a disallowed prev_cpu. In fact
> select_idle_sibling() may happily return a disallowed cpu in that case.
> The mistake gets fixed in select_task_rq() which uses
> select_fallback_rq() to find an allowed cpu instead.
> 
> Could we fix the issue in find_energy_efficient_cpu() by a simple test
> like below
> 
> if (cpumask_test_cpu(prev_cpu, &p->cpus_allowed))
>   prev_energy = best_energy = compute_energy(p, prev_cpu);
> else
>   prev_energy = best_energy = ULONG_MAX;

Right, that should work. I'll change this in v2.

Thanks,
Quentin


Re: [PATCH 6/8] Pmalloc selftest

2018-03-24 Thread Igor Stoppa


On 14/03/18 14:25, Matthew Wilcox wrote:
> On Tue, Mar 13, 2018 at 11:45:52PM +0200, Igor Stoppa wrote:
>> Add basic self-test functionality for pmalloc.
> 
> Here're some additional tests for your test-suite:
> 
>   for (i = 1; i; i *= 2)
>   pzalloc(pool, i - 1, GFP_KERNEL);
> 

Ok, I have almost finished the rewrite.
I still have to address this comment.

When I run the test, eventually the system runs out of memory, it keeps
getting allocation errors from vmalloc, until i finally overflows and
becomes 0.

Am I supposed to do something about it?
If pmalloc receives a request that the vmalloc backend cannot satisfy, I
would prefer that vmalloc itself produces the warning and pmalloc
returns NULL.

This doesn't look like a test case that one can leave always enabled in
a build, but maybe I'm missing the point.

--
igor



[PATCH v2 0/2] SDM845 System Cache Driver

2018-03-24 Thread Rishabh Bhatnagar
This series implements system cache or LLCC(Last Level Cache Controller) driver
for SDM845 SOC. The purpose of the driver is to partition the system cache and
program the settings such as priortiy, lines to probe while doing a look up
in the system cache, low power related settings etc. The partitions are called
cache slices. Each cache slice is associated with size and SCID(System Cache ID)
The driver also provides API for clients to query the cache slice details,
activate and deactivate them.

The driver can be broadly classified into:
* SOC specific driver: llcc-sdm845.c: Cache partitioning and cache slice
properties for usecases on sdm845 that need to use system cache.

* API : llcc-slice.c: Exports APIs to clients to query cache slice details,
activate and deactivate cache slices. Register the child devices using platform 
APIs.

Changes since v1:
* Added Makefile and Kconfig.

ckad...@codeaurora.org (2):
  Documentation: Documentaion for qcom, llcc
  drivers: soc: Add LLCC driver

 .../devicetree/bindings/arm/msm/qcom,llcc.txt  |  70 
 drivers/soc/qcom/Kconfig   |  16 +
 drivers/soc/qcom/Makefile  |   2 +
 drivers/soc/qcom/llcc-sdm845.c | 120 ++
 drivers/soc/qcom/llcc-slice.c  | 454 +
 include/linux/soc/qcom/llcc-qcom.h | 178 
 6 files changed, 840 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/msm/qcom,llcc.txt
 create mode 100644 drivers/soc/qcom/llcc-sdm845.c
 create mode 100644 drivers/soc/qcom/llcc-slice.c
 create mode 100644 include/linux/soc/qcom/llcc-qcom.h

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v2 2/2] drivers: soc: Add LLCC driver

2018-03-24 Thread Rishabh Bhatnagar
LLCC (Last Level Cache Controller) provides additional cache memory
in the system. LLCC is partitioned into muliple slices and each
slice getting its own priority, size, ID and other config parameters.
LLCC driver programs these parameters for each slice. Clients that
are assigned to use LLCC need to get information such size & ID of the
 slice they get and activate or deactivate the slice as needed. LLCC driver
provides API interfaces for the clients to perform these operations.

Change-Id: I93c5f3225d0a917f0d6c64c7588a4e64e33a59ed
Signed-off-by: Channagoud Kadabi 
Signed-off-by: Rishabh Bhatnagar 
---
 drivers/soc/qcom/Kconfig   |  16 ++
 drivers/soc/qcom/Makefile  |   2 +
 drivers/soc/qcom/llcc-sdm845.c | 120 ++
 drivers/soc/qcom/llcc-slice.c  | 454 +
 include/linux/soc/qcom/llcc-qcom.h | 178 +++
 5 files changed, 770 insertions(+)
 create mode 100644 drivers/soc/qcom/llcc-sdm845.c
 create mode 100644 drivers/soc/qcom/llcc-slice.c
 create mode 100644 include/linux/soc/qcom/llcc-qcom.h

diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig
index e050eb8..28237fc 100644
--- a/drivers/soc/qcom/Kconfig
+++ b/drivers/soc/qcom/Kconfig
@@ -21,6 +21,22 @@ config QCOM_GSBI
   functions for connecting the underlying serial UART, SPI, and I2C
   devices to the output pins.
 
+config QCOM_LLCC
+   tristate "Qualcomm Technologies, Inc. LLCC driver"
+   depends on ARCH_QCOM
+   help
+ Qualcomm Technologies, Inc. platform specific LLCC driver for Last
+ Level Cache. This provides interfaces to client's that use the LLCC.
+ Say yes here to enable LLCC slice driver.
+
+config QCOM_SDM845_LLCC
+   tristate "Qualcomm Technologies, Inc. SDM845 LLCC driver"
+   depends on QCOM_LLCC
+   help
+ Say yes here to enable the LLCC driver for SDM845. This is provides
+ data required to configure LLCC so that clients can start using the
+ LLCC slices.
+
 config QCOM_MDT_LOADER
tristate
select QCOM_SCM
diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile
index dcebf28..234560f 100644
--- a/drivers/soc/qcom/Makefile
+++ b/drivers/soc/qcom/Makefile
@@ -12,3 +12,5 @@ obj-$(CONFIG_QCOM_SMEM_STATE) += smem_state.o
 obj-$(CONFIG_QCOM_SMP2P)   += smp2p.o
 obj-$(CONFIG_QCOM_SMSM)+= smsm.o
 obj-$(CONFIG_QCOM_WCNSS_CTRL) += wcnss_ctrl.o
+obj-$(CONFIG_QCOM_LLCC) += llcc-core.o llcc-slice.o
+obj-$(CONFIG_QCOM_SDM845_LLCC) += llcc-sdm845.o
diff --git a/drivers/soc/qcom/llcc-sdm845.c b/drivers/soc/qcom/llcc-sdm845.c
new file mode 100644
index 000..cd431d9
--- /dev/null
+++ b/drivers/soc/qcom/llcc-sdm845.c
@@ -0,0 +1,120 @@
+/* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+ 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+
+/*
+ * SCT entry contains of the following parameters
+ * name: Name of the client's use case for which the llcc slice is used
+ * uid: Unique id for the client's use case
+ * slice_id: llcc slice id for each client
+ * max_cap: The maximum capacity of the cache slice provided in KB
+ * priority: Priority of the client used to select victim line for replacement
+ * fixed_size: Determine of the slice has a fixed capacity
+ * bonus_ways: Bonus ways to be used by any slice, bonus way is used only if
+ * it't not a reserved way.
+ * res_ways: Reserved ways for the cache slice, the reserved ways cannot be 
+ *  used by any other client than the one its assigned to.
+ * cache_mode: Each slice operates as a cache, this controls the mode of the
+ * slice normal or TCM
+ * probe_target_ways: Determines what ways to probe for access hit. When
+ *configured to 1 only bonus and reseved ways are probed.
+ *when configured to 0 all ways in llcc are probed.
+ * dis_cap_alloc: Disable capacity based allocation for a client
+ * retain_on_pc: If this bit is set and client has maitained active vote
+ *   then the ways assigned to this client are not flushed on power
+ *   collapse.
+ * activate_on_init: Activate the slice immidiately after the SCT is programmed
+ */
+#define SCT_ENTRY(n, uid, sid, mc, p, fs, bway, rway, cmod, ptw, dca, rp, a) \
+   {   \
+   .name = n,  \
+   .usecase_id = uid,  \
+ 

[PATCH v2 1/2] Documentation: Documentation for qcom, llcc

2018-03-24 Thread Rishabh Bhatnagar
Documentation for last level cache controller device tree bindings,
client bindings usage examples.

Change-Id: Ic2d6d6154ab8269cfce6828e9f2250320a0572e8
Signed-off-by: Channagoud Kadabi 
Signed-off-by: Rishabh Bhatnagar 
---
 .../devicetree/bindings/arm/msm/qcom,llcc.txt  | 70 ++
 1 file changed, 70 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/msm/qcom,llcc.txt

diff --git a/Documentation/devicetree/bindings/arm/msm/qcom,llcc.txt 
b/Documentation/devicetree/bindings/arm/msm/qcom,llcc.txt
new file mode 100644
index 000..ceb20a4
--- /dev/null
+++ b/Documentation/devicetree/bindings/arm/msm/qcom,llcc.txt
@@ -0,0 +1,70 @@
+== Introduction==
+
+LLCC (Last Level Cache Controller) driver is implemented as a platform device.
+The driver Programs the SCT (system configuration table). The SCT programming 
+divides the system cache into slices. Each slice is assigned an ID A.K.A 
+SCID(Sub-cache ID).
+HW modules that are designated to use the system cache are known as clients.   
+Each client must also be represented as a node in the device tree just like
+any other hw module.   
+One client can have multiple SCID's assigned meaning each client could get 

+multiple slices in the cache. Client can use the slices for various pre-defined
+usecases. Each client defines a set of names for these usecases in its 
+device tree binding.   
+Client makes a request to LLCC device to get cache-slices properties for each  
+of its usecase. Client gets the information like cache slice ID and size of the
+cache slice.
+
+== llcc device ==
+
+Properties:
+- compatible:
+Usage: required
+Value type: 
+Definition: must be "qcom,sdm855-llcc"
+
+- reg:
+Usage: required
+Value Type: 
+Definition: must be addresses and sizes of the LLCC registers
+
+- #cache-cells:
+Usage: required
+Value Type: 
+Definition: Number of cache cells, must be 1
+
+- max-slices:
+usage: required
+Value Type: 
+Definition: Number of cache slices supported by hardware
+
+Example:
+
+   llcc: qcom,sdm855-llcc@0110 {
+   compatible = "qcom,sdm845-llcc";
+   reg = <0x0110 0x25>;
+   #cache-cells = <1>;
+   max-slices = <32>;
+   };
+
+== Client ==
+
+Required properties:
+- cache-slice-names:
+Usage: required
+Value type: 
+Definition: A set of names that identify the usecase names of a client 
that
+   uses cache slice. These strings are used to look up the 
cache slice
+   entries by name.
+
+- cache-slices:
+Usage: required
+Value type: 
+Definition: The tuple has phandle to llcc device as the first argument 
and 
+   the second argument is the usecase id of the client.
+For Example:
+
+venus {
+   cache-slice-names = "vidsc0", "vidsc1";
+   cache-slices = <&llcc 2>, <&llcc 3>;
+};
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[GIT PULL] Revert "mqueue: switch to on-demand creation of internal mount"

2018-03-24 Thread Eric W. Biederman

Linus,

Please pull the for-linus branch from the git tree:

   git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace.git 
for-linus

   HEAD: cfb2f6f6e0ba11ea7b263d6b69c170c4b32ac0ea Revert "mqueue: switch to 
on-demand creation of internal mount"

This fixes a regression that came in the merge window for v4.16.  The
problem is that the permissions for mounting and using the mqueuefs
filesystem are broken.  The necessary permission check is missing
letting people who should not be able to mount mqueuefs mount mqueuefs.
The field sb->s_user_ns is set incorrectly not allowing the mounter of
mqueuefs to remount and otherwise have proper control over the
filesystem.

Al Viro and I see the path to the necessary fixes differently and I am
not even certain at this point he actually sees all of the necessary
fixes.  Given a couple weeks we can probably work something out but I
don't see the review being resolved in time for the final v4.16.  I
don't want v4.16 shipping with a nasty regression.  So unfortunately I
am sending a revert.

Eric

From: "Eric W. Biederman" 
Date: Sat, 24 Mar 2018 11:28:14 -0500
Subject: [PATCH] Revert "mqueue: switch to on-demand creation of internal mount"

This reverts commit 36735a6a2b5e042db1af956ce4bcc13f3ff99e21.

Aleksa Sarai  writes:
> [REGRESSION v4.16-rc6] [PATCH] mqueue: forbid unprivileged user access to 
> internal mount
>
> Felix reported weird behaviour on 4.16.0-rc6 with regards to mqueue[1],
> which was introduced by 36735a6a2b5e ("mqueue: switch to on-demand
> creation of internal mount").
>
> Basically, the reproducer boils down to being able to mount mqueue if
> you create a new user namespace, even if you don't unshare the IPC
> namespace.
>
> Previously this was not possible, and you would get an -EPERM. The mount
> is the *host* mqueue mount, which is being cached and just returned from
> mqueue_mount(). To be honest, I'm not sure if this is safe or not (or if
> it was intentional -- since I'm not familiar with mqueue).
>
> To me it looks like there is a missing permission check. I've included a
> patch below that I've compile-tested, and should block the above case.
> Can someone please tell me if I'm missing something? Is this actually
> safe?
>
> [1]: https://github.com/docker/docker/issues/36674

The issue is a lot deeper than a missing permission check.  sb->s_user_ns
was is improperly set as well.  So in addition to the filesystem being
mounted when it should not be mounted, so things are not allow that should
be.

We are practically to the release of 4.16 and there is no agreement between
Al Viro and myself on what the code should looks like to fix things properly.
So revert the code to what it was before so that we can take our time
and discuss this properly.

Fixes: 36735a6a2b5e ("mqueue: switch to on-demand creation of internal mount")
Reported-by: Felix Abecassis 
Reported-by: Aleksa Sarai 
Signed-off-by: "Eric W. Biederman" 
---
 ipc/mqueue.c | 74 
 1 file changed, 19 insertions(+), 55 deletions(-)

diff --git a/ipc/mqueue.c b/ipc/mqueue.c
index d7f309f74dec..a808f29d4c5a 100644
--- a/ipc/mqueue.c
+++ b/ipc/mqueue.c
@@ -325,9 +325,8 @@ static struct inode *mqueue_get_inode(struct super_block 
*sb,
 static int mqueue_fill_super(struct super_block *sb, void *data, int silent)
 {
struct inode *inode;
-   struct ipc_namespace *ns = data;
+   struct ipc_namespace *ns = sb->s_fs_info;
 
-   sb->s_fs_info = ns;
sb->s_iflags |= SB_I_NOEXEC | SB_I_NODEV;
sb->s_blocksize = PAGE_SIZE;
sb->s_blocksize_bits = PAGE_SHIFT;
@@ -344,44 +343,18 @@ static int mqueue_fill_super(struct super_block *sb, void 
*data, int silent)
return 0;
 }
 
-static struct file_system_type mqueue_fs_type;
-/*
- * Return value is pinned only by reference in ->mq_mnt; it will
- * live until ipcns dies.  Caller does not need to drop it.
- */
-static struct vfsmount *mq_internal_mount(void)
-{
-   struct ipc_namespace *ns = current->nsproxy->ipc_ns;
-   struct vfsmount *m = ns->mq_mnt;
-   if (m)
-   return m;
-   m = kern_mount_data(&mqueue_fs_type, ns);
-   spin_lock(&mq_lock);
-   if (unlikely(ns->mq_mnt)) {
-   spin_unlock(&mq_lock);
-   if (!IS_ERR(m))
-   kern_unmount(m);
-   return ns->mq_mnt;
-   }
-   if (!IS_ERR(m))
-   ns->mq_mnt = m;
-   spin_unlock(&mq_lock);
-   return m;
-}
-
 static struct dentry *mqueue_mount(struct file_system_type *fs_type,
 int flags, const char *dev_name,
 void *data)
 {
-   struct vfsmount *m;
-   if (flags & SB_KERNMOUNT)
-   return mount_nodev(fs_type, flags, data, mqueue_fill_super);
-   m = mq_internal_mount();
-   if (IS_ERR(m))
-   return ERR_CAST(m);
-   atomic_inc(&m->mnt_sb->s_active);
-   down_write(&m->mnt

Re: [v6] usb: ohci: Proper handling of ed_rm_list to handle race condition between usb_kill_urb() and finish_unlinks()

2018-03-24 Thread Jonathan Liu
Hi,

On 8 February 2018 at 14:55, Jeffy Chen  wrote:
> From: AMAN DEEP 
>
> There is a race condition between finish_unlinks->finish_urb() function
> and usb_kill_urb() in ohci controller case. The finish_urb calls
> spin_unlock(&ohci->lock) before usb_hcd_giveback_urb() function call,
> then if during this time, usb_kill_urb is called for another endpoint,
> then new ed will be added to ed_rm_list at beginning for unlink, and
> ed_rm_list will point to newly added.
>
> When finish_urb() is completed in finish_unlinks() and ed->td_list
> becomes empty as in below code (in finish_unlinks() function):
>
> if (list_empty(&ed->td_list)) {
> *last = ed->ed_next;
> ed->ed_next = NULL;
> } else if (ohci->rh_state == OHCI_RH_RUNNING) {
> *last = ed->ed_next;
> ed->ed_next = NULL;
> ed_schedule(ohci, ed);
> }
>
> The *last = ed->ed_next will make ed_rm_list to point to ed->ed_next
> and previously added ed by usb_kill_urb will be left unreferenced by
> ed_rm_list. This causes usb_kill_urb() hang forever waiting for
> finish_unlink to remove added ed from ed_rm_list.
>
> The main reason for hang in this race condtion is addition and removal
> of ed from ed_rm_list in the beginning during usb_kill_urb and later
> last* is modified in finish_unlinks().
>
> As suggested by Alan Stern, the solution for proper handling of
> ohci->ed_rm_list is to remove ed from the ed_rm_list before finishing
> any URBs. Then at the end, we can add ed back to the list if necessary.
>
> This properly handle the updated ohci->ed_rm_list in usb_kill_urb().
>
> Fixes:977dcfdc6031("USB:OHCI:don't lose track of EDs when a controller dies")
> Acked-by: Alan Stern 
> CC: 
> Signed-off-by: Aman Deep 
> Signed-off-by: Jeffy Chen 
> ---
>
> Changes in v6:
> This is a resend of Aman Deep's v5 patch [0], which solved the hang we
> hit [1]. (Thanks Aman :)
>
> The v5 has some format issues, so i slightly adjust the commit message.
>
> [0] https://www.spinics.net/lists/linux-usb/msg129010.html
> [1] https://bugs.chromium.org/p/chromium/issues/detail?id=803749
>
>  drivers/usb/host/ohci-q.c | 17 ++---
>  1 file changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/usb/host/ohci-q.c b/drivers/usb/host/ohci-q.c
> index b2ec8c399363..4ccb85a67bb3 100644
> --- a/drivers/usb/host/ohci-q.c
> +++ b/drivers/usb/host/ohci-q.c
> @@ -1019,6 +1019,8 @@ static void finish_unlinks(struct ohci_hcd *ohci)
>  * have modified this list.  normally it's just prepending
>  * entries (which we'd ignore), but paranoia won't hurt.
>  */
> +   *last = ed->ed_next;
> +   ed->ed_next = NULL;
> modified = 0;
>
> /* unlink urbs as requested, but rescan the list after
> @@ -1077,21 +1079,22 @@ static void finish_unlinks(struct ohci_hcd *ohci)
> goto rescan_this;
>
> /*
> -* If no TDs are queued, take ED off the ed_rm_list.
> +* If no TDs are queued, ED is now idle.
>  * Otherwise, if the HC is running, reschedule.
> -* If not, leave it on the list for further dequeues.
> +* If the HC isn't running, add ED back to the
> +* start of the list for later processing.
>  */
> if (list_empty(&ed->td_list)) {
> -   *last = ed->ed_next;
> -   ed->ed_next = NULL;
> ed->state = ED_IDLE;
> list_del(&ed->in_use_list);
> } else if (ohci->rh_state == OHCI_RH_RUNNING) {
> -   *last = ed->ed_next;
> -   ed->ed_next = NULL;
> ed_schedule(ohci, ed);
> } else {
> -   last = &ed->ed_next;
> +   ed->ed_next = ohci->ed_rm_list;
> +   ohci->ed_rm_list = ed;
> +   /* Don't loop on the same ED */
> +   if (last == &ohci->ed_rm_list)
> +   last = &ed->ed_next;
> }
>
> if (modified)

I am experiencing a USB function call hang from userspace with OCHI
(full speed USB device) after updating from Linux 4.14.15 to 4.14.24
and noticed this commit.

Here is the Linux 4.14.24 kernel stack trace (extracted from SysRq+w
and amended with addr2line):
[] (__schedule) from [] (schedule+0x50/0xb4)
kernel/sched/core.c:2792
[] (schedule) from []
(usb_kill_urb.part.3+0x78/0xa8) include/asm-generic/preempt.h:59
[] (usb_kill_urb.part.3) from []
(usbdev_ioctl+0x1288/0x1cf0) drivers/usb/core/urb.c:690
[] (usbdev_ioctl) from []
(do_vfs_ioctl+0x9c/0x8ec) drivers/usb/core/devio.c:1835
[] (do_vfs_ioctl) from [] (SyS_ioctl+0x34/0x5c)
fs/ioctl.c:47
[] (SyS_ioctl) from [] (ret_fast_syscall+0x0/0x54)
include/

RE: [PATCH net-next,1/2] hv_netvsc: Fix the return status in RX path

2018-03-24 Thread Haiyang Zhang


> -Original Message-
> From: Michael Kelley (EOSG)
> Sent: Saturday, March 24, 2018 12:48 PM
> To: Haiyang Zhang ; da...@davemloft.net;
> net...@vger.kernel.org
> Cc: KY Srinivasan ; Stephen Hemminger
> ; o...@aepfle.de; vkuzn...@redhat.com;
> de...@linuxdriverproject.org; linux-kernel@vger.kernel.org
> Subject: RE: [PATCH net-next,1/2] hv_netvsc: Fix the return status in RX path
> 
> > -Original Message-
> > From: linux-kernel-ow...@vger.kernel.org
> >  On Behalf Of Haiyang Zhang
> > Sent: Thursday, March 22, 2018 12:01 PM
> > To: da...@davemloft.net; net...@vger.kernel.org
> > Cc: Haiyang Zhang ; KY Srinivasan
> > ; Stephen Hemminger ;
> > o...@aepfle.de; vkuzn...@redhat.com; de...@linuxdriverproject.org;
> > linux-kernel@vger.kernel.org
> > Subject: [PATCH net-next,1/2] hv_netvsc: Fix the return status in RX
> > path
> >
> > From: Haiyang Zhang 
> >
> > As defined in hyperv_net.h, the NVSP_STAT_SUCCESS is one not zero.
> > Some functions returns 0 when it actually means NVSP_STAT_SUCCESS.
> > This patch fixes them.
> >
> > In netvsc_receive(), it puts the last RNDIS packet's receive status
> > for all packets in a vmxferpage which may contain multiple RNDIS
> > packets.
> > This patch puts NVSP_STAT_FAIL in the receive completion if one of the
> > packets in a vmxferpage fails.
> 
> This patch changes the status field that is being reported back to the Hyper-V
> host in the receive completion message in
> enq_receive_complete().   The current code reports 0 on success,
> and with the patch, it will report 1 on success.  So does this change affect
> anything on the Hyper-V side?  Or is Hyper-V just ignoring
> the value?   If this change doesn't have any impact on the
> interactions with Hyper-V, perhaps it would be good to explain why in the
> commit message.

Here is the definition of each status code for NetVSP. 
enum {
NVSP_STAT_NONE = 0,
NVSP_STAT_SUCCESS,
NVSP_STAT_FAIL,
NVSP_STAT_PROTOCOL_TOO_NEW,
NVSP_STAT_PROTOCOL_TOO_OLD,
NVSP_STAT_INVALID_RNDIS_PKT,
NVSP_STAT_BUSY,
NVSP_STAT_PROTOCOL_UNSUPPORTED,
NVSP_STAT_MAX,
};

Existing code returns NVSP_STAT_NONE = 0, and with this patch
we return NVSP_STAT_SUCCESS = 1. 
Based on testing, either way works for now. But for correctness
and future stability (e.g. host side becomes more stringent), we
should follow the protocol.

Thanks,
- Haiyang



Re: [PATCH] mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct

2018-03-24 Thread Yang Shi



On 3/23/18 9:30 PM, Matthew Wilcox wrote:

So, introduce a new rwlock in mm_struct to protect the concurrent access
to arg_start|end and env_start|end.

I don't think an rwlock makes much sense here.  There is almost no
concurrency on the read side, and an rwlock is more expensive than
a spinlock.  Just use a spinlock.


Thanks for the comment. Yes, actually there is not concurrency on the 
read side, will change to regular spin lock.


Yang




RE: [PATCH v3] cpuidle: poll_state: Add time limit to poll_idle()

2018-03-24 Thread Doug Smythies
On 2018.03.14 07:04 Rafael J. Wysocki wrote:

> If poll_idle() is allowed to spin until need_resched() returns 'true',
> it may actually spin for a much longer time than expected by the idle
> governor, since set_tsk_need_resched() is not always called by the
> timer interrupt handler.  If that happens, the CPU may spend much
> more time than anticipated in the "polling" state.
>
> To prevent that from happening, limit the time of the spinning loop
> in poll_idle().

...[snip]...

> +#define POLL_IDLE_TIME_LIMIT (TICK_NSEC / 16)

The other ongoing threads on this aside, potentially, there might
be another issue.

What if the next available idle state, after 0, has a residency
that is greater than TICK_NSEC / 16? Meaning these numbers, for example:

/sys/devices/system/cpu/cpu0/cpuidle/state*/residency

The suggestion is that upon a timeout exit from idle state 0,
the measured_us should maybe be rejected, because the statistics
are being biased and it doesn't seem to correct itself.

Up to 1300% (<- not a typo) extra power consumption has been observed.

Supporting experimental data:

My processor: 
/sys/devices/system/cpu/cpu0/cpuidle/state0/residency:0
/sys/devices/system/cpu/cpu0/cpuidle/state1/residency:2
/sys/devices/system/cpu/cpu0/cpuidle/state2/residency:20
/sys/devices/system/cpu/cpu0/cpuidle/state3/residency:211 <<< Important
/sys/devices/system/cpu/cpu0/cpuidle/state4/residency:345

A 1000 Hz kernel (TICK_NSEC/16) = 62.5 nsec; idle system:

Idle state 0 time: Typically 0 uSec.
Processor package power: 3.7 watts (steady)

Now, disable idle states 1 and 2:

Idle state 0 time (all 8 CPUs): ~~ 430 Seconds / minute
Processor package power: ~52 watts (1300% more power, 14X)

A 250 Hz kernel (TICK_NSEC/16) = 250 nSec; idle system:

Idle state 0 time: Typically < 1 mSec / minute
Processor package power: 3.7 to 3.8 watts

Now, disable idle states 1 and 2:

Idle state 0 time (all 8 CPUs): Typically 0 to 70 mSecs / minute
Processor package power: 3.7 to 3.8 watts

A 1000 Hz kernel with:

+#define POLL_IDLE_TIME_LIMIT   (TICK_NSEC / 4)

Note: Just for a test. I am not suggesting this should change.

instead. i.e. (TICK_NSEC/4) = 250 nSec.

Idle state 0 time: Typically 0 uSec.
Processor package power: 3.7 watts (steady)

Now, disable idle states 1 and 2:

Idle state 0 time (all 8 CPUs): Typically 0 to 70 mSecs / minute
Processor package power: ~3.8 watts

Note 1: My example is contrived via disabling idle states, so
I don't know if it actually needs to be worried about.

Note 2: I do not know if there is some processor where
cpuidle/state1/residency is > 62.5 nSec.

Note 3: I am trying to figure out a way to test rejecting
measured_us upon timeout exit, but haven't made much progress.

... Doug




Re: [PATCH net-next v2 2/2] cxgb4: collect hardware dump in second kernel

2018-03-24 Thread Eric W. Biederman
Thadeu Lima de Souza Cascardo  writes:

> On Sat, Mar 24, 2018 at 04:26:34PM +0530, Rahul Lakkireddy wrote:
>> Register callback to collect hardware/firmware dumps in second kernel
>> before hardware/firmware is initialized.  The dumps for each device
>> will be available under /sys/kernel/crashdd/cxgb4/ directory in second
>> kernel.
>> 
>> Signed-off-by: Rahul Lakkireddy 
>> Signed-off-by: Ganesh Goudar 
>> ---
>> v2:
>> - No Changes.
>> 
>> Changes since rfc v2:
>> - Update comments and commit message for sysfs change.
>> 
>> rfc v2:
>> - Updated dump registration to the new API in patch 1.
> [...]
>> diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c 
>> b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
>> index e880be8e3c45..265cb026f868 100644
>> --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
>> +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
>> @@ -5527,6 +5527,18 @@ static int init_one(struct pci_dev *pdev, const 
>> struct pci_device_id *ent)
>>  if (err)
>>  goto out_free_adapter;
>>  
>> +if (is_kdump_kernel()) {
>> +/* Collect hardware state and append to
>> + * /sys/kernel/crashdd/cxgb4/ directory
>> + */
>> +err = cxgb4_cudbg_crashdd_add_dump(adapter);
>> +if (err) {
>> +dev_warn(adapter->pdev_dev,
>> + "Fail collecting crash device dump, err: %d. 
>> Continuing\n",
>> + err);
>> +err = 0;
>> +}
>> +}
>>  
>
> The problem I see with this approach is that you require that the driver
> is built into the kdump kernel (or present as a module in the kdump
> initramfs), and that you will probe the device during the collection of
> the dumps.

Compared to doing something in a crashing kernel anything in the kdump
kernel is a walk in the park.  Nothing is trustable in a crashing
kernel.

> IMHO, if you are going to require the device to be probed by the same
> driver during kdump, you might just as well use the device object itself
> to present the crash data. I think that's what Stephen Hemminger meant
> when he said to use sysfs. No need at all for any special crashdd. Just
> add an attribute or attribute group to the device object.

Doing something with the device model might make sense.  I am not
certain it does.  It is quite possible the device is in such a weird
state that the device driver fails to initialize.  That doesn't
mean the device driver can't scrape the registers and present
meaningful information to the rest of the system.

Whatever you do with capturing the state needs to happen early before
the driver initializes and stomps on the relevant state.

I don't expect there is much for the driver model to do, unless we wish
to do something explicitly before the normal device probe methods
happen.  What we need is the infrastructure for catching what gets
read from the driver and placing it in the core dump.

> Otherwise, as Eric Biederman pointed out, you should just add that data
> into the vmcore before you kexec, so you don't even need to look at a
> different file, and the driver does not even need to be present in the
> kdump kernel.

No.  I do mean before a kexec on panic happens.  Doing anything with
gathering this kind of information before kexec on panic is a very very
very very bad idea that will almost certainly make crash dumps less
reliable.  Don't even think about doing extra work on the crash dump
path.  Not ever.  No.  No.  No.  No.

The reason we use kexec on panic instead just creating a core dump
in the kernel is that many have tried and no one has gotten the kernel
to create crash dumps when things go wrong and it matters.  Meanwhile
kexec on panic works more often than not.

I mean that /proc/vmcore is a device that is used to gather up the bits
of the crashing kernel and to present it in a format that is easy to
read/save.  The tools read /proc/vmcore.

The driver or whatever is gathering this information absolutely needs to
be in the kdump kernel.

Eric



Re: [RFC PATCH 5/6] sched/fair: Select an energy-efficient CPU on task wake-up

2018-03-24 Thread Joel Fernandes
On Fri, Mar 23, 2018 at 6:47 PM, Quentin Perret  wrote:
> On Thursday 22 Mar 2018 at 13:19:03 (-0700), Joel Fernandes wrote:
>> On Thu, Mar 22, 2018 at 11:06 AM, Patrick Bellasi
>>  wrote:
>
> [...]
>
>> >> > @@ -6555,6 +6613,14 @@ select_task_rq_fair(struct task_struct *p, int 
>> >> > prev_cpu, int sd_flag, int wake_f
>> >> > break;
>> >> > }
>> >> >
>> >> > +   /*
>> >> > +* Energy-aware task placement is performed on the 
>> >> > highest
>> >> > +* non-overutilized domain spanning over cpu and 
>> >> > prev_cpu.
>> >> > +*/
>> >> > +   if (want_energy && !sd_overutilized(tmp) &&
>> >> > +   cpumask_test_cpu(prev_cpu, sched_domain_span(tmp)))
>> >>
>> >> Shouldn't you check for the SD_ASYM_CPUCAPACITY flag here for tmp level?
>> >
>> > ... and this then should be covered by the previous check in
>> > wake_energy(), which sets want_energy.
>>
>> Right, but in a scenario which probably doesn't exist today where we
>> have both SD_ASYM_CPUCAPACITY and !SD_ASYM_CPUCAPACITY domains in the
>> hierarchy for which want_energy = 1, I was thinking if its more future
>> proof to check it and not make assumptions...
>
> So we can definitely have cases where SD_ASYM_CPUCAPACITY is not set at all
> sd levels. Today, on mobile systems, this flag is typically set only at DIE
> level for big.LITTLE platforms, and not at MC level.
> We enable EAS if we find _at least_ one domain that has this flag in the
> hierarchy, just to make sure we don't enable EAS for symmetric platform.
> It's just a way to check a property about the topology when EAS starts, not
> really a way to actually select the sd at which we do scheduling at
> runtime.

Yes Ok you're right we do have the ASYM flag set at some sd levels but
not others at the moment. Sorry about the hasty comment. I understand
what you're doing now, I am Ok with that.

thanks,

- Joel


Re: [REVIEW][PATCH 13/11] ipc/smack: Tidy up from the change in type of the ipc security hooks

2018-03-24 Thread Casey Schaufler
On 3/23/2018 10:42 PM, Eric W. Biederman wrote:
> Rename the variables shp, sma, msq to isp. As that is how the code already
> refers to those variables.

Thanks. It's important to keep the code readable.

> Collapse smack_of_shm, smack_of_sem, and smack_of_msq into smack_of_ipc,
> as the three functions had become completely identical.

Thanks. Completely reasonable and correct.

> Collapse smack_shm_alloc_security, smack_sem_alloc_security and
> smack_msg_queue_alloc_security into smack_ipc_alloc_security as the
> three functions had become identical.
>
> Collapse smack_shm_free_security, smack_sem_free_security and
> smack_msg_queue_free_security into smack_ipc_free_security as the three
> functions had become identical.

This is reasonable but unprecedented. Nowhere else is the
same function used to supply multiple LSM hooks. Does anyone
out there see a reason not to do this?

> Requested-by: Casey Schaufler 
> Signed-off-by: "Eric W. Biederman" 
> ---
>  security/smack/smack_lsm.c | 197 
> +
>  1 file changed, 58 insertions(+), 139 deletions(-)
>
> diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
> index d960c2ea8d79..0735b8db158b 100644
> --- a/security/smack/smack_lsm.c
> +++ b/security/smack/smack_lsm.c
> @@ -2945,25 +2945,24 @@ static void smack_msg_msg_free_security(struct 
> msg_msg *msg)
>  }
>  
>  /**
> - * smack_of_shm - the smack pointer for the shm
> - * @shp: the object
> + * smack_of_ipc - the smack pointer for the ipc
> + * @isp: the object
>   *
>   * Returns a pointer to the smack value
>   */
> -static struct smack_known *smack_of_shm(struct kern_ipc_perm *shp)
> +static struct smack_known *smack_of_ipc(struct kern_ipc_perm *isp)
>  {
> - return (struct smack_known *)shp->security;
> + return (struct smack_known *)isp->security;
>  }
>  
>  /**
> - * smack_shm_alloc_security - Set the security blob for shm
> - * @shp: the object
> + * smack_ipc_alloc_security - Set the security blob for ipc
> + * @isp: the object
>   *
>   * Returns 0
>   */
> -static int smack_shm_alloc_security(struct kern_ipc_perm *shp)
> +static int smack_ipc_alloc_security(struct kern_ipc_perm *isp)
>  {
> - struct kern_ipc_perm *isp = shp;
>   struct smack_known *skp = smk_of_current();
>  
>   isp->security = skp;
> @@ -2971,34 +2970,32 @@ static int smack_shm_alloc_security(struct 
> kern_ipc_perm *shp)
>  }
>  
>  /**
> - * smack_shm_free_security - Clear the security blob for shm
> - * @shp: the object
> + * smack_ipc_free_security - Clear the security blob for ipc
> + * @isp: the object
>   *
>   * Clears the blob pointer
>   */
> -static void smack_shm_free_security(struct kern_ipc_perm *shp)
> +static void smack_ipc_free_security(struct kern_ipc_perm *isp)
>  {
> - struct kern_ipc_perm *isp = shp;
> -
>   isp->security = NULL;
>  }
>  
>  /**
>   * smk_curacc_shm : check if current has access on shm
> - * @shp : the object
> + * @isp : the object
>   * @access : access requested
>   *
>   * Returns 0 if current has the requested access, error code otherwise
>   */
> -static int smk_curacc_shm(struct kern_ipc_perm *shp, int access)
> +static int smk_curacc_shm(struct kern_ipc_perm *isp, int access)
>  {
> - struct smack_known *ssp = smack_of_shm(shp);
> + struct smack_known *ssp = smack_of_ipc(isp);
>   struct smk_audit_info ad;
>   int rc;
>  
>  #ifdef CONFIG_AUDIT
>   smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
> - ad.a.u.ipc_id = shp->id;
> + ad.a.u.ipc_id = isp->id;
>  #endif
>   rc = smk_curacc(ssp, access, &ad);
>   rc = smk_bu_current("shm", ssp, access, rc);
> @@ -3007,27 +3004,27 @@ static int smk_curacc_shm(struct kern_ipc_perm *shp, 
> int access)
>  
>  /**
>   * smack_shm_associate - Smack access check for shm
> - * @shp: the object
> + * @isp: the object
>   * @shmflg: access requested
>   *
>   * Returns 0 if current has the requested access, error code otherwise
>   */
> -static int smack_shm_associate(struct kern_ipc_perm *shp, int shmflg)
> +static int smack_shm_associate(struct kern_ipc_perm *isp, int shmflg)
>  {
>   int may;
>  
>   may = smack_flags_to_may(shmflg);
> - return smk_curacc_shm(shp, may);
> + return smk_curacc_shm(isp, may);
>  }
>  
>  /**
>   * smack_shm_shmctl - Smack access check for shm
> - * @shp: the object
> + * @isp: the object
>   * @cmd: what it wants to do
>   *
>   * Returns 0 if current has the requested access, error code otherwise
>   */
> -static int smack_shm_shmctl(struct kern_ipc_perm *shp, int cmd)
> +static int smack_shm_shmctl(struct kern_ipc_perm *isp, int cmd)
>  {
>   int may;
>  
> @@ -3051,81 +3048,42 @@ static int smack_shm_shmctl(struct kern_ipc_perm 
> *shp, int cmd)
>   default:
>   return -EINVAL;
>   }
> - return smk_curacc_shm(shp, may);
> + return smk_curacc_shm(isp, may);
>  }
>  
>  /**
>   * smack_shm_shmat - Smack access for shmat
> - * @shp: the object

[PATCH v2] gpio: ath79: Fix potential NULL dereference in ath79_gpio_probe()

2018-03-24 Thread Alban Bedel
From: Wei Yongjun 

platform_get_resource() may return NULL, add proper
check to avoid potential NULL dereferencing.

This is detected by Coccinelle semantic patch.

@@
expression pdev, res, n, t, e, e1, e2;
@@

res = platform_get_resource(pdev, t, n);
+ if (!res)
+   return -EINVAL;
... when != res == NULL
e = devm_ioremap(e1, res->start, e2);

Signed-off-by: Wei Yongjun 
[al...@free.fr: Fixed patch to apply on current tree]
Signed-off-by: Alban Bedel 
---
 drivers/gpio/gpio-ath79.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpio/gpio-ath79.c b/drivers/gpio/gpio-ath79.c
index 3ae7c18..684e9d6 100644
--- a/drivers/gpio/gpio-ath79.c
+++ b/drivers/gpio/gpio-ath79.c
@@ -258,6 +258,8 @@ static int ath79_gpio_probe(struct platform_device *pdev)
}
 
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+   if (!res)
+   return -EINVAL;
ctrl->base = devm_ioremap_nocache(
&pdev->dev, res->start, resource_size(res));
if (!ctrl->base)
-- 
2.7.4



[PATCH v3 3/3] mtd: Add support for reading MTD devices via the nvmem API

2018-03-24 Thread Alban Bedel
Allow drivers that use the nvmem API to read data stored on MTD devices.
For this the mtd devices are registered as read-only NVMEM providers.
On OF systems only devices that have the 'nvmem-provider' property
are registered, on non-OF system all MTD devices are registered.

Signed-off-by: Alban Bedel 
---
Changelog:
v2: * Moved to the MTD core instead of using notifiers
* Fixed the Kconfig description
v3: * Rebased on current kernel
* Moved the code to mtdcore.c and removed the conditional
  compilation as suggested by Boris Brezillon
* Fixed my name in From and Signed-off-by
* Only allow root to read from the nvmem sysfs interface
---
 drivers/mtd/Kconfig |  1 +
 drivers/mtd/mtdcore.c   | 59 +
 include/linux/mtd/mtd.h |  2 ++
 3 files changed, 62 insertions(+)

diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
index 2a8ac68..911d869 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -1,5 +1,6 @@
 menuconfig MTD
tristate "Memory Technology Device (MTD) support"
+   imply NVMEM
help
  Memory Technology Devices are flash, RAM and similar chips, often
  used for solid state file systems on embedded devices. This option
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 28553c8..d2a127c 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -478,6 +478,48 @@ int mtd_pairing_groups(struct mtd_info *mtd)
 }
 EXPORT_SYMBOL_GPL(mtd_pairing_groups);
 
+static int mtd_nvmem_reg_read(void *priv, unsigned int offset,
+ void *val, size_t bytes)
+{
+   struct mtd_info *mtd = priv;
+   size_t retlen;
+   int err;
+
+   err = mtd_read(mtd, offset, bytes, &retlen, val);
+   if (err && err != -EUCLEAN)
+   return err;
+
+   return retlen == bytes ? 0 : -EIO;
+}
+
+static int mtd_nvmem_add(struct mtd_info *mtd)
+{
+   struct nvmem_config config = {};
+
+   config.dev = &mtd->dev;
+   config.owner = THIS_MODULE;
+   config.reg_read = mtd_nvmem_reg_read;
+   config.size = mtd->size;
+   config.word_size = 1;
+   config.stride = 1;
+   config.read_only = true;
+   config.root_only = true;
+   config.priv = mtd;
+
+   mtd->nvmem = nvmem_register(&config);
+   if (IS_ERR(mtd->nvmem)) {
+   /* Just ignore if there is no NVMEM support in the kernel */
+   if (PTR_ERR(mtd->nvmem) == -ENOSYS) {
+   mtd->nvmem = NULL;
+   } else {
+   dev_err(&mtd->dev, "Failed to register NVMEM device\n");
+   return PTR_ERR(mtd->nvmem);
+   }
+   }
+
+   return 0;
+}
+
 static struct dentry *dfs_dir_mtd;
 
 /**
@@ -560,6 +602,11 @@ int add_mtd_device(struct mtd_info *mtd)
if (error)
goto fail_added;
 
+   /* Add the nvmem provider */
+   error = mtd_nvmem_add(mtd);
+   if (error)
+   goto fail_nvmem_add;
+
if (!IS_ERR_OR_NULL(dfs_dir_mtd)) {
mtd->dbg.dfs_dir = debugfs_create_dir(dev_name(&mtd->dev), 
dfs_dir_mtd);
if (IS_ERR_OR_NULL(mtd->dbg.dfs_dir)) {
@@ -585,6 +632,8 @@ int add_mtd_device(struct mtd_info *mtd)
__module_get(THIS_MODULE);
return 0;
 
+fail_nvmem_add:
+   device_unregister(&mtd->dev);
 fail_added:
of_node_put(mtd_get_of_node(mtd));
idr_remove(&mtd_idr, i);
@@ -627,6 +676,16 @@ int del_mtd_device(struct mtd_info *mtd)
   mtd->index, mtd->name, mtd->usecount);
ret = -EBUSY;
} else {
+   /* Try to remove the NVMEM provider */
+   if (mtd->nvmem) {
+   ret = nvmem_unregister(mtd->nvmem);
+   if (ret) {
+   dev_err(&mtd->dev,
+   "Failed to unregister NVMEM device\n");
+   goto out_error;
+   }
+   }
+
device_unregister(&mtd->dev);
 
idr_remove(&mtd_idr, mtd->index);
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 205eded..660b8e7 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -352,6 +353,7 @@ struct mtd_info {
struct device dev;
int usecount;
struct mtd_debug_info dbg;
+   struct nvmem_device *nvmem;
 };
 
 int mtd_ooblayout_ecc(struct mtd_info *mtd, int section,
-- 
2.7.4



[PATCH v3 2/3] doc: bindings: Add bindings documentation for mtd nvmem

2018-03-24 Thread Alban Bedel
Config data for drivers, like MAC addresses, is often stored in MTD.
Add a binding that define how such data storage can be represented in
device tree.

Signed-off-by: Alban Bedel 
---
Changelog:
v2: * Added a "Required properties" section with the nvmem-provider
  property
v3: * Fixed my name in From and Signed-off-by
* Moved to the new nvmem binding with the nvmem-cells subnode
---
 .../devicetree/bindings/nvmem/mtd-nvmem.txt| 27 ++
 1 file changed, 27 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt

diff --git a/Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt 
b/Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt
new file mode 100644
index 000..c819a69
--- /dev/null
+++ b/Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt
@@ -0,0 +1,27 @@
+= NVMEM in MTD =
+
+Config data for drivers, like MAC addresses, is often stored in MTD.
+An MTD device, or one of its partition, can be defined as a NVMEM provider
+by having an 'nvmem-cells' subnode as defined in nvmem.txt.
+
+Example:
+
+   flash@0 {
+   ...
+
+   partition@2 {
+   label = "art";
+   reg = <0x7F 0x01>;
+   read-only;
+
+   nvmem-cells {
+   compatible = "nvmem-cells";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   eeprom@1000 {
+   reg = <0x1000 0x1000>;
+   };
+   };
+   };
+   };
-- 
2.7.4



[PATCH v3 1/3] nvmem: Update the OF binding to use a subnode for the cells list

2018-03-24 Thread Alban Bedel
Having the cells as subnodes of the provider device without any
compatible property might clash with other bindings. To avoid this
problem update the binding to have all the cells in a 'nvmem-cells'
subnode with a 'nvmem-cells' compatible string. This new binding
guarantee that we can turn any kind of device in a nvmem provider.

While discouraged for new uses the old scheme is still supported for
backward compatibility.

Signed-off-by: Alban Bedel 
---
 Documentation/devicetree/bindings/nvmem/nvmem.txt | 55 ---
 drivers/nvmem/core.c  | 10 +
 2 files changed, 48 insertions(+), 17 deletions(-)

diff --git a/Documentation/devicetree/bindings/nvmem/nvmem.txt 
b/Documentation/devicetree/bindings/nvmem/nvmem.txt
index fd06c09..6b723e7 100644
--- a/Documentation/devicetree/bindings/nvmem/nvmem.txt
+++ b/Documentation/devicetree/bindings/nvmem/nvmem.txt
@@ -11,14 +11,29 @@ these data from, and where they are stored on the storage 
device.
 This document is here to document this.
 
 = Data providers =
-Contains bindings specific to provider drivers and data cells as children
-of this node.
+A data provider should have a subnode named 'nvmem-cells' that contains
+a subnodes for each data cells.
+
+For backward compatibility the nvmem data cells can be direct children
+of the data provider. This use is discouraged as it can conflict with
+other bindings.
 
 Optional properties:
  read-only: Mark the provider as read only.
 
+= Data cells list =
+The data cells list node should be named 'nvmem-cells' and have a
+child node for each data cell.
+
+Required properties:
+ compatible: Must be "nvmem-cells"
+ #address-cells: <1> if the provider use 32 bit addressing,
+ <2> for 64 bits addressing
+ #size-cells: <1> if the provider use 32 bit sizes,
+  <2> for 64 bits sizes
+
 = Data cells =
-These are the child nodes of the provider which contain data cell
+These are the child nodes of the nvmem-cells node which contain data cell
 information like offset and size in nvmem provider.
 
 Required properties:
@@ -37,24 +52,30 @@ For example:
...
 
/* Data cells */
-   tsens_calibration: calib@404 {
-   reg = <0x404 0x10>;
-   };
+   nvmem-cells {
+   compatible = "nvmem-cells";
+   #address-cells = <1>;
+   #size-cells = <1>;
 
-   tsens_calibration_bckp: calib_bckp@504 {
-   reg = <0x504 0x11>;
-   bits = <6 128>
-   };
+   tsens_calibration: calib@404 {
+   reg = <0x404 0x10>;
+   };
 
-   pvs_version: pvs-version@6 {
-   reg = <0x6 0x2>
-   bits = <7 2>
-   };
+   tsens_calibration_bckp: calib_bckp@504 {
+   reg = <0x504 0x11>;
+   bits = <6 128>
+   };
 
-   speed_bin: speed-bin@c{
-   reg = <0xc 0x1>;
-   bits = <2 3>;
+   pvs_version: pvs-version@6 {
+   reg = <0x6 0x2>
+   bits = <7 2>
+   };
 
+   speed_bin: speed-bin@c{
+   reg = <0xc 0x1>;
+   bits = <2 3>;
+
+   };
};
...
};
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 78051f0..a59195c 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -783,6 +783,16 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node 
*np,
if (!nvmem_np)
return ERR_PTR(-EINVAL);
 
+   /* Devices using the new binding have all the cells in
+* a subnode with compatible = "nvmem-cells". In this
+* case the device will be the parent of this node.
+*/
+   if (of_device_is_compatible(nvmem_np, "nvmem-cells")) {
+   nvmem_np = of_get_next_parent(nvmem_np);
+   if (!nvmem_np)
+   return ERR_PTR(-EINVAL);
+   }
+
nvmem = __nvmem_device_get(nvmem_np, NULL, NULL);
of_node_put(nvmem_np);
if (IS_ERR(nvmem))
-- 
2.7.4



[PATCH v3 0/3] mtd: Add support for reading MTD devices via the nvmem API

2018-03-24 Thread Alban Bedel
Hi all,

this series add support for reading MTD devices via the nvmem API, this
is mostly needed on embedded devices where things like MAC address and
calibration data is often stored in a partition on the main flash device.

Adding support for the nvmem API to the MTD core is trivial, however there
is a clash in the OF binding used by both subsystems. The current nvmem
binding expect nvmem cell to be subnode of the nvmem device, without any
compatible string. But MTD devices used a similar scheme for partition in
the past, so a subnode from an MTD device could be a partition using the
old binding or an nvmem cell.

To avoid this problem we update the nvmem cell binding to use a 'nvmem-cells'
subnode with compatible string to hold the list of nvmem cells. This new
binding make sure that any kind of device can be used as nvmem provider.

Alban Bedel (3):
  nvmem: Update the OF binding to use a subnode for the cells list
  doc: bindings: Add bindings documentation for mtd nvmem
  mtd: Add support for reading MTD devices via the nvmem API

 .../devicetree/bindings/nvmem/mtd-nvmem.txt| 27 ++
 Documentation/devicetree/bindings/nvmem/nvmem.txt  | 55 +---
 drivers/mtd/Kconfig|  1 +
 drivers/mtd/mtdcore.c  | 59 ++
 drivers/nvmem/core.c   | 10 
 include/linux/mtd/mtd.h|  2 +
 6 files changed, 137 insertions(+), 17 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/nvmem/mtd-nvmem.txt

-- 
2.7.4



Re: [PATCH v5 2/2] i2c: add support for Socionext SynQuacer I2C controller

2018-03-24 Thread Wolfram Sang
My code checkers mention this:

CPPCHECK
drivers/i2c/busses/i2c-synquacer.c:422: style: Checking if unsigned variable 
'timeout' is less than zero.


  CC  drivers/i2c/busses/i2c-synquacer.o
drivers/i2c/busses/i2c-synquacer.c: In function ‘synquacer_i2c_probe’:
drivers/i2c/busses/i2c-synquacer.c:678:15: warning: comparison of unsigned 
expression < 0 is always false [-Wtype-limits]
  if (i2c->irq < 0) {
   ^


signature.asc
Description: PGP signature


[RFC PATCH] iommu/vt-d: intel_iommu_page_response() can be static

2018-03-24 Thread kbuild test robot

Fixes: 49c5977b4ee7 ("iommu/vt-d: add intel iommu page response function")
Signed-off-by: Fengguang Wu 
---
 intel-iommu.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 8d73ff0..06be796 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -5195,7 +5195,7 @@ static int intel_iommu_sva_invalidate(struct iommu_domain 
*domain,
return ret;
 }
 
-int intel_iommu_page_response(struct device *dev, struct page_response_msg 
*msg)
+static int intel_iommu_page_response(struct device *dev, struct 
page_response_msg *msg)
 {
struct qi_desc resp;
struct intel_iommu *iommu;


Re: [PATCH v4 20/22] iommu/vt-d: add intel iommu page response function

2018-03-24 Thread kbuild test robot
Hi Jacob,

I love your patch! Perhaps something to improve:

[auto build test WARNING on iommu/next]
[also build test WARNING on v4.16-rc6 next-20180323]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Jacob-Pan/IOMMU-and-VT-d-driver-support-for-Shared-Virtual-Address-SVA/20180325-024555
base:   https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git next
reproduce:
# apt-get install sparse
make ARCH=x86_64 allmodconfig
make C=1 CF=-D__CHECK_ENDIAN__


sparse warnings: (new ones prefixed by >>)

   drivers/iommu/intel-iommu.c:500:5: sparse: symbol 'intel_iommu_gfx_mapped' 
was not declared. Should it be static?
   drivers/iommu/intel-iommu.c:3066:41: sparse: incorrect type in argument 1 
(different address spaces) @@expected void volatile [noderef] *addr 
@@got ile [noderef] *addr @@
   drivers/iommu/intel-iommu.c:3066:41:expected void volatile [noderef] 
*addr
   drivers/iommu/intel-iommu.c:3066:41:got struct context_entry *old_ce
>> drivers/iommu/intel-iommu.c:5198:5: sparse: symbol 
>> 'intel_iommu_page_response' was not declared. Should it be static?
>> drivers/iommu/intel-iommu.c:5224:48: sparse: right shift by bigger than 
>> source value

Please review and possibly fold the followup patch.

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


Re: [PATCH v5 2/2] i2c: add support for Socionext SynQuacer I2C controller

2018-03-24 Thread Wolfram Sang
Hi Ard,

> +static int synquacer_i2c_master_start(struct synquacer_i2c *i2c,
> +   struct i2c_msg *pmsg)
> +{
> + unsigned char bsr, bcr;
> +
> + if (pmsg->flags & I2C_M_RD)
> + writeb((pmsg->addr << 1) | 1,
> +i2c->base + SYNQUACER_I2C_REG_DAR);
> + else
> + writeb(pmsg->addr << 1,
> +i2c->base + SYNQUACER_I2C_REG_DAR);

writeb(i2c_8bit_addr_from_msg(pmsg), i2c->base + SYNQUACER_I2C_REG_DAR);

?

> +static int synquacer_i2c_master_recover(struct synquacer_i2c *i2c)
> +{

This is the bus recovery mechanism with toggling SCL pulses, right?
That should be implemented using a 'struct i2c_bus_recovery_info' and
the core helpers.

> +static int synquacer_i2c_doxfer(struct synquacer_i2c *i2c,
> + struct i2c_msg *msgs, int num)
> +{
> + unsigned char bsr;
> + unsigned long timeout, bb_timeout;
> + int ret;
> +
> + if (i2c->is_suspended)
> + return -EBUSY;
> +
> + synquacer_i2c_hw_init(i2c);
> + bsr = readb(i2c->base + SYNQUACER_I2C_REG_BSR);
> + if (bsr & SYNQUACER_I2C_BSR_BB) {
> + dev_err(i2c->dev, "cannot get bus (bus busy)\n");
> + return -EBUSY;
> + }
> +
> + init_completion(&i2c->completion);

reinit_completion? And init_completion() in probe()?

> + /* ensure the stop has been through the bus */
> + bb_timeout = jiffies + HZ;
> + do {
> + bsr = readb(i2c->base + SYNQUACER_I2C_REG_BSR);
> + if (!(bsr & SYNQUACER_I2C_BSR_BB))
> + return 0;
> + } while (time_before(jiffies, bb_timeout));

Busy looping for one second? And won't the bus_free detection at the
beginning of a transfer do?

> +static int synquacer_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
> +   int num)
> +{
> + struct synquacer_i2c *i2c;
> + int retry;
> + int ret;
> +
> + if (!msgs)
> + return -EINVAL;
> + if (num <= 0)
> + return -EINVAL;

Hmm, this should be done by the core. I am surprised it doesn't do that yet :/

> +
> + i2c = i2c_get_adapdata(adap);
> + i2c->timeout_ms = calc_timeout_ms(i2c, msgs, num);
> +
> + dev_dbg(i2c->dev, "calculated timeout %d ms\n", i2c->timeout_ms);
> +
> + for (retry = 0; retry < adap->retries; retry++) {
> +
> + ret = synquacer_i2c_doxfer(i2c, msgs, num);
> + if (ret != -EAGAIN)
> + return ret;
> +
> + dev_dbg(i2c->dev, "Retrying transmission (%d)\n", retry);
> +
> + synquacer_i2c_master_recover(i2c);

Recovery is only when SDA is stuck low, held by a client. That is
nothing you should do just on any error.

If you want the driver in v4.17, I'd suggest to drop
synquacer_i2c_master_recover() now and add it incrementally later, using
the existing recovery infrastructure. The rest is only minor stuff and
needs not much further discussion IMO.

Regards,

   Wolfram



signature.asc
Description: PGP signature


Re: [PATCH 1/3] ieee80211: Replace bit shifts with the BIT() macro for WLAN_CAPABILITY_*.

2018-03-24 Thread Quytelda Kahja
The "document" refers to the file in which the changes were made
('include/linux/ieee80211.h').

I tend to try to split my commits into the smallest logically related
changes possible, hence the three patch series.  This particular case
may be a little on the extreme side, but if the maintainer desires,
they can always squash them together or ask me to resubmit as one
patch.

On 3/24/18, Larry Finger  wrote:
> On 03/23/2018 11:10 PM, Quytelda Kahja wrote:
>> It is neater and more consistent with the rest of the document to use the
>> BIT() macro from 'linux/bitops.h' to define the WLAN_CAPABILITY_*
>> bitmasks.  In the case of WLAN_CAPABILITY_DMG_TYPE_{IBSS, PBSS, AP},
>> bitshifting integers by 0 does nothing, so there is no reason to do it in
>> the code; replace these values with plain integers.
>>
>> Signed-off-by: Quytelda Kahja 
>
> In the commit message for all of these, what is the "document" to which you
> refer?
>
> I'm not quite sure why you split these changes into 3 parts, but I guess
> that is OK.
>
> Larry
>
-- 
Thank you,
Quytelda Kahja


Re: [PATCH v2 0/6] Add different features for I2C

2018-03-24 Thread Wolfram Sang
On Wed, Mar 21, 2018 at 05:48:54PM +0100, Pierre-Yves MORDRET wrote:
> Append new I2C STM32F7 feature set. This includes 10 bit support, slave
> support, SMBBus protocols support, DMA Support and eventually an I2C recovery
> mechanism.

So, I gave a few comments. For hardware details (especially DMA), some
additional review from Maxime or Alexandre would be great.



signature.asc
Description: PGP signature


Re: [PATCH v2 6/6] i2c: i2c-stm32f7: Implement I2C recovery mechanism

2018-03-24 Thread Wolfram Sang
On Wed, Mar 21, 2018 at 05:49:00PM +0100, Pierre-Yves MORDRET wrote:
> Feature prevents I2C lock-ups. Mechanism resets I2C state machine
> and releases SCL/SDA signals but preserves I2C registers.
> 
> Signed-off-by: Pierre-Yves MORDRET 
> ---
>   Version history:
> v1:
>* Initial
> v2:
>* Don't use i2c engine recovery mechanism since driver
>  procedure only recover master and not the slave.

s/recovery/release/ throughout the patch, please. Recovery is really
something else. Also, I think the dev_info's are too noisy in the log
files. I'd think the whole driver could be lifted from quite some
logging...

> ---
> ---
>  drivers/i2c/busses/i2c-stm32f7.c | 27 ---
>  1 file changed, 24 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-stm32f7.c 
> b/drivers/i2c/busses/i2c-stm32f7.c
> index 91f73e0..9a9c469 100644
> --- a/drivers/i2c/busses/i2c-stm32f7.c
> +++ b/drivers/i2c/busses/i2c-stm32f7.c
> @@ -718,6 +718,20 @@ static void stm32f7_i2c_smbus_reload(struct 
> stm32f7_i2c_dev *i2c_dev)
>   writel_relaxed(cr2, i2c_dev->base + STM32F7_I2C_CR2);
>  }
>  
> +static int stm32f7_i2c_recover_bus(struct i2c_adapter *i2c_adap)
> +{
> + struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(i2c_adap);
> +
> + dev_info(i2c_dev->dev, "Trying to recover bus\n");
> +
> + stm32f7_i2c_clr_bits(i2c_dev->base + STM32F7_I2C_CR1,
> +  STM32F7_I2C_CR1_PE);
> +
> + stm32f7_i2c_hw_config(i2c_dev);
> +
> + return 0;
> +}
> +
>  static int stm32f7_i2c_wait_free_bus(struct stm32f7_i2c_dev *i2c_dev)
>  {
>   u32 status;
> @@ -727,12 +741,18 @@ static int stm32f7_i2c_wait_free_bus(struct 
> stm32f7_i2c_dev *i2c_dev)
>status,
>!(status & STM32F7_I2C_ISR_BUSY),
>10, 1000);
> + if (!ret)
> + return 0;
> +
> + dev_info(i2c_dev->dev, "bus busy\n");
> +
> + ret = stm32f7_i2c_recover_bus(&i2c_dev->adap);
>   if (ret) {
> - dev_dbg(i2c_dev->dev, "bus busy\n");
> - ret = -EBUSY;
> + dev_err(i2c_dev->dev, "Failed to recover the bus (%d)\n", ret);
> + return ret;
>   }
>  
> - return ret;
> + return -EBUSY;
>  }
>  
>  static void stm32f7_i2c_xfer_msg(struct stm32f7_i2c_dev *i2c_dev,
> @@ -1474,6 +1494,7 @@ static irqreturn_t stm32f7_i2c_isr_error(int irq, void 
> *data)
>   if (status & STM32F7_I2C_ISR_BERR) {
>   dev_err(dev, "<%s>: Bus error\n", __func__);
>   writel_relaxed(STM32F7_I2C_ICR_BERRCF, base + STM32F7_I2C_ICR);
> + stm32f7_i2c_recover_bus(&i2c_dev->adap);
>   f7_msg->result = -EIO;
>   }
>  
> -- 
> 2.7.4
> 


signature.asc
Description: PGP signature


Re: [PATCH v2 4/6] i2c: i2c-stm32: Add generic DMA API

2018-03-24 Thread Wolfram Sang
On Wed, Mar 21, 2018 at 05:48:58PM +0100, Pierre-Yves MORDRET wrote:
> This patch adds a generic DMA API to implement DMA support for i2c-stm32fx
> drivers
> 
> Signed-off-by: M'boumba Cedric Madianga 
> Signed-off-by: Pierre-Yves MORDRET 

In case you haven't read it so far, there is a new document about I2C &
DMA -> Documentation/i2c/DMA-considerations

Just so you know...



signature.asc
Description: PGP signature


Re: [PATCH v2 3/6] i2c: i2c-stm32f7: Add initial SMBus protocols support

2018-03-24 Thread Wolfram Sang
On Wed, Mar 21, 2018 at 05:48:57PM +0100, Pierre-Yves MORDRET wrote:
> This patch adds SMBus support for I2C controller embedded in STM32F7 Soc.

> All SMBus protocols are implemented except SMBus-specific protocols.

What does that mean?

> 
> Signed-off-by: M'boumba Cedric Madianga 
> Signed-off-by: Pierre-Yves MORDRET 
> ---
>   Version history:
> v1:
>* Initial
> v2:
>* fix Kbuild test robot issue (Unneeded semicolon)
> ---
> 
> fixup! i2c: i2c-stm32f7: Add initial SMBus protocols support
> ---
>  drivers/i2c/busses/i2c-stm32f7.c | 377 
> ++-
>  1 file changed, 368 insertions(+), 9 deletions(-)

That is quite some complexity considering we have I2C_FUNC_SMBUS_EMUL. I
don't mind, but you really want that?



signature.asc
Description: PGP signature


Charity

2018-03-24 Thread Alice Walton
I have a mission worth $ 100,000,000.00 for you


[PATCH] usb: host: Remove the deprecated ATH79 USB host config options

2018-03-24 Thread Alban Bedel
The options USB_EHCI_ATH79 and USB_OHCI_ATH79 only enable the
generic EHCI and OHCI platform drivers, and have been marked as
deprecated since 2012.

These can be safely removed if we make sure that USB_EHCI_ROOT_HUB_TT
still get enabled for the EHCI driver. This is now done be selecting
this option when the EHCI platform driver is enabled on the ATH79
platform.

Signed-off-by: Alban Bedel 
---
 arch/mips/Kconfig|  1 +
 drivers/usb/host/Kconfig | 25 -
 2 files changed, 1 insertion(+), 25 deletions(-)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 8128c3b..61e9a24 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -200,6 +200,7 @@ config ATH79
select SYS_SUPPORTS_MIPS16
select SYS_SUPPORTS_ZBOOT_UART_PROM
select USE_OF
+   select USB_EHCI_ROOT_HUB_TT if USB_EHCI_HCD_PLATFORM
help
  Support for the Atheros AR71XX/AR724X/AR913X SoCs.
 
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 4fcfb30..55b45dc 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -293,19 +293,6 @@ config USB_CNS3XXX_EHCI
  It is needed for high-speed (480Mbit/sec) USB 2.0 device
  support.
 
-config USB_EHCI_ATH79
-   bool "EHCI support for AR7XXX/AR9XXX SoCs (DEPRECATED)"
-   depends on (SOC_AR71XX || SOC_AR724X || SOC_AR913X || SOC_AR933X)
-   select USB_EHCI_ROOT_HUB_TT
-   select USB_EHCI_HCD_PLATFORM
-   default y
-   ---help---
- This option is deprecated now and the driver was removed, use
- USB_EHCI_HCD_PLATFORM instead.
-
- Enables support for the built-in EHCI controller present
- on the Atheros AR7XXX/AR9XXX SoCs.
-
 config USB_EHCI_HCD_PLATFORM
tristate "Generic EHCI driver for a platform device"
default n
@@ -489,18 +476,6 @@ config USB_OHCI_HCD_DAVINCI
  controller. This driver cannot currently be a loadable
  module because it lacks a proper PHY abstraction.
 
-config USB_OHCI_ATH79
-   bool "USB OHCI support for the Atheros AR71XX/AR7240 SoCs (DEPRECATED)"
-   depends on (SOC_AR71XX || SOC_AR724X)
-   select USB_OHCI_HCD_PLATFORM
-   default y
-   help
- This option is deprecated now and the driver was removed, use
- USB_OHCI_HCD_PLATFORM instead.
-
- Enables support for the built-in OHCI controller present on the
- Atheros AR71XX/AR7240 SoCs.
-
 config USB_OHCI_HCD_PPC_OF_BE
bool "OHCI support for OF platform bus (big endian)"
depends on PPC
-- 
2.7.4



Re: meter ABI: (was Re: [PATCH v2 1/3] staging:iio:meter: Replaces IIO_DEV_ATTR_CH_OFF by IIO_DEVICE_ATTR)

2018-03-24 Thread John Syne


> On Mar 24, 2018, at 8:02 AM, Jonathan Cameron  wrote:
> 
> On Mon, 19 Mar 2018 22:57:16 -0700
> John Syne  wrote:
> 
>> Hi Jonathan,
>> 
>> Thank you for all your hard work. Your feedback is really helpful. I’m 
>> surprised that no one from Analog Device has offered any suggestions.
>> 
> 
> Sadly those active in the mainline linux kernel from ADI are focused in
> other areas currently :(
Good point. I will reach out to Analog Devices and get a name of someone 
who is knowledgeable in this area. Perhaps Lars-Peters has a suggestion. 
>> Anyway, please see my comments inline below
>> 
>> Regards,
>> John
>> 
>> 
>> 
>> 
>> 
>>> On Mar 18, 2018, at 5:23 AM, Jonathan Cameron  wrote:
>>> 
>>> On Sat, 17 Mar 2018 23:11:45 -0700
>>> John Syne  wrote:
>>> 
 Hi Jonathan,  
>>> Hi John and All,
>>> 
>>> I'd love to get some additional input on this from anyone interested.
>>> There are a lot of weird and wonderful derived quantities in an energy
>>> meter and it seems we need to make some fundamental changes to support
>>> them - including potentially a userspace breaking change to the event
>>> code description.
>>> 
 
 Here is the complete list of registers for the ADE7878 which I copied from 
 the data sheet. I added a column “IIO Attribute” which I hope follows your 
 IIO ABI. Please make any changes you feel are incorrect. BTW, there are 
 several registers that cannot be generalized and are used purely for chip 
 configuration. I think we should add a new naming convention, namely 
 {register}_{}. Also, I see in the sys_bus_iio doc
> 
> 
> 
> 
 in_accel_x_peak_raw
 
 so shouldn’t the phase be represented as follows:
 
 in_current_A_scale  
>>> I'm still confused.  What does A represent here?  I assumed that was a wild
>>> card for the channel number before but clearly not.
>>> 
>>> Ah, you are labelling the 3 separate phases as A, B and C. Hmm.
>>> I guess they sort of look like axis, and sort of like independent channels.
>>> So could be indexed or done via modifiers depending on how you look at it.  
>> In metering terminology, the three phases are commonly referred to as RED, 
>> GREEN, BLUE or PhaseA, PhaseB, PhaseC and Neutral. Analog Devices uses the 
>> ABCN nomenclature so anyone using this driver will probably have referenced 
>> the Analog Devices datasheet so this terminology should be familiar. 
> Which is more commonly used in general?  We are designing what we hope
> will be a general interface and last thing we want is to have everyone
> not using ADI parts confused!  Personally not assigning 'colours' makes
> more sense to me.
I did a little research and here is the naming used by vendor:

ST Microelectronics: P1, P2, P3, N
http://www.st.com/content/ccc/resource/technical/document/application_note/5e/f4/22/4d/90/96/4c/c4/CD00153264.pdf/files/CD00153264.pdf/jcr:content/translations/en.CD00153264.pdf

Teridian: ABCN
https://www.mouser.com/ds/2/256/71M6513-71M6513H-22603.pdf

Maxim Integrated: ABCN
https://datasheets.maximintegrated.com/en/ds/78M6631.pdf

Microchip: ABCN
http://ww1.microchip.com/downloads/en/DeviceDoc/51643b.pdf

NXP: L1, L2, L3, N
https://www.nxp.com/support/developer-resources/reference-designs/kinetis-km3x-256-mcu-three-phase-metering-reference-design:RD-KM3x-256-3PH-METERING

Renesas: ABCN
https://www.renesas.com/en-us/solutions/home/metering/power-meter-three.html

So the most consistent would be ABCN


All vendor providing three phase energy metering ICs use the ABCN terminology. 
> 
> (btw please wrap any lines that don't need to be long to around 80 
> characters).
> 
>>> 
>>> Hmm. With neutral in there as well I guess we need to make them
>>> modifiers (but might change my mind later ;)
>>> 
>>> Particularly as we are using the the modifier for RMS under the previous
>>> plan... It appears we should treat that instead like we did for peak
>>> and do it as an additional info mask element.  The problem with doing that
>>> on a continuous measurement is that we can't treat it as a channel to
>>> be output through the buffered interface.  
>> I’ve changed the layout of the spreadsheet to breakout the Direction, Type, 
>> Index, Modifier and Info Mask to make sure there is no miss-understanding 
>> and will help identify all the items we need to add.
>> 
>> The ADE7878 channels that will use the buffer are IAWV, VAWV, IBWV, VBWV, 
>> ICWV, VCWV, INWV, AVA, BVA, CVA, AWATT, BWATT, CWATT, AVAR, BVAR, and CVAR. 
>> So I guess we have to add an index
> Probably a good idea anyway, we are sort of slowly moving away
> from index less channels.  The ABI always allowed index assignment
> and it makes for easier userspace code.
> 
>> 
>> Address Register IIO Attribute   
>> Dir TypeIndex   ModifierInfo Mask   R/W  
>>Bit Bit Length  TypeDefault Description 
>>

Re: [PATCH v2 1/6] i2c: i2c-stm32f7: Add 10-bit address support

2018-03-24 Thread Wolfram Sang
On Wed, Mar 21, 2018 at 05:48:55PM +0100, Pierre-Yves MORDRET wrote:
> This patch adds support for 10-bit device address for STM32F7 I2C
> 
> Signed-off-by: M'boumba Cedric Madianga 
> Signed-off-by: Pierre-Yves MORDRET 

Out of curiosity: how did you test this patch? I never managed to find a
10-bit client (except for an SoC with 10-bit slave mode).

> ---
>   Version history:
>  v1:
> * Initial
>  v2:
> ---
> ---
>  drivers/i2c/busses/i2c-stm32f7.c | 22 +-
>  1 file changed, 17 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-stm32f7.c 
> b/drivers/i2c/busses/i2c-stm32f7.c
> index f273e28..ae0d15c 100644
> --- a/drivers/i2c/busses/i2c-stm32f7.c
> +++ b/drivers/i2c/busses/i2c-stm32f7.c
> @@ -65,7 +65,12 @@
>  #define STM32F7_I2C_CR2_NACK BIT(15)
>  #define STM32F7_I2C_CR2_STOP BIT(14)
>  #define STM32F7_I2C_CR2_STARTBIT(13)
> +#define STM32F7_I2C_CR2_HEAD10R  BIT(12)
> +#define STM32F7_I2C_CR2_ADD10BIT(11)
>  #define STM32F7_I2C_CR2_RD_WRN   BIT(10)
> +#define STM32F7_I2C_CR2_SADD10_MASK  GENMASK(9, 0)
> +#define STM32F7_I2C_CR2_SADD10(n)(((n) & \
> + STM32F7_I2C_CR2_SADD10_MASK))
>  #define STM32F7_I2C_CR2_SADD7_MASK   GENMASK(7, 1)
>  #define STM32F7_I2C_CR2_SADD7(n) (((n) & 0x7f) << 1)
>  
> @@ -176,14 +181,14 @@ struct stm32f7_i2c_timings {
>  
>  /**
>   * struct stm32f7_i2c_msg - client specific data
> - * @addr: 8-bit slave addr, including r/w bit
> + * @addr: 8-bit or 10-bit slave addr, including r/w bit
>   * @count: number of bytes to be transferred
>   * @buf: data buffer
>   * @result: result of the transfer
>   * @stop: last I2C msg to be sent, i.e. STOP to be generated
>   */
>  struct stm32f7_i2c_msg {
> - u8 addr;
> + u16 addr;
>   u32 count;
>   u8 *buf;
>   int result;
> @@ -629,8 +634,15 @@ static void stm32f7_i2c_xfer_msg(struct stm32f7_i2c_dev 
> *i2c_dev,
>   cr2 |= STM32F7_I2C_CR2_RD_WRN;
>  
>   /* Set slave address */
> - cr2 &= ~STM32F7_I2C_CR2_SADD7_MASK;
> - cr2 |= STM32F7_I2C_CR2_SADD7(f7_msg->addr);
> + cr2 &= ~(STM32F7_I2C_CR2_HEAD10R | STM32F7_I2C_CR2_ADD10);
> + if (msg->flags & I2C_M_TEN) {
> + cr2 &= ~STM32F7_I2C_CR2_SADD10_MASK;
> + cr2 |= STM32F7_I2C_CR2_SADD10(f7_msg->addr);
> + cr2 |= STM32F7_I2C_CR2_ADD10;
> + } else {
> + cr2 &= ~STM32F7_I2C_CR2_SADD7_MASK;
> + cr2 |= STM32F7_I2C_CR2_SADD7(f7_msg->addr);
> + }
>  
>   /* Set nb bytes to transfer and reload if needed */
>   cr2 &= ~(STM32F7_I2C_CR2_NBYTES_MASK | STM32F7_I2C_CR2_RELOAD);
> @@ -798,7 +810,7 @@ static int stm32f7_i2c_xfer(struct i2c_adapter *i2c_adap,
>  
>  static u32 stm32f7_i2c_func(struct i2c_adapter *adap)
>  {
> - return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
> + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR;
>  }
>  
>  static struct i2c_algorithm stm32f7_i2c_algo = {
> -- 
> 2.7.4
> 


signature.asc
Description: PGP signature


[PATCH] phy: Add a driver for the ATH79 USB phy

2018-03-24 Thread Alban Bedel
The ATH79 USB phy is very simple, it only have a reset. On some SoC a
second reset is used to force the phy in suspend mode regardless of the
USB controller status.

This driver is added to the qualcom directory as atheros is now part
of qualcom and newer SoC of this familly are marketed under the
qualcom name.

Signed-off-by: Alban Bedel 
---
 MAINTAINERS  |   8 +++
 drivers/phy/qualcomm/Kconfig |  11 +++-
 drivers/phy/qualcomm/Makefile|   1 +
 drivers/phy/qualcomm/phy-ath79-usb.c | 108 +++
 4 files changed, 127 insertions(+), 1 deletion(-)
 create mode 100644 drivers/phy/qualcomm/phy-ath79-usb.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 73c0cda..ce5ecd6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2294,6 +2294,14 @@ S:   Maintained
 F: drivers/gpio/gpio-ath79.c
 F: Documentation/devicetree/bindings/gpio/gpio-ath79.txt
 
+ATHEROS 71XX/9XXX USB PHY DRIVER
+M: Alban Bedel 
+W: https://github.com/AlbanBedel/linux
+T: git git://github.com/AlbanBedel/linux
+S: Maintained
+F: drivers/phy/qualcomm/phy-ath79-usb.c
+F: Documentation/devicetree/bindings/phy/phy-ath79-usb.txt
+
 ATHEROS ATH GENERIC UTILITIES
 M: "Luis R. Rodriguez" 
 L: linux-wirel...@vger.kernel.org
diff --git a/drivers/phy/qualcomm/Kconfig b/drivers/phy/qualcomm/Kconfig
index 7bfa64b..632a0e7 100644
--- a/drivers/phy/qualcomm/Kconfig
+++ b/drivers/phy/qualcomm/Kconfig
@@ -1,6 +1,15 @@
 #
-# Phy drivers for Qualcomm platforms
+# Phy drivers for Qualcomm and Atheros platforms
 #
+config PHY_ATH79_USB
+   tristate "Atheros AR71XX/9XXX USB PHY driver"
+   depends on OF && (ATH79 || COMPILE_TEST)
+   default y if USB_EHCI_HCD_PLATFORM || USB_OHCI_HCD_PLATFORM
+   select RESET_CONTROLLER
+   select GENERIC_PHY
+   help
+ Enable this to support the USB PHY on Atheros AR71XX/9XXX SoCs.
+
 config PHY_QCOM_APQ8064_SATA
tristate "Qualcomm APQ8064 SATA SerDes/PHY driver"
depends on ARCH_QCOM
diff --git a/drivers/phy/qualcomm/Makefile b/drivers/phy/qualcomm/Makefile
index 9abb789..deb831f4 100644
--- a/drivers/phy/qualcomm/Makefile
+++ b/drivers/phy/qualcomm/Makefile
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_PHY_ATH79_USB)+= phy-ath79-usb.o
 obj-$(CONFIG_PHY_QCOM_APQ8064_SATA)+= phy-qcom-apq8064-sata.o
 obj-$(CONFIG_PHY_QCOM_IPQ806X_SATA)+= phy-qcom-ipq806x-sata.o
 obj-$(CONFIG_PHY_QCOM_QMP) += phy-qcom-qmp.o
diff --git a/drivers/phy/qualcomm/phy-ath79-usb.c 
b/drivers/phy/qualcomm/phy-ath79-usb.c
new file mode 100644
index 000..6fd6e07
--- /dev/null
+++ b/drivers/phy/qualcomm/phy-ath79-usb.c
@@ -0,0 +1,108 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Atheros AR71XX/9XXX USB PHY driver
+ *
+ * Copyright (C) 2015-2018 Alban Bedel 
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+struct ath79_usb_phy {
+   struct reset_control *reset;
+   /* The suspend override logic is inverted, hence the no prefix
+* to make the code a bit easier to understand.
+*/
+   struct reset_control *no_suspend_override;
+};
+
+static int ath79_usb_phy_power_on(struct phy *phy)
+{
+   struct ath79_usb_phy *priv = phy_get_drvdata(phy);
+   int err = 0;
+
+   if (priv->no_suspend_override) {
+   err = reset_control_assert(priv->no_suspend_override);
+   if (err)
+   return err;
+   }
+
+   err = reset_control_deassert(priv->reset);
+   if (err && priv->no_suspend_override)
+   reset_control_assert(priv->no_suspend_override);
+
+   return err;
+}
+
+static int ath79_usb_phy_power_off(struct phy *phy)
+{
+   struct ath79_usb_phy *priv = phy_get_drvdata(phy);
+   int err = 0;
+
+   err = reset_control_assert(priv->reset);
+   if (err)
+   return err;
+
+   if (priv->no_suspend_override) {
+   err = reset_control_deassert(priv->no_suspend_override);
+   if (err)
+   reset_control_deassert(priv->reset);
+   }
+
+   return err;
+}
+
+static const struct phy_ops ath79_usb_phy_ops = {
+   .power_on   = ath79_usb_phy_power_on,
+   .power_off  = ath79_usb_phy_power_off,
+   .owner  = THIS_MODULE,
+};
+
+static int ath79_usb_phy_probe(struct platform_device *pdev)
+{
+   struct ath79_usb_phy *priv;
+   struct phy *phy;
+
+   priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
+   if (!priv)
+   return -ENOMEM;
+
+   priv->reset = devm_reset_control_get(&pdev->dev, "usb-phy");
+   if (IS_ERR(priv->reset))
+   return PTR_ERR(priv->reset);
+
+   priv->no_suspend_override = devm_reset_control_get_optional(
+   &pdev->dev, "usb-suspend-override");
+   if (IS_ERR(priv->no_suspend_override))
+   return PTR_ERR(priv->no_suspend_override);
+
+   phy = devm_phy_cr

Re: [PATCH v3 01/11] i2c: Export of_i2c_get_board_info()

2018-03-24 Thread Wolfram Sang

> > -   info.archdata = &dev_ad;
> 
> Why did you drop this?

If the removal is safe, it should be a seperate patch, I mean.



signature.asc
Description: PGP signature


Re: efisubsys_init takes more than a few milliseconds

2018-03-24 Thread Ard Biesheuvel
Hello Paul,

On 24 March 2018 at 22:10, Paul Menzel  wrote:
> Dear Ard,
>
>
> According to `initcall_debug`, `efisubsys_init` takes more than a few
> milliseconds to execute on a Dell XPS 13 9370 (Intel(R) Core(TM) i7-8550U
> CPU @ 1.80GHz).
>
>> ```
>> […]
>> [ 0.144474] calling  efisubsys_init+0x0/0x2cf @ 1
>> [ 0.144474] Registered efivars operations
>> [ 0.173690] initcall efisubsys_init+0x0/0x2cf returned 0 after 27343 usecs
>> […]
>> ```
>
>
> To get a vanilla Linux kernel to boot in well under one second, it’d be nice
> if the time could be improved. Do you know, why it takes so long?
>
> According to `bootgraph.py` from pm-graph [1][2] it takes even a little
> longer.
>
>> efisubsys_init: start=690.841, end=720.493, length(w/o overhead)=31.250
>> ms, return=0
>
>
> There are several dozen calls to `virt_efi_get_next_variable()` all but one
> taking around 0.335 ms. This path needs to be optimized. Is that possible?
>

That depends. These are firmware calls, so to make these calls faster,
you need to modify the firmware, not the kernel.

We may be able to make more intrusive changes to get rid of this
delay, e.g., spin up a special kernel thread, but I'd have to check in
more detail. In the mean time, you can try passing 'efi=noruntime' to
the kernel.


> To reproduce this, clone the pm-graph repository [2], use `sudo
> ./bootgraph.py -f -fstat -maxdepth 10 -manual` to see what to add to
> `/boot/grub/grub.cfg`. Then reboot, and execute `sudo ./bootgraph.py -f
> -fstat -maxdepth 10`.
>
> If your system is powerful enough, you can use a higher maximum depth. I
> didn’t get around how `-cgfilter` works to get smaller HTML files.
>
>
> Kind regards,
>
> Paul
>
>
> [1] https://01.org/suspendresume
> [2] https://github.com/01org/pm-graph


Re: [PATCH v3 01/11] i2c: Export of_i2c_get_board_info()

2018-03-24 Thread Wolfram Sang
Hi Boris,

> - rebase on v4.15-rc1

This code has changed a little meanwhile. Please check my for-next
branch. Some changes are identical, some similar.

> - info.archdata = &dev_ad;

Why did you drop this?

Regards,

   Wolfram



signature.asc
Description: PGP signature


Re: [PATCH net-next v2 2/2] cxgb4: collect hardware dump in second kernel

2018-03-24 Thread Thadeu Lima de Souza Cascardo
On Sat, Mar 24, 2018 at 04:26:34PM +0530, Rahul Lakkireddy wrote:
> Register callback to collect hardware/firmware dumps in second kernel
> before hardware/firmware is initialized.  The dumps for each device
> will be available under /sys/kernel/crashdd/cxgb4/ directory in second
> kernel.
> 
> Signed-off-by: Rahul Lakkireddy 
> Signed-off-by: Ganesh Goudar 
> ---
> v2:
> - No Changes.
> 
> Changes since rfc v2:
> - Update comments and commit message for sysfs change.
> 
> rfc v2:
> - Updated dump registration to the new API in patch 1.
[...]
> diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c 
> b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
> index e880be8e3c45..265cb026f868 100644
> --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
> +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
> @@ -5527,6 +5527,18 @@ static int init_one(struct pci_dev *pdev, const struct 
> pci_device_id *ent)
>   if (err)
>   goto out_free_adapter;
>  
> + if (is_kdump_kernel()) {
> + /* Collect hardware state and append to
> +  * /sys/kernel/crashdd/cxgb4/ directory
> +  */
> + err = cxgb4_cudbg_crashdd_add_dump(adapter);
> + if (err) {
> + dev_warn(adapter->pdev_dev,
> +  "Fail collecting crash device dump, err: %d. 
> Continuing\n",
> +  err);
> + err = 0;
> + }
> + }
>  

The problem I see with this approach is that you require that the driver
is built into the kdump kernel (or present as a module in the kdump
initramfs), and that you will probe the device during the collection of
the dumps.

IMHO, if you are going to require the device to be probed by the same
driver during kdump, you might just as well use the device object itself
to present the crash data. I think that's what Stephen Hemminger meant
when he said to use sysfs. No need at all for any special crashdd. Just
add an attribute or attribute group to the device object.

Otherwise, as Eric Biederman pointed out, you should just add that data
into the vmcore before you kexec, so you don't even need to look at a
different file, and the driver does not even need to be present in the
kdump kernel.

Cascardo.

>   if (!is_t4(adapter->params.chip)) {
>   s_qpp = (QUEUESPERPAGEPF0_S +
> -- 
> 2.14.1


efisubsys_init takes more than a few milliseconds

2018-03-24 Thread Paul Menzel

Dear Ard,


According to `initcall_debug`, `efisubsys_init` takes more than a few 
milliseconds to execute on a Dell XPS 13 9370 (Intel(R) Core(TM) 
i7-8550U CPU @ 1.80GHz).



```
[…]
[0.144474] calling  efisubsys_init+0x0/0x2cf @ 1
[0.144474] Registered efivars operations
[0.173690] initcall efisubsys_init+0x0/0x2cf returned 0 after 27343 usecs
[…]
```


To get a vanilla Linux kernel to boot in well under one second, it’d be 
nice if the time could be improved. Do you know, why it takes so long?


According to `bootgraph.py` from pm-graph [1][2] it takes even a little 
longer.



efisubsys_init: start=690.841, end=720.493, length(w/o overhead)=31.250 ms, 
return=0


There are several dozen calls to `virt_efi_get_next_variable()` all but 
one taking around 0.335 ms. This path needs to be optimized. Is that 
possible?


To reproduce this, clone the pm-graph repository [2], use `sudo 
./bootgraph.py -f -fstat -maxdepth 10 -manual` to see what to add to 
`/boot/grub/grub.cfg`. Then reboot, and execute `sudo ./bootgraph.py -f 
-fstat -maxdepth 10`.


If your system is powerful enough, you can use a higher maximum depth. I 
didn’t get around how `-cgfilter` works to get smaller HTML files.



Kind regards,

Paul


[1] https://01.org/suspendresume
[2] https://github.com/01org/pm-graph


[PATCH] staging: pi433: cleanup tx_fifo locking

2018-03-24 Thread Valentin Vidic
pi433_write requires locking due to multiple kfifo writers.  After
acquiring the lock check if enough free space is available in the kfifo
to write the whole message. This check should prevent partial writes to
kfifo so kfifo_reset is not needed anymore.

pi433_tx_thread is the only kfifo reader so it does not require locking
after kfifo_reset is also removed.

Signed-off-by: Valentin Vidic 
---
 drivers/staging/pi433/pi433_if.c | 20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/pi433/pi433_if.c b/drivers/staging/pi433/pi433_if.c
index d1e0ddbc79ce..97239b0eb322 100644
--- a/drivers/staging/pi433/pi433_if.c
+++ b/drivers/staging/pi433/pi433_if.c
@@ -87,7 +87,7 @@ struct pi433_device {
 
/* tx related values */
STRUCT_KFIFO_REC_1(MSG_FIFO_SIZE) tx_fifo;
-   struct mutextx_fifo_lock; // TODO: check, whether necessary 
or obsolete
+   struct mutextx_fifo_lock; /* serialize multiple writers */
struct task_struct  *tx_task_struct;
wait_queue_head_t   tx_wait_queue;
u8  free_in_fifo;
@@ -589,19 +589,15 @@ pi433_tx_thread(void *data)
 * - size of message
 * - message
 */
-   mutex_lock(&device->tx_fifo_lock);
-
retval = kfifo_out(&device->tx_fifo, &tx_cfg, sizeof(tx_cfg));
if (retval != sizeof(tx_cfg)) {
dev_dbg(device->dev, "reading tx_cfg from fifo failed: 
got %d byte(s), expected %d", retval, (unsigned int)sizeof(tx_cfg));
-   mutex_unlock(&device->tx_fifo_lock);
continue;
}
 
retval = kfifo_out(&device->tx_fifo, &size, sizeof(size_t));
if (retval != sizeof(size_t)) {
dev_dbg(device->dev, "reading msg size from fifo 
failed: got %d, expected %d", retval, (unsigned int)sizeof(size_t));
-   mutex_unlock(&device->tx_fifo_lock);
continue;
}
 
@@ -634,7 +630,6 @@ pi433_tx_thread(void *data)
   sizeof(device->buffer) - position);
dev_dbg(device->dev,
"read %d message byte(s) from fifo queue.", retval);
-   mutex_unlock(&device->tx_fifo_lock);
 
/* if rx is active, we need to interrupt the waiting for
 * incoming telegrams, to be able to send something.
@@ -818,7 +813,7 @@ pi433_write(struct file *filp, const char __user *buf,
struct pi433_instance   *instance;
struct pi433_device *device;
int retval;
-   unsigned intcopied;
+   unsigned intrequired, available, copied;
 
instance = filp->private_data;
device = instance->device;
@@ -833,6 +828,16 @@ pi433_write(struct file *filp, const char __user *buf,
 * - message
 */
mutex_lock(&device->tx_fifo_lock);
+
+   required = sizeof(instance->tx_cfg) + sizeof(size_t) + count;
+   available = kfifo_avail(&device->tx_fifo);
+   if (required > available) {
+   dev_dbg(device->dev, "write to fifo failed: %d bytes required 
but %d available",
+   required, available);
+   mutex_unlock(&device->tx_fifo_lock);
+   return -EAGAIN;
+   }
+
retval = kfifo_in(&device->tx_fifo, &instance->tx_cfg,
  sizeof(instance->tx_cfg));
if (retval != sizeof(instance->tx_cfg))
@@ -856,7 +861,6 @@ pi433_write(struct file *filp, const char __user *buf,
 
 abort:
dev_dbg(device->dev, "write to fifo failed: 0x%x", retval);
-   kfifo_reset(&device->tx_fifo); // TODO: maybe find a solution, not to 
discard already stored, valid entries
mutex_unlock(&device->tx_fifo_lock);
return -EAGAIN;
 }
-- 
2.16.2



Re: [PATCH] ftrace: fix stddev calculation in function profiler (again)

2018-03-24 Thread Matthias Schiffer
On 03/24/2018 05:26 PM, Matthias Schiffer wrote:
> It is well-known that it is not possible to accurately calculate variances
> just by accumulating squared samples; in fact, such an approach can even
> result in negative numbers. An earlier attempt to fix the calculation
> referred to Welford's method, but did not implement it correctly, leading
> to meeaningless output like the following:
> 
>   nf_conntrack_proto_fini 50373.523 us7.470 us3234315951 us
> 
> Welford's method uses one do_div() in the tracing path; this cannot be
> avoided. The average time is added to struct ftrace_profile, so only a
> single division is required. I also considered the following alternatives:
> 
> 1) Only keeping the avg field and removing the aggregated time would
> greatly lead to severe rounding errors in calculating the total time based
> on counter and avg.
> 
> 2) Calculating both the old and the new average in profile_graph_return()
> instead of storing it in struct ftrace_profile would require a second
> division.
> 
> 3) I managed to transform Welford's equations in a way that uses the total
> time instead of the average and requires only a single division.
> Unfortunately, the divisor is counter^3 in this case, easily overflowing
> even 64bit integers.
> 
> Ruling out the above alternatives, I chose the present approach to fix the
> issue.
> 
> Fixes: e330b3bcd831 ("tracing: Show sample std dev in function profiling")
> Fixes: 52d85d763086 ("ftrace: Fix stddev calculation in function profiler")
> Signed-off-by: Matthias Schiffer 


Hmm, in further testing, I'm seeing profile_graph_return() being called
without rec->counter getting incremented a lot, completely throwing off the
stddev calculation (and also slightly displacing the average). Is this
expected?

Should we possibly move the counter increment to profile_graph_return() in
the CONFIG_FUNCTION_GRAPH_TRACER case, or introduce a second counter for
returns?

Matthias



> ---
>  kernel/trace/ftrace.c | 33 +++--
>  1 file changed, 19 insertions(+), 14 deletions(-)
> 
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index eac9ce2c57a2..16dce67b855a 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -460,7 +460,8 @@ struct ftrace_profile {
>   unsigned long   counter;
>  #ifdef CONFIG_FUNCTION_GRAPH_TRACER
>   unsigned long long  time;
> - unsigned long long  time_squared;
> + unsigned long long  avg;
> + unsigned long long  stddev;
>  #endif
>  };
>  
> @@ -580,7 +581,6 @@ static int function_stat_show(struct seq_file *m, void *v)
>   int ret = 0;
>  #ifdef CONFIG_FUNCTION_GRAPH_TRACER
>   static struct trace_seq s;
> - unsigned long long avg;
>   unsigned long long stddev;
>  #endif
>   mutex_lock(&ftrace_profile_lock);
> @@ -592,9 +592,7 @@ static int function_stat_show(struct seq_file *m, void *v)
>   }
>  
>  #ifdef CONFIG_FUNCTION_GRAPH_TRACER
> - avg = rec->time;
> - do_div(avg, rec->counter);
> - if (tracing_thresh && (avg < tracing_thresh))
> + if (tracing_thresh && (rec->avg < tracing_thresh))
>   goto out;
>  #endif
>  
> @@ -608,24 +606,19 @@ static int function_stat_show(struct seq_file *m, void 
> *v)
>   if (rec->counter <= 1)
>   stddev = 0;
>   else {
> - /*
> -  * Apply Welford's method:
> -  * s^2 = 1 / (n * (n-1)) * (n * \Sum (x_i)^2 - (\Sum x_i)^2)
> -  */
> - stddev = rec->counter * rec->time_squared -
> -  rec->time * rec->time;
> + stddev = rec->stddev;
>  
>   /*
>* Divide only 1000 for ns^2 -> us^2 conversion.
>* trace_print_graph_duration will divide 1000 again.
>*/
> - do_div(stddev, rec->counter * (rec->counter - 1) * 1000);
> + do_div(stddev, 1000 * (rec->counter - 1));
>   }
>  
>   trace_seq_init(&s);
>   trace_print_graph_duration(rec->time, &s);
>   trace_seq_puts(&s, "");
> - trace_print_graph_duration(avg, &s);
> + trace_print_graph_duration(rec->avg, &s);
>   trace_seq_puts(&s, "");
>   trace_print_graph_duration(stddev, &s);
>   trace_print_seq(m, &s);
> @@ -905,8 +898,20 @@ static void profile_graph_return(struct ftrace_graph_ret 
> *trace)
>  
>   rec = ftrace_find_profiled_func(stat, trace->func);
>   if (rec) {
> + unsigned long long avg, delta1, delta2;
> +
>   rec->time += calltime;
> - rec->time_squared += calltime * calltime;
> +
> + /* Apply Welford's method */
> + delta1 = calltime - rec->avg;
> +
> + avg = rec->time;
> + do_div(avg, rec->counter);
> + rec->avg = avg;
> +
> + delta2 = calltime - rec->avg;
> +
> + rec->stddev += delta1 * delta2

Re: [PATCH 1/2] fs: Extend mount_ns with support for a fast namespace to vfsmount function

2018-03-24 Thread Al Viro
On Sat, Mar 24, 2018 at 11:12:02AM -0500, Eric W. Biederman wrote:

> > This is completely wrong.  Look:
> > * SB_KERNMOUNT and !SB_KERNMOUNT cases are almost entirely isolated;
> > completely so once that ns_to_mnt becomes unconditionally non-NULL.  
> > * in !SB_KERNMOUNT passing ns_to_mnt() is pointless - you might as
> > well pass existing vfsmount (or ERR_PTR()) and use _that_.  fill_super()
> > is not used at all in that case.
> > * is SB_KERNMOUNT ns_to_mnt serves only as a flag, eventually
> > constant true.
> >
> > So let's split it in two helpers and give them sane arguments.
> 
> Everything I look at with multiple helpers feels even worse to me.
> The above has the advantage it is the minimal change to fix the
> regression.  So I am not worried about code correctness.

> I keep wondering is the intention long term to fix sget so it has an
> efficient data structure for finding super blocks (like an rbtree) or if
> the intention is to deprecate sget entirely and just have everything
> call alloc_super, and be responsible for their own data structures for
> finding existing superblocks.
>
> At this point since we are not in agreement on a proper fix I am going
> to plan on just queueing up a revert.   So that we don't ship 4.16 with
> a regression in a permission check.

Permission check is trivial to put back in; I'll do that.

FWIW, I don't believe that sget_userns() is a good place for any kind of
universal permission checks.  It's a library helper, not a place everything
must come through when mounting something.  So's mount_ns(), etc.

BTW, will you be at LSF?  I would suggest discussing the architectural
issues there - they are directly related to fsmount() proposals...


**Herzlichen Glückwunsch**

2018-03-24 Thread Euro Millions
Herzlichen Glückwunsch, Sie haben 650.000 Euro in den monatlichen Gewinnspielen 
von Euro Millions/Google Promo am 10. März 2018 gewonnen.

Kontaktieren Sie unseren Schadenregulierungsbeauftragten mit den folgenden 
Informationen

Vollständiger Name
Heimatadresse
Geschlecht
Alter
Telefon

Mr.Pianese Germano



[PATCH] x86/purgatory: Remove -MD from KBUILD_CFLAGS

2018-03-24 Thread Sven Wegener
The kernel build system already takes care of generating the dependency
files. Having the additional -MD in KBUILD_CFLAGS leads to stray
..d files in the build directory when we call the cc-option macro.

Signed-off-by: Sven Wegener 
---
 arch/x86/purgatory/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile
index 2f15a2ac4209..d70c15de417b 100644
--- a/arch/x86/purgatory/Makefile
+++ b/arch/x86/purgatory/Makefile
@@ -16,7 +16,7 @@ KCOV_INSTRUMENT := n
 # in turn leaves some undefined symbols like __fentry__ in purgatory and not
 # sure how to relocate those. Like kexec-tools, use custom flags.
 
-KBUILD_CFLAGS := -fno-strict-aliasing -Wall -Wstrict-prototypes 
-fno-zero-initialized-in-bss -fno-builtin -ffreestanding -c -MD -Os 
-mcmodel=large
+KBUILD_CFLAGS := -fno-strict-aliasing -Wall -Wstrict-prototypes 
-fno-zero-initialized-in-bss -fno-builtin -ffreestanding -c -Os -mcmodel=large
 KBUILD_CFLAGS += -m$(BITS)
 KBUILD_CFLAGS += $(call cc-option,-fno-PIE)
 


Re: [PATCH][next][V2] staging: r8822be: fix typos in header guard macros

2018-03-24 Thread Larry Finger

On 03/23/2018 01:00 PM, Colin King wrote:

From: Colin Ian King 

The macros for __PHYDMKFREE_H__ and __PHYDM_FEATURES_H__ contain
typos and don't match the #if guard check. Defined them correctly.

Cleans up clang warnings:
warning: '__PHYDMKFREE_H__' is used as a header guard here, followed
by #define of a different macro [-Wheader-guard]
warning: '__PHYDM_FEATURES_H__' is used as a header guard here, followed
by #define of a different macro [-Wheader-guard]

Fixes: 9ce99b04b5b8 ("staging: r8822be: Add phydm mini driver")
Signed-off-by: Colin Ian King 


Acked-by: Larry Finger 


---
  drivers/staging/rtlwifi/phydm/phydm_features.h | 2 +-
  drivers/staging/rtlwifi/phydm/phydm_kfree.h| 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtlwifi/phydm/phydm_features.h 
b/drivers/staging/rtlwifi/phydm/phydm_features.h
index 37f6f0cd7235..a12361c6a1a0 100644
--- a/drivers/staging/rtlwifi/phydm/phydm_features.h
+++ b/drivers/staging/rtlwifi/phydm/phydm_features.h
@@ -24,7 +24,7 @@
   
*/
  
  #ifndef __PHYDM_FEATURES_H__

-#define __PHYDM_FEATURES
+#define __PHYDM_FEATURES_H__
  
  /*phydm debyg report & tools*/
  
diff --git a/drivers/staging/rtlwifi/phydm/phydm_kfree.h b/drivers/staging/rtlwifi/phydm/phydm_kfree.h

index 1ee60059afc1..2c6b0a48e76e 100644
--- a/drivers/staging/rtlwifi/phydm/phydm_kfree.h
+++ b/drivers/staging/rtlwifi/phydm/phydm_kfree.h
@@ -24,7 +24,7 @@
   
*/
  
  #ifndef __PHYDMKFREE_H__

-#define __PHYDKFREE_H__
+#define __PHYDKKFREE_H__
  
  #define KFREE_VERSION "1.0"
  





Re: [PATCH 1/3] ieee80211: Replace bit shifts with the BIT() macro for WLAN_CAPABILITY_*.

2018-03-24 Thread Larry Finger

On 03/23/2018 11:10 PM, Quytelda Kahja wrote:

It is neater and more consistent with the rest of the document to use the
BIT() macro from 'linux/bitops.h' to define the WLAN_CAPABILITY_*
bitmasks.  In the case of WLAN_CAPABILITY_DMG_TYPE_{IBSS, PBSS, AP},
bitshifting integers by 0 does nothing, so there is no reason to do it in
the code; replace these values with plain integers.

Signed-off-by: Quytelda Kahja 


In the commit message for all of these, what is the "document" to which you 
refer?

I'm not quite sure why you split these changes into 3 parts, but I guess that 
is OK.

Larry


[PATCH] net: qmi_wwan: add BroadMobi BM806U 2020:2033

2018-03-24 Thread Pawel Dembicki
BroadMobi BM806U is an Qualcomm MDM9225 based 3G/4G modem.
Tested hardware BM806U is mounted on D-Link DWR-921-C3 router.
The USB id is added to qmi_wwan.c to allow QMI communication with
the BM806U.

Tested on 4.14 kernel and OpenWRT.

Signed-off-by: Pawel Dembicki 
---
 drivers/net/usb/qmi_wwan.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c
index 76ac480..7ced288 100644
--- a/drivers/net/usb/qmi_wwan.c
+++ b/drivers/net/usb/qmi_wwan.c
@@ -1180,6 +1180,7 @@ static const struct usb_device_id products[] = {
{QMI_FIXED_INTF(0x19d2, 0x2002, 4)},/* ZTE (Vodafone) K3765-Z */
{QMI_FIXED_INTF(0x2001, 0x7e19, 4)},/* D-Link DWM-221 B1 */
{QMI_FIXED_INTF(0x2001, 0x7e35, 4)},/* D-Link DWM-222 */
+   {QMI_FIXED_INTF(0x2020, 0x2033, 4)},/* BroadMobi BM806U */
{QMI_FIXED_INTF(0x0f3d, 0x68a2, 8)},/* Sierra Wireless MC7700 */
{QMI_FIXED_INTF(0x114f, 0x68a2, 8)},/* Sierra Wireless MC7750 */
{QMI_FIXED_INTF(0x1199, 0x68a2, 8)},/* Sierra Wireless MC7710 in 
QMI mode */
-- 
2.7.4



[PATCH v2 5/8] cgroup: Factor out and expose cgroup_rstat_*() interface functions

2018-03-24 Thread Tejun Heo
>From 6139f87ac4a5650fed5c8be5611becbce96d7f1c Mon Sep 17 00:00:00 2001
From: Tejun Heo 
Date: Sat, 24 Mar 2018 13:39:36 -0700

cgroup_rstat is being generalized so that controllers can use it too.
This patch factors out and exposes the following interface functions.

* cgroup_rstat_updated(): Renamed from cgroup_rstat_cpu_updated() for
  consistency.

* cgroup_rstat_flush_hold/release(): Factored out from base stat
  implementation.

* cgroup_rstat_flush(): Verbatim expose.

While at it, drop assert on cgroup_rstat_mutex in
cgroup_base_stat_flush() as it crosses layers and make a minor comment
update.

v2: Added EXPORT_SYMBOL_GPL(cgroup_rstat_updated) to fix a build bug.

Signed-off-by: Tejun Heo 
---
 include/linux/cgroup.h  | 11 +--
 kernel/cgroup/cgroup-internal.h |  1 -
 kernel/cgroup/rstat.c   | 42 +
 3 files changed, 39 insertions(+), 15 deletions(-)

diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 473e0c0..5c6018f 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -690,11 +690,18 @@ static inline void cgroup_path_from_kernfs_id(const union 
kernfs_node_id *id,
char *buf, size_t buflen) {}
 #endif /* !CONFIG_CGROUPS */
 
+#ifdef CONFIG_CGROUPS
 /*
- * Basic resource stats.
+ * cgroup scalable recursive statistics.
  */
-#ifdef CONFIG_CGROUPS
+void cgroup_rstat_updated(struct cgroup *cgrp, int cpu);
+void cgroup_rstat_flush(struct cgroup *cgrp);
+void cgroup_rstat_flush_hold(struct cgroup *cgrp);
+void cgroup_rstat_flush_release(void);
 
+/*
+ * Basic resource stats.
+ */
 #ifdef CONFIG_CGROUP_CPUACCT
 void cpuacct_charge(struct task_struct *tsk, u64 cputime);
 void cpuacct_account_field(struct task_struct *tsk, int index, u64 val);
diff --git a/kernel/cgroup/cgroup-internal.h b/kernel/cgroup/cgroup-internal.h
index 2bf6fb4..b68e1a7 100644
--- a/kernel/cgroup/cgroup-internal.h
+++ b/kernel/cgroup/cgroup-internal.h
@@ -203,7 +203,6 @@ int cgroup_task_count(const struct cgroup *cgrp);
 /*
  * rstat.c
  */
-void cgroup_rstat_flush(struct cgroup *cgrp);
 int cgroup_rstat_init(struct cgroup *cgrp);
 void cgroup_rstat_exit(struct cgroup *cgrp);
 void cgroup_rstat_boot(void);
diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c
index 87d7252..d49bf92 100644
--- a/kernel/cgroup/rstat.c
+++ b/kernel/cgroup/rstat.c
@@ -13,7 +13,7 @@ static struct cgroup_rstat_cpu *cgroup_rstat_cpu(struct 
cgroup *cgrp, int cpu)
 }
 
 /**
- * cgroup_rstat_cpu_updated - keep track of updated rstat_cpu
+ * cgroup_rstat_updated - keep track of updated rstat_cpu
  * @cgrp: target cgroup
  * @cpu: cpu on which rstat_cpu was updated
  *
@@ -21,7 +21,7 @@ static struct cgroup_rstat_cpu *cgroup_rstat_cpu(struct 
cgroup *cgrp, int cpu)
  * rstat_cpu->updated_children list.  See the comment on top of
  * cgroup_rstat_cpu definition for details.
  */
-static void cgroup_rstat_cpu_updated(struct cgroup *cgrp, int cpu)
+void cgroup_rstat_updated(struct cgroup *cgrp, int cpu)
 {
raw_spinlock_t *cpu_lock = per_cpu_ptr(&cgroup_rstat_cpu_lock, cpu);
struct cgroup *parent;
@@ -59,6 +59,7 @@ static void cgroup_rstat_cpu_updated(struct cgroup *cgrp, int 
cpu)
 
raw_spin_unlock_irqrestore(cpu_lock, flags);
 }
+EXPORT_SYMBOL_GPL(cgroup_rstat_updated);
 
 /**
  * cgroup_rstat_cpu_pop_updated - iterate and dismantle rstat_cpu updated tree
@@ -167,6 +168,29 @@ void cgroup_rstat_flush(struct cgroup *cgrp)
mutex_unlock(&cgroup_rstat_mutex);
 }
 
+/**
+ * cgroup_rstat_flush_begin - flush stats in @cgrp's subtree and hold
+ * @cgrp: target cgroup
+ *
+ * Flush stats in @cgrp's subtree and prevent further flushes.  Must be
+ * paired with cgroup_rstat_flush_release().
+ */
+void cgroup_rstat_flush_hold(struct cgroup *cgrp)
+   __acquires(&cgroup_rstat_mutex)
+{
+   mutex_lock(&cgroup_rstat_mutex);
+   cgroup_rstat_flush_locked(cgrp);
+}
+
+/**
+ * cgroup_rstat_flush_release - release cgroup_rstat_flush_hold()
+ */
+void cgroup_rstat_flush_release(void)
+   __releases(&cgroup_rstat_mutex)
+{
+   mutex_unlock(&cgroup_rstat_mutex);
+}
+
 int cgroup_rstat_init(struct cgroup *cgrp)
 {
int cpu;
@@ -239,15 +263,13 @@ static void cgroup_base_stat_flush(struct cgroup *cgrp, 
int cpu)
struct cgroup_base_stat delta;
unsigned seq;
 
-   lockdep_assert_held(&cgroup_rstat_mutex);
-
/* fetch the current per-cpu values */
do {
seq = __u64_stats_fetch_begin(&rstatc->bsync);
cputime = rstatc->bstat.cputime;
} while (__u64_stats_fetch_retry(&rstatc->bsync, seq));
 
-   /* accumulate the deltas to propgate */
+   /* calculate the delta to propgate */
delta.cputime.utime = cputime.utime - last_cputime->utime;
delta.cputime.stime = cputime.stime - last_cputime->stime;
delta.cputime.sum_exec_runtime = cputime.sum_exec_runtime -
@@ -278,7 +300,7 @@ static void cgroup_base_stat_cputime_account_end(struct 

Re: [PATCH 10/10] mm: Clear shrinker bit if there are no objects related to memcg

2018-03-24 Thread Vladimir Davydov
On Wed, Mar 21, 2018 at 04:23:01PM +0300, Kirill Tkhai wrote:
> To avoid further unneed calls of do_shrink_slab()
> for shrinkers, which already do not have any charged
> objects in a memcg, their bits have to be cleared.
> 
> This patch introduces new return value SHRINK_EMPTY,
> which will be used in case of there is no charged
> objects in shrinker. We can't use 0 instead of that,
> as a shrinker may return 0, when it has very small
> amount of objects.
> 
> To prevent race with parallel list lru add, we call
> do_shrink_slab() once again, after the bit is cleared.
> So, if there is a new object, we never miss it, and
> the bit will be restored again.
> 
> The below test shows significant performance growths
> after using the patchset:
> 
> $echo 1 > /sys/fs/cgroup/memory/memory.use_hierarchy
> $mkdir /sys/fs/cgroup/memory/ct
> $echo 4000M > /sys/fs/cgroup/memory/ct/memory.kmem.limit_in_bytes
> $for i in `seq 0 4000`; do mkdir /sys/fs/cgroup/memory/ct/$i; echo $$ > 
> /sys/fs/cgroup/memory/ct/$i/cgroup.procs; mkdir -p s/$i; mount -t tmpfs $i 
> s/$i; touch s/$i/file; done
> 
> Then 4 drop_caches:
> $time echo 3 > /proc/sys/vm/drop_caches
> 
> Times of drop_caches:
> 
> *Before (4 iterations)*
> 0.00user 6.80system 0:06.82elapsed 99%CPU
> 0.00user 4.61system 0:04.62elapsed 99%CPU
> 0.00user 4.61system 0:04.61elapsed 99%CPU
> 0.00user 4.61system 0:04.61elapsed 99%CPU
> 
> *After (4 iterations)*
> 0.00user 0.93system 0:00.94elapsed 99%CPU
> 0.00user 0.00system 0:00.01elapsed 80%CPU
> 0.00user 0.00system 0:00.01elapsed 80%CPU
> 0.00user 0.00system 0:00.01elapsed 81%CPU
> 
> 4.61s/0.01s = 461 times faster.
> 
> Signed-off-by: Kirill Tkhai 
> ---
>  fs/super.c   |3 +++
>  include/linux/shrinker.h |1 +
>  mm/vmscan.c  |   21 ++---
>  mm/workingset.c  |3 +++
>  4 files changed, 25 insertions(+), 3 deletions(-)
> 
> diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h
> index 24aeed1bc332..b23180deb928 100644
> --- a/include/linux/shrinker.h
> +++ b/include/linux/shrinker.h
> @@ -34,6 +34,7 @@ struct shrink_control {
>  };
>  
>  #define SHRINK_STOP (~0UL)
> +#define SHRINK_EMPTY (~0UL - 1)

Please update the comment below accordingly.

>  /*
>   * A callback you can register to apply pressure to ageable caches.
>   *
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index e1fd16bc7a9b..1fc05e8bde04 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -387,6 +387,7 @@ void set_shrinker_bit(struct mem_cgroup *memcg, int nid, 
> int nr)
>  {
>   struct shrinkers_map *map = SHRINKERS_MAP(memcg);
>  
> + smp_mb__before_atomic(); /* Pairs with mb in shrink_slab() */

I don't understand the purpose of this barrier. Please add a comment
explaining why you need it.

>   set_bit(nr, map->map[nid]);
>  }
>  #else /* CONFIG_MEMCG && !CONFIG_SLOB */
> @@ -568,8 +569,8 @@ static unsigned long do_shrink_slab(struct shrink_control 
> *shrinkctl,
>   long scanned = 0, next_deferred;
>  
>   freeable = shrinker->count_objects(shrinker, shrinkctl);
> - if (freeable == 0)
> - return 0;
> + if (freeable == 0 || freeable == SHRINK_EMPTY)
> + return freeable;
>  
>   /*
>* copy the current shrinker scan count into a local variable
> @@ -708,6 +709,7 @@ static unsigned long shrink_slab(gfp_t gfp_mask, int nid,
>  #if defined(CONFIG_MEMCG) && !defined(CONFIG_SLOB)
>   if (!memcg_kmem_enabled() || memcg) {
>   struct shrinkers_map *map;
> + unsigned long ret;
>   int i;
>  
>   map = rcu_dereference_protected(SHRINKERS_MAP(memcg), true);
> @@ -724,7 +726,20 @@ static unsigned long shrink_slab(gfp_t gfp_mask, int nid,
>   clear_bit(i, map->map[nid]);
>   continue;
>   }
> - freed += do_shrink_slab(&sc, shrinker, 
> priority);
> + if (!(shrinker->flags & SHRINKER_NUMA_AWARE))
> + sc.nid = 0;

Hmm, if my memory doesn't fail, in the previous patch you added a BUG_ON
ensuring that a memcg-aware shrinker must also be numa-aware while here
you still check it. Please remove the BUG_ON or remove this check.
Better remove the BUG_ON, because a memcg-aware shrinker doesn't have to
be numa-aware.

> + ret = do_shrink_slab(&sc, shrinker, priority);
> + if (ret == SHRINK_EMPTY) {

do_shrink_slab() is also called for memcg-unaware shrinkers, you should
probably handle SHRINK_EMPTY there as well.

> + clear_bit(i, map->map[nid]);
> + /* pairs with mb in set_shrinker_bit() 
> */
> + smp_mb__after_atomic();
> + ret = do_shrink_slab(&sc, shrinker, 
> priority);
> +  

[PATCH] sysctl: fix sizeof argument to match variable name

2018-03-24 Thread Randy Dunlap
From: Randy Dunlap 

Fix sizeof argument to be the same as the data variable name.
Probably a copy/paste error.
Mostly harmless since both variables are unsigned int.

Fixes kernel bugzilla #197371:
  Possible access to unintended variable in "kernel/sysctl.c" line 1339
https://bugzilla.kernel.org/show_bug.cgi?id=197371

Reported-by: Petru Mihancea 
Signed-off-by: Randy Dunlap 
---
 kernel/sysctl.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- lnx-416-rc6.orig/kernel/sysctl.c
+++ lnx-416-rc6/kernel/sysctl.c
@@ -1329,7 +1329,7 @@ static struct ctl_table vm_table[] = {
{
.procname   = "dirtytime_expire_seconds",
.data   = &dirtytime_expire_interval,
-   .maxlen = sizeof(dirty_expire_interval),
+   .maxlen = sizeof(dirtytime_expire_interval),
.mode   = 0644,
.proc_handler   = dirtytime_interval_handler,
.extra1 = &zero,



[PATCH 03/44] perf annotate: Move cycles/IPC formatting width constants outside TUI

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

These will be used in --stdio2 so lets move it first to reduce noise in
the following patches.

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-fisud7pcak3prk7uwsvs3...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/annotate.c | 19 ---
 tools/perf/util/annotate.h|  3 +++
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index 69ec968ac0be..ca3d99c1e4d9 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -22,9 +22,6 @@ struct disasm_line_samples {
struct sym_hist_entry he;
 };
 
-#define IPC_WIDTH 6
-#define CYCLES_WIDTH 6
-
 struct browser_line {
u32 idx;
int idx_asm;
@@ -107,7 +104,7 @@ static int annotate_browser__pcnt_width(struct 
annotate_browser *ab)
 
 static int annotate_browser__cycles_width(struct annotate_browser *ab)
 {
-   return ab->have_cycles ? IPC_WIDTH + CYCLES_WIDTH : 0;
+   return ab->have_cycles ? ANNOTATION__IPC_WIDTH + 
ANNOTATION__CYCLES_WIDTH : 0;
 }
 
 static void disasm_line__write(struct disasm_line *dl, struct ui_browser 
*browser,
@@ -194,19 +191,19 @@ static void annotate_browser__write(struct ui_browser 
*browser, void *entry, int
}
if (ab->have_cycles) {
if (al->ipc)
-   ui_browser__printf(browser, "%*.2f ", IPC_WIDTH - 1, 
al->ipc);
+   ui_browser__printf(browser, "%*.2f ", 
ANNOTATION__IPC_WIDTH - 1, al->ipc);
else if (!show_title)
-   ui_browser__write_nstring(browser, " ", IPC_WIDTH);
+   ui_browser__write_nstring(browser, " ", 
ANNOTATION__IPC_WIDTH);
else
-   ui_browser__printf(browser, "%*s ", IPC_WIDTH - 1, 
"IPC");
+   ui_browser__printf(browser, "%*s ", 
ANNOTATION__IPC_WIDTH - 1, "IPC");
 
if (al->cycles)
ui_browser__printf(browser, "%*" PRIu64 " ",
-  CYCLES_WIDTH - 1, al->cycles);
+  ANNOTATION__CYCLES_WIDTH - 1, 
al->cycles);
else if (!show_title)
-   ui_browser__write_nstring(browser, " ", CYCLES_WIDTH);
+   ui_browser__write_nstring(browser, " ", 
ANNOTATION__CYCLES_WIDTH);
else
-   ui_browser__printf(browser, "%*s ", CYCLES_WIDTH - 1, 
"Cycle");
+   ui_browser__printf(browser, "%*s ", 
ANNOTATION__CYCLES_WIDTH - 1, "Cycle");
}
 
SLsmg_write_char(' ');
@@ -359,7 +356,7 @@ static void annotate_browser__draw_current_jump(struct 
ui_browser *browser)
}
 
if (ab->have_cycles)
-   width = IPC_WIDTH + CYCLES_WIDTH;
+   width = ANNOTATION__IPC_WIDTH + ANNOTATION__CYCLES_WIDTH;
 
ui_browser__set_color(browser, HE_COLORSET_JUMP_ARROWS);
__ui_browser__line_arrow(browser,
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index e924033432a3..0407234b5157 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -58,6 +58,9 @@ bool ins__is_lock(const struct ins *ins);
 int ins__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands 
*ops);
 bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2);
 
+#define ANNOTATION__IPC_WIDTH 6
+#define ANNOTATION__CYCLES_WIDTH 6
+
 struct annotation_options {
bool hide_src_code,
 use_offset,
-- 
2.14.3



[GIT PULL 00/44] perf/core improvements and fixes

2018-03-24 Thread Arnaldo Carvalho de Melo
Hi Ingo,

Mostly a 'perf annotate' refactoring to allow reusing the TUI
formatting routines in a --stdio2 mode for 'perf annotate' that at some
point should replace --stdio, leaving that old code deprecated for a
while, then ditching it.

That will take a while yet because there is some stuff in the
--stdio code that needs to be done in the annotation UI agnostic core to
then get used in --tui and --stdio2.

There is also some improvements for issues Linus reported in the
TUI annotation code for ASM functions.

Please consider pulling,

- Arnaldo

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

The following changes since commit ecd380b8dead1bad67e3af87e2ddfe826c3da79d:

  Merge tag 'perf-core-for-mingo-4.17-20180319' of 
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core 
(2018-03-19 20:37:48 +0100)

are available in the Git repository at:

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

for you to fetch changes up to 980b68ec0694f250e967cb18c5705ef5de10fdd5:

  perf annotate: Use absolute addresses to calculate jump target offsets 
(2018-03-23 16:46:53 -0300)


perf/core improvements and fixes:

- Move non-TUI specific annotation routines out of the TUI browser so
  that it can be used in other UIs, and to demonstrate that introduce
  a 'perf annotate --stdio2' option that will apply those formatting
  routines to provide a non-interactive annotation mode (Arnaldo Carvalho de 
Melo)

- Add 'P' hotkey to the annotation TUI, so dump the current annotated
  symbol to a file, easing report thru e-mail, by getting rid of the
  spaces + right hand side scrollbar chars (Arnaldo Carvalho de Melo)

- Support --ignore-vmlinux to 'perf report' and 'perf annotate', that
  was already present in 'perf top', to use /proc/{kcore,kallsyms},
  allowing to see what is in fact running (patched stuff, alternatives,
  ftrace, etc), not the initial state of the kernel (vmlinux) (Arnaldo Carvalho 
de Melo)

- Support 'jump' instructions to a different function, treating them
  as 'call' instructions (Arnaldo Carvalho de Melo)

- Fix some jump artifacts when using vmlinux + ASM functions, where
  the ELF symtab for instance, for entry_SYSCALL_64 includes that and
  what comes after the 'syscall_return_via_sysret' label, but the
  objdump -dS prints the jump targets + offsets using the
  syscall_return_via_sysret address, which was confusing 'perf annotate'.
  See the cset comments for further info (Arnaldo Carvalho de Melo)

- Report error from dwfl_attach_state() in the unwind code (Martin Vuille)

- Reference Py_None before returning it in the python extension (Petr Machata)

Signed-off-by: Arnaldo Carvalho de Melo 


Arnaldo Carvalho de Melo (42):
  perf annotate: Move annotation_options out of the TUI browser
  perf annotate: Move cycles/IPC formatting width constants outside TUI
  perf annotate tui: Use annotate_browser__cycles_width() mroe
  perf annotate tui: Move have_cycles to struct annotation
  perf annotate: Move annotation_line array from TUI to generic code
  perf annotate: Move compute_ipc() to annotation library
  perf annotate: Move nr_events from annotate_browser to annotation struct
  perf annotate: Stop using a global config struct
  perf annotate: Move pcnt_with() to the annotation library
  perf annotate tui: Add browser__annotation() helper
  perf annotate: Move max_jump_sources to struct annotation
  perf annotate: Move jumps_percent_color to ui_browser
  perf annotate: Move nr_jumps to struct annotation
  perf annotate: Move mark_jump_targets from the TUI to the annotation 
library
  perf annotate: Nuke struct browser_line
  perf annotate: Move 'start' to struct annotation
  perf annotate: Move nr_{asm_}entries to struct annotation
  perf annotate: Introduce set_offsets() method out of TUI code
  perf annotate: Move the column widths from the TUI to generic lib
  perf annotate: Move update_column_widths() to the generic lib
  perf annotate: Introduce init_column_widths() method out of TUI code
  perf annotate: Introduce symbol__annotate2 method
  perf annotate: Introduce annotation_line__max_percent()
  perf ui browser: Add vprintf() method
  perf annotate: Introduce annotation_line__print_start() out of TUI code
  perf annotate: Finish the generalization of annotate_browser__write()
  perf annotate: Use a ops table for annotation_line__write()
  perf annotate: Introduce annotation_line__filter()
  perf annotate: Introduce the --stdio2 output mode
  perf annotate: Move the default annotate options to the library
  perf annotate: Use the default annotation options for --stdio2
  perf annotate: Add function header to --stdio2
  perf annota

[PATCH 09/44] perf annotate: Stop using a global config struct

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

For the TUI, that is interactive, its interesting to have a
configuration that one can go on changing and then when moving from one
symbol annotation to another symbol, the options set while browsing the
first symbol to be kept.

But since we're trying to make this code reusable by a --stdio
formatter, we better have a pointer in struct annotation and in the TUI
case set it to the global, but use something else for other cases, such
as --stdio2.

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-kv1ngr159jfu5h9ddgiuw...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/annotate.c | 84 +++
 tools/perf/util/annotate.h|  1 +
 2 files changed, 51 insertions(+), 34 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index 8a110765b328..b20e0ae72466 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -63,10 +63,12 @@ static inline struct browser_line *browser_line(struct 
annotation_line *al)
return ptr - sizeof(struct browser_line);
 }
 
-static bool disasm_line__filter(struct ui_browser *browser __maybe_unused,
-   void *entry)
+static bool disasm_line__filter(struct ui_browser *browser, void *entry)
 {
-   if (annotate_browser__opts.hide_src_code) {
+   struct map_symbol *ms = browser->priv;
+   struct annotation *notes = symbol__annotation(ms->sym);
+
+   if (notes->options->hide_src_code) {
struct annotation_line *al = list_entry(entry, struct 
annotation_line, node);
 
return al->offset == -1;
@@ -98,12 +100,15 @@ static int annotate_browser__pcnt_width(struct 
annotate_browser *ab)
 {
struct map_symbol *ms = ab->b.priv;
struct annotation *notes = symbol__annotation(ms->sym);
-   return (annotate_browser__opts.show_total_period ? 12 : 7) * 
notes->nr_events;
+   return (notes->options->show_total_period ? 12 : 7) * notes->nr_events;
 }
 
 static void disasm_line__write(struct disasm_line *dl, struct ui_browser 
*browser,
   char *bf, size_t size)
 {
+   struct map_symbol *ms = browser->priv;
+   struct annotation *notes = symbol__annotation(ms->sym);
+
if (dl->ins.ops && dl->ins.ops->scnprintf) {
if (ins__is_jump(&dl->ins)) {
bool fwd = dl->ops.target.offset > dl->al.offset;
@@ -124,7 +129,7 @@ static void disasm_line__write(struct disasm_line *dl, 
struct ui_browser *browse
ui_browser__write_nstring(browser, " ", 2);
}
 
-   disasm_line__scnprintf(dl, bf, size, 
!annotate_browser__opts.use_offset);
+   disasm_line__scnprintf(dl, bf, size, !notes->options->use_offset);
 }
 
 static void annotate_browser__write(struct ui_browser *browser, void *entry, 
int row)
@@ -136,7 +141,7 @@ static void annotate_browser__write(struct ui_browser 
*browser, void *entry, int
struct annotation_line *al = list_entry(entry, struct annotation_line, 
node);
struct browser_line *bl = browser_line(al);
bool current_entry = ui_browser__is_current_entry(browser, row);
-   bool change_color = (!annotate_browser__opts.hide_src_code &&
+   bool change_color = (!notes->options->hide_src_code &&
 (!current_entry || (browser->use_navkeypressed &&
 !browser->navkeypressed)));
int width = browser->width, printed;
@@ -164,10 +169,10 @@ static void annotate_browser__write(struct ui_browser 
*browser, void *entry, int
ui_browser__set_percent_color(browser,
al->samples[i].percent,
current_entry);
-   if (annotate_browser__opts.show_total_period) {
+   if (notes->options->show_total_period) {
ui_browser__printf(browser, "%11" PRIu64 " ",
   al->samples[i].he.period);
-   } else if (annotate_browser__opts.show_nr_samples) {
+   } else if (notes->options->show_nr_samples) {
ui_browser__printf(browser, "%6" PRIu64 " ",
   
al->samples[i].he.nr_samples);
} else {
@@ -182,8 +187,8 @@ static void annotate_browser__write(struct ui_browser 
*browser, void *entry, int
ui_browser__write_nstring(browser, " ", pcnt_width);
else {
ui_browser__printf(browser, "%*s", pcnt_width,
-  
annotate_browser__opts.show_total_period ? "Period" :
- 

[PATCH 07/44] perf annotate: Move compute_ipc() to annotation library

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

Out of the TUI code, as it has nothing specific to that UI and should be
used in the other output modes as well.

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-0jahghvqdodb8vu2591pk...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/annotate.c | 69 +--
 tools/perf/util/annotate.c| 60 ++
 tools/perf/util/annotate.h|  2 ++
 3 files changed, 63 insertions(+), 68 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index e89b68612408..353edff3fdbb 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -967,73 +967,6 @@ int hist_entry__tui_annotate(struct hist_entry *he, struct 
perf_evsel *evsel,
return map_symbol__tui_annotate(&he->ms, evsel, hbt);
 }
 
-
-static unsigned count_insn(struct annotation *notes, u64 start, u64 end)
-{
-   unsigned n_insn = 0;
-   u64 offset;
-
-   for (offset = start; offset <= end; offset++) {
-   if (notes->offsets[offset])
-   n_insn++;
-   }
-   return n_insn;
-}
-
-static void count_and_fill(struct annotation *notes, u64 start, u64 end,
-  struct cyc_hist *ch)
-{
-   unsigned n_insn;
-   u64 offset;
-
-   n_insn = count_insn(notes, start, end);
-   if (n_insn && ch->num && ch->cycles) {
-   float ipc = n_insn / ((double)ch->cycles / (double)ch->num);
-
-   /* Hide data when there are too many overlaps. */
-   if (ch->reset >= 0x7fff || ch->reset >= ch->num / 2)
-   return;
-
-   for (offset = start; offset <= end; offset++) {
-   struct annotation_line *al = notes->offsets[offset];
-
-   if (al)
-   al->ipc = ipc;
-   }
-   }
-}
-
-/*
- * This should probably be in util/annotate.c to share with the tty
- * annotate, but right now we need the per byte offsets arrays,
- * which are only here.
- */
-static void annotate__compute_ipc(struct annotation *notes, size_t size)
-{
-   u64 offset;
-
-   if (!notes->src || !notes->src->cycles_hist)
-   return;
-
-   pthread_mutex_lock(¬es->lock);
-   for (offset = 0; offset < size; ++offset) {
-   struct cyc_hist *ch;
-
-   ch = ¬es->src->cycles_hist[offset];
-   if (ch && ch->cycles) {
-   struct annotation_line *al;
-
-   if (ch->have_start)
-   count_and_fill(notes, ch->start, offset, ch);
-   al = notes->offsets[offset];
-   if (al && ch->num_aggr)
-   al->cycles = ch->cycles_aggr / ch->num_aggr;
-   notes->have_cycles = true;
-   }
-   }
-   pthread_mutex_unlock(¬es->lock);
-}
-
 static void annotate_browser__mark_jump_targets(struct annotate_browser 
*browser,
size_t size)
 {
@@ -1161,7 +1094,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map 
*map,
}
 
annotate_browser__mark_jump_targets(&browser, size);
-   annotate__compute_ipc(notes, size);
+   annotation__compute_ipc(notes, size);
 
browser.addr_width = browser.target_width = browser.min_addr_width = 
hex_width(size);
browser.max_addr_width = hex_width(sym->end);
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 535357c6ce02..d737c33c87d0 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -833,6 +833,66 @@ int addr_map_symbol__account_cycles(struct addr_map_symbol 
*ams,
return err;
 }
 
+static unsigned annotation__count_insn(struct annotation *notes, u64 start, 
u64 end)
+{
+   unsigned n_insn = 0;
+   u64 offset;
+
+   for (offset = start; offset <= end; offset++) {
+   if (notes->offsets[offset])
+   n_insn++;
+   }
+   return n_insn;
+}
+
+static void annotation__count_and_fill(struct annotation *notes, u64 start, 
u64 end, struct cyc_hist *ch)
+{
+   unsigned n_insn;
+   u64 offset;
+
+   n_insn = annotation__count_insn(notes, start, end);
+   if (n_insn && ch->num && ch->cycles) {
+   float ipc = n_insn / ((double)ch->cycles / (double)ch->num);
+
+   /* Hide data when there are too many overlaps. */
+   if (ch->reset >= 0x7fff || ch->reset >= ch->num / 2)
+   return;
+
+   for (offset = start; offset <= end; offset++) {
+   struct annotation_line *al = notes->offsets[offset];
+
+   if (al)
+   al->ipc = i

[PATCH 08/44] perf annotate: Move nr_events from annotate_browser to annotation struct

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

Paving the way to move more stuff out of TUI and into the generic
annotation library.

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-8vqax6wgfqohelot8j8zs...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/annotate.c | 11 ++-
 tools/perf/util/annotate.h|  1 +
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index 353edff3fdbb..8a110765b328 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -41,7 +41,6 @@ struct annotate_browser {
struct rb_node *curr_hot;
struct annotation_line *selection;
struct arch*arch;
-   int nr_events;
u64 start;
int nr_asm_entries;
int nr_entries;
@@ -97,7 +96,9 @@ static int annotate_browser__set_jumps_percent_color(struct 
annotate_browser *br
 
 static int annotate_browser__pcnt_width(struct annotate_browser *ab)
 {
-   return (annotate_browser__opts.show_total_period ? 12 : 7) * 
ab->nr_events;
+   struct map_symbol *ms = ab->b.priv;
+   struct annotation *notes = symbol__annotation(ms->sym);
+   return (annotate_browser__opts.show_total_period ? 12 : 7) * 
notes->nr_events;
 }
 
 static void disasm_line__write(struct disasm_line *dl, struct ui_browser 
*browser,
@@ -145,7 +146,7 @@ static void annotate_browser__write(struct ui_browser 
*browser, void *entry, int
char bf[256];
bool show_title = false;
 
-   for (i = 0; i < ab->nr_events; i++) {
+   for (i = 0; i < notes->nr_events; i++) {
if (al->samples[i].percent > percent_max)
percent_max = al->samples[i].percent;
}
@@ -159,7 +160,7 @@ static void annotate_browser__write(struct ui_browser 
*browser, void *entry, int
}
 
if (al->offset != -1 && percent_max != 0.0) {
-   for (i = 0; i < ab->nr_events; i++) {
+   for (i = 0; i < notes->nr_events; i++) {
ui_browser__set_percent_color(browser,
al->samples[i].percent,
current_entry);
@@ -1099,7 +1100,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map 
*map,
browser.addr_width = browser.target_width = browser.min_addr_width = 
hex_width(size);
browser.max_addr_width = hex_width(sym->end);
browser.jumps_width = width_jumps(browser.max_jump_sources);
-   browser.nr_events = nr_pcnt;
+   notes->nr_events = nr_pcnt;
browser.b.nr_entries = browser.nr_entries;
browser.b.entries = ¬es->src->source,
browser.b.width += 18; /* Percentage */
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 21fa5d7cd9e0..5d15cdf22fc9 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -165,6 +165,7 @@ struct annotation {
pthread_mutex_t lock;
u64 max_coverage;
struct annotation_line  **offsets;
+   int nr_events;
boolhave_cycles;
struct annotated_source *src;
 };
-- 
2.14.3



[PATCH 10/44] perf annotate: Move pcnt_with() to the annotation library

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

Out of the TUI code, since now all it touches is what is in 'struct
annotation'.

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-kh5bbbgd7l4agv9oc5hnw...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/annotate.c | 14 +++---
 tools/perf/util/annotate.h|  5 +
 2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index b20e0ae72466..3b030ee4505f 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -96,13 +96,6 @@ static int annotate_browser__set_jumps_percent_color(struct 
annotate_browser *br
 return ui_browser__set_color(&browser->b, color);
 }
 
-static int annotate_browser__pcnt_width(struct annotate_browser *ab)
-{
-   struct map_symbol *ms = ab->b.priv;
-   struct annotation *notes = symbol__annotation(ms->sym);
-   return (notes->options->show_total_period ? 12 : 7) * notes->nr_events;
-}
-
 static void disasm_line__write(struct disasm_line *dl, struct ui_browser 
*browser,
   char *bf, size_t size)
 {
@@ -145,7 +138,7 @@ static void annotate_browser__write(struct ui_browser 
*browser, void *entry, int
 (!current_entry || (browser->use_navkeypressed &&
 !browser->navkeypressed)));
int width = browser->width, printed;
-   int i, pcnt_width = annotate_browser__pcnt_width(ab),
+   int i, pcnt_width = annotation__pcnt_width(notes),
   cycles_width = annotation__cycles_width(notes);
double percent_max = 0.0;
char bf[256];
@@ -310,7 +303,7 @@ static void annotate_browser__draw_current_jump(struct 
ui_browser *browser)
struct map_symbol *ms = ab->b.priv;
struct symbol *sym = ms->sym;
struct annotation *notes = symbol__annotation(sym);
-   u8 pcnt_width = annotate_browser__pcnt_width(ab);
+   u8 pcnt_width = annotation__pcnt_width(notes);
int width;
 
/* PLT symbols contain external offsets */
@@ -375,11 +368,10 @@ static void annotate_browser__draw_current_jump(struct 
ui_browser *browser)
 
 static unsigned int annotate_browser__refresh(struct ui_browser *browser)
 {
-   struct annotate_browser *ab = container_of(browser, struct 
annotate_browser, b);
struct map_symbol *ms = browser->priv;
struct annotation *notes = symbol__annotation(ms->sym);
int ret = ui_browser__list_head_refresh(browser);
-   int pcnt_width = annotate_browser__pcnt_width(ab);
+   int pcnt_width = annotation__pcnt_width(notes);
 
if (notes->options->jump_arrows)
annotate_browser__draw_current_jump(browser);
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 5936605b5dac..17cd5d274fe5 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -176,6 +176,11 @@ static inline int annotation__cycles_width(struct 
annotation *notes)
return notes->have_cycles ? ANNOTATION__IPC_WIDTH + 
ANNOTATION__CYCLES_WIDTH : 0;
 }
 
+static inline int annotation__pcnt_width(struct annotation *notes)
+{
+   return (notes->options->show_total_period ? 12 : 7) * notes->nr_events;
+}
+
 void annotation__compute_ipc(struct annotation *notes, size_t size);
 
 static inline struct sym_hist *annotation__histogram(struct annotation *notes, 
int idx)
-- 
2.14.3



Re: [PATCH v3 1/4] bus: fsl-mc: move fsl_mc_command struct in a uapi header

2018-03-24 Thread kbuild test robot
Hi Ioana,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on staging/staging-testing]
[cannot apply to linus/master v4.16-rc6 next-20180323]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Ioana-Ciornei/bus-fsl-mc-enhance-Management-Complex-userspace-support/20180325-034313
config: i386-tinyconfig (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=i386 

All warnings (new ones prefixed by >>):

>> ./usr/include/linux/fsl_mc.h:19: found __[us]{8,16,32,64} type without 
>> #include 

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


.config.gz
Description: application/gzip


[PATCH 12/44] perf annotate: Move max_jump_sources to struct annotation

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

This is not useful only for the TUI, we'll want to somehow mark the
--stdio2 lines with the most jump sources too.

And moving this will allow us to change some function signatures from
annotate_browser to ui_browser, reducing boilerplate.

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-vyggbbqd05k3k4mvv7z9l...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/annotate.c | 11 ++-
 tools/perf/util/annotate.h|  1 +
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index c995d28d1a58..3bc003fe0b1d 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -44,7 +44,6 @@ struct annotate_browser {
u64 start;
int nr_asm_entries;
int nr_entries;
-   int max_jump_sources;
int nr_jumps;
boolsearching_backwards;
u8  addr_width;
@@ -85,9 +84,11 @@ static bool disasm_line__filter(struct ui_browser *browser, 
void *entry)
 static int annotate_browser__jumps_percent_color(struct annotate_browser 
*browser,
 int nr, bool current)
 {
+   struct annotation *notes = browser__annotation(&browser->b);
+
if (current && (!browser->b.use_navkeypressed || 
browser->b.navkeypressed))
return HE_COLORSET_SELECTED;
-   if (nr == browser->max_jump_sources)
+   if (nr == notes->max_jump_sources)
return HE_COLORSET_TOP;
if (nr > 1)
return HE_COLORSET_MEDIUM;
@@ -998,8 +999,8 @@ static void annotate_browser__mark_jump_targets(struct 
annotate_browser *browser
continue;
 
blt = browser_line(al);
-   if (++blt->jump_sources > browser->max_jump_sources)
-   browser->max_jump_sources = blt->jump_sources;
+   if (++blt->jump_sources > notes->max_jump_sources)
+   notes->max_jump_sources = blt->jump_sources;
 
++browser->nr_jumps;
}
@@ -1099,7 +1100,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map 
*map,
 
browser.addr_width = browser.target_width = browser.min_addr_width = 
hex_width(size);
browser.max_addr_width = hex_width(sym->end);
-   browser.jumps_width = width_jumps(browser.max_jump_sources);
+   browser.jumps_width = width_jumps(notes->max_jump_sources);
notes->nr_events = nr_pcnt;
browser.b.nr_entries = browser.nr_entries;
browser.b.entries = ¬es->src->source,
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 17cd5d274fe5..b8aca936ed55 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -167,6 +167,7 @@ struct annotation {
struct annotation_options *options;
struct annotation_line  **offsets;
int nr_events;
+   int max_jump_sources;
boolhave_cycles;
struct annotated_source *src;
 };
-- 
2.14.3



[PATCH 11/44] perf annotate tui: Add browser__annotation() helper

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

To reduce the boilerplate to get to the symbol being annotated from the
struct browser ->priv area.

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-ficdyqhe9esjseflvkris...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/annotate.c | 40 ---
 1 file changed, 16 insertions(+), 24 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index 3b030ee4505f..c995d28d1a58 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -55,6 +55,12 @@ struct annotate_browser {
charsearch_bf[128];
 };
 
+static inline struct annotation *browser__annotation(struct ui_browser 
*browser)
+{
+   struct map_symbol *ms = browser->priv;
+   return symbol__annotation(ms->sym);
+}
+
 static inline struct browser_line *browser_line(struct annotation_line *al)
 {
void *ptr = al;
@@ -65,8 +71,7 @@ static inline struct browser_line *browser_line(struct 
annotation_line *al)
 
 static bool disasm_line__filter(struct ui_browser *browser, void *entry)
 {
-   struct map_symbol *ms = browser->priv;
-   struct annotation *notes = symbol__annotation(ms->sym);
+   struct annotation *notes = browser__annotation(browser);
 
if (notes->options->hide_src_code) {
struct annotation_line *al = list_entry(entry, struct 
annotation_line, node);
@@ -99,8 +104,7 @@ static int annotate_browser__set_jumps_percent_color(struct 
annotate_browser *br
 static void disasm_line__write(struct disasm_line *dl, struct ui_browser 
*browser,
   char *bf, size_t size)
 {
-   struct map_symbol *ms = browser->priv;
-   struct annotation *notes = symbol__annotation(ms->sym);
+   struct annotation *notes = browser__annotation(browser);
 
if (dl->ins.ops && dl->ins.ops->scnprintf) {
if (ins__is_jump(&dl->ins)) {
@@ -128,9 +132,7 @@ static void disasm_line__write(struct disasm_line *dl, 
struct ui_browser *browse
 static void annotate_browser__write(struct ui_browser *browser, void *entry, 
int row)
 {
struct annotate_browser *ab = container_of(browser, struct 
annotate_browser, b);
-   struct map_symbol *ms = browser->priv;
-   struct symbol *sym = ms->sym;
-   struct annotation *notes = symbol__annotation(sym);
+   struct annotation *notes = browser__annotation(browser);
struct annotation_line *al = list_entry(entry, struct annotation_line, 
node);
struct browser_line *bl = browser_line(al);
bool current_entry = ui_browser__is_current_entry(browser, row);
@@ -368,8 +370,7 @@ static void annotate_browser__draw_current_jump(struct 
ui_browser *browser)
 
 static unsigned int annotate_browser__refresh(struct ui_browser *browser)
 {
-   struct map_symbol *ms = browser->priv;
-   struct annotation *notes = symbol__annotation(ms->sym);
+   struct annotation *notes = browser__annotation(browser);
int ret = ui_browser__list_head_refresh(browser);
int pcnt_width = annotation__pcnt_width(notes);
 
@@ -438,8 +439,7 @@ static void annotate_browser__set_top(struct 
annotate_browser *browser,
 static void annotate_browser__set_rb_top(struct annotate_browser *browser,
 struct rb_node *nd)
 {
-   struct map_symbol *ms = browser->b.priv;
-   struct annotation *notes = symbol__annotation(ms->sym);
+   struct annotation *notes = browser__annotation(&browser->b);
struct browser_line *bpos;
struct annotation_line *pos;
u32 idx;
@@ -497,8 +497,7 @@ static void annotate_browser__calc_percent(struct 
annotate_browser *browser,
 
 static bool annotate_browser__toggle_source(struct annotate_browser *browser)
 {
-   struct map_symbol *ms = browser->b.priv;
-   struct annotation *notes = symbol__annotation(ms->sym);
+   struct annotation *notes = browser__annotation(&browser->b);
struct annotation_line *al;
struct browser_line *bl;
off_t offset = browser->b.index - browser->b.top_idx;
@@ -588,9 +587,7 @@ static
 struct disasm_line *annotate_browser__find_offset(struct annotate_browser 
*browser,
  s64 offset, s64 *idx)
 {
-   struct map_symbol *ms = browser->b.priv;
-   struct symbol *sym = ms->sym;
-   struct annotation *notes = symbol__annotation(sym);
+   struct annotation *notes = browser__annotation(&browser->b);
struct disasm_line *pos;
 
*idx = 0;
@@ -629,9 +626,7 @@ static
 struct annotation_line *annotate_browser__find_string(struct annotate_browser 
*browser,
  char *s, s64 *idx)
 {
-   struct map_symbol *ms = browser->b.priv;
-   struct symbol *sym = ms->sym;
-

[PATCH 13/44] perf annotate: Move jumps_percent_color to ui_browser

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

Since all it needs is in ui_browser and annotation structs members.

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-9f8c2f9aetbibcw33d615...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/annotate.c | 18 --
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index 3bc003fe0b1d..6e2eea09a9b0 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -81,12 +81,11 @@ static bool disasm_line__filter(struct ui_browser *browser, 
void *entry)
return false;
 }
 
-static int annotate_browser__jumps_percent_color(struct annotate_browser 
*browser,
-int nr, bool current)
+static int ui_browser__jumps_percent_color(struct ui_browser *browser, int nr, 
bool current)
 {
-   struct annotation *notes = browser__annotation(&browser->b);
+   struct annotation *notes = browser__annotation(browser);
 
-   if (current && (!browser->b.use_navkeypressed || 
browser->b.navkeypressed))
+   if (current && (!browser->use_navkeypressed || browser->navkeypressed))
return HE_COLORSET_SELECTED;
if (nr == notes->max_jump_sources)
return HE_COLORSET_TOP;
@@ -95,11 +94,10 @@ static int annotate_browser__jumps_percent_color(struct 
annotate_browser *browse
return HE_COLORSET_NORMAL;
 }
 
-static int annotate_browser__set_jumps_percent_color(struct annotate_browser 
*browser,
-int nr, bool current)
+static int ui_browser__set_jumps_percent_color(struct ui_browser *browser, int 
nr, bool current)
 {
-int color = annotate_browser__jumps_percent_color(browser, nr, 
current);
-return ui_browser__set_color(&browser->b, color);
+int color = ui_browser__jumps_percent_color(browser, nr, current);
+return ui_browser__set_color(browser, color);
 }
 
 static void disasm_line__write(struct disasm_line *dl, struct ui_browser 
*browser,
@@ -237,8 +235,8 @@ static void annotate_browser__write(struct ui_browser 
*browser, void *entry, int
printed = scnprintf(bf, sizeof(bf), 
"%*d ",
ab->jumps_width,
bl->jump_sources);
-   prev = 
annotate_browser__set_jumps_percent_color(ab, bl->jump_sources,
-   
 current_entry);
+   prev = 
ui_browser__set_jumps_percent_color(browser, bl->jump_sources,
+   
   current_entry);
ui_browser__write_nstring(browser, bf, 
printed);
ui_browser__set_color(browser, prev);
}
-- 
2.14.3



[PATCH 15/44] perf annotate: Move mark_jump_targets from the TUI to the annotation library

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

This also is not TUI specific, should be used in the upcoming --stdio2
mode.

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-v827xec8z3hxrmgp7bwa6...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/annotate.c | 54 +++
 tools/perf/util/annotate.c| 44 +++
 tools/perf/util/annotate.h|  4 +++
 3 files changed, 51 insertions(+), 51 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index d05a2f991207..58be0cecb081 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -25,7 +25,6 @@ struct disasm_line_samples {
 struct browser_line {
u32 idx;
int idx_asm;
-   int jump_sources;
 };
 
 static struct annotation_options annotate_browser__opts = {
@@ -132,7 +131,6 @@ static void annotate_browser__write(struct ui_browser 
*browser, void *entry, int
struct annotate_browser *ab = container_of(browser, struct 
annotate_browser, b);
struct annotation *notes = browser__annotation(browser);
struct annotation_line *al = list_entry(entry, struct annotation_line, 
node);
-   struct browser_line *bl = browser_line(al);
bool current_entry = ui_browser__is_current_entry(browser, row);
bool change_color = (!notes->options->hide_src_code &&
 (!current_entry || (browser->use_navkeypressed &&
@@ -228,13 +226,13 @@ static void annotate_browser__write(struct ui_browser 
*browser, void *entry, int
if (!notes->options->use_offset) {
printed = scnprintf(bf, sizeof(bf), "%" PRIx64 ": ", 
addr);
} else {
-   if (bl->jump_sources) {
+   if (al->jump_sources) {
if (notes->options->show_nr_jumps) {
int prev;
printed = scnprintf(bf, sizeof(bf), 
"%*d ",
ab->jumps_width,
-   bl->jump_sources);
-   prev = 
ui_browser__set_jumps_percent_color(browser, bl->jump_sources,
+   al->jump_sources);
+   prev = 
ui_browser__set_jumps_percent_color(browser, al->jump_sources,

   current_entry);
ui_browser__write_nstring(browser, bf, 
printed);
ui_browser__set_color(browser, prev);
@@ -263,17 +261,6 @@ static void annotate_browser__write(struct ui_browser 
*browser, void *entry, int
ab->selection = al;
 }
 
-static bool disasm_line__is_valid_jump(struct disasm_line *dl, struct symbol 
*sym)
-{
-   if (!dl || !dl->ins.ops || !ins__is_jump(&dl->ins)
-   || !disasm_line__has_offset(dl)
-   || dl->ops.target.offset < 0
-   || dl->ops.target.offset >= (s64)symbol__size(sym))
-   return false;
-
-   return true;
-}
-
 static bool is_fused(struct annotate_browser *ab, struct disasm_line *cursor)
 {
struct disasm_line *pos = list_prev_entry(cursor, al.node);
@@ -964,41 +951,6 @@ int hist_entry__tui_annotate(struct hist_entry *he, struct 
perf_evsel *evsel,
return map_symbol__tui_annotate(&he->ms, evsel, hbt);
 }
 
-static void annotation__mark_jump_targets(struct annotation *notes, struct 
symbol *sym)
-{
-   u64 offset, size = symbol__size(sym);
-
-   /* PLT symbols contain external offsets */
-   if (strstr(sym->name, "@plt"))
-   return;
-
-   for (offset = 0; offset < size; ++offset) {
-   struct annotation_line *al = notes->offsets[offset];
-   struct disasm_line *dl;
-   struct browser_line *blt;
-
-   dl = disasm_line(al);
-
-   if (!disasm_line__is_valid_jump(dl, sym))
-   continue;
-
-   al = notes->offsets[dl->ops.target.offset];
-
-   /*
-* FIXME: Oops, no jump target? Buggy disassembler? Or do we
-* have to adjust to the previous offset?
-*/
-   if (al == NULL)
-   continue;
-
-   blt = browser_line(al);
-   if (++blt->jump_sources > notes->max_jump_sources)
-   notes->max_jump_sources = blt->jump_sources;
-
-   ++notes->nr_jumps;
-   }
-}
-
 static inline int width_jumps(int n)
 {
if (n >= 100)
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index d737c33

[PATCH 16/44] perf annotate: Nuke struct browser_line

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

The information in there are all related to things already moved to
struct annotation, so move those members to struct annotation_line.

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-uc2b9c8iocvuuvbl7hyin...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/annotate.c | 66 ---
 tools/perf/util/annotate.h|  2 ++
 2 files changed, 22 insertions(+), 46 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index 58be0cecb081..50f8e671644f 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -22,11 +22,6 @@ struct disasm_line_samples {
struct sym_hist_entry he;
 };
 
-struct browser_line {
-   u32 idx;
-   int idx_asm;
-};
-
 static struct annotation_options annotate_browser__opts = {
.use_offset = true,
.jump_arrows= true,
@@ -58,14 +53,6 @@ static inline struct annotation *browser__annotation(struct 
ui_browser *browser)
return symbol__annotation(ms->sym);
 }
 
-static inline struct browser_line *browser_line(struct annotation_line *al)
-{
-   void *ptr = al;
-
-   ptr = container_of(al, struct disasm_line, al);
-   return ptr - sizeof(struct browser_line);
-}
-
 static bool disasm_line__filter(struct ui_browser *browser, void *entry)
 {
struct annotation *notes = browser__annotation(browser);
@@ -285,7 +272,6 @@ static void annotate_browser__draw_current_jump(struct 
ui_browser *browser)
struct annotate_browser *ab = container_of(browser, struct 
annotate_browser, b);
struct disasm_line *cursor = disasm_line(ab->selection);
struct annotation_line *target;
-   struct browser_line *btarget, *bcursor;
unsigned int from, to;
struct map_symbol *ms = ab->b.priv;
struct symbol *sym = ms->sym;
@@ -327,15 +313,12 @@ static void annotate_browser__draw_current_jump(struct 
ui_browser *browser)
return;
}
 
-   bcursor = browser_line(&cursor->al);
-   btarget = browser_line(target);
-
if (notes->options->hide_src_code) {
-   from = bcursor->idx_asm;
-   to = btarget->idx_asm;
+   from = cursor->al.idx_asm;
+   to = target->idx_asm;
} else {
-   from = (u64)bcursor->idx;
-   to = (u64)btarget->idx;
+   from = (u64)cursor->al.idx;
+   to = (u64)target->idx;
}
 
width = annotation__cycles_width(notes);
@@ -425,16 +408,11 @@ static void annotate_browser__set_rb_top(struct 
annotate_browser *browser,
 struct rb_node *nd)
 {
struct annotation *notes = browser__annotation(&browser->b);
-   struct browser_line *bpos;
-   struct annotation_line *pos;
-   u32 idx;
-
-   pos = rb_entry(nd, struct annotation_line, rb_node);
-   bpos = browser_line(pos);
+   struct annotation_line * pos = rb_entry(nd, struct annotation_line, 
rb_node);
+   u32 idx = pos->idx;
 
-   idx = bpos->idx;
if (notes->options->hide_src_code)
-   idx = bpos->idx_asm;
+   idx = pos->idx_asm;
annotate_browser__set_top(browser, pos, idx);
browser->curr_hot = nd;
 }
@@ -484,37 +462,35 @@ static bool annotate_browser__toggle_source(struct 
annotate_browser *browser)
 {
struct annotation *notes = browser__annotation(&browser->b);
struct annotation_line *al;
-   struct browser_line *bl;
off_t offset = browser->b.index - browser->b.top_idx;
 
browser->b.seek(&browser->b, offset, SEEK_CUR);
al = list_entry(browser->b.top, struct annotation_line, node);
-   bl = browser_line(al);
 
if (notes->options->hide_src_code) {
-   if (bl->idx_asm < offset)
-   offset = bl->idx;
+   if (al->idx_asm < offset)
+   offset = al->idx;
 
browser->b.nr_entries = browser->nr_entries;
notes->options->hide_src_code = false;
browser->b.seek(&browser->b, -offset, SEEK_CUR);
-   browser->b.top_idx = bl->idx - offset;
-   browser->b.index = bl->idx;
+   browser->b.top_idx = al->idx - offset;
+   browser->b.index = al->idx;
} else {
-   if (bl->idx_asm < 0) {
+   if (al->idx_asm < 0) {
ui_helpline__puts("Only available for assembly lines.");
browser->b.seek(&browser->b, -offset, SEEK_CUR);
return false;
}
 
-   if (bl->idx_asm < offset)
-   offset = bl->idx_asm;
+   if (al->idx_asm < offset)
+   offset = a

[PATCH 19/44] perf annotate: Introduce set_offsets() method out of TUI code

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

More non-strictly TUI code being moved to the UI neutral annotation
library, to be used in the upcoming --stdio2 output mode.

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-ek20dnd8z2y5v54pcepih...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/annotate.c | 24 ++--
 tools/perf/util/annotate.c| 28 
 tools/perf/util/annotate.h|  3 +++
 3 files changed, 33 insertions(+), 22 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index 00b88349a3c2..977c7e9fdadb 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -938,7 +938,6 @@ int symbol__tui_annotate(struct symbol *sym, struct map 
*map,
 struct perf_evsel *evsel,
 struct hist_browser_timer *hbt)
 {
-   struct annotation_line *al;
struct annotation *notes = symbol__annotation(sym);
size_t size;
struct map_symbol ms = {
@@ -991,27 +990,8 @@ int symbol__tui_annotate(struct symbol *sym, struct map 
*map,
 
notes->start = map__rip_2objdump(map, sym->start);
 
-   list_for_each_entry(al, ¬es->src->source, node) {
-   size_t line_len = strlen(al->line);
-
-   if (browser.b.width < line_len)
-   browser.b.width = line_len;
-   al->idx = notes->nr_entries++;
-   if (al->offset != -1) {
-   al->idx_asm = notes->nr_asm_entries++;
-   /*
-* FIXME: short term bandaid to cope with assembly
-* routines that comes with labels in the same column
-* as the address in objdump, sigh.
-*
-* E.g. copy_user_generic_unrolled
-*/
-   if (al->offset < (s64)size)
-   notes->offsets[al->offset] = al;
-   } else
-   al->idx_asm = -1;
-   }
-
+   annotation__set_offsets(notes, size);
+   browser.b.width = notes->max_line_len;
annotation__mark_jump_targets(notes, sym);
annotation__compute_ipc(notes, size);
 
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 330275680a1a..b976e3951662 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -2056,6 +2056,34 @@ void annotation__mark_jump_targets(struct annotation 
*notes, struct symbol *sym)
}
 }
 
+void annotation__set_offsets(struct annotation *notes, s64 size)
+{
+   struct annotation_line *al;
+
+   notes->max_line_len = 0;
+
+   list_for_each_entry(al, ¬es->src->source, node) {
+   size_t line_len = strlen(al->line);
+
+   if (notes->max_line_len < line_len)
+   notes->max_line_len = line_len;
+   al->idx = notes->nr_entries++;
+   if (al->offset != -1) {
+   al->idx_asm = notes->nr_asm_entries++;
+   /*
+* FIXME: short term bandaid to cope with assembly
+* routines that comes with labels in the same column
+* as the address in objdump, sigh.
+*
+* E.g. copy_user_generic_unrolled
+*/
+   if (al->offset < size)
+   notes->offsets[al->offset] = al;
+   } else
+   al->idx_asm = -1;
+   }
+}
+
 static void annotation__calc_lines(struct annotation *notes, struct map *map,
  struct rb_root *root, u64 start)
 {
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 0c34eb0bd7c8..8a61ec9a5291 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -177,6 +177,7 @@ struct annotation {
int max_jump_sources;
int nr_entries;
int nr_asm_entries;
+   u16 max_line_len;
boolhave_cycles;
struct annotated_source *src;
 };
@@ -191,6 +192,8 @@ static inline int annotation__pcnt_width(struct annotation 
*notes)
return (notes->options->show_total_period ? 12 : 7) * notes->nr_events;
 }
 
+
+void annotation__set_offsets(struct annotation *notes, s64 size);
 void annotation__compute_ipc(struct annotation *notes, size_t size);
 void annotation__mark_jump_targets(struct annotation *notes, struct symbol 
*sym);
 
-- 
2.14.3



[PATCH 21/44] perf annotate: Move update_column_widths() to the generic lib

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

Previous patch left it where it was to ease review, move it to its
right place.

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-ikdjr014p7k5kachgyjrg...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/annotate.c | 13 -
 tools/perf/util/annotate.c| 13 +
 tools/perf/util/annotate.h|  1 +
 3 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index 07d0d2268008..ab4d004fc184 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -698,19 +698,6 @@ bool annotate_browser__continue_search_reverse(struct 
annotate_browser *browser,
return __annotate_browser__search_reverse(browser);
 }
 
-static void annotation__update_column_widths(struct annotation *notes)
-{
-   if (notes->options->use_offset)
-   notes->widths.target = notes->widths.min_addr;
-   else
-   notes->widths.target = notes->widths.max_addr;
-
-   notes->widths.addr = notes->widths.target;
-
-   if (notes->options->show_nr_jumps)
-   notes->widths.addr += notes->widths.jumps + 1;
-}
-
 static int annotate_browser__run(struct annotate_browser *browser,
 struct perf_evsel *evsel,
 struct hist_browser_timer *hbt)
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index b976e3951662..8a2fda80a221 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -2084,6 +2084,19 @@ void annotation__set_offsets(struct annotation *notes, 
s64 size)
}
 }
 
+void annotation__update_column_widths(struct annotation *notes)
+{
+   if (notes->options->use_offset)
+   notes->widths.target = notes->widths.min_addr;
+   else
+   notes->widths.target = notes->widths.max_addr;
+
+   notes->widths.addr = notes->widths.target;
+
+   if (notes->options->show_nr_jumps)
+   notes->widths.addr += notes->widths.jumps + 1;
+}
+
 static void annotation__calc_lines(struct annotation *notes, struct map *map,
  struct rb_root *root, u64 start)
 {
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 0aa77c154fe3..a8bea758490a 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -203,6 +203,7 @@ static inline int annotation__pcnt_width(struct annotation 
*notes)
 void annotation__set_offsets(struct annotation *notes, s64 size);
 void annotation__compute_ipc(struct annotation *notes, size_t size);
 void annotation__mark_jump_targets(struct annotation *notes, struct symbol 
*sym);
+void annotation__update_column_widths(struct annotation *notes);
 
 static inline struct sym_hist *annotation__histogram(struct annotation *notes, 
int idx)
 {
-- 
2.14.3



Re: [PATCH 09/10] mm: Iterate only over charged shrinkers during memcg shrink_slab()

2018-03-24 Thread Vladimir Davydov
On Wed, Mar 21, 2018 at 04:22:51PM +0300, Kirill Tkhai wrote:
> Using the preparations made in previous patches, in case of memcg
> shrink, we may avoid shrinkers, which are not set in memcg's shrinkers
> bitmap. To do that, we separate iterations over memcg-aware and
> !memcg-aware shrinkers, and memcg-aware shrinkers are chosen
> via for_each_set_bit() from the bitmap. In case of big nodes,
> having many isolated environments, this gives significant
> performance growth. See next patch for the details.
> 
> Note, that the patch does not respect to empty memcg shrinkers,
> since we never clear the bitmap bits after we set it once.
> Their shrinkers will be called again, with no shrinked objects
> as result. This functionality is provided by next patch.
> 
> Signed-off-by: Kirill Tkhai 
> ---
>  mm/vmscan.c |   54 +-
>  1 file changed, 41 insertions(+), 13 deletions(-)
> 
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 265cf069b470..e1fd16bc7a9b 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -327,6 +327,8 @@ static int alloc_shrinker_id(struct shrinker *shrinker)
>  
>   if (!(shrinker->flags & SHRINKER_MEMCG_AWARE))
>   return 0;
> + BUG_ON(!(shrinker->flags & SHRINKER_NUMA_AWARE));
> +
>  retry:
>   ida_pre_get(&bitmap_id_ida, GFP_KERNEL);
>   down_write(&bitmap_rwsem);
> @@ -366,7 +368,8 @@ static void add_shrinker(struct shrinker *shrinker)
>   down_write(&shrinker_rwsem);
>   if (shrinker->flags & SHRINKER_MEMCG_AWARE)
>   mcg_shrinkers[shrinker->id] = shrinker;
> - list_add_tail(&shrinker->list, &shrinker_list);
> + else
> + list_add_tail(&shrinker->list, &shrinker_list);

I don't think we should remove per-memcg shrinkers from the global
shrinker list - this is confusing. It won't be critical if we iterate
over all shrinkers on global reclaim, will it?

>   up_write(&shrinker_rwsem);
>  }
>  
> @@ -701,6 +705,39 @@ static unsigned long shrink_slab(gfp_t gfp_mask, int nid,
>   if (!down_read_trylock(&shrinker_rwsem))
>   goto out;
>  
> +#if defined(CONFIG_MEMCG) && !defined(CONFIG_SLOB)
> + if (!memcg_kmem_enabled() || memcg) {
> + struct shrinkers_map *map;
> + int i;
> +
> + map = rcu_dereference_protected(SHRINKERS_MAP(memcg), true);
> + if (map) {
> + for_each_set_bit(i, map->map[nid], bitmap_nr_ids) {
> + struct shrink_control sc = {
> + .gfp_mask = gfp_mask,
> + .nid = nid,
> + .memcg = memcg,
> + };
> +
> + shrinker = mcg_shrinkers[i];
> + if (!shrinker) {
> + clear_bit(i, map->map[nid]);
> + continue;
> + }
> + freed += do_shrink_slab(&sc, shrinker, 
> priority);
> +
> + if (rwsem_is_contended(&shrinker_rwsem)) {
> + freed = freed ? : 1;
> + goto unlock;
> + }
> + }
> + }
> +
> + if (memcg_kmem_enabled() && memcg)
> + goto unlock;

May be, factor this out to a separate function, say shrink_slab_memcg?
Just for the sake of code legibility.


[PATCH 20/44] perf annotate: Move the column widths from the TUI to generic lib

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

This also will be used in other output formats, such as --stdio2.

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-86h6ftebc62ij1rx8q9zk...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/annotate.c | 45 +--
 tools/perf/util/annotate.h|  7 ++
 2 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index 977c7e9fdadb..07d0d2268008 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -36,11 +36,6 @@ struct annotate_browser {
struct annotation_line *selection;
struct arch*arch;
boolsearching_backwards;
-   u8  addr_width;
-   u8  jumps_width;
-   u8  target_width;
-   u8  min_addr_width;
-   u8  max_addr_width;
charsearch_bf[128];
 };
 
@@ -194,10 +189,10 @@ static void annotate_browser__write(struct ui_browser 
*browser, void *entry, int
else if (al->offset == -1) {
if (al->line_nr && notes->options->show_linenr)
printed = scnprintf(bf, sizeof(bf), "%-*d ",
-   ab->addr_width + 1, al->line_nr);
+   notes->widths.addr + 1, al->line_nr);
else
printed = scnprintf(bf, sizeof(bf), "%*s  ",
-   ab->addr_width, " ");
+   notes->widths.addr, " ");
ui_browser__write_nstring(browser, bf, printed);
ui_browser__write_nstring(browser, al->line, width - printed - 
pcnt_width - cycles_width + 1);
} else {
@@ -214,7 +209,7 @@ static void annotate_browser__write(struct ui_browser 
*browser, void *entry, int
if (notes->options->show_nr_jumps) {
int prev;
printed = scnprintf(bf, sizeof(bf), 
"%*d ",
-   ab->jumps_width,
+   notes->widths.jumps,
al->jump_sources);
prev = 
ui_browser__set_jumps_percent_color(browser, al->jump_sources,

   current_entry);
@@ -223,10 +218,10 @@ static void annotate_browser__write(struct ui_browser 
*browser, void *entry, int
}
 
printed = scnprintf(bf, sizeof(bf), "%*" PRIx64 
": ",
-   ab->target_width, addr);
+   notes->widths.target, addr);
} else {
printed = scnprintf(bf, sizeof(bf), "%*s  ",
-   ab->addr_width, " ");
+   notes->widths.addr, " ");
}
}
 
@@ -322,12 +317,12 @@ static void annotate_browser__draw_current_jump(struct 
ui_browser *browser)
 
ui_browser__set_color(browser, HE_COLORSET_JUMP_ARROWS);
__ui_browser__line_arrow(browser,
-pcnt_width + 2 + ab->addr_width + width,
+pcnt_width + 2 + notes->widths.addr + width,
 from, to);
 
if (is_fused(ab, cursor)) {
ui_browser__mark_fused(browser,
-  pcnt_width + 3 + ab->addr_width + width,
+  pcnt_width + 3 + notes->widths.addr + 
width,
   from - 1,
   to > from ? true : false);
}
@@ -703,19 +698,17 @@ bool annotate_browser__continue_search_reverse(struct 
annotate_browser *browser,
return __annotate_browser__search_reverse(browser);
 }
 
-static void annotate_browser__update_addr_width(struct annotate_browser 
*browser)
+static void annotation__update_column_widths(struct annotation *notes)
 {
-   struct annotation *notes = browser__annotation(&browser->b);
-
if (notes->options->use_offset)
-   browser->target_width = browser->min_addr_width;
+   notes->widths.target = notes->widths.min_addr;
else
-   browser->target_width = browser->max_addr_width;
+   notes->widths.target = notes->widths.max_addr;
 
-   browser

Re: [PATCH 14/19] powerpc/altivec: Add missing prototypes for altivec

2018-03-24 Thread LEROY Christophe

Mathieu Malaterre  a écrit :


On Fri, Mar 23, 2018 at 1:19 PM, christophe leroy
 wrote:



Le 22/03/2018 à 21:20, Mathieu Malaterre a écrit :


Some functions prototypes were missing for the non-altivec code. Add the
missing prototypes directly in xor_vmx, fix warnings treated as errors
with
W=1:

   arch/powerpc/lib/xor_vmx_glue.c:18:6: error: no previous prototype for
‘xor_altivec_2’ [-Werror=missing-prototypes]
   arch/powerpc/lib/xor_vmx_glue.c:29:6: error: no previous prototype for
‘xor_altivec_3’ [-Werror=missing-prototypes]
   arch/powerpc/lib/xor_vmx_glue.c:40:6: error: no previous prototype for
‘xor_altivec_4’ [-Werror=missing-prototypes]
   arch/powerpc/lib/xor_vmx_glue.c:52:6: error: no previous prototype for
‘xor_altivec_5’ [-Werror=missing-prototypes]

Signed-off-by: Mathieu Malaterre 
---
  arch/powerpc/lib/xor_vmx.h | 14 ++
  1 file changed, 14 insertions(+)

diff --git a/arch/powerpc/lib/xor_vmx.h b/arch/powerpc/lib/xor_vmx.h
index 5c2b0839b179..2173e3c84151 100644
--- a/arch/powerpc/lib/xor_vmx.h
+++ b/arch/powerpc/lib/xor_vmx.h
@@ -19,3 +19,17 @@ void __xor_altivec_4(unsigned long bytes, unsigned long
*v1_in,
  void __xor_altivec_5(unsigned long bytes, unsigned long *v1_in,
 unsigned long *v2_in, unsigned long *v3_in,
 unsigned long *v4_in, unsigned long *v5_in);
+
+void xor_altivec_2(unsigned long bytes, unsigned long *v1_in,
+unsigned long *v2_in);
+



Only used in one place, should be static instead of adding it in a .h

Same for the other ones.


$ git grep xor_altivec_2
[...]
arch/powerpc/lib/xor_vmx_glue.c:EXPORT_SYMBOL(xor_altivec_2);

Are you sure I can change this function to static ?


Yes you are right.  But in fact those fonctions are already defined in  
asm/xor. h

So you just need to add the missing #include

Christophe




Christophe



+void xor_altivec_3(unsigned long bytes, unsigned long *v1_in,
+unsigned long *v2_in, unsigned long *v3_in);
+
+void xor_altivec_4(unsigned long bytes, unsigned long *v1_in,
+unsigned long *v2_in, unsigned long *v3_in,
+unsigned long *v4_in);
+
+void xor_altivec_5(unsigned long bytes, unsigned long *v1_in,
+unsigned long *v2_in, unsigned long *v3_in,
+unsigned long *v4_in, unsigned long *v5_in);



---
L'absence de virus dans ce courrier électronique a été vérifiée par le
logiciel antivirus Avast.
https://www.avast.com/antivirus






[PATCH 23/44] perf annotate: Introduce symbol__annotate2 method

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

That does all the extended boilerplate the TUI browser did, leaving the
symbol__annotate() function to be used by the old --stdio output mode.

Now the upcoming --stdio2 output mode should just use this one to set
things up.

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-e2x8wuf6gvdhzdryo229v...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/annotate.c | 28 +---
 tools/perf/util/annotate.c| 39 +++
 tools/perf/util/annotate.h|  4 
 3 files changed, 44 insertions(+), 27 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index 06ad5ecaa67a..ab21739f27ae 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -910,7 +910,6 @@ int symbol__tui_annotate(struct symbol *sym, struct map 
*map,
 struct hist_browser_timer *hbt)
 {
struct annotation *notes = symbol__annotation(sym);
-   size_t size;
struct map_symbol ms = {
.map = map,
.sym = sym,
@@ -926,28 +925,14 @@ int symbol__tui_annotate(struct symbol *sym, struct map 
*map,
},
};
int ret = -1, err;
-   int nr_pcnt = 1;
 
if (sym == NULL)
return -1;
 
-   size = symbol__size(sym);
-
if (map->dso->annotate_warned)
return -1;
 
-   notes->options = &annotate_browser__opts;
-
-   notes->offsets = zalloc(size * sizeof(struct annotation_line *));
-   if (notes->offsets == NULL) {
-   ui__error("Not enough memory!");
-   return -1;
-   }
-
-   if (perf_evsel__is_group_event(evsel))
-   nr_pcnt = evsel->nr_members;
-
-   err = symbol__annotate(sym, map, evsel, 0, &browser.arch);
+   err = symbol__annotate2(sym, map, evsel, &annotate_browser__opts, 
&browser.arch);
if (err) {
char msg[BUFSIZ];
symbol__strerror_disassemble(sym, map, err, msg, sizeof(msg));
@@ -955,18 +940,9 @@ int symbol__tui_annotate(struct symbol *sym, struct map 
*map,
goto out_free_offsets;
}
 
-   symbol__calc_percent(sym, evsel);
-
ui_helpline__push("Press ESC to exit");
 
-   notes->start = map__rip_2objdump(map, sym->start);
-
-   annotation__set_offsets(notes, size);
browser.b.width = notes->max_line_len;
-   annotation__mark_jump_targets(notes, sym);
-   annotation__compute_ipc(notes, size);
-   annotation__init_column_widths(notes, sym);
-   notes->nr_events = nr_pcnt;
browser.b.nr_entries = notes->nr_entries;
browser.b.entries = ¬es->src->source,
browser.b.width += 18; /* Percentage */
@@ -974,8 +950,6 @@ int symbol__tui_annotate(struct symbol *sym, struct map 
*map,
if (notes->options->hide_src_code)
ui_browser__init_asm_mode(&browser.b);
 
-   annotation__update_column_widths(notes);
-
ret = annotate_browser__run(&browser, evsel, hbt);
 
annotated_source__purge(notes->src);
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 9c05b534f428..7ad6400a0d4f 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -2183,3 +2183,42 @@ bool ui__has_annotation(void)
 {
return use_browser == 1 && perf_hpp_list.sym;
 }
+
+int symbol__annotate2(struct symbol *sym, struct map *map, struct perf_evsel 
*evsel,
+ struct annotation_options *options, struct arch **parch)
+{
+   struct annotation *notes = symbol__annotation(sym);
+   size_t size = symbol__size(sym);
+   int nr_pcnt = 1, err;
+
+   notes->offsets = zalloc(size * sizeof(struct annotation_line *));
+   if (notes->offsets == NULL)
+   return -1;
+
+   if (perf_evsel__is_group_event(evsel))
+   nr_pcnt = evsel->nr_members;
+
+   err = symbol__annotate(sym, map, evsel, 0, parch);
+   if (err)
+   goto out_free_offsets;
+
+   notes->options = options;
+
+   symbol__calc_percent(sym, evsel);
+
+   notes->start = map__rip_2objdump(map, sym->start);
+
+   annotation__set_offsets(notes, size);
+   annotation__mark_jump_targets(notes, sym);
+   annotation__compute_ipc(notes, size);
+   annotation__init_column_widths(notes, sym);
+   notes->nr_events = nr_pcnt;
+
+   annotation__update_column_widths(notes);
+
+   return 0;
+
+out_free_offsets:
+   zfree(¬es->offsets);
+   return -1;
+}
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index c4528e03a031..f93c805473f9 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -233,6 +233,10 @@ void symbol__annotate_zero_histograms(struct symbol *sym);
 int symbol__ann

[PATCH 26/44] perf annotate: Introduce annotation_line__print_start() out of TUI code

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

For the --tui and --stdio2 cases using callbacks for print() and
set_percent_color() end up being the easiest path, real GUI remains as
an exercise.

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-1o7az1ng55g2g6ppr2jpe...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/annotate.c | 82 ++-
 tools/perf/util/annotate.c| 75 +++
 tools/perf/util/annotate.h|  5 +++
 3 files changed, 101 insertions(+), 61 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index 05f79f36e906..9b77a016e299 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -105,6 +105,20 @@ static void disasm_line__write(struct disasm_line *dl, 
struct ui_browser *browse
disasm_line__scnprintf(dl, bf, size, !notes->options->use_offset);
 }
 
+static void annotate_browser__set_percent_color(void *browser, double percent, 
bool current)
+{
+   ui_browser__set_percent_color(browser, percent, current);
+}
+
+static void annotate_browser__printf(void *browser, const char *fmt, ...)
+{
+   va_list args;
+
+   va_start(args, fmt);
+   ui_browser__vprintf(browser, fmt, args);
+   va_end(args);
+}
+
 static void annotate_browser__write(struct ui_browser *browser, void *entry, 
int row)
 {
struct annotate_browser *ab = container_of(browser, struct 
annotate_browser, b);
@@ -115,65 +129,13 @@ static void annotate_browser__write(struct ui_browser 
*browser, void *entry, int
 (!current_entry || (browser->use_navkeypressed &&
 !browser->navkeypressed)));
int width = browser->width, printed;
-   int i, pcnt_width = annotation__pcnt_width(notes),
-  cycles_width = annotation__cycles_width(notes);
-   double percent_max = annotation_line__max_percent(al, notes);
+   int pcnt_width = annotation__pcnt_width(notes),
+   cycles_width = annotation__cycles_width(notes);
char bf[256];
-   bool show_title = false;
-
-   if ((row == 0) && (al->offset == -1 || percent_max == 0.0)) {
-   if (notes->have_cycles) {
-   if (al->ipc == 0.0 && al->cycles == 0)
-   show_title = true;
-   } else
-   show_title = true;
-   }
-
-   if (al->offset != -1 && percent_max != 0.0) {
-   for (i = 0; i < notes->nr_events; i++) {
-   ui_browser__set_percent_color(browser,
-   al->samples[i].percent,
-   current_entry);
-   if (notes->options->show_total_period) {
-   ui_browser__printf(browser, "%11" PRIu64 " ",
-  al->samples[i].he.period);
-   } else if (notes->options->show_nr_samples) {
-   ui_browser__printf(browser, "%6" PRIu64 " ",
-  
al->samples[i].he.nr_samples);
-   } else {
-   ui_browser__printf(browser, "%6.2f ",
-  al->samples[i].percent);
-   }
-   }
-   } else {
-   ui_browser__set_percent_color(browser, 0, current_entry);
-
-   if (!show_title)
-   ui_browser__write_nstring(browser, " ", pcnt_width);
-   else {
-   ui_browser__printf(browser, "%*s", pcnt_width,
-  notes->options->show_total_period ? 
"Period" :
-  notes->options->show_nr_samples ? 
"Samples" : "Percent");
-   }
-   }
-   if (notes->have_cycles) {
-   if (al->ipc)
-   ui_browser__printf(browser, "%*.2f ", 
ANNOTATION__IPC_WIDTH - 1, al->ipc);
-   else if (!show_title)
-   ui_browser__write_nstring(browser, " ", 
ANNOTATION__IPC_WIDTH);
-   else
-   ui_browser__printf(browser, "%*s ", 
ANNOTATION__IPC_WIDTH - 1, "IPC");
-
-   if (al->cycles)
-   ui_browser__printf(browser, "%*" PRIu64 " ",
-  ANNOTATION__CYCLES_WIDTH - 1, 
al->cycles);
-   else if (!show_title)
-   ui_browser__write_nstring(browser, " ", 
ANNOTATION__CYCLES_WIDTH);
-   else
-   ui_browser__printf(browser, "%*s ", 
ANNOTATION__CYCLES_WIDTH - 1, "Cycle");
-   }
 
-   SLsmg_write_char(' ');
+   annotatio

[PATCH 32/44] perf annotate: Use the default annotation options for --stdio2

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

With an empty '[annotate]' section in ~/.perfconfig:

  # perf record -a --all-kernel -e '{cycles,instructions}:P' sleep 5
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 2.243 MB perf.data (5513 samples) ]
  # perf annotate --stdio2 _raw_spin_lock | head -20

 Disassembly of section .text:

 81868790 <_raw_spin_lock>:
 _raw_spin_lock():
 EXPORT_SYMBOL(_raw_spin_trylock_bh);
 #endif

 #ifndef CONFIG_INLINE_SPIN_LOCK
 void __lockfunc _raw_spin_lock(raw_spinlock_t *lock)
 {
 → callq  __fentry__
 atomic_cmpxchg():
 return xadd(&v->counter, -i);
 }

 static __always_inline int atomic_cmpxchg(atomic_t *v, int 
old, int new)
 {
  # perf annotate --stdio2 _raw_spin_lock | head -20
 → callq  __fentry__
   xor%eax,%eax
   mov$0x1,%edx
   87.50 100.00lock   cmpxchg %edx,(%rdi)
6.25   0.00test   %eax,%eax
 ↓ jne16
6.25   0.00repz   retq
 16:   mov%eax,%esi
 ↑ jmpq   810e96b0 
  #
  # cat ~/.perfconfig
  [annotate]

hide_src_code = false
show_linenr = true
  # perf annotate --stdio2 _raw_spin_lock | head -20

 3   Disassembly of section .text:

 5   81868790 <_raw_spin_lock>:
 6   _raw_spin_lock():
 143 EXPORT_SYMBOL(_raw_spin_trylock_bh);
 144 #endif

 146 #ifndef CONFIG_INLINE_SPIN_LOCK
 147 void __lockfunc _raw_spin_lock(raw_spinlock_t *lock)
 148 {
 → callq  __fentry__
 150 atomic_cmpxchg():
 187 return xadd(&v->counter, -i);
 188 }

 190 static __always_inline int atomic_cmpxchg(atomic_t *v, int 
old, int new)
 191 {
  #
  # cat ~/.perfconfig
  [annotate]

hide_src_code = true
show_total_period = true
  # perf annotate --stdio2 _raw_spin_lock | head -20
   → callq  __fentry__
 xor%eax,%eax
 mov$0x1,%edx
  1411316  152339lock   cmpxchg %edx,(%rdi)
   344694   0test   %eax,%eax
   ↓ jne16
80806   0repz   retq
   16:   mov%eax,%esi
   ↑ jmpq   810e96b0 

  #

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-nu4rxg5zkdtgs1b2gc40p...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/annotate.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index cfa641bc1df6..ea83b9754ab0 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -2243,9 +2243,7 @@ int symbol__tty_annotate2(struct symbol *sym, struct map 
*map,
 {
struct dso *dso = map->dso;
struct rb_root source_line = RB_ROOT;
-   struct annotation_options opts = {
-   .use_offset = true,
-   };
+   struct annotation_options opts = annotation__default_options;
 
if (symbol__annotate2(sym, map, evsel, &opts, NULL) < 0)
return -1;
-- 
2.14.3



[PATCH 28/44] perf annotate: Use a ops table for annotation_line__write()

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

To simplify the passing of arguments, the --stdio2 code will have to set
all the fields with operations printing to stdout.

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-pcs3c7vdy9ucygxflo4nl...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/annotate.c | 32 +++-
 tools/perf/util/annotate.c| 44 ---
 tools/perf/util/annotate.h| 19 ++---
 3 files changed, 53 insertions(+), 42 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index 2b18c462b882..bed647807d37 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -106,25 +106,29 @@ static void annotate_browser__write(struct ui_browser 
*browser, void *entry, int
struct annotate_browser *ab = container_of(browser, struct 
annotate_browser, b);
struct annotation *notes = browser__annotation(browser);
struct annotation_line *al = list_entry(entry, struct annotation_line, 
node);
-   bool current_entry = ui_browser__is_current_entry(browser, row);
-   bool change_color = (!notes->options->hide_src_code &&
-(!current_entry || (browser->use_navkeypressed &&
-!browser->navkeypressed)));
-   int width = browser->width;
+   struct annotation_write_ops ops = {
+   .first_line  = row == 0,
+   .current_entry   = 
ui_browser__is_current_entry(browser, row),
+   .change_color= (!notes->options->hide_src_code &&
+   (!ops.current_entry ||
+(browser->use_navkeypressed &&
+ !browser->navkeypressed))),
+   .width   = browser->width,
+   .obj = browser,
+   .set_color   = annotate_browser__set_color,
+   .set_percent_color   = annotate_browser__set_percent_color,
+   .set_jumps_percent_color = ui_browser__set_jumps_percent_color,
+   .printf  = annotate_browser__printf,
+   .write_graph = annotate_browser__write_graph,
+   };
 
/* The scroll bar isn't being used */
if (!browser->navkeypressed)
-   width += 1;
+   ops.width += 1;
 
-   annotation_line__write(al, notes, row == 0, current_entry, change_color,
-  width, browser,
-  annotate_browser__set_color,
-  annotate_browser__set_percent_color,
-  ui_browser__set_jumps_percent_color,
-  annotate_browser__printf,
-  annotate_browser__write_graph);
+   annotation_line__write(al, notes, &ops);
 
-   if (current_entry)
+   if (ops.current_entry)
ab->selection = al;
 }
 
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 45a52e2658c8..11ad73211538 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -34,10 +34,10 @@
  * FIXME: Using the same values as slang.h,
  * but that header may not be available everywhere
  */
-#define LARROW_CHAR0x1B
-#define RARROW_CHAR0x1A
-#define DARROW_CHAR0x19
-#define UARROW_CHAR0x18
+#define LARROW_CHAR((unsigned char)',')
+#define RARROW_CHAR((unsigned char)'+')
+#define DARROW_CHAR((unsigned char)'.')
+#define UARROW_CHAR((unsigned char)'-')
 
 #include "sane_ctype.h"
 
@@ -2210,12 +2210,6 @@ double annotation_line__max_percent(struct 
annotation_line *al, struct annotatio
return percent_max;
 }
 
-static void set_percent_color_stub(void *obj __maybe_unused,
-  double percent __maybe_unused,
-  bool current __maybe_unused)
-{
-}
-
 static void disasm_line__write(struct disasm_line *dl, struct annotation 
*notes,
   void *obj, char *bf, size_t size,
   void (*obj__printf)(void *obj, const char *fmt, 
...),
@@ -2243,14 +2237,15 @@ static void disasm_line__write(struct disasm_line *dl, 
struct annotation *notes,
disasm_line__scnprintf(dl, bf, size, !notes->options->use_offset);
 }
 
-void annotation_line__write(struct annotation_line *al, struct annotation 
*notes,
-   bool first_line, bool current_entry, bool 
change_color, int width,
-   void *obj,
-   int  (*obj__set_color)(void *obj, int color),
-   void (*obj__set_percent_color)(void *obj, double 
p

[PATCH 34/44] perf annotate: Introduce --ignore-vmlinux command line option

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

This is already present in 'perf top', albeit undocumented (will fix),
and is useful to use /proc/kcore instead of vmlinux and then get what is
really in place, not what the kernel starts with, before alternatives,
ftrace .text patching, etc, see the differences:

  # perf annotate --stdio2 _raw_spin_lock_irqsave
  _raw_spin_lock_irqsave() /lib/modules/4.16.0-rc4/build/vmlinux
  Event: anon group { cycles, instructions }

0.00   3.17  → callq  __fentry__
0.00   7.94push   %rbx
7.69  36.51  → callq  __page_file_index
   mov%rax,%rbx
7.69   3.17  → callq  *82225cd0
   xor%eax,%eax
   mov$0x1,%edx
   80.77  49.21lock   cmpxchg %edx,(%rdi)
   test   %eax,%eax
 ↓ jne2b
3.85   0.00mov%rbx,%rax
   pop%rbx
 ← retq
 2b:   mov%eax,%esi
 → callq  queued_spin_lock_slowpath
   mov%rbx,%rax
   pop%rbx
 ← retq
  [root@jouet ~]# perf annotate --ignore-vmlinux --stdio2 _raw_spin_lock_irqsave
  _raw_spin_lock_irqsave() /proc/kcore
  Event: anon group { cycles, instructions }

0.00   3.17nop
0.00   7.94push   %rbx
0.00  23.81pushfq
7.69  12.70pop%rax
   nop
   mov%rax,%rbx
7.69   3.17cli
   nop
   xor%eax,%eax
   mov$0x1,%edx
   80.77  49.21lock   cmpxchg %edx,(%rdi)
   test   %eax,%eax
 ↓ jne2b
3.85   0.00mov%rbx,%rax
   pop%rbx
 ← retq
 2b:   mov%eax,%esi
 → callq  *820e96b0
   mov%rbx,%rax
   pop%rbx
 ← retq
  #

Diff of the output of those commands:

  # perf annotate --stdio2 _raw_spin_lock_irqsave > /tmp/vmlinux
  # perf annotate --ignore-vmlinux --stdio2 _raw_spin_lock_irqsave > /tmp/kcore
  # diff -y /tmp/vmlinux /tmp/kcore
  _raw_spin_lock_irqsave() vmlinux | _raw_spin_lock_irqsave() 
/proc/kcore
  Event: anon group { cycles, instructions } Event: anon group { cycles, 
instructions }

   0.00  3.17  → callq __fentry__  |  0.00  3.17 nop
   0.00  7.94push  %rbx   0.00  7.94 push  %rbx
   7.69 36.51  → callq __page_file_index   |  0.00 23.81 pushfq
   >  7.69 12.70 pop   %rax
   > nop
 mov   %rax,%rbx mov   %rax,%rbx
   7.69  3.17  → callq *82225cd0   |  7.69  3.17 cli
   > nop
 xor   %eax,%eax xor   %eax,%eax
 mov   $0x1,%edx mov   $0x1,%edx
  80.77 49.21lock  cmpxchg %edx,(%rdi)   80.77 49.21 lock  cmpxchg 
%edx,(%rdi)
 test  %eax,%eax test  %eax,%eax
   ↓ jne   2b  ↓ jne   2b
   3.85  0.00mov   %rbx,%rax  3.85  0.00 mov   %rbx,%rax
 pop   %rbx  pop   %rbx
   ← retq  ← retq
2b:  mov   %eax,%esi2b:  mov   %eax,%esi
   → callq queued_spin_lock_slowpath|  → callq 
*820e96b0
 mov   %rbx,%rax mov   %rbx,%rax
 pop   %rbx  pop   %rbx
   ← retq  ← retq
  #

This should be further streamlined by doing both annotations and
allowing the TUI to toggle initial/current, and show the patched
instructions in a slightly different color.

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-wz8d269hxkcwaczr0r4rh...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-annotate.txt | 3 +++
 tools/perf/builtin-annotate.c  | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/tools/perf/Documentation/perf-annotate.txt 
b/tools/perf/Documentation/perf-annotate.txt
index c29c7fc93023..749cc6055dac 100644
--- a/tools/perf/Documentation/perf-annotate.txt
+++ b/tools/perf/Documentation/perf-annotate.txt
@@ -55,6 +55,9 @@ OPTIONS
 --vmlinux=::
 vmlinux pathname.
 
+--ignore-vmlinux::
+   Ign

[PATCH 37/44] perf annotate: No need to calculate notes->start twice

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

Since we already set notes->start to map__rip_2objdump(map, sym->start)
in symbol__annotate2(), no need to calculate that address again in
symbol__calc_lines(), just use notes->start.

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-ycxlg8mm5ueuj21w6gi62...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/annotate.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index a7111871440e..666f62c58e1a 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -2230,7 +2230,7 @@ void annotation__update_column_widths(struct annotation 
*notes)
 }
 
 static void annotation__calc_lines(struct annotation *notes, struct map *map,
- struct rb_root *root, u64 start)
+ struct rb_root *root)
 {
struct annotation_line *al;
struct rb_root tmp_root = RB_ROOT;
@@ -2251,8 +2251,8 @@ static void annotation__calc_lines(struct annotation 
*notes, struct map *map,
if (percent_max <= 0.5)
continue;
 
-   al->path = get_srcline(map->dso, start + al->offset, NULL,
-  false, true, start + al->offset);
+   al->path = get_srcline(map->dso, notes->start + al->offset, 
NULL,
+  false, true, notes->start + al->offset);
insert_source_line(&tmp_root, al);
}
 
@@ -2263,9 +2263,8 @@ static void symbol__calc_lines(struct symbol *sym, struct 
map *map,
  struct rb_root *root)
 {
struct annotation *notes = symbol__annotation(sym);
-   u64 start = map__rip_2objdump(map, sym->start);
 
-   annotation__calc_lines(notes, map, root, start);
+   annotation__calc_lines(notes, map, root);
 }
 
 int symbol__tty_annotate2(struct symbol *sym, struct map *map,
-- 
2.14.3



[PATCH 40/44] perf python: Reference Py_None before returning it

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Petr Machata 

Python None objects are handled just like all the other objects with
respect to their reference counting. Before returning Py_None, its
reference count thus needs to be bumped.

Signed-off-by: Petr Machata 
Acked-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Petr Machata 
Link: 
http://lkml.kernel.org/r/b1e565ecccf68064d8d54f37db5d028dda8fa522.1521675563.git.pe...@mellanox.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/python.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index b956868fd445..863b61478edd 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -1004,8 +1004,10 @@ static PyObject *pyrf_evlist__read_on_cpu(struct 
pyrf_evlist *pevlist,
return PyErr_NoMemory();
 
evsel = perf_evlist__event2evsel(evlist, event);
-   if (!evsel)
+   if (!evsel) {
+   Py_INCREF(Py_None);
return Py_None;
+   }
 
pevent->evsel = evsel;
 
-- 
2.14.3



[PATCH 0/4] staging: iio: tsl2x7x: move out of staging

2018-03-24 Thread Brian Masney
Here is a patch series to move the tsl2x7x driver out of staging and
into mainline. Driver was tested using various TSL2X7X devices on a
Raspberry Pi 2.

Datasheet for the TSl2772:
https://ams.com/eng/content/download/291503/1066377/file/TSL2772_DS000181_2-00.pdf

Brian Masney (4):
  staging: iio: tsl2x7x: use auto increment I2C protocol
  staging: iio: tsl2x7x: move IIO_CHAN_INFO_CALIB{SCALE,BIAS} to
IIO_LIGHT channel
  staging: iio: tsl2x7x: use either direction for
IIO_EV_INFO_{ENABLE,PERIOD}
  staging: iio: tsl2x7x: move out of staging

 drivers/iio/light/Kconfig  |   8 ++
 drivers/iio/light/Makefile |   1 +
 drivers/{staging => }/iio/light/tsl2x7x.c  | 135 +
 drivers/staging/iio/Kconfig|   1 -
 drivers/staging/iio/Makefile   |   1 -
 drivers/staging/iio/light/Kconfig  |  14 ---
 drivers/staging/iio/light/Makefile |   5 -
 .../linux/platform_data}/tsl2x7x.h |   0
 8 files changed, 93 insertions(+), 72 deletions(-)
 rename drivers/{staging => }/iio/light/tsl2x7x.c (95%)
 delete mode 100644 drivers/staging/iio/light/Kconfig
 delete mode 100644 drivers/staging/iio/light/Makefile
 rename {drivers/staging/iio/light => include/linux/platform_data}/tsl2x7x.h 
(100%)

-- 
2.14.3



[PATCH 4/4] staging: iio: tsl2x7x: move out of staging

2018-03-24 Thread Brian Masney
Move the tsl2x7x driver out of staging and into mainline.

Signed-off-by: Brian Masney 
---
Note: I intentionally ran git format-patch with --no-renames since
Jonathan likes to see the whole files in the email body for staging
graduation patches.

The #include "tsl2x7x.h" was changed to #include
 in tsl2x7x.c during the rename.

 drivers/iio/light/Kconfig |8 +
 drivers/iio/light/Makefile|1 +
 drivers/iio/light/tsl2x7x.c   | 1784 +
 drivers/staging/iio/Kconfig   |1 -
 drivers/staging/iio/Makefile  |1 -
 drivers/staging/iio/light/Kconfig |   14 -
 drivers/staging/iio/light/Makefile|5 -
 drivers/staging/iio/light/tsl2x7x.c   | 1784 -
 drivers/staging/iio/light/tsl2x7x.h   |  103 --
 include/linux/platform_data/tsl2x7x.h |  103 ++
 10 files changed, 1896 insertions(+), 1908 deletions(-)
 create mode 100644 drivers/iio/light/tsl2x7x.c
 delete mode 100644 drivers/staging/iio/light/Kconfig
 delete mode 100644 drivers/staging/iio/light/Makefile
 delete mode 100644 drivers/staging/iio/light/tsl2x7x.c
 delete mode 100644 drivers/staging/iio/light/tsl2x7x.h
 create mode 100644 include/linux/platform_data/tsl2x7x.h

diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
index 074e50657366..8161e3e1ba1b 100644
--- a/drivers/iio/light/Kconfig
+++ b/drivers/iio/light/Kconfig
@@ -409,6 +409,14 @@ config TSL2583
 Provides support for the TAOS tsl2580, tsl2581 and tsl2583 devices.
 Access ALS data via iio, sysfs.
 
+config TSL2x7x
+   tristate "TAOS TSL/TMD2x71 and TSL/TMD2x72 Family of light and 
proximity sensors"
+   depends on I2C
+   help
+Support for: tsl2571, tsl2671, tmd2671, tsl2771, tmd2771, tsl2572, 
tsl2672,
+tmd2672, tsl2772, tmd2772 devices.
+Provides iio_events and direct access via sysfs.
+
 config TSL4531
tristate "TAOS TSL4531 ambient light sensors"
depends on I2C
diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile
index f1777036d4f8..a20a3662950b 100644
--- a/drivers/iio/light/Makefile
+++ b/drivers/iio/light/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_ST_UVIS25_SPI)   += st_uvis25_spi.o
 obj-$(CONFIG_TCS3414)  += tcs3414.o
 obj-$(CONFIG_TCS3472)  += tcs3472.o
 obj-$(CONFIG_TSL2583)  += tsl2583.o
+obj-$(CONFIG_TSL2x7x)  += tsl2x7x.o
 obj-$(CONFIG_TSL4531)  += tsl4531.o
 obj-$(CONFIG_US5182D)  += us5182d.o
 obj-$(CONFIG_VCNL4000) += vcnl4000.o
diff --git a/drivers/iio/light/tsl2x7x.c b/drivers/iio/light/tsl2x7x.c
new file mode 100644
index ..fffd23ae5c72
--- /dev/null
+++ b/drivers/iio/light/tsl2x7x.c
@@ -0,0 +1,1784 @@
+/*
+ * Device driver for monitoring ambient light intensity in (lux)
+ * and proximity detection (prox) within the TAOS TSL2X7X family of devices.
+ *
+ * Copyright (c) 2012, TAOS Corporation.
+ * Copyright (c) 2017-2018 Brian Masney 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Cal defs*/
+#define PROX_STAT_CAL  0
+#define PROX_STAT_SAMP 1
+#define MAX_SAMPLES_CAL200
+
+/* TSL2X7X Device ID */
+#define TRITON_ID  0x00
+#define SWORDFISH_ID   0x30
+#define HALIBUT_ID 0x20
+
+/* Lux calculation constants */
+#define TSL2X7X_LUX_CALC_OVER_FLOW 65535
+
+/* TAOS Register definitions - note:
+ * depending on device, some of these register are not used and the
+ * register address is benign.
+ */
+/* 2X7X register offsets */
+#define TSL2X7X_MAX_CONFIG_REG 16
+
+/* Device Registers and Masks */
+#define TSL2X7X_CNTRL  0x00
+#define TSL2X7X_ALS_TIME   0X01
+#define TSL2X7X_PRX_TIME   0x02
+#define TSL2X7X_WAIT_TIME  0x03
+#define TSL2X7X_ALS_MINTHRESHLO0X04
+#define TSL2X7X_ALS_MINTHRESHHI0X05
+#define TSL2X7X_ALS_MAXTHRESHLO0X06
+#define TSL2X7X_ALS_MAXTHRESHHI0X07
+#define TSL2X7X_PRX_MINTHRESHLO0X08
+#define TSL2X7X_PRX_MINTHRESHHI0X09
+#define TSL2X7X_PRX_MAXTHRESHLO0X0A
+#define TSL2X7X_PRX_MAXTHRESHHI0X0B
+#define TSL2X7X_PERSISTENCE0x0C
+#define TSL2X7X_PRX_CONFIG 0x0D
+

[PATCH 2/4] staging: iio: tsl2x7x: move IIO_CHAN_INFO_CALIB{SCALE,BIAS} to IIO_LIGHT channel

2018-03-24 Thread Brian Masney
The IIO_CHAN_INFO_CALIBSCALE and IIO_CHAN_INFO_CALIBBIAS masks are
currently associated with the IIO_INTENSITY channel but should be
associated with the IIO_LIGHT channel since these values are used to
calculate the lux. Directory listing of the sysfs attributes for a
TSL2772 with this patch applied:

dev
events
in_illuminance0_calibbias
in_illuminance0_calibrate
in_illuminance0_calibscale
in_illuminance0_calibscale_available
in_illuminance0_input
in_illuminance0_integration_time
in_illuminance0_integration_time_available
in_illuminance0_lux_table
in_illuminance0_target_input
in_intensity0_raw
in_intensity1_raw
in_proximity0_calibrate
in_proximity0_calibscale
in_proximity0_calibscale_available
in_proximity0_raw
name
of_node
power
subsystem
uevent

Signed-off-by: Brian Masney 
---
 drivers/staging/iio/light/tsl2x7x.c | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2x7x.c 
b/drivers/staging/iio/light/tsl2x7x.c
index 8530bccdb317..d5a237fb0a0b 100644
--- a/drivers/staging/iio/light/tsl2x7x.c
+++ b/drivers/staging/iio/light/tsl2x7x.c
@@ -1491,14 +1491,14 @@ static const struct tsl2x7x_chip_info 
tsl2x7x_chip_info_tbl[] = {
.indexed = 1,
.channel = 0,
.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
- BIT(IIO_CHAN_INFO_INT_TIME),
+   BIT(IIO_CHAN_INFO_INT_TIME) |
+   BIT(IIO_CHAN_INFO_CALIBSCALE) |
+   BIT(IIO_CHAN_INFO_CALIBBIAS),
}, {
.type = IIO_INTENSITY,
.indexed = 1,
.channel = 0,
-   .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
-   BIT(IIO_CHAN_INFO_CALIBSCALE) |
-   BIT(IIO_CHAN_INFO_CALIBBIAS),
+   .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.event_spec = tsl2x7x_events,
.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
}, {
@@ -1531,14 +1531,14 @@ static const struct tsl2x7x_chip_info 
tsl2x7x_chip_info_tbl[] = {
.indexed = 1,
.channel = 0,
.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
- BIT(IIO_CHAN_INFO_INT_TIME),
+   BIT(IIO_CHAN_INFO_INT_TIME) |
+   BIT(IIO_CHAN_INFO_CALIBSCALE) |
+   BIT(IIO_CHAN_INFO_CALIBBIAS),
}, {
.type = IIO_INTENSITY,
.indexed = 1,
.channel = 0,
-   .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
-   BIT(IIO_CHAN_INFO_CALIBSCALE) |
-   BIT(IIO_CHAN_INFO_CALIBBIAS),
+   .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.event_spec = tsl2x7x_events,
.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
}, {
@@ -1580,14 +1580,14 @@ static const struct tsl2x7x_chip_info 
tsl2x7x_chip_info_tbl[] = {
.indexed = 1,
.channel = 0,
.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
- BIT(IIO_CHAN_INFO_INT_TIME),
+   BIT(IIO_CHAN_INFO_INT_TIME) |
+   BIT(IIO_CHAN_INFO_CALIBSCALE) |
+   BIT(IIO_CHAN_INFO_CALIBBIAS),
}, {
.type = IIO_INTENSITY,
.indexed = 1,
.channel = 0,
-   .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
-   BIT(IIO_CHAN_INFO_CALIBSCALE) |
-   BIT(IIO_CHAN_INFO_CALIBBIAS),
+   .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.event_spec = tsl2x7x_events,
.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
}, {
-- 
2.14.3



[PATCH 41/44] perf annotate: Add "_local" to jump/offset validation routines

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

Because they all really check if we can access data structures/visual
constructs where a "jump" instruction targets code in the same function,
i.e. things like:

  __pthread_mutex_lock  /usr/lib64/libpthread-2.26.so
  1.95 │   mov__pthread_force_elision,%ecx
   │┌──test   %ecx,%ecx
  0.07 │├──je 60
   ││  test   $0x300,%esi
   ││↓ jne60
   ││  or $0x100,%esi
   ││  mov%esi,0x10(%rdi)
   │ 42:│  mov%esi,%edx
   ││  lea0x16(%r8),%rsi
   ││  mov%r8,%rdi
   ││  and$0x80,%edx
   ││  add$0x8,%rsp
   ││→ jmpq   __lll_lock_elision
   ││  nop
  0.29 │ 60:└─→and$0x80,%esi
  0.07 │   mov$0x1,%edi
  0.29 │   xor%eax,%eax
  2.53 │   lock   cmpxchg %edi,(%r8)

And not things like that "jmpq __lll_lock_elision", that instead should behave
like a "call" instruction and "jump" to the disassembly of 
"___lll_lock_elision".

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-3cwx39u3h66dfw9xjrlt7...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/annotate.c |  2 +-
 tools/perf/util/annotate.c|  9 -
 tools/perf/util/annotate.h| 14 +++---
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index 3834b264ba41..d77896a99570 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -155,7 +155,7 @@ static void annotate_browser__draw_current_jump(struct 
ui_browser *browser)
if (strstr(sym->name, "@plt"))
return;
 
-   if (!disasm_line__is_valid_jump(cursor, sym))
+   if (!disasm_line__is_valid_local_jump(cursor, sym))
return;
 
/*
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index c299881c640a..9524f322f597 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1409,7 +1409,7 @@ static int symbol__parse_objdump_line(struct symbol *sym, 
FILE *file,
if (dl == NULL)
return -1;
 
-   if (!disasm_line__has_offset(dl)) {
+   if (!disasm_line__has_local_offset(dl)) {
dl->ops.target.offset = dl->ops.target.addr -
map__rip_2objdump(map, sym->start);
dl->ops.target.offset_avail = true;
@@ -2176,11 +2176,10 @@ size_t disasm__fprintf(struct list_head *head, FILE *fp)
return printed;
 }
 
-
-bool disasm_line__is_valid_jump(struct disasm_line *dl, struct symbol *sym)
+bool disasm_line__is_valid_local_jump(struct disasm_line *dl, struct symbol 
*sym)
 {
if (!dl || !dl->ins.ops || !ins__is_jump(&dl->ins) ||
-   !disasm_line__has_offset(dl) || dl->ops.target.offset < 0 ||
+   !disasm_line__has_local_offset(dl) || dl->ops.target.offset < 0 ||
dl->ops.target.offset >= (s64)symbol__size(sym))
return false;
 
@@ -2201,7 +2200,7 @@ void annotation__mark_jump_targets(struct annotation 
*notes, struct symbol *sym)
 
dl = disasm_line(al);
 
-   if (!disasm_line__is_valid_jump(dl, sym))
+   if (!disasm_line__is_valid_local_jump(dl, sym))
continue;
 
al = notes->offsets[dl->ops.target.offset];
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index ad8baafaf9f9..ff7e3df31efa 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -117,12 +117,20 @@ static inline struct disasm_line *disasm_line(struct 
annotation_line *al)
return al ? container_of(al, struct disasm_line, al) : NULL;
 }
 
-static inline bool disasm_line__has_offset(const struct disasm_line *dl)
+/*
+ * Is this offset in the same function as the line it is used?
+ * asm functions jump to other functions, for instance.
+ */
+static inline bool disasm_line__has_local_offset(const struct disasm_line *dl)
 {
-   return dl->ops.target.offset_avail;
+   return dl->ops.target.offset_avail && !dl->ops.target.outside;
 }
 
-bool disasm_line__is_valid_jump(struct disasm_line *dl, struct symbol *sym);
+/*
+ * Can we draw an arrow from the jump to its target, for instance? I.e.
+ * is the jump and its target in the same function?
+ */
+bool disasm_line__is_valid_local_jump(struct disasm_line *dl, struct symbol 
*sym);
 
 void disasm_line__free(struct disasm_line *dl);
 struct annotation_line *
-- 
2.14.3



[PATCH 1/4] staging: iio: tsl2x7x: use auto increment I2C protocol

2018-03-24 Thread Brian Masney
The hardware supports 16-bit ALS and proximity readings, however the
datasheet recommends using the I2C auto increment protocol so that the
correct high and low bytes are read even if the integration cycle ends
between reading the lower and upper registers. More information about
this protocol can be found at https://www.i2c-bus.org/auto-increment/.

Signed-off-by: Brian Masney 
---
 drivers/staging/iio/light/tsl2x7x.c | 100 
 1 file changed, 67 insertions(+), 33 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2x7x.c 
b/drivers/staging/iio/light/tsl2x7x.c
index 77a81d75af4f..8530bccdb317 100644
--- a/drivers/staging/iio/light/tsl2x7x.c
+++ b/drivers/staging/iio/light/tsl2x7x.c
@@ -80,6 +80,8 @@
 /* tsl2X7X cmd reg masks */
 #define TSL2X7X_CMD_REG0x80
 #define TSL2X7X_CMD_SPL_FN 0x60
+#define TSL2X7X_CMD_REPEAT_PROTO   0x00
+#define TSL2X7X_CMD_AUTOINC_PROTO  0x20
 
 #define TSL2X7X_CMD_PROX_INT_CLR   0X05
 #define TSL2X7X_CMD_ALS_INT_CLR0x06
@@ -320,6 +322,55 @@ static int tsl2x7x_write_control_reg(struct tsl2X7X_chip 
*chip, u8 data)
return ret;
 }
 
+static int tsl2x7x_read_autoinc_regs(struct tsl2X7X_chip *chip, int lower_reg,
+int upper_reg)
+{
+   u8 buf[2];
+   int ret;
+
+   ret = i2c_smbus_write_byte(chip->client,
+  TSL2X7X_CMD_REG | TSL2X7X_CMD_AUTOINC_PROTO |
+  lower_reg);
+   if (ret < 0) {
+   dev_err(&chip->client->dev,
+   "%s: failed to enable auto increment protocol: %d\n",
+   __func__, ret);
+   return ret;
+   }
+
+   ret = i2c_smbus_read_byte_data(chip->client,
+  TSL2X7X_CMD_REG | lower_reg);
+   if (ret < 0) {
+   dev_err(&chip->client->dev,
+   "%s: failed to read from register %x: %d\n", __func__,
+   lower_reg, ret);
+   return ret;
+   }
+   buf[0] = ret;
+
+   ret = i2c_smbus_read_byte_data(chip->client,
+  TSL2X7X_CMD_REG | upper_reg);
+   if (ret < 0) {
+   dev_err(&chip->client->dev,
+   "%s: failed to read from register %x: %d\n", __func__,
+   upper_reg, ret);
+   return ret;
+   }
+   buf[1] = ret;
+
+   ret = i2c_smbus_write_byte(chip->client,
+  TSL2X7X_CMD_REG | TSL2X7X_CMD_REPEAT_PROTO |
+  lower_reg);
+   if (ret < 0) {
+   dev_err(&chip->client->dev,
+   "%s: failed to enable repeated byte protocol: %d\n",
+   __func__, ret);
+   return ret;
+   }
+
+   return le16_to_cpup((const __le16 *)&buf[0]);
+}
+
 /**
  * tsl2x7x_get_lux() - Reads and calculates current lux value.
  * @indio_dev: pointer to IIO device
@@ -340,9 +391,8 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
struct tsl2X7X_chip *chip = iio_priv(indio_dev);
struct tsl2x7x_lux *p;
u32 lux, ratio;
-   int i, ret;
u64 lux64;
-   u8 buf[4];
+   int ret;
 
mutex_lock(&chip->als_mutex);
 
@@ -366,23 +416,17 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
goto out_unlock;
}
 
-   for (i = 0; i < 4; i++) {
-   int reg = TSL2X7X_CMD_REG | (TSL2X7X_ALS_CHAN0LO + i);
-
-   ret = i2c_smbus_read_byte_data(chip->client, reg);
-   if (ret < 0) {
-   dev_err(&chip->client->dev,
-   "%s: failed to read from register %x: %d\n",
-   __func__, reg, ret);
-   goto out_unlock;
-   }
-
-   buf[i] = ret;
-   }
+   ret = tsl2x7x_read_autoinc_regs(chip, TSL2X7X_ALS_CHAN0LO,
+   TSL2X7X_ALS_CHAN0HI);
+   if (ret < 0)
+   goto out_unlock;
+   chip->als_cur_info.als_ch0 = ret;
 
-   /* extract ALS/lux data */
-   chip->als_cur_info.als_ch0 = le16_to_cpup((const __le16 *)&buf[0]);
-   chip->als_cur_info.als_ch1 = le16_to_cpup((const __le16 *)&buf[2]);
+   ret = tsl2x7x_read_autoinc_regs(chip, TSL2X7X_ALS_CHAN1LO,
+   TSL2X7X_ALS_CHAN1HI);
+   if (ret < 0)
+   goto out_unlock;
+   chip->als_cur_info.als_ch1 = ret;
 
if (chip->als_cur_info.als_ch0 >= chip->als_saturation ||
chip->als_cur_info.als_ch1 >= chip->als_saturation) {
@@ -456,10 +500,8 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
  */
 static int tsl2x7x_get_prox(struct iio_dev *indio_dev)
 {
-   int i;
-   int ret;
-   u8 chdata[2];
struct tsl2X7X_chip *chip = iio_priv(indio_de

[PATCH 3/4] staging: iio: tsl2x7x: use either direction for IIO_EV_INFO_{ENABLE,PERIOD}

2018-03-24 Thread Brian Masney
The events IIO_EV_INFO_VALUE and IIO_EV_INFO_ENABLE currently have a
falling and rising direction configured. There does not need to be a
separate distinction so this patch changes these to use the
either direction. Directory listing of event sysfs attributes for a
TSL2772 with this patch applied:

in_intensity0_thresh_either_en
in_intensity0_thresh_either_period
in_intensity0_thresh_falling_value
in_intensity0_thresh_rising_value
in_proximity0_thresh_either_en
in_proximity0_thresh_either_period
in_proximity0_thresh_falling_value
in_proximity0_thresh_rising_value

Signed-off-by: Brian Masney 
---
 drivers/staging/iio/light/tsl2x7x.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2x7x.c 
b/drivers/staging/iio/light/tsl2x7x.c
index d5a237fb0a0b..940bea2378a9 100644
--- a/drivers/staging/iio/light/tsl2x7x.c
+++ b/drivers/staging/iio/light/tsl2x7x.c
@@ -1469,17 +1469,16 @@ static const struct iio_event_spec tsl2x7x_events[] = {
{
.type = IIO_EV_TYPE_THRESH,
.dir = IIO_EV_DIR_RISING,
-   .mask_separate = BIT(IIO_EV_INFO_VALUE) |
-   BIT(IIO_EV_INFO_ENABLE),
+   .mask_separate = BIT(IIO_EV_INFO_VALUE),
}, {
.type = IIO_EV_TYPE_THRESH,
.dir = IIO_EV_DIR_FALLING,
-   .mask_separate = BIT(IIO_EV_INFO_VALUE) |
-   BIT(IIO_EV_INFO_ENABLE),
+   .mask_separate = BIT(IIO_EV_INFO_VALUE),
}, {
.type = IIO_EV_TYPE_THRESH,
.dir = IIO_EV_DIR_EITHER,
-   .mask_separate = BIT(IIO_EV_INFO_PERIOD),
+   .mask_separate = BIT(IIO_EV_INFO_PERIOD) |
+   BIT(IIO_EV_INFO_ENABLE),
},
 };
 
-- 
2.14.3



[PATCH 43/44] perf annotate: Defer searching for comma in raw line till it is needed

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

That strchr() in jump__scnprintf() needs to be nuked somehow, as it,
IIRC is already done in jump__parse() and if needed at scnprintf() time,
should be stashed in the struct filled in parse() time.

For now jus defer it to just before where it is used.

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-j0t5hagnphoz9xw07bh3h...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/annotate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 5fa270b24eea..f730e0cf8a26 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -350,7 +350,7 @@ static int jump__parse(struct arch *arch __maybe_unused, 
struct ins_operands *op
 static int jump__scnprintf(struct ins *ins, char *bf, size_t size,
   struct ins_operands *ops)
 {
-   const char *c = strchr(ops->raw, ',');
+   const char *c;
 
if (!ops->target.addr || ops->target.offset < 0)
return ins__raw_scnprintf(ins, bf, size, ops);
@@ -358,6 +358,7 @@ static int jump__scnprintf(struct ins *ins, char *bf, 
size_t size,
if (ops->target.outside && ops->target.sym != NULL)
return scnprintf(bf, size, "%-6s %s", ins->name, 
ops->target.sym->name);
 
+   c = strchr(ops->raw, ',');
if (c != NULL) {
const char *c2 = strchr(c + 1, ',');
 
-- 
2.14.3



[PATCH 44/44] perf annotate: Use absolute addresses to calculate jump target offsets

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

These types of jumps were confusing the annotate browser:

entry_SYSCALL_64  /lib/modules/4.16.0-rc5-00086-gdf09348f78dc/build/vmlinux

entry_SYSCALL_64  /lib/modules/4.16.0-rc5-00086-gdf09348f78dc/build/vmlinux
  Percent│81a00020:   swapgs
  
 │81a00128: ↓ jae81a00139 

  
 │81a00155: → jmpq   *0x825d2d(%rip)   # 82225e88 


I.e. the syscall_return_via_sysret function is actually "inside" the
entry_SYSCALL_64 function, and the offsets in jumps like these (+0x53)
are relative to syscall_return_via_sysret, not to syscall_return_via_sysret.

Or this may be some artifact in how the assembler marks the start and
end of a function and how this ends up in the ELF symtab for vmlinux,
i.e. syscall_return_via_sysret() isn't "inside" entry_SYSCALL_64, but
just right after it.

>From readelf -sw vmlinux:

 80267: 81a00020   315 NOTYPE  GLOBAL DEFAULT1 entry_SYSCALL_64
   316: 81a000e6 0 NOTYPE  LOCAL  DEFAULT1 
syscall_return_via_sysret

 0x81a00020 + 315 > 0x81a000e6

So instead of looking for offsets after that last '+' sign, calculate
offsets for jump target addresses that are inside the function being
disassembled from the absolute address, 0x81a00139 in this case,
subtracting from it the objdump address for the start of the function
being disassembled, entry_SYSCALL_64() in this case.

So, before this patch:

entry_SYSCALL_64  /lib/modules/4.16.0-rc5-00086-gdf09348f78dc/build/vmlinux
Percent│   pop%r10
   │   pop%r9
   │   pop%r8
   │   pop%rax
   │   pop%rsi
   │   pop%rdx
   │   pop%rsi
   │   mov%rsp,%rdi
   │   mov%gs:0x5004,%rsp
   │   pushq  0x28(%rdi)
   │   pushq  (%rdi)
   │   push   %rax
   │ ↑ jmp6c
   │   mov%cr3,%rdi
   │ ↑ jmp62
   │   mov%rdi,%rax
   │   and$0x7ff,%rdi
   │   bt %rdi,%gs:0x2219a
   │ ↑ jae53
   │   btr%rdi,%gs:0x2219a
   │   mov%rax,%rdi
   │ ↑ jmp5b

After:

entry_SYSCALL_64  /lib/modules/4.16.0-rc5-00086-gdf09348f78dc/build/vmlinux
  0.65 │ → jneswapgs_restore_regs_and_return_to_usermode
   │   pop%r10
   │   pop%r9
   │   pop%r8
   │   pop%rax
   │   pop%rsi
   │   pop%rdx
   │   pop%rsi
   │   mov%rsp,%rdi
   │   mov%gs:0x5004,%rsp
   │   pushq  0x28(%rdi)
   │   pushq  (%rdi)
   │   push   %rax
   │ ↓ jmp132
   │   mov%cr3,%rdi
   │┌──jmp128
   ││  mov%rdi,%rax
   ││  and$0x7ff,%rdi
   ││  bt %rdi,%gs:0x2219a
   ││↓ jae119
   ││  btr%rdi,%gs:0x2219a
   ││  mov%rax,%rdi
   ││↓ jmp121
   │119:│  mov%rax,%rdi
   ││  bts$0x3f,%rdi
   │121:│  or $0x800,%rdi
   │128:└─→or $0x1000,%rdi
   │   mov%rdi,%cr3
   │132:   pop%rax
   │   pop%rdi
   │   pop%rsp
   │ → jmpq   *0x825d2d(%rip)# 82225e88 


With those at least navigating to the right destination, an improvement
for these cases seems to be to be to somehow mark those inner functions,
which in this case could be:

entry_SYSCALL_64  /lib/modules/4.16.0-rc5-00086-gdf09348f78dc/build/vmlinux
   │syscall_return_via_sysret:
   │   pop%r15
   │   pop%r14
   │   pop%r13
   │   pop%r12
   │   pop%rbp
   │   pop%rbx
   │   pop%rsi
   │   pop%r10
   │   pop%r9
   │   pop%r8
   │   pop%rax
   │   pop%rsi
   │   pop%rdx
   │   pop%rsi
   │   mov%rsp,%rdi
   │   mov%gs:0x5004,%rsp
   │   pushq  0x28(%rdi)
   │   pushq  (%rdi)
   │   push   %rax
   │ ↓ jmp132
   │   mov%cr3,%rdi
   │┌──jmp128
   ││  mov%rdi,%rax
   ││  and$0x7ff,%rdi
   ││  bt %rdi,%gs:0x2219a
   ││↓ jae119
   ││  btr%rdi,%gs:0x2219a
   ││  mov%rax,%rdi
   ││↓ jmp121
   │119:│  mov%rax,%rdi
   ││  bts$0x3f,%rdi
   │121:│  or $0x800,%rdi
   │128:└─→or $0x1000,%rdi
   │   mov%rdi,%cr3
   │132:   pop%rax
   │   pop%rdi
   │   pop%rsp
   │ → jmpq   *0x825d2d(%rip)# 82225e88 


This all gets much better viewed if one uses 'perf report --ignore-vmlinux'
forcing the usage of /proc/kcore + /proc/kallsyms, when the above
actually gets down to:

  # perf report --ignore-vmlinux
  ## do '/64', will show the fu

[PATCH 39/44] perf annotate: Mark jumps to outher functions with the call arrow

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

Things like this in _cpp_lex_token (gcc's cc1 program):

 cpp_named_operator2name@@Base+0xa72

Point to a place that is after the cpp_named_operator2name boundaries,
i.e.  in the ELF symbol table for cc1 cpp_named_operator2name is marked
as being 32-bytes long, but it in fact is much larger than that, so we
seem to need a symbols__find() routine that looks for >= current->start
and  < next_symbol->start, possibly just for C++ objects?

For now lets just make some progress by marking jumps to outside the
current function as call like.

Actual navigation will come next, with further understanding of how the
symbol searching and disassembly should be done.

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-aiys0a0bsgm3e00hbi6fg...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/annotate.c | 55 +++---
 tools/perf/util/annotate.h |  1 +
 2 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 3ff829d89178..c299881c640a 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -273,11 +273,27 @@ bool ins__is_call(const struct ins *ins)
return ins->ops == &call_ops || ins->ops == &s390_call_ops;
 }
 
-static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands 
*ops, struct map_symbol *ms __maybe_unused)
+static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands 
*ops, struct map_symbol *ms)
 {
+   struct map *map = ms->map;
+   struct symbol *sym = ms->sym;
+   struct addr_map_symbol target = {
+   .map = map,
+   };
const char *s = strchr(ops->raw, '+');
const char *c = strchr(ops->raw, ',');
-
+   u64 start, end;
+   /*
+* Examples of lines to parse for the _cpp_lex_token@@Base
+* function:
+*
+* 1159e6c: jne115aa32 <_cpp_lex_token@@Base+0xf92>
+* 1159e8b: jnec469be 
+*
+* The first is a jump to an offset inside the same function,
+* the second is to another function, i.e. that 0xa72 is an
+* offset in the cpp_named_operator2name@@base function.
+*/
/*
 * skip over possible up to 2 operands to get to address, e.g.:
 * tbnz  w0, #26, 083cd190 
@@ -293,6 +309,35 @@ static int jump__parse(struct arch *arch __maybe_unused, 
struct ins_operands *op
ops->target.addr = strtoull(ops->raw, NULL, 16);
}
 
+   target.addr = map__objdump_2mem(map, ops->target.addr);
+   start = map->unmap_ip(map, sym->start),
+   end = map->unmap_ip(map, sym->end);
+
+   ops->target.outside = target.addr < start || target.addr > end;
+
+   /*
+* FIXME: things like this in _cpp_lex_token (gcc's cc1 program):
+
+   cpp_named_operator2name@@Base+0xa72
+
+* Point to a place that is after the cpp_named_operator2name
+* boundaries, i.e.  in the ELF symbol table for cc1
+* cpp_named_operator2name is marked as being 32-bytes long, but it in
+* fact is much larger than that, so we seem to need a symbols__find()
+* routine that looks for >= current->start and  < next_symbol->start,
+* possibly just for C++ objects?
+*
+* For now lets just make some progress by marking jumps to outside the
+* current function as call like.
+*
+* Actual navigation will come next, with further understanding of how
+* the symbol searching and disassembly should be done.
+
+   if (map_groups__find_ams(&target) == 0 &&
+   map__rip_2objdump(target.map, map->map_ip(target.map, target.addr)) 
== ops->target.addr)
+   ops->target.sym = target.sym;
+*/
+
if (s++ != NULL) {
ops->target.offset = strtoull(s, NULL, 16);
ops->target.offset_avail = true;
@@ -2355,11 +2400,15 @@ static void disasm_line__write(struct disasm_line *dl, 
struct annotation *notes,
 {
if (dl->ins.ops && dl->ins.ops->scnprintf) {
if (ins__is_jump(&dl->ins)) {
-   bool fwd = dl->ops.target.offset > dl->al.offset;
+   bool fwd;
 
+   if (dl->ops.target.outside)
+   goto call_like;
+   fwd = dl->ops.target.offset > dl->al.offset;
obj__write_graph(obj, fwd ? DARROW_CHAR : UARROW_CHAR);
obj__printf(obj, " ");
} else if (ins__is_call(&dl->ins)) {
+call_like:
obj__write_graph(obj, RARROW_CHAR);
obj__printf(obj, " ");
} else if (ins__is_ret(&dl->ins)) {
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index c0bf0

[PATCH 42/44] perf annotate: Support jumping from one function to another

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

For instance:

  entry_SYSCALL_64  /lib/modules/4.16.0-rc5-00086-gdf09348f78dc/build/vmlinux
5.50 │ → callq  do_syscall_64
   14.56 │   mov0x58(%rsp),%rcx
7.44 │   mov0x80(%rsp),%r11
0.32 │   cmp%rcx,%r11
 │ → jneswapgs_restore_regs_and_return_to_usermode
0.32 │   shl$0x10,%rcx
0.32 │   sar$0x10,%rcx
3.24 │   cmp%rcx,%r11
 │ → jneswapgs_restore_regs_and_return_to_usermode
2.27 │   cmpq   $0x33,0x88(%rsp)
1.29 │ → jneswapgs_restore_regs_and_return_to_usermode
 │   mov0x30(%rsp),%r11
8.74 │   cmp%r11,0x90(%rsp)
 │ → jneswapgs_restore_regs_and_return_to_usermode
0.32 │   test   $0x10100,%r11
 │ → jneswapgs_restore_regs_and_return_to_usermode
0.32 │   cmpq   $0x2b,0xa0(%rsp)
0.65 │ → jneswapgs_restore_regs_and_return_to_usermode

It'll behave just like a "call" instruction, i.e. press enter or right
arrow over one such line and the browser will navigate to the annotated
disassembly of that function, which when exited, via left arrow or esc,
will come back to the calling function.

Now to support jump to an offset on a different function...

Reported-by: Linus Torvalds 
Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-78o508mqvr8inhj63ddtw...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/annotate.c | 23 ++-
 tools/perf/util/annotate.c|  6 --
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index d77896a99570..c02fb437ac8e 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -384,6 +384,15 @@ static int sym_title(struct symbol *sym, struct map *map, 
char *title,
return snprintf(title, sz, "%s  %s", sym->name, map->dso->long_name);
 }
 
+/*
+ * This can be called from external jumps, i.e. jumps from one functon
+ * to another, like from the kernel's entry_SYSCALL_64 function to the
+ * swapgs_restore_regs_and_return_to_usermode() function.
+ *
+ * So all we check here is that dl->ops.target.sym is set, if it is, just
+ * go to that function and when exiting from its disassembly, come back
+ * to the calling function.
+ */
 static bool annotate_browser__callq(struct annotate_browser *browser,
struct perf_evsel *evsel,
struct hist_browser_timer *hbt)
@@ -393,9 +402,6 @@ static bool annotate_browser__callq(struct annotate_browser 
*browser,
struct annotation *notes;
char title[SYM_TITLE_MAX_SIZE];
 
-   if (!ins__is_call(&dl->ins))
-   return false;
-
if (!dl->ops.target.sym) {
ui_helpline__puts("The called function was not found.");
return true;
@@ -436,7 +442,9 @@ struct disasm_line *annotate_browser__find_offset(struct 
annotate_browser *brows
return NULL;
 }
 
-static bool annotate_browser__jump(struct annotate_browser *browser)
+static bool annotate_browser__jump(struct annotate_browser *browser,
+  struct perf_evsel *evsel,
+  struct hist_browser_timer *hbt)
 {
struct disasm_line *dl = disasm_line(browser->selection);
u64 offset;
@@ -445,6 +453,11 @@ static bool annotate_browser__jump(struct annotate_browser 
*browser)
if (!ins__is_jump(&dl->ins))
return false;
 
+   if (dl->ops.target.outside) {
+   annotate_browser__callq(browser, evsel, hbt);
+   return true;
+   }
+
offset = dl->ops.target.offset;
dl = annotate_browser__find_offset(browser, offset, &idx);
if (dl == NULL) {
@@ -731,7 +744,7 @@ static int annotate_browser__run(struct annotate_browser 
*browser,
goto show_sup_ins;
else if (ins__is_ret(&dl->ins))
goto out;
-   else if (!(annotate_browser__jump(browser) ||
+   else if (!(annotate_browser__jump(browser, evsel, hbt) 
||
 annotate_browser__callq(browser, evsel, 
hbt))) {
 show_sup_ins:
ui_helpline__puts("Actions are only available 
for function call/return & jump/branch instructions.");
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 9524f322f597..5fa270b24eea 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -332,11 +332,10 @@ static int jump__parse(struct arch *arch __maybe_unused, 
struct ins_operands *op
 *
 * Actual navigation will come next, with further understanding of how
 *

[PATCH 38/44] perf annotate: Pass function descriptor to its instruction parsing routines

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

We need that to figure out if jumps have targets in a different
function.

E.g. _cpp_lex_token(), in /usr/libexec/gcc/x86_64-redhat-linux/5.3.1/cc1
has a line like this:

  jnec469be 

Cc: Adrian Hunter 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-ris0ioziyp469pofpzix2...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/s390/annotate/instructions.c |  5 +++--
 tools/perf/util/annotate.c   | 30 
 tools/perf/util/annotate.h   |  2 +-
 3 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/tools/perf/arch/s390/annotate/instructions.c 
b/tools/perf/arch/s390/annotate/instructions.c
index 46c21831f2ac..cee4e2f7c057 100644
--- a/tools/perf/arch/s390/annotate/instructions.c
+++ b/tools/perf/arch/s390/annotate/instructions.c
@@ -2,9 +2,10 @@
 #include 
 
 static int s390_call__parse(struct arch *arch, struct ins_operands *ops,
-   struct map *map)
+   struct map_symbol *ms)
 {
char *endptr, *tok, *name;
+   struct map *map = ms->map;
struct addr_map_symbol target = {
.map = map,
};
@@ -54,7 +55,7 @@ static struct ins_ops s390_call_ops = {
 
 static int s390_mov__parse(struct arch *arch __maybe_unused,
   struct ins_operands *ops,
-  struct map *map __maybe_unused)
+  struct map_symbol *ms __maybe_unused)
 {
char *s = strchr(ops->raw, ','), *target, *endptr;
 
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 666f62c58e1a..3ff829d89178 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -202,9 +202,10 @@ bool ins__is_fused(struct arch *arch, const char *ins1, 
const char *ins2)
return arch->ins_is_fused(arch, ins1, ins2);
 }
 
-static int call__parse(struct arch *arch, struct ins_operands *ops, struct map 
*map)
+static int call__parse(struct arch *arch, struct ins_operands *ops, struct 
map_symbol *ms)
 {
char *endptr, *tok, *name;
+   struct map *map = ms->map;
struct addr_map_symbol target = {
.map = map,
};
@@ -272,7 +273,7 @@ bool ins__is_call(const struct ins *ins)
return ins->ops == &call_ops || ins->ops == &s390_call_ops;
 }
 
-static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands 
*ops, struct map *map __maybe_unused)
+static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands 
*ops, struct map_symbol *ms __maybe_unused)
 {
const char *s = strchr(ops->raw, '+');
const char *c = strchr(ops->raw, ',');
@@ -365,7 +366,7 @@ static int comment__symbol(char *raw, char *comment, u64 
*addrp, char **namep)
return 0;
 }
 
-static int lock__parse(struct arch *arch, struct ins_operands *ops, struct map 
*map)
+static int lock__parse(struct arch *arch, struct ins_operands *ops, struct 
map_symbol *ms)
 {
ops->locked.ops = zalloc(sizeof(*ops->locked.ops));
if (ops->locked.ops == NULL)
@@ -380,7 +381,7 @@ static int lock__parse(struct arch *arch, struct 
ins_operands *ops, struct map *
goto out_free_ops;
 
if (ops->locked.ins.ops->parse &&
-   ops->locked.ins.ops->parse(arch, ops->locked.ops, map) < 0)
+   ops->locked.ins.ops->parse(arch, ops->locked.ops, ms) < 0)
goto out_free_ops;
 
return 0;
@@ -423,7 +424,7 @@ static struct ins_ops lock_ops = {
.scnprintf = lock__scnprintf,
 };
 
-static int mov__parse(struct arch *arch, struct ins_operands *ops, struct map 
*map __maybe_unused)
+static int mov__parse(struct arch *arch, struct ins_operands *ops, struct 
map_symbol *ms __maybe_unused)
 {
char *s = strchr(ops->raw, ','), *target, *comment, prev;
 
@@ -484,7 +485,7 @@ static struct ins_ops mov_ops = {
.scnprintf = mov__scnprintf,
 };
 
-static int dec__parse(struct arch *arch __maybe_unused, struct ins_operands 
*ops, struct map *map __maybe_unused)
+static int dec__parse(struct arch *arch __maybe_unused, struct ins_operands 
*ops, struct map_symbol *ms __maybe_unused)
 {
char *target, *comment, *s, prev;
 
@@ -923,14 +924,14 @@ int hist_entry__inc_addr_samples(struct hist_entry *he, 
struct perf_sample *samp
return symbol__inc_addr_samples(he->ms.sym, he->ms.map, evidx, ip, 
sample);
 }
 
-static void disasm_line__init_ins(struct disasm_line *dl, struct arch *arch, 
struct map *map)
+static void disasm_line__init_ins(struct disasm_line *dl, struct arch *arch, 
struct map_symbol *ms)
 {
dl->ins.ops = ins__find(arch, dl->ins.name);
 
if (!dl->ins.ops)
return;
 
-   if (dl->ins.ops->parse && dl->ins.ops->parse(arch, &dl->ops, map) < 0)
+   if (dl->ins.ops->parse && dl->ins.ops->parse(arch, &dl->ops, ms) < 0)
dl->ins.ops =

[PATCH 35/44] perf report: Introduce --ignore-vmlinux command line option

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

We've had this in 'perf top' for quite a while, useful if one wishes
to force using /proc/kcore to do annotation using the patched kernel
instead of the ELF image it started from, aka vmlinux.

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-ircpvox4wzsv7gasrpb28...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-report.txt | 3 +++
 tools/perf/builtin-report.c  | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/tools/perf/Documentation/perf-report.txt 
b/tools/perf/Documentation/perf-report.txt
index cba16d8a970e..e1a660e60849 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -296,6 +296,9 @@ OPTIONS
 --vmlinux=::
 vmlinux pathname
 
+--ignore-vmlinux::
+   Ignore vmlinux files.
+
 --kallsyms=::
 kallsyms pathname
 
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 1a82f38671a8..0f198f6d9b77 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -1018,6 +1018,8 @@ int cmd_report(int argc, const char **argv)
OPT_BOOLEAN(0, "mmaps", &report.mmaps_mode, "Display recorded tasks 
memory maps"),
OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
   "file", "vmlinux pathname"),
+   OPT_BOOLEAN(0, "ignore-vmlinux", &symbol_conf.ignore_vmlinux,
+"don't load vmlinux even if found"),
OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
   "file", "kallsyms pathname"),
OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"),
-- 
2.14.3



[PATCH 36/44] perf annotate browser: Add 'P' hotkey to dump annotation to file

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

Just like we have in the histograms browser used as the main screen for
'perf top --tui' and 'perf report --tui', to print the current
annotation to a file with a named composed by the symbol name and the
".annotation" suffix.

Here is one example of pressing 'A' on 'perf top' to live annotate a
kernel function and then press 'P' to dump that annotation, the
resulting file:

  # cat _raw_spin_lock_irqsave.annotation
  _raw_spin_lock_irqsave() /proc/kcore
  Event: cycles:ppp

7.14nop
   21.43push   %rbx
7.14pushfq
pop%rax
nop
mov%rax,%rbx
cli
nop
xor%eax,%eax
mov$0x1,%edx
   64.29lock   cmpxchg %edx,(%rdi)
test   %eax,%eax
  ↓ jne2b
mov%rbx,%rax
pop%rbx
  ← retq
  2b:   mov%eax,%esi
  → callq  queued_spin_lock_slowpath
mov%rbx,%rax
pop%rbx
  ← retq
  #

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-zzmnrwugb5vtk7bvg0rbx...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/annotate.c |  4 
 tools/perf/util/annotate.c| 31 +++
 tools/perf/util/annotate.h|  2 ++
 3 files changed, 37 insertions(+)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index 916f237c1df8..3834b264ba41 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -661,6 +661,7 @@ static int annotate_browser__run(struct annotate_browser 
*browser,
"t Circulate percent, total period, samples view\n"
"/ Search string\n"
"k Toggle line numbers\n"
+   "P Print to [symbol_name].annotation file.\n"
"r Run available scripts\n"
"? Search string backwards\n");
continue;
@@ -737,6 +738,9 @@ static int annotate_browser__run(struct annotate_browser 
*browser,
}
continue;
}
+   case 'P':
+   map_symbol__annotation_dump(ms, evsel);
+   continue;
case 't':
if (notes->options->show_total_period) {
notes->options->show_total_period = false;
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 7a6a85f9fea6..a7111871440e 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -2037,6 +2037,37 @@ int symbol__annotate_fprintf2(struct symbol *sym, FILE 
*fp)
return 0;
 }
 
+int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel 
*evsel)
+{
+   const char *ev_name = perf_evsel__name(evsel);
+   char buf[1024];
+   char *filename;
+   int err = -1;
+   FILE *fp;
+
+   if (asprintf(&filename, "%s.annotation", ms->sym->name) < 0)
+   return -1;
+
+   fp = fopen(filename, "w");
+   if (fp == NULL)
+   goto out_free_filename;
+
+   if (perf_evsel__is_group_event(evsel)) {
+   perf_evsel__group_desc(evsel, buf, sizeof(buf));
+   ev_name = buf;
+   }
+
+   fprintf(fp, "%s() %s\nEvent: %s\n\n",
+   ms->sym->name, ms->map->dso->long_name, ev_name);
+   symbol__annotate_fprintf2(ms->sym, fp);
+
+   fclose(fp);
+   err = 0;
+out_free_filename:
+   free(filename);
+   return err;
+}
+
 void symbol__annotate_zero_histogram(struct symbol *sym, int evidx)
 {
struct annotation *notes = symbol__annotation(sym);
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 3faa58045b22..365e9df888cf 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -288,6 +288,8 @@ void symbol__annotate_zero_histogram(struct symbol *sym, 
int evidx);
 void symbol__annotate_decay_histogram(struct symbol *sym, int evidx);
 void annotated_source__purge(struct annotated_source *as);
 
+int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel 
*evsel);
+
 bool ui__has_annotation(void);
 
 int symbol__tty_annotate(struct symbol *sym, struct map *map,
-- 
2.14.3



[PATCH 30/44] perf annotate: Introduce the --stdio2 output mode

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

This uses the TUI augmented formatting routines, modulo interactivity.

  # perf annotate --ignore-vmlinux --stdio2 _raw_spin_lock_irqsave
  _raw_spin_lock_irqsave() /proc/kcore
  Event: cycles:ppp

  Percent

  Disassembly of section load0:

  9a8734b0 :
nop
push   %rbx
   50.00pushfq
pop%rax
nop
mov%rax,%rbx
cli
nop
xor%eax,%eax
mov$0x1,%edx
   50.00lock   cmpxchg %edx,(%rdi)
test   %eax,%eax
  ↓ jne2b
mov%rbx,%rax
pop%rbx
  ← retq
  2b:   mov%eax,%esi
  → callq  queued_spin_lock_slowpath
mov%rbx,%rax
pop%rbx
  ← retq

Tested-by: Jin Yao 
Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-6cte5o8z84mbivbvqlg14...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-annotate.txt |  2 +
 tools/perf/builtin-annotate.c  | 23 +---
 tools/perf/util/annotate.c | 92 ++
 tools/perf/util/annotate.h |  5 ++
 4 files changed, 115 insertions(+), 7 deletions(-)

diff --git a/tools/perf/Documentation/perf-annotate.txt 
b/tools/perf/Documentation/perf-annotate.txt
index 292809c3c0ca..c29c7fc93023 100644
--- a/tools/perf/Documentation/perf-annotate.txt
+++ b/tools/perf/Documentation/perf-annotate.txt
@@ -69,6 +69,8 @@ OPTIONS
 
 --stdio:: Use the stdio interface.
 
+--stdio2:: Use the stdio2 interface, non-interactive, uses the TUI formatting.
+
 --stdio-color=::
'always', 'never' or 'auto', allowing configuring color output
via the command line, in addition to via "color.ui" .perfconfig.
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index ead6ae4549e5..e03f9bea9303 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -40,7 +40,7 @@
 struct perf_annotate {
struct perf_tool tool;
struct perf_session *session;
-   bool   use_tui, use_stdio, use_gtk;
+   bool   use_tui, use_stdio, use_stdio2, use_gtk;
bool   full_paths;
bool   print_line;
bool   skip_missing;
@@ -202,6 +202,11 @@ static int process_branch_callback(struct perf_evsel 
*evsel,
return ret;
 }
 
+static bool has_annotation(struct perf_annotate *ann)
+{
+   return ui__has_annotation() || ann->use_stdio2;
+}
+
 static int perf_evsel__add_sample(struct perf_evsel *evsel,
  struct perf_sample *sample,
  struct addr_location *al,
@@ -212,7 +217,7 @@ static int perf_evsel__add_sample(struct perf_evsel *evsel,
struct hist_entry *he;
int ret;
 
-   if ((!ann->has_br_stack || !ui__has_annotation()) &&
+   if ((!ann->has_br_stack || !has_annotation(ann)) &&
ann->sym_hist_filter != NULL &&
(al->sym == NULL ||
 strcmp(ann->sym_hist_filter, al->sym->name) != 0)) {
@@ -236,7 +241,7 @@ static int perf_evsel__add_sample(struct perf_evsel *evsel,
 */
process_branch_stack(sample->branch_stack, al, sample);
 
-   if (ann->has_br_stack && ui__has_annotation())
+   if (ann->has_br_stack && has_annotation(ann))
return process_branch_callback(evsel, sample, al, ann, machine);
 
he = hists__add_entry(hists, al, NULL, NULL, NULL, sample, true);
@@ -282,8 +287,11 @@ static int hist_entry__tty_annotate(struct hist_entry *he,
struct perf_evsel *evsel,
struct perf_annotate *ann)
 {
-   return symbol__tty_annotate(he->ms.sym, he->ms.map, evsel,
-   ann->print_line, ann->full_paths, 0, 0);
+   if (!ann->use_stdio2)
+   return symbol__tty_annotate(he->ms.sym, he->ms.map, evsel,
+   ann->print_line, ann->full_paths, 
0, 0);
+   return symbol__tty_annotate2(he->ms.sym, he->ms.map, evsel,
+ann->print_line, ann->full_paths);
 }
 
 static void hists__find_annotations(struct hists *hists,
@@ -487,6 +495,7 @@ int cmd_annotate(int argc, const char **argv)
OPT_BOOLEAN(0, "gtk", &annotate.use_gtk, "Use the GTK interface"),
OPT_BOOLEAN(0, "tui", &annotate.use_tui, "Use the TUI interface"),
OPT_BOOLEAN(0, "stdio", &annotate.use_stdio, "Use the stdio interface"),
+   OPT_BOOLEAN(0, "stdio2", &annotate.use_stdio2, "Use the stdio 
interface"),
OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
   "file", "vmlinux pathname"),
OPT_BOOLEAN('m

[PATCH 29/44] perf annotate: Introduce annotation_line__filter()

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

Out of the TUI logic that allows toggling the presentation of source
code lines.

Will be used in the upcoming --stdio2 mode.

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-g0ckz9ajy6unswrv2iy39...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/annotate.c | 19 +++
 tools/perf/util/annotate.h|  4 
 2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index bed647807d37..74a26f4e9b06 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -48,14 +48,8 @@ static inline struct annotation *browser__annotation(struct 
ui_browser *browser)
 static bool disasm_line__filter(struct ui_browser *browser, void *entry)
 {
struct annotation *notes = browser__annotation(browser);
-
-   if (notes->options->hide_src_code) {
-   struct annotation_line *al = list_entry(entry, struct 
annotation_line, node);
-
-   return al->offset == -1;
-   }
-
-   return false;
+   struct annotation_line *al = list_entry(entry, struct annotation_line, 
node);
+   return annotation_line__filter(al, notes);
 }
 
 static int ui_browser__jumps_percent_color(struct ui_browser *browser, int nr, 
bool current)
@@ -268,6 +262,7 @@ static void disasm_rb_tree__insert(struct rb_root *root, 
struct annotation_line
 static void annotate_browser__set_top(struct annotate_browser *browser,
  struct annotation_line *pos, u32 idx)
 {
+   struct annotation *notes = browser__annotation(&browser->b);
unsigned back;
 
ui_browser__refresh_dimensions(&browser->b);
@@ -277,7 +272,7 @@ static void annotate_browser__set_top(struct 
annotate_browser *browser,
while (browser->b.top_idx != 0 && back != 0) {
pos = list_entry(pos->node.prev, struct annotation_line, node);
 
-   if (disasm_line__filter(&browser->b, &pos->node))
+   if (annotation_line__filter(pos, notes))
continue;
 
--browser->b.top_idx;
@@ -440,7 +435,7 @@ struct disasm_line *annotate_browser__find_offset(struct 
annotate_browser *brows
list_for_each_entry(pos, ¬es->src->source, al.node) {
if (pos->al.offset == offset)
return pos;
-   if (!disasm_line__filter(&browser->b, &pos->al.node))
+   if (!annotation_line__filter(&pos->al, notes))
++*idx;
}
 
@@ -477,7 +472,7 @@ struct annotation_line 
*annotate_browser__find_string(struct annotate_browser *b
 
*idx = browser->b.index;
list_for_each_entry_continue(al, ¬es->src->source, node) {
-   if (disasm_line__filter(&browser->b, &al->node))
+   if (annotation_line__filter(al, notes))
continue;
 
++*idx;
@@ -514,7 +509,7 @@ struct annotation_line 
*annotate_browser__find_string_reverse(struct annotate_br
 
*idx = browser->b.index;
list_for_each_entry_continue_reverse(al, ¬es->src->source, node) {
-   if (disasm_line__filter(&browser->b, &al->node))
+   if (annotation_line__filter(al, notes))
continue;
 
--*idx;
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 6fbb34b9bd77..165845de1243 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -215,6 +215,10 @@ static inline int annotation__pcnt_width(struct annotation 
*notes)
return (notes->options->show_total_period ? 12 : 7) * notes->nr_events;
 }
 
+static inline bool annotation_line__filter(struct annotation_line *al, struct 
annotation *notes)
+{
+   return notes->options->hide_src_code && al->offset == -1;
+}
 
 void annotation__set_offsets(struct annotation *notes, s64 size);
 void annotation__compute_ipc(struct annotation *notes, size_t size);
-- 
2.14.3



[PATCH 18/44] perf annotate: Move nr_{asm_}entries to struct annotation

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

More non-TUI stuff.

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-yd4g6q0rngq4i49hz6iym...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/annotate.c | 23 +++
 tools/perf/util/annotate.h|  2 ++
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index 7ec441f93f7e..00b88349a3c2 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -35,8 +35,6 @@ struct annotate_browser {
struct rb_node *curr_hot;
struct annotation_line *selection;
struct arch*arch;
-   int nr_asm_entries;
-   int nr_entries;
boolsearching_backwards;
u8  addr_width;
u8  jumps_width;
@@ -470,7 +468,7 @@ static bool annotate_browser__toggle_source(struct 
annotate_browser *browser)
if (al->idx_asm < offset)
offset = al->idx;
 
-   browser->b.nr_entries = browser->nr_entries;
+   browser->b.nr_entries = notes->nr_entries;
notes->options->hide_src_code = false;
browser->b.seek(&browser->b, -offset, SEEK_CUR);
browser->b.top_idx = al->idx - offset;
@@ -485,7 +483,7 @@ static bool annotate_browser__toggle_source(struct 
annotate_browser *browser)
if (al->idx_asm < offset)
offset = al->idx_asm;
 
-   browser->b.nr_entries = browser->nr_asm_entries;
+   browser->b.nr_entries = notes->nr_asm_entries;
notes->options->hide_src_code = true;
browser->b.seek(&browser->b, -offset, SEEK_CUR);
browser->b.top_idx = al->idx_asm - offset;
@@ -495,10 +493,11 @@ static bool annotate_browser__toggle_source(struct 
annotate_browser *browser)
return true;
 }
 
-static void annotate_browser__init_asm_mode(struct annotate_browser *browser)
+static void ui_browser__init_asm_mode(struct ui_browser *browser)
 {
-   ui_browser__reset_index(&browser->b);
-   browser->b.nr_entries = browser->nr_asm_entries;
+   struct annotation *notes = browser__annotation(browser);
+   ui_browser__reset_index(browser);
+   browser->nr_entries = notes->nr_asm_entries;
 }
 
 #define SYM_TITLE_MAX_SIZE (PATH_MAX + 64)
@@ -854,7 +853,7 @@ static int annotate_browser__run(struct annotate_browser 
*browser,
   browser->b.height,
   browser->b.index,
   browser->b.top_idx,
-  browser->nr_asm_entries);
+  notes->nr_asm_entries);
}
continue;
case K_ENTER:
@@ -997,9 +996,9 @@ int symbol__tui_annotate(struct symbol *sym, struct map 
*map,
 
if (browser.b.width < line_len)
browser.b.width = line_len;
-   al->idx = browser.nr_entries++;
+   al->idx = notes->nr_entries++;
if (al->offset != -1) {
-   al->idx_asm = browser.nr_asm_entries++;
+   al->idx_asm = notes->nr_asm_entries++;
/*
 * FIXME: short term bandaid to cope with assembly
 * routines that comes with labels in the same column
@@ -1020,12 +1019,12 @@ int symbol__tui_annotate(struct symbol *sym, struct map 
*map,
browser.max_addr_width = hex_width(sym->end);
browser.jumps_width = width_jumps(notes->max_jump_sources);
notes->nr_events = nr_pcnt;
-   browser.b.nr_entries = browser.nr_entries;
+   browser.b.nr_entries = notes->nr_entries;
browser.b.entries = ¬es->src->source,
browser.b.width += 18; /* Percentage */
 
if (notes->options->hide_src_code)
-   annotate_browser__init_asm_mode(&browser);
+   ui_browser__init_asm_mode(&browser.b);
 
annotate_browser__update_addr_width(&browser);
 
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 0424c127b004..0c34eb0bd7c8 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -175,6 +175,8 @@ struct annotation {
int nr_events;
int nr_jumps;
int max_jump_sources;
+   int nr_entries;
+   int nr_asm_entries;
boolhave_cycles;
struct annotated_source *src;
 };
-- 
2.14.3



[PATCH 31/44] perf annotate: Move the default annotate options to the library

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

One more thing that goes from the TUI code to be used more widely,
for instance it'll affect the default options used by:

  perf annotate --stdio2

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-0nsz0dm0akdbo30vgja2a...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-annotate.c |  2 ++
 tools/perf/builtin-report.c   |  1 +
 tools/perf/builtin-top.c  |  2 ++
 tools/perf/ui/browser.c   |  2 --
 tools/perf/ui/browser.h   |  1 -
 tools/perf/ui/browsers/annotate.c | 67 +--
 tools/perf/util/annotate.c| 62 
 tools/perf/util/annotate.h|  4 +++
 8 files changed, 72 insertions(+), 69 deletions(-)

diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index e03f9bea9303..fd5aac3fd949 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -572,6 +572,8 @@ int cmd_annotate(int argc, const char **argv)
if (ret < 0)
goto out_delete;
 
+   annotation_config__init();
+
symbol_conf.try_vmlinux_path = true;
 
ret = symbol__init(&annotate.session->header.env);
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 91da12975642..1a82f38671a8 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -1340,6 +1340,7 @@ int cmd_report(int argc, const char **argv)
symbol_conf.priv_size += sizeof(u32);
symbol_conf.sort_by_name = true;
}
+   annotation_config__init();
}
 
if (symbol__init(&session->header.env) < 0)
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 113c298ed38b..f39bd60d2708 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1493,6 +1493,8 @@ int cmd_top(int argc, const char **argv)
if (status < 0)
goto out_delete_evlist;
 
+   annotation_config__init();
+
symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);
if (symbol__init(NULL) < 0)
return -1;
diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c
index 33c30325885f..9f6ce29b83b4 100644
--- a/tools/perf/ui/browser.c
+++ b/tools/perf/ui/browser.c
@@ -784,6 +784,4 @@ void ui_browser__init(void)
struct ui_browser_colorset *c = &ui_browser__colorsets[i++];
sltt_set_color(c->colorset, c->name, c->fg, c->bg);
}
-
-   annotate_browser__init();
 }
diff --git a/tools/perf/ui/browser.h b/tools/perf/ui/browser.h
index 9e69c6a43514..70057178ee34 100644
--- a/tools/perf/ui/browser.h
+++ b/tools/perf/ui/browser.h
@@ -79,5 +79,4 @@ void ui_browser__list_head_seek(struct ui_browser *browser, 
off_t offset, int wh
 unsigned int ui_browser__list_head_refresh(struct ui_browser *browser);
 
 void ui_browser__init(void);
-void annotate_browser__init(void);
 #endif /* _PERF_UI_BROWSER_H_ */
diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index 74a26f4e9b06..916f237c1df8 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -9,7 +9,6 @@
 #include "../../util/sort.h"
 #include "../../util/symbol.h"
 #include "../../util/evsel.h"
-#include "../../util/config.h"
 #include "../../util/evlist.h"
 #include 
 #include 
@@ -22,11 +21,6 @@ struct disasm_line_samples {
struct sym_hist_entry he;
 };
 
-static struct annotation_options annotate_browser__opts = {
-   .use_offset = true,
-   .jump_arrows= true,
-};
-
 struct arch;
 
 struct annotate_browser {
@@ -773,12 +767,6 @@ static int annotate_browser__run(struct annotate_browser 
*browser,
 int map_symbol__tui_annotate(struct map_symbol *ms, struct perf_evsel *evsel,
 struct hist_browser_timer *hbt)
 {
-   /* Set default value for show_total_period and show_nr_samples  */
-   annotate_browser__opts.show_total_period =
-   symbol_conf.show_total_period;
-   annotate_browser__opts.show_nr_samples =
-   symbol_conf.show_nr_samples;
-
return symbol__tui_annotate(ms->sym, ms->map, evsel, hbt);
 }
 
@@ -819,7 +807,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map 
*map,
if (map->dso->annotate_warned)
return -1;
 
-   err = symbol__annotate2(sym, map, evsel, &annotate_browser__opts, 
&browser.arch);
+   err = symbol__annotate2(sym, map, evsel, &annotation__default_options, 
&browser.arch);
if (err) {
char msg[BUFSIZ];
symbol__strerror_disassemble(sym, map, err, msg, sizeof(msg));
@@ -845,56 +833,3 @@ int symbol__tui_annotate(struct symbol *sym, struct map 
*map,
zfree(¬es->offsets);
return ret;
 }
-
-#define ANNOTATE_CF

[PATCH 27/44] perf annotate: Finish the generalization of annotate_browser__write()

2018-03-24 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

We pass some more callbacks and all of annotate_browser__write() seems
to be free of TUI code (except for some arrow constants, will fix).

Cc: Adrian Hunter 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-5uo6yvwnxtsbe8y6v0ysa...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/annotate.c |  97 +---
 tools/perf/util/annotate.c| 113 +++---
 tools/perf/util/annotate.h|  13 +++--
 3 files changed, 127 insertions(+), 96 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index 9b77a016e299..2b18c462b882 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -71,38 +71,20 @@ static int ui_browser__jumps_percent_color(struct 
ui_browser *browser, int nr, b
return HE_COLORSET_NORMAL;
 }
 
-static int ui_browser__set_jumps_percent_color(struct ui_browser *browser, int 
nr, bool current)
+static int ui_browser__set_jumps_percent_color(void *browser, int nr, bool 
current)
 {
 int color = ui_browser__jumps_percent_color(browser, nr, current);
 return ui_browser__set_color(browser, color);
 }
 
-static void disasm_line__write(struct disasm_line *dl, struct ui_browser 
*browser,
-  char *bf, size_t size)
+static int annotate_browser__set_color(void *browser, int color)
 {
-   struct annotation *notes = browser__annotation(browser);
-
-   if (dl->ins.ops && dl->ins.ops->scnprintf) {
-   if (ins__is_jump(&dl->ins)) {
-   bool fwd = dl->ops.target.offset > dl->al.offset;
-
-   ui_browser__write_graph(browser, fwd ? 
SLSMG_DARROW_CHAR :
-   SLSMG_UARROW_CHAR);
-   SLsmg_write_char(' ');
-   } else if (ins__is_call(&dl->ins)) {
-   ui_browser__write_graph(browser, SLSMG_RARROW_CHAR);
-   SLsmg_write_char(' ');
-   } else if (ins__is_ret(&dl->ins)) {
-   ui_browser__write_graph(browser, SLSMG_LARROW_CHAR);
-   SLsmg_write_char(' ');
-   } else {
-   ui_browser__write_nstring(browser, " ", 2);
-   }
-   } else {
-   ui_browser__write_nstring(browser, " ", 2);
-   }
+   return ui_browser__set_color(browser, color);
+}
 
-   disasm_line__scnprintf(dl, bf, size, !notes->options->use_offset);
+static void annotate_browser__write_graph(void *browser, int graph)
+{
+   ui_browser__write_graph(browser, graph);
 }
 
 static void annotate_browser__set_percent_color(void *browser, double percent, 
bool current)
@@ -128,68 +110,19 @@ static void annotate_browser__write(struct ui_browser 
*browser, void *entry, int
bool change_color = (!notes->options->hide_src_code &&
 (!current_entry || (browser->use_navkeypressed &&
 !browser->navkeypressed)));
-   int width = browser->width, printed;
-   int pcnt_width = annotation__pcnt_width(notes),
-   cycles_width = annotation__cycles_width(notes);
-   char bf[256];
-
-   annotation_line__print_start(al, notes, row == 0, current_entry, 
browser,
-annotate_browser__set_percent_color,
-annotate_browser__printf);
+   int width = browser->width;
 
/* The scroll bar isn't being used */
if (!browser->navkeypressed)
width += 1;
 
-   if (!*al->line)
-   ui_browser__write_nstring(browser, " ", width - pcnt_width - 
cycles_width);
-   else if (al->offset == -1) {
-   if (al->line_nr && notes->options->show_linenr)
-   printed = scnprintf(bf, sizeof(bf), "%-*d ", 
notes->widths.addr + 1, al->line_nr);
-   else
-   printed = scnprintf(bf, sizeof(bf), "%*s  ", 
notes->widths.addr, " ");
-   ui_browser__write_nstring(browser, bf, printed);
-   ui_browser__write_nstring(browser, al->line, width - printed - 
pcnt_width - cycles_width + 1);
-   } else {
-   u64 addr = al->offset;
-   int color = -1;
-
-   if (!notes->options->use_offset)
-   addr += notes->start;
-
-   if (!notes->options->use_offset) {
-   printed = scnprintf(bf, sizeof(bf), "%" PRIx64 ": ", 
addr);
-   } else {
-   if (al->jump_sources) {
-   if (notes->options->show_nr_jumps) {
-   int prev;
-   printed = scnprintf(bf, sizeof(bf), 
"%*d ",
-

  1   2   3   4   >