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: <4f945f4a-ac29-3ef7-9e15-123962f2a0e9@huawei.com>
Date: Wed, 13 Mar 2024 19:29:41 +0800
From: Zhihao Cheng <chengzhihao1@...wei.com>
To: Arnd Bergmann <arnd@...nel.org>, Richard Weinberger <richard@....at>,
	Miquel Raynal <miquel.raynal@...tlin.com>, Vignesh Raghavendra
	<vigneshr@...com>, Daniel Golle <daniel@...rotopia.org>
CC: Arnd Bergmann <arnd@...db.de>, <linux-mtd@...ts.infradead.org>,
	<linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] mtd: ubi: avoid expensive do_div() on 32-bit machines

在 2024/3/13 16:46, Arnd Bergmann 写道:
> From: Arnd Bergmann <arnd@...db.de>
> 
> The use of do_div() in ubi_nvmem_reg_read() makes calling it on
> 32-bit machines rather expensive. Since the 'from' variable is
> known to be a 32-bit quantity, it is clearly never needed and
> can be optimized into a regular division operation.
> 
Do you meet a performance problem on a 32-bit machine? There are too 
many places invoking do_div, why do you optimize this one?
Have you tested the influence on a x86_64 platform after this patch 
applied? Looks like that do_div is more efficient in x86.

> Fixes: b8a77b9a5f9c ("mtd: ubi: fix NVMEM over UBI volumes on 32-bit systems")
> Fixes: 3ce485803da1 ("mtd: ubi: provide NVMEM layer over UBI volumes")
> Signed-off-by: Arnd Bergmann <arnd@...db.de>
> ---
>   drivers/mtd/ubi/nvmem.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/mtd/ubi/nvmem.c b/drivers/mtd/ubi/nvmem.c
> index 8aeb9c428e51..a94a1a9aaec1 100644
> --- a/drivers/mtd/ubi/nvmem.c
> +++ b/drivers/mtd/ubi/nvmem.c
> @@ -6,7 +6,6 @@
>   /* UBI NVMEM provider */
>   #include "ubi.h"
>   #include <linux/nvmem-provider.h>
> -#include <asm/div64.h>
>   
>   /* List of all NVMEM devices */
>   static LIST_HEAD(nvmem_devices);
> @@ -27,14 +26,15 @@ static int ubi_nvmem_reg_read(void *priv, unsigned int from,
>   	struct ubi_nvmem *unv = priv;
>   	struct ubi_volume_desc *desc;
>   	uint32_t offs;
> -	uint64_t lnum = from;
> +	uint32_t lnum;
>   	int err = 0;
>   
>   	desc = ubi_open_volume(unv->ubi_num, unv->vol_id, UBI_READONLY);
>   	if (IS_ERR(desc))
>   		return PTR_ERR(desc);
>   
> -	offs = do_div(lnum, unv->usable_leb_size);
> +	offs = from % unv->usable_leb_size;
> +	lnum = from / unv->usable_leb_size;
>   	while (bytes_left) {
>   		to_read = unv->usable_leb_size - offs;
>   
> 


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