All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Russell King - ARM Linux <linux@armlinux.org.uk>
Cc: "Christoph Hellwig" <hch@infradead.org>,
	"Thierry Reding" <treding@nvidia.com>,
	"Christian König" <christian.koenig@amd.com>,
	"moderated list:DMA BUFFER SHARING FRAMEWORK"
	<linaro-mm-sig@lists.linaro.org>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	"amd-gfx list" <amd-gfx@lists.freedesktop.org>,
	"Jerome Glisse" <jglisse@redhat.com>,
	dri-devel <dri-devel@lists.freedesktop.org>,
	"Dan Williams" <dan.j.williams@intel.com>,
	"Logan Gunthorpe" <logang@deltatee.com>,
	"open list:DMA BUFFER SHARING FRAMEWORK"
	<linux-media@vger.kernel.org>,
	iommu@lists.linux-foundation.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: noveau vs arm dma ops
Date: Thu, 26 Apr 2018 02:13:10 -0700	[thread overview]
Message-ID: <20180426091310.GB18811@infradead.org> (raw)
In-Reply-To: <20180425225443.GQ16141@n2100.armlinux.org.uk>

On Wed, Apr 25, 2018 at 11:54:43PM +0100, Russell King - ARM Linux wrote:
> 
> if the memory was previously dirty (iow, CPU has written), you need to
> flush the dirty cache lines _before_ the GPU writes happen, but you
> don't know whether the CPU has speculatively prefetched, so you need
> to flush any prefetched cache lines before reading from the cacheable
> memory _after_ the GPU has finished writing.
> 
> Also note that "flush" there can be "clean the cache", "clean and
> invalidate the cache" or "invalidate the cache" as appropriate - some
> CPUs are able to perform those three operations, and the appropriate
> one depends on not only where in the above sequence it's being used,
> but also on what the operations are.

Agreed on all these counts.

> If we can agree a set of interfaces that allows _proper_ use of these
> facilities, one which can be used appropriately, then there shouldn't
> be a problem.  The DMA API does that via it's ideas about who owns a
> particular buffer (because of the above problem) and that's something
> which would need to be carried over to such a cache flushing API (it
> should be pretty obvious that having a GPU read or write memory while
> the cache for that memory is being cleaned will lead to unexpected
> results.)

I've been trying to come up with such an interface, for now only for
internal use in a generic set of noncoherent ops.  The API is basically
a variant of the existing dma_sync_single_to_device/cpu calls:

http://git.infradead.org/users/hch/misc.git/commitdiff/044dae5f94509288f4655de2f22cb0bea85778af

Review welcome!

> The next issue, which I've brought up before, is that exposing cache
> flushing to userspace on architectures where it isn't already exposed
> comes.  As has been shown by Google Project Zero, this risks exposing
> those architectures to Spectre and Meltdown exploits where they weren't
> at such a risk before.  (I've pretty much shown here that you _do_
> need to control which cache lines get flushed to make these exploits
> work, and flushing the cache by reading lots of data in liu of having
> the ability to explicitly flush bits of cache makes it very difficult
> to impossible for them to work.)

Extending dma coherence to userspace is going to be the next major
nightmare indeed.  I'm not sure how much of that actually still is
going on in the graphics world, but we'll need a coherent (pun intended)
plan how to deal with it.

WARNING: multiple messages have this Message-ID (diff)
From: Christoph Hellwig <hch@infradead.org>
To: Russell King - ARM Linux <linux@armlinux.org.uk>
Cc: "moderated list:DMA BUFFER SHARING FRAMEWORK"
	<linaro-mm-sig@lists.linaro.org>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	"amd-gfx list" <amd-gfx@lists.freedesktop.org>,
	"Christoph Hellwig" <hch@infradead.org>,
	"Jerome Glisse" <jglisse@redhat.com>,
	iommu@lists.linux-foundation.org,
	dri-devel <dri-devel@lists.freedesktop.org>,
	"Dan Williams" <dan.j.williams@intel.com>,
	"Thierry Reding" <treding@nvidia.com>,
	"Logan Gunthorpe" <logang@deltatee.com>,
	"Christian König" <christian.koenig@amd.com>,
	linux-arm-kernel@lists.infradead.org,
	"open list:DMA BUFFER SHARING FRAMEWORK"
	<linux-media@vger.kernel.org>
