From: Mike Rapoport <rppt@linux.ibm.com>
To: Sasha Levin <sashal@kernel.org>
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
Catalin Marinas <catalin.marinas@arm.com>,
Christophe Leroy <christophe.leroy@c-s.fr>,
Christoph Hellwig <hch@lst.de>,
"David S. Miller" <davem@davemloft.net>,
Dennis Zhou <dennis@kernel.org>,
Geert Uytterhoeven <geert@linux-m68k.org>,
Greentime Hu <green.hu@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Guan Xuetao <gxt@pku.edu.cn>, Guo Ren <guoren@kernel.org>,
Guo Ren <ren_guo@c-sky.com>,
Heiko Carstens <heiko.carstens@de.ibm.com>,
Juergen Gross <jgross@suse.com>, Mark Salter <msalter@redhat.com>,
Matt Turner <mattst88@gmail.com>,
Max Filippov <jcmvbkbc@gmail.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Michal Simek <monstr@monstr.eu>,
Paul Burton <paul.burton@mips.com>
Subject: Re: [PATCH AUTOSEL 5.0 008/262] swiotlb: add checks for the return value of memblock_alloc*()
Date: Thu, 28 Mar 2019 07:55:20 +0200 [thread overview]
Message-ID: <20190328055520.GA14864@rapoport-lnx> (raw)
In-Reply-To: <20190327180158.10245-8-sashal@kernel.org>
Hi,
On Wed, Mar 27, 2019 at 01:57:43PM -0400, Sasha Levin wrote:
> From: Mike Rapoport <rppt@linux.ibm.com>
>
> [ Upstream commit a0bf842e89a3842162aa8514b9bf4611c86fee10 ]
>
> Add panic() calls if memblock_alloc() returns NULL.
>
> The panic() format duplicates the one used by memblock itself and in
> order to avoid explosion with long parameters list replace open coded
> allocation size calculations with a local variable.
This patch is a part of a series that removes panic() calls from memblock
allocators rather than a fix.
> Link: http://lkml.kernel.org/r/1548057848-15136-19-git-send-email-rppt@linux.ibm.com
> Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Christophe Leroy <christophe.leroy@c-s.fr>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Dennis Zhou <dennis@kernel.org>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: Greentime Hu <green.hu@gmail.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Guan Xuetao <gxt@pku.edu.cn>
> Cc: Guo Ren <guoren@kernel.org>
> Cc: Guo Ren <ren_guo@c-sky.com> [c-sky]
> Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
> Cc: Juergen Gross <jgross@suse.com> [Xen]
> Cc: Mark Salter <msalter@redhat.com>
> Cc: Matt Turner <mattst88@gmail.com>
> Cc: Max Filippov <jcmvbkbc@gmail.com>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: Michal Simek <monstr@monstr.eu>
> Cc: Paul Burton <paul.burton@mips.com>
> Cc: Petr Mladek <pmladek@suse.com>
> Cc: Richard Weinberger <richard@nod.at>
> Cc: Rich Felker <dalias@libc.org>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Rob Herring <robh@kernel.org>
> Cc: Russell King <linux@armlinux.org.uk>
> Cc: Stafford Horne <shorne@gmail.com>
> Cc: Tony Luck <tony.luck@intel.com>
> Cc: Vineet Gupta <vgupta@synopsys.com>
> Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
> kernel/dma/swiotlb.c | 19 +++++++++++++------
> 1 file changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index c873f9cc2146..41224f0ec40e 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -191,6 +191,7 @@ void __init swiotlb_update_mem_attributes(void)
> int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
> {
> unsigned long i, bytes;
> + size_t alloc_size;
>
> bytes = nslabs << IO_TLB_SHIFT;
>
> @@ -203,12 +204,18 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
> * to find contiguous free memory regions of size up to IO_TLB_SEGSIZE
> * between io_tlb_start and io_tlb_end.
> */
> - io_tlb_list = memblock_alloc(
> - PAGE_ALIGN(io_tlb_nslabs * sizeof(int)),
> - PAGE_SIZE);
> - io_tlb_orig_addr = memblock_alloc(
> - PAGE_ALIGN(io_tlb_nslabs * sizeof(phys_addr_t)),
> - PAGE_SIZE);
> + alloc_size = PAGE_ALIGN(io_tlb_nslabs * sizeof(int));
> + io_tlb_list = memblock_alloc(alloc_size, PAGE_SIZE);
> + if (!io_tlb_list)
> + panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
> + __func__, alloc_size, PAGE_SIZE);
> +
> + alloc_size = PAGE_ALIGN(io_tlb_nslabs * sizeof(phys_addr_t));
> + io_tlb_orig_addr = memblock_alloc(alloc_size, PAGE_SIZE);
> + if (!io_tlb_orig_addr)
> + panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
> + __func__, alloc_size, PAGE_SIZE);
> +
> for (i = 0; i < io_tlb_nslabs; i++) {
> io_tlb_list[i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE);
> io_tlb_orig_addr[i] = INVALID_PHYS_ADDR;
> --
> 2.19.1
>
--
Sincerely yours,
Mike.
next prev parent reply other threads:[~2019-03-28 5:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20190327180158.10245-1-sashal@kernel.org>
[not found] ` <20190327180158.10245-1-sashal-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2019-03-27 17:57 ` [PATCH AUTOSEL 5.0 008/262] swiotlb: add checks for the return value of memblock_alloc*() Sasha Levin
2019-03-28 5:55 ` Mike Rapoport [this message]
2019-04-04 0:56 ` Sasha Levin
2019-03-27 17:58 ` [PATCH AUTOSEL 5.0 056/262] iommu/vt-d: Disable ATS support on untrusted devices Sasha Levin
2019-03-27 17:59 ` [PATCH AUTOSEL 5.0 085/262] iommu/io-pgtable-arm-v7s: Only kmemleak_ignore L2 tables Sasha Levin
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=20190328055520.GA14864@rapoport-lnx \
--to=rppt@linux.ibm.com \
--cc=catalin.marinas@arm.com \
--cc=christophe.leroy@c-s.fr \
--cc=davem@davemloft.net \
--cc=dennis@kernel.org \
--cc=geert@linux-m68k.org \
--cc=green.hu@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=guoren@kernel.org \
--cc=gxt@pku.edu.cn \
--cc=hch@lst.de \
--cc=heiko.carstens@de.ibm.com \
--cc=jcmvbkbc@gmail.com \
--cc=jgross@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mattst88@gmail.com \
--cc=monstr@monstr.eu \
--cc=mpe@ellerman.id.au \
--cc=msalter@redhat.com \
--cc=paul.burton@mips.com \
--cc=ren_guo@c-sky.com \
--cc=sashal@kernel.org \
--cc=stable@vger.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).