linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Claire Chang <tientzu@chromium.org>
To: Will Deacon <will@kernel.org>
Cc: "list@263.net:IOMMU DRIVERS <iommu@lists.linux-foundation.org>,
	Joerg Roedel <joro@8bytes.org>,"
	<iommu@lists.linux-foundation.org>,
	lkml <linux-kernel@vger.kernel.org>,
	Guenter Roeck <linux@roeck-us.net>,
	Christoph Hellwig <hch@lst.de>,
	Robin Murphy <robin.murphy@arm.com>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	Nathan Chancellor <nathan@kernel.org>
Subject: Re: [PATCH 5/5] swiotlb: Free tbl memory in swiotlb_exit()
Date: Tue, 20 Jul 2021 11:36:19 +0800	[thread overview]
Message-ID: <CALiNf2_Ubi9cynH1Rjy-o87V3MyvdTazv5rO=sggNai0WJZ81g@mail.gmail.com> (raw)
In-Reply-To: <20210719123054.6844-6-will@kernel.org>

On Mon, Jul 19, 2021 at 8:31 PM Will Deacon <will@kernel.org> wrote:
>
> Although swiotlb_exit() frees the 'slots' metadata array referenced by
> 'io_tlb_default_mem', it leaves the underlying buffer pages allocated
> despite no longer being usable.
>
> Extend swiotlb_exit() to free the buffer pages as well as the slots
> array.
>
> Cc: Claire Chang <tientzu@chromium.org>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Tested-by: Nathan Chancellor <nathan@kernel.org>

Tested-by: Claire Chang <tientzu@chromium.org>

> Signed-off-by: Will Deacon <will@kernel.org>
> ---
>  kernel/dma/swiotlb.c | 21 +++++++++++++++------
>  1 file changed, 15 insertions(+), 6 deletions(-)
>
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index b3c793ed9e64..87c40517e822 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -328,18 +328,27 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
>
>  void __init swiotlb_exit(void)
>  {
> -       size_t size;
>         struct io_tlb_mem *mem = &io_tlb_default_mem;
> +       unsigned long tbl_vaddr;
> +       size_t tbl_size, slots_size;
>
>         if (!mem->nslabs)
>                 return;
>
>         pr_info("tearing down default memory pool\n");
> -       size = array_size(sizeof(*mem->slots), mem->nslabs);
> -       if (mem->late_alloc)
> -               free_pages((unsigned long)mem->slots, get_order(size));
> -       else
> -               memblock_free_late(__pa(mem->slots), PAGE_ALIGN(size));
> +       tbl_vaddr = (unsigned long)phys_to_virt(mem->start);
> +       tbl_size = PAGE_ALIGN(mem->end - mem->start);
> +       slots_size = PAGE_ALIGN(array_size(sizeof(*mem->slots), mem->nslabs));
> +
> +       set_memory_encrypted(tbl_vaddr, tbl_size >> PAGE_SHIFT);
> +       if (mem->late_alloc) {
> +               free_pages(tbl_vaddr, get_order(tbl_size));
> +               free_pages((unsigned long)mem->slots, get_order(slots_size));
> +       } else {
> +               memblock_free_late(mem->start, tbl_size);
> +               memblock_free_late(__pa(mem->slots), slots_size);
> +       }
> +
>         memset(mem, 0, sizeof(*mem));
>  }
>
> --
> 2.32.0.402.g57bb445576-goog
>

  reply	other threads:[~2021-07-20  3:39 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-19 12:30 [PATCH 0/5] Fix restricted DMA vs swiotlb_exit() Will Deacon
2021-07-19 12:30 ` [PATCH 1/5] of: Return success from of_dma_set_restricted_buffer() when !OF_ADDRESS Will Deacon
2021-07-20  3:35   ` Claire Chang
2021-07-19 12:30 ` [PATCH 2/5] swiotlb: Point io_default_tlb_mem at static allocation Will Deacon
2021-07-20  3:35   ` Claire Chang
2021-07-20  7:51   ` Christoph Hellwig
2021-07-20  8:49     ` Will Deacon
2021-07-19 12:30 ` [PATCH 3/5] swiotlb: Remove io_tlb_default_mem indirection Will Deacon
2021-07-20  3:35   ` Claire Chang
2021-07-19 12:30 ` [PATCH 4/5] swiotlb: Emit diagnostic in swiotlb_exit() Will Deacon
2021-07-20  3:36   ` Claire Chang
2021-07-19 12:30 ` [PATCH 5/5] swiotlb: Free tbl memory " Will Deacon
2021-07-20  3:36   ` Claire Chang [this message]
2021-07-20  8:35     ` Will Deacon
2021-07-20  7:51 ` [PATCH 0/5] Fix restricted DMA vs swiotlb_exit() 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='CALiNf2_Ubi9cynH1Rjy-o87V3MyvdTazv5rO=sggNai0WJZ81g@mail.gmail.com' \
    --to=tientzu@chromium.org \
    --cc=hch@lst.de \
    --cc=iommu@lists.linux-foundation.org \
    --cc=konrad.wilk@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=nathan@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=will@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).