mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wesley Cheng <wesley.cheng@oss.qualcomm.com>
To: Mathias Nyman <mathias.nyman@linux.intel.com>,
	Michal Pecio <michal.pecio@gmail.com>
Cc: Mathias Nyman <mathias.nyman@intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-sound@vger.kernel.org
Subject: Re: [PATCH v4 3/5] usb: xhci: sideband: allocate sideband ring segments from a dedicated pool
Date: Tue, 27 Oct 2026 13:19:02 -0700	[thread overview]
Message-ID: <24d045db-b8ab-44db-83c1-9832d22dc9d8@oss.qualcomm.com> (raw)
In-Reply-To: <090277e2-e36c-437a-8c2c-f6f3b63abc89@oss.qualcomm.com>



On 10/20/2026 4:13 PM, Wesley Cheng wrote:
> 
> 
> On 10/14/2026 5:44 PM, Wesley Cheng wrote:
>>
>>
>> On 10/14/2026 7:26 AM, Mathias Nyman wrote:
>>> On 10/13/26 12:11, Michal Pecio wrote:
>>>> On Mon, 12 Oct 2026 18:01:50 -0700, Wesley Cheng wrote:
>>>>> On 10/5/2026 4:03 AM, Mathias Nyman wrote:
>>>>>> xhci is the one allocating the ring when adding an endpoint, and
>>>>>> telling xHC hardware to write to that ring. It seems more
>>>>>> approriate that xhci should be the one freeing the ring after it
>>>>>> told xHC hardware to drop the endpoint, and there no longer is a
>>>>>> risk on hardware accessing it.
>>>>>
>>>>> Hi Mathias,
>>>>>
>>>>> Sorry for the late response.  Was out last week.
>>>>>
>>>>> Specifically in the disconnect path (while audio offload is active),
>>>>> when we utilize the usb_set_interface() path, it'll return early due
>>>>> to the iface->unregistering check.  This would lead to the
>>>>> drop_endpoint not to be called, and rely on the xhci_free_dev() to
>>>>> handle the transfer ring cleanup.  This wouldn't work in the offload
>>>>> situation, because qc_audio_offload is the only entity managing the
>>>>> DMA pool, and that would be freed during the .disconnect callback,
>>>>> which happens BEFORE xhci_free_dev().
>>>
>>> You are right, audio class driver .disconnect is called, driver unbound
>>> and interface device gone before xhci_free_dev() is called.
>>>
>>> If sideband is unregistered as part of .disconnect callback it also means
>>> ring/pool would be destroyed before xHC has dropped the endpoint/disabled
>>> the slot. Would be better to free the ring after we know xHC controller
>>> won't access it.
>>>
>>>>>
>>>>> Would you be more inclined to prefer a solution where we can defer
>>>>> the DMA pool free'ing to the xHCI core during xhci_free_dev, or maybe
>>>>> adding another sideband notifier (sb->notify_client) enum to tell the
>>>>> client driver that it can release the pool?
>>>
>>> sb->notify_client callback has the risk that this sideband entity is
>>> unregistered and gone by the time we want to call it
>>>
>>> Deferring freeing the DMA poolby some kind of reference counting again adds
>>> complexity, and maybe not a suitable solution for this issue.
>>> (taking a reference at sideband register and every dma_pool_zalloc(), 
>>> putting
>>> when freeing or sideband unregister, finally freeing pool when reaching 
>>> zero.)
>>>
>>> I'm trying to figure out a simpler solution.
>>>
>>> How about skipping dma pools completely for endpoints in these cases?
>>> (page size over 4k with offloaded endpoints)
>>>
>>> Instead of sideband client creating a custom dma pool it could just set a
>>> 'no dma pool' flag for the endpoint. xhci driver would allocate the
>>> ring segments using dma_alloc_coherent() instead of dma_pool_zalloc() for
>>> these, possibly even allocate a full page for each segment?
>>> Freeing would be done similarly.
>>>
>>> Would this be a viable simple solution?
>>>
> 
> Hi Mathias,
> 
> There is one difficulty I ran into, and that's w/ dma_free_coherent() not 
> being able to be done in the current xhci_ring_free() context, as it is 
> under atomic context.  I could move the dma memory ownership from xhci core 
> to xhci sideband, which could probably get around this.
> 
> xHCI sideband will allocate the DMA backed memory then populate the 
> new_ring reference.  Then when xhci_add_endpoint() --> xhci_endpoint_init() 
> is run it'll check if new_ring is present, if not, follow the non offload 
> path and allocate from xHCI segment pool.  Then on the sideband unregister 
> path, we can handle the freeing of this DMA memory as well.  This kind of 
> moves the memory operations from xHCI to xHCI sideband.  We would need to 
> have a set of sideband specific ring alloc/free though.
> 
Hi Mathias,

I'm going to go ahead and start working on this approach.  Feel free to 
comment on if you have any major concerns from your end.  From what I've 
looked at so far, I think it is a feasible solution, and the only major 
shift is that xHCI sideband will own some of the memory allocations that 
will populate xHCI core references.

Thanks
Wesley Cheng

  reply	other threads:[~2026-10-27 20:19 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10  1:50 [PATCH v4 0/5] Add larger page size support for USB audio offload path Wesley Cheng
2026-09-10  1:50 ` [PATCH v4 1/5] usb: xhci: sideband: fix ring sg table for sub-page TRB segments Wesley Cheng
2026-09-10  1:50 ` [PATCH v4 2/5] usb: xhci: Allow to specify a different segment pool for allocations Wesley Cheng
2026-09-10  1:50 ` [PATCH v4 3/5] usb: xhci: sideband: allocate sideband ring segments from a dedicated pool Wesley Cheng
2026-10-05 11:03   ` Mathias Nyman
2026-10-13  1:01     ` Wesley Cheng
2026-10-13  9:11       ` Michal Pecio
2026-10-13 22:53         ` Wesley Cheng
2026-10-14  9:17           ` Michal Pecio
2026-10-14 14:26         ` Mathias Nyman
2026-10-15  0:44           ` Wesley Cheng
2026-10-20 23:13             ` Wesley Cheng
2026-10-27 20:19               ` Wesley Cheng [this message]
2026-09-10  1:51 ` [PATCH v4 4/5] ALSA: usb-audio: qcom: tag sideband endpoints before ring allocation Wesley Cheng
2026-09-10  1:51 ` [PATCH v4 5/5] ALSA: usb-audio: qcom: fix xfer ring IOMMU unmap on 16K+ page kernels Wesley Cheng
2026-09-30 22:23 ` [PATCH v4 0/5] Add larger page size support for USB audio offload path Wesley Cheng
2026-10-01 22:33   ` Mathias Nyman
2026-10-02  1:42     ` Wesley Cheng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=24d045db-b8ab-44db-83c1-9832d22dc9d8@oss.qualcomm.com \
    --to=wesley.cheng@oss.qualcomm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=mathias.nyman@linux.intel.com \
    --cc=michal.pecio@gmail.com \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®