Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp627996pxx; Mon, 26 Oct 2020 17:23:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcewvOanG1wXJl+gU3+ea7nRFi8CVqdhp7FOSnxJEnHHzJi2cKTmtUBSMgdr3u0DlxmYAc X-Received: by 2002:a05:6402:943:: with SMTP id h3mr18369224edz.88.1603758212727; Mon, 26 Oct 2020 17:23:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603758212; cv=none; d=google.com; s=arc-20160816; b=AF5fmY/fTmAAmZDqpmQ+2OKccpQme98quwqf93yGf8BU0LqdejrxdSkoOGx6oIocyY 35xcCCKopLXBZx56HwRkjdWL8HpdFiAdeZywv5I3MQmvySlZLR8TEkJKH0GvXKsu2dxe 72HKIzrSFr7p2PJEyRHdYTeQkR2jIy+h1a/8j/XNjvUjCiOM+0MsbCYb1TU1GUXIAVpn TWeyYX5pZBGzsXh+HDWzsrtEmLSGaPDFQtQKxn+rh88Szmk/y7ZCLLRjrO/Z/eFZsiB/ 3OlflItLj12QlQcAzfn3huu2IKquAO0eGci4i/3pt4pN6Caveu5evtJnvUkEf68Dd07i W8og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:subject:cc:to :from:date:dkim-signature; bh=QPIoQmp410WlQ2fNsBF81KMvJfzieuft1MIZ0mWljk4=; b=Jv7AX4CQp2GJyzcY3gNvj8n+gKFKixkPgiPqyksvRrlyDNuHwJQ+iwBbQmcbD5m+QO f3r0MBgVtRGaNabMJNcSjFPwB423I0uhWUX83VHuxsvfwX12r9JcTzyD9mHH/wSokAaS dxXodUqI+ESF6ohwFElGPhkgrNvaN8J6a7oaG3ekQUpfp0UKWljzk8c8jSeLnJSyn3+5 mxVezdGF37sh0rP2LTe0d5JrUmwIYBb9VV0/0rsczi7g4xE36vk0brtyViLr6BoZN7ME mleFoI8U5B8diPfCYqlB+SJebBhcghtK71+3o/skwodousdrJpelr5r2WsPLxj13dFP4 y90g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=L1iKctRV; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r4si2417066edw.586.2020.10.26.17.23.10; Mon, 26 Oct 2020 17:23:32 -0700 (PDT) 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=L1iKctRV; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437453AbgJ0ACb (ORCPT + 99 others); Mon, 26 Oct 2020 20:02:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:48002 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2437433AbgJ0ACQ (ORCPT ); Mon, 26 Oct 2020 20:02:16 -0400 Received: from sstabellini-ThinkPad-T480s (c-24-130-65-46.hsd1.ca.comcast.net [24.130.65.46]) (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 53D6520773; Tue, 27 Oct 2020 00:02:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603756935; bh=S2fWz7i/YT4lvIbM2qM9onXOHifLeu3fj+WHAM6/Uic=; h=Date:From:To:cc:Subject:From; b=L1iKctRVl+HbjZOuleP6fj+u871oq3QJwoicqf8T9s77ZZfViR4y4lgH0KRvluXXE 7HFEZzg/saCMcBDD3TkhqW7EZrHaEYEnFTIS3Cl1IUMxL3LX1kr+N2tNI8mguV1DC9 Mu+SdZmJhL00T7eivPsMxiectmupJ6g6BRr5e3Xo= Date: Mon, 26 Oct 2020 17:02:14 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-T480s To: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org cc: sstabellini@kernel.org, xen-devel@lists.xenproject.org, konrad.wilk@oracle.com, hch@lst.de Subject: [PATCH] fix swiotlb panic on Xen Message-ID: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stefano Stabellini 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. Signed-off-by: Stefano Stabellini diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index c19379fabd20..9924214df60a 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -231,6 +231,7 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose) io_tlb_orig_addr[i] = INVALID_PHYS_ADDR; } io_tlb_index = 0; + no_iotlb_memory = false; if (verbose) swiotlb_print_info(); @@ -262,9 +263,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; } @@ -362,6 +365,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs) io_tlb_orig_addr[i] = INVALID_PHYS_ADDR; } io_tlb_index = 0; + no_iotlb_memory = false; swiotlb_print_info();