Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3885368pxb; Tue, 17 Nov 2020 06:11:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJwBCCsfGX1HW7Wz+SFZKhgsjd0tIAQs93J+wQKoUcaCx/n6zrwvNExkA9Tpjvxs531Weikq X-Received: by 2002:a7b:c4c3:: with SMTP id g3mr4412017wmk.127.1605622300351; Tue, 17 Nov 2020 06:11:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605622300; cv=none; d=google.com; s=arc-20160816; b=NNbv5KO982QPWPgWZzmxrEbAxUfyLo/EtqgM5wt9LKSeClU8UkRnKRaPfiw+Sq7fgB aqEpLk/d/PYfEFUpFFz5Tfq/fKwktNTHeUinFiccK+i8gYemlo8nn+bKw+U1KYH1v0jq wE8lJPih7YvijVvTiAU3LiCkqt0nD0sOnVHNBlJNUWQPoXwCoJQvWcC963H6kTGT0FJe pZ7MBhERZWK/97Ln/FipjAblTlPD6Q+tLPZFF5bBcJpRaQdwFsvTRfqWp8MN75zWwaEj A5Bv+BRlczaGoMkr+kWLJhzrD9J53Hkca3ojrEEsCKdlsvjJhc/B3toWK7YeCawIz4zv 3r1Q== 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=bR6drbStjTXQaGUoTsZkPg8ZQv1ugRi4PSM4meI1tbM=; b=nqUtb7wbXJ+O2zFXKTkFtt2tt/x6+ZS8SYJTmG7iyIqiurfeeG/FNMrRsdZmLd+2Oh pn6GDJH7gKr93Dv9W3YUK+Du0p9u9LknIH5pbUUDcemXm7FR3aNekTaRel2/hxTGyKPP wMZT8xdiSkTrLBzZAFZ960HUqezewbE5QjCIeLlNj6+Zsi9RXDWP2hBZoHA+xcTZyN6z S3S48DGorbFbiydzmlQKxByOvUqqz5C8A39FASSJ6n3vLLJR1i5Q6+/E4mMPjxkGuVKM PSEfb27pUPYFB6r8/pU72RGvIMK1mGEjv6scL0GS/9reQloWxrhAqFWJ2P/wkvP2Fu/R wzRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="IbbJ/olj"; 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 f9si12260619ejq.352.2020.11.17.06.11.15; Tue, 17 Nov 2020 06:11:40 -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="IbbJ/olj"; 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 S1729125AbgKQOGz (ORCPT + 99 others); Tue, 17 Nov 2020 09:06:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:35430 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729136AbgKQNHm (ORCPT ); Tue, 17 Nov 2020 08:07:42 -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 BD25B246BE; Tue, 17 Nov 2020 13:07:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605618460; bh=BgUU6vuA4mdDWxDbHnZ3Iq/uuzNoZaKCqquELStN1Os=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IbbJ/oljRrSjdkrWZ5RHFMx+x7dTCwiRaMZMI6NeDmwLblEGrburGwuFvEkUCIon3 LZaXsKhGZtHsWxBzrP1RNHaelyc0YXyG1n4muNkpl0ynELW4NQPsSWRCIJpS9vmyy5 gOhVU1yZNoc1QSgZtaE/7yWJcjRWzUKFrkoa57hw= 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.4 41/64] swiotlb: fix "x86: Dont panic if can not alloc buffer for swiotlb" Date: Tue, 17 Nov 2020 14:05:04 +0100 Message-Id: <20201117122108.191850580@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122106.144800239@linuxfoundation.org> References: <20201117122106.144800239@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 --- lib/swiotlb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/lib/swiotlb.c +++ b/lib/swiotlb.c @@ -195,6 +195,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(); @@ -225,9 +226,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; } @@ -326,6 +329,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();