From: "Björn Töpel" <bjorn@kernel.org>
To: Conor Dooley <conor@kernel.org>
Cc: "Paul Walmsley" <paul.walmsley@sifive.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Albert Ou" <aou@eecs.berkeley.edu>,
linux-riscv@lists.infradead.org,
"Christoph Muellner" <christoph.muellner@vrull.eu>,
"Heiko Stuebner" <heiko.stuebner@vrull.eu>,
"Björn Töpel" <bjorn@rivosinc.com>,
"Conor Dooley" <conor.dooley@microchip.com>,
"Guenter Roeck" <linux@roeck-us.net>,
"Andrew Jones" <ajones@ventanamicro.com>
Subject: Re: [PATCH] riscv, lib: Fix Zbb strncmp
Date: Tue, 28 Feb 2023 20:41:44 +0100 [thread overview]
Message-ID: <87k001fuh3.fsf@all.your.base.are.belong.to.us> (raw)
In-Reply-To: <Y/5SJc1AlfnY/l3l@spud>
Conor Dooley <conor@kernel.org> writes:
> On Tue, Feb 28, 2023 at 07:42:10PM +0100, Björn Töpel wrote:
>> From: Björn Töpel <bjorn@rivosinc.com>
>>
>> The Zbb optimized strncmp has two parts; a fast path that does XLEN/8B
>> per iteration, and a slow that does one byte per iteration.
>>
>> The idea is to compare aligned XLEN chunks for most of strings, and do
>> the remainder tail in the slow path.
>>
>> The Zbb strncmp has two issues in the fast path:
>>
>> Incorrect remainder handling (wrong compare): Assume that the string
>> length is 9. On 64b systems, the fast path should do one iteration,
>> and one iteration in the slow path. Instead, both were done in the
>> fast path, which lead to incorrect results. An example:
>>
>> strncmp("/dev/vda", "/dev/", 5);
>>
>> Correct by changing "bgt" to "bge".
>>
>> Missing NULL checks in the second string: This could lead to incorrect
>> results for:
>>
>> strncmp("/dev/vda", "/dev/vda\0", 8);
>>
>> Correct by adding an additional check.
>>
>> Fixes: b6fcdb191e36 ("RISC-V: add zbb support to string functions")
>> Suggested-by: Heiko Stuebner <heiko.stuebner@vrull.eu>
>> Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
>
> With your new selftest stuff & on a JH7110:
> Tested-by: Conor Dooley <conor.dooley@microchip.com>
> Also, given the reporter, this should be:
> Reported-by: Guenter Roeck <linux@roeck-us.net>
> no?
Indeed. Sorry, Guenter, for missing that!
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2023-02-28 19:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-28 18:42 [PATCH] riscv, lib: Fix Zbb strncmp Björn Töpel
2023-02-28 19:12 ` Conor Dooley
2023-02-28 19:41 ` Björn Töpel [this message]
2023-02-28 19:53 ` Guenter Roeck
2023-02-28 21:18 ` Guenter Roeck
2023-02-28 21:55 ` Palmer Dabbelt
2023-03-01 3:20 ` patchwork-bot+linux-riscv
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=87k001fuh3.fsf@all.your.base.are.belong.to.us \
--to=bjorn@kernel.org \
--cc=ajones@ventanamicro.com \
--cc=aou@eecs.berkeley.edu \
--cc=bjorn@rivosinc.com \
--cc=christoph.muellner@vrull.eu \
--cc=conor.dooley@microchip.com \
--cc=conor@kernel.org \
--cc=heiko.stuebner@vrull.eu \
--cc=linux-riscv@lists.infradead.org \
--cc=linux@roeck-us.net \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.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