Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp4382801rwl; Wed, 28 Dec 2022 03:25:28 -0800 (PST) X-Google-Smtp-Source: AMrXdXuYYehhLLe3v7PmMr52oXqcGYMHqfm4C0QepWP5TBO4ObcWK6hjRG4se/5+Ge6d9bwNAuZ0 X-Received: by 2002:a62:6345:0:b0:580:cfbc:2902 with SMTP id x66-20020a626345000000b00580cfbc2902mr14513222pfb.1.1672226728662; Wed, 28 Dec 2022 03:25:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672226728; cv=none; d=google.com; s=arc-20160816; b=EvHLlJvNdAlTieTD7jfo3d7+E5u99GFAbm6/57GeWvuh819ffb/Kg2X7SOm7Dn0VTo bOZcvtYa/BARg7CyZLe4oDnkh5N04NzmmgFNwpQ1tvckxorsRrwJqhI1uS/CyYnGfErY JNmZI6hiIG5KPMyNpiUjZ/mVvwffWn8K7D92bNwLh2iYJak0ynwze2FlSsmhmkHFjs5d MjjO5C5OkPg0cfHFmgfIA5/oQ0fDXfLaauU34pNyHB5wZsCvRDevSRS9z75zSe4LC7HM rmRbsjWuwtOIf7Uj+Xjh0EQIirMA3t6EAfTQ/cnJu0ryUo31bb9jvo2IEHW2Y871hA7P bH8g== 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:dkim-signature; bh=Ged0BcnMZ3PHOcZjrhhdZ4FPZDaKW1IVNE4NHro+GqM=; b=T7jybT3CoqMNcRq93xb6YIJOelkF90TMWwCfQa5m9HNj6OwGWAe8PNGFNmNMB/7/US g/+yKh8m2JiMG5ji6kbA5gK3tGJA4qsX9uVcsss5W3GTRnWAOnhx0hvcs3wSulYCewjh 5IMeMpQX/JZ3Fhd6NjyBvZR3DNs1OQCSkNxXJt2dIjRN+DZNvI9uykobT9JGCu4Qre3L 2uZWPvXpO9TkEAK4YK5oOkge+6Qbnsh0rHxR2JvBFjOSKrezwkZNHeBL025aSVxc+Ua/ wXavWl1wx/v6OqRiMRtsrZnBjp4SAixYgSE3F0JqsxUxpe1dUaYO3NssIG5HiLwhGtqZ HMsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b="o3z6ig/m"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t28-20020aa7947c000000b00577d10d6eaesi8227249pfq.169.2022.12.28.03.25.19; Wed, 28 Dec 2022 03:25:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b="o3z6ig/m"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230224AbiL1KUH (ORCPT + 64 others); Wed, 28 Dec 2022 05:20:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229785AbiL1KUF (ORCPT ); Wed, 28 Dec 2022 05:20:05 -0500 Received: from msg-2.mailo.com (msg-2.mailo.com [213.182.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 368721009 for ; Wed, 28 Dec 2022 02:20:05 -0800 (PST) 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 >