lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <13d6bf0e-b22b-4414-a091-264877904ab9.liusong@linux.alibaba.com>
Date:   Mon, 18 Jul 2022 00:42:24 +0800
From:   "liusong" <liusong@...ux.alibaba.com>
To:     "Andrew Morton" <akpm@...ux-foundation.org>
Cc:     "linux-mm" <linux-mm@...ck.org>,
        "linux-kernel" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] mm/dmapool.c: avoid duplicate memset within dma_pool_alloc

>> From: Liu Song <liusong@...ux.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?
The following is the code flow, 
dma_pool_alloc
    |--> pool_alloc_page
           |--> dma_alloc_coherent
                  |--> dma_alloc_attrs
In "dma_alloc_attrs", if "dma_alloc_direct" is true, then enter "dma_direct_alloc",
and in "dma_direct_alloc", as long as the memory allocation is successful, will execute
"memset(ret, 0, size);", which set memory to zero.
Kernel use "dma_go_direct" to determine whether to use direct allocation, which mainly
by judging whether "dma_map_ops" exists.

So this patch determines whether direct alloc will be used by judging does "dma_map_ops" exists,
thereby avoiding repeated memset.

>
>> --- 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.

If DMAPOOL_DEBUG is configured, its logic is internally self-consistent.
If the user needs __GFP_ZERO, the corresponding memory will be set to 0.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