Commit Graph

340 Commits

Author SHA1 Message Date
Desnes Nunes 0aaa7b0473 usb: core: hcd: only check primary hcd skip_phy_initialization
JIRA: https://issues.redhat.com/browse/RHEL-78828

commit d2ec94fbc431cc77ed53d4480bdc856669c2b5aa
Author: Xu Yang <xu.yang_2@nxp.com>
Date: Tue, 5 Nov 2024 17:01:20 +0800

  Before commit 53a2d95df836 ("usb: core: add phy notify connect and
  disconnect"), phy initialization will be skipped even when shared hcd
  doesn't set skip_phy_initialization flag. However, the situation is
  changed after the commit. The hcd.c will initialize phy when add shared
  hcd. This behavior is unexpected for some platforms which will handle phy
  initialization by themselves. To avoid the issue, this will only check
  skip_phy_initialization flag of primary hcd since shared hcd normally
  follow primary hcd setting.

  Fixes: 53a2d95df836 ("usb: core: add phy notify connect and disconnect")
  Cc: stable@vger.kernel.org
  Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
  Link: https://lore.kernel.org/r/20241105090120.2438366-1-xu.yang_2@nxp.com
  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2025-03-19 21:24:06 -03:00
Desnes Nunes dbb80ec7e1 usb: core: Remove the useless struct usb_devmap which is just a bitmap
JIRA: https://issues.redhat.com/browse/RHEL-59050

commit 562be61b35d911a8b45acc3dcf8642876dbb66dd
Author: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Date: Sat, 4 May 2024 11:47:05 +0200

  struct usb_devmap is really just a bitmap. No need to have a dedicated
  structure for that.

  Simplify code and use DECLARE_BITMAP() directly instead.

  Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
  Acked-by: Alan Stern <stern@rowland.harvard.edu>
  Link: https://lore.kernel.org/r/1d818575ff7a1e8317674aecf761ee23c89fdc84.1714815990.git.christophe.jaillet@wanadoo.fr
  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2024-10-10 16:36:45 -03:00
Desnes Nunes 4fa731f6e4 kcov, usb: disable interrupts in kcov_remote_start_usb_softirq
JIRA: https://issues.redhat.com/browse/RHEL-37673
Conflicts:
* Avoiding commit <e0ddec73fd48> ("kcov: add prototypes for helper
  functions") and its series

commit f85d39dd7ed89ffdd622bc1de247ffba8d961504
Author: Andrey Konovalov <andreyknvl@gmail.com>
Date: Mon, 27 May 2024 19:35:38 +0200

  After commit 8fea0c8fda30 ("usb: core: hcd: Convert from tasklet to BH
  workqueue"), usb_giveback_urb_bh() runs in the BH workqueue with
  interrupts enabled.

  Thus, the remote coverage collection section in usb_giveback_urb_bh()->
  __usb_hcd_giveback_urb() might be interrupted, and the interrupt handler
  might invoke __usb_hcd_giveback_urb() again.

  This breaks KCOV, as it does not support nested remote coverage collection
  sections within the same context (neither in task nor in softirq).

  Update kcov_remote_start/stop_usb_softirq() to disable interrupts for the
  duration of the coverage collection section to avoid nested sections in
  the softirq context (in addition to such in the task context, which are
  already handled).

  Reported-by: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
  Closes: https://lore.kernel.org/linux-usb/0f4d1964-7397-485b-bc48-11c01e2fcbca@I-love.SAKURA.ne.jp/
  Closes: https://syzkaller.appspot.com/bug?extid=0438378d6f157baae1a2
  Suggested-by: Alan Stern <stern@rowland.harvard.edu>
  Fixes: 8fea0c8fda30 ("usb: core: hcd: Convert from tasklet to BH workqueue")
  Cc: stable@vger.kernel.org
  Acked-by: Dmitry Vyukov <dvyukov@google.com>
  Signed-off-by: Andrey Konovalov <andreyknvl@gmail.com>
  Link: https://lore.kernel.org/r/20240527173538.4989-1-andrey.konovalov@linux.dev
  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2024-06-21 14:48:44 -03:00
Desnes Nunes 71b331d6a0 usb: core: hcd: Convert from tasklet to BH workqueue
JIRA: https://issues.redhat.com/browse/RHEL-37673

commit 8fea0c8fda30129b4168464975505d5dc9735ac1
Author: Tejun Heo <tj@kernel.org>
Date: Sun, 4 Feb 2024 11:34:34 -1000

  The only generic interface to execute asynchronously in the BH context is
  tasklet; however, it's marked deprecated and has some design flaws. To
  replace tasklets, BH workqueue support was recently added. A BH workqueue
  behaves similarly to regular workqueues except that the queued work items
  are executed in the BH context.

  This patch converts usb hcd from tasklet to BH workqueue.

  Signed-off-by: Tejun Heo <tj@kernel.org>
  Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  Cc: Alan Stern <stern@rowland.harvard.edu>
  Cc: linux-usb@vger.kernel.org

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2024-06-18 17:26:55 -03:00
Desnes Nunes 4c5fc99880 usb: core: add phy notify connect and disconnect
JIRA: https://issues.redhat.com/browse/RHEL-37673

commit 53a2d95df83688d0e160e3d55a925d85dbfd4809
Author: Stanley Chang <stanley_chang@realtek.com>
Date: Wed, 13 Dec 2023 11:10:09 +0800

  In Realtek SoC, the parameter of usb phy is designed to can dynamic
  tuning base on port status. Therefore, add a notify callback of generic
  phy driver when usb device connect and disconnect change.

  The Realtek phy driver is designed to dynamically adjust disconnection
  level and calibrate phy parameters. When the device connected bit changes
  and when the disconnected bit changes, do connection change notification:

  Check if portstatus is USB_PORT_STAT_CONNECTION and portchange is
  USB_PORT_STAT_C_CONNECTION.
  1. The device is connected, the driver lowers the disconnection level and
     calibrates the phy parameters.
  2. The device disconnects, the driver increases the disconnect level and
     calibrates the phy parameters.

  Generic phy driver in usb core framework does not support device connect
  and disconnect notifications. Therefore, we add an api to notify phy
  the connection changes.

  Additionally, the generic phy only specifies primary_hcd in the original
  design. Added specific "usb2-phy" on primary_hcd and "usb3-phy" on
  shared_hcd.

  Signed-off-by: Stanley Chang <stanley_chang@realtek.com>
  Link: https://lore.kernel.org/r/20231213031203.4911-4-stanley_chang@realtek.com
  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2024-06-13 13:56:57 -03:00
Desnes Nunes 5a0738ca57 usb: core: Make default authorization mode configurable
JIRA: https://issues.redhat.com/browse/RHEL-37673

commit bec7e43b162c58798e6dc30d8e70d1e2318aaf2d
Author: Niko Mauno <niko.mauno@vaisala.com>
Date: Fri, 5 Jan 2024 13:49:56 +0200

  Make the default USB device authorization mode configurable at build
  time. This is useful for systems that require a mode that is stricter
  than the standard setting, as it avoids relying on the kernel command
  line being properly set.

  Signed-off-by: Niko Mauno <niko.mauno@vaisala.com>
  Link: https://lore.kernel.org/r/20240105114956.30714-2-niko.mauno@vaisala.com
  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2024-06-13 13:56:57 -03:00
Desnes Nunes 3172d925ae usb: core: Amend initial authorized_default value
JIRA: https://issues.redhat.com/browse/RHEL-37673

commit aa6e11e9a792997a183d3b6936b01601233c570d
Author: Niko Mauno <niko.mauno@vaisala.com>
Date: Fri, 5 Jan 2024 13:49:55 +0200

  Since the wireless USB implementation has been removed and since the
  behavior with authorized_default values -1 and 1 is now effectively
  same, change the initial value to latter in order to stop using the
  leftover value. The former value can still be passed as a module
  parameter to retain backwards compatibility.

  Signed-off-by: Niko Mauno <niko.mauno@vaisala.com>
  Link: https://lore.kernel.org/r/20240105114956.30714-1-niko.mauno@vaisala.com
  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2024-06-13 13:56:57 -03:00
Desnes Nunes 9ea3e32c01 USB: Remove remnants of Wireless USB and UWB
JIRA: https://issues.redhat.com/browse/RHEL-15948

commit 1e4c574225cc5a0553115e5eb5787d1474db5b0f
Author: Alan Stern <stern@rowland.harvard.edu>
Date: Tue, 8 Aug 2023 20:44:18 -0400

  Wireless USB has long been defunct, and kernel support for it was
  removed in 2020 by commit caa6772db4 ("Staging: remove wusbcore and
  UWB from the kernel tree.").

  Nevertheless, some vestiges of the old implementation still clutter up
  the USB subsystem and one or two other places.  Let's get rid of them
  once and for all.

  The only parts still left are the user-facing APIs in
  include/uapi/linux/usb/ch9.h.  (There are also a couple of misleading
  instances, such as the Sierra Wireless USB modem, which is a USB modem
  made by Sierra Wireless.)

  Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
  Link: https://lore.kernel.org/r/b4f2710f-a2de-4fb0-b50f-76776f3a961b@rowland.harvard.edu
  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2023-11-21 15:33:05 -03:00
Desnes Nunes 5f060bd4de USB: core: Change usb_get_device_descriptor() API
JIRA: https://issues.redhat.com/browse/RHEL-2566
JIRA: https://issues.redhat.com/browse/RHEL-2680
CVE: CVE-2023-37453

commit de28e469da75359a2bb8cd8778b78aa64b1be1f4
Author: Alan Stern <stern@rowland.harvard.edu>
Date: Fri, 4 Aug 2023 15:12:21 -0400

  The usb_get_device_descriptor() routine reads the device descriptor
  from the udev device and stores it directly in udev->descriptor.  This
  interface is error prone, because the USB subsystem expects in-memory
  copies of a device's descriptors to be immutable once the device has
  been initialized.

  The interface is changed so that the device descriptor is left in a
  kmalloc-ed buffer, not copied into the usb_device structure.  A
  pointer to the buffer is returned to the caller, who is then
  responsible for kfree-ing it.  The corresponding changes needed in the
  various callers are fairly small.

  Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
  Link: https://lore.kernel.org/r/d0111bb6-56c1-4f90-adf2-6cfe152f6561@rowland.harvard.edu
  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2023-10-16 22:07:07 -03:00
Desnes Nunes 18ee49a312 usb: core: hcd: Fix return value check in usb_hcd_setup_local_mem()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2190250
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=3c347cdafa3db43337870006e5c2d7b78a8dae20

commit 3c347cdafa3db43337870006e5c2d7b78a8dae20
Author: Yang Yingliang <yangyingliang@huawei.com>
Date: Fri, 25 Nov 2022 14:41:20 +0800

  If dmam_alloc_attrs() fails, it returns NULL pointer and never
  return ERR_PTR(), so repleace IS_ERR() with IS_ERR_OR_NULL()
  and if it's NULL, returns -ENOMEM.

  Fixes: 9ba26f5cecd8 ("ARM: sa1100/assabet: move dmabounce hack to ohci driver")
  Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
  Link: https://lore.kernel.org/r/20221125064120.2842452-1-yangyingliang@huawei.com
  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2023-05-08 15:02:49 -03:00
Desnes Nunes c111ef8cca usb: host: Initiate urb ep with udev ep0
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2181663
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=9013d8fc0ad91dc369f5b8ea708b9b068aa5d434

commit 9013d8fc0ad91dc369f5b8ea708b9b068aa5d434
Author: Khalid Masum <khalid.masum.92@gmail.com>
Date: Thu, 25 Aug 2022 02:31:07 +0600

  Currently we look up for endpoint in a table and initate urb endpoint
  with it. This is unnecessary because the lookup will always result in
  endpoint 0.

  Suggested-by: Alan Stern <stern@rowland.harvard.edu>
  Acked-by: Alan Stern <stern@rowland.harvard.edu>
  Signed-off-by: Khalid Masum <khalid.masum.92@gmail.com>
  Link: https://lore.kernel.org/r/20220824203107.14908-1-khalid.masum.92@gmail.com
  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2023-04-03 20:35:49 -03:00
Desnes Nunes 41eadfe07a usb/hcd: Fix dma_map_sg error check
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2181663
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=4dce3b375179fdd4aba2191be11ace90ef0ec6d6

commit 4dce3b375179fdd4aba2191be11ace90ef0ec6d6
Author: Jack Wang <jinpu.wang@ionos.com>
Date: Fri, 19 Aug 2022 08:07:48 +0200

  dma_map_sg return 0 on error.

  Cc: Alan Stern <stern@rowland.harvard.edu>
  Cc: Kishon Vijay Abraham I <kishon@ti.com>
  Cc: Alexey Sheplyakov <asheplyakov@basealt.ru>
  Cc: Stephen Boyd <swboyd@chromium.org>
  Cc: Weitao Wang <WeitaoWang-oc@zhaoxin.com>
  Cc: Matthias Kaehlcke <mka@chromium.org>
  Cc: Arnd Bergmann <arnd@arndb.de>
  Cc: linux-usb@vger.kernel.org
  Cc: linux-kernel@vger.kernel.org
  Signed-off-by: Jack Wang <jinpu.wang@ionos.com>
  Link: https://lore.kernel.org/r/20220819060801.10443-7-jinpu.wang@ionos.com
  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2023-04-03 20:35:48 -03:00
Torez Smith 9f76bb5987 USB: HCD: Fix URB giveback issue in tasklet function
Bugzilla: http://bugzilla.redhat.com/2113003
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=48723298
Tested: HP ZBook 15 G5/80D5 Laptop
  ThinkPad P1 Gen5  TB4
  HP zBook Fury

commit 26c6c2f8a907c9e3a2f24990552a4d77235791e6
Author: Weitao Wang <WeitaoWang-oc@zhaoxin.com>
Date:   Tue Jul 26 15:49:18 2022 +0800

    USB: HCD: Fix URB giveback issue in tasklet function

    Usb core introduce the mechanism of giveback of URB in tasklet context to
    reduce hardware interrupt handling time. On some test situation(such as
    FIO with 4KB block size), when tasklet callback function called to
    giveback URB, interrupt handler add URB node to the bh->head list also.
    If check bh->head list again after finish all URB giveback of local_list,
    then it may introduce a "dynamic balance" between giveback URB and add URB
    to bh->head list. This tasklet callback function may not exit for a long
    time, which will cause other tasklet function calls to be delayed. Some
    real-time applications(such as KB and Mouse) will see noticeable lag.

    In order to prevent the tasklet function from occupying the cpu for a long
    time at a time, new URBS will not be added to the local_list even though
    the bh->head list is not empty. But also need to ensure the left URB
    giveback to be processed in time, so add a member high_prio for structure
    giveback_urb_bh to prioritize tasklet and schelule this tasklet again if
    bh->head list is not empty.

    At the same time, we are able to prioritize tasklet through structure
    member high_prio. So, replace the local high_prio_bh variable with this
    structure member in usb_hcd_giveback_urb.

    Fixes: 94dfd7edfd ("USB: HCD: support giveback of URB in tasklet context")
    Cc: stable <stable@kernel.org>
    Reviewed-by: Alan Stern <stern@rowland.harvard.edu>
    Signed-off-by: Weitao Wang <WeitaoWang-oc@zhaoxin.com>
    Link: https://lore.kernel.org/r/20220726074918.5114-1-WeitaoWang-oc@zhaoxin.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Torez Smith <torez@redhat.com>
2022-11-01 22:28:58 -04:00
Torez Smith d006b1dd87 usb: xhci_plat_remove: avoid NULL dereference
Bugzilla: http://bugzilla.redhat.com/2113003
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=48723298
Tested: HP ZBook 15 G5/80D5 Laptop
  ThinkPad P1 Gen5  TB4
  HP zBook Fury

commit d7de14d74d6551f0d097430f9893ce82ad17e5b8
Author: Alexey Sheplyakov <asheplyakov@basealt.ru>
Date:   Fri Jul 22 18:17:00 2022 +0400

    usb: xhci_plat_remove: avoid NULL dereference

    Since commit 4736ebd7fcaff1eb8481c140ba494962847d6e0a ("usb: host:
    xhci-plat: omit shared hcd if either root hub has no ports")
    xhci->shared_hcd can be NULL, which causes the following Oops
    on reboot:

    [  710.124450] systemd-shutdown[1]: Rebooting.
    [  710.298861] xhci-hcd xhci-hcd.2.auto: remove, state 4
    [  710.304217] usb usb3: USB disconnect, device number 1
    [  710.317441] xhci-hcd xhci-hcd.2.auto: USB bus 3 deregistered
    [  710.323280] xhci-hcd xhci-hcd.2.auto: remove, state 1
    [  710.328401] usb usb2: USB disconnect, device number 1
    [  710.333515] usb 2-3: USB disconnect, device number 2
    [  710.467649] xhci-hcd xhci-hcd.2.auto: USB bus 2 deregistered
    [  710.475450] Unable to handle kernel NULL pointer dereference at virtual address 00000000000003b8
    [  710.484425] Mem abort info:
    [  710.487265]   ESR = 0x0000000096000004
    [  710.491060]   EC = 0x25: DABT (current EL), IL = 32 bits
    [  710.496427]   SET = 0, FnV = 0
    [  710.499525]   EA = 0, S1PTW = 0
    [  710.502716]   FSC = 0x04: level 0 translation fault
    [  710.507648] Data abort info:
    [  710.510577]   ISV = 0, ISS = 0x00000004
    [  710.514462]   CM = 0, WnR = 0
    [  710.517480] user pgtable: 4k pages, 48-bit VAs, pgdp=00000008b0050000
    [  710.523976] [00000000000003b8] pgd=0000000000000000, p4d=0000000000000000
    [  710.530961] Internal error: Oops: 96000004 [#1] PREEMPT SMP
    [  710.536551] Modules linked in: rfkill input_leds snd_soc_simple_card snd_soc_simple_card_utils snd_soc_nau8822 designware_i2s snd_soc_core dw_hdmi_ahb_audio snd_pcm_dmaengine arm_ccn panfrost ac97_bus gpu_sched snd_pcm at24 fuse configfs sdhci_of_dwcmshc sdhci_pltfm sdhci nvme led_class mmc_core nvme_core bt1_pvt polynomial tp_serio snd_seq_midi snd_seq_midi_event snd_seq snd_timer snd_rawmidi snd_seq_device snd soundcore efivarfs ipv6
    [  710.575286] CPU: 7 PID: 1 Comm: systemd-shutdow Not tainted 5.19.0-rc7-00043-gfd8619f4fd54 #1
    [  710.583822] Hardware name: T-Platforms TF307-MB/BM1BM1-A, BIOS 5.6 07/06/2022
    [  710.590972] pstate: 40000005 (nZcv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
    [  710.597949] pc : usb_remove_hcd+0x34/0x1e4
    [  710.602067] lr : xhci_plat_remove+0x74/0x140
    [  710.606351] sp : ffff800009f3b7c0
    [  710.609674] x29: ffff800009f3b7c0 x28: ffff000800960040 x27: 0000000000000000
    [  710.616833] x26: ffff800008dc22a0 x25: 0000000000000000 x24: 0000000000000000
    [  710.623992] x23: 0000000000000000 x22: ffff000805465810 x21: ffff000805465800
    [  710.631149] x20: ffff000800f80000 x19: 0000000000000000 x18: ffffffffffffffff
    [  710.638307] x17: ffff000805096000 x16: ffff00080633b800 x15: ffff000806537a1c
    [  710.645465] x14: 0000000000000001 x13: 0000000000000000 x12: ffff00080378d6f0
    [  710.652621] x11: ffff00080041a900 x10: ffff800009b204e8 x9 : ffff8000088abaa4
    [  710.659779] x8 : ffff000800960040 x7 : ffff800009409000 x6 : 0000000000000001
    [  710.666936] x5 : ffff800009241000 x4 : ffff800009241440 x3 : 0000000000000000
    [  710.674094] x2 : ffff000800960040 x1 : ffff000800960040 x0 : 0000000000000000
    [  710.681251] Call trace:
    [  710.683704]  usb_remove_hcd+0x34/0x1e4
    [  710.687467]  xhci_plat_remove+0x74/0x140
    [  710.691400]  platform_remove+0x34/0x70
    [  710.695165]  device_remove+0x54/0x90
    [  710.698753]  device_release_driver_internal+0x200/0x270
    [  710.703992]  device_release_driver+0x24/0x30
    [  710.708273]  bus_remove_device+0xe0/0x16c
    [  710.712293]  device_del+0x178/0x390
    [  710.715797]  platform_device_del.part.0+0x24/0x90
    [  710.720514]  platform_device_unregister+0x30/0x50
    [  710.725232]  dwc3_host_exit+0x20/0x30
    [  710.728907]  dwc3_remove+0x174/0x1b0
    [  710.732494]  platform_remove+0x34/0x70
    [  710.736254]  device_remove+0x54/0x90
    [  710.739840]  device_release_driver_internal+0x200/0x270
    [  710.745078]  device_release_driver+0x24/0x30
    [  710.749359]  bus_remove_device+0xe0/0x16c
    [  710.753380]  device_del+0x178/0x390
    [  710.756881]  platform_device_del.part.0+0x24/0x90
    [  710.761598]  platform_device_unregister+0x30/0x50
    [  710.766314]  of_platform_device_destroy+0xe8/0x100
    [  710.771119]  device_for_each_child_reverse+0x70/0xc0
    [  710.776099]  of_platform_depopulate+0x48/0x90
    [  710.780468]  __dwc3_of_simple_teardown+0x28/0xe0
    [  710.785099]  dwc3_of_simple_shutdown+0x20/0x30
    [  710.789555]  platform_shutdown+0x30/0x40
    [  710.793490]  device_shutdown+0x138/0x32c
    [  710.797425]  __do_sys_reboot+0x1c4/0x2ac
    [  710.801362]  __arm64_sys_reboot+0x30/0x40
    [  710.805383]  invoke_syscall+0x50/0x120
    [  710.809146]  el0_svc_common.constprop.0+0x68/0x124
    [  710.813950]  do_el0_svc+0x3c/0xcc
    [  710.817275]  el0_svc+0x60/0x12c
    [  710.820428]  el0t_64_sync_handler+0xc0/0x13c
    [  710.824710]  el0t_64_sync+0x18c/0x190
    [  710.828386] Code: a9025bf5 f942c420 f9001fe0 d2800000 (b943ba62)
    [  710.834498] ---[ end trace 0000000000000000 ]---
    [  710.875958] pstore: crypto_comp_compress failed, ret = -22!
    [  710.895047] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
    [  710.902757] Kernel Offset: disabled
    [  710.906255] CPU features: 0x800,00004811,00001082
    [  710.910971] Memory Limit: none
    [  710.927474] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b ]---

    To avoid the problem check for NULL in usb_remove_hcd.

    Fixes: 4736ebd7fcaf ("usb: host: xhci-plat: omit shared hcd if either root hub has no ports")
    Signed-off-by: Alexey Sheplyakov <asheplyakov@basealt.ru>
    Link: https://lore.kernel.org/r/20220722141700.1271439-1-asheplyakov@basealt.ru
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Torez Smith <torez@redhat.com>
2022-11-01 22:28:58 -04:00
Torez Smith efd116a707 ARM: sa1100/assabet: move dmabounce hack to ohci driver
Bugzilla: http://bugzilla.redhat.com/2113003
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=48723298
Tested: HP ZBook 15 G5/80D5 Laptop
  ThinkPad P1 Gen5  TB4
  HP zBook Fury

commit 9ba26f5cecd86c85551a5120529c2f548099100f
Author: Arnd Bergmann <arnd@arndb.de>
Date:   Thu Feb 3 09:36:33 2022 +0100

    ARM: sa1100/assabet: move dmabounce hack to ohci driver

    The sa1111 platform is one of the two remaining users of the old Arm
    specific "dmabounce" code, which is an earlier implementation of the
    generic swiotlb.

    Linus Walleij submitted a patch that removes dmabounce support from
    the ixp4xx, and I had a look at the other user, which is the sa1111
    companion chip.

    Looking at how dmabounce is used, I could narrow it down to one driver
    one three machines:

     - dmabounce is only initialized on assabet/neponset, jornada720 and
       badge4, which are the platforms that have an sa1111 and support
       DMA on it.

     - All three of these suffer from "erratum #7" that requires only
       doing DMA to half the memory sections based on one of the address
       lines, in addition, the neponset also can't DMA to the RAM that
       is connected to sa1111 itself.

     - the pxa lubbock machine also has sa1111, but does not support DMA
       on it and does not set dmabounce.

     - only the OHCI and audio devices on sa1111 support DMA, but as
       there is no audio driver for this hardware, only OHCI remains.

    In the OHCI code, I noticed that two other platforms already have
    a local bounce buffer support in the form of the "local_mem"
    allocator. Specifically, TMIO and SM501 use this on a few other ARM
    boards with 16KB or 128KB of local SRAM that can be accessed from the
    OHCI and from the CPU.

    While this is not the same problem as on sa1111, I could not find a
    reason why we can't re-use the existing implementation but replace the
    physical SRAM address mapping with a locally allocated DMA buffer.

    There are two main downsides:

     - rather than using a dynamically sized pool, this buffer needs
       to be allocated at probe time using a fixed size. Without
       having any idea of what it should be, I picked a size of
       64KB, which is between what the other two OHCI front-ends use
       in their SRAM. If anyone has a better idea what that size
       is reasonable, this can be trivially changed.

     - Previously, only USB transfers to unaddressable memory needed
       to go through the bounce buffer, now all of them do, which may
       impact runtime performance for USB endpoints that do a lot of
       transfers.

    On the upside, the local_mem support uses write-combining buffers,
    which should be a bit faster for transfers to the device compared to
    normal uncached coherent memory as used in dmabounce.

    Cc: Linus Walleij <linus.walleij@linaro.org>
    Cc: Russell King <linux@armlinux.org.uk>
    Cc: Christoph Hellwig <hch@infradead.org>
    Cc: Laurentiu Tudor <laurentiu.tudor@nxp.com>
    Cc: linux-usb@vger.kernel.org
    Signed-off-by: Arnd Bergmann <arnd@arndb.de>
    Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Acked-by: Alan Stern <stern@rowland.harvard.edu>
    Signed-off-by: Christoph Hellwig <hch@lst.de>

Signed-off-by: Torez Smith <torez@redhat.com>
2022-11-01 22:28:43 -04:00
Torez Smith 7569ce7e68 usb: core: hcd: Add support for deferring roothub registration
Bugzilla: http://bugzilla.redhat.com/2084667
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=46653455
Tested: HP ZBook 15 G5/80D5 Laptop

commit a44623d9279086c89f631201d993aa332f7c9e66
Author: Kishon Vijay Abraham I <kishon@ti.com>
Date:   Tue May 10 14:46:29 2022 +0530

    usb: core: hcd: Add support for deferring roothub registration

    It has been observed with certain PCIe USB cards (like Inateck connected
    to AM64 EVM or J7200 EVM) that as soon as the primary roothub is
    registered, port status change is handled even before xHC is running
    leading to cold plug USB devices not detected. For such cases, registering
    both the root hubs along with the second HCD is required. Add support for
    deferring roothub registration in usb_add_hcd(), so that both primary and
    secondary roothubs are registered along with the second HCD.

    This patch has been added and reverted earier as it triggered a race
    in usb device enumeration.
    That race is now fixed in 5.16-rc3, and in stable back to 5.4
    commit 6cca13de26ee ("usb: hub: Fix locking issues with address0_mutex")
    commit 6ae6dc22d2d1 ("usb: hub: Fix usb enumeration issue due to address0
    race")

    CC: stable@vger.kernel.org # 5.4+
    Suggested-by: Mathias Nyman <mathias.nyman@linux.intel.com>
    Tested-by: Chris Chiu <chris.chiu@canonical.com>
    Acked-by: Alan Stern <stern@rowland.harvard.edu>
    Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
    Link: https://lore.kernel.org/r/20220510091630.16564-2-kishon@ti.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Torez Smith <torez@redhat.com>
2022-07-25 15:38:36 -04:00
Torez Smith e123ccb9b1 Revert "usb: core: hcd: Create platform devices for onboard hubs in probe()"
Bugzilla: http://bugzilla.redhat.com/2084667
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=46653455
Tested: HP ZBook 15 G5/80D5 Laptop

commit f2b6e79c7378542e03e42fd47c0c8bf00a2fcf6b
Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date:   Tue May 3 16:44:02 2022 +0200

    Revert "usb: core: hcd: Create platform devices for onboard hubs in probe()"

    This reverts commit c40b62216c1aecc0dc00faf33d71bd71cb440337.

    The series still has built errors as reported in linux-next, so revert
    it for now.

    Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
    Link: https://lore.kernel.org/r/20220502210728.0b36f3cd@canb.auug.org.au
    Cc: Stephen Boyd <swboyd@chromium.org>
    Cc: Douglas Anderson <dianders@chromium.org>
    Cc: Matthias Kaehlcke <mka@chromium.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Torez Smith <torez@redhat.com>
2022-07-25 15:38:26 -04:00
Torez Smith 462dfd241b usb: core: hcd: Create platform devices for onboard hubs in probe()
Bugzilla: http://bugzilla.redhat.com/2084667
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=46653455
Tested: HP ZBook 15 G5/80D5 Laptop

commit c40b62216c1aecc0dc00faf33d71bd71cb440337
Author: Matthias Kaehlcke <mka@chromium.org>
Date:   Thu Feb 17 10:42:54 2022 -0800

    usb: core: hcd: Create platform devices for onboard hubs in probe()

    Call onboard_hub_create/destroy_pdevs() from usb_add/remove_hcd()
    for primary HCDs to create/destroy platform devices for onboard
    USB hubs that may be connected to the root hub of the controller.
    These functions are a NOP unless CONFIG_USB_ONBOARD_HUB=y/m.

    Also add a field to struct usb_hcd to keep track of the onboard hub
    platform devices that are owned by the HCD.

    Reviewed-by: Douglas Anderson <dianders@chromium.org>
    Reviewed-by: Stephen Boyd <swboyd@chromium.org>
    Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
    Link: https://lore.kernel.org/r/20220217104219.v21.3.I7a3a7d9d2126c34079b1cab87aa0b2ec3030f9b7@changeid
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Torez Smith <torez@redhat.com>
2022-07-25 15:38:24 -04:00
Torez Smith 169237e0aa USB: core: Fix hang in usb_kill_urb by adding memory barriers
Bugzilla: http://bugzilla.redhat.com/2061784
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=45014530
Tested: HP ZBook 15 G5/80D5 Laptop
 TGL-U(QS) Laptop

commit 26fbe9772b8c459687930511444ce443011f86bf
Author: Alan Stern <stern@rowland.harvard.edu>
Date:   Mon Jan 24 15:23:45 2022 -0500

    USB: core: Fix hang in usb_kill_urb by adding memory barriers

    The syzbot fuzzer has identified a bug in which processes hang waiting
    for usb_kill_urb() to return.  It turns out the issue is not unlinking
    the URB; that works just fine.  Rather, the problem arises when the
    wakeup notification that the URB has completed is not received.

    The reason is memory-access ordering on SMP systems.  In outline form,
    usb_kill_urb() and __usb_hcd_giveback_urb() operating concurrently on
    different CPUs perform the following actions:

    CPU 0                                   CPU 1
    ----------------------------            ---------------------------------
    usb_kill_urb():                         __usb_hcd_giveback_urb():
      ...                                     ...
      atomic_inc(&urb->reject);               atomic_dec(&urb->use_count);
      ...                                     ...
      wait_event(usb_kill_urb_queue,
            atomic_read(&urb->use_count) == 0);
                                              if (atomic_read(&urb->reject))
                                                    wake_up(&usb_kill_urb_queue);

    Confining your attention to urb->reject and urb->use_count, you can
    see that the overall pattern of accesses on CPU 0 is:

            write urb->reject, then read urb->use_count;

    whereas the overall pattern of accesses on CPU 1 is:

            write urb->use_count, then read urb->reject.

    This pattern is referred to in memory-model circles as SB (for "Store
    Buffering"), and it is well known that without suitable enforcement of
    the desired order of accesses -- in the form of memory barriers -- it
    is entirely possible for one or both CPUs to execute their reads ahead
    of their writes.  The end result will be that sometimes CPU 0 sees the
    old un-decremented value of urb->use_count while CPU 1 sees the old
    un-incremented value of urb->reject.  Consequently CPU 0 ends up on
    the wait queue and never gets woken up, leading to the observed hang
    in usb_kill_urb().

    The same pattern of accesses occurs in usb_poison_urb() and the
    failure pathway of usb_hcd_submit_urb().

    The problem is fixed by adding suitable memory barriers.  To provide
    proper memory-access ordering in the SB pattern, a full barrier is
    required on both CPUs.  The atomic_inc() and atomic_dec() accesses
    themselves don't provide any memory ordering, but since they are
    present, we can use the optimized smp_mb__after_atomic() memory
    barrier in the various routines to obtain the desired effect.

    This patch adds the necessary memory barriers.

    CC: <stable@vger.kernel.org>
    Reported-and-tested-by: syzbot+76629376e06e2c2ad626@syzkaller.appspotmail.com
    Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
    Link: https://lore.kernel.org/r/Ye8K0QYee0Q0Nna2@rowland.harvard.edu
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Torez Smith <torez@redhat.com>
2022-05-02 15:30:38 -04:00
Torez Smith 63d30fb338 USB: Fix "slab-out-of-bounds Write" bug in usb_hcd_poll_rh_status
Bugzilla: http://bugzilla.redhat.com/2061784
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=45014530
Tested: HP ZBook 15 G5/80D5 Laptop
 TGL-U(QS) Laptop

commit 1d7d4c07932e04355d6e6528d44a2f2c9e354346
Author: Alan Stern <stern@rowland.harvard.edu>
Date:   Fri Dec 31 21:07:12 2021 -0500

    USB: Fix "slab-out-of-bounds Write" bug in usb_hcd_poll_rh_status

    When the USB core code for getting root-hub status reports was
    originally written, it was assumed that the hub driver would be its
    only caller.  But this isn't true now; user programs can use usbfs to
    communicate with root hubs and get status reports.  When they do this,
    they may use a transfer_buffer that is smaller than the data returned
    by the HCD, which will lead to a buffer overflow error when
    usb_hcd_poll_rh_status() tries to store the status data.  This was
    discovered by syzbot:

    BUG: KASAN: slab-out-of-bounds in memcpy include/linux/fortify-string.h:225 [inline]
    BUG: KASAN: slab-out-of-bounds in usb_hcd_poll_rh_status+0x5f4/0x780 drivers/usb/core/hcd.c:776
    Write of size 2 at addr ffff88801da403c0 by task syz-executor133/4062

    This patch fixes the bug by reducing the amount of status data if it
    won't fit in the transfer_buffer.  If some data gets discarded then
    the URB's completion status is set to -EOVERFLOW rather than 0, to let
    the user know what happened.

    Reported-and-tested-by: syzbot+3ae6a2b06f131ab9849f@syzkaller.appspotmail.com
    Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
    Cc: <stable@vger.kernel.org>
    Link: https://lore.kernel.org/r/Yc+3UIQJ2STbxNua@rowland.harvard.edu
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Torez Smith <torez@redhat.com>
2022-05-02 15:30:35 -04:00
Torez Smith 57737e9040 usb: core: hcd: change sizeof(vaddr) to sizeof(unsigned long)
Bugzilla: http://bugzilla.redhat.com/2061784
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=45014530
Tested: HP ZBook 15 G5/80D5 Laptop
 TGL-U(QS) Laptop

commit a927ae1fba4b0aa51e1fa9b43c4018bbf10d27f6
Author: Guo Zhengkui <guozhengkui@vivo.com>
Date:   Thu Dec 9 14:23:05 2021 +0800

    usb: core: hcd: change sizeof(vaddr) to sizeof(unsigned long)

    `vaddr` is a pointer to unsigned char. sizeof(vaddr) here intends
    to get the size of a pointer. But readers may get confused. Change
    sizeof(vaddr) to sizeof(unsigned long) makes more sense.

    Suggested-by: Alan Stern <stern@rowland.harvard.edu>
    Signed-off-by: Guo Zhengkui <guozhengkui@vivo.com>
    Link: https://lore.kernel.org/r/20211209062441.9856-1-guozhengkui@vivo.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Torez Smith <torez@redhat.com>
2022-05-02 15:30:19 -04:00
Torez Smith fcd5790e48 Revert "usb: core: hcd: Add support for deferring roothub registration"
Bugzilla: http://bugzilla.redhat.com/2061784
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=45014530
Tested: HP ZBook 15 G5/80D5 Laptop
 TGL-U(QS) Laptop

commit 439b08c57c3fe1df85cfe9d00accdf9b62cb3275
Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date:   Wed Nov 3 16:51:36 2021 +0100

    Revert "usb: core: hcd: Add support for deferring roothub registration"

    This reverts commit 58877b0824da15698bd85a0a9dbfa8c354e6ecb7.

    It has been reported to be causing problems in Arch and Fedora bug
    reports.

    Reported-by: Hans de Goede <hdegoede@redhat.com>
    Link: https://bbs.archlinux.org/viewtopic.php?pid=2000956#p2000956
    Link: https://bugzilla.redhat.com/show_bug.cgi?id=2019542
    Link: https://bugzilla.redhat.com/show_bug.cgi?id=2019576
    Link: https://lore.kernel.org/r/42bcbea6-5eb8-16c7-336a-2cb72e71bc36@redhat.com
    Cc: Mathias Nyman <mathias.nyman@linux.intel.com>
    Cc: Chris Chiu <chris.chiu@canonical.com>
    Cc: Alan Stern <stern@rowland.harvard.edu>
    Cc: Kishon Vijay Abraham I <kishon@ti.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Torez Smith <torez@redhat.com>
2022-05-02 15:30:01 -04:00
Torez Smith 7f2709c3aa usb: core: hcd: fix messages in usb_hcd_request_irqs()
Bugzilla: http://bugzilla.redhat.com/2061784
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=45014530
Tested: HP ZBook 15 G5/80D5 Laptop
 TGL-U(QS) Laptop

commit a8426a43b0c0f257a090f8551d6b09b79b8095e5
Author: Sergey Shtylyov <s.shtylyov@omp.ru>
Date:   Thu Sep 16 23:04:41 2021 +0300

    usb: core: hcd: fix messages in usb_hcd_request_irqs()

    Two dev_info() calls in usb_hcd_request_irqs() mistreat the I/O port base
    address, calling it just "io base" instead of "io port".

    While fixing this, make indenataion of the argument lists more sane...

    Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>
    Link: https://lore.kernel.org/r/5d10014d-e58b-d081-ed7c-7424f649ce0b@omp.ru
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Torez Smith <torez@redhat.com>
2022-05-02 15:29:31 -04:00
Torez Smith e857e1618c usb: core: hcd: Modularize HCD stop configuration in usb_stop_hcd()
Bugzilla: http://bugzilla.redhat.com/2061784
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=45014530
Tested: HP ZBook 15 G5/80D5 Laptop
 TGL-U(QS) Laptop

commit 5cf86349e98b14f505f83aae45a6df2bacc15a7a
Author: Kishon Vijay Abraham I <kishon@ti.com>
Date:   Thu Sep 9 12:12:00 2021 +0530

    usb: core: hcd: Modularize HCD stop configuration in usb_stop_hcd()

    No functional change. Since configuration to stop HCD is invoked from
    multiple places, group all of them in usb_stop_hcd().

    Tested-by: Chris Chiu <chris.chiu@canonical.com>
    Acked-by: Alan Stern <stern@rowland.harvard.edu>
    Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
    Link: https://lore.kernel.org/r/20210909064200.16216-4-kishon@ti.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Torez Smith <torez@redhat.com>
2022-05-02 15:29:28 -04:00
Torez Smith c8da984020 usb: core: hcd: Add support for deferring roothub registration
Bugzilla: http://bugzilla.redhat.com/2061784
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=45014530
Tested: HP ZBook 15 G5/80D5 Laptop
 TGL-U(QS) Laptop

commit 58877b0824da15698bd85a0a9dbfa8c354e6ecb7
Author: Kishon Vijay Abraham I <kishon@ti.com>
Date:   Thu Sep 9 12:11:58 2021 +0530

    usb: core: hcd: Add support for deferring roothub registration

    It has been observed with certain PCIe USB cards (like Inateck connected
    to AM64 EVM or J7200 EVM) that as soon as the primary roothub is
    registered, port status change is handled even before xHC is running
    leading to cold plug USB devices not detected. For such cases, registering
    both the root hubs along with the second HCD is required. Add support for
    deferring roothub registration in usb_add_hcd(), so that both primary and
    secondary roothubs are registered along with the second HCD.

    CC: stable@vger.kernel.org # 5.4+
    Suggested-by: Mathias Nyman <mathias.nyman@linux.intel.com>
    Tested-by: Chris Chiu <chris.chiu@canonical.com>
    Acked-by: Alan Stern <stern@rowland.harvard.edu>
    Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
    Link: https://lore.kernel.org/r/20210909064200.16216-2-kishon@ti.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Torez Smith <torez@redhat.com>
2022-05-02 15:29:27 -04:00
Li Jun 216e0e563d usb: core: hcd: use map_urb_for_dma for single step set feature urb
Use map_urb_for_dma() to improve the dma map code for single step
set feature request urb in test mode.

Signed-off-by: Li Jun <jun.li@nxp.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Link: https://lore.kernel.org/r/1620452039-11694-3-git-send-email-jun.li@nxp.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-05-13 16:02:30 +02:00
Peter Chen cbbc07e1e8 usb: host: move EH SINGLE_STEP_SET_FEATURE implementation to core
It is needed at USB Certification test for Embedded Host 2.0, and
the detail is at CH6.4.1.1 of On-The-Go and Embedded Host Supplement
to the USB Revision 2.0 Specification. Since other USB 2.0 capable
host like XHCI also need it, so move it to HCD core.

Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
Link: https://lore.kernel.org/r/1620452039-11694-1-git-send-email-jun.li@nxp.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-05-13 16:01:59 +02:00
Thinh Nguyen 0299809be4 usb: core: Track SuperSpeed Plus GenXxY
Introduce ssp_rate field to usb_device structure to capture the
connected SuperSpeed Plus signaling rate generation and lane count with
the corresponding usb_ssp_rate enum.

Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Link: https://lore.kernel.org/r/b7805d121e5ae4ad5ae144bd860b6ac04ee47436.1615432770.git.Thinh.Nguyen@synopsys.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-03-23 13:12:37 +01:00
Sasha Levin 88a686728b kbuild: simplify access to the kernel's version
Instead of storing the version in a single integer and having various
kernel (and userspace) code how it's constructed, export individual
(major, patchlevel, sublevel) components and simplify kernel code that
uses it.

This should also make it easier on userspace.

Signed-off-by: Sasha Levin <sashal@kernel.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2021-02-16 12:01:45 +09:00
Andrey Konovalov e89eed02a5 kcov, usb: hide in_serving_softirq checks in __usb_hcd_giveback_urb
Done opencode in_serving_softirq() checks in in_serving_softirq() to avoid
cluttering the code, hide them in kcov helpers instead.

Fixes: aee9ddb1d3 ("kcov, usb: only collect coverage from __usb_hcd_giveback_urb in softirq")
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Link: https://lore.kernel.org/r/aeb430c5bb90b0ccdf1ec302c70831c1a47b9c45.1609876340.git.andreyknvl@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-01-07 14:17:29 +01:00
Andrey Konovalov aee9ddb1d3 kcov, usb: only collect coverage from __usb_hcd_giveback_urb in softirq
Currently there's a KCOV remote coverage collection section in
__usb_hcd_giveback_urb(). Initially that section was added based on the
assumption that usb_hcd_giveback_urb() can only be called in interrupt
context as indicated by a comment before it. This is what happens when
syzkaller is fuzzing the USB stack via the dummy_hcd driver.

As it turns out, it's actually valid to call usb_hcd_giveback_urb() in task
context, provided that the caller turned off the interrupts; USB/IP does
exactly that. This can lead to a nested KCOV remote coverage collection
sections both trying to collect coverage in task context. This isn't
supported by KCOV, and leads to a WARNING.

Change __usb_hcd_giveback_urb() to only call kcov_remote_*() callbacks
when it's being executed in a softirq. As the result, the coverage from
USB/IP related usb_hcd_giveback_urb() calls won't be collected, but the
WARNING is fixed.

A potential future improvement would be to support nested remote coverage
collection sections, but this patch doesn't address that.

Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
Acked-by: Marco Elver <elver@google.com>
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Link: https://lore.kernel.org/r/f3a7a153f0719cb53ec385b16e912798bd3e4cf9.1602856358.git.andreyknvl@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-10-28 13:10:54 +01:00
Ahmed S. Darwish 41631d3616 usb: core: Replace in_interrupt() in comments
The usage of in_interrupt() in drivers is phased out for various reasons.

Various comments use !in_interrupt() to describe calling context for
functions which might sleep. That's wrong because the calling context has
to be preemptible task context, which is not what !in_interrupt()
describes.

Replace !in_interrupt() with more accurate plain text descriptions.

The comment for usb_hcd_poll_rh_status() is misleading as this function is
called from all kinds of contexts including preemptible task
context. Remove it as there is obviously no restriction.

Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Cc: linux-usb@vger.kernel.org
Link: https://lore.kernel.org/r/20201019101110.851821025@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-10-28 12:32:59 +01:00
Allen Pais e71ea55a5b usb: hcd: convert tasklets to use new tasklet_setup() API
In preparation for unconditionally passing the
struct tasklet_struct pointer to all tasklet
callbacks, switch to using the new tasklet_setup()
and from_tasklet() to pass the tasklet pointer explicitly.

Signed-off-by: Romain Perier <romain.perier@gmail.com>
Signed-off-by: Allen Pais <allen.lkml@gmail.com>
Link: https://lore.kernel.org/r/20200817090209.26351-4-allen.cryptic@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-08-18 13:00:00 +02:00
Gustavo A. R. Silva 0d9b6d49fe usb: Use fallthrough pseudo-keyword
Replace the existing /* fall through */ comments and its variants with
the new pseudo-keyword macro fallthrough[1]. Also, remove unnecessary
fall-through markings when it is the case.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html?highlight=fallthrough#implicit-switch-case-fall-through

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Link: https://lore.kernel.org/r/20200707195607.GA4198@embeddedor
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-07-10 08:55:17 +02:00
Andrey Konovalov 76e278d6b5 usb: core: kcov: collect coverage from usb complete callback
This patch adds kcov_remote_start/stop() callbacks around the urb
complete() callback that is executed in softirq context when dummy_hcd is
in use.  As the result, kcov can be used to collect coverage from those
callbacks, which is used to facilitate coverage-guided fuzzing with
syzkaller.

Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Marco Elver <elver@google.com>
Link: http://lkml.kernel.org/r/4520671eeb604adbc2432c248b0c07fbaa5519ef.1585233617.git.andreyknvl@google.com
Link: http://lkml.kernel.org/r/2821d497ac1cdc0efb5e00df30271e4a67fc8009.1584655448.git.andreyknvl@google.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-06-04 19:06:20 -07:00
Fredrik Noring f8c63edfd7 USB: Fix incorrect DMA allocations for local memory pool drivers
Fix commit 7b81cb6bdd ("usb: add a HCD_DMA flag instead of
guestimating DMA capabilities") where local memory USB drivers
erroneously allocate DMA memory instead of pool memory, causing

	OHCI Unrecoverable Error, disabled
	HC died; cleaning up

The order between hcd_uses_dma() and hcd->localmem_pool is now
arranged as in hcd_buffer_alloc() and hcd_buffer_free(), with the
test for hcd->localmem_pool placed first.

As an alternative, one might consider adjusting hcd_uses_dma() with

 static inline bool hcd_uses_dma(struct usb_hcd *hcd)
 {
-	return IS_ENABLED(CONFIG_HAS_DMA) && (hcd->driver->flags & HCD_DMA);
+	return IS_ENABLED(CONFIG_HAS_DMA) &&
+		(hcd->driver->flags & HCD_DMA) &&
+		(hcd->localmem_pool == NULL);
 }

One can also consider unsetting HCD_DMA for local memory pool drivers.

Fixes: 7b81cb6bdd ("usb: add a HCD_DMA flag instead of guestimating DMA capabilities")
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Fredrik Noring <noring@nocrew.org>
Link: https://lore.kernel.org/r/20191210172905.GA52526@sx9
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-12-11 09:06:41 +01:00
Kees Cook b3d53f5fce usb: core: Remove redundant vmap checks
Now that the vmap area checks are being performed in the DMA
infrastructure directly, there is no need to repeat them in USB.

Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
2019-10-31 06:40:43 -07:00
Marek Szyprowski 34c7ed72f4 usb: core: phy: add support for PHY calibration
Some PHYs (for example Exynos5 USB3.0 DRD PHY) require calibration to be
done after every USB HCD reset. Generic PHY framework has been already
extended with phy_calibrate() function in commit 36914111e6 ("drivers:
phy: add calibrate method"). This patch adds support for it to generic
PHY handling code in USB HCD core.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Tested-by: Anand Moon <linux.amoon@gmail.com>
Tested-by: Jochen Sprickerhof <jochen@sprickerhof.de>
Link: https://lore.kernel.org/r/20190829053028.32438-2-m.szyprowski@samsung.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-09-03 15:54:55 +02:00
Christoph Hellwig ac2658e0d9 usb: remove a stale comment in hcd_alloc_coherent
Now that we have the local memory pool implemented there is no
need to use dma_declare_coherent_memory.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20190903084615.19161-5-hch@lst.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-09-03 15:26:11 +02:00
Christoph Hellwig 7b81cb6bdd usb: add a HCD_DMA flag instead of guestimating DMA capabilities
The usb core is the only major place in the kernel that checks for
a non-NULL device dma_mask to see if a device is DMA capable.  This
is generally a bad idea, as all major busses always set up a DMA mask,
even if the device is not DMA capable - in fact bus layers like PCI
can't even know if a device is DMA capable at enumeration time.  This
leads to lots of workaround in HCD drivers, and also prevented us from
setting up a DMA mask for platform devices by default last time we
tried.

Replace this guess with an explicit HCD_DMA that is set by drivers that
appear to have DMA support.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20190816062435.881-4-hch@lst.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-08-21 10:03:35 -07:00
Christoph Hellwig edfbcb321f usb: add a hcd_uses_dma helper
The USB buffer allocation code is the only place in the usb core (and in
fact the whole kernel) that uses is_device_dma_capable, while the URB
mapping code uses the uses_dma flag in struct usb_bus.  Switch the buffer
allocation to use the uses_dma flag used by the rest of the USB code,
and create a helper in hcd.h that checks this flag as well as the
CONFIG_HAS_DMA to simplify the caller a bit.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20190811080520.21712-3-hch@lst.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-08-15 15:18:05 +02:00
Thiébaud Weksteen 27709ae4e2 usb: setup authorized_default attributes using usb_bus_notify
Currently, the authorized_default and interface_authorized_default
attributes for HCD are set up after the uevent has been sent to userland.
This creates a race condition where userland may fail to access this
file when processing the event. Move the appending of these attributes
earlier relying on the usb_bus_notify dispatcher.

Signed-off-by: Thiébaud Weksteen <tweek@google.com>
Cc: stable <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20190806110050.38918-1-tweek@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-08-08 16:07:34 +02:00
Dan Carpenter 94b9a70d32 usb/hcd: Fix a NULL vs IS_ERR() bug in usb_hcd_setup_local_mem()
The devm_memremap() function doesn't return NULL, it returns error
pointers.

Fixes: b0310c2f09 ("USB: use genalloc for USB HCs with local memory")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Link: https://lore.kernel.org/r/20190607135709.GC16718@mwanda
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-07-25 10:40:02 +02:00
Fredrik Noring ff2437befd usb: host: Fix excessive alignment restriction for local memory allocations
The PAGE_SHIFT alignment restriction to devm_gen_pool_create() quickly
exhaust local memory because most allocations are much smaller than
PAGE_SIZE. This causes USB device failures such as

	usb 1-2.1: reset full-speed USB device number 4 using sm501-usb
	sd 1:0:0:0: [sda] tag#0 UNKNOWN(0x2003) Result: hostbyte=0x03 driverbyte=0x00
	sd 1:0:0:0: [sda] tag#0 CDB: opcode=0x28 28 00 00 00 08 7c 00 00 f0 00
	print_req_error: I/O error, dev sda, sector 2172 flags 80700

when trying to boot from the SM501 USB controller on SH4 with QEMU.

Align allocations as required but not necessarily much more than that.
The HCCA, TD and ED structures align with 256, 32 and 16 byte memory
boundaries, as specified by the Open HCI[1]. The min_alloc_order argument
to devm_gen_pool_create is now somewhat arbitrarily set to 4 (16 bytes).
Perhaps it could be somewhat lower for general buffer allocations.

Reference:

[1] "Open Host Controller Interface Specification for USB",
    release 1.0a, Compaq, Microsoft, National Semiconductor, 1999,
    pp. 16, 19, 33.

Reported-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Fredrik Noring <noring@nocrew.org>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Christoph Hellwig <hch@lst.de>
2019-06-28 07:57:07 +02:00
Laurentiu Tudor 2d7a3dc3e2 USB: drop HCD_LOCAL_MEM flag
With the addition of the local memory allocator, the HCD_LOCAL_MEM
flag can be dropped and the checks against it replaced with a check
for the localmem_pool ptr being initialized.

Signed-off-by: Laurentiu Tudor <laurentiu.tudor@nxp.com>
Tested-by: Fredrik Noring <noring@nocrew.org>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
2019-06-03 16:00:08 +02:00
Laurentiu Tudor b0310c2f09 USB: use genalloc for USB HCs with local memory
For HCs that have local memory, replace the current DMA API usage with
a genalloc generic allocator to manage the mappings for these devices.
To help users, introduce a new HCD API, usb_hcd_setup_local_mem() that
will setup up the genalloc backing up the device local memory. It will
be used in subsequent patches.  This is in preparation for dropping
the existing "coherent" dma mem declaration APIs.  The current
implementation was relying on a short circuit in the DMA API that in
the end, was acting as an allocator for these type of devices.

Signed-off-by: Laurentiu Tudor <laurentiu.tudor@nxp.com>
Tested-by: Fredrik Noring <noring@nocrew.org>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
2019-06-03 16:00:07 +02:00
Raul E Rangel a4d6a2989d usb/hcd: Send a uevent signaling that the host controller had died
This change will send an OFFLINE event to udev with the ERROR=DEAD
environment variable set when the HC dies.

By notifying user space the appropriate policies can be applied.
i.e.,
 * Collect error logs.
 * Notify the user that USB is no longer functional.
 * Perform a graceful reboot.

Reported-by: kbuild test robot <lkp@intel.com>
Signed-off-by: Raul E Rangel <rrangel@chromium.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-04-25 11:07:09 +02:00
Greg Kroah-Hartman 8cdfd068c1 Merge 5.1-rc3 into usb-next
We want the USB fixes in here as well.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-04-01 07:42:04 +02:00
Chen-Yu Tsai e671765e52 usb: core: Try generic PHY_MODE_USB_HOST if usb_phy_roothub_set_mode fails
Some PHYs do not support PHY_MODE_USB_HOST_SS, i.e. USB 3.0 or higher.
Fall back and try the more generic PHY_MODE_USB_HOST if it fails.

Fixes: b97a313483 ("usb: core: comply to PHY framework")
Signed-off-by: Chen-Yu Tsai <wens@csie.org>
Tested-by: Neil Armstrong <narmstrong@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-03-26 16:48:55 +09:00
Chunfeng Yun 4d537f37e0 usb: introduce usb_ep_type_string() function
In some places, the code prints a human-readable USB endpoint
transfer type (e.g. "bulk"). This involves a switch statement
sometimes wrapped around in ({ ... }) block leading to code
repetition.
To make this scenario easier, here introduces usb_ep_type_string()
function, which returns a human-readable name of provided
endpoint type.
It also changes a few places switch was used to use this
new function.

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-03-26 16:45:03 +09:00