Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3891514pxb; Tue, 17 Nov 2020 06:19:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJx2RutzljSCk00xvRm2gxWIxExBCcCy8bI7Q7+B+qRjfVzrqVIg3jdx+fJB8PhnToH5irYT X-Received: by 2002:a17:906:13d2:: with SMTP id g18mr1131560ejc.76.1605622761496; Tue, 17 Nov 2020 06:19:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605622761; cv=none; d=google.com; s=arc-20160816; b=TasRKXexBzDUI3xQBqkgEof9UFf0GyBbKlkGvA24Wm1LMNWTMKCG+EQEaZ/f27MJMS YyxeezAL1brYyYeoQl9Iy+AVNbxBZO7ulkr9d0RXmtSiDPCvuZwjfvfp9fUeZPGDFQqh uMh3VJex7ueaIfzKfCd5dpGujSUF1FORBpbMUCdr7xzaGLOSyGdPyqDroabG6yJE2+0+ YzfaGgttzv1aOpyPKcZwK9skU+b1hiDoMQFll8uu/mjJ33Y9uEAG4NRYI0OLVYx2QMwk voa9HgP2iUriN2rjJJs1Gdk3QORI0BQe7PD1FtjTl4ib7FI92CnNvneEOVPjEHhJhs4o dAUw== 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=Y953r4BA3oV4tD35TjN1VeLRXz7lxNAq599j+OxKvEQ=; b=IYnLxotu3MfYsdN/B7hOxoH5oIrj3mNvZkPFEiNv+//PB+vytTx1NZTNwrharPoyXs MqFTi4HxsVj2BKApf05GkdR6YF9MX5F880fdwsd5tyn92PhrFpR8EgZTSoqzCxi6DzKw cEIeTxfIYxJzMcL54AVaVCv/9L8CLXXj0xRPV+SDuTUkt77P4P0WvsNZqF8WXWXl2Bye rbnqJjQ+VnTBj24xk6hhwpbgxjA0w69tky4y2Zdb5/tJpv8snkyCNrqI5rj7IxB46Kvl 8j+ZCykjLnz7+VI3L2YV49O/v+DJtItWXlMje3GW0TShAWnIfydFsk9edeujqIYkVsXY nMRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1tGke6Ov; 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 c1si7045077edx.275.2020.11.17.06.18.58; Tue, 17 Nov 2020 06:19:21 -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=1tGke6Ov; 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 S1733078AbgKQNlZ (ORCPT + 99 others); Tue, 17 Nov 2020 08:41:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:53614 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733079AbgKQNlW (ORCPT ); Tue, 17 Nov 2020 08:41:22 -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 65D41207BC; Tue, 17 Nov 2020 13:41:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605620480; bh=uMt8wEHflXX1QE9Fyc2eI7neZNUuU0xC3YESKQm76W4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1tGke6OvY7gd5Y7GvdLI1OLvTmfeJMuGMSiCMxtojd5dBxRWGcM6Vup66cG0/0Vx4 Aasl1PG74xqiE9p+ubt6wiXtDgIkz2dOvX3SLjVc2IRxPNiWzjC91vCbv2g3S+A9bH F3zPGq7KD4LlEqsjPA5vVfcgexkrI55mU13hfKLo= 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 5.9 234/255] swiotlb: fix "x86: Dont panic if can not alloc buffer for swiotlb" Date: Tue, 17 Nov 2020 14:06:14 +0100 Message-Id: <20201117122150.326264475@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122138.925150709@linuxfoundation.org> References: <20201117122138.925150709@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 @@ -231,6 +231,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(); @@ -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, un io_tlb_orig_addr[i] = INVALID_PHYS_ADDR; } io_tlb_index = 0; + no_iotlb_memory = false; swiotlb_print_info();