BOOKE KVM calling load_up_fpu from C?
Scott,
I was looking at changing how load_up_fpu works and I found this in arch/powerpc/kvm/booke.h:
static inline void kvmppc_load_guest_fp(struct kvm_vcpu *vcpu) {
#ifdef CONFIG_PPC_FPU
if (vcpu->fpu_active && !(current->thread.regs->msr & MSR_FP)) {
load_up_fpu();
current->thread.regs->msr |= MSR_FP;
}#endif
}
I'm wondering how this is suppose to work since load_up_fpu is suppose to have MSR in R12?
Mikey
Quoted 5 lines
-----Original Message-----
From: Linuxppc-dev [mailto:linuxppc-dev- [email protected]] On Behalf Of Mic=
hael
Quoted 13 lines
Neuling
Sent: Tuesday, February 12, 2013 8:59 AM
To: Wood Scott-B07421
Cc: [email protected]
Subject: BOOKE KVM callingload_up_fpufrom C?
=20
Scott,
=20
I was looking at changing howload_up_fpuworks and I found this inarch/powerpc/kvm/booke.h:
=20
static inline voidkvmppc_load_guest_fp(struct kvm_vcpu *vcpu){ #ifdefCONFIG_PPC_FPU
Quoted 8 lines
if (vcpu->fpu_active && !(current->thread.regs->msr & MSR_FP)) { load_up_fpu(); current->thread.regs->msr |=3D MSR_FP; }#endif
}
=20
I'm wondering how this is suppose to work sinceload_up_fpuis suppose to=
have
Quoted 1 line
MSR in R12?
Is not the load_up_fpu() does mfmsr:
_GLOBAL(load_up_fpu)
mfmsr r5
ori r5,r5,MSR_FP
#ifdef CONFIG_VSXBEGIN_FTR_SECTION
oris r5,r5,MSR_VSX@h
END_FTR_SECTION_IFSET(CPU_FTR_VSX)
#endif
SYNC
MTMSRD(r5) /* enable use of fpu now */
isync
<snip>
-Bharat
Quoted 6 lines
=20
Mikey
_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev
Quoted 35 lines · Bhushan Bharat-R65777 <[email protected]> wrote:
Quoted 22 lines
-----Original Message-----
From: Linuxppc-dev [mailto:linuxppc-dev- [email protected]] On Behalf Of Michael Neuling
Sent: Tuesday, February 12, 2013 8:59 AM
To: Wood Scott-B07421
Cc: [email protected]
Subject: BOOKE KVM callingload_up_fpufrom C?Scott,
I was looking at changing how
load_up_fpuworks and I found this inarch/powerpc/kvm/booke.h:static inline void
kvmppc_load_guest_fp(struct kvm_vcpu *vcpu){ #ifdefCONFIG_PPC_FPUif (vcpu->fpu_active && !(current->thread.regs->msr & MSR_FP)) { load_up_fpu(); current->thread.regs->msr |= MSR_FP; }Quoted 5 lines
#endif
}I'm wondering how this is suppose to work since
load_up_fpuis suppose to have MSR in R12?Is not the
load_up_fpu()does mfmsr:
_GLOBAL(load_up_fpu)
mfmsr r5
ori r5,r5,MSR_FP
#ifdefCONFIG_VSXBEGIN_FTR_SECTION
Quoted 7 lines
oris r5,r5,MSR_VSX@h
END_FTR_SECTION_IFSET(CPU_FTR_VSX)
#endif
SYNC
MTMSRD(r5) /* enable use of fpu now */
isync
<snip>
Look further down...
#ifdef CONFIG_PPC32 mfspr r5,SPRN_SPRG_THREAD /* current task's THREAD (phys) */ lwz r4,THREAD_FPEXC_MODE(r5) ori r9,r9,MSR_FP /* enable FP for current */ or r9,r9,r4 #else ld r4,PACACURRENT(r13) addi r5,r4,THREAD /* Get THREAD */ lwz r4,THREAD_FPEXC_MODE(r5) ori r12,r12,MSR_FP or r12,r12,r4 std r12,_MSR(r1)
#endif
R12 is loaded with SRR1 in the exception prolog before load_up_fpu is called. It's the MSR of the user process, not the current MSR.
Mikey
Quoted 69 lines
-----Original Message-----
From: Michael Neuling [mailto:[email protected]]
Sent: Tuesday, February 12, 2013 9:16 AM
To: Bhushan Bharat-R65777
Cc: Wood Scott-B07421; [email protected]
Subject: Re: BOOKE KVM callingload_up_fpufrom C? =20
Bhushan Bharat-R65777 <[email protected]> wrote:
=20Quoted 36 lines
Quoted 23 lines
-----Original Message-----
From: Linuxppc-dev [mailto:linuxppc-dev- [email protected]] On Behalf Of bounces+Michael
Neuling
Sent: Tuesday, February 12, 2013 8:59 AM
To: Wood Scott-B07421
Cc: [email protected]
Subject: BOOKE KVM callingload_up_fpufrom C?Scott,
I was looking at changing how
load_up_fpuworks and I found this inarch/powerpc/kvm/booke.h:static inline void
kvmppc_load_guest_fp(struct kvm_vcpu *vcpu){#ifdef CONFIG_PPC_FPU if (vcpu->fpu_active && !(current->thread.regs->msr & MSR_FP)) { load_up_fpu(); current->thread.regs->msr |=3D MSR_FP; }Quoted 5 lines
#endif
}I'm wondering how this is suppose to work since
load_up_fpuis suppose to have MSR in R12?Is not the
load_up_fpu()does mfmsr:
_GLOBAL(load_up_fpu)
mfmsr r5
ori r5,r5,MSR_FP
#ifdefCONFIG_VSXBEGIN_FTR_SECTIONQuoted 7 lines
oris r5,r5,MSR_VSX@h
END_FTR_SECTION_IFSET(CPU_FTR_VSX)
#endif
SYNC
MTMSRD(r5) /* enable use of fpu now */
isync
<snip>=20
Look further down...
=20#ifdef CONFIG_PPC32 mfspr r5,SPRN_SPRG_THREAD /* current task's THREAD (phys) */ lwz r4,THREAD_FPEXC_MODE(r5) ori r9,r9,MSR_FP /* enable FP for current */ or r9,r9,r4 #else ld r4,PACACURRENT(r13) addi r5,r4,THREAD /* Get THREAD */ lwz r4,THREAD_FPEXC_MODE(r5) ori r12,r12,MSR_FP or r12,r12,r4 std r12,_MSR(r1)
Quoted 3 lines
#endif
=20
R12 is loaded with SRR1 in the exception prolog beforeload_up_fpuis cal=
led.
Yes it is SRR1 not MSR.
Also on 32bit it looks like that R9 is assumed to have SRR1.
-Bharat
Quoted 3 lines
It's the MSR of the user process, not the current MSR. =20
Mikey
Quoted 71 lines · Bhushan Bharat-R65777 <[email protected]> wrote:
Quoted 71 lines
-----Original Message-----
From: Michael Neuling [mailto:[email protected]]
Sent: Tuesday, February 12, 2013 9:16 AM
To: Bhushan Bharat-R65777
Cc: Wood Scott-B07421; [email protected]
Subject: Re: BOOKE KVM callingload_up_fpufrom C?Quoted 36 lines · Bhushan Bharat-R65777 <[email protected]> wrote:
Quoted 23 lines
-----Original Message-----
From: Linuxppc-dev [mailto:linuxppc-dev- [email protected]] On Behalf Of bounces+Michael
Neuling
Sent: Tuesday, February 12, 2013 8:59 AM
To: Wood Scott-B07421
Cc: [email protected]
Subject: BOOKE KVM callingload_up_fpufrom C?Scott,
I was looking at changing how
load_up_fpuworks and I found this inarch/powerpc/kvm/booke.h:static inline void
kvmppc_load_guest_fp(struct kvm_vcpu *vcpu){#ifdef CONFIG_PPC_FPU if (vcpu->fpu_active && !(current->thread.regs->msr & MSR_FP)) { load_up_fpu(); current->thread.regs->msr |= MSR_FP; }Quoted 5 lines
#endif
}I'm wondering how this is suppose to work since
load_up_fpuis suppose to have MSR in R12?Is not the
load_up_fpu()does mfmsr:
_GLOBAL(load_up_fpu)
mfmsr r5
ori r5,r5,MSR_FP
#ifdefCONFIG_VSXBEGIN_FTR_SECTIONQuoted 7 lines
oris r5,r5,MSR_VSX@h
END_FTR_SECTION_IFSET(CPU_FTR_VSX)
#endif
SYNC
MTMSRD(r5) /* enable use of fpu now */
isync
<snip>Look further down...
#ifdef CONFIG_PPC32 mfspr r5,SPRN_SPRG_THREAD /* current task's THREAD (phys) */ lwz r4,THREAD_FPEXC_MODE(r5) ori r9,r9,MSR_FP /* enable FP for current */ or r9,r9,r4 #else ld r4,PACACURRENT(r13) addi r5,r4,THREAD /* Get THREAD */ lwz r4,THREAD_FPEXC_MODE(r5) ori r12,r12,MSR_FP or r12,r12,r4 std r12,_MSR(r1)#endif
Quoted 3 lines
Quoted 1 line
R12 is loaded with SRR1 in the exception prolog before
load_up_fpuis called.Yes it is SRR1 not MSR.
Yes, SRR1 == the MSR of the user process, not the current MSR.
Quoted 1 line
Also on 32bit it looks like that R9 is assumed to have SRR1.
Yep that too.
So any idea how it's suppose to work or is it broken?
Mikey
Quoted 27 lines
-----Original Message-----
From: Michael Neuling [mailto:[email protected]]
Sent: Tuesday, February 12, 2013 9:46 AM
To: Bhushan Bharat-R65777
Cc: Wood Scott-B07421; [email protected]
Subject: Re: BOOKE KVM callingload_up_fpufrom C? =20
Bhushan Bharat-R65777 <[email protected]> wrote:
=20Quoted 16 lines
Quoted 16 lines
-----Original Message-----
From: Michael Neuling [mailto:[email protected]]
Sent: Tuesday, February 12, 2013 9:16 AM
To: Bhushan Bharat-R65777
Cc: Wood Scott-B07421; [email protected]
Subject: Re: BOOKE KVM callingload_up_fpufrom C?Quoted 5 lines · Bhushan Bharat-R65777 <[email protected]> wrote:
Quoted 5 lines
-----Original Message-----
From: Linuxppc-dev [mailto:linuxppc-dev- [email protected]] On Behal=
f
Quoted 60 lines
Quoted 56 lines
Quoted 56 lines
Quoted 32 lines
Quoted 19 lines
bounces+Of Michael
Neuling
Sent: Tuesday, February 12, 2013 8:59 AM
To: Wood Scott-B07421
Cc: [email protected]
Subject: BOOKE KVM callingload_up_fpufrom C?Scott,
I was looking at changing how
load_up_fpuworks and I found this inarch/powerpc/kvm/booke.h:static inline void
kvmppc_load_guest_fp(struct kvm_vcpu *vcpu){#ifdef CONFIG_PPC_FPU if (vcpu->fpu_active && !(current->thread.regs->msr & MSR_FP)) { load_up_fpu(); current->thread.regs->msr |=3D MSR_FP; }Quoted 5 lines
#endif
}I'm wondering how this is suppose to work since
load_up_fpuis suppose to have MSR in R12?Is not the
load_up_fpu()does mfmsr:
_GLOBAL(load_up_fpu)
mfmsr r5
ori r5,r5,MSR_FP
#ifdefCONFIG_VSXBEGIN_FTR_SECTIONQuoted 7 lines
oris r5,r5,MSR_VSX@h
END_FTR_SECTION_IFSET(CPU_FTR_VSX)
#endif
SYNC
MTMSRD(r5) /* enable use of fpu now */
isync
<snip>Look further down...
#ifdef CONFIG_PPC32 mfspr r5,SPRN_SPRG_THREAD /* current task's THREAD (phys) */ lwz r4,THREAD_FPEXC_MODE(r5) ori r9,r9,MSR_FP /* enable FP for current */ or r9,r9,r4 #else ld r4,PACACURRENT(r13) addi r5,r4,THREAD /* Get THREAD */ lwz r4,THREAD_FPEXC_MODE(r5) ori r12,r12,MSR_FP or r12,r12,r4 std r12,_MSR(r1)#endif
Quoted 1 line
Quoted 1 line
R12 is loaded with SRR1 in the exception prolog before
load_up_fpuiscalled.
Quoted 2 lines
Yes it is SRR1 not MSR.
Quoted 8 lines
=20
Yes, SRR1 =3D=3D the MSR of the user process, not the current MSR. =20Quoted 1 line
Also on 32bit it looks like that R9 is assumed to have SRR1.
=20
Yep that too.
=20
So any idea how it's suppose to work or is it broken?
To me this looks wrong. And this seems to works because the thread->reg->ms= r is not actually used to write SRR1 (and eventually the thread MSR) when d= oing rfi to enter guest. Infact Guest(shadow_msr) MSR is used as SRR1 and w= hich will have proper MSR (including FP set).
But Yes, Scott is right person to comment, So let us wait for him comment.
Thanks
-Bharat
Quoted 51 lines · On 02/12/2013 03:01:07 AM, Bhushan Bharat-R65777 wrote:
=20
=20Quoted 7 lines
-----Original Message-----
From: Michael Neuling [mailto:[email protected]]
Sent: Tuesday, February 12, 2013 9:46 AM
To: Bhushan Bharat-R65777
Cc: Wood Scott-B07421; [email protected]
Subject: Re: BOOKE KVM callingload_up_fpufrom C?Quoted 15 lines
Quoted 13 lines · Bhushan Bharat-R65777 <[email protected]> wrote:
Quoted 13 lines
-----Original Message-----
From: Michael Neuling [mailto:[email protected]]
Sent: Tuesday, February 12, 2013 9:16 AM
To: Bhushan Bharat-R65777
Cc: Wood Scott-B07421; [email protected]
Subject: Re: BOOKE KVM callingload_up_fpufrom C?Look further down...
#ifdef CONFIG_PPC32 mfspr r5,SPRN_SPRG_THREAD /* current =20task's THREAD (phys) */
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
lwz r4,THREAD_FPEXC_MODE(r5) ori r9,r9,MSR_FP /* enable FP for =20current */
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
or r9,r9,r4 #else ld r4,PACACURRENT(r13) addi r5,r4,THREAD /* Get THREAD */ lwz r4,THREAD_FPEXC_MODE(r5) ori r12,r12,MSR_FP or r12,r12,r4 std r12,_MSR(r1)#endif
R12 is loaded with SRR1 in the exception prolog before =20
load_up_fpuisQuoted 11 lines
called.
Quoted 2 lines
Yes it is SRR1 not MSR.
Yes, SRR1 =3D=3D the MSR of the user process, not the current MSR.
Quoted 1 line
Also on 32bit it looks like that R9 is assumed to have SRR1.
Yep that too.
So any idea how it's suppose to work or is it broken?
Quoted 9 lines
=20
To me this looks wrong. And this seems to works because the =20thread->reg->msris not actually used to write SRR1 (and eventually =20 the thread MSR) when doing rfi to enter guest. Infact =20Guest(shadow_msr)MSR is used as SRR1 and which will have proper MSR =20 (including FP set).
=20
But Yes, Scott is right person to comment, So let us wait for him =20 comment.
I don't think it's actually a problem on 32-bit, since r9 is modified =20 but never actually used for anything. On 64-bit, though, there's a =20 store to the caller's stack frame (yuck) which the kvm/booke.h caller =20 is not prepared for. Indeed, book3s's kvmppc_load_up_fpu creates an =20 interrupt-like stack frame, but does not load r9 or r12.
It would be really nice if assumptions like these were put in a code =20 comment above load_up_fpu... and if we didn't have so many random =20 differences between 32-bit and 64-bit. :-P
-Scott=
Quoted 59 lines · Scott Wood
Quoted 58 lines · On 02/12/2013 03:01:07 AM, Bhushan Bharat-R65777 wrote:
Quoted 24 lines
-----Original Message-----
From: Michael Neuling [mailto:[email protected]]
Sent: Tuesday, February 12, 2013 9:46 AM
To: Bhushan Bharat-R65777
Cc: Wood Scott-B07421; [email protected]
Subject: Re: BOOKE KVM callingload_up_fpufrom C?Quoted 13 lines · Bhushan Bharat-R65777 <[email protected]> wrote:
Quoted 13 lines
-----Original Message-----
From: Michael Neuling [mailto:[email protected]]
Sent: Tuesday, February 12, 2013 9:16 AM
To: Bhushan Bharat-R65777
Cc: Wood Scott-B07421; [email protected]
Subject: Re: BOOKE KVM callingload_up_fpufrom C?Look further down...
#ifdef
CONFIG_PPC32
mfspr r5,SPRN_SPRG_THREAD /* currenttask's THREAD (phys) */
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
lwz r4,THREAD_FPEXC_MODE(r5) ori r9,r9,MSR_FP /* enable FP forcurrent */
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
or r9,r9,r4 #else ld r4,PACACURRENT(r13) addi r5,r4,THREAD /* Get THREAD */ lwz r4,THREAD_FPEXC_MODE(r5) ori r12,r12,MSR_FP or r12,r12,r4 std r12,_MSR(r1)#endif
R12 is loaded with SRR1 in the exception prolog before
load_up_fpuisQuoted 11 lines
called.
Quoted 2 lines
Yes it is SRR1 not MSR.
Yes, SRR1 == the MSR of the user process, not the current MSR.
Quoted 1 line
Also on 32bit it looks like that R9 is assumed to have SRR1.
Yep that too.
So any idea how it's suppose to work or is it broken?
To me this looks wrong. And this seems to works because the
thread->reg->msris not actually used to write SRR1 (and eventually the thread MSR) when doing rfi to enter guest. InfactGuest(shadow_msr)MSR is used as SRR1 and which will have proper MSR (including FP set).
Quoted 8 lines
Quoted 2 lines
But Yes, Scott is right person to comment, So let us wait for him comment.
I don't think it's actually a problem on 32-bit, since r9 is modified but never actually used for anything. On 64-bit, though, there's a store to the caller's stack frame (yuck) which the
kvm/booke.hcaller is not prepared for. Indeed, book3s'skvmppc_load_up_fpucreates an interrupt-like stack frame, but does not load r9 or r12.
Yep.
Quoted 3 lines
It would be really nice if assumptions like these were put in a code comment above
load_up_fpu... and if we didn't have so many random differences between 32-bit and 64-bit. :-P
Yep.. I won't NACK that patch when you send it :-)
It was pretty much assumed that load_up_fpu was going to be called right after the exception prolog. Calling it any other way was going to be tricky.
Mikey
Quoted 68 lines
-----Original Message-----
From: Wood Scott-B07421
Sent: Wednesday, February 13, 2013 12:03 AM
To: Bhushan Bharat-R65777
Cc: Michael Neuling; Wood Scott-B07421; [email protected]
Subject: Re: BOOKE KVM callingload_up_fpufrom C?
=20Quoted 58 lines · On 02/12/2013 03:01:07 AM, Bhushan Bharat-R65777 wrote:
Quoted 24 lines
-----Original Message-----
From: Michael Neuling [mailto:[email protected]]
Sent: Tuesday, February 12, 2013 9:46 AM
To: Bhushan Bharat-R65777
Cc: Wood Scott-B07421; [email protected]
Subject: Re: BOOKE KVM callingload_up_fpufrom C?Quoted 13 lines · Bhushan Bharat-R65777 <[email protected]> wrote:
Quoted 13 lines
-----Original Message-----
From: Michael Neuling [mailto:[email protected]]
Sent: Tuesday, February 12, 2013 9:16 AM
To: Bhushan Bharat-R65777
Cc: Wood Scott-B07421; [email protected]
Subject: Re: BOOKE KVM callingload_up_fpufrom C?Look further down...
#ifdef
CONFIG_PPC32
mfspr r5,SPRN_SPRG_THREAD /* currenttask's THREAD (phys) */
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
lwz r4,THREAD_FPEXC_MODE(r5) ori r9,r9,MSR_FP /* enable FP forcurrent */
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
or r9,r9,r4 #else ld r4,PACACURRENT(r13) addi r5,r4,THREAD /* Get THREAD */ lwz r4,THREAD_FPEXC_MODE(r5) ori r12,r12,MSR_FP or r12,r12,r4 std r12,_MSR(r1)#endif
R12 is loaded with SRR1 in the exception prolog before
load_up_fpuisQuoted 11 lines
called.
Quoted 2 lines
Yes it is SRR1 not MSR.
Yes, SRR1 =3D=3D the MSR of the user process, not the current MSR.
Quoted 1 line
Also on 32bit it looks like that R9 is assumed to have SRR1.
Yep that too.
So any idea how it's suppose to work or is it broken?
To me this looks wrong. And this seems to works because the
thread->reg->msris not actually used to write SRR1 (and eventually the thread MSR) when doing rfi to enter guest. InfactGuest(shadow_msr)MSR is used as SRR1 and which will have proper MSR (including FP set).
Quoted 4 lines
Quoted 2 lines
But Yes, Scott is right person to comment, So let us wait for him comment.
=20
I don't think it's actually a problem on 32-bit, since r9 is modified but=
never
Quoted 1 line
actually used for anything.
Is not the epilog loads srr1 in r9 and load_up_fpu() changes r9 and then r9=
is written back in srr1 ?
Quoted 2 lines
On 64-bit, though, there's a store to the caller's
stack frame (yuck) which thekvm/booke.hcaller is not prepared for.
So if caller is using r12 then it can lead to come corruption, right ?
Quoted 2 lines
Indeed,
book3s'skvmppc_load_up_fpucreates an interrupt-like stack frame, but do=
es not
Quoted 3 lines
load r9 or r12.
=20
It would be really nice if assumptions like these were put in a code comm=
ent
Quoted 1 line
above
load_up_fpu... and if we didn't have so many random differences be=
tween
Quoted 1 line
32-bit and 64-bit. :-P
:)
Thanks
-Bharat
Quoted 2 lines
=20
-Scott
Quoted 22 lines · On 02/12/2013 07:18:14 PM, Bhushan Bharat-R65777 wrote:
=20
=20Quoted 5 lines
-----Original Message-----
From: Wood Scott-B07421
Sent: Wednesday, February 13, 2013 12:03 AM
To: Bhushan Bharat-R65777
Cc: Michael Neuling; Wood Scott-B07421; =20Quoted 5 lines
Subject: Re: BOOKE KVM calling
load_up_fpufrom C?Quoted 2 lines · On 02/12/2013 03:01:07 AM, Bhushan Bharat-R65777 wrote:
To me this looks wrong. And this seems to works because the
thread->reg->msris not actually used to write SRR1 (and =20eventually
Quoted 2 lines
Quoted 2 lines
the thread MSR) when doing rfi to enter guest. Infact
Guest(shadow_msr)MSR is used as SRR1 and which will have proper =20MSR
Quoted 5 lines
Quoted 4 lines
(including FP set).
But Yes, Scott is right person to comment, So let us wait for him comment.
Quoted 6 lines
Quoted 1 line
I don't think it's actually a problem on 32-bit, since r9 is =20
modified but never
Quoted 1 line
actually used for anything.
=20
Is not the epilog loads srr1 in r9 andload_up_fpu()changes r9 and =20 then r9 is written back in srr1 ?
What epilog? We're talking about the case where it's called from C =20 code.
When it's called from an exception handler, then r9 is used, but in =20 that case it's also initialized before calling load_up_fpu, by the =20 prolog.
Quoted 4 lines
Quoted 2 lines
On 64-bit, though, there's a store to the caller's
stack frame (yuck) which thekvm/booke.hcaller is not prepared for.=20
So if caller is using r12 then it can lead to come corruption, right ?
No, r12 is a volatile register in the ABI, as is r9. The issue is that =20 the stack can be corrupted.
-Scott=
Quoted 34 lines
-----Original Message-----
From: Wood Scott-B07421
Sent: Wednesday, February 13, 2013 6:53 AM
To: Bhushan Bharat-R65777
Cc: Wood Scott-B07421; Michael Neuling; [email protected]
Subject: Re: BOOKE KVM callingload_up_fpufrom C?
=20Quoted 24 lines · On 02/12/2013 07:18:14 PM, Bhushan Bharat-R65777 wrote:
Quoted 7 lines
-----Original Message-----
From: Wood Scott-B07421
Sent: Wednesday, February 13, 2013 12:03 AM
To: Bhushan Bharat-R65777
Cc: Michael Neuling; Wood Scott-B07421;Quoted 5 lines
Subject: Re: BOOKE KVM calling
load_up_fpufrom C?Quoted 2 lines · On 02/12/2013 03:01:07 AM, Bhushan Bharat-R65777 wrote:
To me this looks wrong. And this seems to works because the
thread->reg->msris not actually used to write SRR1 (andeventually
Quoted 2 lines
Quoted 2 lines
the thread MSR) when doing rfi to enter guest. Infact
Guest(shadow_msr)MSR is used as SRR1 and which will have properMSR
Quoted 6 lines
Quoted 4 lines
(including FP set).
But Yes, Scott is right person to comment, So let us wait for him comment.
I don't think it's actually a problem on 32-bit, since r9 is
modified but never
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
actually used for anything.
Is not the epilog loads srr1 in r9 and
load_up_fpu()changes r9 and then r9 is written back in srr1 ?=20
What epilog? We're talking about the case where it's called from C code =20
When it's called from an exception handler, then r9 is used, but in that =
case
Quoted 1 line
it's also initialized before calling
load_up_fpu, by the prolog.
Agree. Was just confirming the exception handler case.
Quoted 7 lines
=20
Quoted 4 lines
Quoted 2 lines
On 64-bit, though, there's a store to the caller's stack frame
(yuck) which thekvm/booke.hcaller is not prepared for.So if caller is using r12 then it can lead to come corruption, right ?
=20
No, r12 is a volatile register in the ABI, as is r9. The issue is that t=
he
Quoted 1 line
stack can be corrupted.
Ok, Thanks
-Bharat
Quoted 2 lines
=20
-Scott
Quoted 34 lines
-----Original Message-----
From: Wood Scott-B07421
Sent: Wednesday, February 13, 2013 6:53 AM
To: Bhushan Bharat-R65777
Cc: Wood Scott-B07421; Michael Neuling; [email protected]
Subject: Re: BOOKE KVM callingload_up_fpufrom C?
=20Quoted 24 lines · On 02/12/2013 07:18:14 PM, Bhushan Bharat-R65777 wrote:
Quoted 7 lines
-----Original Message-----
From: Wood Scott-B07421
Sent: Wednesday, February 13, 2013 12:03 AM
To: Bhushan Bharat-R65777
Cc: Michael Neuling; Wood Scott-B07421;Quoted 5 lines
Subject: Re: BOOKE KVM calling
load_up_fpufrom C?Quoted 2 lines · On 02/12/2013 03:01:07 AM, Bhushan Bharat-R65777 wrote:
To me this looks wrong. And this seems to works because the
thread->reg->msris not actually used to write SRR1 (andeventually
Quoted 2 lines
Quoted 2 lines
the thread MSR) when doing rfi to enter guest. Infact
Guest(shadow_msr)MSR is used as SRR1 and which will have properMSR
Quoted 6 lines
Quoted 4 lines
(including FP set).
But Yes, Scott is right person to comment, So let us wait for him comment.
I don't think it's actually a problem on 32-bit, since r9 is
modified but never
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
actually used for anything.
Is not the epilog loads srr1 in r9 and
load_up_fpu()changes r9 and then r9 is written back in srr1 ?=20
What epilog? We're talking about the case where it's called from C code. =20
When it's called from an exception handler, then r9 is used, but in that =
case
Quoted 8 lines
it's also initialized before calling
load_up_fpu, by the prolog. =20Quoted 4 lines
Quoted 2 lines
On 64-bit, though, there's a store to the caller's stack frame
(yuck) which thekvm/booke.hcaller is not prepared for.So if caller is using r12 then it can lead to come corruption, right ?
=20
No, r12 is a volatile register in the ABI, as is r9. The issue is that t=
he
Quoted 1 line
stack can be corrupted.
What do you mean by stack is corrupted?
My understanding is that when calling the assembly function from C function=
then stack frame will not be pushed and assembly function uses the caller =
stack frame. Example function1() calls function2() which calls assembly_ro= utine()
functio1()=20
|---------------------| | Stack Frame 1 | | <function1 caller | | registers etc> | |---------------------|
Calls function 2
|----------------------| | Stack Frame 2 | | <function1 registers | | etc > | |----------------------| | Stack Frame 1 | | <function1 caller | | registers etc> | |----------------------|
calls assembly_routine();
Now no stack frame push; And the assembly_routine() changes register values=
saved in stack. So when stack will be unrolled then registers of function1=
() will get corrupted, right?
Thanks
-Bharat
Quoted 24 lines · On 02/12/2013 10:17:00 PM, Bhushan Bharat-R65777 wrote:
=20
=20Quoted 5 lines
-----Original Message-----
From: Wood Scott-B07421
Sent: Wednesday, February 13, 2013 6:53 AM
To: Bhushan Bharat-R65777
Cc: Wood Scott-B07421; Michael Neuling; =20Quoted 16 lines
Subject: Re: BOOKE KVM calling
load_up_fpufrom C?Quoted 13 lines · On 02/12/2013 07:18:14 PM, Bhushan Bharat-R65777 wrote:
Quoted 7 lines
-----Original Message-----
From: Wood Scott-B07421
Sent: Wednesday, February 13, 2013 12:03 AM
To: Bhushan Bharat-R65777
Cc: Michael Neuling; Wood Scott-B07421;Quoted 4 lines
Subject: Re: BOOKE KVM calling
load_up_fpufrom C?On 64-bit, though, there's a store to the caller's stack frame
(yuck) which thekvm/booke.hcaller is not prepared for.
Quoted 8 lines
Quoted 1 line
Quoted 1 line
So if caller is using r12 then it can lead to come corruption, =20
right ?
Quoted 2 lines
No, r12 is a volatile register in the ABI, as is r9. The issue is =20
that the
Quoted 1 line
stack can be corrupted.
=20
What do you mean by stack is corrupted?
load_up_fpu() makes assumptions about the caller's stack frame that =20 aren't true when called from C code.
Quoted 3 lines
My understanding is that when calling the assembly function from C =20 function then stack frame will not be pushed and assembly function =20 uses the caller stack frame.
Huh? Assembly functions obey the same ABI as C functions (at least, =20 asm functions meant to be callable from C do). If the above were true, =20 how would C code know that it's calling an asm function, and how would =20 it know how much stack to create and which portions would be clobbered?
The issue with load_up_fpu() is that it was apparently not meant to be =20 called directly from C code.
-Scott=