diff options
author | Avi Kivity <avi@qumranet.com> | 2008-07-14 07:44:59 -0400 |
---|---|---|
committer | Avi Kivity <avi@qumranet.com> | 2008-10-15 04:15:14 -0400 |
commit | 80e31d4f61f69d0e480ae092cda0e590d6a30aeb (patch) | |
tree | 220259160b40ba6e5875930e1166c6e9403e6857 | |
parent | c801949ddf0a51074937f488a52072825ed50174 (diff) |
KVM: SVM: Unify register save/restore across 32 and 64 bit hosts
Signed-off-by: Avi Kivity <avi@qumranet.com>
-rw-r--r-- | arch/x86/kvm/svm.c | 78 |
1 files changed, 26 insertions, 52 deletions
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 743c98d135c4..179c2e00d0f9 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c | |||
@@ -1697,6 +1697,12 @@ static inline void sync_lapic_to_cr8(struct kvm_vcpu *vcpu) | |||
1697 | svm->vmcb->control.int_ctl |= cr8 & V_TPR_MASK; | 1697 | svm->vmcb->control.int_ctl |= cr8 & V_TPR_MASK; |
1698 | } | 1698 | } |
1699 | 1699 | ||
1700 | #ifdef CONFIG_X86_64 | ||
1701 | #define R "r" | ||
1702 | #else | ||
1703 | #define R "e" | ||
1704 | #endif | ||
1705 | |||
1700 | static void svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) | 1706 | static void svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) |
1701 | { | 1707 | { |
1702 | struct vcpu_svm *svm = to_svm(vcpu); | 1708 | struct vcpu_svm *svm = to_svm(vcpu); |
@@ -1735,19 +1741,14 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) | |||
1735 | local_irq_enable(); | 1741 | local_irq_enable(); |
1736 | 1742 | ||
1737 | asm volatile ( | 1743 | asm volatile ( |
1744 | "push %%"R"bp; \n\t" | ||
1745 | "mov %c[rbx](%[svm]), %%"R"bx \n\t" | ||
1746 | "mov %c[rcx](%[svm]), %%"R"cx \n\t" | ||
1747 | "mov %c[rdx](%[svm]), %%"R"dx \n\t" | ||
1748 | "mov %c[rsi](%[svm]), %%"R"si \n\t" | ||
1749 | "mov %c[rdi](%[svm]), %%"R"di \n\t" | ||
1750 | "mov %c[rbp](%[svm]), %%"R"bp \n\t" | ||
1738 | #ifdef CONFIG_X86_64 | 1751 | #ifdef CONFIG_X86_64 |
1739 | "push %%rbp; \n\t" | ||
1740 | #else | ||
1741 | "push %%ebp; \n\t" | ||
1742 | #endif | ||
1743 | |||
1744 | #ifdef CONFIG_X86_64 | ||
1745 | "mov %c[rbx](%[svm]), %%rbx \n\t" | ||
1746 | "mov %c[rcx](%[svm]), %%rcx \n\t" | ||
1747 | "mov %c[rdx](%[svm]), %%rdx \n\t" | ||
1748 | "mov %c[rsi](%[svm]), %%rsi \n\t" | ||
1749 | "mov %c[rdi](%[svm]), %%rdi \n\t" | ||
1750 | "mov %c[rbp](%[svm]), %%rbp \n\t" | ||
1751 | "mov %c[r8](%[svm]), %%r8 \n\t" | 1752 | "mov %c[r8](%[svm]), %%r8 \n\t" |
1752 | "mov %c[r9](%[svm]), %%r9 \n\t" | 1753 | "mov %c[r9](%[svm]), %%r9 \n\t" |
1753 | "mov %c[r10](%[svm]), %%r10 \n\t" | 1754 | "mov %c[r10](%[svm]), %%r10 \n\t" |
@@ -1756,41 +1757,24 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) | |||
1756 | "mov %c[r13](%[svm]), %%r13 \n\t" | 1757 | "mov %c[r13](%[svm]), %%r13 \n\t" |
1757 | "mov %c[r14](%[svm]), %%r14 \n\t" | 1758 | "mov %c[r14](%[svm]), %%r14 \n\t" |
1758 | "mov %c[r15](%[svm]), %%r15 \n\t" | 1759 | "mov %c[r15](%[svm]), %%r15 \n\t" |
1759 | #else | ||
1760 | "mov %c[rbx](%[svm]), %%ebx \n\t" | ||
1761 | "mov %c[rcx](%[svm]), %%ecx \n\t" | ||
1762 | "mov %c[rdx](%[svm]), %%edx \n\t" | ||
1763 | "mov %c[rsi](%[svm]), %%esi \n\t" | ||
1764 | "mov %c[rdi](%[svm]), %%edi \n\t" | ||
1765 | "mov %c[rbp](%[svm]), %%ebp \n\t" | ||
1766 | #endif | 1760 | #endif |
1767 | 1761 | ||
1768 | #ifdef CONFIG_X86_64 | ||
1769 | /* Enter guest mode */ | 1762 | /* Enter guest mode */ |
1770 | "push %%rax \n\t" | 1763 | "push %%"R"ax \n\t" |
1771 | "mov %c[vmcb](%[svm]), %%rax \n\t" | 1764 | "mov %c[vmcb](%[svm]), %%"R"ax \n\t" |
1772 | __ex(SVM_VMLOAD) "\n\t" | 1765 | __ex(SVM_VMLOAD) "\n\t" |
1773 | __ex(SVM_VMRUN) "\n\t" | 1766 | __ex(SVM_VMRUN) "\n\t" |
1774 | __ex(SVM_VMSAVE) "\n\t" | 1767 | __ex(SVM_VMSAVE) "\n\t" |
1775 | "pop %%rax \n\t" | 1768 | "pop %%"R"ax \n\t" |
1776 | #else | ||
1777 | /* Enter guest mode */ | ||
1778 | "push %%eax \n\t" | ||
1779 | "mov %c[vmcb](%[svm]), %%eax \n\t" | ||
1780 | __ex(SVM_VMLOAD) "\n\t" | ||
1781 | __ex(SVM_VMRUN) "\n\t" | ||
1782 | __ex(SVM_VMSAVE) "\n\t" | ||
1783 | "pop %%eax \n\t" | ||
1784 | #endif | ||
1785 | 1769 | ||
1786 | /* Save guest registers, load host registers */ | 1770 | /* Save guest registers, load host registers */ |
1771 | "mov %%"R"bx, %c[rbx](%[svm]) \n\t" | ||
1772 | "mov %%"R"cx, %c[rcx](%[svm]) \n\t" | ||
1773 | "mov %%"R"dx, %c[rdx](%[svm]) \n\t" | ||
1774 | "mov %%"R"si, %c[rsi](%[svm]) \n\t" | ||
1775 | "mov %%"R"di, %c[rdi](%[svm]) \n\t" | ||
1776 | "mov %%"R"bp, %c[rbp](%[svm]) \n\t" | ||
1787 | #ifdef CONFIG_X86_64 | 1777 | #ifdef CONFIG_X86_64 |
1788 | "mov %%rbx, %c[rbx](%[svm]) \n\t" | ||
1789 | "mov %%rcx, %c[rcx](%[svm]) \n\t" | ||
1790 | "mov %%rdx, %c[rdx](%[svm]) \n\t" | ||
1791 | "mov %%rsi, %c[rsi](%[svm]) \n\t" | ||
1792 | "mov %%rdi, %c[rdi](%[svm]) \n\t" | ||
1793 | "mov %%rbp, %c[rbp](%[svm]) \n\t" | ||
1794 | "mov %%r8, %c[r8](%[svm]) \n\t" | 1778 | "mov %%r8, %c[r8](%[svm]) \n\t" |
1795 | "mov %%r9, %c[r9](%[svm]) \n\t" | 1779 | "mov %%r9, %c[r9](%[svm]) \n\t" |
1796 | "mov %%r10, %c[r10](%[svm]) \n\t" | 1780 | "mov %%r10, %c[r10](%[svm]) \n\t" |
@@ -1799,18 +1783,8 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) | |||
1799 | "mov %%r13, %c[r13](%[svm]) \n\t" | 1783 | "mov %%r13, %c[r13](%[svm]) \n\t" |
1800 | "mov %%r14, %c[r14](%[svm]) \n\t" | 1784 | "mov %%r14, %c[r14](%[svm]) \n\t" |
1801 | "mov %%r15, %c[r15](%[svm]) \n\t" | 1785 | "mov %%r15, %c[r15](%[svm]) \n\t" |
1802 | |||
1803 | "pop %%rbp; \n\t" | ||
1804 | #else | ||
1805 | "mov %%ebx, %c[rbx](%[svm]) \n\t" | ||
1806 | "mov %%ecx, %c[rcx](%[svm]) \n\t" | ||
1807 | "mov %%edx, %c[rdx](%[svm]) \n\t" | ||
1808 | "mov %%esi, %c[rsi](%[svm]) \n\t" | ||
1809 | "mov %%edi, %c[rdi](%[svm]) \n\t" | ||
1810 | "mov %%ebp, %c[rbp](%[svm]) \n\t" | ||
1811 | |||
1812 | "pop %%ebp; \n\t" | ||
1813 | #endif | 1786 | #endif |
1787 | "pop %%"R"bp" | ||
1814 | : | 1788 | : |
1815 | : [svm]"a"(svm), | 1789 | : [svm]"a"(svm), |
1816 | [vmcb]"i"(offsetof(struct vcpu_svm, vmcb_pa)), | 1790 | [vmcb]"i"(offsetof(struct vcpu_svm, vmcb_pa)), |
@@ -1831,11 +1805,9 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) | |||
1831 | [r15]"i"(offsetof(struct vcpu_svm, vcpu.arch.regs[VCPU_REGS_R15])) | 1805 | [r15]"i"(offsetof(struct vcpu_svm, vcpu.arch.regs[VCPU_REGS_R15])) |
1832 | #endif | 1806 | #endif |
1833 | : "cc", "memory" | 1807 | : "cc", "memory" |
1808 | , R"bx", R"cx", R"dx", R"si", R"di" | ||
1834 | #ifdef CONFIG_X86_64 | 1809 | #ifdef CONFIG_X86_64 |
1835 | , "rbx", "rcx", "rdx", "rsi", "rdi" | ||
1836 | , "r8", "r9", "r10", "r11" , "r12", "r13", "r14", "r15" | 1810 | , "r8", "r9", "r10", "r11" , "r12", "r13", "r14", "r15" |
1837 | #else | ||
1838 | , "ebx", "ecx", "edx" , "esi", "edi" | ||
1839 | #endif | 1811 | #endif |
1840 | ); | 1812 | ); |
1841 | 1813 | ||
@@ -1867,6 +1839,8 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) | |||
1867 | svm->next_rip = 0; | 1839 | svm->next_rip = 0; |
1868 | } | 1840 | } |
1869 | 1841 | ||
1842 | #undef R | ||
1843 | |||
1870 | static void svm_set_cr3(struct kvm_vcpu *vcpu, unsigned long root) | 1844 | static void svm_set_cr3(struct kvm_vcpu *vcpu, unsigned long root) |
1871 | { | 1845 | { |
1872 | struct vcpu_svm *svm = to_svm(vcpu); | 1846 | struct vcpu_svm *svm = to_svm(vcpu); |