Skip to contentSkip to conversation

Arm32: memset() & friends

PATCH Superseded Jan Beulich 4 participants 22 messages Aug 19, 2022 – Aug 25, 2022

lore
Share & tools
lore
#0 lore raw

cover Arm32: memset() & friends

Note that while the original Linux code has the same issue, I don't really fancy sending there a patch similar to patch 1. That's because my XSA-307 related "make find_next_{,zero_}bit() have well defined behavior" was entirely ignored, so I would expect nothing better here.

1: correct string.h functions for "int" -> "unsigned char" conversion 2: tidy the memset() macro

Really I happened to be looking at the memset() macro, being a little surprised of the special casing of 0 there. As a result I was curious to see how much more efficient __memzero() really was compared to memset(). The first thing which actually caught my attention is that part of __memzero()'s code lives outside of the function (i.e. ahead of ENTRY()). This saves a branch (and interestingly memset() does _not_ do the same), but (a) renders the ELF symbol table somewhat wrong and (b) leaves debug info generated with gas 2.39 not covering the entire function in the new subprogram DIE that it generates (line number info and .debug_ranges are correct nevertheless).

Jan

#1 lore raw

PATCH 1/2 Arm32: correct string.h functions for "int" -> "unsigned char" conversion

While Arm64 does so uniformly, for Arm32 only strchr() currently handles this properly. Add the necessary conversion also to strrchr(), memchr(), and memset().

As to the placement in memset(): Putting the new insn at the beginning of the function could perhaps be deemed more "obvious", but the code reachable without ever making it to the "1" label only ever does byte stores.

xen/arch/arm/arm32/lib/memchr.S +1 -0
@@ -14,6 +14,7 @@
 	.text
 	.align	5
 ENTRY(memchr)
+	and	r1, r1, #0xff
 1:	subs	r2, r2, #1
 	bmi	2f
 	ldrb	r3, [r0], #1
xen/arch/arm/arm32/lib/memset.S +2 -1
@@ -21,7 +21,8 @@ ENTRY(memset)
 /*
  * we know that the pointer in ip is aligned to a word boundary.
  */
-1:	orr	r1, r1, r1, lsl #8
+1:	and	r1, r1, #0xff
+	orr	r1, r1, r1, lsl #8
 	orr	r1, r1, r1, lsl #16
 	mov	r3, r1
 	cmp	r2, #16
xen/arch/arm/arm32/lib/strrchr.S +1 -0
@@ -14,6 +14,7 @@
 		.text
 		.align	5
 ENTRY(strrchr)
+		and	r1, r1, #0xff
 		mov	r3, #0
 1:		ldrb	r2, [r0], #1
 		teq	r2, r1
#2 lore raw

Re: [PATCH 1/2] Arm32: correct string.h functions for "int" -> "unsigned char" conversion

Hi Jan,

Quoted 8 lines · Jan Beulich

While Arm64 does so uniformly, for Arm32 only strchr() currently handles this properly. Add the necessary conversion also to strrchr(), memchr(), and memset().

As to the placement in memset(): Putting the new insn at the beginning of the function could perhaps be deemed more "obvious", but the code reachable without ever making it to the "1" label only ever does byte stores.

So the assumption here is the rest of the code will always use byte stores. Given that this issue has been present for a long time, I think it would be wiser to do the conversion at the start of the function.

The changes in memchr() and strrchr() looks fine to me.

Quoted 29 lines
xen/arch/arm/arm32/lib/memchr.S +1 -0
@@ -14,6 +14,7 @@
  	.text
  	.align	5
  ENTRY(memchr)
+	and	r1, r1, #0xff
  1:	subs	r2, r2, #1
  	bmi	2f
  	ldrb	r3, [r0], #1
xen/arch/arm/arm32/lib/memset.S +2 -1
@@ -21,7 +21,8 @@ ENTRY(memset)
 
   * we know that the pointer in ip is aligned to a word boundary.
   */
