From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C0ACDC4332F for ; Wed, 28 Dec 2022 10:21:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8CSFXgcN4VQjKwfei/Uj2ucn8F6BzF9NhVh8GYTVQ2Y=; b=XOp6cAF30tEKHo jWcmlXEKR7rmpsFQfj67ww9V/a8ytUfYc6IR1huEQG3v6iKKki24j+FHUm8GN1UySVNCx8HutSO+c Q2Q/7ov72ebWWH4P+rO+t+R1z8NW7cC2pQSm+0YfWXxbT+v9O/f0r8w1U+fQF1t63I1lZ0Ei/IEUh eJw4gjXN47K48PEQr/JuG3KIE6npzlrnjVhuugnYPT1u8pnlcEJiax2r0Ia8PekGwx6vAlrz8iUk/ TowOX2MFMUB+Ai7PlqSjtKUjV8wk2bQWUdkPaKGIaWXw35jAD2SoHOaAeH5R+Gb9WWL2SOyfTEZxr +P0/vYXasm7UBkXtfPJA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pATXZ-0042e1-Qw; Wed, 28 Dec 2022 10:20:05 +0000 Received: from msg-2.mailo.com ([213.182.54.12]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pATXV-0042a7-Jo for linux-arm-kernel@lists.infradead.org; Wed, 28 Dec 2022 10:20:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1672222789; bh=yaSeTGEOIHFUCNv85STZQEEdflntXgAfikFausxiyNQ=; h=X-EA-Auth:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:In-Reply-To; b=o3z6ig/mwe1pOTfipWIAixNbdYJreeh/1tjproiEss1amx8twidj1vIfz0kBOBGI5 Ls2nklyGlBVyvBoE2DDdPfCs4J7wISFy5sk2h5NXxQ2gHSWQBtZMUdhJdBhIvZffQI RDQTnImemxjgbqNbN39kMmICZM+yhs6tNvZJOVbk= Received: by b-4.in.mailobj.net [192.168.90.14] with ESMTP via ip-206.mailobj.net [213.182.55.206] Wed, 28 Dec 2022 11:19:49 +0100 (CET) X-EA-Auth: HTwR0RTVn3jmTAnZvKty8PhPAQ09MjALLL2vXYUaBOtEbkvPSuYBqLA55Dc031s0qJx6Yu4fYJvUgMpUXgqC8wfLRY27uWCz Date: Wed, 28 Dec 2022 15:49:44 +0530 From: Deepak R Varma To: Russell King , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Praveen Kumar , Saurabh Singh Sengar , Julia Lawall , Deepak R Varma Subject: Re: [PATCH v2] ARM/dma-mapping: use kvcalloc for fallback memory allocation need Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221228_022002_124312_501FC54B X-CRM114-Status: GOOD ( 22.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Dec 20, 2022 at 07:46:32PM +0530, Deepak R Varma wrote: > Current conditional determination of whether to use kzalloc or vzalloc > has known issues such as "indefinite retry" when less than PAGE_SIZE > memory is needed, but is unavailable. This LWN article [1] describes > these issues in greater detail. Use helper function kvcalloc() instead > which is more efficient in terms of performance and security. > > [1] https://lwn.net/Articles/711653/ > > This patch proposal is based on following Coccinelle warning using the > kvmalloc.cocci semantic patch. > arch/arm/mm/dma-mapping.c:858:28-29: WARNING opportunity for kvmalloc > > The semantic patch suggests using kvzalloc() helper function, however, > this patch proposes to use kvcalloc instead. kvcalloc() helper function > uses 2-factor argument form which is better from a security perspective > as described in the following KSPP project commit. > > Commit 4e3fd7217105 ("wireguard: ratelimiter: use kvcalloc() instead of kvzalloc()") > > Signed-off-by: Deepak R Varma Hello, May I please request a review and feedback on this patch proposal? Thank you, ./drv > --- > > Changes in v2: > 1. Update patch subject to use kvcalloc > 2. Use kvcalloc instead of kvzalloc helper function. Revise the patch > proposal and the patch description accordingly. > > > arch/arm/mm/dma-mapping.c | 6 +----- > 1 file changed, 1 insertion(+), 5 deletions(-) > > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c > index c135f6e37a00..35092ecd30e1 100644 > --- a/arch/arm/mm/dma-mapping.c > +++ b/arch/arm/mm/dma-mapping.c > @@ -851,14 +851,10 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size, > { > struct page **pages; > int count = size >> PAGE_SHIFT; > - int array_size = count * sizeof(struct page *); > int i = 0; > int order_idx = 0; > > - if (array_size <= PAGE_SIZE) > - pages = kzalloc(array_size, GFP_KERNEL); > - else > - pages = vzalloc(array_size); > + pages = kvcalloc(count, sizeof(struct page *), GFP_KERNEL); > if (!pages) > return NULL; > > -- > 2.34.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel