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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 129D5C43334 for ; Sun, 17 Jul 2022 01:01:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1F1D86B0082; Sat, 16 Jul 2022 21:01:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A1156B0083; Sat, 16 Jul 2022 21:01:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 08F4C6B0085; Sat, 16 Jul 2022 21:01:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id EAE9F6B0082 for ; Sat, 16 Jul 2022 21:01:13 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 9ADD11203BF for ; Sun, 17 Jul 2022 01:01:13 +0000 (UTC) X-FDA: 79694788026.06.172D5B5 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf25.hostedemail.com (Postfix) with ESMTP id 359F1A0070 for ; Sun, 17 Jul 2022 01:01:13 +0000 (UTC) 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 3E28160EB7; 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658019673; a=rsa-sha256; cv=none; b=gy3YdVE0a5MJ7GibCnrC/+K0WjF/Cs2hGxZ2eMPQR15DhzmVHVZDkjkeBCNFqPPulkTGFn L57O2nkQwJlr0gLFDfXnGytkglW3g/D6wp6YcvC4jcix1MixRHz+0evMwpGjeRP+ZoJItK 44EPWP+YKWCQUvUo7nw4chUFDh1Onu4= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=eFOHmUhV; spf=pass (imf25.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658019673; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Ykd2EdN2v7CnwgnbQeTMaJ/AbR60XIpPjWQucRvkl+0=; b=cMlOHCKtkA1rpxZPPH3W6h8UxDoo+CGfZnwJmYNtl2Dkby7aEWiHCnUdc/UVGryTYCiq0v +x1pUyEgvb2cdwRfa/6MR9LM0KvkSTcliBmBhpd9o4Bt3ARSzV3nFoDmkLItWSk/j7hIrt 7dvT9zAqKmR0xsVbI9nKw2bg6oCB9TM= X-Rspamd-Queue-Id: 359F1A0070 Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=eFOHmUhV; spf=pass (imf25.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Rspamd-Server: rspam05 X-Rspam-User: X-Stat-Signature: nzmjixmcne1fj334jwrwef57p8r75z3m X-HE-Tag: 1658019673-224221 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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.