Subject: Re: noveau vs arm dma ops
Date: Thu, 26 Apr 2018 02:13:10 -0700	[thread overview]
Message-ID: <20180426091310.GB18811@infradead.org> (raw)
In-Reply-To: <20180425225443.GQ16141@n2100.armlinux.org.uk>

On Wed, Apr 25, 2018 at 11:54:43PM +0100, Russell King - ARM Linux wrote:
> 
> if the memory was previously dirty (iow, CPU has written), you need to
> flush the dirty cache lines _before_ the GPU writes happen, but you
> don't know whether the CPU has speculatively prefetched, so you need
> to flush any prefetched cache lines before reading from the cacheable
> memory _after_ the GPU has finished writing.
> 
> Also note that "flush" there can be "clean the cache", "clean and
> invalidate the cache" or "invalidate the cache" as appropriate - some
> CPUs are able to perform those three operations, and the appropriate
> one depends on not only where in the above sequence it's being used,
> but also on what the operations are.

Agreed on all these counts.

> If we can agree a set of interfaces that allows _proper_ use of these
> facilities, one which can be used appropriately, then there shouldn't
> be a problem.  The DMA API does that via it's ideas about who owns a
> particular buffer (because of the above problem) and that's something
> which would need to be carried over to such a cache flushing API (it
> should be pretty obvious that having a GPU read or write memory while
> the cache for that memory is being cleaned will lead to unexpected
> results.)

I've been trying to come up with such an interface, for now only for
internal use in a generic set of noncoherent ops.  The API is basically
a variant of the existing dma_sync_single_to_device/cpu calls:

http://git.infradead.org/users/hch/misc.git/commitdiff/044dae5f94509288f4655de2f22cb0bea85778af

Review welcome!

> The next issue, which I've brought up before, is that exposing cache
> flushing to userspace on architectures where it isn't already exposed
> comes.  As has been shown by Google Project Zero, this risks exposing
> those architectures to Spectre and Meltdown exploits where they weren't
> at such a risk before.  (I've pretty much shown here that you _do_
> need to control which cache lines get flushed to make these exploits
> work, and flushing the cache by reading lots of data in liu of having
> the ability to explicitly flush bits of cache makes it very difficult
> to impossible for them to work.)

Extending dma coherence to userspace is going to be the next major
nightmare indeed.  I'm not sure how much of that actually still is
going on in the graphics world, but we'll need a coherent (pun intended)
plan how to deal with it.
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

WARNING: multiple messages have this Message-ID (diff)
From: hch@infradead.org (Christoph Hellwig)
To: linux-arm-kernel@lists.infradead.org
Subject: noveau vs arm dma ops
Date: Thu, 26 Apr 2018 02:13:10 -0700	[thread overview]
Message-ID: <20180426091310.GB18811@infradead.org> (raw)
In-Reply-To: <20180425225443.GQ16141@n2100.armlinux.org.uk>

On Wed, Apr 25, 2018 at 11:54:43PM +0100, Russell King - ARM Linux wrote:
> 
> if the memory was previously dirty (iow, CPU has written), you need to
> flush the dirty cache lines _before_ the GPU writes happen, but you
> don't know whether the CPU has speculatively prefetched, so you need
> to flush any prefetched cache lines before reading from the cacheable
> memory _after_ the GPU has finished writing.
> 
> Also note that "flush" there can be "clean the cache", "clean and
> invalidate the cache" or "invalidate the cache" as appropriate - some
> CPUs are able to perform those three operations, and the appropriate
> one depends on not only where in the above sequence it's being used,
> but also on what the operations are.

Agreed on all these counts.

