Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp611407pxx; Wed, 28 Oct 2020 12:22:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwcPQX+cr1NenXnwGiS4lnrfI973j7z/QQiS09iCnFeKgQ8nAFS5XVUg7mJMu7qCxb65wvp X-Received: by 2002:a17:906:fc10:: with SMTP id ov16mr588487ejb.417.1603912927222; Wed, 28 Oct 2020 12:22:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603912927; cv=none; d=google.com; s=arc-20160816; b=ySu4hw5LBFbL9nSTVr0h7Iti5XpqLRYmf6QUgXXpVTzWrF0/Ptca3pHT/4wNBZYrwe MS3/Mb+9cK1itDWJ24xgK68YfOS5KfQC69oTPlmPMeaKAlcfpBPKmmVAfxdX6S2ed0dQ /fXcfUw8JF6rxEoYgG0+3QOtGtjnvi1RhqTboDHjA3YqzMwBs1kKSitdu5OL9mnV3M3F dk3VwKokAHhYue2TsCXaz+QMQCl38LG9fUuhmdWeTuMA1vDPS37G5oJ0f9GriOWQe2rR lPS9dni9Opd+crMzKUvLmKkYy+ahQ338/awMEn2GSrYs7wBf/hzPexVga8YlTlD3nPm2 olmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=cfJejkImOytUufwfa2ygl4ItC3y2KTTENvxtOi6ei6U=; b=iXIzWCxOPfT5AYhx5TLnJMHXq/IS7oTKzalU8BAoJHhMjR1hezDyTeoXlr2MCmk/14 q6pCPCHtt10MViM9Wyv87rpfaHs3JeTZDFGvgrq5DiJQaKSYk27KjNGzAX/or2kdhqfr fKrxQsybvbHT5VJnH9wE8GTxmC8fSNpQC90L7hexkJye0J+2SHQ6ViYwbffEkydxCH7v PBuuoc+16okjeRrulaweTbtcR3VCps2ifm79mgn7Y4+aLEpBAvtPNYdj1wipy0EJQe5C INbtBYokzzFhLkKTjK5M310Q8LhE6ohveRfVJXZt5Y87/eraD8i48H5XiP8ChgIL1EAK otYA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bm13si21671edb.281.2020.10.28.12.21.44; Wed, 28 Oct 2020 12:22:07 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1827245AbgJ0SWc (ORCPT + 99 others); Tue, 27 Oct 2020 14:22:32 -0400 Received: from mailhost.m5p.com ([74.104.188.4]:29455 "EHLO mailhost.m5p.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1826543AbgJ0SUW (ORCPT ); Tue, 27 Oct 2020 14:20:22 -0400 X-Greylist: delayed 1721 seconds by postgrey-1.27 at vger.kernel.org; Tue, 27 Oct 2020 14:20:22 EDT Received: from m5p.com (mailhost.m5p.com [IPv6:2001:470:1f07:15ff:0:0:0:f7]) by mailhost.m5p.com (8.15.2/8.15.2) with ESMTPS id 09RHpF0L032137 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 27 Oct 2020 13:51:20 -0400 (EDT) (envelope-from ehem@m5p.com) Received: (from ehem@localhost) by m5p.com (8.15.2/8.15.2/Submit) id 09RHpEQr032136; Tue, 27 Oct 2020 10:51:14 -0700 (PDT) (envelope-from ehem) Date: Tue, 27 Oct 2020 10:51:14 -0700 From: Elliott Mitchell To: Stefano Stabellini Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, konrad.wilk@oracle.com, hch@lst.de Subject: Re: [PATCH] fix swiotlb panic on Xen Message-ID: <20201027175114.GA32110@mattapan.m5p.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=0.0 required=10.0 tests=KHOP_HELO_FCRDNS autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mattapan.m5p.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > > 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(); > As the person who first found this and then confirmed this fixes a bug: Tested-by: Elliott Mitchell -- (\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/) \BS ( | ehem+sigmsg@m5p.com PGP 87145445 | ) / \_CS\ | _____ -O #include O- _____ | / _/ 8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445