Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1083690pxx; Tue, 27 Oct 2020 07:55:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyH4WccQ58NFcQTf05H0CdPauvtOYSIozzxyRuWYfwDH4ewAGlFFDdn1VabKxZd9ueuSyXo X-Received: by 2002:a17:906:31c1:: with SMTP id f1mr2931198ejf.253.1603810558950; Tue, 27 Oct 2020 07:55:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603810558; cv=none; d=google.com; s=arc-20160816; b=0hzmtzn2BYaiZVi3Rklbm935nse7rqflVtrDt+9CCXt+BQM9ecTuC6Ys48j2kFqP4J 1oyw/2lgtLB4naDmnF5CT80lebx5KnGGPX5X5zub8QdtSGFLj0V3hlpiadgj7mFXCebK RRi3RjU8e8HLsuINBk0eGSEhZxJO3FM7inqqfOiu6sstMowmKxv0E1Q/gj7zzssOIUig WiApyQE7JPCD+sD+lDRhysqFaDFZhka7PhpspQrHMXlxXp9VwF9BKObOzoN5Q5OH+RYr 1P61jQZk/Q1cHMfQ+b4tfHtaxL+U6MYIeeelUEW7Gs0SMHApxvQ4Z85htYl6q1d//7n2 iP/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=6SwjgoK6NmHrI7CpsdIL3yfEJog1phV7AEfu8seZA/M=; b=l0ot0zrU8IkBIgPZlrqBTWbiQAPWWH4meRaNIOfAZkFnts2ez+ZCZZl5lto0g+AnOg xkcIPv3jZAHPgjtzOQFWB6u5bGVORXlqnjDLMTpEju26CwYhU+N6s1UfrJs735rdGqCY TS8nwYM6XWlbqmLHs7MF1tbFEyklZvCYH+TuNhmqp2LcNkhVHhWPhP7WKX61l1SQ+FC9 abfVwNSc1lUUI0hcMcoZixi30mQ1JrIG+IxyKdqovyckbWIZRRD8oA5yL7NZY46bnmmR jglF+jfB2IZoNFjNix2EHC6d2oZcJRAUp7a38ABNBNEMTZ8rlH5QNNBmCd9nqwYZ3uCK 4vBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=kRXDExu9; 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=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s16si1131225edy.300.2020.10.27.07.55.36; Tue, 27 Oct 2020 07:55:58 -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=@oracle.com header.s=corp-2020-01-29 header.b=kRXDExu9; 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=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752277AbgJ0Nf2 (ORCPT + 99 others); Tue, 27 Oct 2020 09:35:28 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:47940 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752272AbgJ0Nf2 (ORCPT ); Tue, 27 Oct 2020 09:35:28 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 09RDUV5F054249; Tue, 27 Oct 2020 13:35:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2020-01-29; bh=6SwjgoK6NmHrI7CpsdIL3yfEJog1phV7AEfu8seZA/M=; b=kRXDExu9qqJPjZrehu24qzSbTC0ClcfPsU+E1LCNqwZPgXaAuNivtu7tqhMfiZ6q0lpe Bc1rJ0kUziITVuLTbsP+xc0QqqexEpxCiNpw4wC3MvpUMWaUVfEDuHdObkmMq/Z/v6tH X6h2+gop8GjYD+39av1lHRI9HqyrzDcYyIEZ5VDgzqp4QFliovcuwBR6IXhG+0YeYv6n zZ4tglD5BG/aTAmPoqTvmoggu26V0I/2ZQQVXMhKytv7dCCx8onZQvV3Z5ohpk4C1U1/ TQXQoHQHMUjEUi7pbhhlMvU0zdedoahfmbvsem7LF20QVv3dtc1iiQTSPRaKivdbHjOp Fg== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 34dgm3yjgm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 27 Oct 2020 13:35:20 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 09RDVI8m168151; Tue, 27 Oct 2020 13:35:19 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 34cx6vygrw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 27 Oct 2020 13:35:19 +0000 Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 09RDZI5Y012414; Tue, 27 Oct 2020 13:35:18 GMT Received: from char.us.oracle.com (/10.152.32.25) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 27 Oct 2020 06:35:18 -0700 Received: by char.us.oracle.com (Postfix, from userid 1000) id 8FA456A0121; Tue, 27 Oct 2020 09:37:01 -0400 (EDT) Date: Tue, 27 Oct 2020 09:37:01 -0400 From: Konrad Rzeszutek Wilk To: Stefano Stabellini Cc: 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 Message-ID: <20201027133701.GB6077@char.us.oracle.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.1 (2017-09-22) X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9786 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 spamscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 mlxscore=0 suspectscore=2 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2010270085 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9786 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 impostorscore=0 adultscore=0 bulkscore=0 spamscore=0 phishscore=0 mlxlogscore=999 suspectscore=2 clxscore=1011 mlxscore=0 malwarescore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2010270085 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. Should this have a Fixes: flag? > > 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(); >