public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] kernel/dma: Fix panic caused by passing swiotlb to command line
@ 2018-12-03 10:22 zhe.he
  2019-01-07  8:46 ` He Zhe
  0 siblings, 1 reply; 5+ messages in thread
From: zhe.he @ 2018-12-03 10:22 UTC (permalink / raw)
  To: konrad, konrad.wilk, hch, m.szyprowski, robin.murphy, iommu,
	linux-kernel, zhe.he

From: He Zhe <zhe.he@windriver.com>

setup_io_tlb_npages does not check input argument before passing it
to isdigit. The argument would be a NULL pointer if "swiotlb", without
its value, is set in command line and thus causes the following panic.

PANIC: early exception 0xe3 IP 10:ffffffffbb9b8e9f error 0 cr2 0x0
[    0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 4.19.0-rc3-yocto-standard+ #9
[    0.000000] RIP: 0010:setup_io_tlb_npages+0xf/0x95
...
[    0.000000] Call Trace:
[    0.000000]  do_early_param+0x57/0x8e
[    0.000000]  parse_args+0x208/0x320
[    0.000000]  ? rdinit_setup+0x30/0x30
[    0.000000]  parse_early_options+0x29/0x2d
[    0.000000]  ? rdinit_setup+0x30/0x30
[    0.000000]  parse_early_param+0x36/0x4d
[    0.000000]  setup_arch+0x336/0x99e
[    0.000000]  start_kernel+0x6f/0x4e6
[    0.000000]  x86_64_start_reservations+0x24/0x26
[    0.000000]  x86_64_start_kernel+0x6f/0x72
[    0.000000]  secondary_startup_64+0xa4/0xb0

This patch adds a check to prevent the panic and sets it for 4MB by default.

Signed-off-by: He Zhe <zhe.he@windriver.com>
Cc: stable@vger.kernel.org
Cc: konrad.wilk@oracle.com
Cc: hch@lst.de
Cc: m.szyprowski@samsung.com
Cc: robin.murphy@arm.com

Signed-off-by: He Zhe <zhe.he@windriver.com>
---
v2: Set swiotlb for 4MB by default

 kernel/dma/swiotlb.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 045930e..0e18cd4 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -58,6 +58,9 @@
  */
 #define IO_TLB_MIN_SLABS ((1<<20) >> IO_TLB_SHIFT)
 
+#define IO_TLB_DEFAULT_MB 4
+#define IO_TLB_DEFAULT_SLABS ((IO_TLB_DEFAULT_MB<<20) >> IO_TLB_SHIFT)
+
 enum swiotlb_force swiotlb_force;
 
 /*
@@ -103,6 +106,14 @@ static int late_alloc;
 static int __init
 setup_io_tlb_npages(char *str)
 {
+	if (!str) {
+		pr_err("No value provided for swiotlb, "
+		       "set it to %d slabs for %dMB by default.\n",
+		       IO_TLB_DEFAULT_SLABS, IO_TLB_DEFAULT_MB);
+		io_tlb_nslabs = IO_TLB_DEFAULT_SLABS;
+		return 0;
+	}
+
 	if (isdigit(*str)) {
 		io_tlb_nslabs = simple_strtoul(str, &str, 0);
 		/* avoid tail segment of size < IO_TLB_SEGSIZE */
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] kernel/dma: Fix panic caused by passing swiotlb to command line
  2018-12-03 10:22 [PATCH v2] kernel/dma: Fix panic caused by passing swiotlb to command line zhe.he
@ 2019-01-07  8:46 ` He Zhe
  2019-01-07  9:07   ` Christoph Hellwig
  0 siblings, 1 reply; 5+ messages in thread
From: He Zhe @ 2019-01-07  8:46 UTC (permalink / raw)
  To: konrad, konrad.wilk, hch, m.szyprowski, robin.murphy, iommu,
	linux-kernel

Kindly ping.

Zhe

On 12/3/18 6:22 PM, zhe.he@windriver.com wrote:
> From: He Zhe <zhe.he@windriver.com>
>
> setup_io_tlb_npages does not check input argument before passing it
> to isdigit. The argument would be a NULL pointer if "swiotlb", without
> its value, is set in command line and thus causes the following panic.
>
> PANIC: early exception 0xe3 IP 10:ffffffffbb9b8e9f error 0 cr2 0x0
> [    0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 4.19.0-rc3-yocto-standard+ #9
> [    0.000000] RIP: 0010:setup_io_tlb_npages+0xf/0x95
> ...
> [    0.000000] Call Trace:
> [    0.000000]  do_early_param+0x57/0x8e
> [    0.000000]  parse_args+0x208/0x320
> [    0.000000]  ? rdinit_setup+0x30/0x30
> [    0.000000]  parse_early_options+0x29/0x2d
> [    0.000000]  ? rdinit_setup+0x30/0x30
> [    0.000000]  parse_early_param+0x36/0x4d
> [    0.000000]  setup_arch+0x336/0x99e
> [    0.000000]  start_kernel+0x6f/0x4e6
> [    0.000000]  x86_64_start_reservations+0x24/0x26
> [    0.000000]  x86_64_start_kernel+0x6f/0x72
> [    0.000000]  secondary_startup_64+0xa4/0xb0
>
> This patch adds a check to prevent the panic and sets it for 4MB by default.
>
> Signed-off-by: He Zhe <zhe.he@windriver.com>
> Cc: stable@vger.kernel.org
> Cc: konrad.wilk@oracle.com
> Cc: hch@lst.de
> Cc: m.szyprowski@samsung.com
> Cc: robin.murphy@arm.com
>
> Signed-off-by: He Zhe <zhe.he@windriver.com>
> ---
> v2: Set swiotlb for 4MB by default
>
>  kernel/dma/swiotlb.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 045930e..0e18cd4 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -58,6 +58,9 @@
>   */
>  #define IO_TLB_MIN_SLABS ((1<<20) >> IO_TLB_SHIFT)
>  
> +#define IO_TLB_DEFAULT_MB 4
> +#define IO_TLB_DEFAULT_SLABS ((IO_TLB_DEFAULT_MB<<20) >> IO_TLB_SHIFT)
> +
>  enum swiotlb_force swiotlb_force;
>  
>  /*
> @@ -103,6 +106,14 @@ static int late_alloc;
>  static int __init
>  setup_io_tlb_npages(char *str)
>  {
> +	if (!str) {
> +		pr_err("No value provided for swiotlb, "
> +		       "set it to %d slabs for %dMB by default.\n",
> +		       IO_TLB_DEFAULT_SLABS, IO_TLB_DEFAULT_MB);
> +		io_tlb_nslabs = IO_TLB_DEFAULT_SLABS;
> +		return 0;
> +	}
> +
>  	if (isdigit(*str)) {
>  		io_tlb_nslabs = simple_strtoul(str, &str, 0);
>  		/* avoid tail segment of size < IO_TLB_SEGSIZE */


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] kernel/dma: Fix panic caused by passing swiotlb to command line
  2019-01-07  8:46 ` He Zhe
