Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp535291pxx; Wed, 28 Oct 2020 10:31:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnAldiivtoZyPJWuqb9rCG2lHNXGLbgX273yjMZKj9bWx/m4Q9hO31b6Mw0+zKeiMk1SXr X-Received: by 2002:a17:906:4059:: with SMTP id y25mr148958ejj.418.1603906261101; Wed, 28 Oct 2020 10:31:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603906261; cv=none; d=google.com; s=arc-20160816; b=GrbKjUEArqv0eZE+RHV9Gflrmpr3truz0PjA/WKFSj8M8x2809uJ19yQEJzzRgVWGw aXp7ZyLC0Vfd0pwafnQ6dYXOS7iFTqAFXCsx6I3K3ypjmUCH34sJXb8lGK4BohLvbuT3 u7+wh19IWmH6zxYP8d3qgA9L1G6lKoRL8lpq/mzNA5tJ9RwTadxESsLeQ4mkTD8eFiiw kdZd6YcK+Rj1AYRzK6rkGv+vWwvFbyBUrXEEUy4vDXKzU7gE1Qpn7pDhOj8GaAcOheZe Pq/2Kf582VKSlp3dnWNXGQrSuTsa1ENbc1VlkA6hojboZXBTSBhadV+QZoHojoNlgAkS uhsQ== 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:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=CLrpajFOdONLPopIuAfT3Tz8XRkMs+02q993li/AJVM=; b=ARYT2HeqgD+7jjc6lwCeznbqb32YD7HfrQQbsarjvZdeLZMzpohhBCPNqzQKClgZh2 3Gk0az4iFYx83XN4ieMo7J7kOYzul4vSABnTzFH35fdjFoLrio1JXdj+S2+WUAp+F7Uz esbOTBAHamQfLZVgNhkNBrkn4Lp2d2jkIgRc89SAVAWC4AujUAbF23qTljSIDOqaovKv CaxXupgIa6KOqYjzxsWnSNfY+IT1uIpYezYsdHd2KuaS2HnFFABnTWTjagqvI+PA74OZ J2W6b43i+//yLUN9YSC4PFfEhyCkIqHzqtPdncCbumOkRdyB+fps47n9lFHkFeas13XP SnhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MMM+0N60; 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 z17si3710274ejc.499.2020.10.28.10.30.38; Wed, 28 Oct 2020 10:31:01 -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=MMM+0N60; 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 S1821388AbgJ0RnN (ORCPT + 99 others); Tue, 27 Oct 2020 13:43:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:33008 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1821381AbgJ0RnK (ORCPT ); Tue, 27 Oct 2020 13:43:10 -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 E2B912054F; Tue, 27 Oct 2020 17:43:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603820590; bh=7PAIrARo+U5BjdgOi0yQlsQrBkmZ+IVZWY4TopAO5S0=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=MMM+0N60ODKjqcP7/UwhGGndw5EYDfe/PwXyJI+6tNbzrhUuGH+SoWyHcSgzjOqNz fovF3qvrYsGblmTK/PtbuY+/wlQATssJpiclYPtzUGafdoOhjwqfgsoQBeFL/zjs2R wQhW8o38W5vMUl+wL+KE9PxS4CW7FEyLrSSwW2SI= Date: Tue, 27 Oct 2020 10:43:09 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-T480s To: Konrad Rzeszutek Wilk cc: Stefano Stabellini , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, hch@lst.de Subject: Re: [PATCH] fix swiotlb panic on Xen In-Reply-To: <20201027133701.GB6077@char.us.oracle.com> Message-ID: References: <20201027133701.GB6077@char.us.oracle.com> 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 On Tue, 27 Oct 2020, Konrad Rzeszutek Wilk wrote: > On Mon, Oct 26, 2020 at 05:02:14PM -0700, Stefano Stabellini wrote: > > 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. > > Should this have a Fixes: flag? That would be Fixes: ac2cbab21f31 ("x86: Don't panic if can not alloc buffer for swiotlb") > > 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(); > > >