Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1892704pxb; Wed, 20 Oct 2021 14:02:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzg4Knq1+UN2iguNFFEEr7OGWhoqxoL7sQLUp2ejUVCs0X2RT01CWeiAe3VBxHXsyYLT8cK X-Received: by 2002:aa7:c2da:: with SMTP id m26mr1778480edp.89.1634763744291; Wed, 20 Oct 2021 14:02:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634763744; cv=none; d=google.com; s=arc-20160816; b=KZsTpP/zoY2i8A9xmpuCp0BdruIfGlMPksHDhOvTOaWqbajE3LdwlDq/OUgaouhJBF 74oF2NVoialUqgDjH8wWM2pdIqE9NB6IXJhSiTZELzXBe6+Xv56GeRR7L6Y1A8j0tjz5 LBkYePKBrHR2qBZbmtAOUxJuz0+ZYR+xESubhSL4P7h1hoAYObJ2F7scyJFS+t8rR0Vk 180Z4MteVjX5CWSPd8KzQ7VGw9kBDHj2nk/miRjo+iFyWI6BZGJu4/FgLw1lD4EaD+ug N5bx0Y3DTt0tGtjXzuhdPir+gwAYhgoGSEZGDJd9z/Zp9BHqiH63H3OIsExGr/cZi6rI AL3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:subject:from :references:cc:to:dkim-signature; bh=ej3tolcgPxSkmZKxTFzlEV+yeFLAQSjDBgYwepQ5Y2A=; b=0tChZ9u3/gC+g/m5+hhS88sxduWc++tVheT+ZpVu/DpK46f3YeXETxPdTYtm2wyIe9 u8lp5HkbNo6jO/AWR4mxQCsaPbWxdf44vMffAZ/b6BANu1lNAZRJJm1jfdVSF3iDGq2r PxuWyK7zODfkCMp4rYrkuUr6POs+VJdJx9m0Gxb8QZhLpxnl9yTB1sala3AjkkhaVUtC OzXD/WqM51sydI+nR1WiZgy5IFO/xOxTP6hdo7EpViz9cVWBwpDeiPtfjpNZ+kWcWuNP yPgVvNJi4vhqCFJZyC7dVGPWAv1cIgplRgMl6wPj8P4aB9tPiW8pGpbgWlhhbbYWIncQ oXnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=E4jWBuQc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c12si7165514ede.394.2021.10.20.14.01.51; Wed, 20 Oct 2021 14:02:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=E4jWBuQc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230269AbhJTU7C (ORCPT + 99 others); Wed, 20 Oct 2021 16:59:02 -0400 Received: from smtp-relay-internal-1.canonical.com ([185.125.188.123]:56244 "EHLO smtp-relay-internal-1.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230049AbhJTU7B (ORCPT ); Wed, 20 Oct 2021 16:59:01 -0400 Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id B42B33F320 for ; Wed, 20 Oct 2021 20:56:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1634763404; bh=ej3tolcgPxSkmZKxTFzlEV+yeFLAQSjDBgYwepQ5Y2A=; h=To:Cc:References:From:Subject:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=E4jWBuQcHPNGhupYX3qlsuIbG9SCZpbb5knizIWG+id5bnvEy/123OF9WSWAAVv/3 4Na9dTUvQlpdyI7lJ3p9gkURDJVtXTlIqchgm0SUGRKSHqo89L54kYs/YYm1yHOUH+ iwW1mpwuum5mmLSq85vdVfD/twAQHnrBdvpw3sDV0F2E/rRBw+AlcrVbN/jJdFjDMt pN4OiSdw/3iPVDOVuyrmFqka35TQ91IoIJD4JbqlrVzGUEFAbwYesKPx8iJKef+tsK 7sEEwBBGEAQ4bgBOL/OrR3/sdhCAhxzK+usK/k8+jZF7YB/PN3zmx0FYCe5HfhtobU tNECw/uCHZRiQ== Received: by mail-lf1-f70.google.com with SMTP id k8-20020a0565123d8800b003fd6e160c77so3533019lfv.17 for ; Wed, 20 Oct 2021 13:56:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:to:cc:references:from:subject:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=ej3tolcgPxSkmZKxTFzlEV+yeFLAQSjDBgYwepQ5Y2A=; b=hKpyBO7sM5HEHOx/aIHBx9yOdtG2aUhHhMUdJ+0W+DnUo7Gmmiwzme+HxhjZBaz/oM mBG4YwIkol9GrvP2qd9e0EAThYWypWs/J9s0zkVuYqLIcb38XAMFiAwCbQGwhr/ZBCVR 4mCWku1gIhhgjX++6Py98HVCcZ/C8OoKPaAjA480HUlzcLf8P7uDqT7wJ+Kw8jiHJU7U 5hStixBb0f52jM9iMZF4bO38gS+8KInTBDTdqdwl6ZBdAqsqku0eIC4BIo0OteEZrjuM SiQgcmHSPrVKDLcTdACdoviCnn6f2ERY++CJIQoX0eL24x0SScJyGrmtWScGFsxcbNpD F0cw== X-Gm-Message-State: AOAM531PWg51Qyl/F7H5UpHKiac/7gtikO4zBohAxNzEYA9ENLJbcwpi WsvIlcTjEub6WLYgU/1ZfI1WhM1Zt1tZuJf5URZ7/Xf7eM2f4mJwb+Un33R5NzXJ+OU/Hh8HNKq P7zklY4pCMUf7inpaVZ4IDxaU6hVG2uUviR8XGSuLLg== X-Received: by 2002:a05:6512:398d:: with SMTP id j13mr1475184lfu.292.1634763404025; Wed, 20 Oct 2021 13:56:44 -0700 (PDT) X-Received: by 2002:a05:6512:398d:: with SMTP id j13mr1475160lfu.292.1634763403744; Wed, 20 Oct 2021 13:56:43 -0700 (PDT) Received: from [192.168.3.161] (89-77-68-124.dynamic.chello.pl. [89.77.68.124]) by smtp.gmail.com with ESMTPSA id a11sm276538lfl.157.2021.10.20.13.56.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 20 Oct 2021 13:56:43 -0700 (PDT) To: Alan Stern , Felipe Balbi , Greg Kroah-Hartman Cc: syzbot , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, syzkaller-bugs@googlegroups.com, Pavel Skripkin , Thierry Escande , Andrey Konovalov References: <000000000000c644cd05c55ca652@google.com> <9e06e977-9a06-f411-ab76-7a44116e883b@canonical.com> <20210722144721.GA6592@rowland.harvard.edu> From: Krzysztof Kozlowski Subject: Re: [syzbot] INFO: task hung in port100_probe Message-ID: Date: Wed, 20 Oct 2021 22:56:42 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20210722144721.GA6592@rowland.harvard.edu> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 22/07/2021 16:47, Alan Stern wrote: > On Thu, Jul 22, 2021 at 04:20:10PM +0200, Krzysztof Kozlowski wrote: >> On 22/06/2021 17:43, syzbot wrote: >>> Hello, >>> >>> syzbot found the following issue on: >>> >>> HEAD commit: fd0aa1a4 Merge tag 'for-linus' of git://git.kernel.org/pub.. >>> git tree: upstream >>> console output: https://syzkaller.appspot.com/x/log.txt?x=13e1500c300000 >>> kernel config: https://syzkaller.appspot.com/x/.config?x=7ca96a2d153c74b0 >>> dashboard link: https://syzkaller.appspot.com/bug?extid=abd2e0dafb481b621869 >>> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1792e284300000 >>> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=13ad9d48300000 >>> >>> IMPORTANT: if you fix the issue, please add the following tag to the commit: >>> Reported-by: syzbot+abd2e0dafb481b621869@syzkaller.appspotmail.com >>> >>> INFO: task kworker/0:1:7 blocked for more than 143 seconds. >>> Not tainted 5.13.0-rc6-syzkaller #0 >>> "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. >>> task:kworker/0:1 state:D stack:25584 pid: 7 ppid: 2 flags:0x00004000 >>> Workqueue: usb_hub_wq hub_event >>> Call Trace: >>> context_switch kernel/sched/core.c:4339 [inline] >>> __schedule+0x916/0x23e0 kernel/sched/core.c:5147 >>> schedule+0xcf/0x270 kernel/sched/core.c:5226 >>> schedule_timeout+0x1db/0x250 kernel/time/timer.c:1868 >>> do_wait_for_common kernel/sched/completion.c:85 [inline] >>> __wait_for_common kernel/sched/completion.c:106 [inline] >>> wait_for_common kernel/sched/completion.c:117 [inline] >>> wait_for_completion+0x168/0x270 kernel/sched/completion.c:138 >>> port100_send_cmd_sync drivers/nfc/port100.c:923 [inline] >>> port100_get_command_type_mask drivers/nfc/port100.c:1008 [inline] >>> port100_probe+0x9e4/0x1340 drivers/nfc/port100.c:1554 >>> usb_probe_interface+0x315/0x7f0 drivers/usb/core/driver.c:396 > ... > >> Cc: Thierry, Alan, Andrey, >> >> The issue is reproducible immediately on QEMU instance with >> USB_DUMMY_HCD and USB_RAW_GADGET. I don't know about real port100 NFC >> device. >> >> I spent some time looking into this and have no clue, except that it >> looks like an effect of a race condition. >> >> 1. When using syskaller reproducer against one USB device (In the C >> reproducer change the loop in main() to use procid=0) - issue does not >> happen. >> >> 2. With two threads or more talking to separate Dummy USB devices, the >> issue appears. The more of them, the better... >> >> 3. The reported problem is in missing complete. The correct flow is like: >> port100_probe() >> port100_get_command_type_mask() >> port100_send_cmd_sync() >> port100_send_cmd_async() >> port100_submit_urb_for_ack() >> port100_send_complete() >> [ 63.363863] port100 2-1:0.0: NFC: Urb failure (status -71) >> port100_recv_ack() >> [ 63.369942] port100 2-1:0.0: NFC: Urb failure (status -71) >> >> and schedule_work() which completes and unblocks port100_send_cmd_sync >> >> However in the failing case (hung task) the port100_recv_ack() is never >> called. It looks like USB core / HCD / gadget does not send the Ack/URB >> complete. >> >> I don't know why. The port100 NFC driver code looks OK, except it is not >> prepared for missing ack/urb so it waits indefinitely. I could try to >> convert it to wait_for_completion_timeout() but it won't be trivial and >> more important - I am not sure if this is the problem. Somehow the ACK >> with Urb failure is not sent back to the port100 device. Therefore I am >> guessing that the race condition is somwhere in USB stack, not in >> port100 driver. >> >> The lockdep and other testing tools did not find anything here. >> >> Anyone hints where the issue could be? > > Here's what I wrote earlier: "It looks like the problem stems from the fact > that port100_send_frame_async() submits two URBs, but > port100_send_cmd_sync() only waits for one of them to complete. The other > URB may then still be active when the driver tries to reuse it." > > Of course, there may be more than one problem, so we may not be talking > about the same thing. Hi Alan, Felipe, Greg and others, This is an old issue reported by syzkaller for NFC port100 driver [1]. There is something similar for pn533 [2]. I was looking at it some time ago, took a break and now I am trying to fix it again. Without success. The issue is reproducible via USB gadget on QEMU, not on real HW. I looked and debugged the code and I think previously mentioned double-URB-submit is not the reason here. Or I miss how the USB works (which is quite probable...). 1. The port100 driver calls port100_send_cmd_sync() which eventually goes to port100_send_frame_async(). After it, it waits for "sync" completion. 2. In port100_send_frame_async(), driver indeed first submits "out_urb" which quite fast is being processed by dummy_hcd with "no ep configured" and -EPROTO. 3. Then (or sometimes before -EPROTO response from (2) above) the port100_send_frame_async() submits "in_urb" via port100_submit_urb_for_ack() and waits for its completion. Completion of "in_urb" (or the "ack") in port100_recv_ack() would schedule work to complete the (1) above - the sync completion. 4. Usually, when reproducer works fine (does not trigger issue), the dummy_timer() from gadget responds with the same "no ep configured for urb" for this "in_urb" (3). This completes "in_urb", which eventually completes (1) and probe finishes with error. Error is expected, because it's random junk-gadget... The syzkaller reproducer fails if >1 of threads are running these usb gadgets. When this happens, no "in_urb" completion happens. No this "ack" port100_recv_ack(). I added some debugs and simply dummy_hcd dummy_timer() is woken up on enqueuing in_urb and then is looping crazy on a previous URB (some older URB, coming from before port100 driver probe started). The dummy_timer() loop never reaches the second "in_urb" to process it, I think. The pn533 NFC driver has similar design, but I have now really doubts it is a NFC driver issue. Instead an issue in dummy gadget HCD is somehow triggered by the reproducer. Reproduction - just follow [1] or [2]. Eventually I slightly tweaked the code and put here: https://github.com/krzk/tools/tree/master/tests-var/nfc/port100_probe $ make $ sudo ./port100_probe [1] https://syzkaller.appspot.com/bug?extid=abd2e0dafb481b621869 [2] https://syzkaller.appspot.com/bug?extid=1dc8b460d6d48d7ef9ca Best regards, Krzysztof