From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Xu Yang <xu.yang_2@nxp.com>, Christoph Hellwig <hch@lst.de>,
ezequiel@vanguardiasur.com.ar, mchehab@kernel.org,
hdegoede@redhat.com, gregkh@linuxfoundation.org,
mingo@kernel.org, tglx@linutronix.de,
andriy.shevchenko@linux.intel.com, viro@zeniv.linux.org.uk,
thomas.weissschuh@linutronix.de, linux-media@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
imx@lists.linux.dev, jun.li@nxp.com
Subject: Re: [PATCH v2 1/3] usb: core: add dma-noncoherent buffer alloc and free API
Date: Mon, 30 Jun 2025 20:38:51 +0300 [thread overview]
Message-ID: <20250630173851.GH20333@pendragon.ideasonboard.com> (raw)
In-Reply-To: <e908261b-2acd-46ac-b3ef-92691eb50f88@rowland.harvard.edu>
Hi Alan,
On Mon, Jun 30, 2025 at 10:16:30AM -0400, Alan Stern wrote:
> On Mon, Jun 30, 2025 at 04:18:51PM +0800, Xu Yang wrote:
> > > Also, the material that this routine replaces in the uvc and stk1160
> > > drivers do not call flush_kernel_vmap_range(). Why did you add that
> > > here? Was this omission a bug in those drivers?
> >
> > According to dma-api.rst:
> > https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git/tree/Documentation/core-api/dma-api.rst?h=linux-6.15.y#n664
> >
> > "Once a non-contiguous allocation is mapped using this function, the
> > flush_kernel_vmap_range() and invalidate_kernel_vmap_range() APIs must
> > be used to manage the coherency between the kernel mapping, the device
> > and user space mappings (if any)."
> >
> > Possibly the uvc and stk1160 missed calling it, but since they won't be
> > the only user of the USB core, so we'd better call these APIs.
>
> Documentation/core-api/cachetbl.rst says:
>
> ``void flush_kernel_vmap_range(void *vaddr, int size)``
>
> flushes the kernel cache for a given virtual address range in
> the vmap area. This is to make sure that any data the kernel
> modified in the vmap range is made visible to the physical
> page. The design is to make this area safe to perform I/O on.
> Note that this API does *not* also flush the offset map alias
> of the area.
>
> ``void invalidate_kernel_vmap_range(void *vaddr, int size) invalidates``
>
> the cache for a given virtual address range in the vmap area
> which prevents the processor from making the cache stale by
> speculatively reading data while the I/O was occurring to the
> physical pages. This is only necessary for data reads into the
> vmap area.
>
> So invalidate_kernel_vmap_range() is not needed for data writes, that
> is, for OUT transfers. And ironically, flush_kernel_vmap_range() _is_
> needed (but only for OUT transfers).
flush_kernel_vmap_range() for OUT transfers and
invalidate_kernel_vmap_range() for IN transfers make sense to me.
> On the other hand, Christoph may think these call should be included
> regardless. Let's see what he recommends. Christoph?
>
> (Actually, I would expect dma_sync_sgtable_for_cpu() and
> dma_sync_sgtable_for_device() to handle all of this for us
> automatically, but never mind...)
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2025-06-30 17:39 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-27 10:19 [PATCH v2 0/3] add dma noncoherent API Xu Yang
2025-06-27 10:19 ` [PATCH v2 1/3] usb: core: add dma-noncoherent buffer alloc and free API Xu Yang
2025-06-27 11:22 ` Andy Shevchenko
2025-06-30 7:26 ` Xu Yang
2025-06-27 14:23 ` Alan Stern
2025-06-29 23:39 ` Laurent Pinchart
2025-06-30 6:48 ` Ricardo Ribalda
2025-06-30 8:23 ` Laurent Pinchart
2025-06-30 13:37 ` Christoph Hellwig
2025-06-30 8:45 ` Xu Yang
2025-06-30 8:18 ` Xu Yang
2025-06-30 14:16 ` Alan Stern
2025-06-30 17:38 ` Laurent Pinchart [this message]
2025-07-01 9:32 ` Xu Yang
2025-06-27 10:19 ` [PATCH v2 2/3] media: uvcvideo: use usb_alloc_noncoherent/usb_free_noncoherent() Xu Yang
2025-06-27 10:19 ` [PATCH v2 3/3] media: stk1160: " Xu Yang
2025-06-27 11:25 ` [PATCH v2 0/3] add dma noncoherent API Andy Shevchenko
2025-06-30 7:28 ` Xu Yang
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=20250630173851.GH20333@pendragon.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=ezequiel@vanguardiasur.com.ar \
--cc=gregkh@linuxfoundation.org \
--cc=hch@lst.de \
--cc=hdegoede@redhat.com \
--cc=imx@lists.linux.dev \
--cc=jun.li@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=mingo@kernel.org \
--cc=stern@rowland.harvard.edu \
--cc=tglx@linutronix.de \
--cc=thomas.weissschuh@linutronix.de \
--cc=viro@zeniv.linux.org.uk \
--cc=xu.yang_2@nxp.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