linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Liu Song <liusong@linux.alibaba.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/dmapool.c: avoid duplicate memset within dma_pool_alloc
Date: Sat, 16 Jul 2022 18:01:10 -0700	[thread overview]
Message-ID: <20220716180110.eb9402180137d0ce84e3971c@linux-foundation.org> (raw)
In-Reply-To: <1657769100-66142-1-git-send-email-liusong@linux.alibaba.com>

On Thu, 14 Jul 2022 11:25:00 +0800 Liu Song <liusong@linux.alibaba.com> wrote:

> From: Liu Song <liusong@linux.alibaba.com>
> 
> 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 <linux/device.h>
>  #include <linux/dma-mapping.h>
> +#include <linux/dma-map-ops.h>
>  #include <linux/dmapool.h>
>  #include <linux/kernel.h>
>  #include <linux/list.h>
> @@ -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.



  reply	other threads:[~2022-07-17  1:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-14  3:25 Liu Song
2022-07-17  1:01 ` Andrew Morton [this message]
2022-07-17 16:42   ` liusong
2022-07-18  2:07     ` liusong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220716180110.eb9402180137d0ce84e3971c@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=liusong@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox