From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EBCDB606A322 for ; Wed, 2 Dec 2026 04:44:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=oM/XRAzI; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=dUBsQ+KU DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=n94dWlJRm2Re3ANC4gik8ZEsyDnCn+0FKHuVyiZcaOI=; b=oM/XRAzILOnL5L p8dpDj+XwmJVOq6+2E1/bUiJ0VKtiFC9RIadL2csSP54BUUsPOZ2EHZYkboB7EWicvLu+Jzg3pWMZ RFmLobyGuHdr5d0y5ZRP0WPBFyWt5wHQGrRfCpa7PpzSFSqpz2AODjomkarqSUjY/vZuyW8ImIezJ /bnA9PnXd/9moGeB90kg4d43MNQtqiaVGqJqY2yuXoeD/Z+T5Or4zFI8yYEHnyznepsW8Qjw8xaHJ K9GpN/Gf551FEehk+jPXy6komzZfWV0Orx1fL3cdgBJfprK+ITP9bRIIdvbu2NELjKz5QnH/n/w59 9Dm3GYFXPOwRr0Uqh4uQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYcCu-0000000ACdC-2dPb; Wed, 02 Dec 2026 04:44:40 +0000 Received: from mail-oo2-x0a.google.com ([2607:f8b0:4864:31::a]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYcCq-0000000ACay-0RCX for linux-mediatek@lists.infradead.org; Wed, 02 Dec 2026 04:44:37 +0000 Received: by mail-oo2-x0a.google.com with SMTP id 006d021491bc7-71ad9f62e49so1456597eaf.0 for ; Tue, 01 Dec 2026 20:44:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796186675; x=1796791475; darn=lists.infradead.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=n94dWlJRm2Re3ANC4gik8ZEsyDnCn+0FKHuVyiZcaOI=; b=dUBsQ+KUxgJM/C5pmbNb8gqyzJNNHkR0KHO9RYNz/+rl7LnUDKmVUts2/Hi7YyRU2L 4S8mz8EcSimAGfxiDBmPJgrUqmFf0jZWVxo8vBOrZB3DsiZRT9wUsgsX4crb8EVW9o3c A7u7XqRNR2DfY441wBkmuOicFWKxvpjkU46osPf4t6JiSklxugZnJQa5LRPGXvww0yuG Jbn/qzFMGi5kPOETZ90rH0yA7C8cHF2s72BvWybyEidRruNlFq/5KEgkrcJWt351jJeI 3lCLyT2rJHT1MZaxFGgeTo0uajAoAO7giq29WbHyvbtimO1H38aJYRDDquNpJm7cs//r ErJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796186675; x=1796791475; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=n94dWlJRm2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hvM+A85ke acUXP9dJiS/t2cq7RcfX5eYryq50XkQWccE9/q+zStWSMYGnF2BZCXWLCSEwiyhP1fBKNyGYLZY fW7AVqyUEvq6nl4Jt8uFkOHlJMxMMlb1plJcrltKrAqaWLtek3jfVgypxCk6g8LU6/N7DIfxOGv CfuKLpspue9eeVJhm11yfM2gM5Q0epeLm+W2JrvnjD26 X-Received: by 2002:a05:6820:16a0:b0:71b:40c:9d5c with SMTP id 006d021491bc7-71b3942fb61mr32600122eaf.29.1796186674670; Tue, 01 Dec 2026 20:44:34 -0800 (PST) Received: from ?IPV6:2600:8804:5716:d800::d500? ([2600:8804:5716:d800::d500]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-71b38015c51sm27085982eaf.3.2026.12.01.20.44.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Dec 2026 20:44:33 -0800 (PST) Message-ID: <8c827a28-e424-4a32-8c16-e8389c5c69ce@gmail.com> Date: Tue, 1 Dec 2026 22:44:31 -0600 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RESEND] usb: mtu3: keep interrupts disabled in gadget completion callbacks To: Alan Stern Cc: Chunfeng Yun , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, stable@kernel.org References: <20261130-usb-mtu3-callbacks-irqs-off-v1-1-b3180defb60c@gmail.com> <449e050f-4dab-4403-b507-f20514863b26@rowland.harvard.edu> Content-Language: en-US From: Ryan Brue In-Reply-To: <449e050f-4dab-4403-b507-f20514863b26@rowland.harvard.edu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261201_204436_201646_CC6125D7 X-CRM114-Status: GOOD ( 19.79 ) X-Spam-Score: -2.1 (--) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" X-Spam-Status: No, score=-4.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Hi Alan, thanks for the look. On 11/30/26 12:18 PM, Alan Stern wrote: > This seems like a strange approach. > > Yes, interrupts certainly should be disabled when the request's > completion routine is called. But why explicitly disable bottom halves? > And besides, doesn't spin_lock_irqsave() disable bottom halves already? Not in the sense that matters here. spin_lock_irqsave() turns interrupts off, but it leaves softirq_count() at zero, and mtu3_irq() is a threaded handler (no primary handler) since 13118959cb1a. So the completion runs in task context with interrupts off and neither hardirq_count() nor softirq_count() set. netif_rx() checks exactly those two counts, and when both are zero it does its own local_bh_disable()/local_bh_enable(). local_bh_enable() with interrupts disabled is the WARN that 625dd9076e35 intended to fix:   WARNING: kernel/softirq.c:430 at __local_bh_enable_ip+0x17c/0x188     netif_rx     rx_complete [u_ether]     usb_gadget_giveback_request     mtu3_req_complete     ...     mtu3_irq     irq_thread_fn Disabling bottom halves explicitly, outside the irqsave, means netif_rx() sees softirq_count() set and leaves BH alone. The NET_RX softirq it raises then runs at our local_bh_enable(), after interrupts are back on. > Also, why should a networking gadget depend on some particular BH > setting when the completion routine runs? Different UDC drivers will > behave in different ways, and the gadget driver has to work with all of > them. The only real guarantee is the one stated in the API, namely, > that interrupts will be disabled. If the gadget wants more, it has to > take the additional actions itself. The UDC driver isn't responsible. > > Alan Stern I agree that the API only promises interrupts disabled, but I don't think u_ether can take those actions itself. Called with interrupts off from task context, it can't call netif_rx(), and it can't wrap the call in its own local_bh_disable()/local_bh_enable() either, because that hits the same assertion. It would have to defer the receive path to a work item or similar. The callbacks used to run in hardirq context, where all of this is fine. They stopped doing so when mtu3 moved to a threaded handler. For force-threaded handlers the IRQ core already brackets the handler with local_bh_disable()/local_bh_enable() (irq_forced_thread_fn()) for this reason. mtu3 threads its handler voluntarily, so it doesn't get that. dwc3 had the same problem and fixed it the same way in the controller, in 84918a89d6ef ("usb: dwc3: gadget: Let the interrupt handler disable bottom halves."), which this follows. Also, the BH part is already in mainline: 625dd9076e35 (in v7.4-rc5) switched mtu3_irq() to spin_lock_bh(). That made the callbacks run with interrupts enabled, which breaks the guarantee you quote: u_serial's console callback takes a lock that printk takes with spin_lock_irqsave() on the same CPU. This patch only restores interrupts-off and keeps the BH disabling. If you'd rather see the gadget side changed instead, I can look at that, but mtu3 would still need this fix, since 625dd9076e35 breaks the interrupts-disabled guarantee on its own (my bad :|). Best regards, Ryan Brue