Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA05A3F99F5 for ; Wed, 1 Apr 2026 12:32:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775046765; cv=none; b=Z57Vxl4H0IbRQq5QQZOEceqkHo0eot9Bw9Td0/5CbEa2S7LXQ/m5v3p6HzLD8bSgUqCdslhh5EZHzbV+xxmqnqCiQI3sTU3DrJnjAObBVqSkXCd2RZ4t2wPPoicWPQDZb81b/H3KRNVIjXaLnkgjhOPLcdR5vyxM7+FBPNR9P/g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775046765; c=relaxed/simple; bh=ibk0bQN/ByI0CUeuRlmijZM5DofIEEeYHnmPB3e9Ibg=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=E+fFGfx8A7EGAGV7zgNx2JoMa5RbQFVtBrvE/jO71JqbcEvFQaj7PunE+uduKOPbveQLGO7LG+nKqjvWgAuBE1fm0DXTITEUFAkLDxmbEjfD2Vq9QhPcO4awzwKRZf4w1VzpySUDmSWwqdJOVsD39hlH8YF/X7Rh7ohltvGbDc8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--guanyulin.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=CZBSaX3P; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--guanyulin.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CZBSaX3P" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b630753cc38so14950323a12.1 for ; Wed, 01 Apr 2026 05:32:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775046763; x=1775651563; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=YcXBQG8D+snwNvD2Om+UYpFzj7Dd8z4o0RuXSY5rICk=; b=CZBSaX3PT36VTPB6kgC+pPm+oWU/RFF4T5gRxKfofCPkmPeHd2H68I0LGrwdV2LXqu Mj+wR7nLB287KoTgrYc/xl8ER/YTj1MjLbArubPJeBvs13fSamF4kUDUiEqJHTbxy/S2 D5lPbiYxtZO8HRr2LWwBeSzJroaN2PXcK5u9AY1N9ovrWpgNHLiY7ecKtyuPiPzJmCQI fwcrj3XZjFbX7EtYQeBhazKGe200w5/OJKM3GY5hZofXYn4ZB8FVJtWFi9Lz+3usURNV V4px+yNmfN4EnWhjvF3W+9ZVMtWBsJVtZ/LTJUiT+HzeQdoAx25JAuOjqabEoCKRLiFY bUtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775046763; x=1775651563; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=YcXBQG8D+snwNvD2Om+UYpFzj7Dd8z4o0RuXSY5rICk=; b=A0enw1zb6CE3ojpRXE/0lRyfNlsLLVntN1Rl5PE0Q6r/leLjooLtAAGukRRNBtcuN9 MbaJ6U0/AKsd6eNKlDZ62Egs3+p1PkmwnKcpmL4Wq07TKaBQvJcUZq2obkaU1LAzEeWj u9WHm9rduQT2sp7a7JB71KvX7UNM6d0eBRfUGgHBE1Q1qWtBpTNhXWKSZWSp6FpVWYHF pYezrcRMjNCQuSvt5NLjNatRspQ/280lsQ0Ld+z7rSvrtMvHAK4sdZ873RQGHdD5t9aJ MND46+SuOUMbkJV7lUbTUlNJJw4/UHjyC91H415yFUXR/COBJ7cx4ZVEqtBGYcuMFhC5 Hq7Q== X-Forwarded-Encrypted: i=1; AJvYcCW4+6GzDIGQYPNznq/SYI1oXLTxcmx3plEKtmAjlHCpfMEn9I0jzsa4je9awpfNXbvJVxXnU9Xezrpxww==@vger.kernel.org X-Gm-Message-State: AOJu0YwuUe8qit4P+jGYeOIZZzGj8MfNQPHhFqbWHmDOlVd4O0l0ieMF vJiJ0g4vAjwl1vDMeYTmp3J1CDn2J1vqIPMOT5fv/A+50G5z2k20cd1zkbHOySTegOqr2Qo1hhX j8XPg5EnhL6YoAfKB7g== X-Received: from pgax36.prod.google.com ([2002:a05:6a02:2e64:b0:c73:cc95:c0e4]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:6d89:b0:39b:e6af:2d8 with SMTP id adf61e73a8af0-39ef71fe1c9mr3888925637.4.1775046762634; Wed, 01 Apr 2026 05:32:42 -0700 (PDT) Date: Wed, 1 Apr 2026 12:32:16 +0000 Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.53.0.1118.gaef5881109-goog Message-ID: <20260401123238.3790062-1-guanyulin@google.com> Subject: [PATCH v4 0/2] usb: offload: Decouple interrupter lifecycle and refactor usage tracking From: Guan-Yu Lin To: gregkh@linuxfoundation.org, mathias.nyman@intel.com, perex@perex.cz, dominique.martinet@atmark-techno.com, eadavis@qq.com, hannelotta@gmail.com, tiwai@suse.com, quic_wcheng@quicinc.com, broonie@kernel.org, arnd@arndb.de, xiaopei01@kylinos.cn, wesley.cheng@oss.qualcomm.com, sakari.ailus@linux.intel.com, stern@rowland.harvard.edu, amardeep.rai@intel.com, xu.yang_2@nxp.com, andriy.shevchenko@linux.intel.com, nkapron@google.com Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, Guan-Yu Lin Content-Type: text/plain; charset="UTF-8" The current USB offload implementation couples the allocation of xHCI sideband interrupters with the device's offload usage counter. This coupling is conceptually incorrect, as hardware resource availability and power management state serve distinct purposes. Furthermore, the reliance on the coarse USB device lock for offload state updates has led to potential recursive locking issues, especially during device disconnect when the lock is already held by the USB core. This series refactors the offload synchronization by introducing a dedicated spinlock for offload state, allowing for more granular concurrency control and avoiding deadlocks. It also optimizes power management by ensuring that offload state is only modified when the device is already active, avoiding unnecessary auto-resumes. Patch 1 introduces the `offload_lock` spinlock and `offload_pm_locked` synchronization, replacing the coarse `udev->lock` and the legacy `offload_at_suspend` flag. It also updates `usb_offload_get/put` to use `pm_runtime_get_if_active()`. Patch 2 removes the implicit usage tracking from the xHCI sideband layer and delegates the responsibility to class drivers, who have the correct context for managing offload data stream activity. --- Changes in v4: - remove spinlock in `usb_offload_check`. - Collect the tag from the OPPO team. - Link to v3: https://lore.kernel.org/all/20260324203851.4091193-1-guanyulin@google.com/ Changes in v3: - Replace the coarse USB device lock with a dedicated `offload_lock` spinlock to reduce contention and prevent recursive locking. - Introduce `offload_pm_locked` to synchronize with PM transitions and replace the legacy `offload_at_suspend` flag. - Optimize `usb_offload_get/put` by switching from auto-resume/suspend to `pm_runtime_get_if_active()`, avoiding unnecessary power transitions. - Explicitly delegate `offload_usage` tracking to USB class drivers (e.g., the Qualcomm USB audio offload driver). - Link to v2: https://lore.kernel.org/all/20260309022205.28136-1-guanyulin@google.com/ Changes in v2: - Collect the tag from the OPPO team. - Link to v1: https://lore.kernel.org/all/20260225064601.270301-1-guanyulin@google.com/ Changes in v1: - Fix build error when building sound/usb/qcom/qc_audio_offload.o. - Link to RFC v2: https://lore.kernel.org/all/20260213100736.2914690-1-guanyulin@google.com/ Changes in RFC v2: - Move device locking to callers. - Decouple sideband from offload counting. - Link to RFC v1: https://lore.kernel.org/all/20260130074746.287750-1-guanyulin@google.com/ --- Guan-Yu Lin (2): usb: core: use dedicated spinlock for offload state usb: host: xhci-sideband: delegate offload_usage tracking to class drivers drivers/usb/core/driver.c | 23 ++++--- drivers/usb/core/offload.c | 102 +++++++++++++++++------------- drivers/usb/core/usb.c | 1 + drivers/usb/host/xhci-sideband.c | 18 +----- include/linux/usb.h | 10 ++- sound/usb/qcom/qc_audio_offload.c | 10 ++- 6 files changed, 94 insertions(+), 70 deletions(-) -- 2.53.0.1018.g2bb0e51243-goog