* [ALPHA] Fix unaligned stxncpy again
@ 2004-04-09 10:32 Herbert Xu
2004-04-09 19:35 ` Ivan Kokshaysky
0 siblings, 1 reply; 4+ messages in thread
From: Herbert Xu @ 2004-04-09 10:32 UTC (permalink / raw)
To: Richard Henderson, Andrew Morton, Marcelo Tosatti,
Linus Torvalds, Linux Kernel Mailing List
[-- Attachment #1: Type: text/plain, Size: 659 bytes --]
Hi:
The current stxncpy on alpha is still broken when it comes to single
word, unaligned, src misalignment > dest misalignment copies.
I've attached a program which demonstrates this problem.
It looks like the code in glibc is correct and does not suffer from
the last problem that Richard fixed where the destination got
partially cleared.
So here is the patch to revert the unaligned case to use the same code
as glibc.
Cheers,
--
Debian GNU/Linux 3.0 is out! ( http://www.debian.org/ )
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
[-- Attachment #2: b.c --]
[-- Type: text/x-csrc, Size: 501 bytes --]
#include <string.h>
#include <stdio.h>
#include <strings.h>
#include <pwd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
char buf[64];
union {
unsigned long foo;
char salt[16];
} u;
int off;
memcpy(u.salt, "abcde\0../\0jjj", 16);
off = argc > 1 ? atoi(argv[1]) : 34;
printf("%d\n", off);
memset(buf, 1, 64);
__stxncpy(buf + off, u.salt + 6, 3);
buf[off + 3] = 0;
printf("%s\n", buf + off - 8);
return 0;
}
[-- Attachment #3: p --]
[-- Type: text/plain, Size: 1503 bytes --]
Index: arch/alpha/lib/stxncpy.S
===================================================================
RCS file: /home/gondolin/herbert/src/CVS/debian/kernel-source-2.4/arch/alpha/lib/stxncpy.S,v
retrieving revision 1.4
diff -u -r1.4 stxncpy.S
--- a/arch/alpha/lib/stxncpy.S 3 Sep 2003 10:26:49 -0000 1.4
+++ b/arch/alpha/lib/stxncpy.S 9 Apr 2004 10:23:30 -0000
@@ -313,9 +313,9 @@
lda t2, -1 # e0 : for creating masks later
beq t12, $u_head # .. e1 :
- extql t2, a1, t2 # e0 :
+ mskqh t2, t5, t2 # e0 : begin src validity mask
cmpbge zero, t1, t8 # .. e1 : is there a zero?
- andnot t2, t6, t12 # e0 : dest mask for a single word copy
+ extql t2, a1, t2 # e0 :
or t8, t10, t5 # .. e1 : test for end-of-count too
cmpbge zero, t2, t3 # e0 :
cmoveq a2, t5, t8 # .. e1 :
@@ -330,14 +330,14 @@
ldq_u t0, 0(a0) # e0 :
negq t8, t6 # .. e1 : build bitmask of bytes <= zero
mskqh t1, t4, t1 # e0 :
- and t6, t8, t2 # .. e1 :
- subq t2, 1, t6 # e0 :
- or t6, t2, t8 # e1 :
+ and t6, t8, t12 # .. e1 :
+ subq t12, 1, t6 # e0 :
+ or t6, t12, t8 # e1 :
- zapnot t12, t8, t12 # e0 : prepare source word; mirror changes
+ zapnot t2, t8, t2 # e0 : prepare source word; mirror changes
zapnot t1, t8, t1 # .. e1 : to source validity mask
- andnot t0, t12, t0 # e0 : zero place for source to reside
+ andnot t0, t2, t0 # e0 : zero place for source to reside
or t0, t1, t0 # e1 : and put it there
stq_u t0, 0(a0) # e0 :
ret (t9) # .. e1 :
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [ALPHA] Fix unaligned stxncpy again
2004-04-09 10:32 [ALPHA] Fix unaligned stxncpy again Herbert Xu
@ 2004-04-09 19:35 ` Ivan Kokshaysky
2004-04-09 23:50 ` Herbert Xu
0 siblings, 1 reply; 4+ messages in thread
From: Ivan Kokshaysky @ 2004-04-09 19:35 UTC (permalink / raw)
To: Herbert Xu
Cc: Richard Henderson, Andrew Morton, Marcelo Tosatti,
Linus Torvalds, Linux Kernel Mailing List
On Fri, Apr 09, 2004 at 08:32:44PM +1000, Herbert Xu wrote:
> The current stxncpy on alpha is still broken when it comes to single
> word, unaligned, src misalignment > dest misalignment copies.
>
> I've attached a program which demonstrates this problem.
Ugh, indeed. It fails when there is a zero byte before the data.
Thanks.
> So here is the patch to revert the unaligned case to use the same code
> as glibc.
Here is simpler equivalent of that and ev6 fix.
Ivan.
--- linux.orig/arch/alpha/lib/ev6-stxncpy.S Sun Apr 4 07:37:42 2004
+++ linux/arch/alpha/lib/ev6-stxncpy.S Fri Apr 9 22:13:40 2004
@@ -365,7 +365,7 @@ $unaligned:
andnot t2, t6, t12 # E : dest mask for a single word copy
or t8, t10, t5 # E : test for end-of-count too
- cmpbge zero, t2, t3 # E :
+ cmpbge zero, t12, t3 # E :
cmoveq a2, t5, t8 # E : Latency=2, extra map slot
nop # E : keep with cmoveq
andnot t8, t3, t8 # E : (stall)
--- linux.orig/arch/alpha/lib/stxncpy.S Sun Apr 4 07:38:22 2004
+++ linux/arch/alpha/lib/stxncpy.S Fri Apr 9 22:14:24 2004
@@ -317,7 +317,7 @@ $unaligned:
cmpbge zero, t1, t8 # .. e1 : is there a zero?
andnot t2, t6, t12 # e0 : dest mask for a single word copy
or t8, t10, t5 # .. e1 : test for end-of-count too
- cmpbge zero, t2, t3 # e0 :
+ cmpbge zero, t12, t3 # e0 :
cmoveq a2, t5, t8 # .. e1 :
andnot t8, t3, t8 # e0 :
beq t8, $u_head # .. e1 (zdb)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [ALPHA] Fix unaligned stxncpy again
2004-04-09 19:35 ` Ivan Kokshaysky
@ 2004-04-09 23:50 ` Herbert Xu
2004-04-10 17:46 ` Ivan Kokshaysky
0 siblings, 1 reply; 4+ messages in thread
From: Herbert Xu @ 2004-04-09 23:50 UTC (permalink / raw)
To: Ivan Kokshaysky
Cc: Richard Henderson, Andrew Morton, Marcelo Tosatti,
Linus Torvalds, Linux Kernel Mailing List
On Fri, Apr 09, 2004 at 11:35:11PM +0400, Ivan Kokshaysky wrote:
>
> Here is simpler equivalent of that and ev6 fix.
Thanks. But is there any reason why we need to have code that
is different from glibc?
--
Debian GNU/Linux 3.0 is out! ( http://www.debian.org/ )
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [ALPHA] Fix unaligned stxncpy again
2004-04-09 23:50 ` Herbert Xu
@ 2004-04-10 17:46 ` Ivan Kokshaysky
0 siblings, 0 replies; 4+ messages in thread
From: Ivan Kokshaysky @ 2004-04-10 17:46 UTC (permalink / raw)
To: Herbert Xu
Cc: Richard Henderson, Andrew Morton, Marcelo Tosatti,
Linus Torvalds, Linux Kernel Mailing List
On Sat, Apr 10, 2004 at 09:50:40AM +1000, Herbert Xu wrote:
> Thanks. But is there any reason why we need to have code that
> is different from glibc?
The code is different anyway because the glibc routine clobbers
t7 register which must not be touched in the kernel.
Apparently the whole mess started with a typo in the register
renaming patch...
Yes, ideally glibc and kernel stxncpy code can be exactly the same,
but this assumes that the glibc variant is updated to not use the t7.
Ivan.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-04-10 17:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-09 10:32 [ALPHA] Fix unaligned stxncpy again Herbert Xu
2004-04-09 19:35 ` Ivan Kokshaysky
2004-04-09 23:50 ` Herbert Xu
2004-04-10 17:46 ` Ivan Kokshaysky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®