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]
Date:   Mon, 12 Jun 2023 13:49:56 +0200
From:   "Fabio M. De Francesco" <fmdefrancesco@...il.com>
To:     Sumitra Sharma <sumitraartsy@...il.com>
Cc:     Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Andrii Nakryiko <andrii@...nel.org>,
        Martin KaFai Lau <martin.lau@...ux.dev>,
        Song Liu <song@...nel.org>, Yonghong Song <yhs@...com>,
        John Fastabend <john.fastabend@...il.com>,
        KP Singh <kpsingh@...nel.org>,
        Stanislav Fomichev <sdf@...gle.com>,
        Hao Luo <haoluo@...gle.com>, Jiri Olsa <jolsa@...nel.org>,
        bpf@...r.kernel.org, linux-kernel@...r.kernel.org,
        Ira Weiny <ira.weiny@...el.com>, Deepak R Varma <drv@...lo.com>
Subject: Re: [PATCH] lib/test_bpf: Replace kmap() with kmap_local_page()

On lunedì 12 giugno 2023 12:33:41 CEST Sumitra Sharma wrote:
> kmap() has been deprecated in favor of the kmap_local_page()
> due to high cost, restricted mapping space, the overhead of
> a global lock for synchronization, and making the process
> sleep in the absence of free slots.
> 
> kmap_local_page() is faster than kmap() and offers thread-local
> and CPU-local mappings, take pagefaults in a local kmap region
> and preserves preemption by saving the mappings of outgoing
> tasks and restoring those of the incoming one during a context
> switch.
> 
> The mapping is kept thread local in the function
> “generate_test_data” in test_bpf.c
> 
> Therefore, replace kmap() with kmap_local_page() and use
> memcpy_to_page() to avoid open coding kmap_local_page()
> + memcpy() + kunmap_local().
> 
> Remove the unused variable “ptr”.

Sumitra,

Please Cc your mentors while in the internship.
It's not mandatory but it would expedite comments and reviews :-)

> 
> Signed-off-by: Sumitra Sharma <sumitraartsy@...il.com>
> ---
>  lib/test_bpf.c | 10 +---------
>  1 file changed, 1 insertion(+), 9 deletions(-)
> 
> diff --git a/lib/test_bpf.c b/lib/test_bpf.c
> index ade9ac672adb..3bb94727d83b 100644
> --- a/lib/test_bpf.c
> +++ b/lib/test_bpf.c
> @@ -14381,25 +14381,17 @@ static void *generate_test_data(struct bpf_test
> *test, int sub) * single fragment to the skb, filled with
>  		 * test->frag_data.
>  		 */
> -		void *ptr;
> -
>  		page = alloc_page(GFP_KERNEL);
> 
>  		if (!page)
>  			goto err_kfree_skb;
> 
> -		ptr = kmap(page);
> -		if (!ptr)
> -			goto err_free_page;
> -		memcpy(ptr, test->frag_data, MAX_DATA);
> -		kunmap(page);
> +		memcpy_to_page(page, 0, test->frag_data, MAX_DATA);

Why are you temporary mapping a page allocated with the GFP_KERNEL flag? 
It cannot come from ZONE_HIGHMEM. 

Fabio

>  		skb_add_rx_frag(skb, 0, page, 0, MAX_DATA, MAX_DATA);
>  	}
> 
>  	return skb;
> 
> -err_free_page:
> -	__free_page(page);
>  err_kfree_skb:
>  	kfree_skb(skb);
>  	return NULL;
> --
> 2.25.1



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