From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.231.138 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796186676; b=3ayrchG1OlsNrIjQk+3vW6orfVhVPP8oZwFanPa6txV/vSEC95Z9+tWku0ptZO1MUtqe nNaRXwqOY1ta8cM6+TAsoG6sy+52gVZ7rdixD1a5SL/cqS+7VIdjEwvpkzz4Dhwu3p9rI 9q0UH1R9T2CB9EKjCes1F5vcUyGOlny8ITLo0zF7KW2attA/vj1QIwS7uEADXyjZAP/aS CX7WdKrCxTERQs0krxkB8AAXsEQRvPj5qawXOlfB0GR+dIs9eBNyVf0syxltH7EI2zXfZ eiIc5fCasNHDjCzitffM6d9102MD8zxSQ/ld57ghyZta6sPB/e12eNWYDT6ZUSnWk8w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796186676; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=n94dWlJRm2Re3ANC4gik8ZEsyDnCn+0FKHuVyiZcaOI=; b=TuuzxNTECIEmGsVuy//s5vVsTwxXrOJr/5FbSFKMAwhTyLi44xH3g3jTKBj6NLtMQP6Q Frc54652kEpiEgx53I9OIZEefwsiVAmJUkPobbwCE/8zVlH6IMA+cgWBr+5WZ/V9NNWi6 PPabS8xTEp7s+qzpIPBAed2k71zcomOPh5DpgU5sq0eNEa0nOL1TkfzWuRQZN3iu80kVq 61XN70ODf8h8GocJsZ8YjdxYtNQXnmpOi5DEBMBc3dSGMENzvxaQL1kBr+s1XIMx1raaB NtgnhwF/145f5UcGgHMCz2m1XQANPfvYBqzXWswqDV/5sZSvxEHPohHI7H4WBtFLZog== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=G9o2pBA7; arc=none smtp.remote-ip=74.125.231.138 Received: from mail-oo2-f10.google.com (mail-oo2-f10.google.com [74.125.231.138]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BDABE606A325 for ; Wed, 2 Dec 2026 04:44:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BDABE606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=G9o2pBA7 Received: by mail-oo2-f10.google.com with SMTP id 006d021491bc7-71ad9f62e49so1456598eaf.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=vger.kernel.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=G9o2pBA7/X0rLW4OlVlL8BWToUlM2l08qzdjKlVpEsnkmLE6Tvvezvrqzz0pQTCQbl FdRaG5ACIhgK3fmRCluCD5/MnDXrctDoyPJs1zmrrzz4J61XJpY8ACxdkSDd+YaVBMN5 JCZ4dZsIfQXMuFtGY1U93daWHPr7pvIUCXqWMQxuJSKg7pF2S6vZFOMofIL1LcgudGgA qCiWgqqhddp6d4yJ+RU+xrz8Pk0vX0KrX7flFVhUx0ht5ut8oXEzPe2E1EuNe7Gcrd3W Khwq4rPYU/3MyFGDSfUH+SemUkbX0Y0LayGsNmZtSPwEDiSgSgTPWRhfLKEw2riLAL8+ dw9w== 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=n94dWlJRm2Re3ANC4gik8ZEsyDnCn+0FKHuVyiZcaOI=; b=wliqmAg35HpPUqc9MgdpvnriV6cZT7G5tdc2D1VryLfm8XokEtAvUPXZF7rfizwc0s DN2ZEx8WAOksyyqViocGtN3coaBYxOMWZQdksQ36DH//FkpKb+uMrFiLXQ9jgMI1pryW 8g0boitom0sEfTMXfcQjcXeEQAaxLTGfv44dcMLjdFFJK7S7NOnjBA20xcnTFsU2qVZa oyP3OaLCj2oz6Nulm2hTLVMu+xUJeBC/51SpP+D8UL293I92mBARikFO25tA4NMkCC1s a0knpZrPMBJfcmcggJNrccnSFzxENuOOJpJv608uQHRSKfYZqq9wdddt9BpBHbDvqRO9 2JoA== X-Forwarded-Encrypted: i=1; AL+hErFdgXO9W13x4UWINuli841m3Zxzal6rX93HNeK40A+9HTlqg1MJWqezd0xK+wNg3hNMrN3cO3Wja5w=@vger.kernel.org X-Gm-Message-State: APuU4Z+FPQmrJzXu0tNTTqlqdR99DMygjMKmexlot7ifqHaMhNe31131 YZGhNyCbHK/UlRuLxaI2M9odt+bchqyxtVLqBA3zOCgWqncY4ZHKNaz0 X-Gm-Gg: AZFdTZeyNBIvAqoJDCAupEBQHDs9hkn078fSDZTVxNLBgWXQCrb/kGko6y9BHiw7Lmj P1k/77LJHX5mFyo1dCF5rbQFUzIPplnxUkOI4KIJ/SxCpZBZAwNSIxbuOevegyZ9Ed1NcAuDu+c iUTSlDRLwBjhGHS6MgqHa820HuYQXTaZMHEoNEbzMY/UUQQx637UMVXLQEq4Zn0VBRbx3ytcb+n YFfsi71W59m9Fo2a5TqnGOOzngn7lCe6Fum38Q6qEiCe9UYuSyJCQRRKh+0A6KbIF0cp79H9Ry5 LxAsso7omAd+IHPVaaY/s7Fa3qfboW7rMQQ6Dxvdi1B41yKu/L5jxReVlmxZ9AplTtAUnTowBsR ERN2GRwCJyVw99+nVkJ4sUz3mzgyEA333WCv15uW4Aj6GNrf9VshUXjxVdRDiLR/OLxd+hTvF9U Pk7sVYfC9APUi04GLu6X3tscaqyXAzpF9H3FQicAJHeBW5tEl20KCPUeYnPazbiD86fNa+WjPxf Wilg9kLwlErThjVQGBS+RVntq/F5rRqYzUg4cUwEkIorZjyq+m27Ut9qfvx4i9N2NdjSA0W7f0/ ZoUJ2X9W38cz9JBb81AhwQ2qnrxsKm/D06/tpjCMVoQc 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-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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