@ 2019-01-07  9:07   ` Christoph Hellwig
       [not found]     ` <CAPbh3rupHC_G0=5dBhhpoXvXO_=i-Y6p=9WdRtn9W19jRpVVcg@mail.gmail.com>
  0 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2019-01-07  9:07 UTC (permalink / raw)
  To: He Zhe
  Cc: konrad, konrad.wilk, hch, m.szyprowski, robin.murphy, iommu,
	linux-kernel

On Mon, Jan 07, 2019 at 04:46:51PM +0800, He Zhe wrote:
> Kindly ping.

Konrad, I'll pick this up through the DMA mapping tree unless you
protest in the next few days.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] kernel/dma: Fix panic caused by passing swiotlb to command line
       [not found]     ` <CAPbh3rupHC_G0=5dBhhpoXvXO_=i-Y6p=9WdRtn9W19jRpVVcg@mail.gmail.com>
@ 2019-01-11  1:46       ` He Zhe
  2019-01-11  1:49         ` He Zhe
  0 siblings, 1 reply; 5+ messages in thread
From: He Zhe @ 2019-01-11  1:46 UTC (permalink / raw)
  To: konrad, Christoph Hellwig
  Cc: Konrad Rzeszutek Wilk, m.szyprowski, robin.murphy, iommu,
	linux-kernel



On 1/11/19 1:27 AM, Konrad Rzeszutek Wilk wrote:
> Let's skip it. There was another patch that would allocate a default 4MB size if it there was an misue of swiotlb parameters.

But this patch mainly fixes a crash. Could you please point me to the patch you mentioned?

Thanks,
Zhe

>
>
>
> On Mon, Jan 7, 2019, 4:07 AM Christoph Hellwig <hch@lst.de <mailto:hch@lst.de> wrote:
>
>     On Mon, Jan 07, 2019 at 04:46:51PM +0800, He Zhe wrote:
>     > Kindly ping.
>
>     Konrad, I'll pick this up through the DMA mapping tree unless you
>     protest in the next few days.
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] kernel/dma: Fix panic caused by passing swiotlb to command line
  2019-01-11  1:46       ` He Zhe
@ 2019-01-11  1:49         ` He Zhe
  0 siblings, 0 replies; 5+ messages in thread
From: He Zhe @ 2019-01-11  1:49 UTC (permalink / raw)
  To: konrad, Christoph Hellwig
  Cc: Konrad Rzeszutek Wilk, m.szyprowski, robin.murphy, iommu,
	linux-kernel



On 1/11/19 9:46 AM, He Zhe wrote:
>
> On 1/11/19 1:27 AM, Konrad Rzeszutek Wilk wrote:
>> Let's skip it. There was another patch that would allocate a default 4MB size if it there was an misue of swiotlb parameters.
> But this patch mainly fixes a crash. Could you please point me to the patch you mentioned?

And the v2 is modified according to your suggestion.

Zhe

>
> Thanks,
> Zhe
>
>>
>>
>> On Mon, Jan 7, 2019, 4:07 AM Christoph Hellwig <hch@lst.de <mailto:hch@lst.de> wrote:
>>
>>     On Mon, Jan 07, 2019 at 04:46:51PM +0800, He Zhe wrote:
>>     > Kindly ping.
>>
>>     Konrad, I'll pick this up through the DMA mapping tree unless you
>>     protest in the next few days.
>>
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-01-11  1:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-03 10:22 [PATCH v2] kernel/dma: Fix panic caused by passing swiotlb to command line zhe.he
2019-01-07  8:46 ` He Zhe
2019-01-07  9:07   ` Christoph Hellwig
     [not found]     ` <CAPbh3rupHC_G0=5dBhhpoXvXO_=i-Y6p=9WdRtn9W19jRpVVcg@mail.gmail.com>
2019-01-11  1:46       ` He Zhe
2019-01-11  1:49         ` He Zhe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox