From: Christoph Hellwig <hch@lst.de>
To: David Rientjes <rientjes@google.com>
Cc: Thomas Lendacky <thomas.lendacky@amd.com>,
Brijesh Singh <brijesh.singh@amd.com>,
linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org,
Robin Murphy <robin.murphy@arm.com>,
Christoph Hellwig <hch@lst.de>
Subject: Re: [patch for-5.8 1/4] dma-direct: always align allocation size in dma_direct_alloc_pages()
Date: Mon, 15 Jun 2020 08:54:55 +0200 [thread overview]
Message-ID: <20200615065455.GA21248@lst.de> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2006111218570.153880@chino.kir.corp.google.com>
On Thu, Jun 11, 2020 at 12:20:28PM -0700, David Rientjes wrote:
> dma_alloc_contiguous() does size >> PAGE_SHIFT and set_memory_decrypted()
> works at page granularity. It's necessary to page align the allocation
> size in dma_direct_alloc_pages() for consistent behavior.
>
> This also fixes an issue when arch_dma_prep_coherent() is called on an
> unaligned allocation size for dma_alloc_need_uncached() when
> CONFIG_DMA_DIRECT_REMAP is disabled but CONFIG_ARCH_HAS_DMA_SET_UNCACHED
> is enabled.
>
> Cc: stable@vger.kernel.org
> Signed-off-by: David Rientjes <rientjes@google.com>
> ---
> kernel/dma/direct.c | 17 ++++++++++-------
> 1 file changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
> --- a/kernel/dma/direct.c
> +++ b/kernel/dma/direct.c
> @@ -112,11 +112,12 @@ static inline bool dma_should_free_from_pool(struct device *dev,
> struct page *__dma_direct_alloc_pages(struct device *dev, size_t size,
> gfp_t gfp, unsigned long attrs)
> {
> - size_t alloc_size = PAGE_ALIGN(size);
> int node = dev_to_node(dev);
> struct page *page = NULL;
> u64 phys_limit;
>
> + VM_BUG_ON(!PAGE_ALIGNED(size));
This really should be a WARN_ON_ONCE, but I've fixed this up before
applying. I've also added a prep patch to mark __dma_direct_alloc_pages
static as part of auditing for other callers.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
WARNING: multiple messages have this Message-ID (diff)
From: Christoph Hellwig <hch@lst.de>
To: David Rientjes <rientjes@google.com>
Cc: Christoph Hellwig <hch@lst.de>,
Thomas Lendacky <thomas.lendacky@amd.com>,
Brijesh Singh <brijesh.singh@amd.com>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Robin Murphy <robin.murphy@arm.com>,
iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org
Subject: Re: [patch for-5.8 1/4] dma-direct: always align allocation size in dma_direct_alloc_pages()
Date: Mon, 15 Jun 2020 08:54:55 +0200 [thread overview]
Message-ID: <20200615065455.GA21248@lst.de> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2006111218570.153880@chino.kir.corp.google.com>
On Thu, Jun 11, 2020 at 12:20:28PM -0700, David Rientjes wrote:
> dma_alloc_contiguous() does size >> PAGE_SHIFT and set_memory_decrypted()
> works at page granularity. It's necessary to page align the allocation
> size in dma_direct_alloc_pages() for consistent behavior.
>
> This also fixes an issue when arch_dma_prep_coherent() is called on an
> unaligned allocation size for dma_alloc_need_uncached() when
> CONFIG_DMA_DIRECT_REMAP is disabled but CONFIG_ARCH_HAS_DMA_SET_UNCACHED
> is enabled.
>
> Cc: stable@vger.kernel.org
> Signed-off-by: David Rientjes <rientjes@google.com>
> ---
> kernel/dma/direct.c | 17 ++++++++++-------
> 1 file changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
> --- a/kernel/dma/direct.c
> +++ b/kernel/dma/direct.c
> @@ -112,11 +112,12 @@ static inline bool dma_should_free_from_pool(struct device *dev,
> struct page *__dma_direct_alloc_pages(struct device *dev, size_t size,
> gfp_t gfp, unsigned long attrs)
> {
> - size_t alloc_size = PAGE_ALIGN(size);
> int node = dev_to_node(dev);
> struct page *page = NULL;
> u64 phys_limit;
>
> + VM_BUG_ON(!PAGE_ALIGNED(size));
This really should be a WARN_ON_ONCE, but I've fixed this up before
applying. I've also added a prep patch to mark __dma_direct_alloc_pages
static as part of auditing for other callers.
next prev parent reply other threads:[~2020-06-15 6:55 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-11 19:20 [patch for-5.8 0/4] dma-direct: dma_direct_alloc_pages() fixes for AMD SEV David Rientjes via iommu
2020-06-11 19:20 ` David Rientjes
2020-06-11 19:20 ` [patch for-5.8 1/4] dma-direct: always align allocation size in dma_direct_alloc_pages() David Rientjes via iommu
2020-06-11 19:20 ` David Rientjes
2020-06-15 6:54 ` Christoph Hellwig [this message]
2020-06-15 6:54 ` Christoph Hellwig
2020-06-11 19:20 ` [patch for-5.8 2/4] dma-direct: re-encrypt memory if dma_direct_alloc_pages() fails David Rientjes via iommu
2020-06-11 19:20 ` David Rientjes
2020-06-15 6:56 ` Christoph Hellwig
2020-06-15 6:56 ` Christoph Hellwig
2020-06-11 19:20 ` [patch for-5.8 3/4] dma-direct: check return value when encrypting or decrypting memory David Rientjes via iommu
2020-06-11 19:20 ` David Rientjes
2020-06-11 19:20 ` [patch for-5.8 4/4] dma-direct: add missing set_memory_decrypted() for coherent mapping David Rientjes via iommu
2020-06-11 19:20 ` David Rientjes
2020-06-15 7:00 ` Christoph Hellwig
2020-06-15 7:00 ` 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=20200615065455.GA21248@lst.de \
--to=hch@lst.de \
--cc=brijesh.singh@amd.com \
--cc=iommu@lists.linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rientjes@google.com \
--cc=robin.murphy@arm.com \
--cc=thomas.lendacky@amd.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.