> If we can agree a set of interfaces that allows _proper_ use of these
> facilities, one which can be used appropriately, then there shouldn't
> be a problem.  The DMA API does that via it's ideas about who owns a
> particular buffer (because of the above problem) and that's something
> which would need to be carried over to such a cache flushing API (it
> should be pretty obvious that having a GPU read or write memory while
> the cache for that memory is being cleaned will lead to unexpected
> results.)

I've been trying to come up with such an interface, for now only for
internal use in a generic set of noncoherent ops.  The API is basically
a variant of the existing dma_sync_single_to_device/cpu calls:

http://git.infradead.org/users/hch/misc.git/commitdiff/044dae5f94509288f4655de2f22cb0bea85778af

Review welcome!

> The next issue, which I've brought up before, is that exposing cache
> flushing to userspace on architectures where it isn't already exposed
> comes.  As has been shown by Google Project Zero, this risks exposing
> those architectures to Spectre and Meltdown exploits where they weren't
> at such a risk before.  (I've pretty much shown here that you _do_
> need to control which cache lines get flushed to make these exploits
> work, and flushing the cache by reading lots of data in liu of having
> the ability to explicitly flush bits of cache makes it very difficult
> to impossible for them to work.)

Extending dma coherence to userspace is going to be the next major
nightmare indeed.  I'm not sure how much of that actually still is
going on in the graphics world, but we'll need a coherent (pun intended)
plan how to deal with it.

  reply	other threads:[~2018-04-26  9:13 UTC|newest]

