Skip to contentSkip to conversation

powerpc/spapr_hcall: Fix assembler constraints of the h_random h-call

PATCH Applied Thomas Huth 2 participants 2 messages Mar 3, 2016 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/spapr_hcall: Fix assembler constraints of the h_random h-call

As noted by Laurent Vivier, a register that is marked with "+r" as input and output is not required to be listed in the set of input registers anymore.
And as noted by David Gibson, the sPAPR hypercall is also allowed to clobber a bunch of other registers. According to the LoPAPR spec, r0 and r3-r12, CTR, XER and CC registers are volatile, so we should mark them in the clobber list.

---
 powerpc/spapr_hcall.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
powerpc/spapr_hcall.c +3 -1
index 46731e1..dbff630 100644
@@ -96,7 +96,9 @@ static int h_random(uint64_t *val)
 	register uint64_t r3 asm("r3") = H_RANDOM;
 	register uint64_t r4 asm("r4");
 
-	asm volatile (" sc 1 " : "+r"(r3), "=r"(r4) : "r"(r3));
+	asm volatile (" sc 1 "	: "+r"(r3), "=r"(r4) :
+				: "r0", "r5", "r6", "r7", "r8", "r9", "r10",
+				  "r11", "r12", "xer", "ctr", "cc");
 	*val = r4;
 
 	return r3;
Signature · 1 line
1.8.3.1
maintainer Applied
#1 lore raw
Quoted 19 lines · Thomas Huth

As noted by Laurent Vivier, a register that is marked with "+r" as input and output is not required to be listed in the set of input registers anymore.
And as noted by David Gibson, the sPAPR hypercall is also allowed to clobber a bunch of other registers. According to the LoPAPR spec, r0 and r3-r12, CTR, XER and CC registers are volatile, so we should mark them in the clobber list.

---
 powerpc/spapr_hcall.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
powerpc/spapr_hcall.c +0 -0
index 46731e1..dbff630 100644

powerpc/spapr_hcall.c static int h_random(uint64_t *val) · line 104

Quoted 10 lines
powerpc/spapr_hcall.c +3 -1
@@ -96,7 +96,9 @@ static int h_random(uint64_t *val)
 	register uint64_t r3 asm("r3") = H_RANDOM;
 	register uint64_t r4 asm("r4");
 
-	asm volatile (" sc 1 " : "+r"(r3), "=r"(r4) : "r"(r3));
+	asm volatile (" sc 1 "	: "+r"(r3), "=r"(r4) :
+				: "r0", "r5", "r6", "r7", "r8", "r9", "r10",
+				  "r11", "r12", "xer", "ctr", "cc");
 	*val = r4;
 
 	return r3;

Applied, thanks.

Paolo