Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp279408img; Wed, 27 Mar 2019 22:56:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqzYOeofwamXzy6p4L+fS/F6jfIQqfRyacxvC3H898xFsI4Z1ijmga5ikx/yNC8Qh8yIoUMM X-Received: by 2002:a17:902:be04:: with SMTP id r4mr27533015pls.218.1553752595227; Wed, 27 Mar 2019 22:56:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553752595; cv=none; d=google.com; s=arc-20160816; b=td5bhacLZlwwwFBtL55FMHX6RIRA7U4wzE32w7G4TLNR/aC6RjUoIulpIk2ddHGOi+ vv4fl+D1o54ipnnLAu+NgKffWA94Ux0UYszJIJ2WThOFnY3pYf7OxOZJ/rQGkYUUAY+n DZdXa3m1Uu3L4p9U1oAvyOJlyyMUa4c4t74pdC8fIGRBWAO4aEpe4UPgwhzEz5CdrBaq 7q7vekCsb0/YdQufZ1ZpCqF2+kUn8ZjJ43uvt7eYDQ3tjZLWS+NLDYBagZEA4yJvgZcV Wb+oCTXVzxLoIjmL10YY4vwe3hqFgfZ5ubk2r0Wg8vDZhpEGuEQUrg+dD9+xRtmJSWUg ZDtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:subject:cc:to:from:date; bh=vtVcaA4hbw60YzEkSa3PSWX//zF2FxiT9y7VxPk/wzU=; b=lxHVsgFwlu0YdgVR3utKCB+Pnrr1jIwMHY85v49elJlA8z5tl6vb4cK7tzJZnX4uiX 78vYpdX1F1puyLYGuxH1NkR+SNR/DNEmz9U2SaxfY8/GbBdAcG09zxbmeox0hcHVhugY lt4UNtcttefnDH/OY+7ghBNkOLZg1crOm3oJIiD4X1Pz2wd8yNKjFlfZEuAMRn6rPFiS 8W9tIYaYYeNg8Su/QQgZD/zlam5vQIWABlRL/UDr68yExSWpsC3en5p8ksEIgxliXQz7 dsE9ngDG07UvuvwnF8y35WRRi9HfjOg6PIx3CDIMOKmMdAX0FnJM3GUiMyyuv+TUmci4 2lSQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m2si20739161plt.394.2019.03.27.22.56.19; Wed, 27 Mar 2019 22:56:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726164AbfC1Fzj (ORCPT + 99 others); Thu, 28 Mar 2019 01:55:39 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:42588 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725806AbfC1Fzj (ORCPT ); Thu, 28 Mar 2019 01:55:39 -0400 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x2S5nIHE072437 for ; Thu, 28 Mar 2019 01:55:37 -0400 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0b-001b2d01.pphosted.com with ESMTP id 2rgq2wkdek-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 28 Mar 2019 01:55:37 -0400 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 28 Mar 2019 05:55:35 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 28 Mar 2019 05:55:26 -0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x2S5tOJu54198406 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 28 Mar 2019 05:55:25 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D2EBD4C046; Thu, 28 Mar 2019 05:55:24 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 517B94C05C; Thu, 28 Mar 2019 05:55:22 +0000 (GMT) Received: from rapoport-lnx (unknown [9.148.8.112]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Thu, 28 Mar 2019 05:55:22 +0000 (GMT) Date: Thu, 28 Mar 2019 07:55:20 +0200 From: Mike Rapoport To: Sasha Levin Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Catalin Marinas , Christophe Leroy , Christoph Hellwig , "David S. Miller" , Dennis Zhou , Geert Uytterhoeven , Greentime Hu , Greg Kroah-Hartman , Guan Xuetao , Guo Ren , Guo Ren , Heiko Carstens , Juergen Gross , Mark Salter , Matt Turner , Max Filippov , Michael Ellerman , Michal Simek , Paul Burton , Petr Mladek , Richard Weinberger , Rich Felker , Rob Herring , Rob Herring , Russell King , Stafford Horne , Tony Luck , Vineet Gupta , Yoshinori Sato , Andrew Morton , Linus Torvalds , iommu@lists.linux-foundation.org Subject: Re: [PATCH AUTOSEL 5.0 008/262] swiotlb: add checks for the return value of memblock_alloc*() References: <20190327180158.10245-1-sashal@kernel.org> <20190327180158.10245-8-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190327180158.10245-8-sashal@kernel.org> User-Agent: Mutt/1.5.24 (2015-08-30) X-TM-AS-GCONF: 00 x-cbid: 19032805-0012-0000-0000-0000030830CD X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19032805-0013-0000-0000-0000213F6046 Message-Id: <20190328055520.GA14864@rapoport-lnx> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-03-28_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=52 phishscore=0 bulkscore=0 spamscore=0 clxscore=1031 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903280044 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Wed, Mar 27, 2019 at 01:57:43PM -0400, Sasha Levin wrote: > From: Mike Rapoport > > [ Upstream commit a0bf842e89a3842162aa8514b9bf4611c86fee10 ] > > Add panic() calls if memblock_alloc() returns NULL. > > The panic() format duplicates the one used by memblock itself and in > order to avoid explosion with long parameters list replace open coded > allocation size calculations with a local variable. This patch is a part of a series that removes panic() calls from memblock allocators rather than a fix. > Link: http://lkml.kernel.org/r/1548057848-15136-19-git-send-email-rppt@linux.ibm.com > Signed-off-by: Mike Rapoport > Cc: Catalin Marinas > Cc: Christophe Leroy > Cc: Christoph Hellwig > Cc: "David S. Miller" > Cc: Dennis Zhou > Cc: Geert Uytterhoeven > Cc: Greentime Hu > Cc: Greg Kroah-Hartman > Cc: Guan Xuetao > Cc: Guo Ren > Cc: Guo Ren [c-sky] > Cc: Heiko Carstens > Cc: Juergen Gross [Xen] > Cc: Mark Salter > Cc: Matt Turner > Cc: Max Filippov > Cc: Michael Ellerman > Cc: Michal Simek > Cc: Paul Burton > Cc: Petr Mladek > Cc: Richard Weinberger > Cc: Rich Felker > Cc: Rob Herring > Cc: Rob Herring > Cc: Russell King > Cc: Stafford Horne > Cc: Tony Luck > Cc: Vineet Gupta > Cc: Yoshinori Sato > Signed-off-by: Andrew Morton > Signed-off-by: Linus Torvalds > Signed-off-by: Sasha Levin > --- > kernel/dma/swiotlb.c | 19 +++++++++++++------ > 1 file changed, 13 insertions(+), 6 deletions(-) > > diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c > index c873f9cc2146..41224f0ec40e 100644 > --- a/kernel/dma/swiotlb.c > +++ b/kernel/dma/swiotlb.c > @@ -191,6 +191,7 @@ void __init swiotlb_update_mem_attributes(void) > int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose) > { > unsigned long i, bytes; > + size_t alloc_size; > > bytes = nslabs << IO_TLB_SHIFT; > > @@ -203,12 +204,18 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose) > * to find contiguous free memory regions of size up to IO_TLB_SEGSIZE > * between io_tlb_start and io_tlb_end. > */ > - io_tlb_list = memblock_alloc( > - PAGE_ALIGN(io_tlb_nslabs * sizeof(int)), > - PAGE_SIZE); > - io_tlb_orig_addr = memblock_alloc( > - PAGE_ALIGN(io_tlb_nslabs * sizeof(phys_addr_t)), > - PAGE_SIZE); > + alloc_size = PAGE_ALIGN(io_tlb_nslabs * sizeof(int)); > + io_tlb_list = memblock_alloc(alloc_size, PAGE_SIZE); > + if (!io_tlb_list) > + panic("%s: Failed to allocate %lu bytes align=0x%lx\n", > + __func__, alloc_size, PAGE_SIZE); > + > + alloc_size = PAGE_ALIGN(io_tlb_nslabs * sizeof(phys_addr_t)); > + io_tlb_orig_addr = memblock_alloc(alloc_size, PAGE_SIZE); > + if (!io_tlb_orig_addr) > + panic("%s: Failed to allocate %lu bytes align=0x%lx\n", > + __func__, alloc_size, PAGE_SIZE); > + > for (i = 0; i < io_tlb_nslabs; i++) { > io_tlb_list[i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE); > io_tlb_orig_addr[i] = INVALID_PHYS_ADDR; > -- > 2.19.1 > -- Sincerely yours, Mike.