1. 29 Aug, 2013 40 commits
    • Martin Peschke's avatar
      SCSI: zfcp: fix lock imbalance by reworking request queue locking · bda5d1ef
      Martin Peschke authored
      commit d79ff142 upstream.
      
      This patch adds wait_event_interruptible_lock_irq_timeout(), which is a
      straight-forward descendant of wait_event_interruptible_timeout() and
      wait_event_interruptible_lock_irq().
      
      The zfcp driver used to call wait_event_interruptible_timeout()
      in combination with some intricate and error-prone locking. Using
      wait_event_interruptible_lock_irq_timeout() as a replacement
      nicely cleans up that locking.
      
      This rework removes a situation that resulted in a locking imbalance
      in zfcp_qdio_sbal_get():
      
      BUG: workqueue leaked lock or atomic: events/1/0xffffff00/10
          last function: zfcp_fc_wka_port_offline+0x0/0xa0 [zfcp]
      
      It was introduced by commit c2af7545
      "[SCSI] zfcp: Do not wait for SBALs on stopped queue", which had a new
      code path related to ZFCP_STATUS_ADAPTER_QDIOUP that took an early exit
      without a required lock being held. The problem occured when a
      special, non-SCSI I/O request was being submitted in process context,
      when the adapter's queues had been torn down. In this case the bug
      surfaced when the Fibre Channel port connection for a well-known address
      was closed during a concurrent adapter shut-down procedure, which is a
      rare constellation.
      
      This patch also fixes these warnings from the sparse tool (make C=1):
      
      drivers/s390/scsi/zfcp_qdio.c:224:12: warning: context imbalance in
       'zfcp_qdio_sbal_check' - wrong count at exit
      drivers/s390/scsi/zfcp_qdio.c:244:5: warning: context imbalance in
       'zfcp_qdio_sbal_get' - unexpected unlock
      
      Last but not least, we get rid of that crappy lock-unlock-lock
      sequence at the beginning of the critical section.
      
      It is okay to call zfcp_erp_adapter_reopen() with req_q_lock held.
      Reported-by: default avatarMikulas Patocka <mpatocka@redhat.com>
      Reported-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
      Signed-off-by: default avatarMartin Peschke <mpeschke@linux.vnet.ibm.com>
      Signed-off-by: default avatarSteffen Maier <maier@linux.vnet.ibm.com>
      Signed-off-by: default avatarJames Bottomley <JBottomley@Parallels.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bda5d1ef
    • Emmanuel Grumbach's avatar
      iwlwifi: pcie: disable L1 Active after pci_enable_device · 67bdd3c0
      Emmanuel Grumbach authored
      commit eabc4ac5 upstream.
      
      As Arjan pointed out, we mustn't do anything related to PCI
      configuration until the device is properly enabled with
      pci_enable_device().
      Reported-by: default avatarArjan van de Ven <arjan@linux.intel.com>
      Signed-off-by: default avatarEmmanuel Grumbach <emmanuel.grumbach@intel.com>
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      67bdd3c0
    • Stanislaw Gruszka's avatar
      iwlwifi: dvm: fix calling ieee80211_chswitch_done() with NULL · 753fb619
      Stanislaw Gruszka authored
      commit 9186a1fd upstream.
      
      If channel switch is pending and we remove interface we can
      crash like showed below due to passing NULL vif to mac80211:
      
      BUG: unable to handle kernel paging request at fffffffffffff8cc
      IP: [<ffffffff8130924d>] strnlen+0xd/0x40
      Call Trace:
       [<ffffffff8130ad2e>] string.isra.3+0x3e/0xd0
       [<ffffffff8130bf99>] vsnprintf+0x219/0x640
       [<ffffffff8130c481>] vscnprintf+0x11/0x30
       [<ffffffff81061585>] vprintk_emit+0x115/0x4f0
       [<ffffffff81657bd5>] printk+0x61/0x63
       [<ffffffffa048987f>] ieee80211_chswitch_done+0xaf/0xd0 [mac80211]
       [<ffffffffa04e7b34>] iwl_chswitch_done+0x34/0x40 [iwldvm]
       [<ffffffffa04f83c3>] iwlagn_commit_rxon+0x2a3/0xdc0 [iwldvm]
       [<ffffffffa04ebc50>] ? iwlagn_set_rxon_chain+0x180/0x2c0 [iwldvm]
       [<ffffffffa04e5e76>] iwl_set_mode+0x36/0x40 [iwldvm]
       [<ffffffffa04e5f0d>] iwlagn_mac_remove_interface+0x8d/0x1b0 [iwldvm]
       [<ffffffffa0459b3d>] ieee80211_do_stop+0x29d/0x7f0 [mac80211]
      
      This is because we nulify ctx->vif in iwlagn_mac_remove_interface()
      before calling some other functions that teardown interface. To fix
      just check ctx->vif on iwl_chswitch_done(). We should not call
      ieee80211_chswitch_done() as channel switch works were already canceled
      by mac80211 in ieee80211_do_stop() -> ieee80211_mgd_stop().
      
      Resolve:
      https://bugzilla.redhat.com/show_bug.cgi?id=979581Reported-by: default avatarLukasz Jagiello <jagiello.lukasz@gmail.com>
      Signed-off-by: default avatarStanislaw Gruszka <sgruszka@redhat.com>
      Reviewed-by: default avatarEmmanuel Grumbach <emmanuel.grumbach@intel.com>
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      753fb619
    • Terry Suereth's avatar
      libata: apply behavioral quirks to sil3826 PMP · 323d5a7b
      Terry Suereth authored
      commit 8ffff94d upstream.
      
      Fixing support for the Silicon Image 3826 port multiplier, by applying
      to it the same quirks applied to the Silicon Image 3726.  Specifically
      fixes the repeated timeout/reset process which previously afflicted
      the 3726, as described from line 290.  Slightly based on notes from:
      
      https://bugzilla.redhat.com/show_bug.cgi?id=890237Signed-off-by: default avatarTerry Suereth <terry.suereth@gmail.com>
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      323d5a7b
    • Dan Carpenter's avatar
      Hostap: copying wrong data prism2_ioctl_giwaplist() · 9e50b0dd
      Dan Carpenter authored
      commit 909bd592 upstream.
      
      We want the data stored in "addr" and "qual", but the extra ampersands
      mean we are copying stack data instead.
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
      Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9e50b0dd
    • Anthony Foiani's avatar
      sata_fsl: save irqs while coalescing · 2650a684
      Anthony Foiani authored
      commit 99bbdfa6 upstream.
      
      Before this patch, I was seeing the following lockdep splat on my
      MPC8315 (PPC32) target:
      
        [    9.086051] =================================
        [    9.090393] [ INFO: inconsistent lock state ]
        [    9.094744] 3.9.7-ajf-gc39503d #1 Not tainted
        [    9.099087] ---------------------------------
        [    9.103432] inconsistent {HARDIRQ-ON-W} -> {IN-HARDIRQ-W} usage.
        [    9.109431] scsi_eh_1/39 [HC1[1]:SC0[0]:HE0:SE1] takes:
        [    9.114642]  (&(&host->lock)->rlock){?.+...}, at: [<c02f4168>] sata_fsl_interrupt+0x50/0x250
        [    9.123137] {HARDIRQ-ON-W} state was registered at:
        [    9.128004]   [<c006cdb8>] lock_acquire+0x90/0xf4
        [    9.132737]   [<c043ef04>] _raw_spin_lock+0x34/0x4c
        [    9.137645]   [<c02f3560>] fsl_sata_set_irq_coalescing+0x68/0x100
        [    9.143750]   [<c02f36a0>] sata_fsl_init_controller+0xa8/0xc0
        [    9.149505]   [<c02f3f10>] sata_fsl_probe+0x17c/0x2e8
        [    9.154568]   [<c02acc90>] driver_probe_device+0x90/0x248
        [    9.159987]   [<c02acf0c>] __driver_attach+0xc4/0xc8
        [    9.164964]   [<c02aae74>] bus_for_each_dev+0x5c/0xa8
        [    9.170028]   [<c02ac218>] bus_add_driver+0x100/0x26c
        [    9.175091]   [<c02ad638>] driver_register+0x88/0x198
        [    9.180155]   [<c0003a24>] do_one_initcall+0x58/0x1b4
        [    9.185226]   [<c05aeeac>] kernel_init_freeable+0x118/0x1c0
        [    9.190823]   [<c0004110>] kernel_init+0x18/0x108
        [    9.195542]   [<c000f6b8>] ret_from_kernel_thread+0x64/0x6c
        [    9.201142] irq event stamp: 160
        [    9.204366] hardirqs last  enabled at (159): [<c043f778>] _raw_spin_unlock_irq+0x30/0x50
        [    9.212469] hardirqs last disabled at (160): [<c000f414>] reenable_mmu+0x30/0x88
        [    9.219867] softirqs last  enabled at (144): [<c002ae5c>] __do_softirq+0x168/0x218
        [    9.227435] softirqs last disabled at (137): [<c002b0d4>] irq_exit+0xa8/0xb4
        [    9.234481]
        [    9.234481] other info that might help us debug this:
        [    9.240995]  Possible unsafe locking scenario:
        [    9.240995]
        [    9.246898]        CPU0
        [    9.249337]        ----
        [    9.251776]   lock(&(&host->lock)->rlock);
        [    9.255878]   <Interrupt>
        [    9.258492]     lock(&(&host->lock)->rlock);
        [    9.262765]
        [    9.262765]  *** DEADLOCK ***
        [    9.262765]
        [    9.268684] no locks held by scsi_eh_1/39.
        [    9.272767]
        [    9.272767] stack backtrace:
        [    9.277117] Call Trace:
        [    9.279589] [cfff9da0] [c0008504] show_stack+0x48/0x150 (unreliable)
        [    9.285972] [cfff9de0] [c0447d5c] print_usage_bug.part.35+0x268/0x27c
        [    9.292425] [cfff9e10] [c006ace4] mark_lock+0x2ac/0x658
        [    9.297660] [cfff9e40] [c006b7e4] __lock_acquire+0x754/0x1840
        [    9.303414] [cfff9ee0] [c006cdb8] lock_acquire+0x90/0xf4
        [    9.308745] [cfff9f20] [c043ef04] _raw_spin_lock+0x34/0x4c
        [    9.314250] [cfff9f30] [c02f4168] sata_fsl_interrupt+0x50/0x250
        [    9.320187] [cfff9f70] [c0079ff0] handle_irq_event_percpu+0x90/0x254
        [    9.326547] [cfff9fc0] [c007a1fc] handle_irq_event+0x48/0x78
        [    9.332220] [cfff9fe0] [c007c95c] handle_level_irq+0x9c/0x104
        [    9.337981] [cfff9ff0] [c000d978] call_handle_irq+0x18/0x28
        [    9.343568] [cc7139f0] [c000608c] do_IRQ+0xf0/0x1a8
        [    9.348464] [cc713a20] [c000fc8c] ret_from_except+0x0/0x14
        [    9.353983] --- Exception: 501 at _raw_spin_unlock_irq+0x40/0x50
        [    9.353983]     LR = _raw_spin_unlock_irq+0x30/0x50
        [    9.364839] [cc713af0] [c043db10] wait_for_common+0xac/0x188
        [    9.370513] [cc713b30] [c02ddee4] ata_exec_internal_sg+0x2b0/0x4f0
        [    9.376699] [cc713be0] [c02de18c] ata_exec_internal+0x68/0xa8
        [    9.382454] [cc713c20] [c02de4b8] ata_dev_read_id+0x158/0x594
        [    9.388205] [cc713ca0] [c02ec244] ata_eh_recover+0xd88/0x13d0
        [    9.393962] [cc713d20] [c02f2520] sata_pmp_error_handler+0xc0/0x8ac
        [    9.400234] [cc713dd0] [c02ecdc8] ata_scsi_port_error_handler+0x464/0x5e8
        [    9.407023] [cc713e10] [c02ecfd0] ata_scsi_error+0x84/0xb8
        [    9.412528] [cc713e40] [c02c4974] scsi_error_handler+0xd8/0x47c
        [    9.418457] [cc713eb0] [c004737c] kthread+0xa8/0xac
        [    9.423355] [cc713f40] [c000f6b8] ret_from_kernel_thread+0x64/0x6c
      
      This fix was suggested by Bhushan Bharat <R65777@freescale.com>, and
      was discussed in email at:
      
        http://linuxppc.10917.n7.nabble.com/MPC8315-reboot-failure-lockdep-splat-possibly-related-tp75162.html
      
      Same patch successfully tested with 3.9.7.  linux-next compiled but
      not tested on hardware.
      
      This patch is based off linux-next tag next-20130819
      (which is commit 66a01bae29d11916c09f9f5a937cafe7d402e4a5 )
      Signed-off-by: default avatarAnthony Foiani <anthony.foiani@gmail.com>
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2650a684
    • Anatolij Gustschin's avatar
      usb: phy: fix build breakage · 2356788f
      Anatolij Gustschin authored
      commit 52d5b9ab upstream.
      
      Commit 94ae9843 (usb: phy: rename all phy drivers to phy-$name-usb.c)
      renamed drivers/usb/phy/otg_fsm.h to drivers/usb/phy/phy-fsm-usb.h
      but changed drivers/usb/phy/phy-fsm-usb.c to include not existing
      "phy-otg-fsm.h" instead of new "phy-fsm-usb.h". This breaks building:
        ...
        drivers/usb/phy/phy-fsm-usb.c:32:25: fatal error: phy-otg-fsm.h: No such file or directory
        compilation terminated.
        make[3]: *** [drivers/usb/phy/phy-fsm-usb.o] Error 1
      
      This commit also missed to modify drivers/usb/phy/phy-fsl-usb.h
      to include new "phy-fsm-usb.h" instead of "otg_fsm.h" resulting
      in another build breakage:
        ...
        In file included from drivers/usb/phy/phy-fsl-usb.c:46:0:
        drivers/usb/phy/phy-fsl-usb.h:18:21: fatal error: otg_fsm.h: No such file or directory
        compilation terminated.
        make[3]: *** [drivers/usb/phy/phy-fsl-usb.o] Error 1
      
      Fix both issues.
      Signed-off-by: default avatarAnatolij Gustschin <agust@denx.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2356788f
    • Daniel Drake's avatar
      drivers/platform/olpc/olpc-ec.c: initialise earlier · 6797361e
      Daniel Drake authored
      commit 93dbc1b3 upstream.
      
      Being a low-level component, various drivers (e.g.  olpc-battery) assume
      that it is ok to communicate with the OLPC Embedded Controller during
      probe.  Therefore the OLPC EC driver must be initialised before other
      drivers try to use it.  This was the case until it was recently moved
      out of arch/x86 and restructured around commits ac250415 ("Platform:
      OLPC: turn EC driver into a platform_driver") and 85f90cf6 ("x86:
      OLPC: switch over to using new EC driver on x86").
      
      Use arch_initcall so that olpc-ec is readied earlier, matching the
      previous behaviour.
      
      Fixes a regression introduced in Linux-3.6 where various drivers such as
      olpc-battery and olpc-xo1-sci failed to load due to an inability to
      communicate with the EC.  The user-visible effect was a lack of battery
      monitoring, missing ebook/lid switch input devices, etc.
      Signed-off-by: default avatarDaniel Drake <dsd@laptop.org>
      Cc: Andres Salomon <dilinger@queued.net>
      Cc: Paul Fox <pgf@laptop.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6797361e
    • Vyacheslav Dubeyko's avatar
      nilfs2: fix issue with counting number of bio requests for BIO_EOPNOTSUPP error detection · 020269d2
      Vyacheslav Dubeyko authored
      commit 4bf93b50 upstream.
      
      Fix the issue with improper counting number of flying bio requests for
      BIO_EOPNOTSUPP error detection case.
      
      The sb_nbio must be incremented exactly the same number of times as
      complete() function was called (or will be called) because
      nilfs_segbuf_wait() will call wail_for_completion() for the number of
      times set to sb_nbio:
      
        do {
            wait_for_completion(&segbuf->sb_bio_event);
        } while (--segbuf->sb_nbio > 0);
      
      Two functions complete() and wait_for_completion() must be called the
      same number of times for the same sb_bio_event.  Otherwise,
      wait_for_completion() will hang or leak.
      Signed-off-by: default avatarVyacheslav Dubeyko <slava@dubeyko.com>
      Cc: Dan Carpenter <dan.carpenter@oracle.com>
      Acked-by: default avatarRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
      Tested-by: default avatarRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      020269d2
    • Vyacheslav Dubeyko's avatar
      nilfs2: remove double bio_put() in nilfs_end_bio_write() for BIO_EOPNOTSUPP error · b0e01ab2
      Vyacheslav Dubeyko authored
      commit 2df37a19 upstream.
      
      Remove double call of bio_put() in nilfs_end_bio_write() for the case of
      BIO_EOPNOTSUPP error detection.  The issue was found by Dan Carpenter
      and he suggests first version of the fix too.
      Signed-off-by: default avatarVyacheslav Dubeyko <slava@dubeyko.com>
      Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
      Acked-by: default avatarRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
      Tested-by: default avatarRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b0e01ab2
    • Wladislav Wiebe's avatar
      of: fdt: fix memory initialization for expanded DT · abcdf87c
      Wladislav Wiebe authored
      commit 9e401275 upstream.
      
      Already existing property flags are filled wrong for properties created from
      initial FDT. This could cause problems if this DYNAMIC device-tree functions
      are used later, i.e. properties are attached/detached/replaced. Simply dumping
      flags from the running system show, that some initial static (not allocated via
      kzmalloc()) nodes are marked as dynamic.
      
      I putted some debug extensions to property_proc_show(..) :
      ..
      +       if (OF_IS_DYNAMIC(pp))
      +               pr_err("DEBUG: xxx : OF_IS_DYNAMIC\n");
      +       if (OF_IS_DETACHED(pp))
      +               pr_err("DEBUG: xxx : OF_IS_DETACHED\n");
      
      when you operate on the nodes (e.g.: ~$ cat /proc/device-tree/*some_node*) you
      will see that those flags are filled wrong, basically in most cases it will dump
      a DYNAMIC or DETACHED status, which is in not true.
      (BTW. this OF_IS_DETACHED is a own define for debug purposes which which just
      make a test_bit(OF_DETACHED, &x->_flags)
      
      If nodes are dynamic kernel is allowed to kfree() them. But it will crash
      attempting to do so on the nodes from FDT -- they are not allocated via
      kzmalloc().
      Signed-off-by: default avatarWladislav Wiebe <wladislav.kw@gmail.com>
      Acked-by: default avatarAlexander Sverdlin <alexander.sverdlin@nsn.com>
      Signed-off-by: default avatarRob Herring <rob.herring@calxeda.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      abcdf87c
    • Chris Wilson's avatar
      drm/i915: Invalidate TLBs for the rings after a reset · ce04434c
      Chris Wilson authored
      commit 884020bf upstream.
      
      After any "soft gfx reset" we must manually invalidate the TLBs
      associated with each ring. Empirically, it seems that a
      suspend/resume or D3-D0 cycle count as a "soft reset". The symptom is
      that the hardware would fail to note the new address for its status
      page, and so it would continue to write the shadow registers and
      breadcrumbs into the old physical address (now used by something
      completely different, scary). Whereas the driver would read the new
      status page and never see any progress, it would appear that the GPU
      hung immediately upon resume.
      
      Based on a patch by naresh kumar kachhi <naresh.kumar.kacchi@intel.com>
      Reported-by: default avatarThiago Macieira <thiago@kde.org>
      Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=64725Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
      Tested-by: default avatarThiago Macieira <thiago@kde.org>
      Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ce04434c
    • Rafał Miłecki's avatar
      drm/radeon: fix WREG32_OR macro setting bits in a register · 749e7bff
      Rafał Miłecki authored
      commit d43a93c8 upstream.
      
      This bug (introduced in 3.10) in WREG32_OR made
      commit d3418eac
      "drm/radeon/evergreen: setup HDMI before enabling it"
      cause a regression. Sometimes audio over HDMI wasn't working, sometimes
      display was corrupted.
      
      This fixes:
      https://bugzilla.kernel.org/show_bug.cgi?id=60687
      https://bugzilla.kernel.org/show_bug.cgi?id=60709
      https://bugs.freedesktop.org/show_bug.cgi?id=67767Signed-off-by: default avatarRafał Miłecki <zajec5@gmail.com>
      Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      749e7bff
    • Christian König's avatar
      drm/radeon: fix UVD message buffer validation · 21779249
      Christian König authored
      commit 112a6d0c upstream.
      
      When the message buffer is currently moving block until it is idle again.
      Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
      Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      21779249
    • Alex Deucher's avatar
      drm/radeon/r7xx: fix copy paste typo in golden register setup · 6a33cbd0
      Alex Deucher authored
      commit 022374c0 upstream.
      
      Uses the wrong array size for some asics which can lead
      to garbage getting written to registers.
      
      Fixes:
      https://bugzilla.kernel.org/show_bug.cgi?id=60674Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6a33cbd0
    • Ian Abbott's avatar
      staging: comedi: bug-fix NULL pointer dereference on failed attach · 6f123e95
      Ian Abbott authored
      commit 3955dfa8 upstream.
      
      Commit dcd7b8bd ("staging: comedi: put
      module _after_ detach" by myself) reversed a couple of calls in
      `comedi_device_attach()` when recovering from an error returned by the
      low-level driver's 'attach' handler.  Unfortunately, that introduced a
      NULL pointer dereference bug as `dev->driver` is NULL after the call to
      `comedi_device_detach()`.   We still have a pointer to the low-level
      comedi driver structure in the `driv` variable, so use that instead.
      Signed-off-by: default avatarIan Abbott <abbotti@mev.co.uk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6f123e95
    • Nicolas Pitre's avatar
      ARM: 7816/1: CONFIG_KUSER_HELPERS: fix help text · 90dbc54a
      Nicolas Pitre authored
      commit ac124504 upstream.
      
      Commit f6f91b0d ("ARM: allow kuser helpers to be removed from the
      vector page") introduced some help text for the CONFIG_KUSER_HELPERS
      option which is rather contradictory.
      
      Let's fix that, and improve it a little.
      Signed-off-by: default avatarNicolas Pitre <nico@linaro.org>
      Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      90dbc54a
    • Will Deacon's avatar
      arm64: perf: fix event validation for software group leaders · 6c6f6c71
      Will Deacon authored
      commit ee7538a0 upstream.
      
      This is a port of c95eb318 ("ARM: 7809/1: perf: fix event validation
      for software group leaders") to arm64, which fixes a panic in the arm64
      perf backend found as a result of Vince's fuzzing tool.
      Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
      Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6c6f6c71
    • Will Deacon's avatar
      arm64: perf: fix array out of bounds access in armpmu_map_hw_event() · 975a3cd4
      Will Deacon authored
      commit 868f6fea upstream.
      
      This is a port of d9f96635 ("ARM: 7810/1: perf: Fix array out of
      bounds access in armpmu_map_hw_event()") to arm64, which fixes an oops
      in the arm64 perf backend found as a result of Vince's fuzzing tool.
      Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
      Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      975a3cd4
    • Nicolas Ferre's avatar
      805eea0b
    • Sekhar Nori's avatar
      ARM: davinci: nand: specify ecc strength · 66ed6f3d
      Sekhar Nori authored
      commit acd36357 upstream.
      
      Starting with kernel v3.5, it is mandatory
      to specify ECC strength when using hardware
      ECC. Without this, kernel panics with a warning
      of the sort:
      
      Driver must set ecc.strength when using hardware ECC
      ------------[ cut here ]------------
      kernel BUG at drivers/mtd/nand/nand_base.c:3519!
      
      Fix this by specifying ECC strength for the boards
      which were missing this.
      Reported-by: default avatarHolger Freyther <holger@freyther.de>
      Signed-off-by: default avatarSekhar Nori <nsekhar@ti.com>
      Signed-off-by: default avatarKevin Hilman <khilman@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      66ed6f3d
    • David Vrabel's avatar
      xen/events: mask events when changing their VCPU binding · 131cb95f
      David Vrabel authored
      commit 4704fe4f upstream.
      
      When a event is being bound to a VCPU there is a window between the
      EVTCHNOP_bind_vpcu call and the adjustment of the local per-cpu masks
      where an event may be lost.  The hypervisor upcalls the new VCPU but
      the kernel thinks that event is still bound to the old VCPU and
      ignores it.
      
      There is even a problem when the event is being bound to the same VCPU
      as there is a small window beween the clear_bit() and set_bit() calls
      in bind_evtchn_to_cpu().  When scanning for pending events, the kernel
      may read the bit when it is momentarily clear and ignore the event.
      
      Avoid this by masking the event during the whole bind operation.
      Signed-off-by: default avatarDavid Vrabel <david.vrabel@citrix.com>
      Signed-off-by: default avatarKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
      Reviewed-by: default avatarJan Beulich <jbeulich@suse.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      131cb95f
    • David Vrabel's avatar
      xen/events: initialize local per-cpu mask for all possible events · d8251a94
      David Vrabel authored
      commit 84ca7a8e upstream.
      
      The sizeof() argument in init_evtchn_cpu_bindings() is incorrect
      resulting in only the first 64 (or 32 in 32-bit guests) ports having
      their bindings being initialized to VCPU 0.
      
      In most cases this does not cause a problem as request_irq() will set
      the irq affinity which will set the correct local per-cpu mask.
      However, if the request_irq() is called on a VCPU other than 0, there
      is a window between the unmasking of the event and the affinity being
      set were an event may be lost because it is not locally unmasked on
      any VCPU. If request_irq() is called on VCPU 0 then local irqs are
      disabled during the window and the race does not occur.
      
      Fix this by initializing all NR_EVENT_CHANNEL bits in the local
      per-cpu masks.
      Signed-off-by: default avatarDavid Vrabel <david.vrabel@citrix.com>
      Signed-off-by: default avatarKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d8251a94
    • Daniel Drake's avatar
      x86: Don't clear olpc_ofw_header when sentinel is detected · 8a34139a
      Daniel Drake authored
      commit d55e37bb upstream.
      
      OpenFirmware wasn't quite following the protocol described in boot.txt
      and the kernel has detected this through use of the sentinel value
      in boot_params. OFW does zero out almost all of the stuff that it should
      do, but not the sentinel.
      
      This causes the kernel to clear olpc_ofw_header, which breaks x86 OLPC
      support.
      
      OpenFirmware has now been fixed. However, it would be nice if we could
      maintain Linux compatibility with old firmware versions. To do that, we just
      have to avoid zeroing out olpc_ofw_header.
      
      OFW does not write to any other parts of the header that are being zapped
      by the sentinel-detection code, and all users of olpc_ofw_header are
      somewhat protected through checking for the OLPC_OFW_SIG magic value
      before using it. So this should not cause any problems for anyone.
      Signed-off-by: default avatarDaniel Drake <dsd@laptop.org>
      Link: http://lkml.kernel.org/r/20130809221420.618E6FAB03@dev.laptop.orgAcked-by: default avatarYinghai Lu <yinghai@kernel.org>
      Signed-off-by: default avatarH. Peter Anvin <hpa@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8a34139a
    • Dan Carpenter's avatar
      VFS: collect_mounts() should return an ERR_PTR · 2bee1e0f
      Dan Carpenter authored
      commit 52e220d3 upstream.
      
      This should actually be returning an ERR_PTR on error instead of NULL.
      That was how it was designed and all the callers expect it.
      
      [AV: actually, that's what "VFS: Make clone_mnt()/copy_tree()/collect_mounts()
      return errors" missed - originally collect_mounts() was expected to return
      NULL on failure]
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2bee1e0f
    • Jussi Kivilinna's avatar
      zd1201: do not use stack as URB transfer_buffer · b1693951
      Jussi Kivilinna authored
      commit 1206ff4f upstream.
      
      Patch fixes zd1201 not to use stack as URB transfer_buffer. URB buffers need
      to be DMA-able, which stack is not.
      
      Patch is only compile tested.
      Signed-off-by: default avatarJussi Kivilinna <jussi.kivilinna@iki.fi>
      Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b1693951
    • Joern Rennecke's avatar
      ARC: [lib] strchr breakage in Big-endian configuration · 0cbf3972
      Joern Rennecke authored
      commit b0f55f2a upstream.
      
      For a search buffer, 2 byte aligned, strchr() was returning pointer
      outside of buffer (buf - 1)
      
      ------------->8----------------
          // Input buffer (default 4 byte aigned)
          char *buffer = "1AA_";
      
          // actual search start (to mimick 2 byte alignment)
          char *current_line = &(buffer[2]);
      
          // Character to search for
          char c = 'A';
      
          char *c_pos = strchr(current_line, c);
      
          printf("%s\n", c_pos) --> 'AA_' as oppose to 'A_'
      ------------->8----------------
      Reported-by: default avatarAnton Kolesov <Anton.Kolesov@synopsys.com>
      Debugged-by: default avatarAnton Kolesov <Anton.Kolesov@synopsys.com>
      Cc: Noam Camus <noamc@ezchip.com>
      Signed-off-by: default avatarJoern Rennecke  <joern.rennecke@embecosm.com>
      Signed-off-by: default avatarVineet Gupta <vgupta@synopsys.com>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0cbf3972
    • Chuck Anderson's avatar
      xen/smp: initialize IPI vectors before marking CPU online · 51f50872
      Chuck Anderson authored
      commit fc78d343 upstream.
      
      An older PVHVM guest (v3.0 based) crashed during vCPU hot-plug with:
      
      	kernel BUG at drivers/xen/events.c:1328!
      
      RCU has detected that a CPU has not entered a quiescent state within the
      grace period.  It needs to send the CPU a reschedule IPI if it is not
      offline.  rcu_implicit_offline_qs() does this check:
      
      	/*
      	 * If the CPU is offline, it is in a quiescent state.  We can
      	 * trust its state not to change because interrupts are disabled.
      	 */
      	if (cpu_is_offline(rdp->cpu)) {
      		rdp->offline_fqs++;
      		return 1;
      	}
      
      	Else the CPU is online.  Send it a reschedule IPI.
      
      The CPU is in the middle of being hot-plugged and has been marked online
      (!cpu_is_offline()).  See start_secondary():
      
      	set_cpu_online(smp_processor_id(), true);
      	...
      	per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE;
      
      start_secondary() then waits for the CPU bringing up the hot-plugged CPU to
      mark it as active:
      
      	/*
      	 * Wait until the cpu which brought this one up marked it
      	 * online before enabling interrupts. If we don't do that then
      	 * we can end up waking up the softirq thread before this cpu
      	 * reached the active state, which makes the scheduler unhappy
      	 * and schedule the softirq thread on the wrong cpu. This is
      	 * only observable with forced threaded interrupts, but in
      	 * theory it could also happen w/o them. It's just way harder
      	 * to achieve.
      	 */
      	while (!cpumask_test_cpu(smp_processor_id(), cpu_active_mask))
      		cpu_relax();
      
      	/* enable local interrupts */
      	local_irq_enable();
      
      The CPU being hot-plugged will be marked active after it has been fully
      initialized by the CPU managing the hot-plug.  In the Xen PVHVM case
      xen_smp_intr_init() is called to set up the hot-plugged vCPU's
      XEN_RESCHEDULE_VECTOR.
      
      The hot-plugging CPU is marked online, not marked active and does not have
      its IPI vectors set up.  rcu_implicit_offline_qs() sees the hot-plugging
      cpu is !cpu_is_offline() and tries to send it a reschedule IPI:
      This will lead to:
      
      	kernel BUG at drivers/xen/events.c:1328!
      
      	xen_send_IPI_one()
      	xen_smp_send_reschedule()
      	rcu_implicit_offline_qs()
      	rcu_implicit_dynticks_qs()
      	force_qs_rnp()
      	force_quiescent_state()
      	__rcu_process_callbacks()
      	rcu_process_callbacks()
      	__do_softirq()
      	call_softirq()
      	do_softirq()
      	irq_exit()
      	xen_evtchn_do_upcall()
      
      because xen_send_IPI_one() will attempt to use an uninitialized IRQ for
      the XEN_RESCHEDULE_VECTOR.
      
      There is at least one other place that has caused the same crash:
      
      	xen_smp_send_reschedule()
      	wake_up_idle_cpu()
      	add_timer_on()
      	clocksource_watchdog()
      	call_timer_fn()
      	run_timer_softirq()
      	__do_softirq()
      	call_softirq()
      	do_softirq()
      	irq_exit()
      	xen_evtchn_do_upcall()
      	xen_hvm_callback_vector()
      
      clocksource_watchdog() uses cpu_online_mask to pick the next CPU to handle
      a watchdog timer:
      
      	/*
      	 * Cycle through CPUs to check if the CPUs stay synchronized
      	 * to each other.
      	 */
      	next_cpu = cpumask_next(raw_smp_processor_id(), cpu_online_mask);
      	if (next_cpu >= nr_cpu_ids)
      		next_cpu = cpumask_first(cpu_online_mask);
      	watchdog_timer.expires += WATCHDOG_INTERVAL;
      	add_timer_on(&watchdog_timer, next_cpu);
      
      This resulted in an attempt to send an IPI to a hot-plugging CPU that
      had not initialized its reschedule vector. One option would be to make
      the RCU code check to not check for CPU offline but for CPU active.
      As becoming active is done after a CPU is online (in older kernels).
      
      But Srivatsa pointed out that "the cpu_active vs cpu_online ordering has been
      completely reworked - in the online path, cpu_active is set *before* cpu_online,
      and also, in the cpu offline path, the cpu_active bit is reset in the CPU_DYING
      notification instead of CPU_DOWN_PREPARE." Drilling in this the bring-up
      path: "[brought up CPU].. send out a CPU_STARTING notification, and in response
      to that, the scheduler sets the CPU in the cpu_active_mask. Again, this mask
      is better left to the scheduler alone, since it has the intelligence to use it
      judiciously."
      
      The conclusion was that:
      "
      1. At the IPI sender side:
      
         It is incorrect to send an IPI to an offline CPU (cpu not present in
         the cpu_online_mask). There are numerous places where we check this
         and warn/complain.
      
      2. At the IPI receiver side:
      
         It is incorrect to let the world know of our presence (by setting
         ourselves in global bitmasks) until our initialization steps are complete
         to such an extent that we can handle the consequences (such as
         receiving interrupts without crashing the sender etc.)
      " (from Srivatsa)
      
      As the native code enables the interrupts at some point we need to be
      able to service them. In other words a CPU must have valid IPI vectors
      if it has been marked online.
      
      It doesn't need to handle the IPI (interrupts may be disabled) but needs
      to have valid IPI vectors because another CPU may find it in cpu_online_mask
      and attempt to send it an IPI.
      
      This patch will change the order of the Xen vCPU bring-up functions so that
      Xen vectors have been set up before start_secondary() is called.
      It also will not continue to bring up a Xen vCPU if xen_smp_intr_init() fails
      to initialize it.
      
      Orabug 13823853
      Signed-off-by Chuck Anderson <chuck.anderson@oracle.com>
      Acked-by: default avatarSrivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
      Signed-off-by: default avatarKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
      Signed-off-by: default avatarJonghwan Choi <jhbird.choi@samsung.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      51f50872
    • Steven Rostedt (Red Hat)'s avatar
      ftrace: Check module functions being traced on reload · f05e999f
      Steven Rostedt (Red Hat) authored
      commit 8c4f3c3f upstream.
      
      There's been a nasty bug that would show up and not give much info.
      The bug displayed the following warning:
      
       WARNING: at kernel/trace/ftrace.c:1529 __ftrace_hash_rec_update+0x1e3/0x230()
       Pid: 20903, comm: bash Tainted: G           O 3.6.11+ #38405.trunk
       Call Trace:
        [<ffffffff8103e5ff>] warn_slowpath_common+0x7f/0xc0
        [<ffffffff8103e65a>] warn_slowpath_null+0x1a/0x20
        [<ffffffff810c2ee3>] __ftrace_hash_rec_update+0x1e3/0x230
        [<ffffffff810c4f28>] ftrace_hash_move+0x28/0x1d0
        [<ffffffff811401cc>] ? kfree+0x2c/0x110
        [<ffffffff810c68ee>] ftrace_regex_release+0x8e/0x150
        [<ffffffff81149f1e>] __fput+0xae/0x220
        [<ffffffff8114a09e>] ____fput+0xe/0x10
        [<ffffffff8105fa22>] task_work_run+0x72/0x90
        [<ffffffff810028ec>] do_notify_resume+0x6c/0xc0
        [<ffffffff8126596e>] ? trace_hardirqs_on_thunk+0x3a/0x3c
        [<ffffffff815c0f88>] int_signal+0x12/0x17
       ---[ end trace 793179526ee09b2c ]---
      
      It was finally narrowed down to unloading a module that was being traced.
      
      It was actually more than that. When functions are being traced, there's
      a table of all functions that have a ref count of the number of active
      tracers attached to that function. When a function trace callback is
      registered to a function, the function's record ref count is incremented.
      When it is unregistered, the function's record ref count is decremented.
      If an inconsistency is detected (ref count goes below zero) the above
      warning is shown and the function tracing is permanently disabled until
      reboot.
      
      The ftrace callback ops holds a hash of functions that it filters on
      (and/or filters off). If the hash is empty, the default means to filter
      all functions (for the filter_hash) or to disable no functions (for the
      notrace_hash).
      
      When a module is unloaded, it frees the function records that represent
      the module functions. These records exist on their own pages, that is
      function records for one module will not exist on the same page as
      function records for other modules or even the core kernel.
      
      Now when a module unloads, the records that represents its functions are
      freed. When the module is loaded again, the records are recreated with
      a default ref count of zero (unless there's a callback that traces all
      functions, then they will also be traced, and the ref count will be
      incremented).
      
      The problem is that if an ftrace callback hash includes functions of the
      module being unloaded, those hash entries will not be removed. If the
      module is reloaded in the same location, the hash entries still point
      to the functions of the module but the module's ref counts do not reflect
      that.
      
      With the help of Steve and Joern, we found a reproducer:
      
       Using uinput module and uinput_release function.
      
       cd /sys/kernel/debug/tracing
       modprobe uinput
       echo uinput_release > set_ftrace_filter
       echo function > current_tracer
       rmmod uinput
       modprobe uinput
       # check /proc/modules to see if loaded in same addr, otherwise try again
       echo nop > current_tracer
      
       [BOOM]
      
      The above loads the uinput module, which creates a table of functions that
      can be traced within the module.
      
      We add uinput_release to the filter_hash to trace just that function.
      
      Enable function tracincg, which increments the ref count of the record
      associated to uinput_release.
      
      Remove uinput, which frees the records including the one that represents
      uinput_release.
      
      Load the uinput module again (and make sure it's at the same address).
      This recreates the function records all with a ref count of zero,
      including uinput_release.
      
      Disable function tracing, which will decrement the ref count for uinput_release
      which is now zero because of the module removal and reload, and we have
      a mismatch (below zero ref count).
      
      The solution is to check all currently tracing ftrace callbacks to see if any
      are tracing any of the module's functions when a module is loaded (it already does
      that with callbacks that trace all functions). If a callback happens to have
      a module function being traced, it increments that records ref count and starts
      tracing that function.
      
      There may be a strange side effect with this, where tracing module functions
      on unload and then reloading a new module may have that new module's functions
      being traced. This may be something that confuses the user, but it's not
      a big deal. Another approach is to disable all callback hashes on module unload,
      but this leaves some ftrace callbacks that may not be registered, but can
      still have hashes tracing the module's function where ftrace doesn't know about
      it. That situation can cause the same bug. This solution solves that case too.
      Another benefit of this solution, is it is possible to trace a module's
      function on unload and load.
      
      Link: http://lkml.kernel.org/r/20130705142629.GA325@redhat.comReported-by: default avatarJörn Engel <joern@logfs.org>
      Reported-by: default avatarDave Jones <davej@redhat.com>
      Reported-by: default avatarSteve Hodgson <steve@purestorage.com>
      Tested-by: default avatarSteve Hodgson <steve@purestorage.com>
      Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f05e999f
    • Steven Rostedt (Red Hat)'s avatar
      tracing/uprobes: Fail to unregister if probe event files are in use · 396dd500
      Steven Rostedt (Red Hat) authored
      commit c6c2401d upstream.
      
      Uprobes suffer the same problem that kprobes have. There's a race between
      writing to the "enable" file and removing the probe. The probe checks for
      it being in use and if it is not, goes about deleting the probe and the
      event that represents it. But the problem with that is, after it checks
      if it is in use it can be enabled, and the deletion of the event (access
      to the probe) will fail, as it is in use. But the uprobe will still be
      deleted. This is a problem as the event can reference the uprobe that
      was deleted.
      
      The fix is to remove the event first, and check to make sure the event
      removal succeeds. Then it is safe to remove the probe.
      
      When the event exists, either ftrace or perf can enable the probe and
      prevent the event from being removed.
      
      Link: http://lkml.kernel.org/r/20130704034038.991525256@goodmis.orgAcked-by: default avatarOleg Nesterov <oleg@redhat.com>
      Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      396dd500
    • Steven Rostedt (Red Hat)'s avatar
      tracing/kprobes: Fail to unregister if probe event files are in use · 428fbcf9
      Steven Rostedt (Red Hat) authored
      commit 40c32592 upstream.
      
      When a probe is being removed, it cleans up the event files that correspond
      to the probe. But there is a race between writing to one of these files
      and deleting the probe. This is especially true for the "enable" file.
      
      	CPU 0				CPU 1
      	-----				-----
      
      				  fd = open("enable",O_WRONLY);
      
        probes_open()
        release_all_trace_probes()
        unregister_trace_probe()
        if (trace_probe_is_enabled(tp))
      	return -EBUSY
      
      				   write(fd, "1", 1)
      				   __ftrace_set_clr_event()
      				   call->class->reg()
      				    (kprobe_register)
      				     enable_trace_probe(tp)
      
        __unregister_trace_probe(tp);
        list_del(&tp->list)
        unregister_probe_event(tp) <-- fails!
        free_trace_probe(tp)
      
      				   write(fd, "0", 1)
      				   __ftrace_set_clr_event()
      				   call->class->unreg
      				    (kprobe_register)
      				    disable_trace_probe(tp) <-- BOOM!
      
      A test program was written that used two threads to simulate the
      above scenario adding a nanosleep() interval to change the timings
      and after several thousand runs, it was able to trigger this bug
      and crash:
      
      BUG: unable to handle kernel paging request at 00000005000000f9
      IP: [<ffffffff810dee70>] probes_open+0x3b/0xa7
      PGD 7808a067 PUD 0
      Oops: 0000 [#1] PREEMPT SMP
      Dumping ftrace buffer:
      ---------------------------------
      Modules linked in: ipt_MASQUERADE sunrpc ip6t_REJECT nf_conntrack_ipv6
      CPU: 1 PID: 2070 Comm: test-kprobe-rem Not tainted 3.11.0-rc3-test+ #47
      Hardware name: To Be Filled By O.E.M. To Be Filled By O.E.M./To be filled by O.E.M., BIOS SDBLI944.86P 05/08/2007
      task: ffff880077756440 ti: ffff880076e52000 task.ti: ffff880076e52000
      RIP: 0010:[<ffffffff810dee70>]  [<ffffffff810dee70>] probes_open+0x3b/0xa7
      RSP: 0018:ffff880076e53c38  EFLAGS: 00010203
      RAX: 0000000500000001 RBX: ffff88007844f440 RCX: 0000000000000003
      RDX: 0000000000000003 RSI: 0000000000000003 RDI: ffff880076e52000
      RBP: ffff880076e53c58 R08: ffff880076e53bd8 R09: 0000000000000000
      R10: ffff880077756440 R11: 0000000000000006 R12: ffffffff810dee35
      R13: ffff880079250418 R14: 0000000000000000 R15: ffff88007844f450
      FS:  00007f87a276f700(0000) GS:ffff88007d480000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
      CR2: 00000005000000f9 CR3: 0000000077262000 CR4: 00000000000007e0
      Stack:
       ffff880076e53c58 ffffffff81219ea0 ffff88007844f440 ffffffff810dee35
       ffff880076e53ca8 ffffffff81130f78 ffff8800772986c0 ffff8800796f93a0
       ffffffff81d1b5d8 ffff880076e53e04 0000000000000000 ffff88007844f440
      Call Trace:
       [<ffffffff81219ea0>] ? security_file_open+0x2c/0x30
       [<ffffffff810dee35>] ? unregister_trace_probe+0x4b/0x4b
       [<ffffffff81130f78>] do_dentry_open+0x162/0x226
       [<ffffffff81131186>] finish_open+0x46/0x54
       [<ffffffff8113f30b>] do_last+0x7f6/0x996
       [<ffffffff8113cc6f>] ? inode_permission+0x42/0x44
       [<ffffffff8113f6dd>] path_openat+0x232/0x496
       [<ffffffff8113fc30>] do_filp_open+0x3a/0x8a
       [<ffffffff8114ab32>] ? __alloc_fd+0x168/0x17a
       [<ffffffff81131f4e>] do_sys_open+0x70/0x102
       [<ffffffff8108f06e>] ? trace_hardirqs_on_caller+0x160/0x197
       [<ffffffff81131ffe>] SyS_open+0x1e/0x20
       [<ffffffff81522742>] system_call_fastpath+0x16/0x1b
      Code: e5 41 54 53 48 89 f3 48 83 ec 10 48 23 56 78 48 39 c2 75 6c 31 f6 48 c7
      RIP  [<ffffffff810dee70>] probes_open+0x3b/0xa7
       RSP <ffff880076e53c38>
      CR2: 00000005000000f9
      ---[ end trace 35f17d68fc569897 ]---
      
      The unregister_trace_probe() must be done first, and if it fails it must
      fail the removal of the kprobe.
      
      Several changes have already been made by Oleg Nesterov and Masami Hiramatsu
      to allow moving the unregister_probe_event() before the removal of
      the probe and exit the function if it fails. This prevents the tp
      structure from being used after it is freed.
      
      Link: http://lkml.kernel.org/r/20130704034038.819592356@goodmis.orgAcked-by: default avatarMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      428fbcf9
    • Oleg Nesterov's avatar
      tracing: trace_remove_event_call() should fail if call/file is in use · 8169887b
      Oleg Nesterov authored
      commit 2816c551 upstream.
      
      Change trace_remove_event_call(call) to return the error if this
      call is active. This is what the callers assume but can't verify
      outside of the tracing locks. Both trace_kprobe.c/trace_uprobe.c
      need the additional changes, unregister_trace_probe() should abort
      if trace_remove_event_call() fails.
      
      The caller is going to free this call/file so we must ensure that
      nobody can use them after trace_remove_event_call() succeeds.
      debugfs should be fine after the previous changes and event_remove()
      does TRACE_REG_UNREGISTER, but still there are 2 reasons why we need
      the additional checks:
      
      - There could be a perf_event(s) attached to this tp_event, so the
        patch checks ->perf_refcount.
      
      - TRACE_REG_UNREGISTER can be suppressed by FTRACE_EVENT_FL_SOFT_MODE,
        so we simply check FTRACE_EVENT_FL_ENABLED protected by event_mutex.
      
      Link: http://lkml.kernel.org/r/20130729175033.GB26284@redhat.comReviewed-by: default avatarMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
      Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8169887b
    • Oleg Nesterov's avatar
      tracing: Change remove_event_file_dir() to clear "d_subdirs"->i_private · 012dc156
      Oleg Nesterov authored
      commit bf682c31 upstream.
      
      Change remove_event_file_dir() to clear ->i_private for every
      file we are going to remove.
      
      We need to check file->dir != NULL because event_create_dir()
      can fail. debugfs_remove_recursive(NULL) is fine but the patch
      moves it under the same check anyway for readability.
      
      spin_lock(d_lock) and "d_inode != NULL" check are not needed
      afaics, but I do not understand this code enough.
      
      tracing_open_generic_file() and tracing_release_generic_file()
      can go away, ftrace_enable_fops and ftrace_event_filter_fops()
      use tracing_open_generic() but only to check tracing_disabled.
      
      This fixes all races with event_remove() or instance_delete().
      f_op->read/write/whatever can never use the freed file/call,
      all event/* files were changed to check and use ->i_private
      under event_mutex.
      
      Note: this doesn't not fix other problems, event_remove() can
      destroy the active ftrace_event_call, we need more changes but
      those changes are completely orthogonal.
      
      Link: http://lkml.kernel.org/r/20130728183527.GB16723@redhat.comReviewed-by: default avatarMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
      Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      012dc156
    • Oleg Nesterov's avatar
      tracing: Introduce remove_event_file_dir() · c6febdf2
      Oleg Nesterov authored
      commit f6a84bdc upstream.
      
      Preparation for the next patch. Extract the common code from
      remove_event_from_tracers() and __trace_remove_event_dirs()
      into the new helper, remove_event_file_dir().
      
      The patch looks more complicated than it actually is, it also
      moves remove_subsystem() up to avoid the forward declaration.
      
      Link: http://lkml.kernel.org/r/20130726172547.GA3629@redhat.comReviewed-by: default avatarMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
      Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c6febdf2
    • Oleg Nesterov's avatar
      tracing: Change f_start() to take event_mutex and verify i_private != NULL · b86d0ba6
      Oleg Nesterov authored
      commit c5a44a12 upstream.
      
      trace_format_open() and trace_format_seq_ops are racy, nothing
      protects ftrace_event_call from trace_remove_event_call().
      
      Change f_start() to take event_mutex and verify i_private != NULL,
      change f_stop() to drop this lock.
      
      This fixes nothing, but now we can change debugfs_remove("format")
      callers to nullify ->i_private and fix the the problem.
      
      Note: the usage of event_mutex is sub-optimal but simple, we can
      change this later.
      
      Link: http://lkml.kernel.org/r/20130726172543.GA3622@redhat.comReviewed-by: default avatarMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
      Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      
      b86d0ba6
    • Oleg Nesterov's avatar
      tracing: Change event_filter_read/write to verify i_private != NULL · 70c91fb9
      Oleg Nesterov authored
      commit e2912b09 upstream.
      
      event_filter_read/write() are racy, ftrace_event_call can be already
      freed by trace_remove_event_call() callers.
      
      1. Shift mutex_lock(event_mutex) from print/apply_event_filter to
         the callers.
      
      2. Change the callers, event_filter_read() and event_filter_write()
         to read i_private under this mutex and abort if it is NULL.
      
      This fixes nothing, but now we can change debugfs_remove("filter")
      callers to nullify ->i_private and fix the the problem.
      
      Link: http://lkml.kernel.org/r/20130726172540.GA3619@redhat.comReviewed-by: default avatarMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
      Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      
      70c91fb9
    • Oleg Nesterov's avatar
      tracing: Change event_enable/disable_read() to verify i_private != NULL · df89bf77
      Oleg Nesterov authored
      commit bc6f6b08 upstream.
      
      tracing_open_generic_file() is racy, ftrace_event_file can be
      already freed by rmdir or trace_remove_event_call().
      
      Change event_enable_read() and event_disable_read() to read and
      verify "file = i_private" under event_mutex.
      
      This fixes nothing, but now we can change debugfs_remove("enable")
      callers to nullify ->i_private and fix the the problem.
      
      Link: http://lkml.kernel.org/r/20130726172536.GA3612@redhat.comReviewed-by: default avatarMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
      Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      
      df89bf77
    • Oleg Nesterov's avatar
      tracing: Turn event/id->i_private into call->event.type · fdb65fe2
      Oleg Nesterov authored
      commit 1a11126b upstream.
      
      event_id_read() is racy, ftrace_event_call can be already freed
      by trace_remove_event_call() callers.
      
      Change event_create_dir() to pass "data = call->event.type", this
      is all event_id_read() needs. ftrace_event_id_fops no longer needs
      tracing_open_generic().
      
      We add the new helper, event_file_data(), to read ->i_private, it
      will have more users.
      
      Note: currently ACCESS_ONCE() and "id != 0" check are not needed,
      but we are going to change event_remove/rmdir to clear ->i_private.
      
      Link: http://lkml.kernel.org/r/20130726172532.GA3605@redhat.comReviewed-by: default avatarMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
      Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
      Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fdb65fe2
    • Steven Rostedt (Red Hat)'s avatar
      ftrace: Add check for NULL regs if ops has SAVE_REGS set · 29632b10
      Steven Rostedt (Red Hat) authored
      commit 195a8afc upstream.
      
      If a ftrace ops is registered with the SAVE_REGS flag set, and there's
      already a ops registered to one of its functions but without the
      SAVE_REGS flag, there's a small race window where the SAVE_REGS ops gets
      added to the list of callbacks to call for that function before the
      callback trampoline gets set to save the regs.
      
      The problem is, the function is not currently saving regs, which opens
      a small race window where the ops that is expecting regs to be passed
      to it, wont. This can cause a crash if the callback were to reference
      the regs, as the SAVE_REGS guarantees that regs will be set.
      
      To fix this, we add a check in the loop case where it checks if the ops
      has the SAVE_REGS flag set, and if so, it will ignore it if regs is
      not set.
      Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      29632b10
    • Oleg Nesterov's avatar
      tracing: Change tracing_fops/snapshot_fops to rely on tracing_get_cpu() · 7272711a
      Oleg Nesterov authored
      commit 6484c71c upstream.
      
      tracing_open() and tracing_snapshot_open() are racy, the memory
      inode->i_private points to can be already freed.
      
      Convert these last users of "inode->i_private == trace_cpu" to
      use "i_private = trace_array" and rely on tracing_get_cpu().
      
      v2: incorporate the fix from Steven, tracing_release() must not
          blindly dereference file->private_data unless we know that
          the file was opened for reading.
      
      Link: http://lkml.kernel.org/r/20130723152610.GA23737@redhat.comSigned-off-by: default avatarOleg Nesterov <oleg@redhat.com>
      Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7272711a