i386: EFER vs 32-bit CPU
Hello!
I found this while debugging the inconsistent saved/restored state of the virtual machine.
i386 (32 bit) emulation uses this register (in wrmsr and in MMU fault processing).
But it does not included in VMState, because "efer" field is disabled with #ifdef TARGET_X86_64
I think that efer should be saved for i386 too, but how it should be made to preserve the backward compatibility?
Should we add a section for i386, which duplicates efer, or just version_id of the main VMSD should be updated?
Pavel Dovgalyuk
Quoted 14 lines · * Pavel Dovgalyuk ([email protected]) wrote:
Hello!
I found this while debugging the inconsistent saved/restored state of the virtual machine.
i386 (32 bit) emulation uses this register (in wrmsr and in MMU fault processing).
But it does not included in VMState, because "efer" field is disabled with #ifdef
TARGET_X86_64
Quoted 5 lines
I think that efer should be saved for i386 too, but how it should be made to preserve the backward compatibility?
Should we add a section for i386, which duplicates efer, or just
version_idof the main VMSD should be updated?
You could do:
#ifdef TARGET_X86_64
VMSTATE_UINT64(env.efer, X86CPU),
VMSTATE_UINT64(env.star, X86CPU),...
to become:
VMSTATE_UINT64_TEST(env.efer, X86CPU, efer_needed)
#ifdef TARGET_X86_64
VMSTATE_UINT64(env.star, X86CPU),and then make efer_needed a function that returns true if TARGET_X86_64 or it's a new machine type that knows about whatever you're going to do with it.
Dave
Quoted 6 lines
Pavel Dovgalyuk
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 12 lines · Dr. David Alan Gilbert
Quoted 2 lines
Should we add a section for i386, which duplicates efer, or just
version_idof the main VMSD should be updated?You could do:
#ifdef TARGET_X86_64 VMSTATE_UINT64(env.efer, X86CPU), VMSTATE_UINT64(env.star, X86CPU),...
to become:
Quoted 8 lines
VMSTATE_UINT64_TEST(env.efer, X86CPU, efer_needed)#ifdef TARGET_X86_64 VMSTATE_UINT64(env.star, X86CPU),and then make
efer_neededa function that returns true ifTARGET_X86_64or it's a new machine type that knows about whatever you're going to do with it.
I prefer adding a subsection for 32-bit, so that EFER is saved/restored if nonzero.
Paolo
Quoted 20 lines
From: Paolo Bonzini [mailto:[email protected]]
Quoted 1 line · Dr. David Alan Gilbert
Quoted 1 line
Should we add a section for i386, which duplicates efer, or just
version_idof the mainVMSD should
Quoted 16 lines
Quoted 1 line
be updated?
You could do:
#ifdef TARGET_X86_64 VMSTATE_UINT64(env.efer, X86CPU), VMSTATE_UINT64(env.star, X86CPU),...
to become:
VMSTATE_UINT64_TEST(env.efer, X86CPU, efer_needed)#ifdef TARGET_X86_64 VMSTATE_UINT64(env.star, X86CPU),
Quoted 6 lines
Quoted 3 lines
and then make
efer_neededa function that returns true ifTARGET_X86_64or it's a new machine type that knows about whatever you're going to do with it.I prefer adding a subsection for 32-bit, so that EFER is saved/restored if nonzero.
The question is: should we remove EFER from the original VMSD?
Pavel Dovgalyuk
Quoted 20 lines · * Pavel Dovgalyuk ([email protected]) wrote:
Quoted 20 lines
From: Paolo Bonzini [mailto:[email protected]]
Quoted 1 line · Dr. David Alan Gilbert
Quoted 1 line
Should we add a section for i386, which duplicates efer, or just
version_idof the mainVMSD should
Quoted 16 lines
Quoted 1 line
be updated?
You could do:
#ifdef TARGET_X86_64 VMSTATE_UINT64(env.efer, X86CPU), VMSTATE_UINT64(env.star, X86CPU),...
to become:
VMSTATE_UINT64_TEST(env.efer, X86CPU, efer_needed)#ifdef TARGET_X86_64 VMSTATE_UINT64(env.star, X86CPU),
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
and then make
efer_neededa function that returns true ifTARGET_X86_64or it's a new machine type that knows about whatever you're going to do with it.I prefer adding a subsection for 32-bit, so that EFER is saved/restored if nonzero.
The question is: should we remove EFER from the original VMSD?
No, because that would break 64bit compat.
Dave
Quoted 2 lines
Pavel Dovgalyuk
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 26 lines
From: Dr. David Alan Gilbert [mailto:[email protected]]
Quoted 24 lines · * Pavel Dovgalyuk ([email protected]) wrote:
Quoted 24 lines
From: Paolo Bonzini [mailto:[email protected]]
Quoted 1 line · Dr. David Alan Gilbert
Quoted 1 line
Should we add a section for i386, which duplicates efer, or just
version_idof the mainVMSD should
Quoted 19 lines
Quoted 1 line
be updated?
You could do:
#ifdef TARGET_X86_64 VMSTATE_UINT64(env.efer, X86CPU), VMSTATE_UINT64(env.star, X86CPU),...
to become:
VMSTATE_UINT64_TEST(env.efer, X86CPU, efer_needed)#ifdef TARGET_X86_64 VMSTATE_UINT64(env.star, X86CPU),and then make
efer_neededa function that returns true ifTARGET_X86_64or it's a new machine type that knows about whatever you're going to do with it.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
I prefer adding a subsection for 32-bit, so that EFER is saved/restored if nonzero.
The question is: should we remove EFER from the original VMSD?
No, because that would break 64bit compat.
Thanks. Already posted a patch here:
https://lists.gnu.org/archive/html/qemu-devel/2019-05/msg06796.html
Pavel Dovgalyuk
Quoted 9 lines · Pavel Dovgalyuk
Hello!
I found this while debugging the inconsistent saved/restored state of the virtual machine.
i386 (32 bit) emulation uses this register (in wrmsr and in MMU fault processing).
Sorry if this question is elementary, but... why would a 32bit guest use IA32_EFER? From SDM I only see 4 bits defined in this MSR (SCE, LME, LMA, NXE) but is there any of them that should be set in a 32bit guest?
Regards,
Signature · 1 line
Peter Xu
Quoted 10 lines
From: Peter Xu [mailto:[email protected]]
Quoted 8 lines · Pavel Dovgalyuk
Hello!
I found this while debugging the inconsistent saved/restored state of the virtual machine.
Quoted 6 lines
Quoted 1 line
i386 (32 bit) emulation uses this register (in wrmsr and in MMU fault processing).
Sorry if this question is elementary, but... why would a 32bit guest use
IA32_EFER? From SDM I only see 4 bits defined in this MSR (SCE, LME, LMA, NXE) but is there any of them that should be set in a 32bit guest?
Ubuntu server 16.04 (32 bit) sets NXE while booting. NXE affects the MMU fault processing and exception generation.
Pavel Dovgalyuk
Quoted 12 lines · Pavel Dovgalyuk
Quoted 12 lines
From: Peter Xu [mailto:[email protected]]
Quoted 9 lines · Pavel Dovgalyuk
Hello!
I found this while debugging the inconsistent saved/restored state of the virtual machine.
i386 (32 bit) emulation uses this register (in wrmsr and in MMU fault processing).
Quoted 7 lines
Quoted 4 lines
Sorry if this question is elementary, but... why would a 32bit guest use
IA32_EFER? From SDM I only see 4 bits defined in this MSR (SCE, LME, LMA, NXE) but is there any of them that should be set in a 32bit guest?Ubuntu server 16.04 (32 bit) sets NXE while booting. NXE affects the MMU fault processing and exception generation.
But this is what I read from the spec (SDM 4.6.1):
Instruction fetches:
- Access rights depend on the mode of the linear address, the paging mode, and the value of IA32_EFER.NXE:
- For 32-bit paging or if IA32_EFER.NXE = 0, instructions may be fetched from any user-mode address.
- For PAE paging or 4-level paging with IA32_EFER.NXE = 1, instructions may be fetched from any user-mode address with a translation for which the XD flag is 0 in every paging-structure entry controlling the translation.
- Instructions may not be fetched from any supervisor-mode address.
I'm not an expert of x86 arch but it seems to me that no matter what NXE bit should be meaningless on x86 32bit according to above.
Also, above spec seems to match with the kvm code too, since in init_kvm_tdp_mmu() where kvm_mmu.nx is only set with either long mode or PAE, but never 32bit. So I'm a bit confused on why that should be migrated for 32bit (or even, whether should EFER MSR be visible to such a guest at all?).
Regards,
Signature · 1 line
Peter Xu
Quoted 38 lines · Peter Xu
Quoted 12 lines · Pavel Dovgalyuk
Quoted 12 lines
From: Peter Xu [mailto:[email protected]]
Quoted 9 lines · Pavel Dovgalyuk
Hello!
I found this while debugging the inconsistent saved/restored state of the virtual machine.
i386 (32 bit) emulation uses this register (in wrmsr and in MMU fault processing).
Quoted 7 lines
Quoted 4 lines
Sorry if this question is elementary, but... why would a 32bit guest use
IA32_EFER? From SDM I only see 4 bits defined in this MSR (SCE, LME, LMA, NXE) but is there any of them that should be set in a 32bit guest?Ubuntu server 16.04 (32 bit) sets NXE while booting. NXE affects the MMU fault processing and exception generation.
But this is what I read from the spec (SDM 4.6.1):
Instruction fetches:
- Access rights depend on the mode of the linear address, the paging mode, and the value of IA32_EFER.NXE:
- For 32-bit paging or if IA32_EFER.NXE = 0, instructions may be fetched from any user-mode address.
- For PAE paging or 4-level paging with IA32_EFER.NXE = 1, instructions may be fetched from any user-mode address with a translation for which the XD flag is 0 in every paging-structure entry controlling the translation.
- Instructions may not be fetched from any supervisor-mode address.
Quoted 8 lines
I'm not an expert of x86 arch but it seems to me that no matter what NXE bit should be meaningless on x86 32bit according to above.
Also, above spec seems to match with the kvm code too, since in
init_kvm_tdp_mmu()where kvm_mmu.nx is only set with either long mode or PAE, but never 32bit. So I'm a bit confused on why that should be migrated for 32bit (or even, whether should EFER MSR be visible to such a guest at all?).
Ouch, I obviously overlooked on that PAE is 32bit... I am sorry for the noise.
Signature · 1 line
Peter Xu
Quoted 18 lines · Pavel Dovgalyuk
Hello!
I found this while debugging the inconsistent saved/restored state of the virtual machine.
i386 (32 bit) emulation uses this register (in wrmsr and in MMU fault processing).
But it does not included in VMState, because "efer" field is disabled with #ifdef
TARGET_X86_64I think that efer should be saved for i386 too, but how it should be made to preserve the backward compatibility?
Quoted 9 lines
Should we add a section for i386, which duplicates efer, or just
version_idof the main VMSD should be updated?Pavel Dovgalyuk
Nobody followed this issue 10 years ago:
https://lists.gnu.org/archive/html/qemu-devel/2009-10/msg01765.html