Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1892054imw; Sat, 16 Jul 2022 18:05:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ufthTSEAb80XSSTsVIGwFjS5TH+jWWRkNCuLltRQp5qYhUDxwsm+IHgXR7D/IqaycglVQ0 X-Received: by 2002:a50:ce1d:0:b0:43a:742f:9db3 with SMTP id y29-20020a50ce1d000000b0043a742f9db3mr28529593edi.308.1658019949304; Sat, 16 Jul 2022 18:05:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658019949; cv=none; d=google.com; s=arc-20160816; b=OozZj2ElAqEkoOuFq39lCC2et5gdNBrGzoyflyPGW5yZOGD9z/YlA30Yhn58CUlGZO zrfLEu695jO0Dddyd4SHv7gPJ8z23eoFTfJ3ZDdzusneL0ohI8VPAUMKhstnrJEbb2NH nC0XlF0j4fIawW5D6wM3UsxJHdUw+lEtSp/PU10nh+kFGMapxcO2P0B01uZ0TZl30Qys M0ukb60Ti6JQWO0ma17cDaI3m41iDnvalEpZn8YycbqtaZIp8TBTIJju0XezixG6bML8 O4NB28c2N8lJ+uyiejUamfvyiPacUE9o5iO65PzAmlSp3kRrZzzz9n8tNaq50OAmvTDt e4Gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=Ykd2EdN2v7CnwgnbQeTMaJ/AbR60XIpPjWQucRvkl+0=; b=YxMsNaQfD4cyENphKfEamTqNhk2290mYKbV2w9R5jT2/KQ0bLA1dSDGYAFoDiTZj2E RWOasWJWEgQUJSfozhCDHOnovCa24Obzksikfshu9IgJ8aw+7XKRcuYWhzgBbNpbPzAX kItpvGDKXj9a7blF715yBthBcgjPXr/QLm484L7v5MwoAvKyMYPGEwNQy/RNy5TLrdDW oBhNSGf0H3tXWwiY/UgzN0srGBo5E0tAvhUdYoonBkhYyQuQQInNu0vs0zInA0P2bvkF r2+U0Ijrx27VSU4LUnlFDOtSXJI4f3PCHDuFB4iPvuOvcKeFpBaWytj4+h2vKg99sTDZ ISuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=eFOHmUhV; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hr32-20020a1709073fa000b00722e91c126bsi13086694ejc.55.2022.07.16.18.05.19; Sat, 16 Jul 2022 18:05:49 -0700 (PDT) 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=pass header.i=@linux-foundation.org header.s=korg header.b=eFOHmUhV; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231588AbiGQBBO (ORCPT + 99 others); Sat, 16 Jul 2022 21:01:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229544AbiGQBBN (ORCPT ); Sat, 16 Jul 2022 21:01:13 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98B1D1A807 for ; Sat, 16 Jul 2022 18:01:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3382260C53 for ; Sun, 17 Jul 2022 01:01:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A681C34114; Sun, 17 Jul 2022 01:01:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1658019671; bh=efYIWOoWV0zkOHCTekecrsLSFtORWtfGT60gVLT8918=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=eFOHmUhVf40FTuq6n783AYVUnDjqFs1s2oBFNrcOxWB72HxkcELLD+n0Riwxl23g6 lknYahEVTA5Qi9HjpxyiIAox3xKgDzVrKGACH8i2gaTWf5SV5vk7rEqptUgAJAqjCS nmsM+JvZRXCYjvJlt+Yea4wAcUiPym7UHVWH797w= Date: Sat, 16 Jul 2022 18:01:10 -0700 From: Andrew Morton To: Liu Song Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/dmapool.c: avoid duplicate memset within dma_pool_alloc Message-Id: <20220716180110.eb9402180137d0ce84e3971c@linux-foundation.org> In-Reply-To: <1657769100-66142-1-git-send-email-liusong@linux.alibaba.com> References: <1657769100-66142-1-git-send-email-liusong@linux.alibaba.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, 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 Thu, 14 Jul 2022 11:25:00 +0800 Liu Song wrote: > From: Liu Song > > In "dma_direct_alloc", the allocated memory is explicitly set to 0. > If use direct alloc, we need to avoid possible duplicate memset in > dma_pool_alloc. I'm having trouble seeing how this change is safe and correct and maintainable. Please describe the code flow more completely? > --- a/mm/dmapool.c > +++ b/mm/dmapool.c > @@ -21,6 +21,7 @@ > > #include > #include > +#include > #include > #include > #include > @@ -372,7 +373,7 @@ void *dma_pool_alloc(struct dma_pool *pool, gfp_t mem_flags, > #endif > spin_unlock_irqrestore(&pool->lock, flags); > > - if (want_init_on_alloc(mem_flags)) > + if (want_init_on_alloc(mem_flags) && get_dma_ops(pool->dev)) > memset(retval, 0, pool->size); That DMAPOOL_DEBUG memset a couple of lines earlier could/should be testing the same condition - there's no point in poisoning an area which we're about to zero out.