1. 26 5月, 2019 40 次提交
    • A
      apparmorfs: fix use-after-free on symlink traversal · b21ca276
      Al Viro 提交于
      [ Upstream commit f51dcd0f621caac5380ce90fbbeafc32ce4517ae ]
      
      symlink body shouldn't be freed without an RCU delay.  Switch apparmorfs
      to ->destroy_inode() and use of call_rcu(); free both the inode and symlink
      body in the callback.
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      b21ca276
    • A
      securityfs: fix use-after-free on symlink traversal · 9a0467e1
      Al Viro 提交于
      [ Upstream commit 46c874419652bbefdfed17420fd6e88d8a31d9ec ]
      
      symlink body shouldn't be freed without an RCU delay.  Switch securityfs
      to ->destroy_inode() and use of call_rcu(); free both the inode and symlink
      body in the callback.
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      9a0467e1
    • T
      power: supply: cpcap-battery: Fix division by zero · 900bf351
      Tony Lindgren 提交于
      [ Upstream commit dbe7208c6c4aec083571f2ec742870a0d0edbea3 ]
      
      If called fast enough so samples do not increment, we can get
      division by zero in kernel:
      
      __div0
      cpcap_battery_cc_raw_div
      cpcap_battery_get_property
      power_supply_get_property.part.1
      power_supply_get_property
      power_supply_show_property
      power_supply_uevent
      
      Fixes: 874b2adb ("power: supply: cpcap-battery: Add a battery driver")
      Signed-off-by: NTony Lindgren <tony@atomide.com>
      Acked-by: NPavel Machek <pavel@ucw.cz>
      Signed-off-by: NSebastian Reichel <sebastian.reichel@collabora.com>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      900bf351
    • J
      clk: sunxi-ng: nkmp: Avoid GENMASK(-1, 0) · b7771cb0
      Jernej Skrabec 提交于
      [ Upstream commit 2abc330c514fe56c570bb1a6318b054b06a4f72e ]
      
      Sometimes one of the nkmp factors is unused. This means that one of the
      factors shift and width values are set to 0. Current nkmp clock code
      generates a mask for each factor with GENMASK(width + shift - 1, shift).
      For unused factor this translates to GENMASK(-1, 0). This code is
      further expanded by C preprocessor to final version:
      (((~0UL) - (1UL << (0)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (-1))))
      or a bit simplified:
      (~0UL & (~0UL >> BITS_PER_LONG))
      
      It turns out that result of the second part (~0UL >> BITS_PER_LONG) is
      actually undefined by C standard, which clearly specifies:
      
      "If the value of the right operand is negative or is greater than or
      equal to the width of the promoted left operand, the behavior is
      undefined."
      
      Additionally, compiling kernel with aarch64-linux-gnu-gcc 8.3.0 gave
      different results whether literals or variables with same values as
      literals were used. GENMASK with literals -1 and 0 gives zero and with
      variables gives 0xFFFFFFFFFFFFFFF (~0UL). Because nkmp driver uses
      GENMASK with variables as parameter, expression calculates mask as ~0UL
      instead of 0. This has further consequences that LSB in register is
      always set to 1 (1 is neutral value for a factor and shift is 0).
      
      For example, H6 pll-de clock is set to 600 MHz by sun4i-drm driver, but
      due to this bug ends up being 300 MHz. Additionally, 300 MHz seems to be
      too low because following warning can be found in dmesg:
      
      [    1.752763] WARNING: CPU: 2 PID: 41 at drivers/clk/sunxi-ng/ccu_common.c:41 ccu_helper_wait_for_lock.part.0+0x6c/0x90
      [    1.763378] Modules linked in:
      [    1.766441] CPU: 2 PID: 41 Comm: kworker/2:1 Not tainted 5.1.0-rc2-next-20190401 #138
      [    1.774269] Hardware name: Pine H64 (DT)
      [    1.778200] Workqueue: events deferred_probe_work_func
      [    1.783341] pstate: 40000005 (nZcv daif -PAN -UAO)
      [    1.788135] pc : ccu_helper_wait_for_lock.part.0+0x6c/0x90
      [    1.793623] lr : ccu_helper_wait_for_lock.part.0+0x48/0x90
      [    1.799107] sp : ffff000010f93840
      [    1.802422] x29: ffff000010f93840 x28: 0000000000000000
      [    1.807735] x27: ffff800073ce9d80 x26: ffff000010afd1b8
      [    1.813049] x25: ffffffffffffffff x24: 00000000ffffffff
      [    1.818362] x23: 0000000000000001 x22: ffff000010abd5c8
      [    1.823675] x21: 0000000010000000 x20: 00000000685f367e
      [    1.828987] x19: 0000000000001801 x18: 0000000000000001
      [    1.834300] x17: 0000000000000001 x16: 0000000000000000
      [    1.839613] x15: 0000000000000000 x14: ffff000010789858
      [    1.844926] x13: 0000000000000000 x12: 0000000000000001
      [    1.850239] x11: 0000000000000000 x10: 0000000000000970
      [    1.855551] x9 : ffff000010f936c0 x8 : ffff800074cec0d0
      [    1.860864] x7 : 0000800067117000 x6 : 0000000115c30b41
      [    1.866177] x5 : 00ffffffffffffff x4 : 002c959300bfe500
      [    1.871490] x3 : 0000000000000018 x2 : 0000000029aaaaab
      [    1.876802] x1 : 00000000000002e6 x0 : 00000000686072bc
      [    1.882114] Call trace:
      [    1.884565]  ccu_helper_wait_for_lock.part.0+0x6c/0x90
      [    1.889705]  ccu_helper_wait_for_lock+0x10/0x20
      [    1.894236]  ccu_nkmp_set_rate+0x244/0x2a8
      [    1.898334]  clk_change_rate+0x144/0x290
      [    1.902258]  clk_core_set_rate_nolock+0x180/0x1b8
      [    1.906963]  clk_set_rate+0x34/0xa0
      [    1.910455]  sun8i_mixer_bind+0x484/0x558
      [    1.914466]  component_bind_all+0x10c/0x230
      [    1.918651]  sun4i_drv_bind+0xc4/0x1a0
      [    1.922401]  try_to_bring_up_master+0x164/0x1c0
      [    1.926932]  __component_add+0xa0/0x168
      [    1.930769]  component_add+0x10/0x18
      [    1.934346]  sun8i_dw_hdmi_probe+0x18/0x20
      [    1.938443]  platform_drv_probe+0x50/0xa0
      [    1.942455]  really_probe+0xcc/0x280
      [    1.946032]  driver_probe_device+0x54/0xe8
      [    1.950130]  __device_attach_driver+0x80/0xb8
      [    1.954488]  bus_for_each_drv+0x78/0xc8
      [    1.958326]  __device_attach+0xd4/0x130
      [    1.962163]  device_initial_probe+0x10/0x18
      [    1.966348]  bus_probe_device+0x90/0x98
      [    1.970185]  deferred_probe_work_func+0x6c/0xa0
      [    1.974720]  process_one_work+0x1e0/0x320
      [    1.978732]  worker_thread+0x228/0x428
      [    1.982484]  kthread+0x120/0x128
      [    1.985714]  ret_from_fork+0x10/0x18
      [    1.989290] ---[ end trace 9babd42e1ca4b84f ]---
      
      This commit solves the issue by first checking value of the factor
      width. If it is equal to 0 (unused factor), mask is set to 0, otherwise
      GENMASK() macro is used as before.
      
      Fixes: d897ef56 ("clk: sunxi-ng: Mask nkmp factors when setting register")
      Signed-off-by: NJernej Skrabec <jernej.skrabec@siol.net>
      Signed-off-by: NMaxime Ripard <maxime.ripard@bootlin.com>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      b7771cb0
    • S
      xfrm4: Fix uninitialized memory read in _decode_session4 · a654a73d
      Steffen Klassert 提交于
      [ Upstream commit 8742dc86d0c7a9628117a989c11f04a9b6b898f3 ]
      
      We currently don't reload pointers pointing into skb header
      after doing pskb_may_pull() in _decode_session4(). So in case
      pskb_may_pull() changed the pointers, we read from random
      memory. Fix this by putting all the needed infos on the
      stack, so that we don't need to access the header pointers
      after doing pskb_may_pull().
      
      Fixes: 1da177e4 ("Linux-2.6.12-rc2")
      Signed-off-by: NSteffen Klassert <steffen.klassert@secunet.com>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      a654a73d
    • M
      xfrm: Honor original L3 slave device in xfrmi policy lookup · 6faa6206
      Martin Willi 提交于
      [ Upstream commit 025c65e119bf58b610549ca359c9ecc5dee6a8d2 ]
      
      If an xfrmi is associated to a vrf layer 3 master device,
      xfrm_policy_check() fails after traffic decapsulation. The input
      interface is replaced by the layer 3 master device, and hence
      xfrmi_decode_session() can't match the xfrmi anymore to satisfy
      policy checking.
      
      Extend ingress xfrmi lookup to honor the original layer 3 slave
      device, allowing xfrm interfaces to operate within a vrf domain.
      
      Fixes: f203b76d ("xfrm: Add virtual xfrm interfaces")
      Signed-off-by: NMartin Willi <martin@strongswan.org>
      Signed-off-by: NSteffen Klassert <steffen.klassert@secunet.com>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      6faa6206
    • S
      esp4: add length check for UDP encapsulation · 3716c262
      Sabrina Dubroca 提交于
      [ Upstream commit 8dfb4eba4100e7cdd161a8baef2d8d61b7a7e62e ]
      
      esp_output_udp_encap can produce a length that doesn't fit in the 16
      bits of a UDP header's length field. In that case, we'll send a
      fragmented packet whose length is larger than IP_MAX_MTU (resulting in
      "Oversized IP packet" warnings on receive) and with a bogus UDP
      length.
      
      To prevent this, add a length check to esp_output_udp_encap and return
       -EMSGSIZE on failure.
      
      This seems to be older than git history.
      Signed-off-by: NSabrina Dubroca <sd@queasysnail.net>
      Signed-off-by: NSteffen Klassert <steffen.klassert@secunet.com>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      3716c262
    • C
      xfrm: clean up xfrm protocol checks · d410ef75
      Cong Wang 提交于
      [ Upstream commit dbb2483b2a46fbaf833cfb5deb5ed9cace9c7399 ]
      
      In commit 6a53b759 ("xfrm: check id proto in validate_tmpl()")
      I introduced a check for xfrm protocol, but according to Herbert
      IPSEC_PROTO_ANY should only be used as a wildcard for lookup, so
      it should be removed from validate_tmpl().
      
      And, IPSEC_PROTO_ANY is expected to only match 3 IPSec-specific
      protocols, this is why xfrm_state_flush() could still miss
      IPPROTO_ROUTING, which leads that those entries are left in
      net->xfrm.state_all before exit net. Fix this by replacing
      IPSEC_PROTO_ANY with zero.
      
      This patch also extracts the check from validate_tmpl() to
      xfrm_id_proto_valid() and uses it in parse_ipsecrequest().
      With this, no other protocols should be added into xfrm.
      
      Fixes: 6a53b759 ("xfrm: check id proto in validate_tmpl()")
      Reported-by: syzbot+0bf0519d6e0de15914fe@syzkaller.appspotmail.com
      Cc: Steffen Klassert <steffen.klassert@secunet.com>
      Cc: Herbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: NCong Wang <xiyou.wangcong@gmail.com>
      Acked-by: NHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: NSteffen Klassert <steffen.klassert@secunet.com>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      d410ef75
    • J
      vti4: ipip tunnel deregistration fixes. · 159269cc
      Jeremy Sowden 提交于
      [ Upstream commit 5483844c3fc18474de29f5d6733003526e0a9f78 ]
      
      If tunnel registration failed during module initialization, the module
      would fail to deregister the IPPROTO_COMP protocol and would attempt to
      deregister the tunnel.
      
      The tunnel was not deregistered during module-exit.
      
      Fixes: dd9ee3444014e ("vti4: Fix a ipip packet processing bug in 'IPCOMP' virtual tunnel")
      Signed-off-by: NJeremy Sowden <jeremy@azazel.net>
      Signed-off-by: NSteffen Klassert <steffen.klassert@secunet.com>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      159269cc
    • S
      xfrm6_tunnel: Fix potential panic when unloading xfrm6_tunnel module · 64f214ce
      Su Yanjun 提交于
      [ Upstream commit 6ee02a54ef990a71bf542b6f0a4e3321de9d9c66 ]
      
      When unloading xfrm6_tunnel module, xfrm6_tunnel_fini directly
      frees the xfrm6_tunnel_spi_kmem. Maybe someone has gotten the
      xfrm6_tunnel_spi, so need to wait it.
      
      Fixes: 91cc3bb0("xfrm6_tunnel: RCU conversion")
      Signed-off-by: NSu Yanjun <suyj.fnst@cn.fujitsu.com>
      Acked-by: NHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: NSteffen Klassert <steffen.klassert@secunet.com>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      64f214ce
    • Y
      xfrm: policy: Fix out-of-bound array accesses in __xfrm_policy_unlink · c9516503
      YueHaibing 提交于
      [ Upstream commit b805d78d300bcf2c83d6df7da0c818b0fee41427 ]
      
      UBSAN report this:
      
      UBSAN: Undefined behaviour in net/xfrm/xfrm_policy.c:1289:24
      index 6 is out of range for type 'unsigned int [6]'
      CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.4.162-514.55.6.9.x86_64+ #13
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014
       0000000000000000 1466cf39b41b23c9 ffff8801f6b07a58 ffffffff81cb35f4
       0000000041b58ab3 ffffffff83230f9c ffffffff81cb34e0 ffff8801f6b07a80
       ffff8801f6b07a20 1466cf39b41b23c9 ffffffff851706e0 ffff8801f6b07ae8
      Call Trace:
       <IRQ>  [<ffffffff81cb35f4>] __dump_stack lib/dump_stack.c:15 [inline]
       <IRQ>  [<ffffffff81cb35f4>] dump_stack+0x114/0x1a0 lib/dump_stack.c:51
       [<ffffffff81d94225>] ubsan_epilogue+0x12/0x8f lib/ubsan.c:164
       [<ffffffff81d954db>] __ubsan_handle_out_of_bounds+0x16e/0x1b2 lib/ubsan.c:382
       [<ffffffff82a25acd>] __xfrm_policy_unlink+0x3dd/0x5b0 net/xfrm/xfrm_policy.c:1289
       [<ffffffff82a2e572>] xfrm_policy_delete+0x52/0xb0 net/xfrm/xfrm_policy.c:1309
       [<ffffffff82a3319b>] xfrm_policy_timer+0x30b/0x590 net/xfrm/xfrm_policy.c:243
       [<ffffffff813d3927>] call_timer_fn+0x237/0x990 kernel/time/timer.c:1144
       [<ffffffff813d8e7e>] __run_timers kernel/time/timer.c:1218 [inline]
       [<ffffffff813d8e7e>] run_timer_softirq+0x6ce/0xb80 kernel/time/timer.c:1401
       [<ffffffff8120d6f9>] __do_softirq+0x299/0xe10 kernel/softirq.c:273
       [<ffffffff8120e676>] invoke_softirq kernel/softirq.c:350 [inline]
       [<ffffffff8120e676>] irq_exit+0x216/0x2c0 kernel/softirq.c:391
       [<ffffffff82c5edab>] exiting_irq arch/x86/include/asm/apic.h:652 [inline]
       [<ffffffff82c5edab>] smp_apic_timer_interrupt+0x8b/0xc0 arch/x86/kernel/apic/apic.c:926
       [<ffffffff82c5c985>] apic_timer_interrupt+0xa5/0xb0 arch/x86/entry/entry_64.S:735
       <EOI>  [<ffffffff81188096>] ? native_safe_halt+0x6/0x10 arch/x86/include/asm/irqflags.h:52
       [<ffffffff810834d7>] arch_safe_halt arch/x86/include/asm/paravirt.h:111 [inline]
       [<ffffffff810834d7>] default_idle+0x27/0x430 arch/x86/kernel/process.c:446
       [<ffffffff81085f05>] arch_cpu_idle+0x15/0x20 arch/x86/kernel/process.c:437
       [<ffffffff8132abc3>] default_idle_call+0x53/0x90 kernel/sched/idle.c:92
       [<ffffffff8132b32d>] cpuidle_idle_call kernel/sched/idle.c:156 [inline]
       [<ffffffff8132b32d>] cpu_idle_loop kernel/sched/idle.c:251 [inline]
       [<ffffffff8132b32d>] cpu_startup_entry+0x60d/0x9a0 kernel/sched/idle.c:299
       [<ffffffff8113e119>] start_secondary+0x3c9/0x560 arch/x86/kernel/smpboot.c:245
      
      The issue is triggered as this:
      
      xfrm_add_policy
          -->verify_newpolicy_info  //check the index provided by user with XFRM_POLICY_MAX
      			      //In my case, the index is 0x6E6BB6, so it pass the check.
          -->xfrm_policy_construct  //copy the user's policy and set xfrm_policy_timer
          -->xfrm_policy_insert
      	--> __xfrm_policy_link //use the orgin dir, in my case is 2
      	--> xfrm_gen_index   //generate policy index, there is 0x6E6BB6
      
      then xfrm_policy_timer be fired
      
      xfrm_policy_timer
         --> xfrm_policy_id2dir  //get dir from (policy index & 7), in my case is 6
         --> xfrm_policy_delete
            --> __xfrm_policy_unlink //access policy_count[dir], trigger out of range access
      
      Add xfrm_policy_id2dir check in verify_newpolicy_info, make sure the computed dir is
      valid, to fix the issue.
      Reported-by: NHulk Robot <hulkci@huawei.com>
      Fixes: e682adf0 ("xfrm: Try to honor policy index if it's supplied by user")
      Signed-off-by: NYueHaibing <yuehaibing@huawei.com>
      Acked-by: NHerbert Xu <herbert@gondor.apana.org.au>
      Signed-off-by: NSteffen Klassert <steffen.klassert@secunet.com>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      c9516503
    • K
      fuse: Add FOPEN_STREAM to use stream_open() · fea68500
      Kirill Smelkov 提交于
      commit bbd84f33652f852ce5992d65db4d020aba21f882 upstream.
      
      Starting from commit 9c225f26 ("vfs: atomic f_pos accesses as per
      POSIX") files opened even via nonseekable_open gate read and write via lock
      and do not allow them to be run simultaneously. This can create read vs
      write deadlock if a filesystem is trying to implement a socket-like file
      which is intended to be simultaneously used for both read and write from
      filesystem client.  See commit 10dce8af3422 ("fs: stream_open - opener for
      stream-like files so that read and write can run simultaneously without
      deadlock") for details and e.g. commit 581d21a2 ("xenbus: fix deadlock
      on writes to /proc/xen/xenbus") for a similar deadlock example on
      /proc/xen/xenbus.
      
      To avoid such deadlock it was tempting to adjust fuse_finish_open to use
      stream_open instead of nonseekable_open on just FOPEN_NONSEEKABLE flags,
      but grepping through Debian codesearch shows users of FOPEN_NONSEEKABLE,
      and in particular GVFS which actually uses offset in its read and write
      handlers
      
      	https://codesearch.debian.net/search?q=-%3Enonseekable+%3D
      	https://gitlab.gnome.org/GNOME/gvfs/blob/1.40.0-6-gcbc54396/client/gvfsfusedaemon.c#L1080
      	https://gitlab.gnome.org/GNOME/gvfs/blob/1.40.0-6-gcbc54396/client/gvfsfusedaemon.c#L1247-1346
      	https://gitlab.gnome.org/GNOME/gvfs/blob/1.40.0-6-gcbc54396/client/gvfsfusedaemon.c#L1399-1481
      
      so if we would do such a change it will break a real user.
      
      Add another flag (FOPEN_STREAM) for filesystem servers to indicate that the
      opened handler is having stream-like semantics; does not use file position
      and thus the kernel is free to issue simultaneous read and write request on
      opened file handle.
      
      This patch together with stream_open() should be added to stable kernels
      starting from v3.14+. This will allow to patch OSSPD and other FUSE
      filesystems that provide stream-like files to return FOPEN_STREAM |
      FOPEN_NONSEEKABLE in open handler and this way avoid the deadlock on all
      kernel versions. This should work because fuse_finish_open ignores unknown
      open flags returned from a filesystem and so passing FOPEN_STREAM to a
      kernel that is not aware of this flag cannot hurt. In turn the kernel that
      is not aware of FOPEN_STREAM will be < v3.14 where just FOPEN_NONSEEKABLE
      is sufficient to implement streams without read vs write deadlock.
      
      Cc: stable@vger.kernel.org # v3.14+
      Signed-off-by: NKirill Smelkov <kirr@nexedi.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fea68500
    • M
      dm mpath: always free attached_handler_name in parse_path() · f9eccf6c
      Martin Wilck 提交于
      commit 940bc471780b004a5277c1931f52af363c2fc9da upstream.
      
      Commit b592211c ("dm mpath: fix attached_handler_name leak and
      dangling hw_handler_name pointer") fixed a memory leak for the case
      where setup_scsi_dh() returns failure. But setup_scsi_dh may return
      success and not "use" attached_handler_name if the
      retain_attached_hwhandler flag is not set on the map. As setup_scsi_sh
      properly "steals" the pointer by nullifying it, freeing it
      unconditionally in parse_path() is safe.
      
      Fixes: b592211c ("dm mpath: fix attached_handler_name leak and dangling hw_handler_name pointer")
      Cc: stable@vger.kernel.org
      Reported-by: NYufen Yu <yuyufen@huawei.com>
      Signed-off-by: NMartin Wilck <mwilck@suse.com>
      Signed-off-by: NMike Snitzer <snitzer@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f9eccf6c
    • M
      dm integrity: correctly calculate the size of metadata area · 9407680a
      Mikulas Patocka 提交于
      commit 30bba430ddf737978e40561198693ba91386dac1 upstream.
      
      When we use separate devices for data and metadata, dm-integrity would
      incorrectly calculate the size of the metadata device as if it had
      512-byte block size - and it would refuse activation with larger block
      size and smaller metadata device.
      
      Fix this so that it takes actual block size into account, which fixes
      the following reported issue:
      https://gitlab.com/cryptsetup/cryptsetup/issues/450
      
      Fixes: 356d9d52 ("dm integrity: allow separate metadata device")
      Cc: stable@vger.kernel.org # v4.19+
      Signed-off-by: NMikulas Patocka <mpatocka@redhat.com>
      Signed-off-by: NMike Snitzer <snitzer@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9407680a
    • M
      dm delay: fix a crash when invalid device is specified · 3b92ff72
      Mikulas Patocka 提交于
      commit 81bc6d150ace6250503b825d9d0c10f7bbd24095 upstream.
      
      When the target line contains an invalid device, delay_ctr() will call
      delay_dtr() with NULL workqueue.  Attempting to destroy the NULL
      workqueue causes a crash.
      Signed-off-by: NMikulas Patocka <mpatocka@redhat.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: NMike Snitzer <snitzer@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3b92ff72
    • D
      dm zoned: Fix zone report handling · 90cc7112
      Damien Le Moal 提交于
      commit 7aedf75ff740a98f3683439449cd91c8662d03b2 upstream.
      
      The function blkdev_report_zones() returns success even if no zone
      information is reported (empty report). Empty zone reports can only
      happen if the report start sector passed exceeds the device capacity.
      The conditions for this to happen are either a bug in the caller code,
      or, a change in the device that forced the low level driver to change
      the device capacity to a value that is lower than the report start
      sector. This situation includes a failed disk revalidation resulting in
      the disk capacity being changed to 0.
      
      If this change happens while dm-zoned is in its initialization phase
      executing dmz_init_zones(), this function may enter an infinite loop
      and hang the system. To avoid this, add a check to disallow empty zone
      reports and bail out early. Also fix the function dmz_update_zone() to
      make sure that the report for the requested zone was correctly obtained.
      
      Fixes: 3b1a94c8 ("dm zoned: drive-managed zoned block device target")
      Cc: stable@vger.kernel.org
      Signed-off-by: NDamien Le Moal <damien.lemoal@wdc.com>
      Reviewed-by: NShaun Tancheff <shaun@tancheff.com>
      Signed-off-by: NDamien Le Moal <damien.lemoal@wdc.com>
      Signed-off-by: NMike Snitzer <snitzer@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      90cc7112
    • N
      dm cache metadata: Fix loading discard bitset · ff0699a5
      Nikos Tsironis 提交于
      commit e28adc3bf34e434b30e8d063df4823ba0f3e0529 upstream.
      
      Add missing dm_bitset_cursor_next() to properly advance the bitset
      cursor.
      
      Otherwise, the discarded state of all blocks is set according to the
      discarded state of the first block.
      
      Fixes: ae4a46a1 ("dm cache metadata: use bitset cursor api to load discard bitset")
      Cc: stable@vger.kernel.org
      Signed-off-by: NNikos Tsironis <ntsironis@arrikto.com>
      Signed-off-by: NMike Snitzer <snitzer@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ff0699a5
    • S
      PCI: Work around Pericom PCIe-to-PCI bridge Retrain Link erratum · d5c35230
      Stefan Mätje 提交于
      commit 4ec73791a64bab25cabf16a6067ee478692e506d upstream.
      
      Due to an erratum in some Pericom PCIe-to-PCI bridges in reverse mode
      (conventional PCI on primary side, PCIe on downstream side), the Retrain
      Link bit needs to be cleared manually to allow the link training to
      complete successfully.
      
      If it is not cleared manually, the link training is continuously restarted
      and no devices below the PCI-to-PCIe bridge can be accessed.  That means
      drivers for devices below the bridge will be loaded but won't work and may
      even crash because the driver is only reading 0xffff.
      
      See the Pericom Errata Sheet PI7C9X111SLB_errata_rev1.2_102711.pdf for
      details.  Devices known as affected so far are: PI7C9X110, PI7C9X111SL,
      PI7C9X130.
      
      Add a new flag, clear_retrain_link, in struct pci_dev.  Quirks for affected
      devices set this bit.
      
      Note that pcie_retrain_link() lives in aspm.c because that's currently the
      only place we use it, but this erratum is not specific to ASPM, and we may
      retrain links for other reasons in the future.
      Signed-off-by: NStefan Mätje <stefan.maetje@esd.eu>
      [bhelgaas: apply regardless of CONFIG_PCIEASPM]
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      Reviewed-by: NAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      CC: stable@vger.kernel.org
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d5c35230
    • S
      PCI: Factor out pcie_retrain_link() function · b51a0333
      Stefan Mätje 提交于
      commit 86fa6a344209d9414ea962b1f1ac6ade9dd7563a upstream.
      
      Factor out pcie_retrain_link() to use for Pericom Retrain Link quirk.  No
      functional change intended.
      Signed-off-by: NStefan Mätje <stefan.maetje@esd.eu>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      Reviewed-by: NAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      CC: stable@vger.kernel.org
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b51a0333
    • K
      PCI: rcar: Add the initialization of PCIe link in resume_noirq() · 7bc992e2
      Kazufumi Ikeda 提交于
      commit be20bbcb0a8cb5597cc62b3e28d275919f3431df upstream.
      
      Reestablish the PCIe link very early in the resume process in case it
      went down to prevent PCI accesses from hanging the bus. Such accesses
      can happen early in the PCI resume process, as early as the
      SUSPEND_RESUME_NOIRQ step, thus the link must be reestablished in the
      driver resume_noirq() callback.
      
      Fixes: e015f88c ("PCI: rcar: Add support for R-Car H3 to pcie-rcar")
      Signed-off-by: NKazufumi Ikeda <kaz-ikeda@xc.jp.nec.com>
      Signed-off-by: NGaku Inami <gaku.inami.xw@bp.renesas.com>
      Signed-off-by: NMarek Vasut <marek.vasut+renesas@gmail.com>
      [lorenzo.pieralisi@arm.com: reformatted commit log]
      Signed-off-by: NLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Reviewed-by: NSimon Horman <horms+renesas@verge.net.au>
      Reviewed-by: NGeert Uytterhoeven <geert+renesas@glider.be>
      Acked-by: NWolfram Sang <wsa+renesas@sang-engineering.com>
      Cc: stable@vger.kernel.org
      Cc: Geert Uytterhoeven <geert+renesas@glider.be>
      Cc: Phil Edworthy <phil.edworthy@renesas.com>
      Cc: Simon Horman <horms+renesas@verge.net.au>
      Cc: Wolfram Sang <wsa@the-dreams.de>
      Cc: linux-renesas-soc@vger.kernel.org
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7bc992e2
    • J
      PCI/AER: Change pci_aer_init() stub to return void · 2e757498
      Jisheng Zhang 提交于
      commit 31f996efbd5a7825f4d30150469e9d110aea00e8 upstream.
      
      Commit 60ed982a ("PCI/AER: Move internal declarations to
      drivers/pci/pci.h") changed pci_aer_init() to return "void", but didn't
      change the stub for when CONFIG_PCIEAER isn't enabled.  Change the stub to
      match.
      
      Fixes: 60ed982a ("PCI/AER: Move internal declarations to drivers/pci/pci.h")
      Signed-off-by: NJisheng Zhang <Jisheng.Zhang@synaptics.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      CC: stable@vger.kernel.org	# v4.19+
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2e757498
    • J
      PCI: Init PCIe feature bits for managed host bridge alloc · 8c30e149
      Jean-Philippe Brucker 提交于
      commit 6302bf3ef78dd210b5ff4a922afcb7d8eff8a211 upstream.
      
      Two functions allocate a host bridge: devm_pci_alloc_host_bridge() and
      pci_alloc_host_bridge().  At the moment, only the unmanaged one initializes
      the PCIe feature bits, which prevents from using features such as hotplug
      or AER on some systems, when booting with device tree.  Make the
      initialization code common.
      
      Fixes: 02bfeb48 ("PCI/portdrv: Simplify PCIe feature permission checking")
      Signed-off-by: NJean-Philippe Brucker <jean-philippe.brucker@arm.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      CC: stable@vger.kernel.org	# v4.17+
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8c30e149
    • J
      PCI: Mark Atheros AR9462 to avoid bus reset · 29d03140
      James Prestwood 提交于
      commit 6afb7e26978da5e86e57e540fdce65c8b04f398a upstream.
      
      When using PCI passthrough with this device, the host machine locks up
      completely when starting the VM, requiring a hard reboot.  Add a quirk to
      avoid bus resets on this device.
      
      Fixes: c3e59ee4 ("PCI: Mark Atheros AR93xx to avoid bus reset")
      Link: https://lore.kernel.org/linux-pci/20190107213248.3034-1-james.prestwood@linux.intel.comSigned-off-by: NJames Prestwood <james.prestwood@linux.intel.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      CC: stable@vger.kernel.org	# v3.14+
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      29d03140
    • N
      PCI: Mark AMD Stoney Radeon R7 GPU ATS as broken · f4be6b7e
      Nikolai Kostrigin 提交于
      commit d28ca864c493637f3c957f4ed9348a94fca6de60 upstream.
      
      ATS is broken on the Radeon R7 GPU (at least for Stoney Ridge based laptop)
      and causes IOMMU stalls and system failure.  Disable ATS on these devices
      to make them usable again with IOMMU enabled.
      
      Thanks to Joerg Roedel <jroedel@suse.de> for help.
      
      [bhelgaas: In the email thread mentioned below, Alex suspects the real
      problem is in sbios or iommu, so it may affect only certain systems, and it
      may affect other devices in those systems as well.  However, per Joerg we
      lack the ability to debug further, so this quirk is the best we can do for
      now.]
      
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=194521
      Link: https://lore.kernel.org/lkml/20190408103725.30426-1-nickel@altlinux.org
      Fixes: 9b44b0b0 ("PCI: Mark AMD Stoney GPU ATS as broken")
      Signed-off-by: NNikolai Kostrigin <nickel@altlinux.org>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      Acked-by: NJoerg Roedel <jroedel@suse.de>
      CC: stable@vger.kernel.org
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f4be6b7e
    • Y
      fbdev: sm712fb: fix crashes and garbled display during DPMS modesetting · 2cf1dce1
      Yifeng Li 提交于
      commit f627caf55b8e735dcec8fa6538e9668632b55276 upstream.
      
      On a Thinkpad s30 (Pentium III / i440MX, Lynx3DM), blanking the display
      or starting the X server will crash and freeze the system, or garble the
      display.
      
      Experiments showed this problem can mostly be solved by adjusting the
      order of register writes. Also, sm712fb failed to consider the difference
      of clock frequency when unblanking the display, and programs the clock for
      SM712 to SM720.
      
      Fix them by adjusting the order of register writes, and adding an
      additional check for SM720 for programming the clock frequency.
      Signed-off-by: NYifeng Li <tomli@tomli.me>
      Tested-by: NSudip Mukherjee <sudipm.mukherjee@gmail.com>
      Cc: Teddy Wang <teddy.wang@siliconmotion.com>
      Cc: <stable@vger.kernel.org>  # v4.4+
      Signed-off-by: NBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2cf1dce1
    • Y
      fbdev: sm712fb: use 1024x768 by default on non-MIPS, fix garbled display · 27968d82
      Yifeng Li 提交于
      commit 4ed7d2ccb7684510ec5f7a8f7ef534bc6a3d55b2 upstream.
      
      Loongson MIPS netbooks use 1024x600 LCD panels, which is the original
      target platform of this driver, but nearly all old x86 laptops have
      1024x768. Lighting 768 panels using 600's timings would partially
      garble the display. Since it's not possible to distinguish them reliably,
      we change the default to 768, but keep 600 as-is on MIPS.
      
      Further, earlier laptops, such as IBM Thinkpad 240X, has a 800x600 LCD
      panel, this driver would probably garbled those display. As we don't
      have one for testing, the original behavior of the driver is kept as-is,
      but the problem has been documented is the comments.
      Signed-off-by: NYifeng Li <tomli@tomli.me>
      Tested-by: NSudip Mukherjee <sudipm.mukherjee@gmail.com>
      Cc: Teddy Wang <teddy.wang@siliconmotion.com>
      Cc: <stable@vger.kernel.org>  # v4.4+
      Signed-off-by: NBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      27968d82
    • Y
      fbdev: sm712fb: fix support for 1024x768-16 mode · f1c97f63
      Yifeng Li 提交于
      commit 6053d3a4793e5bde6299ac5388e76a3bf679ff65 upstream.
      
      In order to support the 1024x600 panel on Yeeloong Loongson MIPS
      laptop, the original 1024x768-16 table was modified to 1024x600-16,
      without leaving the original. It causes problem on x86 laptop as
      the 1024x768-16 support was still claimed but not working.
      
      Fix it by introducing the 1024x768-16 mode.
      Signed-off-by: NYifeng Li <tomli@tomli.me>
      Tested-by: NSudip Mukherjee <sudipm.mukherjee@gmail.com>
      Cc: Teddy Wang <teddy.wang@siliconmotion.com>
      Cc: <stable@vger.kernel.org>  # v4.4+
      Signed-off-by: NBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f1c97f63
    • Y
      fbdev: sm712fb: fix crashes during framebuffer writes by correctly mapping VRAM · b415308a
      Yifeng Li 提交于
      commit 9e0e59993df0601cddb95c4f6c61aa3d5e753c00 upstream.
      
      On a Thinkpad s30 (Pentium III / i440MX, Lynx3DM), running fbtest or X
      will crash the machine instantly, because the VRAM/framebuffer is not
      mapped correctly.
      
      On SM712, the framebuffer starts at the beginning of address space, but
      SM720's framebuffer starts at the 1 MiB offset from the beginning. However,
      sm712fb fails to take this into account, as a result, writing to the
      framebuffer will destroy all the registers and kill the system immediately.
      Another problem is the driver assumes 8 MiB of VRAM for SM720, but some
      SM720 system, such as this IBM Thinkpad, only has 4 MiB of VRAM.
      
      Fix this problem by removing the hardcoded VRAM size, adding a function to
      query the amount of VRAM from register MCR76 on SM720, and adding proper
      framebuffer offset.
      
      Please note that the memory map may have additional problems on Big-Endian
      system, which is not available for testing by myself. But I highly suspect
      that the original code is also broken on Big-Endian machines for SM720, so
      at least we are not making the problem worse. More, the driver also assumed
      SM710/SM712 has 4 MiB of VRAM, but it has a 2 MiB version as well, and used
      in earlier laptops, such as IBM Thinkpad 240X, the driver would probably
      crash on them. I've never seen one of those machines and cannot fix it, but
      I have documented these problems in the comments.
      Signed-off-by: NYifeng Li <tomli@tomli.me>
      Tested-by: NSudip Mukherjee <sudipm.mukherjee@gmail.com>
      Cc: Teddy Wang <teddy.wang@siliconmotion.com>
      Cc: <stable@vger.kernel.org>  # v4.4+
      Signed-off-by: NBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b415308a
    • Y
      fbdev: sm712fb: fix boot screen glitch when sm712fb replaces VGA · 02f89dd9
      Yifeng Li 提交于
      commit ec1587d5073f29820e358f3a383850d61601d981 upstream.
      
      When the machine is booted in VGA mode, loading sm712fb would cause
      a glitch of random pixels shown on the screen. To prevent it from
      happening, we first clear the entire framebuffer, and we also need
      to stop calling smtcfb_setmode() during initialization, the fbdev
      layer will call it for us later when it's ready.
      Signed-off-by: NYifeng Li <tomli@tomli.me>
      Tested-by: NSudip Mukherjee <sudipm.mukherjee@gmail.com>
      Cc: Teddy Wang <teddy.wang@siliconmotion.com>
      Cc: <stable@vger.kernel.org>  # v4.4+
      Signed-off-by: NBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      02f89dd9
    • Y
      fbdev: sm712fb: fix white screen of death on reboot, don't set CR3B-CR3F · 7e1b9659
      Yifeng Li 提交于
      commit 8069053880e0ee3a75fd6d7e0a30293265fe3de4 upstream.
      
      On a Thinkpad s30 (Pentium III / i440MX, Lynx3DM), rebooting with
      sm712fb framebuffer driver would cause a white screen of death on
      the next POST, presumably the proper timings for the LCD panel was
      not reprogrammed properly by the BIOS.
      
      Experiments showed a few CRTC Scratch Registers, including CRT3D,
      CRT3E and CRT3F may be used internally by BIOS as some flags. CRT3B is
      a hardware testing register, we shouldn't mess with it. CRT3C has
      blanking signal and line compare control, which is not needed for this
      driver.
      
      Stop writing to CR3B-CR3F (a.k.a CRT3B-CRT3F) registers. Even if these
      registers don't have side-effect on other systems, writing to them is
      also highly questionable.
      Signed-off-by: NYifeng Li <tomli@tomli.me>
      Tested-by: NSudip Mukherjee <sudipm.mukherjee@gmail.com>
      Cc: Teddy Wang <teddy.wang@siliconmotion.com>
      Cc: <stable@vger.kernel.org>  # v4.4+
      Signed-off-by: NBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7e1b9659
    • Y
      fbdev: sm712fb: fix VRAM detection, don't set SR70/71/74/75 · b0f08070
      Yifeng Li 提交于
      commit dcf9070595e100942c539e229dde4770aaeaa4e9 upstream.
      
      On a Thinkpad s30 (Pentium III / i440MX, Lynx3DM), the amount of Video
      RAM is not detected correctly by the xf86-video-siliconmotion driver.
      This is because sm712fb overwrites the GPR71 Scratch Pad Register, which
      is set by BIOS on x86 and used to indicate amount of VRAM.
      
      Other Scratch Pad Registers, including GPR70/74/75, don't have the same
      side-effect, but overwriting to them is still questionable, as they are
      not related to modesetting.
      
      Stop writing to SR70/71/74/75 (a.k.a GPR70/71/74/75).
      Signed-off-by: NYifeng Li <tomli@tomli.me>
      Tested-by: NSudip Mukherjee <sudipm.mukherjee@gmail.com>
      Cc: Teddy Wang <teddy.wang@siliconmotion.com>
      Cc: <stable@vger.kernel.org>  # v4.4+
      Signed-off-by: NBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b0f08070
    • Y
      fbdev: sm712fb: fix brightness control on reboot, don't set SR30 · d3076897
      Yifeng Li 提交于
      commit 5481115e25e42b9215f2619452aa99c95f08492f upstream.
      
      On a Thinkpad s30 (Pentium III / i440MX, Lynx3DM), rebooting with
      sm712fb framebuffer driver would cause the role of brightness up/down
      button to swap.
      
      Experiments showed the FPR30 register caused this behavior. Moreover,
      even if this register don't have side-effect on other systems, over-
      writing it is also highly questionable, since it was originally
      configurated by the motherboard manufacturer by hardwiring pull-down
      resistors to indicate the type of LCD panel. We should not mess with
      it.
      
      Stop writing to the SR30 (a.k.a FPR30) register.
      Signed-off-by: NYifeng Li <tomli@tomli.me>
      Tested-by: NSudip Mukherjee <sudipm.mukherjee@gmail.com>
      Cc: Teddy Wang <teddy.wang@siliconmotion.com>
      Cc: <stable@vger.kernel.org>  # v4.4+
      Signed-off-by: NBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d3076897
    • A
      fbdev/efifb: Ignore framebuffer memmap entries that lack any memory types · 702156cd
      Ard Biesheuvel 提交于
      commit f8585539df0a1527c78b5d760665c89fe1c105a9 upstream.
      
      The following commit:
      
        38ac0287 ("fbdev/efifb: Honour UEFI memory map attributes when mapping the FB")
      
      updated the EFI framebuffer code to use memory mappings for the linear
      framebuffer that are permitted by the memory attributes described by the
      EFI memory map for the particular region, if the framebuffer happens to
      be covered by the EFI memory map (which is typically only the case for
      framebuffers in shared memory). This is required since non-x86 systems
      may require cacheable attributes for memory mappings that are shared
      with other masters (such as GPUs), and this information cannot be
      described by the Graphics Output Protocol (GOP) EFI protocol itself,
      and so we rely on the EFI memory map for this.
      
      As reported by James, this breaks some x86 systems:
      
        [ 1.173368] efifb: probing for efifb
        [ 1.173386] efifb: abort, cannot remap video memory 0x1d5000 @ 0xcf800000
        [ 1.173395] Trying to free nonexistent resource <00000000cf800000-00000000cf9d4bff>
        [ 1.173413] efi-framebuffer: probe of efi-framebuffer.0 failed with error -5
      
      The problem turns out to be that the memory map entry that describes the
      framebuffer has no memory attributes listed at all, and so we end up with
      a mem_flags value of 0x0.
      
      So work around this by ensuring that the memory map entry's attribute field
      has a sane value before using it to mask the set of usable attributes.
      Reported-by: NJames Hilliard <james.hilliard1@gmail.com>
      Tested-by: NJames Hilliard <james.hilliard1@gmail.com>
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: <stable@vger.kernel.org> # v4.19+
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: James Morse <james.morse@arm.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Matt Fleming <matt@codeblueprint.co.uk>
      Cc: Peter Jones <pjones@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: linux-efi@vger.kernel.org
      Fixes: 38ac0287 ("fbdev/efifb: Honour UEFI memory map attributes when ...")
      Link: http://lkml.kernel.org/r/20190516213159.3530-2-ard.biesheuvel@linaro.orgSigned-off-by: NIngo Molnar <mingo@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      702156cd
    • N
      objtool: Allow AR to be overridden with HOSTAR · e738fb38
      Nathan Chancellor 提交于
      commit 8ea58f1e8b11cca3087b294779bf5959bf89cc10 upstream.
      
      Currently, this Makefile hardcodes GNU ar, meaning that if it is not
      available, there is no way to supply a different one and the build will
      fail.
      
        $ make AR=llvm-ar CC=clang LD=ld.lld HOSTAR=llvm-ar HOSTCC=clang \
               HOSTLD=ld.lld HOSTLDFLAGS=-fuse-ld=lld defconfig modules_prepare
        ...
          AR       /out/tools/objtool/libsubcmd.a
        /bin/sh: 1: ar: not found
        ...
      
      Follow the logic of HOST{CC,LD} and allow the user to specify a
      different ar tool via HOSTAR (which is used elsewhere in other
      tools/ Makefiles).
      Signed-off-by: NNathan Chancellor <natechancellor@gmail.com>
      Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Reviewed-by: NNick Desaulniers <ndesaulniers@google.com>
      Reviewed-by: NMukesh Ojha <mojha@codeaurora.org>
      Cc: <stable@vger.kernel.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: http://lkml.kernel.org/r/80822a9353926c38fd7a152991c6292491a9d0e8.1558028966.git.jpoimboe@redhat.com
      Link: https://github.com/ClangBuiltLinux/linux/issues/481Signed-off-by: NIngo Molnar <mingo@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e738fb38
    • F
      MIPS: perf: Fix build with CONFIG_CPU_BMIPS5000 enabled · 9ae0f86c
      Florian Fainelli 提交于
      commit 1b1f01b653b408ebe58fec78c566d1075d285c64 upstream.
      
      arch/mips/kernel/perf_event_mipsxx.c: In function 'mipsxx_pmu_enable_event':
      arch/mips/kernel/perf_event_mipsxx.c:326:21: error: unused variable 'event' [-Werror=unused-variable]
        struct perf_event *event = container_of(evt, struct perf_event, hw);
                           ^~~~~
      
      Fix this by making use of IS_ENABLED() to simplify the code and avoid
      unnecessary ifdefery.
      
      Fixes: 84002c88 ("MIPS: perf: Fix perf with MT counting other threads")
      Signed-off-by: NFlorian Fainelli <f.fainelli@gmail.com>
      Signed-off-by: NPaul Burton <paul.burton@mips.com>
      Cc: linux-mips@linux-mips.org
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Cc: James Hogan <jhogan@kernel.org>
      Cc: linux-kernel@vger.kernel.org
      Cc: linux-mips@vger.kernel.org
      Cc: stable@vger.kernel.org # v4.18+
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9ae0f86c
    • A
      perf intel-pt: Fix sample timestamp wrt non-taken branches · 05fab345
      Adrian Hunter 提交于
      commit 1b6599a9d8e6c9f7e9b0476012383b1777f7fc93 upstream.
      
      The sample timestamp is updated to ensure that the timestamp represents
      the time of the sample and not a branch that the decoder is still
      walking towards. The sample timestamp is updated when the decoder
      returns, but the decoder does not return for non-taken branches. Update
      the sample timestamp then also.
      
      Note that commit 3f04d98e ("perf intel-pt: Improve sample
      timestamp") was also a stable fix and appears, for example, in v4.4
      stable tree as commit a4ebb58fd124 ("perf intel-pt: Improve sample
      timestamp").
      Signed-off-by: NAdrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: stable@vger.kernel.org # v4.4+
      Fixes: 3f04d98e ("perf intel-pt: Improve sample timestamp")
      Link: http://lkml.kernel.org/r/20190510124143.27054-4-adrian.hunter@intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      05fab345
    • A
      perf intel-pt: Fix improved sample timestamp · ba86f8f8
      Adrian Hunter 提交于
      commit 61b6e08dc8e3ea80b7485c9b3f875ddd45c8466b upstream.
      
      The decoder uses its current timestamp in samples. Usually that is a
      timestamp that has already passed, but in some cases it is a timestamp
      for a branch that the decoder is walking towards, and consequently
      hasn't reached.
      
      The intel_pt_sample_time() function decides which is which, but was not
      handling TNT packets exactly correctly.
      
      In the case of TNT, the timestamp applies to the first branch, so the
      decoder must first walk to that branch.
      
      That means intel_pt_sample_time() should return true for TNT, and this
      patch makes that change. However, if the first branch is a non-taken
      branch (i.e. a 'N'), then intel_pt_sample_time() needs to return false
      for subsequent taken branches in the same TNT packet.
      
      To handle that, introduce a new state INTEL_PT_STATE_TNT_CONT to
      distinguish the cases.
      
      Note that commit 3f04d98e ("perf intel-pt: Improve sample
      timestamp") was also a stable fix and appears, for example, in v4.4
      stable tree as commit a4ebb58fd124 ("perf intel-pt: Improve sample
      timestamp").
      Signed-off-by: NAdrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: stable@vger.kernel.org # v4.4+
      Fixes: 3f04d98e ("perf intel-pt: Improve sample timestamp")
      Link: http://lkml.kernel.org/r/20190510124143.27054-3-adrian.hunter@intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ba86f8f8
    • A
      perf intel-pt: Fix instructions sampling rate · 3ed850ab
      Adrian Hunter 提交于
      commit 7ba8fa20e26eb3c0c04d747f7fd2223694eac4d5 upstream.
      
      The timestamp used to determine if an instruction sample is made, is an
      estimate based on the number of instructions since the last known
      timestamp. A consequence is that it might go backwards, which results in
      extra samples. Change it so that a sample is only made when the
      timestamp goes forwards.
      
      Note this does not affect a sampling period of 0 or sampling periods
      specified as a count of instructions.
      
      Example:
      
       Before:
      
       $ perf script --itrace=i10us
       ls 13812 [003] 2167315.222583:       3270 instructions:u:      7fac71e2e494 __GI___tunables_init+0xf4 (/lib/x86_64-linux-gnu/ld-2.28.so)
       ls 13812 [003] 2167315.222667:      30902 instructions:u:      7fac71e2da0f _dl_cache_libcmp+0x2f (/lib/x86_64-linux-gnu/ld-2.28.so)
       ls 13812 [003] 2167315.222667:         10 instructions:u:      7fac71e2d9ff _dl_cache_libcmp+0x1f (/lib/x86_64-linux-gnu/ld-2.28.so)
       ls 13812 [003] 2167315.222667:          8 instructions:u:      7fac71e2d9ea _dl_cache_libcmp+0xa (/lib/x86_64-linux-gnu/ld-2.28.so)
       ls 13812 [003] 2167315.222667:         14 instructions:u:      7fac71e2d9ea _dl_cache_libcmp+0xa (/lib/x86_64-linux-gnu/ld-2.28.so)
       ls 13812 [003] 2167315.222667:          6 instructions:u:      7fac71e2d9ff _dl_cache_libcmp+0x1f (/lib/x86_64-linux-gnu/ld-2.28.so)
       ls 13812 [003] 2167315.222667:         14 instructions:u:      7fac71e2d9ff _dl_cache_libcmp+0x1f (/lib/x86_64-linux-gnu/ld-2.28.so)
       ls 13812 [003] 2167315.222667:          4 instructions:u:      7fac71e2dab2 _dl_cache_libcmp+0xd2 (/lib/x86_64-linux-gnu/ld-2.28.so)
       ls 13812 [003] 2167315.222728:      16423 instructions:u:      7fac71e2477a _dl_map_object_deps+0x1ba (/lib/x86_64-linux-gnu/ld-2.28.so)
       ls 13812 [003] 2167315.222734:      12731 instructions:u:      7fac71e27938 _dl_name_match_p+0x68 (/lib/x86_64-linux-gnu/ld-2.28.so)
       ...
      
       After:
       $ perf script --itrace=i10us
       ls 13812 [003] 2167315.222583:       3270 instructions:u:      7fac71e2e494 __GI___tunables_init+0xf4 (/lib/x86_64-linux-gnu/ld-2.28.so)
       ls 13812 [003] 2167315.222667:      30902 instructions:u:      7fac71e2da0f _dl_cache_libcmp+0x2f (/lib/x86_64-linux-gnu/ld-2.28.so)
       ls 13812 [003] 2167315.222728:      16479 instructions:u:      7fac71e2477a _dl_map_object_deps+0x1ba (/lib/x86_64-linux-gnu/ld-2.28.so)
       ...
      Signed-off-by: NAdrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: stable@vger.kernel.org
      Fixes: f4aa0819 ("perf tools: Add Intel PT decoder")
      Link: http://lkml.kernel.org/r/20190510124143.27054-2-adrian.hunter@intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3ed850ab
    • D
      memory: tegra: Fix integer overflow on tick value calculation · 5e011f33
      Dmitry Osipenko 提交于
      commit b906c056b6023c390f18347169071193fda57dde upstream.
      
      Multiplying the Memory Controller clock rate by the tick count results
      in an integer overflow and in result the truncated tick value is being
      programmed into hardware, such that the GR3D memory client performance is
      reduced by two times.
      
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NDmitry Osipenko <digetx@gmail.com>
      Signed-off-by: NThierry Reding <treding@nvidia.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5e011f33
    • E
      tracing: Fix partial reading of trace event's id file · fb8c9c90
      Elazar Leibovich 提交于
      commit cbe08bcbbe787315c425dde284dcb715cfbf3f39 upstream.
      
      When reading only part of the id file, the ppos isn't tracked correctly.
      This is taken care by simple_read_from_buffer.
      
      Reading a single byte, and then the next byte would result EOF.
      
      While this seems like not a big deal, this breaks abstractions that
      reads information from files unbuffered. See for example
      https://github.com/golang/go/issues/29399
      
      This code was mentioned as problematic in
      commit cd458ba9
      ("tracing: Do not (ab)use trace_seq in event_id_read()")
      
      An example C code that show this bug is:
      
        #include <stdio.h>
        #include <stdint.h>
      
        #include <sys/types.h>
        #include <sys/stat.h>
        #include <fcntl.h>
        #include <unistd.h>
      
        int main(int argc, char **argv) {
          if (argc < 2)
            return 1;
          int fd = open(argv[1], O_RDONLY);
          char c;
          read(fd, &c, 1);
          printf("First  %c\n", c);
          read(fd, &c, 1);
          printf("Second %c\n", c);
        }
      
      Then run with, e.g.
      
        sudo ./a.out /sys/kernel/debug/tracing/events/tcp/tcp_set_state/id
      
      You'll notice you're getting the first character twice, instead of the
      first two characters in the id file.
      
      Link: http://lkml.kernel.org/r/20181231115837.4932-1-elazar@lightbitslabs.com
      
      Cc: Orit Wasserman <orit.was@gmail.com>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: stable@vger.kernel.org
      Fixes: 23725aee ("ftrace: provide an id file for each event")
      Signed-off-by: NElazar Leibovich <elazar@lightbitslabs.com>
      Signed-off-by: NSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fb8c9c90