-1:	orr	r1, r1, r1, lsl #8
+1:	and	r1, r1, #0xff
+	orr	r1, r1, r1, lsl #8
  	orr	r1, r1, r1, lsl #16
  	mov	r3, r1
  	cmp	r2, #16

xen/arch/arm/arm32/lib/strrchr.S line 20

Quoted 7 lines
xen/arch/arm/arm32/lib/strrchr.S +1 -0
@@ -14,6 +14,7 @@
  		.text
  		.align	5
  ENTRY(strrchr)
+		and	r1, r1, #0xff
  		mov	r3, #0
  1:		ldrb	r2, [r0], #1
  		teq	r2, r1

Cheers,

Signature · 1 line
Julien Grall
#3 lore raw

PATCH 2/2 Arm32: tidy the memset() macro

In reply to Jan Beulich

- add parentheses where they were missing (MISRA)
- make sure to evaluate also v exactly once (MISRA)
- remove excess parentheses
- rename local variables to not have leading underscores
- apply Xen coding style

---
I wonder whether "if ( n_ )" is really helpful: It's extra code in all callers passing a non-constant size, just to cover a pretty rare case which memset() is required to deal with correctly anyway, and which __memzero() also handles quite fine from all I can tell.

xen/arch/arm/include/asm/string.h +13 -11
@@ -28,17 +28,19 @@
 
 void __memzero(void *ptr, size_t n);
 
-#define memset(p, v, n)                                                 \
-        ({                                                              \
-                void *__p = (p); size_t __n = n;                        \
-                if ((__n) != 0) {                                       \
-                        if (__builtin_constant_p((v)) && (v) == 0)      \
-                                __memzero((__p),(__n));                 \
-                        else                                            \
-                                memset((__p),(v),(__n));                \
-                }                                                       \
-                (__p);                                                  \
-        })
+#define memset(p, v, n)                                 \
+    ({                                                  \
+        void *p_ = (p); size_t n_ = (n);                \
+        typeof(v) v_ = (v);                             \
+        if ( n_ )                                       \
+        {                                               \
+            if ( __builtin_constant_p(v) && !v_ )       \
+                __memzero(p_, n_);                      \
+            else                                        \
+                memset(p_, v_, n_);                     \
+        }                                               \
+        p_;                                             \
+    })
 
 #endif
 
#4 lore raw

Re: [PATCH 2/2] Arm32: tidy the memset() macro

Hi Jan,

Quoted 5 lines · Jan Beulich

- add parentheses where they were missing (MISRA)
- make sure to evaluate also v exactly once (MISRA)
- remove excess parentheses
- rename local variables to not have leading underscores
- apply Xen coding style

This code has been taken from Linux. From you write above, I don't see any strong reason for us to modify it (even if it is small).

Cheers,

Signature · 1 line
Julien Grall
#5 lore raw

Re: [PATCH 2/2] Arm32: tidy the memset() macro

Quoted 9 lines · Julien Grall
Quoted 5 lines · Jan Beulich

- add parentheses where they were missing (MISRA)
- make sure to evaluate also v exactly once (MISRA)
- remove excess parentheses
- rename local variables to not have leading underscores
- apply Xen coding style

This code has been taken from Linux. From you write above, I don't see any strong reason for us to modify it (even if it is small).

At least the MISRA issues want addressing, I suppose. Plus I wasn't able to spot the macro in Linux anymore (nor __memzero()), so to me there seemed to be little point to consider keeping anything "in sync" here.

Jan

#6 lore raw

Re: [PATCH 2/2] Arm32: tidy the memset() macro

Hi Jan,

Quoted 8 lines · Jan Beulich
Quoted 7 lines · Julien Grall
Quoted 5 lines · Jan Beulich

- add parentheses where they were missing (MISRA)
- make sure to evaluate also v exactly once (MISRA)
- remove excess parentheses
- rename local variables to not have leading underscores
- apply Xen coding style

Quoted 7 lines
Quoted 2 lines

This code has been taken from Linux. From you write above, I don't see any strong reason for us to modify it (even if it is small).

