Skip to contentSkip to conversation

BOOKE KVM calling load_up_fpu from C?

DISCUSSION Michael Neuling 3 participants 13 messages Feb 12, 2013 – Feb 13, 2013

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw
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 calling load_up_fpu from C?
=20
Scott,
=20
I was looking at changing how load_up_fpu works and I found this in arch/powerpc/kvm/booke.h:
=20
static inline void kvmppc_load_guest_fp(struct kvm_vcpu *vcpu) { #ifdef CONFIG_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 since load_up_fpu is 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_VSX
BEGIN_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

#2 lore raw
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 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;
	}
Quoted 5 lines

#endif
}

I'm wondering how this is suppose to work since load_up_fpu is 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
#ifdef CONFIG_VSX
BEGIN_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

#3 lore raw
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 calling load_up_fpu from C? =20
Bhushan Bharat-R65777 <[email protected]> wrote:
=20

Quoted 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 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 |=3D MSR_FP;
	}
Quoted 5 lines

#endif
}

I'm wondering how this is suppose to work since load_up_fpu is 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
#ifdef CONFIG_VSX
BEGIN_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>

=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 before load_up_fpu is 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

#4 lore raw
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 calling load_up_fpu from 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 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;
	}
Quoted 5 lines

#endif
}

I'm wondering how this is suppose to work since load_up_fpu is 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
#ifdef CONFIG_VSX
BEGIN_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

Quoted 3 lines
Quoted 1 line

R12 is loaded with SRR1 in the exception prolog before load_up_fpu is 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

#5 lore raw
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 calling load_up_fpu from C? =20
Bhushan Bharat-R65777 <[email protected]> wrote:
=20

Quoted 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 calling load_up_fpu from 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 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 |=3D MSR_FP;
	}
Quoted 5 lines

#endif
}

I'm wondering how this is suppose to work since load_up_fpu is 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
#ifdef CONFIG_VSX
BEGIN_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

Quoted 1 line
Quoted 1 line

R12 is loaded with SRR1 in the exception prolog before load_up_fpu is

called.

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. =20

Quoted 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

#6 lore raw
Quoted 51 lines · On 02/12/2013 03:01:07 AM, Bhushan Bharat-R65777 wrote:

=20
=20

Quoted 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 calling load_up_fpu from 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 calling load_up_fpu from C?

Look further down...

#ifdef CONFIG_PPC32
	mfspr	r5,SPRN_SPRG_THREAD		/* current =20

task'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 =20

current */

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_fpu is

Quoted 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 =20 thread->reg->msr is not actually used to write SRR1 (and eventually =20 the thread MSR) when doing rfi to enter guest. Infact =20 Guest(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=

#7 lore raw
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 calling load_up_fpu from 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 calling load_up_fpu from C?

Look further down...

#ifdef CONFIG_PPC32
mfspr r5,SPRN_SPRG_THREAD /* current

task'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  

current */

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_fpu is

Quoted 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->msr is not actually used to write SRR1 (and eventually the thread MSR) when doing rfi to enter guest. Infact Guest(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.h caller is not prepared for. Indeed, book3s's kvmppc_load_up_fpu creates 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

#8 lore raw
In reply to Scott Wood
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 calling load_up_fpu from C?
=20

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 calling load_up_fpu from 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 calling load_up_fpu from C?

Look further down...

#ifdef CONFIG_PPC32
mfspr r5,SPRN_SPRG_THREAD /* current

task'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

current */

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_fpu is

Quoted 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->msr is not actually used to write SRR1 (and eventually the thread MSR) when doing rfi to enter guest. Infact Guest(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 the kvm/booke.h caller is not prepared for.

So if caller is using r12 then it can lead to come corruption, right ?

Quoted 2 lines

Indeed,
book3s's kvmppc_load_up_fpu creates 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

#9 lore raw
Quoted 22 lines · On 02/12/2013 07:18:14 PM, Bhushan Bharat-R65777 wrote:

=20
=20

Quoted 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; =20

[email protected]

Quoted 5 lines

Subject: Re: BOOKE KVM calling load_up_fpu from 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->msr is not actually used to write SRR1 (and =20

eventually

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 =20

MSR

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 and load_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 the kvm/booke.h caller 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=

#10 lore raw
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 calling load_up_fpu from C?
=20

Quoted 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;

[email protected]

Quoted 5 lines

Subject: Re: BOOKE KVM calling load_up_fpu from 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->msr is not actually used to write SRR1 (and

eventually

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

MSR

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 the kvm/booke.h caller 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

#11 lore raw
In reply to Scott Wood
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 calling load_up_fpu from C?
=20

Quoted 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;

[email protected]

Quoted 5 lines

Subject: Re: BOOKE KVM calling load_up_fpu from 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->msr is not actually used to write SRR1 (and

eventually

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

MSR

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. =20

Quoted 4 lines
Quoted 2 lines

On 64-bit, though, there's a store to the caller's stack frame
(yuck) which the kvm/booke.h caller 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

#12 lore raw
Quoted 24 lines · On 02/12/2013 10:17:00 PM, Bhushan Bharat-R65777 wrote:

=20
=20

Quoted 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; =20

[email protected]

Quoted 16 lines

Subject: Re: BOOKE KVM calling load_up_fpu from 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;

[email protected]

Quoted 4 lines

Subject: Re: BOOKE KVM calling load_up_fpu from C?

On 64-bit, though, there's a store to the caller's stack frame
(yuck) which the kvm/booke.h caller 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=