Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3853552pxb; Tue, 17 Nov 2020 05:26:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJw6+NhFflIVFp9mxWE3Gahqx0uJS0ZBxzUpVD7uyk1F1MEKzdyXa+edR50bwex97PsQg2iL X-Received: by 2002:a17:906:7c54:: with SMTP id g20mr19786483ejp.105.1605619595784; Tue, 17 Nov 2020 05:26:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605619595; cv=none; d=google.com; s=arc-20160816; b=GbE06FCtFI8GGYgyngbnjrt+mM8IcipwRNhTirfh24WG3CHfiwqHQA3tuhm/Ed9dV+ o3Jn2d5c61cBdh1xZs5KPrgtSJSPXFWvyMWqvnB5piq8RuM4WuOYq+rcv46hvufwm3iB fKmZQBVF2NeIPotf9yTkfT8Tsz21c3wXRYy6/tkj+pJZWH9U41kifYIPl5wBNr0H7lFx 3rIdwEbZhr9xFuTu7XKSddZAFfdn7M7QxfXnDf5OMWUvGHWLUzBtlUcwGELwJ6gUlyJL uIQfT+HDYXAwb+At8jJ8fQYgEq2bmpfoo1wkGEyzYbUa+bckhtt2JUbJ9nGh+0cLAd/O GeLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5ZjhqXMfj3R68WjkL4UNfWt6dtdsYfefYf2idcvPME8=; b=nxXhO4aNVNCEceUMPUCPjW2djB02RTcLCF9sdE4rf2TLMspIYQ432TiboAgWnzkULF 8E9zksuUUo9gvl1HKCQIQydKkLQBs6tG2oznD/kLiJJg1zNpNJkaLY2UbnjcM+5hTsSC vi5Q4Kt+rcvCY1ZLXLs5lzAT6bkKR4EvdyKzSCX9lvfpDdIwSK5BwfHtpOKAwh2PFMBO iVOt7jgBs5ZQlvwlJ1n58IEjVwmdV6CZqT2wqCU2TZQk9O/oO6oM+wH6v7k72xPJEWqP 5nM9Y0ubjud3KwslO8EulI0PRIDHUbaguwrw1ii78uOSLfHxCfX6Zsz3J/aGHZ4wOiuy WkhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bkw2wSoN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bi10si9528310edb.483.2020.11.17.05.26.12; Tue, 17 Nov 2020 05:26:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bkw2wSoN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730853AbgKQNVX (ORCPT + 99 others); Tue, 17 Nov 2020 08:21:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:54816 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730654AbgKQNVL (ORCPT ); Tue, 17 Nov 2020 08:21:11 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 68C9224631; Tue, 17 Nov 2020 13:21:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605619271; bh=/pH3EfrVK2U/e6eMTmDZBuXq5WXy2IelrJJoNSchUTI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bkw2wSoNGVxe9ZByz+o4g+mh6debf64GRq3vc7nEM3f76VEHt3sc6ATtoCsYwig35 Nx5woAnOneq44qJH8bE8+v0In1D8kc4BQYkrnBE92/1vdI57xx5V6x/bLRICPalvDe xEawgtkr9/KGkEFoLlnSFSonRWWgf+xqQ5kxu0A0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Elliott Mitchell , Stefano Stabellini , Christoph Hellwig , Konrad Rzeszutek Wilk Subject: [PATCH 4.19 086/101] swiotlb: fix "x86: Dont panic if can not alloc buffer for swiotlb" Date: Tue, 17 Nov 2020 14:05:53 +0100 Message-Id: <20201117122117.319836226@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122113.128215851@linuxfoundation.org> References: <20201117122113.128215851@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stefano Stabellini commit e9696d259d0fb5d239e8c28ca41089838ea76d13 upstream. kernel/dma/swiotlb.c:swiotlb_init gets called first and tries to allocate a buffer for the swiotlb. It does so by calling memblock_alloc_low(PAGE_ALIGN(bytes), PAGE_SIZE); If the allocation must fail, no_iotlb_memory is set. Later during initialization swiotlb-xen comes in (drivers/xen/swiotlb-xen.c:xen_swiotlb_init) and given that io_tlb_start is != 0, it thinks the memory is ready to use when actually it is not. When the swiotlb is actually needed, swiotlb_tbl_map_single gets called and since no_iotlb_memory is set the kernel panics. Instead, if swiotlb-xen.c:xen_swiotlb_init knew the swiotlb hadn't been initialized, it would do the initialization itself, which might still succeed. Fix the panic by setting io_tlb_start to 0 on swiotlb initialization failure, and also by setting no_iotlb_memory to false on swiotlb initialization success. Fixes: ac2cbab21f31 ("x86: Don't panic if can not alloc buffer for swiotlb") Reported-by: Elliott Mitchell Tested-by: Elliott Mitchell Signed-off-by: Stefano Stabellini Reviewed-by: Christoph Hellwig Cc: stable@vger.kernel.org Signed-off-by: Konrad Rzeszutek Wilk Signed-off-by: Greg Kroah-Hartman --- kernel/dma/swiotlb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -239,6 +239,7 @@ int __init swiotlb_init_with_tbl(char *t io_tlb_orig_addr[i] = INVALID_PHYS_ADDR; } io_tlb_index = 0; + no_iotlb_memory = false; if (verbose) swiotlb_print_info(); @@ -270,9 +271,11 @@ swiotlb_init(int verbose) if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs, verbose)) return; - if (io_tlb_start) + if (io_tlb_start) { memblock_free_early(io_tlb_start, PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT)); + io_tlb_start = 0; + } pr_warn("Cannot allocate buffer"); no_iotlb_memory = true; } @@ -376,6 +379,7 @@ swiotlb_late_init_with_tbl(char *tlb, un io_tlb_orig_addr[i] = INVALID_PHYS_ADDR; } io_tlb_index = 0; + no_iotlb_memory = false; swiotlb_print_info();