At least the MISRA issues want addressing, I suppose. Plus I wasn't able to spot the macro in Linux anymore (nor __memzero()), so to me there seemed to be little point to consider keeping anything "in sync" here.

I read the last part as we want a re-sync of the code (we haven't done one in the past couple of years).

Cheers,

Signature · 1 line
Julien Grall
#7 lore raw

Re: [PATCH 2/2] Arm32: tidy the memset() macro

Quoted 12 lines · Julien Grall
Quoted 11 lines · Jan Beulich
Quoted 9 lines · Julien Grall
Quoted 5 lines · Jan Beulich

- add parentheses where they were missing (MISRA)
- make sure to evaluate also v exactly once (MISRA)
- remove excess parentheses
- rename local variables to not have leading underscores
- apply Xen coding style

This code has been taken from Linux. From you write above, I don't see any strong reason for us to modify it (even if it is small).

Quoted 6 lines
Quoted 4 lines

At least the MISRA issues want addressing, I suppose. Plus I wasn't able to spot the macro in Linux anymore (nor __memzero()), so to me there seemed to be little point to consider keeping anything "in sync" here.

I read the last part as we want a re-sync of the code (we haven't done one in the past couple of years).

I'm afraid I'm now really confused: Which last part? I don't see how any of what I have said could be read that way. Quite the opposite:
By stating that Linux doesn't have this macro anymore, isn't it quite clear that there's nothing to re-sync against?

Jan

#8 lore raw

Re: [PATCH 2/2] Arm32: tidy the memset() macro

Hi Jan,

Quoted 17 lines · Jan Beulich
Quoted 16 lines · Julien Grall
Quoted 15 lines · Jan Beulich
Quoted 9 lines · Julien Grall
Quoted 5 lines · Jan Beulich

- add parentheses where they were missing (MISRA)
- make sure to evaluate also v exactly once (MISRA)
- remove excess parentheses
- rename local variables to not have leading underscores
- apply Xen coding style

This code has been taken from Linux. From you write above, I don't see any strong reason for us to modify it (even if it is small).

At least the MISRA issues want addressing, I suppose. Plus I wasn't able to spot the macro in Linux anymore (nor __memzero()), so to me there seemed to be little point to consider keeping anything "in sync" here.

Quoted 7 lines
Quoted 2 lines

I read the last part as we want a re-sync of the code (we haven't done one in the past couple of years).

I'm afraid I'm now really confused: Which last part? I don't see how any of what I have said could be read that way. Quite the opposite:
By stating that Linux doesn't have this macro anymore, isn't it quite clear that there's nothing to re-sync against?

Your view here if we will never re-sync the code. This is incorrect, we still want to keep it close so we can benefit from improvement in the Linux code. So if you start tweaking the code just for coding style purpose, it will just make it more difficult for us (I appreciate this is limited here).

In this case, Linux has removed __memzero() is patch ff5fdafc9e97 "ARM: 8745/1: get rid of __memzero()" because the performance difference with memset() was limited. For Xen, I think we should also remove the function.

With that, this patch becomes pointless.

Cheers,

Signature · 1 line
Julien Grall
#9 lore raw

Re: [PATCH 2/2] Arm32: tidy the memset() macro

Quoted 31 lines · Julien Grall
Quoted 17 lines · Jan Beulich
Quoted 16 lines · Julien Grall
Quoted 15 lines · Jan Beulich
Quoted 9 lines · Julien Grall
Quoted 5 lines · Jan Beulich

- add parentheses where they were missing (MISRA)
- make sure to evaluate also v exactly once (MISRA)
- remove excess parentheses
- rename local variables to not have leading underscores
- apply Xen coding style

This code has been taken from Linux. From you write above, I don't see any strong reason for us to modify it (even if it is small).

At least the MISRA issues want addressing, I suppose. Plus I wasn't able to spot the macro in Linux anymore (nor __memzero()), so to me there seemed to be little point to consider keeping anything "in sync" here.

Quoted 7 lines
Quoted 2 lines

I read the last part as we want a re-sync of the code (we haven't done one in the past couple of years).

I'm afraid I'm now really confused: Which last part? I don't see how any of what I have said could be read that way. Quite the opposite:
By stating that Linux doesn't have this macro anymore, isn't it quite clear that there's nothing to re-sync against?

Your view here if we will never re-sync the code. This is incorrect, we still want to keep it close so we can benefit from improvement in the Linux code. So if you start tweaking the code just for coding style purpose, it will just make it more difficult for us (I appreciate this is limited here).

Quoted 5 lines

In this case, Linux has removed __memzero() is patch ff5fdafc9e97 "ARM:
8745/1: get rid of __memzero()" because the performance difference with memset() was limited. For Xen, I think we should also remove the function.

With that, this patch becomes pointless.

Of course. I could have named this as an alternative in a post-commit- message remark ... Looking forward to the re-syncing to be done then, at which point I'll happily drop this patch.

Jan

#10 lore raw

Re: [PATCH 2/2] Arm32: tidy the memset() macro

Hi Jan,

Quoted 36 lines · Jan Beulich
Quoted 35 lines · Julien Grall
Quoted 17 lines · Jan Beulich
Quoted 16 lines · Julien Grall
Quoted 15 lines · Jan Beulich
Quoted 9 lines · Julien Grall
Quoted 5 lines · Jan Beulich

- add parentheses where they were missing (MISRA)
- make sure to evaluate also v exactly once (MISRA)
- remove excess parentheses
- rename local variables to not have leading underscores
- apply Xen coding style

This code has been taken from Linux. From you write above, I don't see any strong reason for us to modify it (even if it is small).

At least the MISRA issues want addressing, I suppose. Plus I wasn't able to spot the macro in Linux anymore (nor __memzero()), so to me there seemed to be little point to consider keeping anything "in sync" here.

Quoted 7 lines
Quoted 2 lines

I read the last part as we want a re-sync of the code (we haven't done one in the past couple of years).

I'm afraid I'm now really confused: Which last part? I don't see how any of what I have said could be read that way. Quite the opposite:
By stating that Linux doesn't have this macro anymore, isn't it quite clear that there's nothing to re-sync against?

Your view here if we will never re-sync the code. This is incorrect, we still want to keep it close so we can benefit from improvement in the Linux code. So if you start tweaking the code just for coding style purpose, it will just make it more difficult for us (I appreciate this is limited here).

In this case, Linux has removed __memzero() is patch ff5fdafc9e97 "ARM:
8745/1: get rid of __memzero()" because the performance difference with memset() was limited. For Xen, I think we should also remove the function.

Quoted 5 lines
Quoted 1 line

With that, this patch becomes pointless.

Of course. I could have named this as an alternative in a post-commit- message remark ... Looking forward to the re-syncing to be done then, at which point I'll happily drop this patch.

I will add it in my queue. I don't think this will reach 4.17 (unless someone else has time).

Cheers,

Signature · 1 line
Julien Grall
#11 lore raw

RE: [PATCH 2/2] Arm32: tidy the memset() macro

In reply to Jan Beulich

Hi Jan,

Quoted 16 lines

-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Jan Beulich
Sent: 2022年8月19日 15:50
To: [email protected]
Cc: Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Volodymyr Babchuk <[email protected]>; Bertrand Marquis <[email protected]>
Subject: [PATCH 2/2] Arm32: tidy the memset() macro

- add parentheses where they were missing (MISRA)
- make sure to evaluate also v exactly once (MISRA)
- remove excess parentheses
- rename local variables to not have leading underscores
- apply Xen coding style

Quoted 5 lines

---
I wonder whether "if ( n_ )" is really helpful: It's extra code in all callers passing a non-constant size, just to cover a pretty rare case which memset() is required to deal with correctly anyway, and which

What rare case we need to use n_ that can make memset happy? As your comment, I read the code again, but it seems to work fine without n_.

Cheers,
Wei Chen

Quoted 36 lines

__memzero() also handles quite fine from all I can tell.

xen/arch/arm/include/asm/string.h +13 -11
@@ -28,17 +28,19 @@
 
 void __memzero(void *ptr, size_t n);
 
-#define memset(p, v, n)                                                 \
-        ({                                                              \
-                void *__p = (p); size_t __n = n;                        \
-                if ((__n) != 0) {                                       \
-                        if (__builtin_constant_p((v)) && (v) == 0)      \
-                                __memzero((__p),(__n));                 \
-                        else                                            \
-                                memset((__p),(v),(__n));                \
-                }                                                       \
-                (__p);                                                  \
-        })
+#define memset(p, v, n)                                 \
+    ({                                                  \
+        void *p_ = (p); size_t n_ = (n);                \
+        typeof(v) v_ = (v);                             \
+        if ( n_ )                                       \
+        {                                               \
+            if ( __builtin_constant_p(v) && !v_ )       \
+                __memzero(p_, n_);                      \
+            else                                        \
+                memset(p_, v_, n_);                     \
+        }                                               \
+        p_;                                             \
+    })
 
 #endif
 
#12 lore raw

Re: [PATCH 2/2] Arm32: tidy the memset() macro

Quoted 11 lines · Wei Chen
Quoted 11 lines

-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Jan Beulich
Sent: 2022年8月19日 15:50

- add parentheses where they were missing (MISRA)
- make sure to evaluate also v exactly once (MISRA)
- remove excess parentheses
- rename local variables to not have leading underscores
- apply Xen coding style

Quoted 7 lines
Quoted 5 lines

---
I wonder whether "if ( n_ )" is really helpful: It's extra code in all callers passing a non-constant size, just to cover a pretty rare case which memset() is required to deal with correctly anyway, and which

What rare case we need to use n_ that can make memset happy?

I'm afraid I don't understand the question.

Jan

Quoted 5 lines

As your
comment, I read the code again, but it seems to work fine without n_.

Cheers,
Wei Chen

#13 lore raw

RE: [PATCH 2/2] Arm32: tidy the memset() macro

Hi Jan,

Quoted 29 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 2022年8月19日 16:04
To: Wei Chen <[email protected]>
Cc: Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Volodymyr Babchuk <[email protected]>; Bertrand Marquis <[email protected]>; xen- [email protected]
Subject: Re: [PATCH 2/2] Arm32: tidy the memset() macro

Quoted 2 lines · Wei Chen
Quoted 2 lines

-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of

Jan

Quoted 15 lines
Quoted 14 lines

Beulich
Sent: 2022年8月19日 15:50

- add parentheses where they were missing (MISRA)
- make sure to evaluate also v exactly once (MISRA)
- remove excess parentheses
- rename local variables to not have leading underscores
- apply Xen coding style

---
I wonder whether "if ( n_ )" is really helpful: It's extra code in all callers passing a non-constant size, just to cover a pretty rare case which memset() is required to deal with correctly anyway, and which

Quoted 4 lines
Quoted 1 line

What rare case we need to use n_ that can make memset happy?

I'm afraid I don't understand the question.

Sorry I didn't describe the problem clearly in the last email. You mentioned whether if (n_) is useful in your patch comments. I looked at the implementation of the current memset macro, and I didn't feel it was too useful.

Then in the comments you mentioned that if (n_) is just to cover a very rare case. Does the rare case is memset(p, v, 0)? If this is the case, I agree with you, memset itself should be able to handle with size=0.

Sorry again for confusing you!

Thanks,
Wei Chen

Quoted 7 lines

Jan

Quoted 5 lines

As your
comment, I read the code again, but it seems to work fine without n_.

Cheers,
Wei Chen

#14 lore raw

Re: [PATCH 2/2] Arm32: tidy the memset() macro

Quoted 36 lines · Wei Chen

Hi Jan,

Quoted 29 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 2022年8月19日 16:04
To: Wei Chen <[email protected]>
Cc: Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Volodymyr Babchuk <[email protected]>; Bertrand Marquis <[email protected]>; xen- [email protected]
Subject: Re: [PATCH 2/2] Arm32: tidy the memset() macro

Quoted 2 lines · Wei Chen
Quoted 2 lines

-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of

Jan

Quoted 15 lines
Quoted 14 lines

Beulich
Sent: 2022年8月19日 15:50

- add parentheses where they were missing (MISRA)
- make sure to evaluate also v exactly once (MISRA)
- remove excess parentheses
- rename local variables to not have leading underscores
- apply Xen coding style

---
I wonder whether "if ( n_ )" is really helpful: It's extra code in all callers passing a non-constant size, just to cover a pretty rare case which memset() is required to deal with correctly anyway, and which

Quoted 4 lines
Quoted 1 line

What rare case we need to use n_ that can make memset happy?

I'm afraid I don't understand the question.

Quoted 6 lines

Sorry I didn't describe the problem clearly in the last email. You mentioned whether if (n_) is useful in your patch comments. I looked at the implementation of the current memset macro, and I didn't feel it was too useful.

Then in the comments you mentioned that if (n_) is just to cover a very rare case. Does the rare case is memset(p, v, 0)?

Yes, albeit not in the form you've written it, but with the last argument being a variable which happens to be zero. With literal zero, the compiler would dead-code eliminate the construct anyway.

Jan

Quoted 7 lines

If this is the case, I agree with you, memset itself should be able to handle with size=0.

Sorry again for confusing you!

Thanks,
Wei Chen

#15 lore raw
In reply to Jan Beulich
Quoted 4 lines · Jan Beulich

Note that while the original Linux code has the same issue, I don't really fancy sending there a patch similar to patch 1. That's because my XSA-307 related "make find_next_{,zero_}bit() have well defined behavior" was entirely ignored, so I would expect nothing better here.

Would you be able to point me to the discussion?

Cheers,

Signature · 1 line
Julien Grall
#16 lore raw
Quoted 7 lines · Julien Grall
Quoted 4 lines · Jan Beulich

Note that while the original Linux code has the same issue, I don't really fancy sending there a patch similar to patch 1. That's because my XSA-307 related "make find_next_{,zero_}bit() have well defined behavior" was entirely ignored, so I would expect nothing better here.

Would you be able to point me to the discussion?

Hmm, I can't spot it on
https://patchwork.kernel.org/project/linux-arm-kernel/list/ , but then again there are only very few entries there anyway which pre- date July 2022. I've been able to easily spot it at
https://lore.kernel.org/linux-arm-kernel/[email protected]/

Jan

#17 lore raw

PATCH v2 1/1 Arm32: correct string.h functions for "int" -> "unsigned char" conversion

In reply to Jan Beulich

While Arm64 does so uniformly, for Arm32 only strchr() currently handles this properly. Add the necessary conversion also to strrchr(), memchr(), and memset().

As to the placement in memset(): Putting the new insn at the beginning of the function is apparently deemed more "obvious". It could be placed later, as the code reachable without ever making it to the "1" label only ever does byte stores.

---
v2: For memset() use the "more obvious" adjustment.

xen/arch/arm/arm32/lib/memchr.S +1 -0
@@ -14,6 +14,7 @@
 	.text
 	.align	5
 ENTRY(memchr)
+	and	r1, r1, #0xff
 1:	subs	r2, r2, #1
 	bmi	2f
 	ldrb	r3, [r0], #1
xen/arch/arm/arm32/lib/memset.S +1 -0
@@ -15,6 +15,7 @@
 	.align	5
 
 ENTRY(memset)
+	and	r1, r1, #0xff
 	ands	r3, r0, #3		@ 1 unaligned?
 	mov	ip, r0			@ preserve r0 as return value
 	bne	6f			@ 1
xen/arch/arm/arm32/lib/strrchr.S +1 -0
@@ -14,6 +14,7 @@
 		.text
 		.align	5
 ENTRY(strrchr)
+		and	r1, r1, #0xff
 		mov	r3, #0
 1:		ldrb	r2, [r0], #1
 		teq	r2, r1
Reviewed-by on v2 1/1
#18 lore raw

Re: [PATCH v2] Arm32: correct string.h functions for "int" -> "unsigned char" conversion

Hi Jan,

Quoted 6 lines · Jan Beulich

While Arm64 does so uniformly, for Arm32 only strchr() currently handles this properly. Add the necessary conversion also to strrchr(), memchr(), and memset().

Quoted 6 lines

As to the placement in memset(): Putting the new insn at the beginning of the function is apparently deemed more "obvious". It could be placed later, as the code reachable without ever making it to the "1" label only ever does byte stores.

Cheers
Bertrand

Quoted 33 lines

---
v2: For memset() use the "more obvious" adjustment.

xen/arch/arm/arm32/lib/memchr.S +1 -0
@@ -14,6 +14,7 @@
 	.text
 	.align	5
 ENTRY(memchr)
+	and	r1, r1, #0xff

1: subs r2, r2, #1

	bmi	2f
	ldrb	r3, [r0], #1
xen/arch/arm/arm32/lib/memset.S +1 -0
@@ -15,6 +15,7 @@
 	.align	5
 
 ENTRY(memset)
+	and	r1, r1, #0xff
 	ands	r3, r0, #3		@ 1 unaligned?
 	mov	ip, r0			@ preserve r0 as return value
 	bne	6f			@ 1
xen/arch/arm/arm32/lib/strrchr.S +1 -0
@@ -14,6 +14,7 @@
 		.text
 		.align	5
 ENTRY(strrchr)
+		and	r1, r1, #0xff
 		mov	r3, #0

1: ldrb r2, [r0], #1

		teq	r2, r1
#19 lore raw

Re: [PATCH v2] Arm32: correct string.h functions for "int" -> "unsigned char" conversion

Quoted 6 lines · Bertrand Marquis
Quoted 6 lines · Jan Beulich

While Arm64 does so uniformly, for Arm32 only strchr() currently handles this properly. Add the necessary conversion also to strrchr(), memchr(), and memset().

Quoted 7 lines
Quoted 6 lines

As to the placement in memset(): Putting the new insn at the beginning of the function is apparently deemed more "obvious". It could be placed later, as the code reachable without ever making it to the "1" label only ever does byte stores.

It is now committed.

Cheers,

Signature · 1 line
Julien Grall
#20 lore raw

Re: [PATCH v2] Arm32: correct string.h functions for "int" -> "unsigned char" conversion

Quoted 12 lines · Julien Grall
Quoted 11 lines · Bertrand Marquis
Quoted 11 lines · Jan Beulich

While Arm64 does so uniformly, for Arm32 only strchr() currently handles this properly. Add the necessary conversion also to strrchr(), memchr(), and memset().

As to the placement in memset(): Putting the new insn at the beginning of the function is apparently deemed more "obvious". It could be placed later, as the code reachable without ever making it to the "1" label only ever does byte stores.

Quoted 4 lines
Quoted 2 lines
Quoted 1 line

It is now committed.

But then perhaps not pushed yet?

Jan

#21 lore raw

Re: [PATCH v2] Arm32: correct string.h functions for "int" -> "unsigned char" conversion

Hi Jan,

Quoted 13 lines · Jan Beulich
Quoted 12 lines · Julien Grall
Quoted 11 lines · Bertrand Marquis
Quoted 11 lines · Jan Beulich

While Arm64 does so uniformly, for Arm32 only strchr() currently handles this properly. Add the necessary conversion also to strrchr(), memchr(), and memset().

As to the placement in memset(): Putting the new insn at the beginning of the function is apparently deemed more "obvious". It could be placed later, as the code reachable without ever making it to the "1" label only ever does byte stores.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line

It is now committed.

But then perhaps not pushed yet?

Yes. I tend to send the message just after I apply it. I will push when I am done with a batch (in this case, this is the only patch I pushed).

Cheers,

Signature · 1 line
Julien Grall