Thread overview: 161+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-25 10:59 [PATCH 1/8] lib/scatterlist: add sg_set_dma_addr() helper Christian König
2018-03-25 10:59 ` Christian König
2018-03-25 10:59 ` [PATCH 2/8] PCI: Add pci_find_common_upstream_dev() Christian König
2018-03-25 10:59   ` Christian König
2018-03-28 12:38   ` Christoph Hellwig
2018-03-28 15:07     ` Christian König
2018-03-28 15:07       ` Christian König
2018-03-28 15:47       ` Logan Gunthorpe
2018-03-28 16:02         ` Christian König
2018-03-28 16:02           ` Christian König
2018-03-28 16:25           ` Logan Gunthorpe
2018-03-28 18:28             ` Christian König
2018-03-28 18:28               ` Christian König
2018-03-28 18:57               ` Logan Gunthorpe
2018-03-28 19:44                 ` Christian König
2018-03-28 19:44                   ` Christian König
2018-03-28 19:53                   ` Logan Gunthorpe
2018-03-29 11:44                     ` Christian König
2018-03-29 15:45                       ` Logan Gunthorpe
2018-03-29 16:10                         ` Christian König
2018-03-29 16:10                           ` Christian König
2018-03-29 16:25                           ` Logan Gunthorpe
2018-03-29 18:15                             ` Christian König
2018-03-29 18:15                               ` Christian König
2018-03-30  1:58                             ` Jerome Glisse
2018-03-30  1:58                               ` Jerome Glisse
2018-03-30  6:33                               ` Christoph Hellwig
2018-03-30  6:33                                 ` Christoph Hellwig
2018-03-30 15:25                                 ` Jerome Glisse
2018-03-30 18:46                               ` Logan Gunthorpe
2018-03-30 19:45                                 ` Jerome Glisse
2018-03-30 19:45                                   ` Jerome Glisse
2018-04-02 17:02                                   ` Logan Gunthorpe
2018-04-02 17:20                                     ` Jerome Glisse
2018-04-02 17:20                                       ` Jerome Glisse
2018-04-02 17:37                                       ` Logan Gunthorpe
2018-04-02 19:16                                         ` Jerome Glisse
2018-04-02 19:16                                           ` Jerome Glisse
2018-04-02 19:32                                           ` Logan Gunthorpe
2018-04-02 19:45                                             ` Jerome Glisse
2018-04-02 19:45                                               ` Jerome Glisse
     [not found]                     ` <CADnq5_P-z=Noos_jaME9_CERri3C-m2hPPvx2bArr36O=1FnrA@mail.gmail.com>
2018-03-29 14:37                       ` Alex Deucher
2018-03-29 14:37                         ` Alex Deucher
2018-03-25 10:59 ` [PATCH 3/8] PCI: Add pci_peer_traffic_supported() Christian König
2018-03-25 10:59   ` Christian König
2018-03-25 10:59 ` [PATCH 4/8] dma-buf: add peer2peer flag Christian König
2018-03-25 10:59   ` Christian König
2018-03-29  6:57   ` Daniel Vetter
2018-03-29  6:57     ` Daniel Vetter
2018-03-29 11:34     ` Christian König
2018-03-29 11:34       ` Christian König
2018-04-03  9:09       ` Daniel Vetter
2018-04-03  9:09         ` Daniel Vetter
2018-04-03 17:06         ` Jerome Glisse
2018-04-03 17:06           ` Jerome Glisse
2018-04-03 18:08           ` Daniel Vetter
2018-04-03 18:08             ` Daniel Vetter
2018-04-16 12:39             ` Christoph Hellwig
2018-04-16 12:39               ` Christoph Hellwig
2018-04-16 13:38               ` Daniel Vetter
2018-04-16 13:38                 ` Daniel Vetter
2018-04-19  8:16                 ` Christoph Hellwig
2018-04-19  8:16                   ` Christoph Hellwig
2018-04-20  7:13                   ` Daniel Vetter
2018-04-20  7:13                     ` Daniel Vetter
2018-04-20  8:58                     ` Christian König
2018-04-20  8:58                       ` Christian König
2018-04-20 10:17                       ` Christoph Hellwig
2018-04-20 10:17                         ` Christoph Hellwig
2018-04-20 10:44                         ` Christian König
2018-04-20 10:44                           ` Christian König
2018-04-20 12:46                           ` Christoph Hellwig
2018-04-20 15:21                             ` [Linaro-mm-sig] " Daniel Vetter
2018-04-24 18:48                               ` Christoph Hellwig
2018-04-24 18:48                                 ` Christoph Hellwig
2018-04-24 19:32                                 ` Daniel Vetter
2018-04-24 19:32                                   ` Daniel Vetter
2018-04-25  5:48                                   ` Christoph Hellwig
2018-04-25  5:48                                     ` Christoph Hellwig
2018-04-25  6:10                                     ` Alex Deucher
2018-04-25  6:10                                       ` Alex Deucher
2018-04-25  6:13                                     ` Daniel Vetter
2018-04-25  6:13                                       ` Daniel Vetter
2018-04-25  6:23                                       ` Daniel Vetter
2018-04-25  6:23                                         ` Daniel Vetter
2018-04-25  6:43                                         ` Christoph Hellwig
2018-04-25  6:43                                           ` Christoph Hellwig
2018-04-25  7:02                                           ` Daniel Vetter
2018-04-25  7:02                                             ` Daniel Vetter
2018-04-25  7:09                                             ` Christoph Hellwig
2018-04-25  7:09                                               ` Christoph Hellwig
2018-04-25  7:30                                               ` Daniel Vetter
2018-04-25  7:30                                                 ` Daniel Vetter
2018-04-25  7:56                                                 ` Thierry Reding
2018-04-25  7:56                                                   ` Thierry Reding
2018-04-25  8:55                                                   ` Christoph Hellwig
2018-04-25  8:55                                                     ` Christoph Hellwig
2018-04-25  7:43                                               ` Thierry Reding
2018-04-25  7:43                                                 ` Thierry Reding
2018-04-25  7:41                                           ` Thierry Reding
2018-04-25  7:41                                             ` Thierry Reding
2018-04-25  8:54                                             ` noveau vs arm dma ops Christoph Hellwig
2018-04-25  8:54                                               ` Christoph Hellwig
2018-04-25  8:54                                               ` Christoph Hellwig
2018-04-25  9:25                                               ` Russell King - ARM Linux
2018-04-25  9:25                                                 ` Russell King - ARM Linux
2018-04-25 10:04                                               ` Daniel Vetter
2018-04-25 10:04                                                 ` Daniel Vetter
2018-04-25 10:04                                                 ` Daniel Vetter
2018-04-25 15:33                                                 ` Christoph Hellwig
2018-04-25 15:33                                                   ` Christoph Hellwig
2018-04-25 15:33                                                   ` Christoph Hellwig
2018-04-25 21:35                                                   ` Daniel Vetter
2018-04-25 21:35                                                     ` Daniel Vetter
2018-04-25 21:35                                                     ` Daniel Vetter
2018-04-25 23:26                                                     ` Russell King - ARM Linux
2018-04-25 23:26                                                       ` Russell King - ARM Linux
2018-04-26  9:17                                                       ` Daniel Vetter
2018-04-26  9:17                                                         ` Daniel Vetter
2018-04-26  9:17                                                         ` Daniel Vetter
2018-04-26  9:09                                                     ` Christoph Hellwig
2018-04-26  9:09                                                       ` Christoph Hellwig
2018-04-26  9:09                                                       ` Christoph Hellwig
2018-04-26  9:45                                                       ` Daniel Vetter
2018-04-26  9:45                                                         ` Daniel Vetter
2018-04-26  9:45                                                         ` Daniel Vetter
2018-04-26 11:12                                                       ` Russell King - ARM Linux
2018-04-26 11:12                                                         ` Russell King - ARM Linux
2018-04-25 22:54                                                   ` Russell King - ARM Linux
2018-04-25 22:54                                                     ` Russell King - ARM Linux
2018-04-26  9:13                                                     ` Christoph Hellwig [this message]
2018-04-26  9:13                                                       ` Christoph Hellwig
2018-04-26  9:13                                                       ` Christoph Hellwig
2018-04-26  9:20                                                     ` [Linaro-mm-sig] " Daniel Vetter
2018-04-26  9:20                                                       ` Daniel Vetter
2018-04-26  9:20                                                       ` Daniel Vetter
2018-04-26  9:24                                                       ` Christoph Hellwig
2018-04-26  9:24                                                         ` Christoph Hellwig
2018-04-26  9:24                                                         ` Christoph Hellwig
2018-04-26  9:39                                                         ` Daniel Vetter
2018-04-26  9:39                                                           ` Daniel Vetter
2018-04-26  9:39                                                           ` Daniel Vetter
2018-04-25  6:24                                       ` [Linaro-mm-sig] [PATCH 4/8] dma-buf: add peer2peer flag Alex Deucher
2018-04-25  6:24                                         ` Alex Deucher
2018-04-25  6:41                                         ` Christoph Hellwig
2018-04-25  6:41                                           ` Christoph Hellwig
2018-04-25 17:44                                           ` Alex Deucher
2018-04-25 17:44                                             ` Alex Deucher
2018-04-25 18:38                                             ` Dan Williams
2018-04-25 18:38                                               ` Dan Williams
2018-05-04 12:45                                             ` Lucas Stach
2018-03-25 10:59 ` [PATCH 5/8] drm/amdgpu: print DMA-buf status in debugfs Christian König
2018-03-25 10:59   ` Christian König
2018-03-25 10:59 ` [PATCH 6/8] drm/amdgpu: note that we can handle peer2peer DMA-buf Christian König
2018-03-25 10:59   ` Christian König
2018-03-25 10:59 ` [PATCH 7/8] drm/amdgpu: add amdgpu_gem_attach Christian König
2018-03-25 10:59   ` Christian König
2018-03-25 11:00 ` [PATCH 8/8] drm/amdgpu: add support for exporting VRAM using DMA-buf Christian König
2018-03-25 11:00   ` Christian König
2018-03-28 12:37 ` [PATCH 1/8] lib/scatterlist: add sg_set_dma_addr() helper Christoph Hellwig
2018-03-28 12:37   ` Christoph Hellwig

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=20180426091310.GB18811@infradead.org \
    --to=hch@infradead.org \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=dan.j.williams@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jglisse@redhat.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=logang@deltatee.com \
    --cc=treding@nvidia.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.