Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm

Pull KVM changes from Paolo Bonzini:
"These are the x86, MIPS and s390 changes; PPC and ARM will come in a
few days.

MIPS and s390 have little going on this release; just bugfixes, some
small, some larger.

The highlights for x86 are nested VMX improvements (Jan Kiszka),
optimizations for old processor (up to Nehalem, by me and Bandan Das),
and a lot of x86 emulator bugfixes (Nadav Amit).

Stephen Rothwell reported a trivial conflict with the tracing branch"

* tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (104 commits)
x86/kvm: Resolve shadow warnings in macro expansion
KVM: s390: rework broken SIGP STOP interrupt handling
KVM: x86: always exit on EOIs for interrupts listed in the IOAPIC redir table
KVM: vmx: remove duplicate vmx_mpx_supported() prototype
KVM: s390: Fix memory leak on busy SIGP stop
x86/kvm: Resolve shadow warning from min macro
kvm: Resolve missing-field-initializers warnings
Replace NR_VMX_MSR with its definition
KVM: x86: Assertions to check no overrun in MSR lists
KVM: x86: set rflags.rf during fault injection
KVM: x86: Setting rflags.rf during rep-string emulation
KVM: x86: DR6/7.RTM cannot be written
KVM: nVMX: clean up nested_release_vmcs12 and code around it
KVM: nVMX: fix lifetime issues for vmcs02
KVM: x86: Defining missing x86 vectors
KVM: x86: emulator injects #DB when RFLAGS.RF is set
KVM: x86: Cleanup of rflags.rf cleaning
KVM: x86: Clear rflags.rf on emulated instructions
KVM: x86: popf emulation should not change RF
KVM: x86: Clearing rflags.rf upon skipped emulated instruction
...

+1792 -1446
+217 -128
Documentation/virtual/kvm/api.txt
··· 297 297 __u64 rip, rflags; 298 298 }; 299 299 300 + /* mips */ 301 + struct kvm_regs { 302 + /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */ 303 + __u64 gpr[32]; 304 + __u64 hi; 305 + __u64 lo; 306 + __u64 pc; 307 + }; 308 + 300 309 301 310 4.12 KVM_SET_REGS 302 311 ··· 387 378 4.16 KVM_INTERRUPT 388 379 389 380 Capability: basic 390 - Architectures: x86, ppc 381 + Architectures: x86, ppc, mips 391 382 Type: vcpu ioctl 392 383 Parameters: struct kvm_interrupt (in) 393 384 Returns: 0 on success, -1 on error ··· 431 422 432 423 Note that any value for 'irq' other than the ones stated above is invalid 433 424 and incurs unexpected behavior. 425 + 426 + MIPS: 427 + 428 + Queues an external interrupt to be injected into the virtual CPU. A negative 429 + interrupt number dequeues the interrupt. 434 430 435 431 436 432 4.17 KVM_DEBUG_GUEST ··· 526 512 4.21 KVM_SET_SIGNAL_MASK 527 513 528 514 Capability: basic 529 - Architectures: x86 515 + Architectures: all 530 516 Type: vcpu ioctl 531 517 Parameters: struct kvm_signal_mask (in) 532 518 Returns: 0 on success, -1 on error ··· 988 974 4.38 KVM_GET_MP_STATE 989 975 990 976 Capability: KVM_CAP_MP_STATE 991 - Architectures: x86, ia64 977 + Architectures: x86, ia64, s390 992 978 Type: vcpu ioctl 993 979 Parameters: struct kvm_mp_state (out) 994 980 Returns: 0 on success; -1 on error ··· 1002 988 1003 989 Possible values are: 1004 990 1005 - - KVM_MP_STATE_RUNNABLE: the vcpu is currently running 991 + - KVM_MP_STATE_RUNNABLE: the vcpu is currently running [x86, ia64] 1006 992 - KVM_MP_STATE_UNINITIALIZED: the vcpu is an application processor (AP) 1007 - which has not yet received an INIT signal 993 + which has not yet received an INIT signal [x86, 994 + ia64] 1008 995 - KVM_MP_STATE_INIT_RECEIVED: the vcpu has received an INIT signal, and is 1009 - now ready for a SIPI 996 + now ready for a SIPI [x86, ia64] 1010 997 - KVM_MP_STATE_HALTED: the vcpu has executed a HLT instruction and 1011 - is waiting for an interrupt 998 + is waiting for an interrupt [x86, ia64] 1012 999 - KVM_MP_STATE_SIPI_RECEIVED: the vcpu has just received a SIPI (vector 1013 - accessible via KVM_GET_VCPU_EVENTS) 1000 + accessible via KVM_GET_VCPU_EVENTS) [x86, ia64] 1001 + - KVM_MP_STATE_STOPPED: the vcpu is stopped [s390] 1002 + - KVM_MP_STATE_CHECK_STOP: the vcpu is in a special error state [s390] 1003 + - KVM_MP_STATE_OPERATING: the vcpu is operating (running or halted) 1004 + [s390] 1005 + - KVM_MP_STATE_LOAD: the vcpu is in a special load/startup state 1006 + [s390] 1014 1007 1015 - This ioctl is only useful after KVM_CREATE_IRQCHIP. Without an in-kernel 1016 - irqchip, the multiprocessing state must be maintained by userspace. 1008 + On x86 and ia64, this ioctl is only useful after KVM_CREATE_IRQCHIP. Without an 1009 + in-kernel irqchip, the multiprocessing state must be maintained by userspace on 1010 + these architectures. 1017 1011 1018 1012 1019 1013 4.39 KVM_SET_MP_STATE 1020 1014 1021 1015 Capability: KVM_CAP_MP_STATE 1022 - Architectures: x86, ia64 1016 + Architectures: x86, ia64, s390 1023 1017 Type: vcpu ioctl 1024 1018 Parameters: struct kvm_mp_state (in) 1025 1019 Returns: 0 on success; -1 on error ··· 1035 1013 Sets the vcpu's current "multiprocessing state"; see KVM_GET_MP_STATE for 1036 1014 arguments. 1037 1015 1038 - This ioctl is only useful after KVM_CREATE_IRQCHIP. Without an in-kernel 1039 - irqchip, the multiprocessing state must be maintained by userspace. 1016 + On x86 and ia64, this ioctl is only useful after KVM_CREATE_IRQCHIP. Without an 1017 + in-kernel irqchip, the multiprocessing state must be maintained by userspace on 1018 + these architectures. 1040 1019 1041 1020 1042 1021 4.40 KVM_SET_IDENTITY_MAP_ADDR ··· 1797 1774 and their own constants and width. To keep track of the implemented 1798 1775 registers, find a list below: 1799 1776 1800 - Arch | Register | Width (bits) 1801 - | | 1802 - PPC | KVM_REG_PPC_HIOR | 64 1803 - PPC | KVM_REG_PPC_IAC1 | 64 1804 - PPC | KVM_REG_PPC_IAC2 | 64 1805 - PPC | KVM_REG_PPC_IAC3 | 64 1806 - PPC | KVM_REG_PPC_IAC4 | 64 1807 - PPC | KVM_REG_PPC_DAC1 | 64 1808 - PPC | KVM_REG_PPC_DAC2 | 64 1809 - PPC | KVM_REG_PPC_DABR | 64 1810 - PPC | KVM_REG_PPC_DSCR | 64 1811 - PPC | KVM_REG_PPC_PURR | 64 1812 - PPC | KVM_REG_PPC_SPURR | 64 1813 - PPC | KVM_REG_PPC_DAR | 64 1814 - PPC | KVM_REG_PPC_DSISR | 32 1815 - PPC | KVM_REG_PPC_AMR | 64 1816 - PPC | KVM_REG_PPC_UAMOR | 64 1817 - PPC | KVM_REG_PPC_MMCR0 | 64 1818 - PPC | KVM_REG_PPC_MMCR1 | 64 1819 - PPC | KVM_REG_PPC_MMCRA | 64 1820 - PPC | KVM_REG_PPC_MMCR2 | 64 1821 - PPC | KVM_REG_PPC_MMCRS | 64 1822 - PPC | KVM_REG_PPC_SIAR | 64 1823 - PPC | KVM_REG_PPC_SDAR | 64 1824 - PPC | KVM_REG_PPC_SIER | 64 1825 - PPC | KVM_REG_PPC_PMC1 | 32 1826 - PPC | KVM_REG_PPC_PMC2 | 32 1827 - PPC | KVM_REG_PPC_PMC3 | 32 1828 - PPC | KVM_REG_PPC_PMC4 | 32 1829 - PPC | KVM_REG_PPC_PMC5 | 32 1830 - PPC | KVM_REG_PPC_PMC6 | 32 1831 - PPC | KVM_REG_PPC_PMC7 | 32 1832 - PPC | KVM_REG_PPC_PMC8 | 32 1833 - PPC | KVM_REG_PPC_FPR0 | 64 1777 + Arch | Register | Width (bits) 1778 + | | 1779 + PPC | KVM_REG_PPC_HIOR | 64 1780 + PPC | KVM_REG_PPC_IAC1 | 64 1781 + PPC | KVM_REG_PPC_IAC2 | 64 1782 + PPC | KVM_REG_PPC_IAC3 | 64 1783 + PPC | KVM_REG_PPC_IAC4 | 64 1784 + PPC | KVM_REG_PPC_DAC1 | 64 1785 + PPC | KVM_REG_PPC_DAC2 | 64 1786 + PPC | KVM_REG_PPC_DABR | 64 1787 + PPC | KVM_REG_PPC_DSCR | 64 1788 + PPC | KVM_REG_PPC_PURR | 64 1789 + PPC | KVM_REG_PPC_SPURR | 64 1790 + PPC | KVM_REG_PPC_DAR | 64 1791 + PPC | KVM_REG_PPC_DSISR | 32 1792 + PPC | KVM_REG_PPC_AMR | 64 1793 + PPC | KVM_REG_PPC_UAMOR | 64 1794 + PPC | KVM_REG_PPC_MMCR0 | 64 1795 + PPC | KVM_REG_PPC_MMCR1 | 64 1796 + PPC | KVM_REG_PPC_MMCRA | 64 1797 + PPC | KVM_REG_PPC_MMCR2 | 64 1798 + PPC | KVM_REG_PPC_MMCRS | 64 1799 + PPC | KVM_REG_PPC_SIAR | 64 1800 + PPC | KVM_REG_PPC_SDAR | 64 1801 + PPC | KVM_REG_PPC_SIER | 64 1802 + PPC | KVM_REG_PPC_PMC1 | 32 1803 + PPC | KVM_REG_PPC_PMC2 | 32 1804 + PPC | KVM_REG_PPC_PMC3 | 32 1805 + PPC | KVM_REG_PPC_PMC4 | 32 1806 + PPC | KVM_REG_PPC_PMC5 | 32 1807 + PPC | KVM_REG_PPC_PMC6 | 32 1808 + PPC | KVM_REG_PPC_PMC7 | 32 1809 + PPC | KVM_REG_PPC_PMC8 | 32 1810 + PPC | KVM_REG_PPC_FPR0 | 64 1834 1811 ... 1835 - PPC | KVM_REG_PPC_FPR31 | 64 1836 - PPC | KVM_REG_PPC_VR0 | 128 1812 + PPC | KVM_REG_PPC_FPR31 | 64 1813 + PPC | KVM_REG_PPC_VR0 | 128 1837 1814 ... 1838 - PPC | KVM_REG_PPC_VR31 | 128 1839 - PPC | KVM_REG_PPC_VSR0 | 128 1815 + PPC | KVM_REG_PPC_VR31 | 128 1816 + PPC | KVM_REG_PPC_VSR0 | 128 1840 1817 ... 1841 - PPC | KVM_REG_PPC_VSR31 | 128 1842 - PPC | KVM_REG_PPC_FPSCR | 64 1843 - PPC | KVM_REG_PPC_VSCR | 32 1844 - PPC | KVM_REG_PPC_VPA_ADDR | 64 1845 - PPC | KVM_REG_PPC_VPA_SLB | 128 1846 - PPC | KVM_REG_PPC_VPA_DTL | 128 1847 - PPC | KVM_REG_PPC_EPCR | 32 1848 - PPC | KVM_REG_PPC_EPR | 32 1849 - PPC | KVM_REG_PPC_TCR | 32 1850 - PPC | KVM_REG_PPC_TSR | 32 1851 - PPC | KVM_REG_PPC_OR_TSR | 32 1852 - PPC | KVM_REG_PPC_CLEAR_TSR | 32 1853 - PPC | KVM_REG_PPC_MAS0 | 32 1854 - PPC | KVM_REG_PPC_MAS1 | 32 1855 - PPC | KVM_REG_PPC_MAS2 | 64 1856 - PPC | KVM_REG_PPC_MAS7_3 | 64 1857 - PPC | KVM_REG_PPC_MAS4 | 32 1858 - PPC | KVM_REG_PPC_MAS6 | 32 1859 - PPC | KVM_REG_PPC_MMUCFG | 32 1860 - PPC | KVM_REG_PPC_TLB0CFG | 32 1861 - PPC | KVM_REG_PPC_TLB1CFG | 32 1862 - PPC | KVM_REG_PPC_TLB2CFG | 32 1863 - PPC | KVM_REG_PPC_TLB3CFG | 32 1864 - PPC | KVM_REG_PPC_TLB0PS | 32 1865 - PPC | KVM_REG_PPC_TLB1PS | 32 1866 - PPC | KVM_REG_PPC_TLB2PS | 32 1867 - PPC | KVM_REG_PPC_TLB3PS | 32 1868 - PPC | KVM_REG_PPC_EPTCFG | 32 1869 - PPC | KVM_REG_PPC_ICP_STATE | 64 1870 - PPC | KVM_REG_PPC_TB_OFFSET | 64 1871 - PPC | KVM_REG_PPC_SPMC1 | 32 1872 - PPC | KVM_REG_PPC_SPMC2 | 32 1873 - PPC | KVM_REG_PPC_IAMR | 64 1874 - PPC | KVM_REG_PPC_TFHAR | 64 1875 - PPC | KVM_REG_PPC_TFIAR | 64 1876 - PPC | KVM_REG_PPC_TEXASR | 64 1877 - PPC | KVM_REG_PPC_FSCR | 64 1878 - PPC | KVM_REG_PPC_PSPB | 32 1879 - PPC | KVM_REG_PPC_EBBHR | 64 1880 - PPC | KVM_REG_PPC_EBBRR | 64 1881 - PPC | KVM_REG_PPC_BESCR | 64 1882 - PPC | KVM_REG_PPC_TAR | 64 1883 - PPC | KVM_REG_PPC_DPDES | 64 1884 - PPC | KVM_REG_PPC_DAWR | 64 1885 - PPC | KVM_REG_PPC_DAWRX | 64 1886 - PPC | KVM_REG_PPC_CIABR | 64 1887 - PPC | KVM_REG_PPC_IC | 64 1888 - PPC | KVM_REG_PPC_VTB | 64 1889 - PPC | KVM_REG_PPC_CSIGR | 64 1890 - PPC | KVM_REG_PPC_TACR | 64 1891 - PPC | KVM_REG_PPC_TCSCR | 64 1892 - PPC | KVM_REG_PPC_PID | 64 1893 - PPC | KVM_REG_PPC_ACOP | 64 1894 - PPC | KVM_REG_PPC_VRSAVE | 32 1895 - PPC | KVM_REG_PPC_LPCR | 64 1896 - PPC | KVM_REG_PPC_PPR | 64 1897 - PPC | KVM_REG_PPC_ARCH_COMPAT 32 1898 - PPC | KVM_REG_PPC_DABRX | 32 1899 - PPC | KVM_REG_PPC_WORT | 64 1900 - PPC | KVM_REG_PPC_TM_GPR0 | 64 1818 + PPC | KVM_REG_PPC_VSR31 | 128 1819 + PPC | KVM_REG_PPC_FPSCR | 64 1820 + PPC | KVM_REG_PPC_VSCR | 32 1821 + PPC | KVM_REG_PPC_VPA_ADDR | 64 1822 + PPC | KVM_REG_PPC_VPA_SLB | 128 1823 + PPC | KVM_REG_PPC_VPA_DTL | 128 1824 + PPC | KVM_REG_PPC_EPCR | 32 1825 + PPC | KVM_REG_PPC_EPR | 32 1826 + PPC | KVM_REG_PPC_TCR | 32 1827 + PPC | KVM_REG_PPC_TSR | 32 1828 + PPC | KVM_REG_PPC_OR_TSR | 32 1829 + PPC | KVM_REG_PPC_CLEAR_TSR | 32 1830 + PPC | KVM_REG_PPC_MAS0 | 32 1831 + PPC | KVM_REG_PPC_MAS1 | 32 1832 + PPC | KVM_REG_PPC_MAS2 | 64 1833 + PPC | KVM_REG_PPC_MAS7_3 | 64 1834 + PPC | KVM_REG_PPC_MAS4 | 32 1835 + PPC | KVM_REG_PPC_MAS6 | 32 1836 + PPC | KVM_REG_PPC_MMUCFG | 32 1837 + PPC | KVM_REG_PPC_TLB0CFG | 32 1838 + PPC | KVM_REG_PPC_TLB1CFG | 32 1839 + PPC | KVM_REG_PPC_TLB2CFG | 32 1840 + PPC | KVM_REG_PPC_TLB3CFG | 32 1841 + PPC | KVM_REG_PPC_TLB0PS | 32 1842 + PPC | KVM_REG_PPC_TLB1PS | 32 1843 + PPC | KVM_REG_PPC_TLB2PS | 32 1844 + PPC | KVM_REG_PPC_TLB3PS | 32 1845 + PPC | KVM_REG_PPC_EPTCFG | 32 1846 + PPC | KVM_REG_PPC_ICP_STATE | 64 1847 + PPC | KVM_REG_PPC_TB_OFFSET | 64 1848 + PPC | KVM_REG_PPC_SPMC1 | 32 1849 + PPC | KVM_REG_PPC_SPMC2 | 32 1850 + PPC | KVM_REG_PPC_IAMR | 64 1851 + PPC | KVM_REG_PPC_TFHAR | 64 1852 + PPC | KVM_REG_PPC_TFIAR | 64 1853 + PPC | KVM_REG_PPC_TEXASR | 64 1854 + PPC | KVM_REG_PPC_FSCR | 64 1855 + PPC | KVM_REG_PPC_PSPB | 32 1856 + PPC | KVM_REG_PPC_EBBHR | 64 1857 + PPC | KVM_REG_PPC_EBBRR | 64 1858 + PPC | KVM_REG_PPC_BESCR | 64 1859 + PPC | KVM_REG_PPC_TAR | 64 1860 + PPC | KVM_REG_PPC_DPDES | 64 1861 + PPC | KVM_REG_PPC_DAWR | 64 1862 + PPC | KVM_REG_PPC_DAWRX | 64 1863 + PPC | KVM_REG_PPC_CIABR | 64 1864 + PPC | KVM_REG_PPC_IC | 64 1865 + PPC | KVM_REG_PPC_VTB | 64 1866 + PPC | KVM_REG_PPC_CSIGR | 64 1867 + PPC | KVM_REG_PPC_TACR | 64 1868 + PPC | KVM_REG_PPC_TCSCR | 64 1869 + PPC | KVM_REG_PPC_PID | 64 1870 + PPC | KVM_REG_PPC_ACOP | 64 1871 + PPC | KVM_REG_PPC_VRSAVE | 32 1872 + PPC | KVM_REG_PPC_LPCR | 64 1873 + PPC | KVM_REG_PPC_PPR | 64 1874 + PPC | KVM_REG_PPC_ARCH_COMPAT | 32 1875 + PPC | KVM_REG_PPC_DABRX | 32 1876 + PPC | KVM_REG_PPC_WORT | 64 1877 + PPC | KVM_REG_PPC_TM_GPR0 | 64 1901 1878 ... 1902 - PPC | KVM_REG_PPC_TM_GPR31 | 64 1903 - PPC | KVM_REG_PPC_TM_VSR0 | 128 1879 + PPC | KVM_REG_PPC_TM_GPR31 | 64 1880 + PPC | KVM_REG_PPC_TM_VSR0 | 128 1904 1881 ... 1905 - PPC | KVM_REG_PPC_TM_VSR63 | 128 1906 - PPC | KVM_REG_PPC_TM_CR | 64 1907 - PPC | KVM_REG_PPC_TM_LR | 64 1908 - PPC | KVM_REG_PPC_TM_CTR | 64 1909 - PPC | KVM_REG_PPC_TM_FPSCR | 64 1910 - PPC | KVM_REG_PPC_TM_AMR | 64 1911 - PPC | KVM_REG_PPC_TM_PPR | 64 1912 - PPC | KVM_REG_PPC_TM_VRSAVE | 64 1913 - PPC | KVM_REG_PPC_TM_VSCR | 32 1914 - PPC | KVM_REG_PPC_TM_DSCR | 64 1915 - PPC | KVM_REG_PPC_TM_TAR | 64 1882 + PPC | KVM_REG_PPC_TM_VSR63 | 128 1883 + PPC | KVM_REG_PPC_TM_CR | 64 1884 + PPC | KVM_REG_PPC_TM_LR | 64 1885 + PPC | KVM_REG_PPC_TM_CTR | 64 1886 + PPC | KVM_REG_PPC_TM_FPSCR | 64 1887 + PPC | KVM_REG_PPC_TM_AMR | 64 1888 + PPC | KVM_REG_PPC_TM_PPR | 64 1889 + PPC | KVM_REG_PPC_TM_VRSAVE | 64 1890 + PPC | KVM_REG_PPC_TM_VSCR | 32 1891 + PPC | KVM_REG_PPC_TM_DSCR | 64 1892 + PPC | KVM_REG_PPC_TM_TAR | 64 1893 + | | 1894 + MIPS | KVM_REG_MIPS_R0 | 64 1895 + ... 1896 + MIPS | KVM_REG_MIPS_R31 | 64 1897 + MIPS | KVM_REG_MIPS_HI | 64 1898 + MIPS | KVM_REG_MIPS_LO | 64 1899 + MIPS | KVM_REG_MIPS_PC | 64 1900 + MIPS | KVM_REG_MIPS_CP0_INDEX | 32 1901 + MIPS | KVM_REG_MIPS_CP0_CONTEXT | 64 1902 + MIPS | KVM_REG_MIPS_CP0_USERLOCAL | 64 1903 + MIPS | KVM_REG_MIPS_CP0_PAGEMASK | 32 1904 + MIPS | KVM_REG_MIPS_CP0_WIRED | 32 1905 + MIPS | KVM_REG_MIPS_CP0_HWRENA | 32 1906 + MIPS | KVM_REG_MIPS_CP0_BADVADDR | 64 1907 + MIPS | KVM_REG_MIPS_CP0_COUNT | 32 1908 + MIPS | KVM_REG_MIPS_CP0_ENTRYHI | 64 1909 + MIPS | KVM_REG_MIPS_CP0_COMPARE | 32 1910 + MIPS | KVM_REG_MIPS_CP0_STATUS | 32 1911 + MIPS | KVM_REG_MIPS_CP0_CAUSE | 32 1912 + MIPS | KVM_REG_MIPS_CP0_EPC | 64 1913 + MIPS | KVM_REG_MIPS_CP0_CONFIG | 32 1914 + MIPS | KVM_REG_MIPS_CP0_CONFIG1 | 32 1915 + MIPS | KVM_REG_MIPS_CP0_CONFIG2 | 32 1916 + MIPS | KVM_REG_MIPS_CP0_CONFIG3 | 32 1917 + MIPS | KVM_REG_MIPS_CP0_CONFIG7 | 32 1918 + MIPS | KVM_REG_MIPS_CP0_ERROREPC | 64 1919 + MIPS | KVM_REG_MIPS_COUNT_CTL | 64 1920 + MIPS | KVM_REG_MIPS_COUNT_RESUME | 64 1921 + MIPS | KVM_REG_MIPS_COUNT_HZ | 64 1916 1922 1917 1923 ARM registers are mapped using the lower 32 bits. The upper 16 of that 1918 1924 is the register group type, or coprocessor number: ··· 1979 1927 1980 1928 arm64 system registers have the following id bit patterns: 1981 1929 0x6030 0000 0013 <op0:2> <op1:3> <crn:4> <crm:4> <op2:3> 1930 + 1931 + 1932 + MIPS registers are mapped using the lower 32 bits. The upper 16 of that is 1933 + the register group type: 1934 + 1935 + MIPS core registers (see above) have the following id bit patterns: 1936 + 0x7030 0000 0000 <reg:16> 1937 + 1938 + MIPS CP0 registers (see KVM_REG_MIPS_CP0_* above) have the following id bit 1939 + patterns depending on whether they're 32-bit or 64-bit registers: 1940 + 0x7020 0000 0001 00 <reg:5> <sel:3> (32-bit) 1941 + 0x7030 0000 0001 00 <reg:5> <sel:3> (64-bit) 1942 + 1943 + MIPS KVM control registers (see above) have the following id bit patterns: 1944 + 0x7030 0000 0002 <reg:16> 1945 + 1982 1946 1983 1947 4.69 KVM_GET_ONE_REG 1984 1948 ··· 2483 2415 4.84 KVM_GET_REG_LIST 2484 2416 2485 2417 Capability: basic 2486 - Architectures: arm, arm64 2418 + Architectures: arm, arm64, mips 2487 2419 Type: vcpu ioctl 2488 2420 Parameters: struct kvm_reg_list (in/out) 2489 2421 Returns: 0 on success; -1 on error ··· 2934 2866 6. Capabilities that can be enabled 2935 2867 ----------------------------------- 2936 2868 2937 - There are certain capabilities that change the behavior of the virtual CPU when 2938 - enabled. To enable them, please see section 4.37. Below you can find a list of 2939 - capabilities and what their effect on the vCPU is when enabling them. 2869 + There are certain capabilities that change the behavior of the virtual CPU or 2870 + the virtual machine when enabled. To enable them, please see section 4.37. 2871 + Below you can find a list of capabilities and what their effect on the vCPU or 2872 + the virtual machine is when enabling them. 2940 2873 2941 2874 The following information is provided along with the description: 2942 2875 2943 2876 Architectures: which instruction set architectures provide this ioctl. 2944 2877 x86 includes both i386 and x86_64. 2878 + 2879 + Target: whether this is a per-vcpu or per-vm capability. 2945 2880 2946 2881 Parameters: what parameters are accepted by the capability. 2947 2882 ··· 2955 2884 6.1 KVM_CAP_PPC_OSI 2956 2885 2957 2886 Architectures: ppc 2887 + Target: vcpu 2958 2888 Parameters: none 2959 2889 Returns: 0 on success; -1 on error 2960 2890 ··· 2970 2898 6.2 KVM_CAP_PPC_PAPR 2971 2899 2972 2900 Architectures: ppc 2901 + Target: vcpu 2973 2902 Parameters: none 2974 2903 Returns: 0 on success; -1 on error 2975 2904 ··· 2990 2917 6.3 KVM_CAP_SW_TLB 2991 2918 2992 2919 Architectures: ppc 2920 + Target: vcpu 2993 2921 Parameters: args[0] is the address of a struct kvm_config_tlb 2994 2922 Returns: 0 on success; -1 on error 2995 2923 ··· 3033 2959 6.4 KVM_CAP_S390_CSS_SUPPORT 3034 2960 3035 2961 Architectures: s390 2962 + Target: vcpu 3036 2963 Parameters: none 3037 2964 Returns: 0 on success; -1 on error 3038 2965 ··· 3045 2970 When this capability is enabled, KVM_EXIT_S390_TSCH will occur on TEST 3046 2971 SUBCHANNEL intercepts. 3047 2972 2973 + Note that even though this capability is enabled per-vcpu, the complete 2974 + virtual machine is affected. 2975 + 3048 2976 6.5 KVM_CAP_PPC_EPR 3049 2977 3050 2978 Architectures: ppc 2979 + Target: vcpu 3051 2980 Parameters: args[0] defines whether the proxy facility is active 3052 2981 Returns: 0 on success; -1 on error 3053 2982 ··· 3077 2998 6.7 KVM_CAP_IRQ_XICS 3078 2999 3079 3000 Architectures: ppc 3001 + Target: vcpu 3080 3002 Parameters: args[0] is the XICS device fd 3081 3003 args[1] is the XICS CPU number (server ID) for this vcpu 3082 3004 3083 3005 This capability connects the vcpu to an in-kernel XICS device. 3006 + 3007 + 6.8 KVM_CAP_S390_IRQCHIP 3008 + 3009 + Architectures: s390 3010 + Target: vm 3011 + Parameters: none 3012 + 3013 + This capability enables the in-kernel irqchip for s390. Please refer to 3014 + "4.24 KVM_CREATE_IRQCHIP" for details.
+8 -4
arch/mips/include/asm/kvm_host.h
··· 359 359 #define MIPS3_PG_FRAME 0x3fffffc0 360 360 361 361 #define VPN2_MASK 0xffffe000 362 - #define TLB_IS_GLOBAL(x) (((x).tlb_lo0 & MIPS3_PG_G) && \ 362 + #define TLB_IS_GLOBAL(x) (((x).tlb_lo0 & MIPS3_PG_G) && \ 363 363 ((x).tlb_lo1 & MIPS3_PG_G)) 364 364 #define TLB_VPN2(x) ((x).tlb_hi & VPN2_MASK) 365 365 #define TLB_ASID(x) ((x).tlb_hi & ASID_MASK) 366 - #define TLB_IS_VALID(x, va) (((va) & (1 << PAGE_SHIFT)) \ 367 - ? ((x).tlb_lo1 & MIPS3_PG_V) \ 366 + #define TLB_IS_VALID(x, va) (((va) & (1 << PAGE_SHIFT)) \ 367 + ? ((x).tlb_lo1 & MIPS3_PG_V) \ 368 368 : ((x).tlb_lo0 & MIPS3_PG_V)) 369 + #define TLB_HI_VPN2_HIT(x, y) ((TLB_VPN2(x) & ~(x).tlb_mask) == \ 370 + ((y) & VPN2_MASK & ~(x).tlb_mask)) 371 + #define TLB_HI_ASID_HIT(x, y) (TLB_IS_GLOBAL(x) || \ 372 + TLB_ASID(x) == ((y) & ASID_MASK)) 369 373 370 374 struct kvm_mips_tlb { 371 375 long tlb_mask; ··· 764 760 struct kvm_vcpu *vcpu); 765 761 766 762 /* Misc */ 767 - extern int kvm_mips_dump_stats(struct kvm_vcpu *vcpu); 763 + extern void kvm_mips_dump_stats(struct kvm_vcpu *vcpu); 768 764 extern unsigned long kvm_mips_get_ramsize(struct kvm *kvm); 769 765 770 766
+3
arch/mips/include/asm/r4kcache.h
··· 19 19 #include <asm/mipsmtregs.h> 20 20 #include <asm/uaccess.h> /* for segment_eq() */ 21 21 22 + extern void (*r4k_blast_dcache)(void); 23 + extern void (*r4k_blast_icache)(void); 24 + 22 25 /* 23 26 * This macro return a properly sign-extended address suitable as base address 24 27 * for indexed cache operations. Two issues here:
+4 -4
arch/mips/kvm/Makefile
··· 5 5 6 6 EXTRA_CFLAGS += -Ivirt/kvm -Iarch/mips/kvm 7 7 8 - kvm-objs := $(common-objs) kvm_mips.o kvm_mips_emul.o kvm_locore.o \ 9 - kvm_mips_int.o kvm_mips_stats.o kvm_mips_commpage.o \ 10 - kvm_mips_dyntrans.o kvm_trap_emul.o 8 + kvm-objs := $(common-objs) mips.o emulate.o locore.o \ 9 + interrupt.o stats.o commpage.o \ 10 + dyntrans.o trap_emul.o 11 11 12 12 obj-$(CONFIG_KVM) += kvm.o 13 - obj-y += kvm_cb.o kvm_tlb.o 13 + obj-y += callback.o tlb.o
+33
arch/mips/kvm/commpage.c
··· 1 + /* 2 + * This file is subject to the terms and conditions of the GNU General Public 3 + * License. See the file "COPYING" in the main directory of this archive 4 + * for more details. 5 + * 6 + * commpage, currently used for Virtual COP0 registers. 7 + * Mapped into the guest kernel @ 0x0. 8 + * 9 + * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 10 + * Authors: Sanjay Lal <sanjayl@kymasys.com> 11 + */ 12 + 13 + #include <linux/errno.h> 14 + #include <linux/err.h> 15 + #include <linux/module.h> 16 + #include <linux/vmalloc.h> 17 + #include <linux/fs.h> 18 + #include <linux/bootmem.h> 19 + #include <asm/page.h> 20 + #include <asm/cacheflush.h> 21 + #include <asm/mmu_context.h> 22 + 23 + #include <linux/kvm_host.h> 24 + 25 + #include "commpage.h" 26 + 27 + void kvm_mips_commpage_init(struct kvm_vcpu *vcpu) 28 + { 29 + struct kvm_mips_commpage *page = vcpu->arch.kseg0_commpage; 30 + 31 + /* Specific init values for fields */ 32 + vcpu->arch.cop0 = &page->cop0; 33 + }
+24
arch/mips/kvm/commpage.h
··· 1 + /* 2 + * This file is subject to the terms and conditions of the GNU General Public 3 + * License. See the file "COPYING" in the main directory of this archive 4 + * for more details. 5 + * 6 + * KVM/MIPS: commpage: mapped into get kernel space 7 + * 8 + * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 9 + * Authors: Sanjay Lal <sanjayl@kymasys.com> 10 + */ 11 + 12 + #ifndef __KVM_MIPS_COMMPAGE_H__ 13 + #define __KVM_MIPS_COMMPAGE_H__ 14 + 15 + struct kvm_mips_commpage { 16 + /* COP0 state is mapped into Guest kernel via commpage */ 17 + struct mips_coproc cop0; 18 + }; 19 + 20 + #define KVM_MIPS_COMM_EIDI_OFFSET 0x0 21 + 22 + extern void kvm_mips_commpage_init(struct kvm_vcpu *vcpu); 23 + 24 + #endif /* __KVM_MIPS_COMMPAGE_H__ */
arch/mips/kvm/kvm_cb.c arch/mips/kvm/callback.c
+31 -24
arch/mips/kvm/kvm_locore.S arch/mips/kvm/locore.S
··· 16 16 #include <asm/stackframe.h> 17 17 #include <asm/asm-offsets.h> 18 18 19 - 20 19 #define _C_LABEL(x) x 21 20 #define MIPSX(name) mips32_ ## name 22 21 #define CALLFRAME_SIZ 32 ··· 90 91 LONG_S $24, PT_R24(k1) 91 92 LONG_S $25, PT_R25(k1) 92 93 93 - /* XXXKYMA k0/k1 not saved, not being used if we got here through an ioctl() */ 94 + /* 95 + * XXXKYMA k0/k1 not saved, not being used if we got here through 96 + * an ioctl() 97 + */ 94 98 95 99 LONG_S $28, PT_R28(k1) 96 100 LONG_S $29, PT_R29(k1) ··· 134 132 /* Save the kernel gp as well */ 135 133 LONG_S gp, VCPU_HOST_GP(k1) 136 134 137 - /* Setup status register for running the guest in UM, interrupts are disabled */ 135 + /* 136 + * Setup status register for running the guest in UM, interrupts 137 + * are disabled 138 + */ 138 139 li k0, (ST0_EXL | KSU_USER | ST0_BEV) 139 140 mtc0 k0, CP0_STATUS 140 141 ehb ··· 157 152 mtc0 k0, CP0_STATUS 158 153 ehb 159 154 160 - 161 155 /* Set Guest EPC */ 162 156 LONG_L t0, VCPU_PC(k1) 163 157 mtc0 t0, CP0_EPC ··· 169 165 INT_ADDIU t1, k1, VCPU_GUEST_KERNEL_ASID /* (BD) */ 170 166 INT_ADDIU t1, k1, VCPU_GUEST_USER_ASID /* else user */ 171 167 1: 172 - /* t1: contains the base of the ASID array, need to get the cpu id */ 168 + /* t1: contains the base of the ASID array, need to get the cpu id */ 173 169 LONG_L t2, TI_CPU($28) /* smp_processor_id */ 174 170 INT_SLL t2, t2, 2 /* x4 */ 175 171 REG_ADDU t3, t1, t2 ··· 233 229 eret 234 230 235 231 VECTOR(MIPSX(exception), unknown) 236 - /* 237 - * Find out what mode we came from and jump to the proper handler. 238 - */ 232 + /* Find out what mode we came from and jump to the proper handler. */ 239 233 mtc0 k0, CP0_ERROREPC #01: Save guest k0 240 234 ehb #02: 241 235 ··· 241 239 INT_SRL k0, k0, 10 #03: Get rid of CPUNum 242 240 INT_SLL k0, k0, 10 #04 243 241 LONG_S k1, 0x3000(k0) #05: Save k1 @ offset 0x3000 244 - INT_ADDIU k0, k0, 0x2000 #06: Exception handler is installed @ offset 0x2000 242 + INT_ADDIU k0, k0, 0x2000 #06: Exception handler is 243 + # installed @ offset 0x2000 245 244 j k0 #07: jump to the function 246 245 nop #08: branch delay slot 247 246 VECTOR_END(MIPSX(exceptionEnd)) ··· 251 248 /* 252 249 * Generic Guest exception handler. We end up here when the guest 253 250 * does something that causes a trap to kernel mode. 254 - * 255 251 */ 256 252 NESTED (MIPSX(GuestException), CALLFRAME_SIZ, ra) 257 253 /* Get the VCPU pointer from DDTATA_LO */ ··· 292 290 LONG_S $30, VCPU_R30(k1) 293 291 LONG_S $31, VCPU_R31(k1) 294 292 295 - /* We need to save hi/lo and restore them on 296 - * the way out 297 - */ 293 + /* We need to save hi/lo and restore them on the way out */ 298 294 mfhi t0 299 295 LONG_S t0, VCPU_HI(k1) 300 296 ··· 321 321 /* Save pointer to run in s0, will be saved by the compiler */ 322 322 move s0, a0 323 323 324 - /* Save Host level EPC, BadVaddr and Cause to VCPU, useful to 325 - * process the exception */ 324 + /* 325 + * Save Host level EPC, BadVaddr and Cause to VCPU, useful to 326 + * process the exception 327 + */ 326 328 mfc0 k0,CP0_EPC 327 329 LONG_S k0, VCPU_PC(k1) 328 330 ··· 353 351 LONG_L k0, VCPU_HOST_EBASE(k1) 354 352 mtc0 k0,CP0_EBASE 355 353 356 - 357 354 /* Now that the new EBASE has been loaded, unset BEV and KSU_USER */ 358 355 .set at 359 356 and v0, v0, ~(ST0_EXL | KSU_USER | ST0_IE) ··· 370 369 /* Saved host state */ 371 370 INT_ADDIU sp, sp, -PT_SIZE 372 371 373 - /* XXXKYMA do we need to load the host ASID, maybe not because the 372 + /* 373 + * XXXKYMA do we need to load the host ASID, maybe not because the 374 374 * kernel entries are marked GLOBAL, need to verify 375 375 */ 376 376 ··· 385 383 386 384 /* Jump to handler */ 387 385 FEXPORT(__kvm_mips_jump_to_handler) 388 - /* XXXKYMA: not sure if this is safe, how large is the stack?? 386 + /* 387 + * XXXKYMA: not sure if this is safe, how large is the stack?? 389 388 * Now jump to the kvm_mips_handle_exit() to see if we can deal 390 - * with this in the kernel */ 389 + * with this in the kernel 390 + */ 391 391 PTR_LA t9, kvm_mips_handle_exit 392 392 jalr.hb t9 393 393 INT_ADDIU sp, sp, -CALLFRAME_SIZ /* BD Slot */ ··· 398 394 di 399 395 ehb 400 396 401 - /* XXXKYMA: k0/k1 could have been blown away if we processed 397 + /* 398 + * XXXKYMA: k0/k1 could have been blown away if we processed 402 399 * an exception while we were handling the exception from the 403 400 * guest, reload k1 404 401 */ ··· 407 402 move k1, s1 408 403 INT_ADDIU k1, k1, VCPU_HOST_ARCH 409 404 410 - /* Check return value, should tell us if we are returning to the 405 + /* 406 + * Check return value, should tell us if we are returning to the 411 407 * host (handle I/O etc)or resuming the guest 412 408 */ 413 409 andi t0, v0, RESUME_HOST ··· 527 521 LONG_L $0, PT_R0(k1) 528 522 LONG_L $1, PT_R1(k1) 529 523 530 - /* r2/v0 is the return code, shift it down by 2 (arithmetic) 531 - * to recover the err code */ 524 + /* 525 + * r2/v0 is the return code, shift it down by 2 (arithmetic) 526 + * to recover the err code 527 + */ 532 528 INT_SRA k0, v0, 2 533 529 move $2, k0 534 530 ··· 573 565 /* Restore RDHWR access */ 574 566 PTR_LI k0, 0x2000000F 575 567 mtc0 k0, CP0_HWRENA 576 - 577 568 578 569 /* Restore RA, which is the address we will return to */ 579 570 LONG_L ra, PT_R31(k1)
+108 -116
arch/mips/kvm/kvm_mips.c arch/mips/kvm/mips.c
··· 7 7 * 8 8 * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 9 9 * Authors: Sanjay Lal <sanjayl@kymasys.com> 10 - */ 10 + */ 11 11 12 12 #include <linux/errno.h> 13 13 #include <linux/err.h> ··· 21 21 22 22 #include <linux/kvm_host.h> 23 23 24 - #include "kvm_mips_int.h" 25 - #include "kvm_mips_comm.h" 24 + #include "interrupt.h" 25 + #include "commpage.h" 26 26 27 27 #define CREATE_TRACE_POINTS 28 28 #include "trace.h" ··· 31 31 #define VECTORSPACING 0x100 /* for EI/VI mode */ 32 32 #endif 33 33 34 - #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU 34 + #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x) 35 35 struct kvm_stats_debugfs_item debugfs_entries[] = { 36 - { "wait", VCPU_STAT(wait_exits) }, 37 - { "cache", VCPU_STAT(cache_exits) }, 38 - { "signal", VCPU_STAT(signal_exits) }, 39 - { "interrupt", VCPU_STAT(int_exits) }, 40 - { "cop_unsuable", VCPU_STAT(cop_unusable_exits) }, 41 - { "tlbmod", VCPU_STAT(tlbmod_exits) }, 42 - { "tlbmiss_ld", VCPU_STAT(tlbmiss_ld_exits) }, 43 - { "tlbmiss_st", VCPU_STAT(tlbmiss_st_exits) }, 44 - { "addrerr_st", VCPU_STAT(addrerr_st_exits) }, 45 - { "addrerr_ld", VCPU_STAT(addrerr_ld_exits) }, 46 - { "syscall", VCPU_STAT(syscall_exits) }, 47 - { "resvd_inst", VCPU_STAT(resvd_inst_exits) }, 48 - { "break_inst", VCPU_STAT(break_inst_exits) }, 49 - { "flush_dcache", VCPU_STAT(flush_dcache_exits) }, 50 - { "halt_wakeup", VCPU_STAT(halt_wakeup) }, 36 + { "wait", VCPU_STAT(wait_exits), KVM_STAT_VCPU }, 37 + { "cache", VCPU_STAT(cache_exits), KVM_STAT_VCPU }, 38 + { "signal", VCPU_STAT(signal_exits), KVM_STAT_VCPU }, 39 + { "interrupt", VCPU_STAT(int_exits), KVM_STAT_VCPU }, 40 + { "cop_unsuable", VCPU_STAT(cop_unusable_exits), KVM_STAT_VCPU }, 41 + { "tlbmod", VCPU_STAT(tlbmod_exits), KVM_STAT_VCPU }, 42 + { "tlbmiss_ld", VCPU_STAT(tlbmiss_ld_exits), KVM_STAT_VCPU }, 43 + { "tlbmiss_st", VCPU_STAT(tlbmiss_st_exits), KVM_STAT_VCPU }, 44 + { "addrerr_st", VCPU_STAT(addrerr_st_exits), KVM_STAT_VCPU }, 45 + { "addrerr_ld", VCPU_STAT(addrerr_ld_exits), KVM_STAT_VCPU }, 46 + { "syscall", VCPU_STAT(syscall_exits), KVM_STAT_VCPU }, 47 + { "resvd_inst", VCPU_STAT(resvd_inst_exits), KVM_STAT_VCPU }, 48 + { "break_inst", VCPU_STAT(break_inst_exits), KVM_STAT_VCPU }, 49 + { "flush_dcache", VCPU_STAT(flush_dcache_exits), KVM_STAT_VCPU }, 50 + { "halt_wakeup", VCPU_STAT(halt_wakeup), KVM_STAT_VCPU }, 51 51 {NULL} 52 52 }; 53 53 54 54 static int kvm_mips_reset_vcpu(struct kvm_vcpu *vcpu) 55 55 { 56 56 int i; 57 + 57 58 for_each_possible_cpu(i) { 58 59 vcpu->arch.guest_kernel_asid[i] = 0; 59 60 vcpu->arch.guest_user_asid[i] = 0; 60 61 } 62 + 61 63 return 0; 62 64 } 63 65 64 - /* XXXKYMA: We are simulatoring a processor that has the WII bit set in Config7, so we 65 - * are "runnable" if interrupts are pending 66 + /* 67 + * XXXKYMA: We are simulatoring a processor that has the WII bit set in 68 + * Config7, so we are "runnable" if interrupts are pending 66 69 */ 67 70 int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu) 68 71 { ··· 97 94 98 95 void kvm_arch_check_processor_compat(void *rtn) 99 96 { 100 - int *r = (int *)rtn; 101 - *r = 0; 102 - return; 97 + *(int *)rtn = 0; 103 98 } 104 99 105 100 static void kvm_mips_init_tlbs(struct kvm *kvm) 106 101 { 107 102 unsigned long wired; 108 103 109 - /* Add a wired entry to the TLB, it is used to map the commpage to the Guest kernel */ 104 + /* 105 + * Add a wired entry to the TLB, it is used to map the commpage to 106 + * the Guest kernel 107 + */ 110 108 wired = read_c0_wired(); 111 109 write_c0_wired(wired + 1); 112 110 mtc0_tlbw_hazard(); ··· 133 129 __func__); 134 130 on_each_cpu(kvm_mips_init_vm_percpu, kvm, 1); 135 131 } 136 - 137 132 138 133 return 0; 139 134 } ··· 188 185 } 189 186 } 190 187 191 - long 192 - kvm_arch_dev_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) 188 + long kvm_arch_dev_ioctl(struct file *filp, unsigned int ioctl, 189 + unsigned long arg) 193 190 { 194 191 return -ENOIOCTLCMD; 195 192 } ··· 210 207 } 211 208 212 209 int kvm_arch_prepare_memory_region(struct kvm *kvm, 213 - struct kvm_memory_slot *memslot, 214 - struct kvm_userspace_memory_region *mem, 215 - enum kvm_mr_change change) 210 + struct kvm_memory_slot *memslot, 211 + struct kvm_userspace_memory_region *mem, 212 + enum kvm_mr_change change) 216 213 { 217 214 return 0; 218 215 } 219 216 220 217 void kvm_arch_commit_memory_region(struct kvm *kvm, 221 - struct kvm_userspace_memory_region *mem, 222 - const struct kvm_memory_slot *old, 223 - enum kvm_mr_change change) 218 + struct kvm_userspace_memory_region *mem, 219 + const struct kvm_memory_slot *old, 220 + enum kvm_mr_change change) 224 221 { 225 222 unsigned long npages = 0; 226 - int i, err = 0; 223 + int i; 227 224 228 225 kvm_debug("%s: kvm: %p slot: %d, GPA: %llx, size: %llx, QVA: %llx\n", 229 226 __func__, kvm, mem->slot, mem->guest_phys_addr, ··· 241 238 242 239 if (!kvm->arch.guest_pmap) { 243 240 kvm_err("Failed to allocate guest PMAP"); 244 - err = -ENOMEM; 245 - goto out; 241 + return; 246 242 } 247 243 248 244 kvm_debug("Allocated space for Guest PMAP Table (%ld pages) @ %p\n", 249 245 npages, kvm->arch.guest_pmap); 250 246 251 247 /* Now setup the page table */ 252 - for (i = 0; i < npages; i++) { 248 + for (i = 0; i < npages; i++) 253 249 kvm->arch.guest_pmap[i] = KVM_INVALID_PAGE; 254 - } 255 250 } 256 251 } 257 - out: 258 - return; 259 252 } 260 253 261 254 void kvm_arch_flush_shadow_all(struct kvm *kvm) ··· 269 270 270 271 struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id) 271 272 { 272 - extern char mips32_exception[], mips32_exceptionEnd[]; 273 - extern char mips32_GuestException[], mips32_GuestExceptionEnd[]; 274 273 int err, size, offset; 275 274 void *gebase; 276 275 int i; ··· 287 290 288 291 kvm_debug("kvm @ %p: create cpu %d at %p\n", kvm, id, vcpu); 289 292 290 - /* Allocate space for host mode exception handlers that handle 293 + /* 294 + * Allocate space for host mode exception handlers that handle 291 295 * guest mode exits 292 296 */ 293 - if (cpu_has_veic || cpu_has_vint) { 297 + if (cpu_has_veic || cpu_has_vint) 294 298 size = 0x200 + VECTORSPACING * 64; 295 - } else { 299 + else 296 300 size = 0x4000; 297 - } 298 301 299 302 /* Save Linux EBASE */ 300 303 vcpu->arch.host_ebase = (void *)read_c0_ebase(); ··· 342 345 local_flush_icache_range((unsigned long)gebase, 343 346 (unsigned long)gebase + ALIGN(size, PAGE_SIZE)); 344 347 345 - /* Allocate comm page for guest kernel, a TLB will be reserved for mapping GVA @ 0xFFFF8000 to this page */ 348 + /* 349 + * Allocate comm page for guest kernel, a TLB will be reserved for 350 + * mapping GVA @ 0xFFFF8000 to this page 351 + */ 346 352 vcpu->arch.kseg0_commpage = kzalloc(PAGE_SIZE << 1, GFP_KERNEL); 347 353 348 354 if (!vcpu->arch.kseg0_commpage) { ··· 392 392 kvm_arch_vcpu_free(vcpu); 393 393 } 394 394 395 - int 396 - kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, 397 - struct kvm_guest_debug *dbg) 395 + int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, 396 + struct kvm_guest_debug *dbg) 398 397 { 399 398 return -ENOIOCTLCMD; 400 399 } ··· 430 431 return r; 431 432 } 432 433 433 - int 434 - kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, struct kvm_mips_interrupt *irq) 434 + int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, 435 + struct kvm_mips_interrupt *irq) 435 436 { 436 437 int intr = (int)irq->irq; 437 438 struct kvm_vcpu *dvcpu = NULL; ··· 458 459 459 460 dvcpu->arch.wait = 0; 460 461 461 - if (waitqueue_active(&dvcpu->wq)) { 462 + if (waitqueue_active(&dvcpu->wq)) 462 463 wake_up_interruptible(&dvcpu->wq); 463 - } 464 464 465 465 return 0; 466 466 } 467 467 468 - int 469 - kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu, 470 - struct kvm_mp_state *mp_state) 468 + int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu, 469 + struct kvm_mp_state *mp_state) 471 470 { 472 471 return -ENOIOCTLCMD; 473 472 } 474 473 475 - int 476 - kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, 477 - struct kvm_mp_state *mp_state) 474 + int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, 475 + struct kvm_mp_state *mp_state) 478 476 { 479 477 return -ENOIOCTLCMD; 480 478 } ··· 628 632 } 629 633 if ((reg->id & KVM_REG_SIZE_MASK) == KVM_REG_SIZE_U64) { 630 634 u64 __user *uaddr64 = (u64 __user *)(long)reg->addr; 635 + 631 636 return put_user(v, uaddr64); 632 637 } else if ((reg->id & KVM_REG_SIZE_MASK) == KVM_REG_SIZE_U32) { 633 638 u32 __user *uaddr32 = (u32 __user *)(long)reg->addr; 634 639 u32 v32 = (u32)v; 640 + 635 641 return put_user(v32, uaddr32); 636 642 } else { 637 643 return -EINVAL; ··· 726 728 return 0; 727 729 } 728 730 729 - long 730 - kvm_arch_vcpu_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) 731 + long kvm_arch_vcpu_ioctl(struct file *filp, unsigned int ioctl, 732 + unsigned long arg) 731 733 { 732 734 struct kvm_vcpu *vcpu = filp->private_data; 733 735 void __user *argp = (void __user *)arg; ··· 737 739 case KVM_SET_ONE_REG: 738 740 case KVM_GET_ONE_REG: { 739 741 struct kvm_one_reg reg; 742 + 740 743 if (copy_from_user(&reg, argp, sizeof(reg))) 741 744 return -EFAULT; 742 745 if (ioctl == KVM_SET_ONE_REG) ··· 772 773 case KVM_INTERRUPT: 773 774 { 774 775 struct kvm_mips_interrupt irq; 776 + 775 777 r = -EFAULT; 776 778 if (copy_from_user(&irq, argp, sizeof(irq))) 777 779 goto out; ··· 791 791 return r; 792 792 } 793 793 794 - /* 795 - * Get (and clear) the dirty memory log for a memory slot. 796 - */ 794 + /* Get (and clear) the dirty memory log for a memory slot. */ 797 795 int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log) 798 796 { 799 797 struct kvm_memory_slot *memslot; ··· 813 815 ga = memslot->base_gfn << PAGE_SHIFT; 814 816 ga_end = ga + (memslot->npages << PAGE_SHIFT); 815 817 816 - printk("%s: dirty, ga: %#lx, ga_end %#lx\n", __func__, ga, 817 - ga_end); 818 + kvm_info("%s: dirty, ga: %#lx, ga_end %#lx\n", __func__, ga, 819 + ga_end); 818 820 819 821 n = kvm_dirty_bitmap_bytes(memslot); 820 822 memset(memslot->dirty_bitmap, 0, n); ··· 841 843 842 844 int kvm_arch_init(void *opaque) 843 845 { 844 - int ret; 845 - 846 846 if (kvm_mips_callbacks) { 847 847 kvm_err("kvm: module already exists\n"); 848 848 return -EEXIST; 849 849 } 850 850 851 - ret = kvm_mips_emulation_init(&kvm_mips_callbacks); 852 - 853 - return ret; 851 + return kvm_mips_emulation_init(&kvm_mips_callbacks); 854 852 } 855 853 856 854 void kvm_arch_exit(void) ··· 854 860 kvm_mips_callbacks = NULL; 855 861 } 856 862 857 - int 858 - kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) 863 + int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, 864 + struct kvm_sregs *sregs) 859 865 { 860 866 return -ENOIOCTLCMD; 861 867 } 862 868 863 - int 864 - kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) 869 + int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, 870 + struct kvm_sregs *sregs) 865 871 { 866 872 return -ENOIOCTLCMD; 867 873 } ··· 917 923 if (!vcpu) 918 924 return -1; 919 925 920 - printk("VCPU Register Dump:\n"); 921 - printk("\tpc = 0x%08lx\n", vcpu->arch.pc); 922 - printk("\texceptions: %08lx\n", vcpu->arch.pending_exceptions); 926 + kvm_debug("VCPU Register Dump:\n"); 927 + kvm_debug("\tpc = 0x%08lx\n", vcpu->arch.pc); 928 + kvm_debug("\texceptions: %08lx\n", vcpu->arch.pending_exceptions); 923 929 924 930 for (i = 0; i < 32; i += 4) { 925 - printk("\tgpr%02d: %08lx %08lx %08lx %08lx\n", i, 931 + kvm_debug("\tgpr%02d: %08lx %08lx %08lx %08lx\n", i, 926 932 vcpu->arch.gprs[i], 927 933 vcpu->arch.gprs[i + 1], 928 934 vcpu->arch.gprs[i + 2], vcpu->arch.gprs[i + 3]); 929 935 } 930 - printk("\thi: 0x%08lx\n", vcpu->arch.hi); 931 - printk("\tlo: 0x%08lx\n", vcpu->arch.lo); 936 + kvm_debug("\thi: 0x%08lx\n", vcpu->arch.hi); 937 + kvm_debug("\tlo: 0x%08lx\n", vcpu->arch.lo); 932 938 933 939 cop0 = vcpu->arch.cop0; 934 - printk("\tStatus: 0x%08lx, Cause: 0x%08lx\n", 935 - kvm_read_c0_guest_status(cop0), kvm_read_c0_guest_cause(cop0)); 940 + kvm_debug("\tStatus: 0x%08lx, Cause: 0x%08lx\n", 941 + kvm_read_c0_guest_status(cop0), 942 + kvm_read_c0_guest_cause(cop0)); 936 943 937 - printk("\tEPC: 0x%08lx\n", kvm_read_c0_guest_epc(cop0)); 944 + kvm_debug("\tEPC: 0x%08lx\n", kvm_read_c0_guest_epc(cop0)); 938 945 939 946 return 0; 940 947 } ··· 975 980 kvm_mips_callbacks->queue_timer_int(vcpu); 976 981 977 982 vcpu->arch.wait = 0; 978 - if (waitqueue_active(&vcpu->wq)) { 983 + if (waitqueue_active(&vcpu->wq)) 979 984 wake_up_interruptible(&vcpu->wq); 980 - } 981 985 } 982 986 983 - /* 984 - * low level hrtimer wake routine. 985 - */ 987 + /* low level hrtimer wake routine */ 986 988 static enum hrtimer_restart kvm_mips_comparecount_wakeup(struct hrtimer *timer) 987 989 { 988 990 struct kvm_vcpu *vcpu; ··· 1000 1008 1001 1009 void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) 1002 1010 { 1003 - return; 1004 1011 } 1005 1012 1006 - int 1007 - kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, struct kvm_translation *tr) 1013 + int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, 1014 + struct kvm_translation *tr) 1008 1015 { 1009 1016 return 0; 1010 1017 } ··· 1014 1023 return kvm_mips_callbacks->vcpu_setup(vcpu); 1015 1024 } 1016 1025 1017 - static 1018 - void kvm_mips_set_c0_status(void) 1026 + static void kvm_mips_set_c0_status(void) 1019 1027 { 1020 1028 uint32_t status = read_c0_status(); 1021 1029 ··· 1044 1054 run->exit_reason = KVM_EXIT_UNKNOWN; 1045 1055 run->ready_for_interrupt_injection = 1; 1046 1056 1047 - /* Set the appropriate status bits based on host CPU features, before we hit the scheduler */ 1057 + /* 1058 + * Set the appropriate status bits based on host CPU features, 1059 + * before we hit the scheduler 1060 + */ 1048 1061 kvm_mips_set_c0_status(); 1049 1062 1050 1063 local_irq_enable(); ··· 1055 1062 kvm_debug("kvm_mips_handle_exit: cause: %#x, PC: %p, kvm_run: %p, kvm_vcpu: %p\n", 1056 1063 cause, opc, run, vcpu); 1057 1064 1058 - /* Do a privilege check, if in UM most of these exit conditions end up 1065 + /* 1066 + * Do a privilege check, if in UM most of these exit conditions end up 1059 1067 * causing an exception to be delivered to the Guest Kernel 1060 1068 */ 1061 1069 er = kvm_mips_check_privilege(cause, opc, run, vcpu); ··· 1075 1081 ++vcpu->stat.int_exits; 1076 1082 trace_kvm_exit(vcpu, INT_EXITS); 1077 1083 1078 - if (need_resched()) { 1084 + if (need_resched()) 1079 1085 cond_resched(); 1080 - } 1081 1086 1082 1087 ret = RESUME_GUEST; 1083 1088 break; ··· 1088 1095 trace_kvm_exit(vcpu, COP_UNUSABLE_EXITS); 1089 1096 ret = kvm_mips_callbacks->handle_cop_unusable(vcpu); 1090 1097 /* XXXKYMA: Might need to return to user space */ 1091 - if (run->exit_reason == KVM_EXIT_IRQ_WINDOW_OPEN) { 1098 + if (run->exit_reason == KVM_EXIT_IRQ_WINDOW_OPEN) 1092 1099 ret = RESUME_HOST; 1093 - } 1094 1100 break; 1095 1101 1096 1102 case T_TLB_MOD: ··· 1099 1107 break; 1100 1108 1101 1109 case T_TLB_ST_MISS: 1102 - kvm_debug 1103 - ("TLB ST fault: cause %#x, status %#lx, PC: %p, BadVaddr: %#lx\n", 1104 - cause, kvm_read_c0_guest_status(vcpu->arch.cop0), opc, 1105 - badvaddr); 1110 + kvm_debug("TLB ST fault: cause %#x, status %#lx, PC: %p, BadVaddr: %#lx\n", 1111 + cause, kvm_read_c0_guest_status(vcpu->arch.cop0), opc, 1112 + badvaddr); 1106 1113 1107 1114 ++vcpu->stat.tlbmiss_st_exits; 1108 1115 trace_kvm_exit(vcpu, TLBMISS_ST_EXITS); ··· 1148 1157 break; 1149 1158 1150 1159 default: 1151 - kvm_err 1152 - ("Exception Code: %d, not yet handled, @ PC: %p, inst: 0x%08x BadVaddr: %#lx Status: %#lx\n", 1153 - exccode, opc, kvm_get_inst(opc, vcpu), badvaddr, 1154 - kvm_read_c0_guest_status(vcpu->arch.cop0)); 1160 + kvm_err("Exception Code: %d, not yet handled, @ PC: %p, inst: 0x%08x BadVaddr: %#lx Status: %#lx\n", 1161 + exccode, opc, kvm_get_inst(opc, vcpu), badvaddr, 1162 + kvm_read_c0_guest_status(vcpu->arch.cop0)); 1155 1163 kvm_arch_vcpu_dump_regs(vcpu); 1156 1164 run->exit_reason = KVM_EXIT_INTERNAL_ERROR; 1157 1165 ret = RESUME_HOST; ··· 1165 1175 kvm_mips_deliver_interrupts(vcpu, cause); 1166 1176 1167 1177 if (!(ret & RESUME_HOST)) { 1168 - /* Only check for signals if not already exiting to userspace */ 1178 + /* Only check for signals if not already exiting to userspace */ 1169 1179 if (signal_pending(current)) { 1170 1180 run->exit_reason = KVM_EXIT_INTR; 1171 1181 ret = (-EINTR << 2) | RESUME_HOST; ··· 1186 1196 if (ret) 1187 1197 return ret; 1188 1198 1189 - /* On MIPS, kernel modules are executed from "mapped space", which requires TLBs. 1190 - * The TLB handling code is statically linked with the rest of the kernel (kvm_tlb.c) 1191 - * to avoid the possibility of double faulting. The issue is that the TLB code 1192 - * references routines that are part of the the KVM module, 1193 - * which are only available once the module is loaded. 1199 + /* 1200 + * On MIPS, kernel modules are executed from "mapped space", which 1201 + * requires TLBs. The TLB handling code is statically linked with 1202 + * the rest of the kernel (tlb.c) to avoid the possibility of 1203 + * double faulting. The issue is that the TLB code references 1204 + * routines that are part of the the KVM module, which are only 1205 + * available once the module is loaded. 1194 1206 */ 1195 1207 kvm_mips_gfn_to_pfn = gfn_to_pfn; 1196 1208 kvm_mips_release_pfn_clean = kvm_release_pfn_clean;
-23
arch/mips/kvm/kvm_mips_comm.h
··· 1 - /* 2 - * This file is subject to the terms and conditions of the GNU General Public 3 - * License. See the file "COPYING" in the main directory of this archive 4 - * for more details. 5 - * 6 - * KVM/MIPS: commpage: mapped into get kernel space 7 - * 8 - * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 9 - * Authors: Sanjay Lal <sanjayl@kymasys.com> 10 - */ 11 - 12 - #ifndef __KVM_MIPS_COMMPAGE_H__ 13 - #define __KVM_MIPS_COMMPAGE_H__ 14 - 15 - struct kvm_mips_commpage { 16 - struct mips_coproc cop0; /* COP0 state is mapped into Guest kernel via commpage */ 17 - }; 18 - 19 - #define KVM_MIPS_COMM_EIDI_OFFSET 0x0 20 - 21 - extern void kvm_mips_commpage_init(struct kvm_vcpu *vcpu); 22 - 23 - #endif /* __KVM_MIPS_COMMPAGE_H__ */
-37
arch/mips/kvm/kvm_mips_commpage.c
··· 1 - /* 2 - * This file is subject to the terms and conditions of the GNU General Public 3 - * License. See the file "COPYING" in the main directory of this archive 4 - * for more details. 5 - * 6 - * commpage, currently used for Virtual COP0 registers. 7 - * Mapped into the guest kernel @ 0x0. 8 - * 9 - * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 10 - * Authors: Sanjay Lal <sanjayl@kymasys.com> 11 - */ 12 - 13 - #include <linux/errno.h> 14 - #include <linux/err.h> 15 - #include <linux/module.h> 16 - #include <linux/vmalloc.h> 17 - #include <linux/fs.h> 18 - #include <linux/bootmem.h> 19 - #include <asm/page.h> 20 - #include <asm/cacheflush.h> 21 - #include <asm/mmu_context.h> 22 - 23 - #include <linux/kvm_host.h> 24 - 25 - #include "kvm_mips_comm.h" 26 - 27 - void kvm_mips_commpage_init(struct kvm_vcpu *vcpu) 28 - { 29 - struct kvm_mips_commpage *page = vcpu->arch.kseg0_commpage; 30 - memset(page, 0, sizeof(struct kvm_mips_commpage)); 31 - 32 - /* Specific init values for fields */ 33 - vcpu->arch.cop0 = &page->cop0; 34 - memset(vcpu->arch.cop0, 0, sizeof(struct mips_coproc)); 35 - 36 - return; 37 - }
+18 -22
arch/mips/kvm/kvm_mips_dyntrans.c arch/mips/kvm/dyntrans.c
··· 1 1 /* 2 - * This file is subject to the terms and conditions of the GNU General Public 3 - * License. See the file "COPYING" in the main directory of this archive 4 - * for more details. 5 - * 6 - * KVM/MIPS: Binary Patching for privileged instructions, reduces traps. 7 - * 8 - * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 9 - * Authors: Sanjay Lal <sanjayl@kymasys.com> 10 - */ 2 + * This file is subject to the terms and conditions of the GNU General Public 3 + * License. See the file "COPYING" in the main directory of this archive 4 + * for more details. 5 + * 6 + * KVM/MIPS: Binary Patching for privileged instructions, reduces traps. 7 + * 8 + * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 9 + * Authors: Sanjay Lal <sanjayl@kymasys.com> 10 + */ 11 11 12 12 #include <linux/errno.h> 13 13 #include <linux/err.h> ··· 18 18 #include <linux/bootmem.h> 19 19 #include <asm/cacheflush.h> 20 20 21 - #include "kvm_mips_comm.h" 21 + #include "commpage.h" 22 22 23 23 #define SYNCI_TEMPLATE 0x041f0000 24 24 #define SYNCI_BASE(x) (((x) >> 21) & 0x1f) ··· 28 28 #define CLEAR_TEMPLATE 0x00000020 29 29 #define SW_TEMPLATE 0xac000000 30 30 31 - int 32 - kvm_mips_trans_cache_index(uint32_t inst, uint32_t *opc, 33 - struct kvm_vcpu *vcpu) 31 + int kvm_mips_trans_cache_index(uint32_t inst, uint32_t *opc, 32 + struct kvm_vcpu *vcpu) 34 33 { 35 34 int result = 0; 36 35 unsigned long kseg0_opc; ··· 46 47 } 47 48 48 49 /* 49 - * Address based CACHE instructions are transformed into synci(s). A little heavy 50 - * for just D-cache invalidates, but avoids an expensive trap 50 + * Address based CACHE instructions are transformed into synci(s). A little 51 + * heavy for just D-cache invalidates, but avoids an expensive trap 51 52 */ 52 - int 53 - kvm_mips_trans_cache_va(uint32_t inst, uint32_t *opc, 54 - struct kvm_vcpu *vcpu) 53 + int kvm_mips_trans_cache_va(uint32_t inst, uint32_t *opc, 54 + struct kvm_vcpu *vcpu) 55 55 { 56 56 int result = 0; 57 57 unsigned long kseg0_opc; ··· 70 72 return result; 71 73 } 72 74 73 - int 74 - kvm_mips_trans_mfc0(uint32_t inst, uint32_t *opc, struct kvm_vcpu *vcpu) 75 + int kvm_mips_trans_mfc0(uint32_t inst, uint32_t *opc, struct kvm_vcpu *vcpu) 75 76 { 76 77 int32_t rt, rd, sel; 77 78 uint32_t mfc0_inst; ··· 112 115 return 0; 113 116 } 114 117 115 - int 116 - kvm_mips_trans_mtc0(uint32_t inst, uint32_t *opc, struct kvm_vcpu *vcpu) 118 + int kvm_mips_trans_mtc0(uint32_t inst, uint32_t *opc, struct kvm_vcpu *vcpu) 117 119 { 118 120 int32_t rt, rd, sel; 119 121 uint32_t mtc0_inst = SW_TEMPLATE;
+263 -276
arch/mips/kvm/kvm_mips_emul.c arch/mips/kvm/emulate.c
··· 1 1 /* 2 - * This file is subject to the terms and conditions of the GNU General Public 3 - * License. See the file "COPYING" in the main directory of this archive 4 - * for more details. 5 - * 6 - * KVM/MIPS: Instruction/Exception emulation 7 - * 8 - * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 9 - * Authors: Sanjay Lal <sanjayl@kymasys.com> 10 - */ 2 + * This file is subject to the terms and conditions of the GNU General Public 3 + * License. See the file "COPYING" in the main directory of this archive 4 + * for more details. 5 + * 6 + * KVM/MIPS: Instruction/Exception emulation 7 + * 8 + * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 9 + * Authors: Sanjay Lal <sanjayl@kymasys.com> 10 + */ 11 11 12 12 #include <linux/errno.h> 13 13 #include <linux/err.h> ··· 29 29 #include <asm/r4kcache.h> 30 30 #define CONFIG_MIPS_MT 31 31 32 - #include "kvm_mips_opcode.h" 33 - #include "kvm_mips_int.h" 34 - #include "kvm_mips_comm.h" 32 + #include "opcode.h" 33 + #include "interrupt.h" 34 + #include "commpage.h" 35 35 36 36 #include "trace.h" 37 37 ··· 51 51 if (epc & 3) 52 52 goto unaligned; 53 53 54 - /* 55 - * Read the instruction 56 - */ 54 + /* Read the instruction */ 57 55 insn.word = kvm_get_inst((uint32_t *) epc, vcpu); 58 56 59 57 if (insn.word == KVM_INVALID_INST) 60 58 return KVM_INVALID_INST; 61 59 62 60 switch (insn.i_format.opcode) { 63 - /* 64 - * jr and jalr are in r_format format. 65 - */ 61 + /* jr and jalr are in r_format format. */ 66 62 case spec_op: 67 63 switch (insn.r_format.func) { 68 64 case jalr_op: ··· 120 124 121 125 dspcontrol = rddsp(0x01); 122 126 123 - if (dspcontrol >= 32) { 127 + if (dspcontrol >= 32) 124 128 epc = epc + 4 + (insn.i_format.simmediate << 2); 125 - } else 129 + else 126 130 epc += 8; 127 131 nextpc = epc; 128 132 break; 129 133 } 130 134 break; 131 135 132 - /* 133 - * These are unconditional and in j_format. 134 - */ 136 + /* These are unconditional and in j_format. */ 135 137 case jal_op: 136 138 arch->gprs[31] = instpc + 8; 137 139 case j_op: ··· 140 146 nextpc = epc; 141 147 break; 142 148 143 - /* 144 - * These are conditional and in i_format. 145 - */ 149 + /* These are conditional and in i_format. */ 146 150 case beq_op: 147 151 case beql_op: 148 152 if (arch->gprs[insn.i_format.rs] == ··· 181 189 nextpc = epc; 182 190 break; 183 191 184 - /* 185 - * And now the FPA/cp1 branch instructions. 186 - */ 192 + /* And now the FPA/cp1 branch instructions. */ 187 193 case cop1_op: 188 - printk("%s: unsupported cop1_op\n", __func__); 194 + kvm_err("%s: unsupported cop1_op\n", __func__); 189 195 break; 190 196 } 191 197 192 198 return nextpc; 193 199 194 200 unaligned: 195 - printk("%s: unaligned epc\n", __func__); 201 + kvm_err("%s: unaligned epc\n", __func__); 196 202 return nextpc; 197 203 198 204 sigill: 199 - printk("%s: DSP branch but not DSP ASE\n", __func__); 205 + kvm_err("%s: DSP branch but not DSP ASE\n", __func__); 200 206 return nextpc; 201 207 } 202 208 ··· 209 219 er = EMULATE_FAIL; 210 220 } else { 211 221 vcpu->arch.pc = branch_pc; 212 - kvm_debug("BD update_pc(): New PC: %#lx\n", vcpu->arch.pc); 222 + kvm_debug("BD update_pc(): New PC: %#lx\n", 223 + vcpu->arch.pc); 213 224 } 214 225 } else 215 226 vcpu->arch.pc += 4; ··· 231 240 static inline int kvm_mips_count_disabled(struct kvm_vcpu *vcpu) 232 241 { 233 242 struct mips_coproc *cop0 = vcpu->arch.cop0; 243 + 234 244 return (vcpu->arch.count_ctl & KVM_REG_MIPS_COUNT_CTL_DC) || 235 245 (kvm_read_c0_guest_cause(cop0) & CAUSEF_DC); 236 246 } ··· 383 391 384 392 return now; 385 393 } 386 - 387 394 388 395 /** 389 396 * kvm_mips_resume_hrtimer() - Resume hrtimer, updating expiry. ··· 751 760 kvm_clear_c0_guest_status(cop0, ST0_ERL); 752 761 vcpu->arch.pc = kvm_read_c0_guest_errorepc(cop0); 753 762 } else { 754 - printk("[%#lx] ERET when MIPS_SR_EXL|MIPS_SR_ERL == 0\n", 755 - vcpu->arch.pc); 763 + kvm_err("[%#lx] ERET when MIPS_SR_EXL|MIPS_SR_ERL == 0\n", 764 + vcpu->arch.pc); 756 765 er = EMULATE_FAIL; 757 766 } 758 767 ··· 761 770 762 771 enum emulation_result kvm_mips_emul_wait(struct kvm_vcpu *vcpu) 763 772 { 764 - enum emulation_result er = EMULATE_DONE; 765 - 766 773 kvm_debug("[%#lx] !!!WAIT!!! (%#lx)\n", vcpu->arch.pc, 767 774 vcpu->arch.pending_exceptions); 768 775 ··· 770 781 vcpu->arch.wait = 1; 771 782 kvm_vcpu_block(vcpu); 772 783 773 - /* We we are runnable, then definitely go off to user space to check if any 774 - * I/O interrupts are pending. 784 + /* 785 + * We we are runnable, then definitely go off to user space to 786 + * check if any I/O interrupts are pending. 775 787 */ 776 788 if (kvm_check_request(KVM_REQ_UNHALT, vcpu)) { 777 789 clear_bit(KVM_REQ_UNHALT, &vcpu->requests); ··· 780 790 } 781 791 } 782 792 783 - return er; 793 + return EMULATE_DONE; 784 794 } 785 795 786 - /* XXXKYMA: Linux doesn't seem to use TLBR, return EMULATE_FAIL for now so that we can catch 787 - * this, if things ever change 796 + /* 797 + * XXXKYMA: Linux doesn't seem to use TLBR, return EMULATE_FAIL for now so that 798 + * we can catch this, if things ever change 788 799 */ 789 800 enum emulation_result kvm_mips_emul_tlbr(struct kvm_vcpu *vcpu) 790 801 { 791 802 struct mips_coproc *cop0 = vcpu->arch.cop0; 792 - enum emulation_result er = EMULATE_FAIL; 793 803 uint32_t pc = vcpu->arch.pc; 794 804 795 - printk("[%#x] COP0_TLBR [%ld]\n", pc, kvm_read_c0_guest_index(cop0)); 796 - return er; 805 + kvm_err("[%#x] COP0_TLBR [%ld]\n", pc, kvm_read_c0_guest_index(cop0)); 806 + return EMULATE_FAIL; 797 807 } 798 808 799 809 /* Write Guest TLB Entry @ Index */ ··· 801 811 { 802 812 struct mips_coproc *cop0 = vcpu->arch.cop0; 803 813 int index = kvm_read_c0_guest_index(cop0); 804 - enum emulation_result er = EMULATE_DONE; 805 814 struct kvm_mips_tlb *tlb = NULL; 806 815 uint32_t pc = vcpu->arch.pc; 807 816 808 817 if (index < 0 || index >= KVM_MIPS_GUEST_TLB_SIZE) { 809 - printk("%s: illegal index: %d\n", __func__, index); 810 - printk 811 - ("[%#x] COP0_TLBWI [%d] (entryhi: %#lx, entrylo0: %#lx entrylo1: %#lx, mask: %#lx)\n", 812 - pc, index, kvm_read_c0_guest_entryhi(cop0), 813 - kvm_read_c0_guest_entrylo0(cop0), 814 - kvm_read_c0_guest_entrylo1(cop0), 815 - kvm_read_c0_guest_pagemask(cop0)); 818 + kvm_debug("%s: illegal index: %d\n", __func__, index); 819 + kvm_debug("[%#x] COP0_TLBWI [%d] (entryhi: %#lx, entrylo0: %#lx entrylo1: %#lx, mask: %#lx)\n", 820 + pc, index, kvm_read_c0_guest_entryhi(cop0), 821 + kvm_read_c0_guest_entrylo0(cop0), 822 + kvm_read_c0_guest_entrylo1(cop0), 823 + kvm_read_c0_guest_pagemask(cop0)); 816 824 index = (index & ~0x80000000) % KVM_MIPS_GUEST_TLB_SIZE; 817 825 } 818 826 819 827 tlb = &vcpu->arch.guest_tlb[index]; 820 - #if 1 821 - /* Probe the shadow host TLB for the entry being overwritten, if one matches, invalidate it */ 828 + /* 829 + * Probe the shadow host TLB for the entry being overwritten, if one 830 + * matches, invalidate it 831 + */ 822 832 kvm_mips_host_tlb_inv(vcpu, tlb->tlb_hi); 823 - #endif 824 833 825 834 tlb->tlb_mask = kvm_read_c0_guest_pagemask(cop0); 826 835 tlb->tlb_hi = kvm_read_c0_guest_entryhi(cop0); 827 836 tlb->tlb_lo0 = kvm_read_c0_guest_entrylo0(cop0); 828 837 tlb->tlb_lo1 = kvm_read_c0_guest_entrylo1(cop0); 829 838 830 - kvm_debug 831 - ("[%#x] COP0_TLBWI [%d] (entryhi: %#lx, entrylo0: %#lx entrylo1: %#lx, mask: %#lx)\n", 832 - pc, index, kvm_read_c0_guest_entryhi(cop0), 833 - kvm_read_c0_guest_entrylo0(cop0), kvm_read_c0_guest_entrylo1(cop0), 834 - kvm_read_c0_guest_pagemask(cop0)); 839 + kvm_debug("[%#x] COP0_TLBWI [%d] (entryhi: %#lx, entrylo0: %#lx entrylo1: %#lx, mask: %#lx)\n", 840 + pc, index, kvm_read_c0_guest_entryhi(cop0), 841 + kvm_read_c0_guest_entrylo0(cop0), 842 + kvm_read_c0_guest_entrylo1(cop0), 843 + kvm_read_c0_guest_pagemask(cop0)); 835 844 836 - return er; 845 + return EMULATE_DONE; 837 846 } 838 847 839 848 /* Write Guest TLB Entry @ Random Index */ 840 849 enum emulation_result kvm_mips_emul_tlbwr(struct kvm_vcpu *vcpu) 841 850 { 842 851 struct mips_coproc *cop0 = vcpu->arch.cop0; 843 - enum emulation_result er = EMULATE_DONE; 844 852 struct kvm_mips_tlb *tlb = NULL; 845 853 uint32_t pc = vcpu->arch.pc; 846 854 int index; 847 855 848 - #if 1 849 856 get_random_bytes(&index, sizeof(index)); 850 857 index &= (KVM_MIPS_GUEST_TLB_SIZE - 1); 851 - #else 852 - index = jiffies % KVM_MIPS_GUEST_TLB_SIZE; 853 - #endif 854 - 855 - if (index < 0 || index >= KVM_MIPS_GUEST_TLB_SIZE) { 856 - printk("%s: illegal index: %d\n", __func__, index); 857 - return EMULATE_FAIL; 858 - } 859 858 860 859 tlb = &vcpu->arch.guest_tlb[index]; 861 860 862 - #if 1 863 - /* Probe the shadow host TLB for the entry being overwritten, if one matches, invalidate it */ 861 + /* 862 + * Probe the shadow host TLB for the entry being overwritten, if one 863 + * matches, invalidate it 864 + */ 864 865 kvm_mips_host_tlb_inv(vcpu, tlb->tlb_hi); 865 - #endif 866 866 867 867 tlb->tlb_mask = kvm_read_c0_guest_pagemask(cop0); 868 868 tlb->tlb_hi = kvm_read_c0_guest_entryhi(cop0); 869 869 tlb->tlb_lo0 = kvm_read_c0_guest_entrylo0(cop0); 870 870 tlb->tlb_lo1 = kvm_read_c0_guest_entrylo1(cop0); 871 871 872 - kvm_debug 873 - ("[%#x] COP0_TLBWR[%d] (entryhi: %#lx, entrylo0: %#lx entrylo1: %#lx)\n", 874 - pc, index, kvm_read_c0_guest_entryhi(cop0), 875 - kvm_read_c0_guest_entrylo0(cop0), 876 - kvm_read_c0_guest_entrylo1(cop0)); 872 + kvm_debug("[%#x] COP0_TLBWR[%d] (entryhi: %#lx, entrylo0: %#lx entrylo1: %#lx)\n", 873 + pc, index, kvm_read_c0_guest_entryhi(cop0), 874 + kvm_read_c0_guest_entrylo0(cop0), 875 + kvm_read_c0_guest_entrylo1(cop0)); 877 876 878 - return er; 877 + return EMULATE_DONE; 879 878 } 880 879 881 880 enum emulation_result kvm_mips_emul_tlbp(struct kvm_vcpu *vcpu) 882 881 { 883 882 struct mips_coproc *cop0 = vcpu->arch.cop0; 884 883 long entryhi = kvm_read_c0_guest_entryhi(cop0); 885 - enum emulation_result er = EMULATE_DONE; 886 884 uint32_t pc = vcpu->arch.pc; 887 885 int index = -1; 888 886 ··· 881 903 kvm_debug("[%#x] COP0_TLBP (entryhi: %#lx), index: %d\n", pc, entryhi, 882 904 index); 883 905 884 - return er; 906 + return EMULATE_DONE; 885 907 } 886 908 887 - enum emulation_result 888 - kvm_mips_emulate_CP0(uint32_t inst, uint32_t *opc, uint32_t cause, 889 - struct kvm_run *run, struct kvm_vcpu *vcpu) 909 + enum emulation_result kvm_mips_emulate_CP0(uint32_t inst, uint32_t *opc, 910 + uint32_t cause, struct kvm_run *run, 911 + struct kvm_vcpu *vcpu) 890 912 { 891 913 struct mips_coproc *cop0 = vcpu->arch.cop0; 892 914 enum emulation_result er = EMULATE_DONE; ··· 900 922 */ 901 923 curr_pc = vcpu->arch.pc; 902 924 er = update_pc(vcpu, cause); 903 - if (er == EMULATE_FAIL) { 925 + if (er == EMULATE_FAIL) 904 926 return er; 905 - } 906 927 907 928 copz = (inst >> 21) & 0x1f; 908 929 rt = (inst >> 16) & 0x1f; ··· 926 949 er = kvm_mips_emul_tlbp(vcpu); 927 950 break; 928 951 case rfe_op: 929 - printk("!!!COP0_RFE!!!\n"); 952 + kvm_err("!!!COP0_RFE!!!\n"); 930 953 break; 931 954 case eret_op: 932 955 er = kvm_mips_emul_eret(vcpu); ··· 950 973 #ifdef CONFIG_KVM_MIPS_DYN_TRANS 951 974 kvm_mips_trans_mfc0(inst, opc, vcpu); 952 975 #endif 953 - } 954 - else { 976 + } else { 955 977 vcpu->arch.gprs[rt] = cop0->reg[rd][sel]; 956 978 957 979 #ifdef CONFIG_KVM_MIPS_DYN_TRANS ··· 975 999 if ((rd == MIPS_CP0_TLB_INDEX) 976 1000 && (vcpu->arch.gprs[rt] >= 977 1001 KVM_MIPS_GUEST_TLB_SIZE)) { 978 - printk("Invalid TLB Index: %ld", 979 - vcpu->arch.gprs[rt]); 1002 + kvm_err("Invalid TLB Index: %ld", 1003 + vcpu->arch.gprs[rt]); 980 1004 er = EMULATE_FAIL; 981 1005 break; 982 1006 } ··· 986 1010 kvm_change_c0_guest_ebase(cop0, 987 1011 ~(C0_EBASE_CORE_MASK), 988 1012 vcpu->arch.gprs[rt]); 989 - printk("MTCz, cop0->reg[EBASE]: %#lx\n", 990 - kvm_read_c0_guest_ebase(cop0)); 1013 + kvm_err("MTCz, cop0->reg[EBASE]: %#lx\n", 1014 + kvm_read_c0_guest_ebase(cop0)); 991 1015 } else if (rd == MIPS_CP0_TLB_HI && sel == 0) { 992 1016 uint32_t nasid = 993 - vcpu->arch.gprs[rt] & ASID_MASK; 994 - if ((KSEGX(vcpu->arch.gprs[rt]) != CKSEG0) 995 - && 1017 + vcpu->arch.gprs[rt] & ASID_MASK; 1018 + if ((KSEGX(vcpu->arch.gprs[rt]) != CKSEG0) && 996 1019 ((kvm_read_c0_guest_entryhi(cop0) & 997 1020 ASID_MASK) != nasid)) { 998 - 999 - kvm_debug 1000 - ("MTCz, change ASID from %#lx to %#lx\n", 1001 - kvm_read_c0_guest_entryhi(cop0) & 1002 - ASID_MASK, 1003 - vcpu->arch.gprs[rt] & ASID_MASK); 1021 + kvm_debug("MTCz, change ASID from %#lx to %#lx\n", 1022 + kvm_read_c0_guest_entryhi(cop0) 1023 + & ASID_MASK, 1024 + vcpu->arch.gprs[rt] 1025 + & ASID_MASK); 1004 1026 1005 1027 /* Blow away the shadow host TLBs */ 1006 1028 kvm_mips_flush_host_tlb(1); ··· 1023 1049 } else if ((rd == MIPS_CP0_STATUS) && (sel == 0)) { 1024 1050 kvm_write_c0_guest_status(cop0, 1025 1051 vcpu->arch.gprs[rt]); 1026 - /* Make sure that CU1 and NMI bits are never set */ 1052 + /* 1053 + * Make sure that CU1 and NMI bits are 1054 + * never set 1055 + */ 1027 1056 kvm_clear_c0_guest_status(cop0, 1028 1057 (ST0_CU1 | ST0_NMI)); 1029 1058 ··· 1035 1058 #endif 1036 1059 } else if ((rd == MIPS_CP0_CAUSE) && (sel == 0)) { 1037 1060 uint32_t old_cause, new_cause; 1061 + 1038 1062 old_cause = kvm_read_c0_guest_cause(cop0); 1039 1063 new_cause = vcpu->arch.gprs[rt]; 1040 1064 /* Update R/W bits */ ··· 1060 1082 break; 1061 1083 1062 1084 case dmtc_op: 1063 - printk 1064 - ("!!!!!!![%#lx]dmtc_op: rt: %d, rd: %d, sel: %d!!!!!!\n", 1065 - vcpu->arch.pc, rt, rd, sel); 1085 + kvm_err("!!!!!!![%#lx]dmtc_op: rt: %d, rd: %d, sel: %d!!!!!!\n", 1086 + vcpu->arch.pc, rt, rd, sel); 1066 1087 er = EMULATE_FAIL; 1067 1088 break; 1068 1089 ··· 1092 1115 cop0->reg[MIPS_CP0_STATUS][2] & 0xf; 1093 1116 uint32_t pss = 1094 1117 (cop0->reg[MIPS_CP0_STATUS][2] >> 6) & 0xf; 1095 - /* We don't support any shadow register sets, so SRSCtl[PSS] == SRSCtl[CSS] = 0 */ 1118 + /* 1119 + * We don't support any shadow register sets, so 1120 + * SRSCtl[PSS] == SRSCtl[CSS] = 0 1121 + */ 1096 1122 if (css || pss) { 1097 1123 er = EMULATE_FAIL; 1098 1124 break; ··· 1106 1126 } 1107 1127 break; 1108 1128 default: 1109 - printk 1110 - ("[%#lx]MachEmulateCP0: unsupported COP0, copz: 0x%x\n", 1111 - vcpu->arch.pc, copz); 1129 + kvm_err("[%#lx]MachEmulateCP0: unsupported COP0, copz: 0x%x\n", 1130 + vcpu->arch.pc, copz); 1112 1131 er = EMULATE_FAIL; 1113 1132 break; 1114 1133 } 1115 1134 } 1116 1135 1117 1136 done: 1118 - /* 1119 - * Rollback PC only if emulation was unsuccessful 1120 - */ 1121 - if (er == EMULATE_FAIL) { 1137 + /* Rollback PC only if emulation was unsuccessful */ 1138 + if (er == EMULATE_FAIL) 1122 1139 vcpu->arch.pc = curr_pc; 1123 - } 1124 1140 1125 1141 dont_update_pc: 1126 1142 /* ··· 1128 1152 return er; 1129 1153 } 1130 1154 1131 - enum emulation_result 1132 - kvm_mips_emulate_store(uint32_t inst, uint32_t cause, 1133 - struct kvm_run *run, struct kvm_vcpu *vcpu) 1155 + enum emulation_result kvm_mips_emulate_store(uint32_t inst, uint32_t cause, 1156 + struct kvm_run *run, 1157 + struct kvm_vcpu *vcpu) 1134 1158 { 1135 1159 enum emulation_result er = EMULATE_DO_MMIO; 1136 1160 int32_t op, base, rt, offset; ··· 1228 1252 break; 1229 1253 1230 1254 default: 1231 - printk("Store not yet supported"); 1255 + kvm_err("Store not yet supported"); 1232 1256 er = EMULATE_FAIL; 1233 1257 break; 1234 1258 } 1235 1259 1236 - /* 1237 - * Rollback PC if emulation was unsuccessful 1238 - */ 1239 - if (er == EMULATE_FAIL) { 1260 + /* Rollback PC if emulation was unsuccessful */ 1261 + if (er == EMULATE_FAIL) 1240 1262 vcpu->arch.pc = curr_pc; 1241 - } 1242 1263 1243 1264 return er; 1244 1265 } 1245 1266 1246 - enum emulation_result 1247 - kvm_mips_emulate_load(uint32_t inst, uint32_t cause, 1248 - struct kvm_run *run, struct kvm_vcpu *vcpu) 1267 + enum emulation_result kvm_mips_emulate_load(uint32_t inst, uint32_t cause, 1268 + struct kvm_run *run, 1269 + struct kvm_vcpu *vcpu) 1249 1270 { 1250 1271 enum emulation_result er = EMULATE_DO_MMIO; 1251 1272 int32_t op, base, rt, offset; ··· 1337 1364 break; 1338 1365 1339 1366 default: 1340 - printk("Load not yet supported"); 1367 + kvm_err("Load not yet supported"); 1341 1368 er = EMULATE_FAIL; 1342 1369 break; 1343 1370 } ··· 1356 1383 gfn = va >> PAGE_SHIFT; 1357 1384 1358 1385 if (gfn >= kvm->arch.guest_pmap_npages) { 1359 - printk("%s: Invalid gfn: %#llx\n", __func__, gfn); 1386 + kvm_err("%s: Invalid gfn: %#llx\n", __func__, gfn); 1360 1387 kvm_mips_dump_host_tlbs(); 1361 1388 kvm_arch_vcpu_dump_regs(vcpu); 1362 1389 return -1; ··· 1364 1391 pfn = kvm->arch.guest_pmap[gfn]; 1365 1392 pa = (pfn << PAGE_SHIFT) | offset; 1366 1393 1367 - printk("%s: va: %#lx, unmapped: %#x\n", __func__, va, CKSEG0ADDR(pa)); 1394 + kvm_debug("%s: va: %#lx, unmapped: %#x\n", __func__, va, 1395 + CKSEG0ADDR(pa)); 1368 1396 1369 1397 local_flush_icache_range(CKSEG0ADDR(pa), 32); 1370 1398 return 0; ··· 1384 1410 #define MIPS_CACHE_DCACHE 0x1 1385 1411 #define MIPS_CACHE_SEC 0x3 1386 1412 1387 - enum emulation_result 1388 - kvm_mips_emulate_cache(uint32_t inst, uint32_t *opc, uint32_t cause, 1389 - struct kvm_run *run, struct kvm_vcpu *vcpu) 1413 + enum emulation_result kvm_mips_emulate_cache(uint32_t inst, uint32_t *opc, 1414 + uint32_t cause, 1415 + struct kvm_run *run, 1416 + struct kvm_vcpu *vcpu) 1390 1417 { 1391 1418 struct mips_coproc *cop0 = vcpu->arch.cop0; 1392 - extern void (*r4k_blast_dcache) (void); 1393 - extern void (*r4k_blast_icache) (void); 1394 1419 enum emulation_result er = EMULATE_DONE; 1395 1420 int32_t offset, cache, op_inst, op, base; 1396 1421 struct kvm_vcpu_arch *arch = &vcpu->arch; ··· 1416 1443 kvm_debug("CACHE (cache: %#x, op: %#x, base[%d]: %#lx, offset: %#x\n", 1417 1444 cache, op, base, arch->gprs[base], offset); 1418 1445 1419 - /* Treat INDEX_INV as a nop, basically issued by Linux on startup to invalidate 1420 - * the caches entirely by stepping through all the ways/indexes 1446 + /* 1447 + * Treat INDEX_INV as a nop, basically issued by Linux on startup to 1448 + * invalidate the caches entirely by stepping through all the 1449 + * ways/indexes 1421 1450 */ 1422 1451 if (op == MIPS_CACHE_OP_INDEX_INV) { 1423 - kvm_debug 1424 - ("@ %#lx/%#lx CACHE (cache: %#x, op: %#x, base[%d]: %#lx, offset: %#x\n", 1425 - vcpu->arch.pc, vcpu->arch.gprs[31], cache, op, base, 1426 - arch->gprs[base], offset); 1452 + kvm_debug("@ %#lx/%#lx CACHE (cache: %#x, op: %#x, base[%d]: %#lx, offset: %#x\n", 1453 + vcpu->arch.pc, vcpu->arch.gprs[31], cache, op, base, 1454 + arch->gprs[base], offset); 1427 1455 1428 1456 if (cache == MIPS_CACHE_DCACHE) 1429 1457 r4k_blast_dcache(); 1430 1458 else if (cache == MIPS_CACHE_ICACHE) 1431 1459 r4k_blast_icache(); 1432 1460 else { 1433 - printk("%s: unsupported CACHE INDEX operation\n", 1434 - __func__); 1461 + kvm_err("%s: unsupported CACHE INDEX operation\n", 1462 + __func__); 1435 1463 return EMULATE_FAIL; 1436 1464 } 1437 1465 ··· 1444 1470 1445 1471 preempt_disable(); 1446 1472 if (KVM_GUEST_KSEGX(va) == KVM_GUEST_KSEG0) { 1447 - 1448 - if (kvm_mips_host_tlb_lookup(vcpu, va) < 0) { 1473 + if (kvm_mips_host_tlb_lookup(vcpu, va) < 0) 1449 1474 kvm_mips_handle_kseg0_tlb_fault(va, vcpu); 1450 - } 1451 1475 } else if ((KVM_GUEST_KSEGX(va) < KVM_GUEST_KSEG0) || 1452 1476 KVM_GUEST_KSEGX(va) == KVM_GUEST_KSEG23) { 1453 1477 int index; 1454 1478 1455 1479 /* If an entry already exists then skip */ 1456 - if (kvm_mips_host_tlb_lookup(vcpu, va) >= 0) { 1480 + if (kvm_mips_host_tlb_lookup(vcpu, va) >= 0) 1457 1481 goto skip_fault; 1458 - } 1459 1482 1460 - /* If address not in the guest TLB, then give the guest a fault, the 1461 - * resulting handler will do the right thing 1483 + /* 1484 + * If address not in the guest TLB, then give the guest a fault, 1485 + * the resulting handler will do the right thing 1462 1486 */ 1463 1487 index = kvm_mips_guest_tlb_lookup(vcpu, (va & VPN2_MASK) | 1464 1488 (kvm_read_c0_guest_entryhi ··· 1471 1499 goto dont_update_pc; 1472 1500 } else { 1473 1501 struct kvm_mips_tlb *tlb = &vcpu->arch.guest_tlb[index]; 1474 - /* Check if the entry is valid, if not then setup a TLB invalid exception to the guest */ 1502 + /* 1503 + * Check if the entry is valid, if not then setup a TLB 1504 + * invalid exception to the guest 1505 + */ 1475 1506 if (!TLB_IS_VALID(*tlb, va)) { 1476 1507 er = kvm_mips_emulate_tlbinv_ld(cause, NULL, 1477 1508 run, vcpu); 1478 1509 preempt_enable(); 1479 1510 goto dont_update_pc; 1480 1511 } else { 1481 - /* We fault an entry from the guest tlb to the shadow host TLB */ 1512 + /* 1513 + * We fault an entry from the guest tlb to the 1514 + * shadow host TLB 1515 + */ 1482 1516 kvm_mips_handle_mapped_seg_tlb_fault(vcpu, tlb, 1483 1517 NULL, 1484 1518 NULL); 1485 1519 } 1486 1520 } 1487 1521 } else { 1488 - printk 1489 - ("INVALID CACHE INDEX/ADDRESS (cache: %#x, op: %#x, base[%d]: %#lx, offset: %#x\n", 1490 - cache, op, base, arch->gprs[base], offset); 1522 + kvm_err("INVALID CACHE INDEX/ADDRESS (cache: %#x, op: %#x, base[%d]: %#lx, offset: %#x\n", 1523 + cache, op, base, arch->gprs[base], offset); 1491 1524 er = EMULATE_FAIL; 1492 1525 preempt_enable(); 1493 1526 goto dont_update_pc; ··· 1507 1530 flush_dcache_line(va); 1508 1531 1509 1532 #ifdef CONFIG_KVM_MIPS_DYN_TRANS 1510 - /* Replace the CACHE instruction, with a SYNCI, not the same, but avoids a trap */ 1533 + /* 1534 + * Replace the CACHE instruction, with a SYNCI, not the same, 1535 + * but avoids a trap 1536 + */ 1511 1537 kvm_mips_trans_cache_va(inst, opc, vcpu); 1512 1538 #endif 1513 1539 } else if (op == MIPS_CACHE_OP_HIT_INV && cache == MIPS_CACHE_ICACHE) { ··· 1522 1542 kvm_mips_trans_cache_va(inst, opc, vcpu); 1523 1543 #endif 1524 1544 } else { 1525 - printk 1526 - ("NO-OP CACHE (cache: %#x, op: %#x, base[%d]: %#lx, offset: %#x\n", 1527 - cache, op, base, arch->gprs[base], offset); 1545 + kvm_err("NO-OP CACHE (cache: %#x, op: %#x, base[%d]: %#lx, offset: %#x\n", 1546 + cache, op, base, arch->gprs[base], offset); 1528 1547 er = EMULATE_FAIL; 1529 1548 preempt_enable(); 1530 1549 goto dont_update_pc; ··· 1531 1552 1532 1553 preempt_enable(); 1533 1554 1534 - dont_update_pc: 1535 - /* 1536 - * Rollback PC 1537 - */ 1555 + dont_update_pc: 1556 + /* Rollback PC */ 1538 1557 vcpu->arch.pc = curr_pc; 1539 - done: 1558 + done: 1540 1559 return er; 1541 1560 } 1542 1561 1543 - enum emulation_result 1544 - kvm_mips_emulate_inst(unsigned long cause, uint32_t *opc, 1545 - struct kvm_run *run, struct kvm_vcpu *vcpu) 1562 + enum emulation_result kvm_mips_emulate_inst(unsigned long cause, uint32_t *opc, 1563 + struct kvm_run *run, 1564 + struct kvm_vcpu *vcpu) 1546 1565 { 1547 1566 enum emulation_result er = EMULATE_DONE; 1548 1567 uint32_t inst; 1549 1568 1550 - /* 1551 - * Fetch the instruction. 1552 - */ 1553 - if (cause & CAUSEF_BD) { 1569 + /* Fetch the instruction. */ 1570 + if (cause & CAUSEF_BD) 1554 1571 opc += 1; 1555 - } 1556 1572 1557 1573 inst = kvm_get_inst(opc, vcpu); 1558 1574 ··· 1575 1601 break; 1576 1602 1577 1603 default: 1578 - printk("Instruction emulation not supported (%p/%#x)\n", opc, 1579 - inst); 1604 + kvm_err("Instruction emulation not supported (%p/%#x)\n", opc, 1605 + inst); 1580 1606 kvm_arch_vcpu_dump_regs(vcpu); 1581 1607 er = EMULATE_FAIL; 1582 1608 break; ··· 1585 1611 return er; 1586 1612 } 1587 1613 1588 - enum emulation_result 1589 - kvm_mips_emulate_syscall(unsigned long cause, uint32_t *opc, 1590 - struct kvm_run *run, struct kvm_vcpu *vcpu) 1614 + enum emulation_result kvm_mips_emulate_syscall(unsigned long cause, 1615 + uint32_t *opc, 1616 + struct kvm_run *run, 1617 + struct kvm_vcpu *vcpu) 1591 1618 { 1592 1619 struct mips_coproc *cop0 = vcpu->arch.cop0; 1593 1620 struct kvm_vcpu_arch *arch = &vcpu->arch; ··· 1613 1638 arch->pc = KVM_GUEST_KSEG0 + 0x180; 1614 1639 1615 1640 } else { 1616 - printk("Trying to deliver SYSCALL when EXL is already set\n"); 1641 + kvm_err("Trying to deliver SYSCALL when EXL is already set\n"); 1617 1642 er = EMULATE_FAIL; 1618 1643 } 1619 1644 1620 1645 return er; 1621 1646 } 1622 1647 1623 - enum emulation_result 1624 - kvm_mips_emulate_tlbmiss_ld(unsigned long cause, uint32_t *opc, 1625 - struct kvm_run *run, struct kvm_vcpu *vcpu) 1648 + enum emulation_result kvm_mips_emulate_tlbmiss_ld(unsigned long cause, 1649 + uint32_t *opc, 1650 + struct kvm_run *run, 1651 + struct kvm_vcpu *vcpu) 1626 1652 { 1627 1653 struct mips_coproc *cop0 = vcpu->arch.cop0; 1628 1654 struct kvm_vcpu_arch *arch = &vcpu->arch; 1629 - enum emulation_result er = EMULATE_DONE; 1630 1655 unsigned long entryhi = (vcpu->arch. host_cp0_badvaddr & VPN2_MASK) | 1631 1656 (kvm_read_c0_guest_entryhi(cop0) & ASID_MASK); 1632 1657 ··· 1663 1688 /* Blow away the shadow host TLBs */ 1664 1689 kvm_mips_flush_host_tlb(1); 1665 1690 1666 - return er; 1691 + return EMULATE_DONE; 1667 1692 } 1668 1693 1669 - enum emulation_result 1670 - kvm_mips_emulate_tlbinv_ld(unsigned long cause, uint32_t *opc, 1671 - struct kvm_run *run, struct kvm_vcpu *vcpu) 1694 + enum emulation_result kvm_mips_emulate_tlbinv_ld(unsigned long cause, 1695 + uint32_t *opc, 1696 + struct kvm_run *run, 1697 + struct kvm_vcpu *vcpu) 1672 1698 { 1673 1699 struct mips_coproc *cop0 = vcpu->arch.cop0; 1674 1700 struct kvm_vcpu_arch *arch = &vcpu->arch; 1675 - enum emulation_result er = EMULATE_DONE; 1676 1701 unsigned long entryhi = 1677 1702 (vcpu->arch.host_cp0_badvaddr & VPN2_MASK) | 1678 1703 (kvm_read_c0_guest_entryhi(cop0) & ASID_MASK); ··· 1709 1734 /* Blow away the shadow host TLBs */ 1710 1735 kvm_mips_flush_host_tlb(1); 1711 1736 1712 - return er; 1737 + return EMULATE_DONE; 1713 1738 } 1714 1739 1715 - enum emulation_result 1716 - kvm_mips_emulate_tlbmiss_st(unsigned long cause, uint32_t *opc, 1717 - struct kvm_run *run, struct kvm_vcpu *vcpu) 1740 + enum emulation_result kvm_mips_emulate_tlbmiss_st(unsigned long cause, 1741 + uint32_t *opc, 1742 + struct kvm_run *run, 1743 + struct kvm_vcpu *vcpu) 1718 1744 { 1719 1745 struct mips_coproc *cop0 = vcpu->arch.cop0; 1720 1746 struct kvm_vcpu_arch *arch = &vcpu->arch; 1721 - enum emulation_result er = EMULATE_DONE; 1722 1747 unsigned long entryhi = (vcpu->arch.host_cp0_badvaddr & VPN2_MASK) | 1723 1748 (kvm_read_c0_guest_entryhi(cop0) & ASID_MASK); 1724 1749 ··· 1753 1778 /* Blow away the shadow host TLBs */ 1754 1779 kvm_mips_flush_host_tlb(1); 1755 1780 1756 - return er; 1781 + return EMULATE_DONE; 1757 1782 } 1758 1783 1759 - enum emulation_result 1760 - kvm_mips_emulate_tlbinv_st(unsigned long cause, uint32_t *opc, 1761 - struct kvm_run *run, struct kvm_vcpu *vcpu) 1784 + enum emulation_result kvm_mips_emulate_tlbinv_st(unsigned long cause, 1785 + uint32_t *opc, 1786 + struct kvm_run *run, 1787 + struct kvm_vcpu *vcpu) 1762 1788 { 1763 1789 struct mips_coproc *cop0 = vcpu->arch.cop0; 1764 1790 struct kvm_vcpu_arch *arch = &vcpu->arch; 1765 - enum emulation_result er = EMULATE_DONE; 1766 1791 unsigned long entryhi = (vcpu->arch.host_cp0_badvaddr & VPN2_MASK) | 1767 1792 (kvm_read_c0_guest_entryhi(cop0) & ASID_MASK); 1768 1793 ··· 1797 1822 /* Blow away the shadow host TLBs */ 1798 1823 kvm_mips_flush_host_tlb(1); 1799 1824 1800 - return er; 1825 + return EMULATE_DONE; 1801 1826 } 1802 1827 1803 1828 /* TLBMOD: store into address matching TLB with Dirty bit off */ 1804 - enum emulation_result 1805 - kvm_mips_handle_tlbmod(unsigned long cause, uint32_t *opc, 1806 - struct kvm_run *run, struct kvm_vcpu *vcpu) 1829 + enum emulation_result kvm_mips_handle_tlbmod(unsigned long cause, uint32_t *opc, 1830 + struct kvm_run *run, 1831 + struct kvm_vcpu *vcpu) 1807 1832 { 1808 1833 enum emulation_result er = EMULATE_DONE; 1809 1834 #ifdef DEBUG ··· 1812 1837 (kvm_read_c0_guest_entryhi(cop0) & ASID_MASK); 1813 1838 int index; 1814 1839 1815 - /* 1816 - * If address not in the guest TLB, then we are in trouble 1817 - */ 1840 + /* If address not in the guest TLB, then we are in trouble */ 1818 1841 index = kvm_mips_guest_tlb_lookup(vcpu, entryhi); 1819 1842 if (index < 0) { 1820 1843 /* XXXKYMA Invalidate and retry */ ··· 1829 1856 return er; 1830 1857 } 1831 1858 1832 - enum emulation_result 1833 - kvm_mips_emulate_tlbmod(unsigned long cause, uint32_t *opc, 1834 - struct kvm_run *run, struct kvm_vcpu *vcpu) 1859 + enum emulation_result kvm_mips_emulate_tlbmod(unsigned long cause, 1860 + uint32_t *opc, 1861 + struct kvm_run *run, 1862 + struct kvm_vcpu *vcpu) 1835 1863 { 1836 1864 struct mips_coproc *cop0 = vcpu->arch.cop0; 1837 1865 unsigned long entryhi = (vcpu->arch.host_cp0_badvaddr & VPN2_MASK) | 1838 1866 (kvm_read_c0_guest_entryhi(cop0) & ASID_MASK); 1839 1867 struct kvm_vcpu_arch *arch = &vcpu->arch; 1840 - enum emulation_result er = EMULATE_DONE; 1841 1868 1842 1869 if ((kvm_read_c0_guest_status(cop0) & ST0_EXL) == 0) { 1843 1870 /* save old pc */ ··· 1868 1895 /* Blow away the shadow host TLBs */ 1869 1896 kvm_mips_flush_host_tlb(1); 1870 1897 1871 - return er; 1898 + return EMULATE_DONE; 1872 1899 } 1873 1900 1874 - enum emulation_result 1875 - kvm_mips_emulate_fpu_exc(unsigned long cause, uint32_t *opc, 1876 - struct kvm_run *run, struct kvm_vcpu *vcpu) 1901 + enum emulation_result kvm_mips_emulate_fpu_exc(unsigned long cause, 1902 + uint32_t *opc, 1903 + struct kvm_run *run, 1904 + struct kvm_vcpu *vcpu) 1877 1905 { 1878 1906 struct mips_coproc *cop0 = vcpu->arch.cop0; 1879 1907 struct kvm_vcpu_arch *arch = &vcpu->arch; 1880 - enum emulation_result er = EMULATE_DONE; 1881 1908 1882 1909 if ((kvm_read_c0_guest_status(cop0) & ST0_EXL) == 0) { 1883 1910 /* save old pc */ ··· 1897 1924 (T_COP_UNUSABLE << CAUSEB_EXCCODE)); 1898 1925 kvm_change_c0_guest_cause(cop0, (CAUSEF_CE), (0x1 << CAUSEB_CE)); 1899 1926 1900 - return er; 1927 + return EMULATE_DONE; 1901 1928 } 1902 1929 1903 - enum emulation_result 1904 - kvm_mips_emulate_ri_exc(unsigned long cause, uint32_t *opc, 1905 - struct kvm_run *run, struct kvm_vcpu *vcpu) 1930 + enum emulation_result kvm_mips_emulate_ri_exc(unsigned long cause, 1931 + uint32_t *opc, 1932 + struct kvm_run *run, 1933 + struct kvm_vcpu *vcpu) 1906 1934 { 1907 1935 struct mips_coproc *cop0 = vcpu->arch.cop0; 1908 1936 struct kvm_vcpu_arch *arch = &vcpu->arch; ··· 1935 1961 return er; 1936 1962 } 1937 1963 1938 - enum emulation_result 1939 - kvm_mips_emulate_bp_exc(unsigned long cause, uint32_t *opc, 1940 - struct kvm_run *run, struct kvm_vcpu *vcpu) 1964 + enum emulation_result kvm_mips_emulate_bp_exc(unsigned long cause, 1965 + uint32_t *opc, 1966 + struct kvm_run *run, 1967 + struct kvm_vcpu *vcpu) 1941 1968 { 1942 1969 struct mips_coproc *cop0 = vcpu->arch.cop0; 1943 1970 struct kvm_vcpu_arch *arch = &vcpu->arch; ··· 1963 1988 arch->pc = KVM_GUEST_KSEG0 + 0x180; 1964 1989 1965 1990 } else { 1966 - printk("Trying to deliver BP when EXL is already set\n"); 1991 + kvm_err("Trying to deliver BP when EXL is already set\n"); 1967 1992 er = EMULATE_FAIL; 1968 1993 } 1969 1994 1970 1995 return er; 1971 1996 } 1972 1997 1973 - /* 1974 - * ll/sc, rdhwr, sync emulation 1975 - */ 1998 + /* ll/sc, rdhwr, sync emulation */ 1976 1999 1977 2000 #define OPCODE 0xfc000000 1978 2001 #define BASE 0x03e00000 ··· 1985 2012 #define SYNC 0x0000000f 1986 2013 #define RDHWR 0x0000003b 1987 2014 1988 - enum emulation_result 1989 - kvm_mips_handle_ri(unsigned long cause, uint32_t *opc, 1990 - struct kvm_run *run, struct kvm_vcpu *vcpu) 2015 + enum emulation_result kvm_mips_handle_ri(unsigned long cause, uint32_t *opc, 2016 + struct kvm_run *run, 2017 + struct kvm_vcpu *vcpu) 1991 2018 { 1992 2019 struct mips_coproc *cop0 = vcpu->arch.cop0; 1993 2020 struct kvm_vcpu_arch *arch = &vcpu->arch; ··· 2004 2031 if (er == EMULATE_FAIL) 2005 2032 return er; 2006 2033 2007 - /* 2008 - * Fetch the instruction. 2009 - */ 2034 + /* Fetch the instruction. */ 2010 2035 if (cause & CAUSEF_BD) 2011 2036 opc += 1; 2012 2037 2013 2038 inst = kvm_get_inst(opc, vcpu); 2014 2039 2015 2040 if (inst == KVM_INVALID_INST) { 2016 - printk("%s: Cannot get inst @ %p\n", __func__, opc); 2041 + kvm_err("%s: Cannot get inst @ %p\n", __func__, opc); 2017 2042 return EMULATE_FAIL; 2018 2043 } 2019 2044 ··· 2070 2099 return kvm_mips_emulate_ri_exc(cause, opc, run, vcpu); 2071 2100 } 2072 2101 2073 - enum emulation_result 2074 - kvm_mips_complete_mmio_load(struct kvm_vcpu *vcpu, struct kvm_run *run) 2102 + enum emulation_result kvm_mips_complete_mmio_load(struct kvm_vcpu *vcpu, 2103 + struct kvm_run *run) 2075 2104 { 2076 2105 unsigned long *gpr = &vcpu->arch.gprs[vcpu->arch.io_gpr]; 2077 2106 enum emulation_result er = EMULATE_DONE; 2078 2107 unsigned long curr_pc; 2079 2108 2080 2109 if (run->mmio.len > sizeof(*gpr)) { 2081 - printk("Bad MMIO length: %d", run->mmio.len); 2110 + kvm_err("Bad MMIO length: %d", run->mmio.len); 2082 2111 er = EMULATE_FAIL; 2083 2112 goto done; 2084 2113 } ··· 2113 2142 } 2114 2143 2115 2144 if (vcpu->arch.pending_load_cause & CAUSEF_BD) 2116 - kvm_debug 2117 - ("[%#lx] Completing %d byte BD Load to gpr %d (0x%08lx) type %d\n", 2118 - vcpu->arch.pc, run->mmio.len, vcpu->arch.io_gpr, *gpr, 2119 - vcpu->mmio_needed); 2145 + kvm_debug("[%#lx] Completing %d byte BD Load to gpr %d (0x%08lx) type %d\n", 2146 + vcpu->arch.pc, run->mmio.len, vcpu->arch.io_gpr, *gpr, 2147 + vcpu->mmio_needed); 2120 2148 2121 2149 done: 2122 2150 return er; 2123 2151 } 2124 2152 2125 - static enum emulation_result 2126 - kvm_mips_emulate_exc(unsigned long cause, uint32_t *opc, 2127 - struct kvm_run *run, struct kvm_vcpu *vcpu) 2153 + static enum emulation_result kvm_mips_emulate_exc(unsigned long cause, 2154 + uint32_t *opc, 2155 + struct kvm_run *run, 2156 + struct kvm_vcpu *vcpu) 2128 2157 { 2129 2158 uint32_t exccode = (cause >> CAUSEB_EXCCODE) & 0x1f; 2130 2159 struct mips_coproc *cop0 = vcpu->arch.cop0; ··· 2152 2181 exccode, kvm_read_c0_guest_epc(cop0), 2153 2182 kvm_read_c0_guest_badvaddr(cop0)); 2154 2183 } else { 2155 - printk("Trying to deliver EXC when EXL is already set\n"); 2184 + kvm_err("Trying to deliver EXC when EXL is already set\n"); 2156 2185 er = EMULATE_FAIL; 2157 2186 } 2158 2187 2159 2188 return er; 2160 2189 } 2161 2190 2162 - enum emulation_result 2163 - kvm_mips_check_privilege(unsigned long cause, uint32_t *opc, 2164 - struct kvm_run *run, struct kvm_vcpu *vcpu) 2191 + enum emulation_result kvm_mips_check_privilege(unsigned long cause, 2192 + uint32_t *opc, 2193 + struct kvm_run *run, 2194 + struct kvm_vcpu *vcpu) 2165 2195 { 2166 2196 enum emulation_result er = EMULATE_DONE; 2167 2197 uint32_t exccode = (cause >> CAUSEB_EXCCODE) & 0x1f; ··· 2187 2215 break; 2188 2216 2189 2217 case T_TLB_LD_MISS: 2190 - /* We we are accessing Guest kernel space, then send an address error exception to the guest */ 2218 + /* 2219 + * We we are accessing Guest kernel space, then send an 2220 + * address error exception to the guest 2221 + */ 2191 2222 if (badvaddr >= (unsigned long) KVM_GUEST_KSEG0) { 2192 - printk("%s: LD MISS @ %#lx\n", __func__, 2193 - badvaddr); 2223 + kvm_debug("%s: LD MISS @ %#lx\n", __func__, 2224 + badvaddr); 2194 2225 cause &= ~0xff; 2195 2226 cause |= (T_ADDR_ERR_LD << CAUSEB_EXCCODE); 2196 2227 er = EMULATE_PRIV_FAIL; ··· 2201 2226 break; 2202 2227 2203 2228 case T_TLB_ST_MISS: 2204 - /* We we are accessing Guest kernel space, then send an address error exception to the guest */ 2229 + /* 2230 + * We we are accessing Guest kernel space, then send an 2231 + * address error exception to the guest 2232 + */ 2205 2233 if (badvaddr >= (unsigned long) KVM_GUEST_KSEG0) { 2206 - printk("%s: ST MISS @ %#lx\n", __func__, 2207 - badvaddr); 2234 + kvm_debug("%s: ST MISS @ %#lx\n", __func__, 2235 + badvaddr); 2208 2236 cause &= ~0xff; 2209 2237 cause |= (T_ADDR_ERR_ST << CAUSEB_EXCCODE); 2210 2238 er = EMULATE_PRIV_FAIL; ··· 2215 2237 break; 2216 2238 2217 2239 case T_ADDR_ERR_ST: 2218 - printk("%s: address error ST @ %#lx\n", __func__, 2219 - badvaddr); 2240 + kvm_debug("%s: address error ST @ %#lx\n", __func__, 2241 + badvaddr); 2220 2242 if ((badvaddr & PAGE_MASK) == KVM_GUEST_COMMPAGE_ADDR) { 2221 2243 cause &= ~0xff; 2222 2244 cause |= (T_TLB_ST_MISS << CAUSEB_EXCCODE); ··· 2224 2246 er = EMULATE_PRIV_FAIL; 2225 2247 break; 2226 2248 case T_ADDR_ERR_LD: 2227 - printk("%s: address error LD @ %#lx\n", __func__, 2228 - badvaddr); 2249 + kvm_debug("%s: address error LD @ %#lx\n", __func__, 2250 + badvaddr); 2229 2251 if ((badvaddr & PAGE_MASK) == KVM_GUEST_COMMPAGE_ADDR) { 2230 2252 cause &= ~0xff; 2231 2253 cause |= (T_TLB_LD_MISS << CAUSEB_EXCCODE); ··· 2238 2260 } 2239 2261 } 2240 2262 2241 - if (er == EMULATE_PRIV_FAIL) { 2263 + if (er == EMULATE_PRIV_FAIL) 2242 2264 kvm_mips_emulate_exc(cause, opc, run, vcpu); 2243 - } 2265 + 2244 2266 return er; 2245 2267 } 2246 2268 2247 - /* User Address (UA) fault, this could happen if 2269 + /* 2270 + * User Address (UA) fault, this could happen if 2248 2271 * (1) TLB entry not present/valid in both Guest and shadow host TLBs, in this 2249 2272 * case we pass on the fault to the guest kernel and let it handle it. 2250 2273 * (2) TLB entry is present in the Guest TLB but not in the shadow, in this 2251 2274 * case we inject the TLB from the Guest TLB into the shadow host TLB 2252 2275 */ 2253 - enum emulation_result 2254 - kvm_mips_handle_tlbmiss(unsigned long cause, uint32_t *opc, 2255 - struct kvm_run *run, struct kvm_vcpu *vcpu) 2276 + enum emulation_result kvm_mips_handle_tlbmiss(unsigned long cause, 2277 + uint32_t *opc, 2278 + struct kvm_run *run, 2279 + struct kvm_vcpu *vcpu) 2256 2280 { 2257 2281 enum emulation_result er = EMULATE_DONE; 2258 2282 uint32_t exccode = (cause >> CAUSEB_EXCCODE) & 0x1f; ··· 2264 2284 kvm_debug("kvm_mips_handle_tlbmiss: badvaddr: %#lx, entryhi: %#lx\n", 2265 2285 vcpu->arch.host_cp0_badvaddr, vcpu->arch.host_cp0_entryhi); 2266 2286 2267 - /* KVM would not have got the exception if this entry was valid in the shadow host TLB 2268 - * Check the Guest TLB, if the entry is not there then send the guest an 2269 - * exception. The guest exc handler should then inject an entry into the 2270 - * guest TLB 2287 + /* 2288 + * KVM would not have got the exception if this entry was valid in the 2289 + * shadow host TLB. Check the Guest TLB, if the entry is not there then 2290 + * send the guest an exception. The guest exc handler should then inject 2291 + * an entry into the guest TLB. 2271 2292 */ 2272 2293 index = kvm_mips_guest_tlb_lookup(vcpu, 2273 2294 (va & VPN2_MASK) | ··· 2280 2299 } else if (exccode == T_TLB_ST_MISS) { 2281 2300 er = kvm_mips_emulate_tlbmiss_st(cause, opc, run, vcpu); 2282 2301 } else { 2283 - printk("%s: invalid exc code: %d\n", __func__, exccode); 2302 + kvm_err("%s: invalid exc code: %d\n", __func__, 2303 + exccode); 2284 2304 er = EMULATE_FAIL; 2285 2305 } 2286 2306 } else { 2287 2307 struct kvm_mips_tlb *tlb = &vcpu->arch.guest_tlb[index]; 2288 2308 2289 - /* Check if the entry is valid, if not then setup a TLB invalid exception to the guest */ 2309 + /* 2310 + * Check if the entry is valid, if not then setup a TLB invalid 2311 + * exception to the guest 2312 + */ 2290 2313 if (!TLB_IS_VALID(*tlb, va)) { 2291 2314 if (exccode == T_TLB_LD_MISS) { 2292 2315 er = kvm_mips_emulate_tlbinv_ld(cause, opc, run, ··· 2299 2314 er = kvm_mips_emulate_tlbinv_st(cause, opc, run, 2300 2315 vcpu); 2301 2316 } else { 2302 - printk("%s: invalid exc code: %d\n", __func__, 2303 - exccode); 2317 + kvm_err("%s: invalid exc code: %d\n", __func__, 2318 + exccode); 2304 2319 er = EMULATE_FAIL; 2305 2320 } 2306 2321 } else { 2307 - kvm_debug 2308 - ("Injecting hi: %#lx, lo0: %#lx, lo1: %#lx into shadow host TLB\n", 2309 - tlb->tlb_hi, tlb->tlb_lo0, tlb->tlb_lo1); 2310 - /* OK we have a Guest TLB entry, now inject it into the shadow host TLB */ 2322 + kvm_debug("Injecting hi: %#lx, lo0: %#lx, lo1: %#lx into shadow host TLB\n", 2323 + tlb->tlb_hi, tlb->tlb_lo0, tlb->tlb_lo1); 2324 + /* 2325 + * OK we have a Guest TLB entry, now inject it into the 2326 + * shadow host TLB 2327 + */ 2311 2328 kvm_mips_handle_mapped_seg_tlb_fault(vcpu, tlb, NULL, 2312 2329 NULL); 2313 2330 }
+23 -24
arch/mips/kvm/kvm_mips_int.c arch/mips/kvm/interrupt.c
··· 1 1 /* 2 - * This file is subject to the terms and conditions of the GNU General Public 3 - * License. See the file "COPYING" in the main directory of this archive 4 - * for more details. 5 - * 6 - * KVM/MIPS: Interrupt delivery 7 - * 8 - * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 9 - * Authors: Sanjay Lal <sanjayl@kymasys.com> 10 - */ 2 + * This file is subject to the terms and conditions of the GNU General Public 3 + * License. See the file "COPYING" in the main directory of this archive 4 + * for more details. 5 + * 6 + * KVM/MIPS: Interrupt delivery 7 + * 8 + * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 9 + * Authors: Sanjay Lal <sanjayl@kymasys.com> 10 + */ 11 11 12 12 #include <linux/errno.h> 13 13 #include <linux/err.h> ··· 20 20 21 21 #include <linux/kvm_host.h> 22 22 23 - #include "kvm_mips_int.h" 23 + #include "interrupt.h" 24 24 25 25 void kvm_mips_queue_irq(struct kvm_vcpu *vcpu, uint32_t priority) 26 26 { ··· 34 34 35 35 void kvm_mips_queue_timer_int_cb(struct kvm_vcpu *vcpu) 36 36 { 37 - /* Cause bits to reflect the pending timer interrupt, 37 + /* 38 + * Cause bits to reflect the pending timer interrupt, 38 39 * the EXC code will be set when we are actually 39 40 * delivering the interrupt: 40 41 */ ··· 52 51 kvm_mips_dequeue_irq(vcpu, MIPS_EXC_INT_TIMER); 53 52 } 54 53 55 - void 56 - kvm_mips_queue_io_int_cb(struct kvm_vcpu *vcpu, struct kvm_mips_interrupt *irq) 54 + void kvm_mips_queue_io_int_cb(struct kvm_vcpu *vcpu, 55 + struct kvm_mips_interrupt *irq) 57 56 { 58 57 int intr = (int)irq->irq; 59 58 60 - /* Cause bits to reflect the pending IO interrupt, 59 + /* 60 + * Cause bits to reflect the pending IO interrupt, 61 61 * the EXC code will be set when we are actually 62 62 * delivering the interrupt: 63 63 */ ··· 85 83 86 84 } 87 85 88 - void 89 - kvm_mips_dequeue_io_int_cb(struct kvm_vcpu *vcpu, 90 - struct kvm_mips_interrupt *irq) 86 + void kvm_mips_dequeue_io_int_cb(struct kvm_vcpu *vcpu, 87 + struct kvm_mips_interrupt *irq) 91 88 { 92 89 int intr = (int)irq->irq; 90 + 93 91 switch (intr) { 94 92 case -2: 95 93 kvm_clear_c0_guest_cause(vcpu->arch.cop0, (C_IRQ0)); ··· 113 111 } 114 112 115 113 /* Deliver the interrupt of the corresponding priority, if possible. */ 116 - int 117 - kvm_mips_irq_deliver_cb(struct kvm_vcpu *vcpu, unsigned int priority, 118 - uint32_t cause) 114 + int kvm_mips_irq_deliver_cb(struct kvm_vcpu *vcpu, unsigned int priority, 115 + uint32_t cause) 119 116 { 120 117 int allowed = 0; 121 118 uint32_t exccode; ··· 165 164 166 165 /* Are we allowed to deliver the interrupt ??? */ 167 166 if (allowed) { 168 - 169 167 if ((kvm_read_c0_guest_status(cop0) & ST0_EXL) == 0) { 170 168 /* save old pc */ 171 169 kvm_write_c0_guest_epc(cop0, arch->pc); ··· 195 195 return allowed; 196 196 } 197 197 198 - int 199 - kvm_mips_irq_clear_cb(struct kvm_vcpu *vcpu, unsigned int priority, 200 - uint32_t cause) 198 + int kvm_mips_irq_clear_cb(struct kvm_vcpu *vcpu, unsigned int priority, 199 + uint32_t cause) 201 200 { 202 201 return 1; 203 202 }
+13 -9
arch/mips/kvm/kvm_mips_int.h arch/mips/kvm/interrupt.h
··· 1 1 /* 2 - * This file is subject to the terms and conditions of the GNU General Public 3 - * License. See the file "COPYING" in the main directory of this archive 4 - * for more details. 5 - * 6 - * KVM/MIPS: Interrupts 7 - * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 8 - * Authors: Sanjay Lal <sanjayl@kymasys.com> 9 - */ 2 + * This file is subject to the terms and conditions of the GNU General Public 3 + * License. See the file "COPYING" in the main directory of this archive 4 + * for more details. 5 + * 6 + * KVM/MIPS: Interrupts 7 + * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 8 + * Authors: Sanjay Lal <sanjayl@kymasys.com> 9 + */ 10 10 11 - /* MIPS Exception Priorities, exceptions (including interrupts) are queued up 11 + /* 12 + * MIPS Exception Priorities, exceptions (including interrupts) are queued up 12 13 * for the guest in the order specified by their priorities 13 14 */ 14 15 ··· 27 26 #define MIPS_EXC_INT_IPI_2 11 28 27 #define MIPS_EXC_MAX 12 29 28 /* XXXSL More to follow */ 29 + 30 + extern char mips32_exception[], mips32_exceptionEnd[]; 31 + extern char mips32_GuestException[], mips32_GuestExceptionEnd[]; 30 32 31 33 #define C_TI (_ULCAST_(1) << 30) 32 34
-24
arch/mips/kvm/kvm_mips_opcode.h
··· 1 - /* 2 - * This file is subject to the terms and conditions of the GNU General Public 3 - * License. See the file "COPYING" in the main directory of this archive 4 - * for more details. 5 - * 6 - * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 7 - * Authors: Sanjay Lal <sanjayl@kymasys.com> 8 - */ 9 - 10 - /* 11 - * Define opcode values not defined in <asm/isnt.h> 12 - */ 13 - 14 - #ifndef __KVM_MIPS_OPCODE_H__ 15 - #define __KVM_MIPS_OPCODE_H__ 16 - 17 - /* COP0 Ops */ 18 - #define mfmcz_op 0x0b /* 01011 */ 19 - #define wrpgpr_op 0x0e /* 01110 */ 20 - 21 - /* COP0 opcodes (only if COP0 and CO=1): */ 22 - #define wait_op 0x20 /* 100000 */ 23 - 24 - #endif /* __KVM_MIPS_OPCODE_H__ */
+13 -15
arch/mips/kvm/kvm_mips_stats.c arch/mips/kvm/stats.c
··· 1 1 /* 2 - * This file is subject to the terms and conditions of the GNU General Public 3 - * License. See the file "COPYING" in the main directory of this archive 4 - * for more details. 5 - * 6 - * KVM/MIPS: COP0 access histogram 7 - * 8 - * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 9 - * Authors: Sanjay Lal <sanjayl@kymasys.com> 10 - */ 2 + * This file is subject to the terms and conditions of the GNU General Public 3 + * License. See the file "COPYING" in the main directory of this archive 4 + * for more details. 5 + * 6 + * KVM/MIPS: COP0 access histogram 7 + * 8 + * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 9 + * Authors: Sanjay Lal <sanjayl@kymasys.com> 10 + */ 11 11 12 12 #include <linux/kvm_host.h> 13 13 ··· 63 63 "DESAVE" 64 64 }; 65 65 66 - int kvm_mips_dump_stats(struct kvm_vcpu *vcpu) 66 + void kvm_mips_dump_stats(struct kvm_vcpu *vcpu) 67 67 { 68 68 #ifdef CONFIG_KVM_MIPS_DEBUG_COP0_COUNTERS 69 69 int i, j; 70 70 71 - printk("\nKVM VCPU[%d] COP0 Access Profile:\n", vcpu->vcpu_id); 71 + kvm_info("\nKVM VCPU[%d] COP0 Access Profile:\n", vcpu->vcpu_id); 72 72 for (i = 0; i < N_MIPS_COPROC_REGS; i++) { 73 73 for (j = 0; j < N_MIPS_COPROC_SEL; j++) { 74 74 if (vcpu->arch.cop0->stat[i][j]) 75 - printk("%s[%d]: %lu\n", kvm_cop0_str[i], j, 76 - vcpu->arch.cop0->stat[i][j]); 75 + kvm_info("%s[%d]: %lu\n", kvm_cop0_str[i], j, 76 + vcpu->arch.cop0->stat[i][j]); 77 77 } 78 78 } 79 79 #endif 80 - 81 - return 0; 82 80 }
+124 -134
arch/mips/kvm/kvm_tlb.c arch/mips/kvm/tlb.c
··· 1 1 /* 2 - * This file is subject to the terms and conditions of the GNU General Public 3 - * License. See the file "COPYING" in the main directory of this archive 4 - * for more details. 5 - * 6 - * KVM/MIPS TLB handling, this file is part of the Linux host kernel so that 7 - * TLB handlers run from KSEG0 8 - * 9 - * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 10 - * Authors: Sanjay Lal <sanjayl@kymasys.com> 11 - */ 2 + * This file is subject to the terms and conditions of the GNU General Public 3 + * License. See the file "COPYING" in the main directory of this archive 4 + * for more details. 5 + * 6 + * KVM/MIPS TLB handling, this file is part of the Linux host kernel so that 7 + * TLB handlers run from KSEG0 8 + * 9 + * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 10 + * Authors: Sanjay Lal <sanjayl@kymasys.com> 11 + */ 12 12 13 13 #include <linux/sched.h> 14 14 #include <linux/smp.h> ··· 17 17 #include <linux/module.h> 18 18 #include <linux/kvm_host.h> 19 19 #include <linux/srcu.h> 20 - 21 20 22 21 #include <asm/cpu.h> 23 22 #include <asm/bootinfo.h> ··· 38 39 EXPORT_SYMBOL(kvm_mips_instance); 39 40 40 41 /* These function pointers are initialized once the KVM module is loaded */ 41 - pfn_t(*kvm_mips_gfn_to_pfn) (struct kvm *kvm, gfn_t gfn); 42 + pfn_t (*kvm_mips_gfn_to_pfn)(struct kvm *kvm, gfn_t gfn); 42 43 EXPORT_SYMBOL(kvm_mips_gfn_to_pfn); 43 44 44 - void (*kvm_mips_release_pfn_clean) (pfn_t pfn); 45 + void (*kvm_mips_release_pfn_clean)(pfn_t pfn); 45 46 EXPORT_SYMBOL(kvm_mips_release_pfn_clean); 46 47 47 - bool(*kvm_mips_is_error_pfn) (pfn_t pfn); 48 + bool (*kvm_mips_is_error_pfn)(pfn_t pfn); 48 49 EXPORT_SYMBOL(kvm_mips_is_error_pfn); 49 50 50 51 uint32_t kvm_mips_get_kernel_asid(struct kvm_vcpu *vcpu) ··· 52 53 return vcpu->arch.guest_kernel_asid[smp_processor_id()] & ASID_MASK; 53 54 } 54 55 55 - 56 56 uint32_t kvm_mips_get_user_asid(struct kvm_vcpu *vcpu) 57 57 { 58 58 return vcpu->arch.guest_user_asid[smp_processor_id()] & ASID_MASK; 59 59 } 60 60 61 - inline uint32_t kvm_mips_get_commpage_asid (struct kvm_vcpu *vcpu) 61 + inline uint32_t kvm_mips_get_commpage_asid(struct kvm_vcpu *vcpu) 62 62 { 63 63 return vcpu->kvm->arch.commpage_tlb; 64 64 } 65 65 66 - 67 - /* 68 - * Structure defining an tlb entry data set. 69 - */ 66 + /* Structure defining an tlb entry data set. */ 70 67 71 68 void kvm_mips_dump_host_tlbs(void) 72 69 { ··· 77 82 old_entryhi = read_c0_entryhi(); 78 83 old_pagemask = read_c0_pagemask(); 79 84 80 - printk("HOST TLBs:\n"); 81 - printk("ASID: %#lx\n", read_c0_entryhi() & ASID_MASK); 85 + kvm_info("HOST TLBs:\n"); 86 + kvm_info("ASID: %#lx\n", read_c0_entryhi() & ASID_MASK); 82 87 83 88 for (i = 0; i < current_cpu_data.tlbsize; i++) { 84 89 write_c0_index(i); ··· 92 97 tlb.tlb_lo1 = read_c0_entrylo1(); 93 98 tlb.tlb_mask = read_c0_pagemask(); 94 99 95 - printk("TLB%c%3d Hi 0x%08lx ", 96 - (tlb.tlb_lo0 | tlb.tlb_lo1) & MIPS3_PG_V ? ' ' : '*', 97 - i, tlb.tlb_hi); 98 - printk("Lo0=0x%09" PRIx64 " %c%c attr %lx ", 99 - (uint64_t) mips3_tlbpfn_to_paddr(tlb.tlb_lo0), 100 - (tlb.tlb_lo0 & MIPS3_PG_D) ? 'D' : ' ', 101 - (tlb.tlb_lo0 & MIPS3_PG_G) ? 'G' : ' ', 102 - (tlb.tlb_lo0 >> 3) & 7); 103 - printk("Lo1=0x%09" PRIx64 " %c%c attr %lx sz=%lx\n", 104 - (uint64_t) mips3_tlbpfn_to_paddr(tlb.tlb_lo1), 105 - (tlb.tlb_lo1 & MIPS3_PG_D) ? 'D' : ' ', 106 - (tlb.tlb_lo1 & MIPS3_PG_G) ? 'G' : ' ', 107 - (tlb.tlb_lo1 >> 3) & 7, tlb.tlb_mask); 100 + kvm_info("TLB%c%3d Hi 0x%08lx ", 101 + (tlb.tlb_lo0 | tlb.tlb_lo1) & MIPS3_PG_V ? ' ' : '*', 102 + i, tlb.tlb_hi); 103 + kvm_info("Lo0=0x%09" PRIx64 " %c%c attr %lx ", 104 + (uint64_t) mips3_tlbpfn_to_paddr(tlb.tlb_lo0), 105 + (tlb.tlb_lo0 & MIPS3_PG_D) ? 'D' : ' ', 106 + (tlb.tlb_lo0 & MIPS3_PG_G) ? 'G' : ' ', 107 + (tlb.tlb_lo0 >> 3) & 7); 108 + kvm_info("Lo1=0x%09" PRIx64 " %c%c attr %lx sz=%lx\n", 109 + (uint64_t) mips3_tlbpfn_to_paddr(tlb.tlb_lo1), 110 + (tlb.tlb_lo1 & MIPS3_PG_D) ? 'D' : ' ', 111 + (tlb.tlb_lo1 & MIPS3_PG_G) ? 'G' : ' ', 112 + (tlb.tlb_lo1 >> 3) & 7, tlb.tlb_mask); 108 113 } 109 114 write_c0_entryhi(old_entryhi); 110 115 write_c0_pagemask(old_pagemask); 111 116 mtc0_tlbw_hazard(); 112 117 local_irq_restore(flags); 113 118 } 119 + EXPORT_SYMBOL(kvm_mips_dump_host_tlbs); 114 120 115 121 void kvm_mips_dump_guest_tlbs(struct kvm_vcpu *vcpu) 116 122 { ··· 119 123 struct kvm_mips_tlb tlb; 120 124 int i; 121 125 122 - printk("Guest TLBs:\n"); 123 - printk("Guest EntryHi: %#lx\n", kvm_read_c0_guest_entryhi(cop0)); 126 + kvm_info("Guest TLBs:\n"); 127 + kvm_info("Guest EntryHi: %#lx\n", kvm_read_c0_guest_entryhi(cop0)); 124 128 125 129 for (i = 0; i < KVM_MIPS_GUEST_TLB_SIZE; i++) { 126 130 tlb = vcpu->arch.guest_tlb[i]; 127 - printk("TLB%c%3d Hi 0x%08lx ", 128 - (tlb.tlb_lo0 | tlb.tlb_lo1) & MIPS3_PG_V ? ' ' : '*', 129 - i, tlb.tlb_hi); 130 - printk("Lo0=0x%09" PRIx64 " %c%c attr %lx ", 131 - (uint64_t) mips3_tlbpfn_to_paddr(tlb.tlb_lo0), 132 - (tlb.tlb_lo0 & MIPS3_PG_D) ? 'D' : ' ', 133 - (tlb.tlb_lo0 & MIPS3_PG_G) ? 'G' : ' ', 134 - (tlb.tlb_lo0 >> 3) & 7); 135 - printk("Lo1=0x%09" PRIx64 " %c%c attr %lx sz=%lx\n", 136 - (uint64_t) mips3_tlbpfn_to_paddr(tlb.tlb_lo1), 137 - (tlb.tlb_lo1 & MIPS3_PG_D) ? 'D' : ' ', 138 - (tlb.tlb_lo1 & MIPS3_PG_G) ? 'G' : ' ', 139 - (tlb.tlb_lo1 >> 3) & 7, tlb.tlb_mask); 131 + kvm_info("TLB%c%3d Hi 0x%08lx ", 132 + (tlb.tlb_lo0 | tlb.tlb_lo1) & MIPS3_PG_V ? ' ' : '*', 133 + i, tlb.tlb_hi); 134 + kvm_info("Lo0=0x%09" PRIx64 " %c%c attr %lx ", 135 + (uint64_t) mips3_tlbpfn_to_paddr(tlb.tlb_lo0), 136 + (tlb.tlb_lo0 & MIPS3_PG_D) ? 'D' : ' ', 137 + (tlb.tlb_lo0 & MIPS3_PG_G) ? 'G' : ' ', 138 + (tlb.tlb_lo0 >> 3) & 7); 139 + kvm_info("Lo1=0x%09" PRIx64 " %c%c attr %lx sz=%lx\n", 140 + (uint64_t) mips3_tlbpfn_to_paddr(tlb.tlb_lo1), 141 + (tlb.tlb_lo1 & MIPS3_PG_D) ? 'D' : ' ', 142 + (tlb.tlb_lo1 & MIPS3_PG_G) ? 'G' : ' ', 143 + (tlb.tlb_lo1 >> 3) & 7, tlb.tlb_mask); 140 144 } 141 145 } 146 + EXPORT_SYMBOL(kvm_mips_dump_guest_tlbs); 142 147 143 148 static int kvm_mips_map_page(struct kvm *kvm, gfn_t gfn) 144 149 { ··· 149 152 if (kvm->arch.guest_pmap[gfn] != KVM_INVALID_PAGE) 150 153 return 0; 151 154 152 - srcu_idx = srcu_read_lock(&kvm->srcu); 155 + srcu_idx = srcu_read_lock(&kvm->srcu); 153 156 pfn = kvm_mips_gfn_to_pfn(kvm, gfn); 154 157 155 158 if (kvm_mips_is_error_pfn(pfn)) { ··· 166 169 167 170 /* Translate guest KSEG0 addresses to Host PA */ 168 171 unsigned long kvm_mips_translate_guest_kseg0_to_hpa(struct kvm_vcpu *vcpu, 169 - unsigned long gva) 172 + unsigned long gva) 170 173 { 171 174 gfn_t gfn; 172 175 uint32_t offset = gva & ~PAGE_MASK; ··· 191 194 192 195 return (kvm->arch.guest_pmap[gfn] << PAGE_SHIFT) + offset; 193 196 } 197 + EXPORT_SYMBOL(kvm_mips_translate_guest_kseg0_to_hpa); 194 198 195 199 /* XXXKYMA: Must be called with interrupts disabled */ 196 200 /* set flush_dcache_mask == 0 if no dcache flush required */ 197 - int 198 - kvm_mips_host_tlb_write(struct kvm_vcpu *vcpu, unsigned long entryhi, 199 - unsigned long entrylo0, unsigned long entrylo1, int flush_dcache_mask) 201 + int kvm_mips_host_tlb_write(struct kvm_vcpu *vcpu, unsigned long entryhi, 202 + unsigned long entrylo0, unsigned long entrylo1, 203 + int flush_dcache_mask) 200 204 { 201 205 unsigned long flags; 202 206 unsigned long old_entryhi; 203 - volatile int idx; 207 + int idx; 204 208 205 209 local_irq_save(flags); 206 - 207 210 208 211 old_entryhi = read_c0_entryhi(); 209 212 write_c0_entryhi(entryhi); ··· 237 240 if (flush_dcache_mask) { 238 241 if (entrylo0 & MIPS3_PG_V) { 239 242 ++vcpu->stat.flush_dcache_exits; 240 - flush_data_cache_page((entryhi & VPN2_MASK) & ~flush_dcache_mask); 243 + flush_data_cache_page((entryhi & VPN2_MASK) & 244 + ~flush_dcache_mask); 241 245 } 242 246 if (entrylo1 & MIPS3_PG_V) { 243 247 ++vcpu->stat.flush_dcache_exits; 244 - flush_data_cache_page(((entryhi & VPN2_MASK) & ~flush_dcache_mask) | 245 - (0x1 << PAGE_SHIFT)); 248 + flush_data_cache_page(((entryhi & VPN2_MASK) & 249 + ~flush_dcache_mask) | 250 + (0x1 << PAGE_SHIFT)); 246 251 } 247 252 } 248 253 ··· 256 257 return 0; 257 258 } 258 259 259 - 260 260 /* XXXKYMA: Must be called with interrupts disabled */ 261 261 int kvm_mips_handle_kseg0_tlb_fault(unsigned long badvaddr, 262 - struct kvm_vcpu *vcpu) 262 + struct kvm_vcpu *vcpu) 263 263 { 264 264 gfn_t gfn; 265 265 pfn_t pfn0, pfn1; ··· 267 269 int even; 268 270 struct kvm *kvm = vcpu->kvm; 269 271 const int flush_dcache_mask = 0; 270 - 271 272 272 273 if (KVM_GUEST_KSEGX(badvaddr) != KVM_GUEST_KSEG0) { 273 274 kvm_err("%s: Invalid BadVaddr: %#lx\n", __func__, badvaddr); ··· 299 302 } 300 303 301 304 entryhi = (vaddr | kvm_mips_get_kernel_asid(vcpu)); 302 - entrylo0 = mips3_paddr_to_tlbpfn(pfn0 << PAGE_SHIFT) | (0x3 << 3) | (1 << 2) | 303 - (0x1 << 1); 304 - entrylo1 = mips3_paddr_to_tlbpfn(pfn1 << PAGE_SHIFT) | (0x3 << 3) | (1 << 2) | 305 - (0x1 << 1); 305 + entrylo0 = mips3_paddr_to_tlbpfn(pfn0 << PAGE_SHIFT) | (0x3 << 3) | 306 + (1 << 2) | (0x1 << 1); 307 + entrylo1 = mips3_paddr_to_tlbpfn(pfn1 << PAGE_SHIFT) | (0x3 << 3) | 308 + (1 << 2) | (0x1 << 1); 306 309 307 310 return kvm_mips_host_tlb_write(vcpu, entryhi, entrylo0, entrylo1, 308 311 flush_dcache_mask); 309 312 } 313 + EXPORT_SYMBOL(kvm_mips_handle_kseg0_tlb_fault); 310 314 311 315 int kvm_mips_handle_commpage_tlb_fault(unsigned long badvaddr, 312 316 struct kvm_vcpu *vcpu) ··· 316 318 unsigned long flags, old_entryhi = 0, vaddr = 0; 317 319 unsigned long entrylo0 = 0, entrylo1 = 0; 318 320 319 - 320 321 pfn0 = CPHYSADDR(vcpu->arch.kseg0_commpage) >> PAGE_SHIFT; 321 322 pfn1 = 0; 322 - entrylo0 = mips3_paddr_to_tlbpfn(pfn0 << PAGE_SHIFT) | (0x3 << 3) | (1 << 2) | 323 - (0x1 << 1); 323 + entrylo0 = mips3_paddr_to_tlbpfn(pfn0 << PAGE_SHIFT) | (0x3 << 3) | 324 + (1 << 2) | (0x1 << 1); 324 325 entrylo1 = 0; 325 326 326 327 local_irq_save(flags); ··· 338 341 mtc0_tlbw_hazard(); 339 342 tlbw_use_hazard(); 340 343 341 - kvm_debug ("@ %#lx idx: %2d [entryhi(R): %#lx] entrylo0 (R): 0x%08lx, entrylo1(R): 0x%08lx\n", 342 - vcpu->arch.pc, read_c0_index(), read_c0_entryhi(), 343 - read_c0_entrylo0(), read_c0_entrylo1()); 344 + kvm_debug("@ %#lx idx: %2d [entryhi(R): %#lx] entrylo0 (R): 0x%08lx, entrylo1(R): 0x%08lx\n", 345 + vcpu->arch.pc, read_c0_index(), read_c0_entryhi(), 346 + read_c0_entrylo0(), read_c0_entrylo1()); 344 347 345 348 /* Restore old ASID */ 346 349 write_c0_entryhi(old_entryhi); ··· 350 353 351 354 return 0; 352 355 } 356 + EXPORT_SYMBOL(kvm_mips_handle_commpage_tlb_fault); 353 357 354 - int 355 - kvm_mips_handle_mapped_seg_tlb_fault(struct kvm_vcpu *vcpu, 356 - struct kvm_mips_tlb *tlb, unsigned long *hpa0, unsigned long *hpa1) 358 + int kvm_mips_handle_mapped_seg_tlb_fault(struct kvm_vcpu *vcpu, 359 + struct kvm_mips_tlb *tlb, 360 + unsigned long *hpa0, 361 + unsigned long *hpa1) 357 362 { 358 363 unsigned long entryhi = 0, entrylo0 = 0, entrylo1 = 0; 359 364 struct kvm *kvm = vcpu->kvm; 360 365 pfn_t pfn0, pfn1; 361 366 362 - 363 367 if ((tlb->tlb_hi & VPN2_MASK) == 0) { 364 368 pfn0 = 0; 365 369 pfn1 = 0; 366 370 } else { 367 - if (kvm_mips_map_page(kvm, mips3_tlbpfn_to_paddr(tlb->tlb_lo0) >> PAGE_SHIFT) < 0) 371 + if (kvm_mips_map_page(kvm, mips3_tlbpfn_to_paddr(tlb->tlb_lo0) 372 + >> PAGE_SHIFT) < 0) 368 373 return -1; 369 374 370 - if (kvm_mips_map_page(kvm, mips3_tlbpfn_to_paddr(tlb->tlb_lo1) >> PAGE_SHIFT) < 0) 375 + if (kvm_mips_map_page(kvm, mips3_tlbpfn_to_paddr(tlb->tlb_lo1) 376 + >> PAGE_SHIFT) < 0) 371 377 return -1; 372 378 373 - pfn0 = kvm->arch.guest_pmap[mips3_tlbpfn_to_paddr(tlb->tlb_lo0) >> PAGE_SHIFT]; 374 - pfn1 = kvm->arch.guest_pmap[mips3_tlbpfn_to_paddr(tlb->tlb_lo1) >> PAGE_SHIFT]; 379 + pfn0 = kvm->arch.guest_pmap[mips3_tlbpfn_to_paddr(tlb->tlb_lo0) 380 + >> PAGE_SHIFT]; 381 + pfn1 = kvm->arch.guest_pmap[mips3_tlbpfn_to_paddr(tlb->tlb_lo1) 382 + >> PAGE_SHIFT]; 375 383 } 376 384 377 385 if (hpa0) ··· 387 385 388 386 /* Get attributes from the Guest TLB */ 389 387 entryhi = (tlb->tlb_hi & VPN2_MASK) | (KVM_GUEST_KERNEL_MODE(vcpu) ? 390 - kvm_mips_get_kernel_asid(vcpu) : kvm_mips_get_user_asid(vcpu)); 388 + kvm_mips_get_kernel_asid(vcpu) : 389 + kvm_mips_get_user_asid(vcpu)); 391 390 entrylo0 = mips3_paddr_to_tlbpfn(pfn0 << PAGE_SHIFT) | (0x3 << 3) | 392 - (tlb->tlb_lo0 & MIPS3_PG_D) | (tlb->tlb_lo0 & MIPS3_PG_V); 391 + (tlb->tlb_lo0 & MIPS3_PG_D) | (tlb->tlb_lo0 & MIPS3_PG_V); 393 392 entrylo1 = mips3_paddr_to_tlbpfn(pfn1 << PAGE_SHIFT) | (0x3 << 3) | 394 - (tlb->tlb_lo1 & MIPS3_PG_D) | (tlb->tlb_lo1 & MIPS3_PG_V); 393 + (tlb->tlb_lo1 & MIPS3_PG_D) | (tlb->tlb_lo1 & MIPS3_PG_V); 395 394 396 395 kvm_debug("@ %#lx tlb_lo0: 0x%08lx tlb_lo1: 0x%08lx\n", vcpu->arch.pc, 397 396 tlb->tlb_lo0, tlb->tlb_lo1); ··· 400 397 return kvm_mips_host_tlb_write(vcpu, entryhi, entrylo0, entrylo1, 401 398 tlb->tlb_mask); 402 399 } 400 + EXPORT_SYMBOL(kvm_mips_handle_mapped_seg_tlb_fault); 403 401 404 402 int kvm_mips_guest_tlb_lookup(struct kvm_vcpu *vcpu, unsigned long entryhi) 405 403 { ··· 408 404 int index = -1; 409 405 struct kvm_mips_tlb *tlb = vcpu->arch.guest_tlb; 410 406 411 - 412 407 for (i = 0; i < KVM_MIPS_GUEST_TLB_SIZE; i++) { 413 - if (((TLB_VPN2(tlb[i]) & ~tlb[i].tlb_mask) == ((entryhi & VPN2_MASK) & ~tlb[i].tlb_mask)) && 414 - (TLB_IS_GLOBAL(tlb[i]) || (TLB_ASID(tlb[i]) == (entryhi & ASID_MASK)))) { 408 + if (TLB_HI_VPN2_HIT(tlb[i], entryhi) && 409 + TLB_HI_ASID_HIT(tlb[i], entryhi)) { 415 410 index = i; 416 411 break; 417 412 } ··· 421 418 422 419 return index; 423 420 } 421 + EXPORT_SYMBOL(kvm_mips_guest_tlb_lookup); 424 422 425 423 int kvm_mips_host_tlb_lookup(struct kvm_vcpu *vcpu, unsigned long vaddr) 426 424 { 427 425 unsigned long old_entryhi, flags; 428 - volatile int idx; 429 - 426 + int idx; 430 427 431 428 local_irq_save(flags); 432 429 433 430 old_entryhi = read_c0_entryhi(); 434 431 435 432 if (KVM_GUEST_KERNEL_MODE(vcpu)) 436 - write_c0_entryhi((vaddr & VPN2_MASK) | kvm_mips_get_kernel_asid(vcpu)); 433 + write_c0_entryhi((vaddr & VPN2_MASK) | 434 + kvm_mips_get_kernel_asid(vcpu)); 437 435 else { 438 - write_c0_entryhi((vaddr & VPN2_MASK) | kvm_mips_get_user_asid(vcpu)); 436 + write_c0_entryhi((vaddr & VPN2_MASK) | 437 + kvm_mips_get_user_asid(vcpu)); 439 438 } 440 439 441 440 mtc0_tlbw_hazard(); ··· 457 452 458 453 return idx; 459 454 } 455 + EXPORT_SYMBOL(kvm_mips_host_tlb_lookup); 460 456 461 457 int kvm_mips_host_tlb_inv(struct kvm_vcpu *vcpu, unsigned long va) 462 458 { ··· 465 459 unsigned long flags, old_entryhi; 466 460 467 461 local_irq_save(flags); 468 - 469 462 470 463 old_entryhi = read_c0_entryhi(); 471 464 ··· 504 499 505 500 return 0; 506 501 } 502 + EXPORT_SYMBOL(kvm_mips_host_tlb_inv); 507 503 508 - /* XXXKYMA: Fix Guest USER/KERNEL no longer share the same ASID*/ 504 + /* XXXKYMA: Fix Guest USER/KERNEL no longer share the same ASID */ 509 505 int kvm_mips_host_tlb_inv_index(struct kvm_vcpu *vcpu, int index) 510 506 { 511 507 unsigned long flags, old_entryhi; ··· 515 509 BUG(); 516 510 517 511 local_irq_save(flags); 518 - 519 512 520 513 old_entryhi = read_c0_entryhi(); 521 514 ··· 551 546 int entry = 0; 552 547 int maxentry = current_cpu_data.tlbsize; 553 548 554 - 555 549 local_irq_save(flags); 556 550 557 551 old_entryhi = read_c0_entryhi(); ··· 558 554 559 555 /* Blast 'em all away. */ 560 556 for (entry = 0; entry < maxentry; entry++) { 561 - 562 557 write_c0_index(entry); 563 558 mtc0_tlbw_hazard(); 564 559 ··· 568 565 entryhi = read_c0_entryhi(); 569 566 570 567 /* Don't blow away guest kernel entries */ 571 - if (KVM_GUEST_KSEGX(entryhi) == KVM_GUEST_KSEG0) { 568 + if (KVM_GUEST_KSEGX(entryhi) == KVM_GUEST_KSEG0) 572 569 continue; 573 - } 574 570 } 575 571 576 572 /* Make sure all entries differ. */ ··· 593 591 594 592 local_irq_restore(flags); 595 593 } 594 + EXPORT_SYMBOL(kvm_mips_flush_host_tlb); 596 595 597 - void 598 - kvm_get_new_mmu_context(struct mm_struct *mm, unsigned long cpu, 599 - struct kvm_vcpu *vcpu) 596 + void kvm_get_new_mmu_context(struct mm_struct *mm, unsigned long cpu, 597 + struct kvm_vcpu *vcpu) 600 598 { 601 599 unsigned long asid = asid_cache(cpu); 602 600 603 - if (!((asid += ASID_INC) & ASID_MASK)) { 604 - if (cpu_has_vtag_icache) { 601 + asid += ASID_INC; 602 + if (!(asid & ASID_MASK)) { 603 + if (cpu_has_vtag_icache) 605 604 flush_icache_all(); 606 - } 607 605 608 606 kvm_local_flush_tlb_all(); /* start new asid cycle */ 609 607 ··· 641 639 642 640 local_irq_restore(flags); 643 641 } 642 + EXPORT_SYMBOL(kvm_local_flush_tlb_all); 644 643 645 644 /** 646 645 * kvm_mips_migrate_count() - Migrate timer. ··· 702 699 } 703 700 704 701 if (!newasid) { 705 - /* If we preempted while the guest was executing, then reload the pre-empted ASID */ 702 + /* 703 + * If we preempted while the guest was executing, then reload 704 + * the pre-empted ASID 705 + */ 706 706 if (current->flags & PF_VCPU) { 707 707 write_c0_entryhi(vcpu->arch. 708 708 preempt_entryhi & ASID_MASK); ··· 714 708 } else { 715 709 /* New ASIDs were allocated for the VM */ 716 710 717 - /* Were we in guest context? If so then the pre-empted ASID is no longer 718 - * valid, we need to set it to what it should be based on the mode of 719 - * the Guest (Kernel/User) 711 + /* 712 + * Were we in guest context? If so then the pre-empted ASID is 713 + * no longer valid, we need to set it to what it should be based 714 + * on the mode of the Guest (Kernel/User) 720 715 */ 721 716 if (current->flags & PF_VCPU) { 722 717 if (KVM_GUEST_KERNEL_MODE(vcpu)) ··· 735 728 local_irq_restore(flags); 736 729 737 730 } 731 + EXPORT_SYMBOL(kvm_arch_vcpu_load); 738 732 739 733 /* ASID can change if another task is scheduled during preemption */ 740 734 void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) ··· 746 738 local_irq_save(flags); 747 739 748 740 cpu = smp_processor_id(); 749 - 750 741 751 742 vcpu->arch.preempt_entryhi = read_c0_entryhi(); 752 743 vcpu->arch.last_sched_cpu = cpu; ··· 761 754 762 755 local_irq_restore(flags); 763 756 } 757 + EXPORT_SYMBOL(kvm_arch_vcpu_put); 764 758 765 759 uint32_t kvm_get_inst(uint32_t *opc, struct kvm_vcpu *vcpu) 766 760 { 767 761 struct mips_coproc *cop0 = vcpu->arch.cop0; 768 - unsigned long paddr, flags; 762 + unsigned long paddr, flags, vpn2, asid; 769 763 uint32_t inst; 770 764 int index; 771 765 ··· 777 769 if (index >= 0) { 778 770 inst = *(opc); 779 771 } else { 780 - index = 781 - kvm_mips_guest_tlb_lookup(vcpu, 782 - ((unsigned long) opc & VPN2_MASK) 783 - | 784 - (kvm_read_c0_guest_entryhi 785 - (cop0) & ASID_MASK)); 772 + vpn2 = (unsigned long) opc & VPN2_MASK; 773 + asid = kvm_read_c0_guest_entryhi(cop0) & ASID_MASK; 774 + index = kvm_mips_guest_tlb_lookup(vcpu, vpn2 | asid); 786 775 if (index < 0) { 787 - kvm_err 788 - ("%s: get_user_failed for %p, vcpu: %p, ASID: %#lx\n", 789 - __func__, opc, vcpu, read_c0_entryhi()); 776 + kvm_err("%s: get_user_failed for %p, vcpu: %p, ASID: %#lx\n", 777 + __func__, opc, vcpu, read_c0_entryhi()); 790 778 kvm_mips_dump_host_tlbs(); 791 779 local_irq_restore(flags); 792 780 return KVM_INVALID_INST; ··· 797 793 } else if (KVM_GUEST_KSEGX(opc) == KVM_GUEST_KSEG0) { 798 794 paddr = 799 795 kvm_mips_translate_guest_kseg0_to_hpa(vcpu, 800 - (unsigned long) opc); 796 + (unsigned long) opc); 801 797 inst = *(uint32_t *) CKSEG0ADDR(paddr); 802 798 } else { 803 799 kvm_err("%s: illegal address: %p\n", __func__, opc); ··· 806 802 807 803 return inst; 808 804 } 809 - 810 - EXPORT_SYMBOL(kvm_local_flush_tlb_all); 811 - EXPORT_SYMBOL(kvm_mips_handle_mapped_seg_tlb_fault); 812 - EXPORT_SYMBOL(kvm_mips_handle_commpage_tlb_fault); 813 - EXPORT_SYMBOL(kvm_mips_dump_host_tlbs); 814 - EXPORT_SYMBOL(kvm_mips_handle_kseg0_tlb_fault); 815 - EXPORT_SYMBOL(kvm_mips_host_tlb_lookup); 816 - EXPORT_SYMBOL(kvm_mips_flush_host_tlb); 817 - EXPORT_SYMBOL(kvm_mips_guest_tlb_lookup); 818 - EXPORT_SYMBOL(kvm_mips_host_tlb_inv); 819 - EXPORT_SYMBOL(kvm_mips_translate_guest_kseg0_to_hpa); 820 - EXPORT_SYMBOL(kvm_mips_dump_guest_tlbs); 821 805 EXPORT_SYMBOL(kvm_get_inst); 822 - EXPORT_SYMBOL(kvm_arch_vcpu_load); 823 - EXPORT_SYMBOL(kvm_arch_vcpu_put);
+55 -57
arch/mips/kvm/kvm_trap_emul.c arch/mips/kvm/trap_emul.c
··· 1 1 /* 2 - * This file is subject to the terms and conditions of the GNU General Public 3 - * License. See the file "COPYING" in the main directory of this archive 4 - * for more details. 5 - * 6 - * KVM/MIPS: Deliver/Emulate exceptions to the guest kernel 7 - * 8 - * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 9 - * Authors: Sanjay Lal <sanjayl@kymasys.com> 10 - */ 2 + * This file is subject to the terms and conditions of the GNU General Public 3 + * License. See the file "COPYING" in the main directory of this archive 4 + * for more details. 5 + * 6 + * KVM/MIPS: Deliver/Emulate exceptions to the guest kernel 7 + * 8 + * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 9 + * Authors: Sanjay Lal <sanjayl@kymasys.com> 10 + */ 11 11 12 12 #include <linux/errno.h> 13 13 #include <linux/err.h> ··· 16 16 17 17 #include <linux/kvm_host.h> 18 18 19 - #include "kvm_mips_opcode.h" 20 - #include "kvm_mips_int.h" 19 + #include "opcode.h" 20 + #include "interrupt.h" 21 21 22 22 static gpa_t kvm_trap_emul_gva_to_gpa_cb(gva_t gva) 23 23 { ··· 27 27 if ((kseg == CKSEG0) || (kseg == CKSEG1)) 28 28 gpa = CPHYSADDR(gva); 29 29 else { 30 - printk("%s: cannot find GPA for GVA: %#lx\n", __func__, gva); 30 + kvm_err("%s: cannot find GPA for GVA: %#lx\n", __func__, gva); 31 31 kvm_mips_dump_host_tlbs(); 32 32 gpa = KVM_INVALID_ADDR; 33 33 } ··· 37 37 return gpa; 38 38 } 39 39 40 - 41 40 static int kvm_trap_emul_handle_cop_unusable(struct kvm_vcpu *vcpu) 42 41 { 43 42 struct kvm_run *run = vcpu->run; ··· 45 46 enum emulation_result er = EMULATE_DONE; 46 47 int ret = RESUME_GUEST; 47 48 48 - if (((cause & CAUSEF_CE) >> CAUSEB_CE) == 1) { 49 + if (((cause & CAUSEF_CE) >> CAUSEB_CE) == 1) 49 50 er = kvm_mips_emulate_fpu_exc(cause, opc, run, vcpu); 50 - } else 51 + else 51 52 er = kvm_mips_emulate_inst(cause, opc, run, vcpu); 52 53 53 54 switch (er) { ··· 82 83 83 84 if (KVM_GUEST_KSEGX(badvaddr) < KVM_GUEST_KSEG0 84 85 || KVM_GUEST_KSEGX(badvaddr) == KVM_GUEST_KSEG23) { 85 - kvm_debug 86 - ("USER/KSEG23 ADDR TLB MOD fault: cause %#lx, PC: %p, BadVaddr: %#lx\n", 87 - cause, opc, badvaddr); 86 + kvm_debug("USER/KSEG23 ADDR TLB MOD fault: cause %#lx, PC: %p, BadVaddr: %#lx\n", 87 + cause, opc, badvaddr); 88 88 er = kvm_mips_handle_tlbmod(cause, opc, run, vcpu); 89 89 90 90 if (er == EMULATE_DONE) ··· 93 95 ret = RESUME_HOST; 94 96 } 95 97 } else if (KVM_GUEST_KSEGX(badvaddr) == KVM_GUEST_KSEG0) { 96 - /* XXXKYMA: The guest kernel does not expect to get this fault when we are not 97 - * using HIGHMEM. Need to address this in a HIGHMEM kernel 98 + /* 99 + * XXXKYMA: The guest kernel does not expect to get this fault 100 + * when we are not using HIGHMEM. Need to address this in a 101 + * HIGHMEM kernel 98 102 */ 99 - printk 100 - ("TLB MOD fault not handled, cause %#lx, PC: %p, BadVaddr: %#lx\n", 101 - cause, opc, badvaddr); 103 + kvm_err("TLB MOD fault not handled, cause %#lx, PC: %p, BadVaddr: %#lx\n", 104 + cause, opc, badvaddr); 102 105 kvm_mips_dump_host_tlbs(); 103 106 kvm_arch_vcpu_dump_regs(vcpu); 104 107 run->exit_reason = KVM_EXIT_INTERNAL_ERROR; 105 108 ret = RESUME_HOST; 106 109 } else { 107 - printk 108 - ("Illegal TLB Mod fault address , cause %#lx, PC: %p, BadVaddr: %#lx\n", 109 - cause, opc, badvaddr); 110 + kvm_err("Illegal TLB Mod fault address , cause %#lx, PC: %p, BadVaddr: %#lx\n", 111 + cause, opc, badvaddr); 110 112 kvm_mips_dump_host_tlbs(); 111 113 kvm_arch_vcpu_dump_regs(vcpu); 112 114 run->exit_reason = KVM_EXIT_INTERNAL_ERROR; ··· 132 134 } 133 135 } else if (KVM_GUEST_KSEGX(badvaddr) < KVM_GUEST_KSEG0 134 136 || KVM_GUEST_KSEGX(badvaddr) == KVM_GUEST_KSEG23) { 135 - kvm_debug 136 - ("USER ADDR TLB LD fault: cause %#lx, PC: %p, BadVaddr: %#lx\n", 137 - cause, opc, badvaddr); 137 + kvm_debug("USER ADDR TLB LD fault: cause %#lx, PC: %p, BadVaddr: %#lx\n", 138 + cause, opc, badvaddr); 138 139 er = kvm_mips_handle_tlbmiss(cause, opc, run, vcpu); 139 140 if (er == EMULATE_DONE) 140 141 ret = RESUME_GUEST; ··· 142 145 ret = RESUME_HOST; 143 146 } 144 147 } else if (KVM_GUEST_KSEGX(badvaddr) == KVM_GUEST_KSEG0) { 145 - /* All KSEG0 faults are handled by KVM, as the guest kernel does not 146 - * expect to ever get them 148 + /* 149 + * All KSEG0 faults are handled by KVM, as the guest kernel does 150 + * not expect to ever get them 147 151 */ 148 152 if (kvm_mips_handle_kseg0_tlb_fault 149 153 (vcpu->arch.host_cp0_badvaddr, vcpu) < 0) { ··· 152 154 ret = RESUME_HOST; 153 155 } 154 156 } else { 155 - kvm_err 156 - ("Illegal TLB LD fault address , cause %#lx, PC: %p, BadVaddr: %#lx\n", 157 - cause, opc, badvaddr); 157 + kvm_err("Illegal TLB LD fault address , cause %#lx, PC: %p, BadVaddr: %#lx\n", 158 + cause, opc, badvaddr); 158 159 kvm_mips_dump_host_tlbs(); 159 160 kvm_arch_vcpu_dump_regs(vcpu); 160 161 run->exit_reason = KVM_EXIT_INTERNAL_ERROR; ··· 182 185 kvm_debug("USER ADDR TLB ST fault: PC: %#lx, BadVaddr: %#lx\n", 183 186 vcpu->arch.pc, badvaddr); 184 187 185 - /* User Address (UA) fault, this could happen if 186 - * (1) TLB entry not present/valid in both Guest and shadow host TLBs, in this 187 - * case we pass on the fault to the guest kernel and let it handle it. 188 - * (2) TLB entry is present in the Guest TLB but not in the shadow, in this 189 - * case we inject the TLB from the Guest TLB into the shadow host TLB 188 + /* 189 + * User Address (UA) fault, this could happen if 190 + * (1) TLB entry not present/valid in both Guest and shadow host 191 + * TLBs, in this case we pass on the fault to the guest 192 + * kernel and let it handle it. 193 + * (2) TLB entry is present in the Guest TLB but not in the 194 + * shadow, in this case we inject the TLB from the Guest TLB 195 + * into the shadow host TLB 190 196 */ 191 197 192 198 er = kvm_mips_handle_tlbmiss(cause, opc, run, vcpu); ··· 206 206 ret = RESUME_HOST; 207 207 } 208 208 } else { 209 - printk 210 - ("Illegal TLB ST fault address , cause %#lx, PC: %p, BadVaddr: %#lx\n", 211 - cause, opc, badvaddr); 209 + kvm_err("Illegal TLB ST fault address , cause %#lx, PC: %p, BadVaddr: %#lx\n", 210 + cause, opc, badvaddr); 212 211 kvm_mips_dump_host_tlbs(); 213 212 kvm_arch_vcpu_dump_regs(vcpu); 214 213 run->exit_reason = KVM_EXIT_INTERNAL_ERROR; ··· 230 231 kvm_debug("Emulate Store to MMIO space\n"); 231 232 er = kvm_mips_emulate_inst(cause, opc, run, vcpu); 232 233 if (er == EMULATE_FAIL) { 233 - printk("Emulate Store to MMIO space failed\n"); 234 + kvm_err("Emulate Store to MMIO space failed\n"); 234 235 run->exit_reason = KVM_EXIT_INTERNAL_ERROR; 235 236 ret = RESUME_HOST; 236 237 } else { ··· 238 239 ret = RESUME_HOST; 239 240 } 240 241 } else { 241 - printk 242 - ("Address Error (STORE): cause %#lx, PC: %p, BadVaddr: %#lx\n", 243 - cause, opc, badvaddr); 242 + kvm_err("Address Error (STORE): cause %#lx, PC: %p, BadVaddr: %#lx\n", 243 + cause, opc, badvaddr); 244 244 run->exit_reason = KVM_EXIT_INTERNAL_ERROR; 245 245 ret = RESUME_HOST; 246 246 } ··· 259 261 kvm_debug("Emulate Load from MMIO space @ %#lx\n", badvaddr); 260 262 er = kvm_mips_emulate_inst(cause, opc, run, vcpu); 261 263 if (er == EMULATE_FAIL) { 262 - printk("Emulate Load from MMIO space failed\n"); 264 + kvm_err("Emulate Load from MMIO space failed\n"); 263 265 run->exit_reason = KVM_EXIT_INTERNAL_ERROR; 264 266 ret = RESUME_HOST; 265 267 } else { ··· 267 269 ret = RESUME_HOST; 268 270 } 269 271 } else { 270 - printk 271 - ("Address Error (LOAD): cause %#lx, PC: %p, BadVaddr: %#lx\n", 272 - cause, opc, badvaddr); 272 + kvm_err("Address Error (LOAD): cause %#lx, PC: %p, BadVaddr: %#lx\n", 273 + cause, opc, badvaddr); 273 274 run->exit_reason = KVM_EXIT_INTERNAL_ERROR; 274 275 ret = RESUME_HOST; 275 276 er = EMULATE_FAIL; ··· 346 349 uint32_t config1; 347 350 int vcpu_id = vcpu->vcpu_id; 348 351 349 - /* Arch specific stuff, set up config registers properly so that the 350 - * guest will come up as expected, for now we simulate a 351 - * MIPS 24kc 352 + /* 353 + * Arch specific stuff, set up config registers properly so that the 354 + * guest will come up as expected, for now we simulate a MIPS 24kc 352 355 */ 353 356 kvm_write_c0_guest_prid(cop0, 0x00019300); 354 357 kvm_write_c0_guest_config(cop0, ··· 370 373 371 374 kvm_write_c0_guest_config2(cop0, MIPS_CONFIG2); 372 375 /* MIPS_CONFIG2 | (read_c0_config2() & 0xfff) */ 373 - kvm_write_c0_guest_config3(cop0, 374 - MIPS_CONFIG3 | (0 << CP0C3_VInt) | (1 << 375 - CP0C3_ULRI)); 376 + kvm_write_c0_guest_config3(cop0, MIPS_CONFIG3 | (0 << CP0C3_VInt) | 377 + (1 << CP0C3_ULRI)); 376 378 377 379 /* Set Wait IE/IXMT Ignore in Config7, IAR, AR */ 378 380 kvm_write_c0_guest_config7(cop0, (MIPS_CONF7_WII) | (1 << 10)); 379 381 380 - /* Setup IntCtl defaults, compatibilty mode for timer interrupts (HW5) */ 382 + /* 383 + * Setup IntCtl defaults, compatibilty mode for timer interrupts (HW5) 384 + */ 381 385 kvm_write_c0_guest_intctl(cop0, 0xFC000000); 382 386 383 387 /* Put in vcpu id as CPUNum into Ebase Reg to handle SMP Guests */
+22
arch/mips/kvm/opcode.h
··· 1 + /* 2 + * This file is subject to the terms and conditions of the GNU General Public 3 + * License. See the file "COPYING" in the main directory of this archive 4 + * for more details. 5 + * 6 + * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 7 + * Authors: Sanjay Lal <sanjayl@kymasys.com> 8 + */ 9 + 10 + /* Define opcode values not defined in <asm/isnt.h> */ 11 + 12 + #ifndef __KVM_MIPS_OPCODE_H__ 13 + #define __KVM_MIPS_OPCODE_H__ 14 + 15 + /* COP0 Ops */ 16 + #define mfmcz_op 0x0b /* 01011 */ 17 + #define wrpgpr_op 0x0e /* 01110 */ 18 + 19 + /* COP0 opcodes (only if COP0 and CO=1): */ 20 + #define wait_op 0x20 /* 100000 */ 21 + 22 + #endif /* __KVM_MIPS_OPCODE_H__ */
+8 -10
arch/mips/kvm/trace.h
··· 1 1 /* 2 - * This file is subject to the terms and conditions of the GNU General Public 3 - * License. See the file "COPYING" in the main directory of this archive 4 - * for more details. 5 - * 6 - * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 7 - * Authors: Sanjay Lal <sanjayl@kymasys.com> 8 - */ 2 + * This file is subject to the terms and conditions of the GNU General Public 3 + * License. See the file "COPYING" in the main directory of this archive 4 + * for more details. 5 + * 6 + * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 7 + * Authors: Sanjay Lal <sanjayl@kymasys.com> 8 + */ 9 9 10 10 #if !defined(_TRACE_KVM_H) || defined(TRACE_HEADER_MULTI_READ) 11 11 #define _TRACE_KVM_H ··· 17 17 #define TRACE_INCLUDE_PATH . 18 18 #define TRACE_INCLUDE_FILE trace 19 19 20 - /* 21 - * Tracepoints for VM eists 22 - */ 20 + /* Tracepoints for VM eists */ 23 21 extern char *kvm_mips_exit_types_str[MAX_KVM_MIPS_EXIT_TYPES]; 24 22 25 23 TRACE_EVENT(kvm_exit,
+1 -2
arch/s390/include/asm/kvm_host.h
··· 305 305 struct list_head list; 306 306 atomic_t active; 307 307 struct kvm_s390_float_interrupt *float_int; 308 - int timer_due; /* event indicator for waitqueue below */ 309 308 wait_queue_head_t *wq; 310 309 atomic_t *cpuflags; 311 310 unsigned int action_bits; ··· 366 367 s390_fp_regs guest_fpregs; 367 368 struct kvm_s390_local_interrupt local_int; 368 369 struct hrtimer ckc_timer; 369 - struct tasklet_struct tasklet; 370 370 struct kvm_s390_pgm_info pgm; 371 371 union { 372 372 struct cpuid cpu_id; ··· 416 418 int css_support; 417 419 int use_irqchip; 418 420 int use_cmma; 421 + int user_cpu_state_ctrl; 419 422 struct s390_io_adapter *adapters[MAX_S390_IO_ADAPTERS]; 420 423 wait_queue_head_t ipte_wq; 421 424 spinlock_t start_stop_lock;
+1
arch/s390/include/uapi/asm/sie.h
··· 108 108 exit_code_ipa0(0xB2, 0x17, "STETR"), \ 109 109 exit_code_ipa0(0xB2, 0x18, "PC"), \ 110 110 exit_code_ipa0(0xB2, 0x20, "SERVC"), \ 111 + exit_code_ipa0(0xB2, 0x21, "IPTE"), \ 111 112 exit_code_ipa0(0xB2, 0x28, "PT"), \ 112 113 exit_code_ipa0(0xB2, 0x29, "ISKE"), \ 113 114 exit_code_ipa0(0xB2, 0x2a, "RRBE"), \
+2 -1
arch/s390/kvm/diag.c
··· 176 176 return -EOPNOTSUPP; 177 177 } 178 178 179 - kvm_s390_vcpu_stop(vcpu); 179 + if (!kvm_s390_user_cpu_state_ctrl(vcpu->kvm)) 180 + kvm_s390_vcpu_stop(vcpu); 180 181 vcpu->run->s390_reset_flags |= KVM_S390_RESET_SUBSYSTEM; 181 182 vcpu->run->s390_reset_flags |= KVM_S390_RESET_IPL; 182 183 vcpu->run->s390_reset_flags |= KVM_S390_RESET_CPU_INIT;
+13 -19
arch/s390/kvm/intercept.c
··· 56 56 static int handle_stop(struct kvm_vcpu *vcpu) 57 57 { 58 58 int rc = 0; 59 + unsigned int action_bits; 59 60 60 61 vcpu->stat.exit_stop_request++; 61 - spin_lock_bh(&vcpu->arch.local_int.lock); 62 - 63 62 trace_kvm_s390_stop_request(vcpu->arch.local_int.action_bits); 64 63 65 - if (vcpu->arch.local_int.action_bits & ACTION_STOP_ON_STOP) { 66 - kvm_s390_vcpu_stop(vcpu); 67 - vcpu->arch.local_int.action_bits &= ~ACTION_STOP_ON_STOP; 68 - VCPU_EVENT(vcpu, 3, "%s", "cpu stopped"); 69 - rc = -EOPNOTSUPP; 70 - } 64 + action_bits = vcpu->arch.local_int.action_bits; 71 65 72 - if (vcpu->arch.local_int.action_bits & ACTION_STORE_ON_STOP) { 73 - vcpu->arch.local_int.action_bits &= ~ACTION_STORE_ON_STOP; 74 - /* store status must be called unlocked. Since local_int.lock 75 - * only protects local_int.* and not guest memory we can give 76 - * up the lock here */ 77 - spin_unlock_bh(&vcpu->arch.local_int.lock); 66 + if (!(action_bits & ACTION_STOP_ON_STOP)) 67 + return 0; 68 + 69 + if (action_bits & ACTION_STORE_ON_STOP) { 78 70 rc = kvm_s390_vcpu_store_status(vcpu, 79 71 KVM_S390_STORE_STATUS_NOADDR); 80 - if (rc >= 0) 81 - rc = -EOPNOTSUPP; 82 - } else 83 - spin_unlock_bh(&vcpu->arch.local_int.lock); 84 - return rc; 72 + if (rc) 73 + return rc; 74 + } 75 + 76 + if (!kvm_s390_user_cpu_state_ctrl(vcpu->kvm)) 77 + kvm_s390_vcpu_stop(vcpu); 78 + return -EOPNOTSUPP; 85 79 } 86 80 87 81 static int handle_validity(struct kvm_vcpu *vcpu)
+35 -68
arch/s390/kvm/interrupt.c
··· 158 158 LCTL_CR10 | LCTL_CR11); 159 159 vcpu->arch.sie_block->ictl |= (ICTL_STCTL | ICTL_PINT); 160 160 } 161 + 162 + if (vcpu->arch.local_int.action_bits & ACTION_STOP_ON_STOP) 163 + atomic_set_mask(CPUSTAT_STOP_INT, &vcpu->arch.sie_block->cpuflags); 161 164 } 162 165 163 166 static void __set_cpuflag(struct kvm_vcpu *vcpu, u32 flag) ··· 547 544 int rc = 0; 548 545 549 546 if (atomic_read(&li->active)) { 550 - spin_lock_bh(&li->lock); 547 + spin_lock(&li->lock); 551 548 list_for_each_entry(inti, &li->list, list) 552 549 if (__interrupt_is_deliverable(vcpu, inti)) { 553 550 rc = 1; 554 551 break; 555 552 } 556 - spin_unlock_bh(&li->lock); 553 + spin_unlock(&li->lock); 557 554 } 558 555 559 556 if ((!rc) && atomic_read(&fi->active)) { ··· 588 585 int kvm_s390_handle_wait(struct kvm_vcpu *vcpu) 589 586 { 590 587 u64 now, sltime; 591 - DECLARE_WAITQUEUE(wait, current); 592 588 593 589 vcpu->stat.exit_wait_state++; 594 - if (kvm_cpu_has_interrupt(vcpu)) 595 - return 0; 596 590 597 - __set_cpu_idle(vcpu); 598 - spin_lock_bh(&vcpu->arch.local_int.lock); 599 - vcpu->arch.local_int.timer_due = 0; 600 - spin_unlock_bh(&vcpu->arch.local_int.lock); 591 + /* fast path */ 592 + if (kvm_cpu_has_pending_timer(vcpu) || kvm_arch_vcpu_runnable(vcpu)) 593 + return 0; 601 594 602 595 if (psw_interrupts_disabled(vcpu)) { 603 596 VCPU_EVENT(vcpu, 3, "%s", "disabled wait"); 604 - __unset_cpu_idle(vcpu); 605 597 return -EOPNOTSUPP; /* disabled wait */ 606 598 } 607 599 600 + __set_cpu_idle(vcpu); 608 601 if (!ckc_interrupts_enabled(vcpu)) { 609 602 VCPU_EVENT(vcpu, 3, "%s", "enabled wait w/o timer"); 610 603 goto no_timer; 611 604 } 612 605 613 606 now = get_tod_clock_fast() + vcpu->arch.sie_block->epoch; 614 - if (vcpu->arch.sie_block->ckc < now) { 615 - __unset_cpu_idle(vcpu); 616 - return 0; 617 - } 618 - 619 607 sltime = tod_to_ns(vcpu->arch.sie_block->ckc - now); 620 - 621 608 hrtimer_start(&vcpu->arch.ckc_timer, ktime_set (0, sltime) , HRTIMER_MODE_REL); 622 609 VCPU_EVENT(vcpu, 5, "enabled wait via clock comparator: %llx ns", sltime); 623 610 no_timer: 624 611 srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx); 625 - spin_lock(&vcpu->arch.local_int.float_int->lock); 626 - spin_lock_bh(&vcpu->arch.local_int.lock); 627 - add_wait_queue(&vcpu->wq, &wait); 628 - while (list_empty(&vcpu->arch.local_int.list) && 629 - list_empty(&vcpu->arch.local_int.float_int->list) && 630 - (!vcpu->arch.local_int.timer_due) && 631 - !signal_pending(current) && 632 - !kvm_s390_si_ext_call_pending(vcpu)) { 633 - set_current_state(TASK_INTERRUPTIBLE); 634 - spin_unlock_bh(&vcpu->arch.local_int.lock); 635 - spin_unlock(&vcpu->arch.local_int.float_int->lock); 636 - schedule(); 637 - spin_lock(&vcpu->arch.local_int.float_int->lock); 638 - spin_lock_bh(&vcpu->arch.local_int.lock); 639 - } 612 + kvm_vcpu_block(vcpu); 640 613 __unset_cpu_idle(vcpu); 641 - __set_current_state(TASK_RUNNING); 642 - remove_wait_queue(&vcpu->wq, &wait); 643 - spin_unlock_bh(&vcpu->arch.local_int.lock); 644 - spin_unlock(&vcpu->arch.local_int.float_int->lock); 645 614 vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); 646 615 647 616 hrtimer_try_to_cancel(&vcpu->arch.ckc_timer); 648 617 return 0; 649 618 } 650 619 651 - void kvm_s390_tasklet(unsigned long parm) 620 + void kvm_s390_vcpu_wakeup(struct kvm_vcpu *vcpu) 652 621 { 653 - struct kvm_vcpu *vcpu = (struct kvm_vcpu *) parm; 654 - 655 - spin_lock(&vcpu->arch.local_int.lock); 656 - vcpu->arch.local_int.timer_due = 1; 657 - if (waitqueue_active(&vcpu->wq)) 622 + if (waitqueue_active(&vcpu->wq)) { 623 + /* 624 + * The vcpu gave up the cpu voluntarily, mark it as a good 625 + * yield-candidate. 626 + */ 627 + vcpu->preempted = true; 658 628 wake_up_interruptible(&vcpu->wq); 659 - spin_unlock(&vcpu->arch.local_int.lock); 629 + } 660 630 } 661 631 662 - /* 663 - * low level hrtimer wake routine. Because this runs in hardirq context 664 - * we schedule a tasklet to do the real work. 665 - */ 666 632 enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer) 667 633 { 668 634 struct kvm_vcpu *vcpu; 669 635 670 636 vcpu = container_of(timer, struct kvm_vcpu, arch.ckc_timer); 671 - vcpu->preempted = true; 672 - tasklet_schedule(&vcpu->arch.tasklet); 637 + kvm_s390_vcpu_wakeup(vcpu); 673 638 674 639 return HRTIMER_NORESTART; 675 640 } ··· 647 676 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; 648 677 struct kvm_s390_interrupt_info *n, *inti = NULL; 649 678 650 - spin_lock_bh(&li->lock); 679 + spin_lock(&li->lock); 651 680 list_for_each_entry_safe(inti, n, &li->list, list) { 652 681 list_del(&inti->list); 653 682 kfree(inti); 654 683 } 655 684 atomic_set(&li->active, 0); 656 - spin_unlock_bh(&li->lock); 685 + spin_unlock(&li->lock); 657 686 658 687 /* clear pending external calls set by sigp interpretation facility */ 659 688 atomic_clear_mask(CPUSTAT_ECALL_PEND, &vcpu->arch.sie_block->cpuflags); ··· 672 701 if (atomic_read(&li->active)) { 673 702 do { 674 703 deliver = 0; 675 - spin_lock_bh(&li->lock); 704 + spin_lock(&li->lock); 676 705 list_for_each_entry_safe(inti, n, &li->list, list) { 677 706 if (__interrupt_is_deliverable(vcpu, inti)) { 678 707 list_del(&inti->list); ··· 683 712 } 684 713 if (list_empty(&li->list)) 685 714 atomic_set(&li->active, 0); 686 - spin_unlock_bh(&li->lock); 715 + spin_unlock(&li->lock); 687 716 if (deliver) { 688 717 __do_deliver_interrupt(vcpu, inti); 689 718 kfree(inti); ··· 729 758 if (atomic_read(&li->active)) { 730 759 do { 731 760 deliver = 0; 732 - spin_lock_bh(&li->lock); 761 + spin_lock(&li->lock); 733 762 list_for_each_entry_safe(inti, n, &li->list, list) { 734 763 if ((inti->type == KVM_S390_MCHK) && 735 764 __interrupt_is_deliverable(vcpu, inti)) { ··· 741 770 } 742 771 if (list_empty(&li->list)) 743 772 atomic_set(&li->active, 0); 744 - spin_unlock_bh(&li->lock); 773 + spin_unlock(&li->lock); 745 774 if (deliver) { 746 775 __do_deliver_interrupt(vcpu, inti); 747 776 kfree(inti); ··· 788 817 789 818 VCPU_EVENT(vcpu, 3, "inject: program check %d (from kernel)", code); 790 819 trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, inti->type, code, 0, 1); 791 - spin_lock_bh(&li->lock); 820 + spin_lock(&li->lock); 792 821 list_add(&inti->list, &li->list); 793 822 atomic_set(&li->active, 1); 794 823 BUG_ON(waitqueue_active(li->wq)); 795 - spin_unlock_bh(&li->lock); 824 + spin_unlock(&li->lock); 796 825 return 0; 797 826 } 798 827 ··· 813 842 814 843 inti->type = KVM_S390_PROGRAM_INT; 815 844 memcpy(&inti->pgm, pgm_info, sizeof(inti->pgm)); 816 - spin_lock_bh(&li->lock); 845 + spin_lock(&li->lock); 817 846 list_add(&inti->list, &li->list); 818 847 atomic_set(&li->active, 1); 819 848 BUG_ON(waitqueue_active(li->wq)); 820 - spin_unlock_bh(&li->lock); 849 + spin_unlock(&li->lock); 821 850 return 0; 822 851 } 823 852 ··· 905 934 } 906 935 dst_vcpu = kvm_get_vcpu(kvm, sigcpu); 907 936 li = &dst_vcpu->arch.local_int; 908 - spin_lock_bh(&li->lock); 937 + spin_lock(&li->lock); 909 938 atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags); 910 - if (waitqueue_active(li->wq)) 911 - wake_up_interruptible(li->wq); 912 - kvm_get_vcpu(kvm, sigcpu)->preempted = true; 913 - spin_unlock_bh(&li->lock); 939 + spin_unlock(&li->lock); 940 + kvm_s390_vcpu_wakeup(kvm_get_vcpu(kvm, sigcpu)); 914 941 unlock_fi: 915 942 spin_unlock(&fi->lock); 916 943 mutex_unlock(&kvm->lock); ··· 1050 1081 1051 1082 mutex_lock(&vcpu->kvm->lock); 1052 1083 li = &vcpu->arch.local_int; 1053 - spin_lock_bh(&li->lock); 1084 + spin_lock(&li->lock); 1054 1085 if (inti->type == KVM_S390_PROGRAM_INT) 1055 1086 list_add(&inti->list, &li->list); 1056 1087 else ··· 1059 1090 if (inti->type == KVM_S390_SIGP_STOP) 1060 1091 li->action_bits |= ACTION_STOP_ON_STOP; 1061 1092 atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags); 1062 - if (waitqueue_active(&vcpu->wq)) 1063 - wake_up_interruptible(&vcpu->wq); 1064 - vcpu->preempted = true; 1065 - spin_unlock_bh(&li->lock); 1093 + spin_unlock(&li->lock); 1066 1094 mutex_unlock(&vcpu->kvm->lock); 1095 + kvm_s390_vcpu_wakeup(vcpu); 1067 1096 return 0; 1068 1097 } 1069 1098
+50 -16
arch/s390/kvm/kvm-s390.c
··· 166 166 case KVM_CAP_IOEVENTFD: 167 167 case KVM_CAP_DEVICE_CTRL: 168 168 case KVM_CAP_ENABLE_CAP_VM: 169 + case KVM_CAP_S390_IRQCHIP: 169 170 case KVM_CAP_VM_ATTRIBUTES: 171 + case KVM_CAP_MP_STATE: 170 172 r = 1; 171 173 break; 172 174 case KVM_CAP_NR_VCPUS: ··· 597 595 vcpu->arch.sie_block->pp = 0; 598 596 vcpu->arch.pfault_token = KVM_S390_PFAULT_TOKEN_INVALID; 599 597 kvm_clear_async_pf_completion_queue(vcpu); 600 - kvm_s390_vcpu_stop(vcpu); 598 + if (!kvm_s390_user_cpu_state_ctrl(vcpu->kvm)) 599 + kvm_s390_vcpu_stop(vcpu); 601 600 kvm_s390_clear_local_irqs(vcpu); 602 601 } 603 602 ··· 650 647 return rc; 651 648 } 652 649 hrtimer_init(&vcpu->arch.ckc_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS); 653 - tasklet_init(&vcpu->arch.tasklet, kvm_s390_tasklet, 654 - (unsigned long) vcpu); 655 650 vcpu->arch.ckc_timer.function = kvm_s390_idle_wakeup; 656 651 get_cpu_id(&vcpu->arch.cpu_id); 657 652 vcpu->arch.cpu_id.version = 0xff; ··· 927 926 { 928 927 int rc = 0; 929 928 930 - if (!(atomic_read(&vcpu->arch.sie_block->cpuflags) & CPUSTAT_STOPPED)) 929 + if (!is_vcpu_stopped(vcpu)) 931 930 rc = -EBUSY; 932 931 else { 933 932 vcpu->run->psw_mask = psw.mask; ··· 981 980 int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu, 982 981 struct kvm_mp_state *mp_state) 983 982 { 984 - return -EINVAL; /* not implemented yet */ 983 + /* CHECK_STOP and LOAD are not supported yet */ 984 + return is_vcpu_stopped(vcpu) ? KVM_MP_STATE_STOPPED : 985 + KVM_MP_STATE_OPERATING; 985 986 } 986 987 987 988 int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, 988 989 struct kvm_mp_state *mp_state) 989 990 { 990 - return -EINVAL; /* not implemented yet */ 991 + int rc = 0; 992 + 993 + /* user space knows about this interface - let it control the state */ 994 + vcpu->kvm->arch.user_cpu_state_ctrl = 1; 995 + 996 + switch (mp_state->mp_state) { 997 + case KVM_MP_STATE_STOPPED: 998 + kvm_s390_vcpu_stop(vcpu); 999 + break; 1000 + case KVM_MP_STATE_OPERATING: 1001 + kvm_s390_vcpu_start(vcpu); 1002 + break; 1003 + case KVM_MP_STATE_LOAD: 1004 + case KVM_MP_STATE_CHECK_STOP: 1005 + /* fall through - CHECK_STOP and LOAD are not supported yet */ 1006 + default: 1007 + rc = -ENXIO; 1008 + } 1009 + 1010 + return rc; 991 1011 } 992 1012 993 1013 bool kvm_s390_cmma_enabled(struct kvm *kvm) ··· 1066 1044 } 1067 1045 goto retry; 1068 1046 } 1047 + 1048 + /* nothing to do, just clear the request */ 1049 + clear_bit(KVM_REQ_UNHALT, &vcpu->requests); 1069 1050 1070 1051 return 0; 1071 1052 } ··· 1309 1284 if (vcpu->sigset_active) 1310 1285 sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved); 1311 1286 1312 - kvm_s390_vcpu_start(vcpu); 1287 + if (!kvm_s390_user_cpu_state_ctrl(vcpu->kvm)) { 1288 + kvm_s390_vcpu_start(vcpu); 1289 + } else if (is_vcpu_stopped(vcpu)) { 1290 + pr_err_ratelimited("kvm-s390: can't run stopped vcpu %d\n", 1291 + vcpu->vcpu_id); 1292 + return -EINVAL; 1293 + } 1313 1294 1314 1295 switch (kvm_run->exit_reason) { 1315 1296 case KVM_EXIT_S390_SIEIC: ··· 1444 1413 return kvm_s390_store_status_unloaded(vcpu, addr); 1445 1414 } 1446 1415 1447 - static inline int is_vcpu_stopped(struct kvm_vcpu *vcpu) 1448 - { 1449 - return atomic_read(&(vcpu)->arch.sie_block->cpuflags) & CPUSTAT_STOPPED; 1450 - } 1451 - 1452 1416 static void __disable_ibs_on_vcpu(struct kvm_vcpu *vcpu) 1453 1417 { 1454 1418 kvm_check_request(KVM_REQ_ENABLE_IBS, vcpu); ··· 1477 1451 1478 1452 trace_kvm_s390_vcpu_start_stop(vcpu->vcpu_id, 1); 1479 1453 /* Only one cpu at a time may enter/leave the STOPPED state. */ 1480 - spin_lock_bh(&vcpu->kvm->arch.start_stop_lock); 1454 + spin_lock(&vcpu->kvm->arch.start_stop_lock); 1481 1455 online_vcpus = atomic_read(&vcpu->kvm->online_vcpus); 1482 1456 1483 1457 for (i = 0; i < online_vcpus; i++) { ··· 1503 1477 * Let's play safe and flush the VCPU at startup. 1504 1478 */ 1505 1479 vcpu->arch.sie_block->ihcpu = 0xffff; 1506 - spin_unlock_bh(&vcpu->kvm->arch.start_stop_lock); 1480 + spin_unlock(&vcpu->kvm->arch.start_stop_lock); 1507 1481 return; 1508 1482 } 1509 1483 ··· 1517 1491 1518 1492 trace_kvm_s390_vcpu_start_stop(vcpu->vcpu_id, 0); 1519 1493 /* Only one cpu at a time may enter/leave the STOPPED state. */ 1520 - spin_lock_bh(&vcpu->kvm->arch.start_stop_lock); 1494 + spin_lock(&vcpu->kvm->arch.start_stop_lock); 1521 1495 online_vcpus = atomic_read(&vcpu->kvm->online_vcpus); 1522 1496 1497 + /* Need to lock access to action_bits to avoid a SIGP race condition */ 1498 + spin_lock(&vcpu->arch.local_int.lock); 1523 1499 atomic_set_mask(CPUSTAT_STOPPED, &vcpu->arch.sie_block->cpuflags); 1500 + 1501 + /* SIGP STOP and SIGP STOP AND STORE STATUS has been fully processed */ 1502 + vcpu->arch.local_int.action_bits &= 1503 + ~(ACTION_STOP_ON_STOP | ACTION_STORE_ON_STOP); 1504 + spin_unlock(&vcpu->arch.local_int.lock); 1505 + 1524 1506 __disable_ibs_on_vcpu(vcpu); 1525 1507 1526 1508 for (i = 0; i < online_vcpus; i++) { ··· 1546 1512 __enable_ibs_on_vcpu(started_vcpu); 1547 1513 } 1548 1514 1549 - spin_unlock_bh(&vcpu->kvm->arch.start_stop_lock); 1515 + spin_unlock(&vcpu->kvm->arch.start_stop_lock); 1550 1516 return; 1551 1517 } 1552 1518
+9 -3
arch/s390/kvm/kvm-s390.h
··· 45 45 d_args); \ 46 46 } while (0) 47 47 48 - static inline int __cpu_is_stopped(struct kvm_vcpu *vcpu) 48 + static inline int is_vcpu_stopped(struct kvm_vcpu *vcpu) 49 49 { 50 - return atomic_read(&vcpu->arch.sie_block->cpuflags) & CPUSTAT_STOP_INT; 50 + return atomic_read(&vcpu->arch.sie_block->cpuflags) & CPUSTAT_STOPPED; 51 51 } 52 52 53 53 static inline int kvm_is_ucontrol(struct kvm *kvm) ··· 129 129 vcpu->arch.sie_block->gpsw.mask |= cc << 44; 130 130 } 131 131 132 + /* are cpu states controlled by user space */ 133 + static inline int kvm_s390_user_cpu_state_ctrl(struct kvm *kvm) 134 + { 135 + return kvm->arch.user_cpu_state_ctrl != 0; 136 + } 137 + 132 138 int kvm_s390_handle_wait(struct kvm_vcpu *vcpu); 139 + void kvm_s390_vcpu_wakeup(struct kvm_vcpu *vcpu); 133 140 enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer); 134 - void kvm_s390_tasklet(unsigned long parm); 135 141 void kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu); 136 142 void kvm_s390_deliver_pending_machine_checks(struct kvm_vcpu *vcpu); 137 143 void kvm_s390_clear_local_irqs(struct kvm_vcpu *vcpu);
+21 -23
arch/s390/kvm/sigp.c
··· 125 125 return rc ? rc : SIGP_CC_ORDER_CODE_ACCEPTED; 126 126 } 127 127 128 - static int __inject_sigp_stop(struct kvm_s390_local_interrupt *li, int action) 128 + static int __inject_sigp_stop(struct kvm_vcpu *dst_vcpu, int action) 129 129 { 130 + struct kvm_s390_local_interrupt *li = &dst_vcpu->arch.local_int; 130 131 struct kvm_s390_interrupt_info *inti; 131 132 int rc = SIGP_CC_ORDER_CODE_ACCEPTED; 132 133 ··· 136 135 return -ENOMEM; 137 136 inti->type = KVM_S390_SIGP_STOP; 138 137 139 - spin_lock_bh(&li->lock); 138 + spin_lock(&li->lock); 139 + if (li->action_bits & ACTION_STOP_ON_STOP) { 140 + /* another SIGP STOP is pending */ 141 + kfree(inti); 142 + rc = SIGP_CC_BUSY; 143 + goto out; 144 + } 140 145 if ((atomic_read(li->cpuflags) & CPUSTAT_STOPPED)) { 141 146 kfree(inti); 142 147 if ((action & ACTION_STORE_ON_STOP) != 0) ··· 151 144 } 152 145 list_add_tail(&inti->list, &li->list); 153 146 atomic_set(&li->active, 1); 154 - atomic_set_mask(CPUSTAT_STOP_INT, li->cpuflags); 155 147 li->action_bits |= action; 156 - if (waitqueue_active(li->wq)) 157 - wake_up_interruptible(li->wq); 148 + atomic_set_mask(CPUSTAT_STOP_INT, li->cpuflags); 149 + kvm_s390_vcpu_wakeup(dst_vcpu); 158 150 out: 159 - spin_unlock_bh(&li->lock); 151 + spin_unlock(&li->lock); 160 152 161 153 return rc; 162 154 } 163 155 164 156 static int __sigp_stop(struct kvm_vcpu *vcpu, u16 cpu_addr, int action) 165 157 { 166 - struct kvm_s390_local_interrupt *li; 167 158 struct kvm_vcpu *dst_vcpu = NULL; 168 159 int rc; 169 160 ··· 171 166 dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr); 172 167 if (!dst_vcpu) 173 168 return SIGP_CC_NOT_OPERATIONAL; 174 - li = &dst_vcpu->arch.local_int; 175 169 176 - rc = __inject_sigp_stop(li, action); 170 + rc = __inject_sigp_stop(dst_vcpu, action); 177 171 178 172 VCPU_EVENT(vcpu, 4, "sent sigp stop to cpu %x", cpu_addr); 179 173 ··· 242 238 if (!inti) 243 239 return SIGP_CC_BUSY; 244 240 245 - spin_lock_bh(&li->lock); 241 + spin_lock(&li->lock); 246 242 /* cpu must be in stopped state */ 247 243 if (!(atomic_read(li->cpuflags) & CPUSTAT_STOPPED)) { 248 244 *reg &= 0xffffffff00000000UL; ··· 257 253 258 254 list_add_tail(&inti->list, &li->list); 259 255 atomic_set(&li->active, 1); 260 - if (waitqueue_active(li->wq)) 261 - wake_up_interruptible(li->wq); 256 + kvm_s390_vcpu_wakeup(dst_vcpu); 262 257 rc = SIGP_CC_ORDER_CODE_ACCEPTED; 263 258 264 259 VCPU_EVENT(vcpu, 4, "set prefix of cpu %02x to %x", cpu_addr, address); 265 260 out_li: 266 - spin_unlock_bh(&li->lock); 261 + spin_unlock(&li->lock); 267 262 return rc; 268 263 } 269 264 ··· 278 275 if (!dst_vcpu) 279 276 return SIGP_CC_NOT_OPERATIONAL; 280 277 281 - spin_lock_bh(&dst_vcpu->arch.local_int.lock); 278 + spin_lock(&dst_vcpu->arch.local_int.lock); 282 279 flags = atomic_read(dst_vcpu->arch.local_int.cpuflags); 283 - spin_unlock_bh(&dst_vcpu->arch.local_int.lock); 280 + spin_unlock(&dst_vcpu->arch.local_int.lock); 284 281 if (!(flags & CPUSTAT_STOPPED)) { 285 282 *reg &= 0xffffffff00000000UL; 286 283 *reg |= SIGP_STATUS_INCORRECT_STATE; ··· 341 338 if (!dst_vcpu) 342 339 return SIGP_CC_NOT_OPERATIONAL; 343 340 li = &dst_vcpu->arch.local_int; 344 - spin_lock_bh(&li->lock); 341 + spin_lock(&li->lock); 345 342 if (li->action_bits & ACTION_STOP_ON_STOP) 346 343 rc = SIGP_CC_BUSY; 347 - spin_unlock_bh(&li->lock); 344 + spin_unlock(&li->lock); 348 345 349 346 return rc; 350 347 } ··· 464 461 dest_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr); 465 462 BUG_ON(dest_vcpu == NULL); 466 463 467 - spin_lock_bh(&dest_vcpu->arch.local_int.lock); 468 - if (waitqueue_active(&dest_vcpu->wq)) 469 - wake_up_interruptible(&dest_vcpu->wq); 470 - dest_vcpu->preempted = true; 471 - spin_unlock_bh(&dest_vcpu->arch.local_int.lock); 472 - 464 + kvm_s390_vcpu_wakeup(dest_vcpu); 473 465 kvm_s390_set_psw_cc(vcpu, SIGP_CC_ORDER_CODE_ACCEPTED); 474 466 return 0; 475 467 }
+21 -12
arch/x86/include/asm/kvm_emulate.h
··· 37 37 u8 modrm_reg; /* index of register used */ 38 38 u8 modrm_rm; /* rm part of modrm */ 39 39 u64 src_val; /* value of source operand */ 40 + u64 dst_val; /* value of destination operand */ 40 41 u8 src_bytes; /* size of source operand */ 41 42 u8 dst_bytes; /* size of destination operand */ 42 43 u8 ad_bytes; /* size of src/dst address */ ··· 195 194 int (*set_dr)(struct x86_emulate_ctxt *ctxt, int dr, ulong value); 196 195 int (*set_msr)(struct x86_emulate_ctxt *ctxt, u32 msr_index, u64 data); 197 196 int (*get_msr)(struct x86_emulate_ctxt *ctxt, u32 msr_index, u64 *pdata); 197 + int (*check_pmc)(struct x86_emulate_ctxt *ctxt, u32 pmc); 198 198 int (*read_pmc)(struct x86_emulate_ctxt *ctxt, u32 pmc, u64 *pdata); 199 199 void (*halt)(struct x86_emulate_ctxt *ctxt); 200 200 void (*wbinvd)(struct x86_emulate_ctxt *ctxt); ··· 233 231 union { 234 232 unsigned long val; 235 233 u64 val64; 236 - char valptr[sizeof(unsigned long) + 2]; 234 + char valptr[sizeof(sse128_t)]; 237 235 sse128_t vec_val; 238 236 u64 mm_val; 239 237 void *data; ··· 242 240 243 241 struct fetch_cache { 244 242 u8 data[15]; 245 - unsigned long start; 246 - unsigned long end; 243 + u8 *ptr; 244 + u8 *end; 247 245 }; 248 246 249 247 struct read_cache { ··· 288 286 u8 opcode_len; 289 287 u8 b; 290 288 u8 intercept; 291 - u8 lock_prefix; 292 - u8 rep_prefix; 293 289 u8 op_bytes; 294 290 u8 ad_bytes; 295 - u8 rex_prefix; 296 291 struct operand src; 297 292 struct operand src2; 298 293 struct operand dst; 299 - bool has_seg_override; 300 - u8 seg_override; 301 - u64 d; 302 294 int (*execute)(struct x86_emulate_ctxt *ctxt); 303 295 int (*check_perm)(struct x86_emulate_ctxt *ctxt); 296 + /* 297 + * The following six fields are cleared together, 298 + * the rest are initialized unconditionally in x86_decode_insn 299 + * or elsewhere 300 + */ 301 + bool rip_relative; 302 + u8 rex_prefix; 303 + u8 lock_prefix; 304 + u8 rep_prefix; 305 + /* bitmaps of registers in _regs[] that can be read */ 306 + u32 regs_valid; 307 + /* bitmaps of registers in _regs[] that have been written */ 308 + u32 regs_dirty; 304 309 /* modrm */ 305 310 u8 modrm; 306 311 u8 modrm_mod; 307 312 u8 modrm_reg; 308 313 u8 modrm_rm; 309 314 u8 modrm_seg; 310 - bool rip_relative; 315 + u8 seg_override; 316 + u64 d; 311 317 unsigned long _eip; 312 318 struct operand memop; 313 - u32 regs_valid; /* bitmaps of registers in _regs[] that can be read */ 314 - u32 regs_dirty; /* bitmaps of registers in _regs[] that have been written */ 315 319 /* Fields above regs are cleared together. */ 316 320 unsigned long _regs[NR_VCPU_REGS]; 317 321 struct operand *memopp; ··· 415 407 #define EMULATION_OK 0 416 408 #define EMULATION_RESTART 1 417 409 #define EMULATION_INTERCEPTED 2 410 + void init_decode_cache(struct x86_emulate_ctxt *ctxt); 418 411 int x86_emulate_insn(struct x86_emulate_ctxt *ctxt); 419 412 int emulator_task_switch(struct x86_emulate_ctxt *ctxt, 420 413 u16 tss_selector, int idt_index, int reason,
+9 -6
arch/x86/include/asm/kvm_host.h
··· 152 152 153 153 #define DR6_BD (1 << 13) 154 154 #define DR6_BS (1 << 14) 155 - #define DR6_FIXED_1 0xffff0ff0 156 - #define DR6_VOLATILE 0x0000e00f 155 + #define DR6_RTM (1 << 16) 156 + #define DR6_FIXED_1 0xfffe0ff0 157 + #define DR6_INIT 0xffff0ff0 158 + #define DR6_VOLATILE 0x0001e00f 157 159 158 160 #define DR7_BP_EN_MASK 0x000000ff 159 161 #define DR7_GE (1 << 9) 160 162 #define DR7_GD (1 << 13) 161 163 #define DR7_FIXED_1 0x00000400 162 - #define DR7_VOLATILE 0xffff23ff 164 + #define DR7_VOLATILE 0xffff2bff 163 165 164 166 /* apic attention bits */ 165 167 #define KVM_APIC_CHECK_VAPIC 0 ··· 450 448 u64 tsc_offset_adjustment; 451 449 u64 this_tsc_nsec; 452 450 u64 this_tsc_write; 453 - u8 this_tsc_generation; 451 + u64 this_tsc_generation; 454 452 bool tsc_catchup; 455 453 bool tsc_always_catchup; 456 454 s8 virtual_tsc_shift; ··· 593 591 u64 cur_tsc_nsec; 594 592 u64 cur_tsc_write; 595 593 u64 cur_tsc_offset; 596 - u8 cur_tsc_generation; 594 + u64 cur_tsc_generation; 597 595 int nr_vcpus_matched_tsc; 598 596 599 597 spinlock_t pvclock_gtod_sync_lock; ··· 719 717 int (*handle_exit)(struct kvm_vcpu *vcpu); 720 718 void (*skip_emulated_instruction)(struct kvm_vcpu *vcpu); 721 719 void (*set_interrupt_shadow)(struct kvm_vcpu *vcpu, int mask); 722 - u32 (*get_interrupt_shadow)(struct kvm_vcpu *vcpu, int mask); 720 + u32 (*get_interrupt_shadow)(struct kvm_vcpu *vcpu); 723 721 void (*patch_hypercall)(struct kvm_vcpu *vcpu, 724 722 unsigned char *hypercall_addr); 725 723 void (*set_irq)(struct kvm_vcpu *vcpu); ··· 1072 1070 bool kvm_pmu_msr(struct kvm_vcpu *vcpu, u32 msr); 1073 1071 int kvm_pmu_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *data); 1074 1072 int kvm_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info); 1073 + int kvm_pmu_check_pmc(struct kvm_vcpu *vcpu, unsigned pmc); 1075 1074 int kvm_pmu_read_pmc(struct kvm_vcpu *vcpu, unsigned pmc, u64 *data); 1076 1075 void kvm_handle_pmu_event(struct kvm_vcpu *vcpu); 1077 1076 void kvm_deliver_pmi(struct kvm_vcpu *vcpu);
+5 -2
arch/x86/include/asm/vmx.h
··· 51 51 #define CPU_BASED_MONITOR_EXITING 0x20000000 52 52 #define CPU_BASED_PAUSE_EXITING 0x40000000 53 53 #define CPU_BASED_ACTIVATE_SECONDARY_CONTROLS 0x80000000 54 + 55 + #define CPU_BASED_ALWAYSON_WITHOUT_TRUE_MSR 0x0401e172 56 + 54 57 /* 55 58 * Definitions of Secondary Processor-Based VM-Execution Controls. 56 59 */ ··· 79 76 80 77 #define PIN_BASED_ALWAYSON_WITHOUT_TRUE_MSR 0x00000016 81 78 82 - #define VM_EXIT_SAVE_DEBUG_CONTROLS 0x00000002 79 + #define VM_EXIT_SAVE_DEBUG_CONTROLS 0x00000004 83 80 #define VM_EXIT_HOST_ADDR_SPACE_SIZE 0x00000200 84 81 #define VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL 0x00001000 85 82 #define VM_EXIT_ACK_INTR_ON_EXIT 0x00008000 ··· 92 89 93 90 #define VM_EXIT_ALWAYSON_WITHOUT_TRUE_MSR 0x00036dff 94 91 95 - #define VM_ENTRY_LOAD_DEBUG_CONTROLS 0x00000002 92 + #define VM_ENTRY_LOAD_DEBUG_CONTROLS 0x00000004 96 93 #define VM_ENTRY_IA32E_MODE 0x00000200 97 94 #define VM_ENTRY_SMM 0x00000400 98 95 #define VM_ENTRY_DEACT_DUAL_MONITOR 0x00000800
+3
arch/x86/include/uapi/asm/kvm.h
··· 23 23 #define GP_VECTOR 13 24 24 #define PF_VECTOR 14 25 25 #define MF_VECTOR 16 26 + #define AC_VECTOR 17 26 27 #define MC_VECTOR 18 28 + #define XM_VECTOR 19 29 + #define VE_VECTOR 20 27 30 28 31 /* Select x86 specific features in <linux/kvm.h> */ 29 32 #define __KVM_HAVE_PIT
+1
arch/x86/include/uapi/asm/msr-index.h
··· 558 558 559 559 /* VMX_BASIC bits and bitmasks */ 560 560 #define VMX_BASIC_VMCS_SIZE_SHIFT 32 561 + #define VMX_BASIC_TRUE_CTLS (1ULL << 55) 561 562 #define VMX_BASIC_64 0x0001000000000000LLU 562 563 #define VMX_BASIC_MEM_TYPE_SHIFT 50 563 564 #define VMX_BASIC_MEM_TYPE_MASK 0x003c000000000000LLU
+8
arch/x86/kvm/cpuid.h
··· 95 95 best = kvm_find_cpuid_entry(vcpu, 0x80000001, 0); 96 96 return best && (best->edx & bit(X86_FEATURE_GBPAGES)); 97 97 } 98 + 99 + static inline bool guest_cpuid_has_rtm(struct kvm_vcpu *vcpu) 100 + { 101 + struct kvm_cpuid_entry2 *best; 102 + 103 + best = kvm_find_cpuid_entry(vcpu, 7, 0); 104 + return best && (best->ebx & bit(X86_FEATURE_RTM)); 105 + } 98 106 #endif
+283 -215
arch/x86/kvm/emulate.c
··· 162 162 #define NoWrite ((u64)1 << 45) /* No writeback */ 163 163 #define SrcWrite ((u64)1 << 46) /* Write back src operand */ 164 164 #define NoMod ((u64)1 << 47) /* Mod field is ignored */ 165 + #define Intercept ((u64)1 << 48) /* Has valid intercept field */ 166 + #define CheckPerm ((u64)1 << 49) /* Has valid check_perm field */ 167 + #define NoBigReal ((u64)1 << 50) /* No big real mode */ 168 + #define PrivUD ((u64)1 << 51) /* #UD instead of #GP on CPL > 0 */ 165 169 166 170 #define DstXacc (DstAccLo | SrcAccHi | SrcWrite) 167 171 ··· 430 426 .modrm_reg = ctxt->modrm_reg, 431 427 .modrm_rm = ctxt->modrm_rm, 432 428 .src_val = ctxt->src.val64, 429 + .dst_val = ctxt->dst.val64, 433 430 .src_bytes = ctxt->src.bytes, 434 431 .dst_bytes = ctxt->dst.bytes, 435 432 .ad_bytes = ctxt->ad_bytes, ··· 516 511 return desc->g ? (limit << 12) | 0xfff : limit; 517 512 } 518 513 519 - static void set_seg_override(struct x86_emulate_ctxt *ctxt, int seg) 520 - { 521 - ctxt->has_seg_override = true; 522 - ctxt->seg_override = seg; 523 - } 524 - 525 514 static unsigned long seg_base(struct x86_emulate_ctxt *ctxt, int seg) 526 515 { 527 516 if (ctxt->mode == X86EMUL_MODE_PROT64 && seg < VCPU_SREG_FS) 528 517 return 0; 529 518 530 519 return ctxt->ops->get_cached_segment_base(ctxt, seg); 531 - } 532 - 533 - static unsigned seg_override(struct x86_emulate_ctxt *ctxt) 534 - { 535 - if (!ctxt->has_seg_override) 536 - return 0; 537 - 538 - return ctxt->seg_override; 539 520 } 540 521 541 522 static int emulate_exception(struct x86_emulate_ctxt *ctxt, int vec, ··· 642 651 if (!fetch && (desc.type & 8) && !(desc.type & 2)) 643 652 goto bad; 644 653 lim = desc_limit_scaled(&desc); 645 - if ((desc.type & 8) || !(desc.type & 4)) { 654 + if ((ctxt->mode == X86EMUL_MODE_REAL) && !fetch && 655 + (ctxt->d & NoBigReal)) { 656 + /* la is between zero and 0xffff */ 657 + if (la > 0xffff || (u32)(la + size - 1) > 0xffff) 658 + goto bad; 659 + } else if ((desc.type & 8) || !(desc.type & 4)) { 646 660 /* expand-up segment */ 647 661 if (addr.ea > lim || (u32)(addr.ea + size - 1) > lim) 648 662 goto bad; ··· 712 716 } 713 717 714 718 /* 715 - * Fetch the next byte of the instruction being emulated which is pointed to 716 - * by ctxt->_eip, then increment ctxt->_eip. 717 - * 718 - * Also prefetch the remaining bytes of the instruction without crossing page 719 + * Prefetch the remaining bytes of the instruction without crossing page 719 720 * boundary if they are not in fetch_cache yet. 720 721 */ 721 - static int do_insn_fetch_byte(struct x86_emulate_ctxt *ctxt, u8 *dest) 722 + static int __do_insn_fetch_bytes(struct x86_emulate_ctxt *ctxt, int op_size) 722 723 { 723 - struct fetch_cache *fc = &ctxt->fetch; 724 724 int rc; 725 - int size, cur_size; 725 + unsigned size; 726 + unsigned long linear; 727 + int cur_size = ctxt->fetch.end - ctxt->fetch.data; 728 + struct segmented_address addr = { .seg = VCPU_SREG_CS, 729 + .ea = ctxt->eip + cur_size }; 726 730 727 - if (ctxt->_eip == fc->end) { 728 - unsigned long linear; 729 - struct segmented_address addr = { .seg = VCPU_SREG_CS, 730 - .ea = ctxt->_eip }; 731 - cur_size = fc->end - fc->start; 732 - size = min(15UL - cur_size, 733 - PAGE_SIZE - offset_in_page(ctxt->_eip)); 734 - rc = __linearize(ctxt, addr, size, false, true, &linear); 735 - if (unlikely(rc != X86EMUL_CONTINUE)) 736 - return rc; 737 - rc = ctxt->ops->fetch(ctxt, linear, fc->data + cur_size, 738 - size, &ctxt->exception); 739 - if (unlikely(rc != X86EMUL_CONTINUE)) 740 - return rc; 741 - fc->end += size; 742 - } 743 - *dest = fc->data[ctxt->_eip - fc->start]; 744 - ctxt->_eip++; 731 + size = 15UL ^ cur_size; 732 + rc = __linearize(ctxt, addr, size, false, true, &linear); 733 + if (unlikely(rc != X86EMUL_CONTINUE)) 734 + return rc; 735 + 736 + size = min_t(unsigned, size, PAGE_SIZE - offset_in_page(linear)); 737 + 738 + /* 739 + * One instruction can only straddle two pages, 740 + * and one has been loaded at the beginning of 741 + * x86_decode_insn. So, if not enough bytes 742 + * still, we must have hit the 15-byte boundary. 743 + */ 744 + if (unlikely(size < op_size)) 745 + return X86EMUL_UNHANDLEABLE; 746 + rc = ctxt->ops->fetch(ctxt, linear, ctxt->fetch.end, 747 + size, &ctxt->exception); 748 + if (unlikely(rc != X86EMUL_CONTINUE)) 749 + return rc; 750 + ctxt->fetch.end += size; 745 751 return X86EMUL_CONTINUE; 746 752 } 747 753 748 - static int do_insn_fetch(struct x86_emulate_ctxt *ctxt, 749 - void *dest, unsigned size) 754 + static __always_inline int do_insn_fetch_bytes(struct x86_emulate_ctxt *ctxt, 755 + unsigned size) 750 756 { 751 - int rc; 752 - 753 - /* x86 instructions are limited to 15 bytes. */ 754 - if (unlikely(ctxt->_eip + size - ctxt->eip > 15)) 755 - return X86EMUL_UNHANDLEABLE; 756 - while (size--) { 757 - rc = do_insn_fetch_byte(ctxt, dest++); 758 - if (rc != X86EMUL_CONTINUE) 759 - return rc; 760 - } 761 - return X86EMUL_CONTINUE; 757 + if (unlikely(ctxt->fetch.end - ctxt->fetch.ptr < size)) 758 + return __do_insn_fetch_bytes(ctxt, size); 759 + else 760 + return X86EMUL_CONTINUE; 762 761 } 763 762 764 763 /* Fetch next part of the instruction being emulated. */ 765 764 #define insn_fetch(_type, _ctxt) \ 766 - ({ unsigned long _x; \ 767 - rc = do_insn_fetch(_ctxt, &_x, sizeof(_type)); \ 765 + ({ _type _x; \ 766 + \ 767 + rc = do_insn_fetch_bytes(_ctxt, sizeof(_type)); \ 768 768 if (rc != X86EMUL_CONTINUE) \ 769 769 goto done; \ 770 - (_type)_x; \ 770 + ctxt->_eip += sizeof(_type); \ 771 + _x = *(_type __aligned(1) *) ctxt->fetch.ptr; \ 772 + ctxt->fetch.ptr += sizeof(_type); \ 773 + _x; \ 771 774 }) 772 775 773 776 #define insn_fetch_arr(_arr, _size, _ctxt) \ 774 - ({ rc = do_insn_fetch(_ctxt, _arr, (_size)); \ 777 + ({ \ 778 + rc = do_insn_fetch_bytes(_ctxt, _size); \ 775 779 if (rc != X86EMUL_CONTINUE) \ 776 780 goto done; \ 781 + ctxt->_eip += (_size); \ 782 + memcpy(_arr, ctxt->fetch.ptr, _size); \ 783 + ctxt->fetch.ptr += (_size); \ 777 784 }) 778 785 779 786 /* ··· 1062 1063 struct operand *op) 1063 1064 { 1064 1065 u8 sib; 1065 - int index_reg = 0, base_reg = 0, scale; 1066 + int index_reg, base_reg, scale; 1066 1067 int rc = X86EMUL_CONTINUE; 1067 1068 ulong modrm_ea = 0; 1068 1069 1069 - if (ctxt->rex_prefix) { 1070 - ctxt->modrm_reg = (ctxt->rex_prefix & 4) << 1; /* REX.R */ 1071 - index_reg = (ctxt->rex_prefix & 2) << 2; /* REX.X */ 1072 - ctxt->modrm_rm = base_reg = (ctxt->rex_prefix & 1) << 3; /* REG.B */ 1073 - } 1070 + ctxt->modrm_reg = ((ctxt->rex_prefix << 1) & 8); /* REX.R */ 1071 + index_reg = (ctxt->rex_prefix << 2) & 8; /* REX.X */ 1072 + base_reg = (ctxt->rex_prefix << 3) & 8; /* REX.B */ 1074 1073 1075 - ctxt->modrm_mod |= (ctxt->modrm & 0xc0) >> 6; 1074 + ctxt->modrm_mod = (ctxt->modrm & 0xc0) >> 6; 1076 1075 ctxt->modrm_reg |= (ctxt->modrm & 0x38) >> 3; 1077 - ctxt->modrm_rm |= (ctxt->modrm & 0x07); 1076 + ctxt->modrm_rm = base_reg | (ctxt->modrm & 0x07); 1078 1077 ctxt->modrm_seg = VCPU_SREG_DS; 1079 1078 1080 1079 if (ctxt->modrm_mod == 3 || (ctxt->d & NoMod)) { ··· 1090 1093 if (ctxt->d & Mmx) { 1091 1094 op->type = OP_MM; 1092 1095 op->bytes = 8; 1093 - op->addr.xmm = ctxt->modrm_rm & 7; 1096 + op->addr.mm = ctxt->modrm_rm & 7; 1094 1097 return rc; 1095 1098 } 1096 1099 fetch_register_operand(op); ··· 1187 1190 } 1188 1191 } 1189 1192 op->addr.mem.ea = modrm_ea; 1193 + if (ctxt->ad_bytes != 8) 1194 + ctxt->memop.addr.mem.ea = (u32)ctxt->memop.addr.mem.ea; 1195 + 1190 1196 done: 1191 1197 return rc; 1192 1198 } ··· 1220 1220 long sv = 0, mask; 1221 1221 1222 1222 if (ctxt->dst.type == OP_MEM && ctxt->src.type == OP_REG) { 1223 - mask = ~(ctxt->dst.bytes * 8 - 1); 1223 + mask = ~((long)ctxt->dst.bytes * 8 - 1); 1224 1224 1225 1225 if (ctxt->src.bytes == 2) 1226 1226 sv = (s16)ctxt->src.val & (s16)mask; 1227 1227 else if (ctxt->src.bytes == 4) 1228 1228 sv = (s32)ctxt->src.val & (s32)mask; 1229 + else 1230 + sv = (s64)ctxt->src.val & (s64)mask; 1229 1231 1230 1232 ctxt->dst.addr.mem.ea += (sv >> 3); 1231 1233 } ··· 1317 1315 in_page = (ctxt->eflags & EFLG_DF) ? 1318 1316 offset_in_page(reg_read(ctxt, VCPU_REGS_RDI)) : 1319 1317 PAGE_SIZE - offset_in_page(reg_read(ctxt, VCPU_REGS_RDI)); 1320 - n = min(min(in_page, (unsigned int)sizeof(rc->data)) / size, 1321 - count); 1318 + n = min3(in_page, (unsigned int)sizeof(rc->data) / size, count); 1322 1319 if (n == 0) 1323 1320 n = 1; 1324 1321 rc->pos = rc->end = 0; ··· 1359 1358 u16 selector, struct desc_ptr *dt) 1360 1359 { 1361 1360 const struct x86_emulate_ops *ops = ctxt->ops; 1361 + u32 base3 = 0; 1362 1362 1363 1363 if (selector & 1 << 2) { 1364 1364 struct desc_struct desc; 1365 1365 u16 sel; 1366 1366 1367 1367 memset (dt, 0, sizeof *dt); 1368 - if (!ops->get_segment(ctxt, &sel, &desc, NULL, VCPU_SREG_LDTR)) 1368 + if (!ops->get_segment(ctxt, &sel, &desc, &base3, 1369 + VCPU_SREG_LDTR)) 1369 1370 return; 1370 1371 1371 1372 dt->size = desc_limit_scaled(&desc); /* what if limit > 65535? */ 1372 - dt->address = get_desc_base(&desc); 1373 + dt->address = get_desc_base(&desc) | ((u64)base3 << 32); 1373 1374 } else 1374 1375 ops->get_gdt(ctxt, dt); 1375 1376 } ··· 1425 1422 ulong desc_addr; 1426 1423 int ret; 1427 1424 u16 dummy; 1425 + u32 base3 = 0; 1428 1426 1429 1427 memset(&seg_desc, 0, sizeof seg_desc); 1430 1428 ··· 1542 1538 ret = write_segment_descriptor(ctxt, selector, &seg_desc); 1543 1539 if (ret != X86EMUL_CONTINUE) 1544 1540 return ret; 1541 + } else if (ctxt->mode == X86EMUL_MODE_PROT64) { 1542 + ret = ctxt->ops->read_std(ctxt, desc_addr+8, &base3, 1543 + sizeof(base3), &ctxt->exception); 1544 + if (ret != X86EMUL_CONTINUE) 1545 + return ret; 1545 1546 } 1546 1547 load: 1547 - ctxt->ops->set_segment(ctxt, selector, &seg_desc, 0, seg); 1548 + ctxt->ops->set_segment(ctxt, selector, &seg_desc, base3, seg); 1548 1549 return X86EMUL_CONTINUE; 1549 1550 exception: 1550 1551 emulate_exception(ctxt, err_vec, err_code, true); ··· 1584 1575 1585 1576 static int writeback(struct x86_emulate_ctxt *ctxt, struct operand *op) 1586 1577 { 1587 - int rc; 1588 - 1589 1578 switch (op->type) { 1590 1579 case OP_REG: 1591 1580 write_register_operand(op); 1592 1581 break; 1593 1582 case OP_MEM: 1594 1583 if (ctxt->lock_prefix) 1595 - rc = segmented_cmpxchg(ctxt, 1584 + return segmented_cmpxchg(ctxt, 1585 + op->addr.mem, 1586 + &op->orig_val, 1587 + &op->val, 1588 + op->bytes); 1589 + else 1590 + return segmented_write(ctxt, 1596 1591 op->addr.mem, 1597 - &op->orig_val, 1598 1592 &op->val, 1599 1593 op->bytes); 1600 - else 1601 - rc = segmented_write(ctxt, 1602 - op->addr.mem, 1603 - &op->val, 1604 - op->bytes); 1605 - if (rc != X86EMUL_CONTINUE) 1606 - return rc; 1607 1594 break; 1608 1595 case OP_MEM_STR: 1609 - rc = segmented_write(ctxt, 1610 - op->addr.mem, 1611 - op->data, 1612 - op->bytes * op->count); 1613 - if (rc != X86EMUL_CONTINUE) 1614 - return rc; 1596 + return segmented_write(ctxt, 1597 + op->addr.mem, 1598 + op->data, 1599 + op->bytes * op->count); 1615 1600 break; 1616 1601 case OP_XMM: 1617 1602 write_sse_reg(ctxt, &op->vec_val, op->addr.xmm); ··· 1674 1671 return rc; 1675 1672 1676 1673 change_mask = EFLG_CF | EFLG_PF | EFLG_AF | EFLG_ZF | EFLG_SF | EFLG_OF 1677 - | EFLG_TF | EFLG_DF | EFLG_NT | EFLG_RF | EFLG_AC | EFLG_ID; 1674 + | EFLG_TF | EFLG_DF | EFLG_NT | EFLG_AC | EFLG_ID; 1678 1675 1679 1676 switch(ctxt->mode) { 1680 1677 case X86EMUL_MODE_PROT64: ··· 1756 1753 rc = emulate_pop(ctxt, &selector, ctxt->op_bytes); 1757 1754 if (rc != X86EMUL_CONTINUE) 1758 1755 return rc; 1756 + 1757 + if (ctxt->modrm_reg == VCPU_SREG_SS) 1758 + ctxt->interruptibility = KVM_X86_SHADOW_INT_MOV_SS; 1759 1759 1760 1760 rc = load_segment_descriptor(ctxt, (u16)selector, seg); 1761 1761 return rc; ··· 1997 1991 { 1998 1992 u64 old = ctxt->dst.orig_val64; 1999 1993 1994 + if (ctxt->dst.bytes == 16) 1995 + return X86EMUL_UNHANDLEABLE; 1996 + 2000 1997 if (((u32) (old >> 0) != (u32) reg_read(ctxt, VCPU_REGS_RAX)) || 2001 1998 ((u32) (old >> 32) != (u32) reg_read(ctxt, VCPU_REGS_RDX))) { 2002 1999 *reg_write(ctxt, VCPU_REGS_RAX) = (u32) (old >> 0); ··· 2026 2017 { 2027 2018 int rc; 2028 2019 unsigned long cs; 2020 + int cpl = ctxt->ops->cpl(ctxt); 2029 2021 2030 2022 rc = emulate_pop(ctxt, &ctxt->_eip, ctxt->op_bytes); 2031 2023 if (rc != X86EMUL_CONTINUE) ··· 2036 2026 rc = emulate_pop(ctxt, &cs, ctxt->op_bytes); 2037 2027 if (rc != X86EMUL_CONTINUE) 2038 2028 return rc; 2029 + /* Outer-privilege level return is not implemented */ 2030 + if (ctxt->mode >= X86EMUL_MODE_PROT16 && (cs & 3) > cpl) 2031 + return X86EMUL_UNHANDLEABLE; 2039 2032 rc = load_segment_descriptor(ctxt, (u16)cs, VCPU_SREG_CS); 2040 2033 return rc; 2041 2034 } ··· 2057 2044 static int em_cmpxchg(struct x86_emulate_ctxt *ctxt) 2058 2045 { 2059 2046 /* Save real source value, then compare EAX against destination. */ 2047 + ctxt->dst.orig_val = ctxt->dst.val; 2048 + ctxt->dst.val = reg_read(ctxt, VCPU_REGS_RAX); 2060 2049 ctxt->src.orig_val = ctxt->src.val; 2061 - ctxt->src.val = reg_read(ctxt, VCPU_REGS_RAX); 2050 + ctxt->src.val = ctxt->dst.orig_val; 2062 2051 fastop(ctxt, em_cmp); 2063 2052 2064 2053 if (ctxt->eflags & EFLG_ZF) { ··· 2070 2055 /* Failure: write the value we saw to EAX. */ 2071 2056 ctxt->dst.type = OP_REG; 2072 2057 ctxt->dst.addr.reg = reg_rmw(ctxt, VCPU_REGS_RAX); 2058 + ctxt->dst.val = ctxt->dst.orig_val; 2073 2059 } 2074 2060 return X86EMUL_CONTINUE; 2075 2061 } ··· 2210 2194 *reg_write(ctxt, VCPU_REGS_RCX) = ctxt->_eip; 2211 2195 if (efer & EFER_LMA) { 2212 2196 #ifdef CONFIG_X86_64 2213 - *reg_write(ctxt, VCPU_REGS_R11) = ctxt->eflags & ~EFLG_RF; 2197 + *reg_write(ctxt, VCPU_REGS_R11) = ctxt->eflags; 2214 2198 2215 2199 ops->get_msr(ctxt, 2216 2200 ctxt->mode == X86EMUL_MODE_PROT64 ? ··· 2218 2202 ctxt->_eip = msr_data; 2219 2203 2220 2204 ops->get_msr(ctxt, MSR_SYSCALL_MASK, &msr_data); 2221 - ctxt->eflags &= ~(msr_data | EFLG_RF); 2205 + ctxt->eflags &= ~msr_data; 2222 2206 #endif 2223 2207 } else { 2224 2208 /* legacy mode */ 2225 2209 ops->get_msr(ctxt, MSR_STAR, &msr_data); 2226 2210 ctxt->_eip = (u32)msr_data; 2227 2211 2228 - ctxt->eflags &= ~(EFLG_VM | EFLG_IF | EFLG_RF); 2212 + ctxt->eflags &= ~(EFLG_VM | EFLG_IF); 2229 2213 } 2230 2214 2231 2215 return X86EMUL_CONTINUE; ··· 2274 2258 break; 2275 2259 } 2276 2260 2277 - ctxt->eflags &= ~(EFLG_VM | EFLG_IF | EFLG_RF); 2261 + ctxt->eflags &= ~(EFLG_VM | EFLG_IF); 2278 2262 cs_sel = (u16)msr_data; 2279 2263 cs_sel &= ~SELECTOR_RPL_MASK; 2280 2264 ss_sel = cs_sel + 8; ··· 2980 2964 2981 2965 static int em_mov(struct x86_emulate_ctxt *ctxt) 2982 2966 { 2983 - memcpy(ctxt->dst.valptr, ctxt->src.valptr, ctxt->op_bytes); 2967 + memcpy(ctxt->dst.valptr, ctxt->src.valptr, sizeof(ctxt->src.valptr)); 2984 2968 return X86EMUL_CONTINUE; 2985 2969 } 2986 2970 ··· 3237 3221 3238 3222 static int em_smsw(struct x86_emulate_ctxt *ctxt) 3239 3223 { 3240 - ctxt->dst.bytes = 2; 3224 + if (ctxt->dst.type == OP_MEM) 3225 + ctxt->dst.bytes = 2; 3241 3226 ctxt->dst.val = ctxt->ops->get_cr(ctxt, 0); 3242 3227 return X86EMUL_CONTINUE; 3243 3228 } ··· 3513 3496 u64 rcx = reg_read(ctxt, VCPU_REGS_RCX); 3514 3497 3515 3498 if ((!(cr4 & X86_CR4_PCE) && ctxt->ops->cpl(ctxt)) || 3516 - (rcx > 3)) 3499 + ctxt->ops->check_pmc(ctxt, rcx)) 3517 3500 return emulate_gp(ctxt, 0); 3518 3501 3519 3502 return X86EMUL_CONTINUE; ··· 3538 3521 } 3539 3522 3540 3523 #define D(_y) { .flags = (_y) } 3541 - #define DI(_y, _i) { .flags = (_y), .intercept = x86_intercept_##_i } 3542 - #define DIP(_y, _i, _p) { .flags = (_y), .intercept = x86_intercept_##_i, \ 3543 - .check_perm = (_p) } 3524 + #define DI(_y, _i) { .flags = (_y)|Intercept, .intercept = x86_intercept_##_i } 3525 + #define DIP(_y, _i, _p) { .flags = (_y)|Intercept|CheckPerm, \ 3526 + .intercept = x86_intercept_##_i, .check_perm = (_p) } 3544 3527 #define N D(NotImpl) 3545 3528 #define EXT(_f, _e) { .flags = ((_f) | RMExt), .u.group = (_e) } 3546 3529 #define G(_f, _g) { .flags = ((_f) | Group | ModRM), .u.group = (_g) } ··· 3549 3532 #define I(_f, _e) { .flags = (_f), .u.execute = (_e) } 3550 3533 #define F(_f, _e) { .flags = (_f) | Fastop, .u.fastop = (_e) } 3551 3534 #define II(_f, _e, _i) \ 3552 - { .flags = (_f), .u.execute = (_e), .intercept = x86_intercept_##_i } 3535 + { .flags = (_f)|Intercept, .u.execute = (_e), .intercept = x86_intercept_##_i } 3553 3536 #define IIP(_f, _e, _i, _p) \ 3554 - { .flags = (_f), .u.execute = (_e), .intercept = x86_intercept_##_i, \ 3555 - .check_perm = (_p) } 3537 + { .flags = (_f)|Intercept|CheckPerm, .u.execute = (_e), \ 3538 + .intercept = x86_intercept_##_i, .check_perm = (_p) } 3556 3539 #define GP(_f, _g) { .flags = ((_f) | Prefix), .u.gprefix = (_g) } 3557 3540 3558 3541 #define D2bv(_f) D((_f) | ByteOp), D(_f) ··· 3651 3634 }; 3652 3635 3653 3636 static const struct group_dual group7 = { { 3654 - II(Mov | DstMem | Priv, em_sgdt, sgdt), 3655 - II(Mov | DstMem | Priv, em_sidt, sidt), 3637 + II(Mov | DstMem, em_sgdt, sgdt), 3638 + II(Mov | DstMem, em_sidt, sidt), 3656 3639 II(SrcMem | Priv, em_lgdt, lgdt), 3657 3640 II(SrcMem | Priv, em_lidt, lidt), 3658 3641 II(SrcNone | DstMem | Mov, em_smsw, smsw), N, ··· 3916 3899 N, N, 3917 3900 N, N, N, N, N, N, N, N, 3918 3901 /* 0x40 - 0x4F */ 3919 - X16(D(DstReg | SrcMem | ModRM | Mov)), 3902 + X16(D(DstReg | SrcMem | ModRM)), 3920 3903 /* 0x50 - 0x5F */ 3921 3904 N, N, N, N, N, N, N, N, N, N, N, N, N, N, N, N, 3922 3905 /* 0x60 - 0x6F */ ··· 4078 4061 mem_common: 4079 4062 *op = ctxt->memop; 4080 4063 ctxt->memopp = op; 4081 - if ((ctxt->d & BitOp) && op == &ctxt->dst) 4064 + if (ctxt->d & BitOp) 4082 4065 fetch_bit_operand(ctxt); 4083 4066 op->orig_val = op->val; 4084 4067 break; 4085 4068 case OpMem64: 4086 - ctxt->memop.bytes = 8; 4069 + ctxt->memop.bytes = (ctxt->op_bytes == 8) ? 16 : 8; 4087 4070 goto mem_common; 4088 4071 case OpAcc: 4089 4072 op->type = OP_REG; ··· 4167 4150 op->bytes = (ctxt->d & ByteOp) ? 1 : ctxt->op_bytes; 4168 4151 op->addr.mem.ea = 4169 4152 register_address(ctxt, reg_read(ctxt, VCPU_REGS_RSI)); 4170 - op->addr.mem.seg = seg_override(ctxt); 4153 + op->addr.mem.seg = ctxt->seg_override; 4171 4154 op->val = 0; 4172 4155 op->count = 1; 4173 4156 break; ··· 4178 4161 register_address(ctxt, 4179 4162 reg_read(ctxt, VCPU_REGS_RBX) + 4180 4163 (reg_read(ctxt, VCPU_REGS_RAX) & 0xff)); 4181 - op->addr.mem.seg = seg_override(ctxt); 4164 + op->addr.mem.seg = ctxt->seg_override; 4182 4165 op->val = 0; 4183 4166 break; 4184 4167 case OpImmFAddr: ··· 4225 4208 int mode = ctxt->mode; 4226 4209 int def_op_bytes, def_ad_bytes, goffset, simd_prefix; 4227 4210 bool op_prefix = false; 4211 + bool has_seg_override = false; 4228 4212 struct opcode opcode; 4229 4213 4230 4214 ctxt->memop.type = OP_NONE; 4231 4215 ctxt->memopp = NULL; 4232 4216 ctxt->_eip = ctxt->eip; 4233 - ctxt->fetch.start = ctxt->_eip; 4234 - ctxt->fetch.end = ctxt->fetch.start + insn_len; 4217 + ctxt->fetch.ptr = ctxt->fetch.data; 4218 + ctxt->fetch.end = ctxt->fetch.data + insn_len; 4235 4219 ctxt->opcode_len = 1; 4236 4220 if (insn_len > 0) 4237 4221 memcpy(ctxt->fetch.data, insn, insn_len); 4222 + else { 4223 + rc = __do_insn_fetch_bytes(ctxt, 1); 4224 + if (rc != X86EMUL_CONTINUE) 4225 + return rc; 4226 + } 4238 4227 4239 4228 switch (mode) { 4240 4229 case X86EMUL_MODE_REAL: ··· 4284 4261 case 0x2e: /* CS override */ 4285 4262 case 0x36: /* SS override */ 4286 4263 case 0x3e: /* DS override */ 4287 - set_seg_override(ctxt, (ctxt->b >> 3) & 3); 4264 + has_seg_override = true; 4265 + ctxt->seg_override = (ctxt->b >> 3) & 3; 4288 4266 break; 4289 4267 case 0x64: /* FS override */ 4290 4268 case 0x65: /* GS override */ 4291 - set_seg_override(ctxt, ctxt->b & 7); 4269 + has_seg_override = true; 4270 + ctxt->seg_override = ctxt->b & 7; 4292 4271 break; 4293 4272 case 0x40 ... 0x4f: /* REX */ 4294 4273 if (mode != X86EMUL_MODE_PROT64) ··· 4339 4314 if (ctxt->d & ModRM) 4340 4315 ctxt->modrm = insn_fetch(u8, ctxt); 4341 4316 4317 + /* vex-prefix instructions are not implemented */ 4318 + if (ctxt->opcode_len == 1 && (ctxt->b == 0xc5 || ctxt->b == 0xc4) && 4319 + (mode == X86EMUL_MODE_PROT64 || 4320 + (mode >= X86EMUL_MODE_PROT16 && (ctxt->modrm & 0x80)))) { 4321 + ctxt->d = NotImpl; 4322 + } 4323 + 4342 4324 while (ctxt->d & GroupMask) { 4343 4325 switch (ctxt->d & GroupMask) { 4344 4326 case Group: ··· 4388 4356 ctxt->d |= opcode.flags; 4389 4357 } 4390 4358 4391 - ctxt->execute = opcode.u.execute; 4392 - ctxt->check_perm = opcode.check_perm; 4393 - ctxt->intercept = opcode.intercept; 4394 - 4395 4359 /* Unrecognised? */ 4396 - if (ctxt->d == 0 || (ctxt->d & NotImpl)) 4360 + if (ctxt->d == 0) 4397 4361 return EMULATION_FAILED; 4398 4362 4399 - if (!(ctxt->d & EmulateOnUD) && ctxt->ud) 4400 - return EMULATION_FAILED; 4363 + ctxt->execute = opcode.u.execute; 4401 4364 4402 - if (mode == X86EMUL_MODE_PROT64 && (ctxt->d & Stack)) 4403 - ctxt->op_bytes = 8; 4365 + if (unlikely(ctxt->d & 4366 + (NotImpl|EmulateOnUD|Stack|Op3264|Sse|Mmx|Intercept|CheckPerm))) { 4367 + /* 4368 + * These are copied unconditionally here, and checked unconditionally 4369 + * in x86_emulate_insn. 4370 + */ 4371 + ctxt->check_perm = opcode.check_perm; 4372 + ctxt->intercept = opcode.intercept; 4404 4373 4405 - if (ctxt->d & Op3264) { 4406 - if (mode == X86EMUL_MODE_PROT64) 4374 + if (ctxt->d & NotImpl) 4375 + return EMULATION_FAILED; 4376 + 4377 + if (!(ctxt->d & EmulateOnUD) && ctxt->ud) 4378 + return EMULATION_FAILED; 4379 + 4380 + if (mode == X86EMUL_MODE_PROT64 && (ctxt->d & Stack)) 4407 4381 ctxt->op_bytes = 8; 4408 - else 4409 - ctxt->op_bytes = 4; 4410 - } 4411 4382 4412 - if (ctxt->d & Sse) 4413 - ctxt->op_bytes = 16; 4414 - else if (ctxt->d & Mmx) 4415 - ctxt->op_bytes = 8; 4383 + if (ctxt->d & Op3264) { 4384 + if (mode == X86EMUL_MODE_PROT64) 4385 + ctxt->op_bytes = 8; 4386 + else 4387 + ctxt->op_bytes = 4; 4388 + } 4389 + 4390 + if (ctxt->d & Sse) 4391 + ctxt->op_bytes = 16; 4392 + else if (ctxt->d & Mmx) 4393 + ctxt->op_bytes = 8; 4394 + } 4416 4395 4417 4396 /* ModRM and SIB bytes. */ 4418 4397 if (ctxt->d & ModRM) { 4419 4398 rc = decode_modrm(ctxt, &ctxt->memop); 4420 - if (!ctxt->has_seg_override) 4421 - set_seg_override(ctxt, ctxt->modrm_seg); 4399 + if (!has_seg_override) { 4400 + has_seg_override = true; 4401 + ctxt->seg_override = ctxt->modrm_seg; 4402 + } 4422 4403 } else if (ctxt->d & MemAbs) 4423 4404 rc = decode_abs(ctxt, &ctxt->memop); 4424 4405 if (rc != X86EMUL_CONTINUE) 4425 4406 goto done; 4426 4407 4427 - if (!ctxt->has_seg_override) 4428 - set_seg_override(ctxt, VCPU_SREG_DS); 4408 + if (!has_seg_override) 4409 + ctxt->seg_override = VCPU_SREG_DS; 4429 4410 4430 - ctxt->memop.addr.mem.seg = seg_override(ctxt); 4431 - 4432 - if (ctxt->memop.type == OP_MEM && ctxt->ad_bytes != 8) 4433 - ctxt->memop.addr.mem.ea = (u32)ctxt->memop.addr.mem.ea; 4411 + ctxt->memop.addr.mem.seg = ctxt->seg_override; 4434 4412 4435 4413 /* 4436 4414 * Decode and fetch the source operand: register, memory ··· 4462 4420 rc = decode_operand(ctxt, &ctxt->dst, (ctxt->d >> DstShift) & OpMask); 4463 4421 4464 4422 done: 4465 - if (ctxt->memopp && ctxt->memopp->type == OP_MEM && ctxt->rip_relative) 4423 + if (ctxt->rip_relative) 4466 4424 ctxt->memopp->addr.mem.ea += ctxt->_eip; 4467 4425 4468 4426 return (rc != X86EMUL_CONTINUE) ? EMULATION_FAILED : EMULATION_OK; ··· 4537 4495 return X86EMUL_CONTINUE; 4538 4496 } 4539 4497 4498 + void init_decode_cache(struct x86_emulate_ctxt *ctxt) 4499 + { 4500 + memset(&ctxt->rip_relative, 0, 4501 + (void *)&ctxt->modrm - (void *)&ctxt->rip_relative); 4502 + 4503 + ctxt->io_read.pos = 0; 4504 + ctxt->io_read.end = 0; 4505 + ctxt->mem_read.end = 0; 4506 + } 4507 + 4540 4508 int x86_emulate_insn(struct x86_emulate_ctxt *ctxt) 4541 4509 { 4542 4510 const struct x86_emulate_ops *ops = ctxt->ops; ··· 4554 4502 int saved_dst_type = ctxt->dst.type; 4555 4503 4556 4504 ctxt->mem_read.pos = 0; 4557 - 4558 - if ((ctxt->mode == X86EMUL_MODE_PROT64 && (ctxt->d & No64)) || 4559 - (ctxt->d & Undefined)) { 4560 - rc = emulate_ud(ctxt); 4561 - goto done; 4562 - } 4563 4505 4564 4506 /* LOCK prefix is allowed only with some instructions */ 4565 4507 if (ctxt->lock_prefix && (!(ctxt->d & Lock) || ctxt->dst.type != OP_MEM)) { ··· 4566 4520 goto done; 4567 4521 } 4568 4522 4569 - if (((ctxt->d & (Sse|Mmx)) && ((ops->get_cr(ctxt, 0) & X86_CR0_EM))) 4570 - || ((ctxt->d & Sse) && !(ops->get_cr(ctxt, 4) & X86_CR4_OSFXSR))) { 4571 - rc = emulate_ud(ctxt); 4572 - goto done; 4573 - } 4574 - 4575 - if ((ctxt->d & (Sse|Mmx)) && (ops->get_cr(ctxt, 0) & X86_CR0_TS)) { 4576 - rc = emulate_nm(ctxt); 4577 - goto done; 4578 - } 4579 - 4580 - if (ctxt->d & Mmx) { 4581 - rc = flush_pending_x87_faults(ctxt); 4582 - if (rc != X86EMUL_CONTINUE) 4523 + if (unlikely(ctxt->d & 4524 + (No64|Undefined|Sse|Mmx|Intercept|CheckPerm|Priv|Prot|String))) { 4525 + if ((ctxt->mode == X86EMUL_MODE_PROT64 && (ctxt->d & No64)) || 4526 + (ctxt->d & Undefined)) { 4527 + rc = emulate_ud(ctxt); 4583 4528 goto done; 4584 - /* 4585 - * Now that we know the fpu is exception safe, we can fetch 4586 - * operands from it. 4587 - */ 4588 - fetch_possible_mmx_operand(ctxt, &ctxt->src); 4589 - fetch_possible_mmx_operand(ctxt, &ctxt->src2); 4590 - if (!(ctxt->d & Mov)) 4591 - fetch_possible_mmx_operand(ctxt, &ctxt->dst); 4592 - } 4529 + } 4593 4530 4594 - if (unlikely(ctxt->guest_mode) && ctxt->intercept) { 4595 - rc = emulator_check_intercept(ctxt, ctxt->intercept, 4596 - X86_ICPT_PRE_EXCEPT); 4597 - if (rc != X86EMUL_CONTINUE) 4531 + if (((ctxt->d & (Sse|Mmx)) && ((ops->get_cr(ctxt, 0) & X86_CR0_EM))) 4532 + || ((ctxt->d & Sse) && !(ops->get_cr(ctxt, 4) & X86_CR4_OSFXSR))) { 4533 + rc = emulate_ud(ctxt); 4598 4534 goto done; 4599 - } 4535 + } 4600 4536 4601 - /* Privileged instruction can be executed only in CPL=0 */ 4602 - if ((ctxt->d & Priv) && ops->cpl(ctxt)) { 4603 - rc = emulate_gp(ctxt, 0); 4604 - goto done; 4605 - } 4606 - 4607 - /* Instruction can only be executed in protected mode */ 4608 - if ((ctxt->d & Prot) && ctxt->mode < X86EMUL_MODE_PROT16) { 4609 - rc = emulate_ud(ctxt); 4610 - goto done; 4611 - } 4612 - 4613 - /* Do instruction specific permission checks */ 4614 - if (ctxt->check_perm) { 4615 - rc = ctxt->check_perm(ctxt); 4616 - if (rc != X86EMUL_CONTINUE) 4537 + if ((ctxt->d & (Sse|Mmx)) && (ops->get_cr(ctxt, 0) & X86_CR0_TS)) { 4538 + rc = emulate_nm(ctxt); 4617 4539 goto done; 4618 - } 4540 + } 4619 4541 4620 - if (unlikely(ctxt->guest_mode) && ctxt->intercept) { 4621 - rc = emulator_check_intercept(ctxt, ctxt->intercept, 4622 - X86_ICPT_POST_EXCEPT); 4623 - if (rc != X86EMUL_CONTINUE) 4624 - goto done; 4625 - } 4542 + if (ctxt->d & Mmx) { 4543 + rc = flush_pending_x87_faults(ctxt); 4544 + if (rc != X86EMUL_CONTINUE) 4545 + goto done; 4546 + /* 4547 + * Now that we know the fpu is exception safe, we can fetch 4548 + * operands from it. 4549 + */ 4550 + fetch_possible_mmx_operand(ctxt, &ctxt->src); 4551 + fetch_possible_mmx_operand(ctxt, &ctxt->src2); 4552 + if (!(ctxt->d & Mov)) 4553 + fetch_possible_mmx_operand(ctxt, &ctxt->dst); 4554 + } 4626 4555 4627 - if (ctxt->rep_prefix && (ctxt->d & String)) { 4628 - /* All REP prefixes have the same first termination condition */ 4629 - if (address_mask(ctxt, reg_read(ctxt, VCPU_REGS_RCX)) == 0) { 4630 - ctxt->eip = ctxt->_eip; 4556 + if (unlikely(ctxt->guest_mode) && (ctxt->d & Intercept)) { 4557 + rc = emulator_check_intercept(ctxt, ctxt->intercept, 4558 + X86_ICPT_PRE_EXCEPT); 4559 + if (rc != X86EMUL_CONTINUE) 4560 + goto done; 4561 + } 4562 + 4563 + /* Privileged instruction can be executed only in CPL=0 */ 4564 + if ((ctxt->d & Priv) && ops->cpl(ctxt)) { 4565 + if (ctxt->d & PrivUD) 4566 + rc = emulate_ud(ctxt); 4567 + else 4568 + rc = emulate_gp(ctxt, 0); 4631 4569 goto done; 4570 + } 4571 + 4572 + /* Instruction can only be executed in protected mode */ 4573 + if ((ctxt->d & Prot) && ctxt->mode < X86EMUL_MODE_PROT16) { 4574 + rc = emulate_ud(ctxt); 4575 + goto done; 4576 + } 4577 + 4578 + /* Do instruction specific permission checks */ 4579 + if (ctxt->d & CheckPerm) { 4580 + rc = ctxt->check_perm(ctxt); 4581 + if (rc != X86EMUL_CONTINUE) 4582 + goto done; 4583 + } 4584 + 4585 + if (unlikely(ctxt->guest_mode) && (ctxt->d & Intercept)) { 4586 + rc = emulator_check_intercept(ctxt, ctxt->intercept, 4587 + X86_ICPT_POST_EXCEPT); 4588 + if (rc != X86EMUL_CONTINUE) 4589 + goto done; 4590 + } 4591 + 4592 + if (ctxt->rep_prefix && (ctxt->d & String)) { 4593 + /* All REP prefixes have the same first termination condition */ 4594 + if (address_mask(ctxt, reg_read(ctxt, VCPU_REGS_RCX)) == 0) { 4595 + ctxt->eip = ctxt->_eip; 4596 + ctxt->eflags &= ~EFLG_RF; 4597 + goto done; 4598 + } 4632 4599 } 4633 4600 } 4634 4601 ··· 4675 4616 4676 4617 special_insn: 4677 4618 4678 - if (unlikely(ctxt->guest_mode) && ctxt->intercept) { 4619 + if (unlikely(ctxt->guest_mode) && (ctxt->d & Intercept)) { 4679 4620 rc = emulator_check_intercept(ctxt, ctxt->intercept, 4680 4621 X86_ICPT_POST_MEMACCESS); 4681 4622 if (rc != X86EMUL_CONTINUE) 4682 4623 goto done; 4683 4624 } 4625 + 4626 + if (ctxt->rep_prefix && (ctxt->d & String)) 4627 + ctxt->eflags |= EFLG_RF; 4628 + else 4629 + ctxt->eflags &= ~EFLG_RF; 4684 4630 4685 4631 if (ctxt->execute) { 4686 4632 if (ctxt->d & Fastop) { ··· 4721 4657 break; 4722 4658 case 0x90 ... 0x97: /* nop / xchg reg, rax */ 4723 4659 if (ctxt->dst.addr.reg == reg_rmw(ctxt, VCPU_REGS_RAX)) 4724 - break; 4725 - rc = em_xchg(ctxt); 4660 + ctxt->dst.type = OP_NONE; 4661 + else 4662 + rc = em_xchg(ctxt); 4726 4663 break; 4727 4664 case 0x98: /* cbw/cwde/cdqe */ 4728 4665 switch (ctxt->op_bytes) { ··· 4774 4709 goto done; 4775 4710 4776 4711 writeback: 4777 - if (!(ctxt->d & NoWrite)) { 4778 - rc = writeback(ctxt, &ctxt->dst); 4779 - if (rc != X86EMUL_CONTINUE) 4780 - goto done; 4781 - } 4782 4712 if (ctxt->d & SrcWrite) { 4783 4713 BUG_ON(ctxt->src.type == OP_MEM || ctxt->src.type == OP_MEM_STR); 4784 4714 rc = writeback(ctxt, &ctxt->src); 4715 + if (rc != X86EMUL_CONTINUE) 4716 + goto done; 4717 + } 4718 + if (!(ctxt->d & NoWrite)) { 4719 + rc = writeback(ctxt, &ctxt->dst); 4785 4720 if (rc != X86EMUL_CONTINUE) 4786 4721 goto done; 4787 4722 } ··· 4826 4761 } 4827 4762 goto done; /* skip rip writeback */ 4828 4763 } 4764 + ctxt->eflags &= ~EFLG_RF; 4829 4765 } 4830 4766 4831 4767 ctxt->eip = ctxt->_eip; ··· 4859 4793 ops->get_dr(ctxt, ctxt->modrm_reg, &ctxt->dst.val); 4860 4794 break; 4861 4795 case 0x40 ... 0x4f: /* cmov */ 4862 - ctxt->dst.val = ctxt->dst.orig_val = ctxt->src.val; 4863 - if (!test_cc(ctxt->b, ctxt->eflags)) 4796 + if (test_cc(ctxt->b, ctxt->eflags)) 4797 + ctxt->dst.val = ctxt->src.val; 4798 + else if (ctxt->mode != X86EMUL_MODE_PROT64 || 4799 + ctxt->op_bytes != 4) 4864 4800 ctxt->dst.type = OP_NONE; /* no writeback */ 4865 4801 break; 4866 4802 case 0x80 ... 0x8f: /* jnz rel, etc*/ ··· 4886 4818 break; 4887 4819 case 0xc3: /* movnti */ 4888 4820 ctxt->dst.bytes = ctxt->op_bytes; 4889 - ctxt->dst.val = (ctxt->op_bytes == 4) ? (u32) ctxt->src.val : 4890 - (u64) ctxt->src.val; 4821 + ctxt->dst.val = (ctxt->op_bytes == 8) ? (u64) ctxt->src.val : 4822 + (u32) ctxt->src.val; 4891 4823 break; 4892 4824 default: 4893 4825 goto cannot_emulate;
+2 -2
arch/x86/kvm/lapic.c
··· 1451 1451 vcpu->arch.apic_arb_prio = 0; 1452 1452 vcpu->arch.apic_attention = 0; 1453 1453 1454 - apic_debug(KERN_INFO "%s: vcpu=%p, id=%d, base_msr=" 1454 + apic_debug("%s: vcpu=%p, id=%d, base_msr=" 1455 1455 "0x%016" PRIx64 ", base_address=0x%0lx.\n", __func__, 1456 1456 vcpu, kvm_apic_id(apic), 1457 1457 vcpu->arch.apic_base, apic->base_address); ··· 1895 1895 /* evaluate pending_events before reading the vector */ 1896 1896 smp_rmb(); 1897 1897 sipi_vector = apic->sipi_vector; 1898 - pr_debug("vcpu %d received sipi with vector # %x\n", 1898 + apic_debug("vcpu %d received sipi with vector # %x\n", 1899 1899 vcpu->vcpu_id, sipi_vector); 1900 1900 kvm_vcpu_deliver_sipi_vector(vcpu, sipi_vector); 1901 1901 vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE;
+2 -2
arch/x86/kvm/mmutrace.h
··· 22 22 __entry->unsync = sp->unsync; 23 23 24 24 #define KVM_MMU_PAGE_PRINTK() ({ \ 25 - const char *ret = trace_seq_buffer_ptr(p); \ 25 + const u32 saved_len = p->len; \ 26 26 static const char *access_str[] = { \ 27 27 "---", "--x", "w--", "w-x", "-u-", "-ux", "wu-", "wux" \ 28 28 }; \ ··· 41 41 role.nxe ? "" : "!", \ 42 42 __entry->root_count, \ 43 43 __entry->unsync ? "unsync" : "sync", 0); \ 44 - ret; \ 44 + p->buffer + saved_len; \ 45 45 }) 46 46 47 47 #define kvm_mmu_trace_pferr_flags \
+9
arch/x86/kvm/pmu.c
··· 428 428 return 1; 429 429 } 430 430 431 + int kvm_pmu_check_pmc(struct kvm_vcpu *vcpu, unsigned pmc) 432 + { 433 + struct kvm_pmu *pmu = &vcpu->arch.pmu; 434 + bool fixed = pmc & (1u << 30); 435 + pmc &= ~(3u << 30); 436 + return (!fixed && pmc >= pmu->nr_arch_gp_counters) || 437 + (fixed && pmc >= pmu->nr_arch_fixed_counters); 438 + } 439 + 431 440 int kvm_pmu_read_pmc(struct kvm_vcpu *vcpu, unsigned pmc, u64 *data) 432 441 { 433 442 struct kvm_pmu *pmu = &vcpu->arch.pmu;
+32 -25
arch/x86/kvm/svm.c
··· 486 486 return info == (SVM_EVTINJ_VALID | SVM_EVTINJ_TYPE_INTR); 487 487 } 488 488 489 - static u32 svm_get_interrupt_shadow(struct kvm_vcpu *vcpu, int mask) 489 + static u32 svm_get_interrupt_shadow(struct kvm_vcpu *vcpu) 490 490 { 491 491 struct vcpu_svm *svm = to_svm(vcpu); 492 492 u32 ret = 0; 493 493 494 494 if (svm->vmcb->control.int_state & SVM_INTERRUPT_SHADOW_MASK) 495 - ret |= KVM_X86_SHADOW_INT_STI | KVM_X86_SHADOW_INT_MOV_SS; 496 - return ret & mask; 495 + ret = KVM_X86_SHADOW_INT_STI | KVM_X86_SHADOW_INT_MOV_SS; 496 + return ret; 497 497 } 498 498 499 499 static void svm_set_interrupt_shadow(struct kvm_vcpu *vcpu, int mask) ··· 1415 1415 var->avl = (s->attrib >> SVM_SELECTOR_AVL_SHIFT) & 1; 1416 1416 var->l = (s->attrib >> SVM_SELECTOR_L_SHIFT) & 1; 1417 1417 var->db = (s->attrib >> SVM_SELECTOR_DB_SHIFT) & 1; 1418 - var->g = (s->attrib >> SVM_SELECTOR_G_SHIFT) & 1; 1418 + 1419 + /* 1420 + * AMD CPUs circa 2014 track the G bit for all segments except CS. 1421 + * However, the SVM spec states that the G bit is not observed by the 1422 + * CPU, and some VMware virtual CPUs drop the G bit for all segments. 1423 + * So let's synthesize a legal G bit for all segments, this helps 1424 + * running KVM nested. It also helps cross-vendor migration, because 1425 + * Intel's vmentry has a check on the 'G' bit. 1426 + */ 1427 + var->g = s->limit > 0xfffff; 1419 1428 1420 1429 /* 1421 1430 * AMD's VMCB does not have an explicit unusable field, so emulate it ··· 1433 1424 var->unusable = !var->present || (var->type == 0); 1434 1425 1435 1426 switch (seg) { 1436 - case VCPU_SREG_CS: 1437 - /* 1438 - * SVM always stores 0 for the 'G' bit in the CS selector in 1439 - * the VMCB on a VMEXIT. This hurts cross-vendor migration: 1440 - * Intel's VMENTRY has a check on the 'G' bit. 1441 - */ 1442 - var->g = s->limit > 0xfffff; 1443 - break; 1444 1427 case VCPU_SREG_TR: 1445 1428 /* 1446 1429 * Work around a bug where the busy flag in the tr selector ··· 2117 2116 2118 2117 static int nested_svm_intercept_ioio(struct vcpu_svm *svm) 2119 2118 { 2120 - unsigned port; 2121 - u8 val, bit; 2119 + unsigned port, size, iopm_len; 2120 + u16 val, mask; 2121 + u8 start_bit; 2122 2122 u64 gpa; 2123 2123 2124 2124 if (!(svm->nested.intercept & (1ULL << INTERCEPT_IOIO_PROT))) 2125 2125 return NESTED_EXIT_HOST; 2126 2126 2127 2127 port = svm->vmcb->control.exit_info_1 >> 16; 2128 + size = (svm->vmcb->control.exit_info_1 & SVM_IOIO_SIZE_MASK) >> 2129 + SVM_IOIO_SIZE_SHIFT; 2128 2130 gpa = svm->nested.vmcb_iopm + (port / 8); 2129 - bit = port % 8; 2130 - val = 0; 2131 + start_bit = port % 8; 2132 + iopm_len = (start_bit + size > 8) ? 2 : 1; 2133 + mask = (0xf >> (4 - size)) << start_bit; 2134 + val = 0; 2131 2135 2132 - if (kvm_read_guest(svm->vcpu.kvm, gpa, &val, 1)) 2133 - val &= (1 << bit); 2136 + if (kvm_read_guest(svm->vcpu.kvm, gpa, &val, iopm_len)) 2137 + return NESTED_EXIT_DONE; 2134 2138 2135 - return val ? NESTED_EXIT_DONE : NESTED_EXIT_HOST; 2139 + return (val & mask) ? NESTED_EXIT_DONE : NESTED_EXIT_HOST; 2136 2140 } 2137 2141 2138 2142 static int nested_svm_exit_handled_msr(struct vcpu_svm *svm) ··· 4211 4205 if (info->intercept == x86_intercept_cr_write) 4212 4206 icpt_info.exit_code += info->modrm_reg; 4213 4207 4214 - if (icpt_info.exit_code != SVM_EXIT_WRITE_CR0) 4208 + if (icpt_info.exit_code != SVM_EXIT_WRITE_CR0 || 4209 + info->intercept == x86_intercept_clts) 4215 4210 break; 4216 4211 4217 4212 intercept = svm->nested.intercept; ··· 4257 4250 u64 exit_info; 4258 4251 u32 bytes; 4259 4252 4260 - exit_info = (vcpu->arch.regs[VCPU_REGS_RDX] & 0xffff) << 16; 4261 - 4262 4253 if (info->intercept == x86_intercept_in || 4263 4254 info->intercept == x86_intercept_ins) { 4264 - exit_info |= SVM_IOIO_TYPE_MASK; 4265 - bytes = info->src_bytes; 4266 - } else { 4255 + exit_info = ((info->src_val & 0xffff) << 16) | 4256 + SVM_IOIO_TYPE_MASK; 4267 4257 bytes = info->dst_bytes; 4258 + } else { 4259 + exit_info = (info->dst_val & 0xffff) << 16; 4260 + bytes = info->src_bytes; 4268 4261 } 4269 4262 4270 4263 if (info->intercept == x86_intercept_outs ||
+3 -3
arch/x86/kvm/trace.h
··· 721 721 ), 722 722 723 723 TP_fast_assign( 724 - __entry->rip = vcpu->arch.emulate_ctxt.fetch.start; 725 724 __entry->csbase = kvm_x86_ops->get_segment_base(vcpu, VCPU_SREG_CS); 726 - __entry->len = vcpu->arch.emulate_ctxt._eip 727 - - vcpu->arch.emulate_ctxt.fetch.start; 725 + __entry->len = vcpu->arch.emulate_ctxt.fetch.ptr 726 + - vcpu->arch.emulate_ctxt.fetch.data; 727 + __entry->rip = vcpu->arch.emulate_ctxt._eip - __entry->len; 728 728 memcpy(__entry->insn, 729 729 vcpu->arch.emulate_ctxt.fetch.data, 730 730 15);
+154 -85
arch/x86/kvm/vmx.c
··· 383 383 384 384 struct hrtimer preemption_timer; 385 385 bool preemption_timer_expired; 386 + 387 + /* to migrate it to L2 if VM_ENTRY_LOAD_DEBUG_CONTROLS is off */ 388 + u64 vmcs01_debugctl; 386 389 }; 387 390 388 391 #define POSTED_INTR_ON 0 ··· 743 740 static void vmx_sync_pir_to_irr_dummy(struct kvm_vcpu *vcpu); 744 741 static void copy_vmcs12_to_shadow(struct vcpu_vmx *vmx); 745 742 static void copy_shadow_to_vmcs12(struct vcpu_vmx *vmx); 746 - static bool vmx_mpx_supported(void); 747 743 748 744 static DEFINE_PER_CPU(struct vmcs *, vmxarea); 749 745 static DEFINE_PER_CPU(struct vmcs *, current_vmcs); ··· 822 820 #endif 823 821 MSR_EFER, MSR_TSC_AUX, MSR_STAR, 824 822 }; 825 - #define NR_VMX_MSR ARRAY_SIZE(vmx_msr_index) 826 823 827 824 static inline bool is_page_fault(u32 intr_info) 828 825 { ··· 1941 1940 vmcs_writel(GUEST_RFLAGS, rflags); 1942 1941 } 1943 1942 1944 - static u32 vmx_get_interrupt_shadow(struct kvm_vcpu *vcpu, int mask) 1943 + static u32 vmx_get_interrupt_shadow(struct kvm_vcpu *vcpu) 1945 1944 { 1946 1945 u32 interruptibility = vmcs_read32(GUEST_INTERRUPTIBILITY_INFO); 1947 1946 int ret = 0; ··· 1951 1950 if (interruptibility & GUEST_INTR_STATE_MOV_SS) 1952 1951 ret |= KVM_X86_SHADOW_INT_MOV_SS; 1953 1952 1954 - return ret & mask; 1953 + return ret; 1955 1954 } 1956 1955 1957 1956 static void vmx_set_interrupt_shadow(struct kvm_vcpu *vcpu, int mask) ··· 2240 2239 * or other means. 2241 2240 */ 2242 2241 static u32 nested_vmx_procbased_ctls_low, nested_vmx_procbased_ctls_high; 2242 + static u32 nested_vmx_true_procbased_ctls_low; 2243 2243 static u32 nested_vmx_secondary_ctls_low, nested_vmx_secondary_ctls_high; 2244 2244 static u32 nested_vmx_pinbased_ctls_low, nested_vmx_pinbased_ctls_high; 2245 2245 static u32 nested_vmx_exit_ctls_low, nested_vmx_exit_ctls_high; 2246 + static u32 nested_vmx_true_exit_ctls_low; 2246 2247 static u32 nested_vmx_entry_ctls_low, nested_vmx_entry_ctls_high; 2248 + static u32 nested_vmx_true_entry_ctls_low; 2247 2249 static u32 nested_vmx_misc_low, nested_vmx_misc_high; 2248 2250 static u32 nested_vmx_ept_caps; 2249 2251 static __init void nested_vmx_setup_ctls_msrs(void) ··· 2269 2265 /* pin-based controls */ 2270 2266 rdmsr(MSR_IA32_VMX_PINBASED_CTLS, 2271 2267 nested_vmx_pinbased_ctls_low, nested_vmx_pinbased_ctls_high); 2272 - /* 2273 - * According to the Intel spec, if bit 55 of VMX_BASIC is off (as it is 2274 - * in our case), bits 1, 2 and 4 (i.e., 0x16) must be 1 in this MSR. 2275 - */ 2276 2268 nested_vmx_pinbased_ctls_low |= PIN_BASED_ALWAYSON_WITHOUT_TRUE_MSR; 2277 2269 nested_vmx_pinbased_ctls_high &= PIN_BASED_EXT_INTR_MASK | 2278 2270 PIN_BASED_NMI_EXITING | PIN_BASED_VIRTUAL_NMIS; 2279 2271 nested_vmx_pinbased_ctls_high |= PIN_BASED_ALWAYSON_WITHOUT_TRUE_MSR | 2280 2272 PIN_BASED_VMX_PREEMPTION_TIMER; 2281 2273 2282 - /* 2283 - * Exit controls 2284 - * If bit 55 of VMX_BASIC is off, bits 0-8 and 10, 11, 13, 14, 16 and 2285 - * 17 must be 1. 2286 - */ 2274 + /* exit controls */ 2287 2275 rdmsr(MSR_IA32_VMX_EXIT_CTLS, 2288 2276 nested_vmx_exit_ctls_low, nested_vmx_exit_ctls_high); 2289 2277 nested_vmx_exit_ctls_low = VM_EXIT_ALWAYSON_WITHOUT_TRUE_MSR; ··· 2292 2296 if (vmx_mpx_supported()) 2293 2297 nested_vmx_exit_ctls_high |= VM_EXIT_CLEAR_BNDCFGS; 2294 2298 2299 + /* We support free control of debug control saving. */ 2300 + nested_vmx_true_exit_ctls_low = nested_vmx_exit_ctls_low & 2301 + ~VM_EXIT_SAVE_DEBUG_CONTROLS; 2302 + 2295 2303 /* entry controls */ 2296 2304 rdmsr(MSR_IA32_VMX_ENTRY_CTLS, 2297 2305 nested_vmx_entry_ctls_low, nested_vmx_entry_ctls_high); 2298 - /* If bit 55 of VMX_BASIC is off, bits 0-8 and 12 must be 1. */ 2299 2306 nested_vmx_entry_ctls_low = VM_ENTRY_ALWAYSON_WITHOUT_TRUE_MSR; 2300 2307 nested_vmx_entry_ctls_high &= 2301 2308 #ifdef CONFIG_X86_64 ··· 2310 2311 if (vmx_mpx_supported()) 2311 2312 nested_vmx_entry_ctls_high |= VM_ENTRY_LOAD_BNDCFGS; 2312 2313 2314 + /* We support free control of debug control loading. */ 2315 + nested_vmx_true_entry_ctls_low = nested_vmx_entry_ctls_low & 2316 + ~VM_ENTRY_LOAD_DEBUG_CONTROLS; 2317 + 2313 2318 /* cpu-based controls */ 2314 2319 rdmsr(MSR_IA32_VMX_PROCBASED_CTLS, 2315 2320 nested_vmx_procbased_ctls_low, nested_vmx_procbased_ctls_high); 2316 - nested_vmx_procbased_ctls_low = 0; 2321 + nested_vmx_procbased_ctls_low = CPU_BASED_ALWAYSON_WITHOUT_TRUE_MSR; 2317 2322 nested_vmx_procbased_ctls_high &= 2318 2323 CPU_BASED_VIRTUAL_INTR_PENDING | 2319 2324 CPU_BASED_VIRTUAL_NMI_PENDING | CPU_BASED_USE_TSC_OFFSETING | ··· 2338 2335 * can use it to avoid exits to L1 - even when L0 runs L2 2339 2336 * without MSR bitmaps. 2340 2337 */ 2341 - nested_vmx_procbased_ctls_high |= CPU_BASED_USE_MSR_BITMAPS; 2338 + nested_vmx_procbased_ctls_high |= CPU_BASED_ALWAYSON_WITHOUT_TRUE_MSR | 2339 + CPU_BASED_USE_MSR_BITMAPS; 2340 + 2341 + /* We support free control of CR3 access interception. */ 2342 + nested_vmx_true_procbased_ctls_low = nested_vmx_procbased_ctls_low & 2343 + ~(CPU_BASED_CR3_LOAD_EXITING | CPU_BASED_CR3_STORE_EXITING); 2342 2344 2343 2345 /* secondary cpu-based controls */ 2344 2346 rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2, ··· 2402 2394 * guest, and the VMCS structure we give it - not about the 2403 2395 * VMX support of the underlying hardware. 2404 2396 */ 2405 - *pdata = VMCS12_REVISION | 2397 + *pdata = VMCS12_REVISION | VMX_BASIC_TRUE_CTLS | 2406 2398 ((u64)VMCS12_SIZE << VMX_BASIC_VMCS_SIZE_SHIFT) | 2407 2399 (VMX_BASIC_MEM_TYPE_WB << VMX_BASIC_MEM_TYPE_SHIFT); 2408 2400 break; ··· 2412 2404 nested_vmx_pinbased_ctls_high); 2413 2405 break; 2414 2406 case MSR_IA32_VMX_TRUE_PROCBASED_CTLS: 2407 + *pdata = vmx_control_msr(nested_vmx_true_procbased_ctls_low, 2408 + nested_vmx_procbased_ctls_high); 2409 + break; 2415 2410 case MSR_IA32_VMX_PROCBASED_CTLS: 2416 2411 *pdata = vmx_control_msr(nested_vmx_procbased_ctls_low, 2417 2412 nested_vmx_procbased_ctls_high); 2418 2413 break; 2419 2414 case MSR_IA32_VMX_TRUE_EXIT_CTLS: 2415 + *pdata = vmx_control_msr(nested_vmx_true_exit_ctls_low, 2416 + nested_vmx_exit_ctls_high); 2417 + break; 2420 2418 case MSR_IA32_VMX_EXIT_CTLS: 2421 2419 *pdata = vmx_control_msr(nested_vmx_exit_ctls_low, 2422 2420 nested_vmx_exit_ctls_high); 2423 2421 break; 2424 2422 case MSR_IA32_VMX_TRUE_ENTRY_CTLS: 2423 + *pdata = vmx_control_msr(nested_vmx_true_entry_ctls_low, 2424 + nested_vmx_entry_ctls_high); 2425 + break; 2425 2426 case MSR_IA32_VMX_ENTRY_CTLS: 2426 2427 *pdata = vmx_control_msr(nested_vmx_entry_ctls_low, 2427 2428 nested_vmx_entry_ctls_high); ··· 2459 2442 *pdata = -1ULL; 2460 2443 break; 2461 2444 case MSR_IA32_VMX_VMCS_ENUM: 2462 - *pdata = 0x1f; 2445 + *pdata = 0x2e; /* highest index: VMX_PREEMPTION_TIMER_VALUE */ 2463 2446 break; 2464 2447 case MSR_IA32_VMX_PROCBASED_CTLS2: 2465 2448 *pdata = vmx_control_msr(nested_vmx_secondary_ctls_low, ··· 3670 3653 vmcs_write32(sf->ar_bytes, vmx_segment_access_rights(var)); 3671 3654 3672 3655 out: 3673 - vmx->emulation_required |= emulation_required(vcpu); 3656 + vmx->emulation_required = emulation_required(vcpu); 3674 3657 } 3675 3658 3676 3659 static void vmx_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l) ··· 4439 4422 vmx->vcpu.arch.pat = host_pat; 4440 4423 } 4441 4424 4442 - for (i = 0; i < NR_VMX_MSR; ++i) { 4425 + for (i = 0; i < ARRAY_SIZE(vmx_msr_index); ++i) { 4443 4426 u32 index = vmx_msr_index[i]; 4444 4427 u32 data_low, data_high; 4445 4428 int j = vmx->nmsrs; ··· 4890 4873 if (!(vcpu->guest_debug & 4891 4874 (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP))) { 4892 4875 vcpu->arch.dr6 &= ~15; 4893 - vcpu->arch.dr6 |= dr6; 4876 + vcpu->arch.dr6 |= dr6 | DR6_RTM; 4894 4877 if (!(dr6 & ~DR6_RESERVED)) /* icebp */ 4895 4878 skip_emulated_instruction(vcpu); 4896 4879 ··· 5056 5039 reg = (exit_qualification >> 8) & 15; 5057 5040 switch ((exit_qualification >> 4) & 3) { 5058 5041 case 0: /* mov to cr */ 5059 - val = kvm_register_read(vcpu, reg); 5042 + val = kvm_register_readl(vcpu, reg); 5060 5043 trace_kvm_cr_write(cr, val); 5061 5044 switch (cr) { 5062 5045 case 0: ··· 5073 5056 return 1; 5074 5057 case 8: { 5075 5058 u8 cr8_prev = kvm_get_cr8(vcpu); 5076 - u8 cr8 = kvm_register_read(vcpu, reg); 5059 + u8 cr8 = (u8)val; 5077 5060 err = kvm_set_cr8(vcpu, cr8); 5078 5061 kvm_complete_insn_gp(vcpu, err); 5079 5062 if (irqchip_in_kernel(vcpu->kvm)) ··· 5149 5132 return 0; 5150 5133 } else { 5151 5134 vcpu->arch.dr7 &= ~DR7_GD; 5152 - vcpu->arch.dr6 |= DR6_BD; 5135 + vcpu->arch.dr6 |= DR6_BD | DR6_RTM; 5153 5136 vmcs_writel(GUEST_DR7, vcpu->arch.dr7); 5154 5137 kvm_queue_exception(vcpu, DB_VECTOR); 5155 5138 return 1; ··· 5182 5165 return 1; 5183 5166 kvm_register_write(vcpu, reg, val); 5184 5167 } else 5185 - if (kvm_set_dr(vcpu, dr, kvm_register_read(vcpu, reg))) 5168 + if (kvm_set_dr(vcpu, dr, kvm_register_readl(vcpu, reg))) 5186 5169 return 1; 5187 5170 5188 5171 skip_emulated_instruction(vcpu); ··· 5638 5621 cpu_exec_ctrl = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL); 5639 5622 intr_window_requested = cpu_exec_ctrl & CPU_BASED_VIRTUAL_INTR_PENDING; 5640 5623 5641 - while (!guest_state_valid(vcpu) && count-- != 0) { 5624 + while (vmx->emulation_required && count-- != 0) { 5642 5625 if (intr_window_requested && vmx_interrupt_allowed(vcpu)) 5643 5626 return handle_interrupt_window(&vmx->vcpu); 5644 5627 ··· 5672 5655 schedule(); 5673 5656 } 5674 5657 5675 - vmx->emulation_required = emulation_required(vcpu); 5676 5658 out: 5677 5659 return ret; 5678 5660 } ··· 5770 5754 5771 5755 /* 5772 5756 * Free all VMCSs saved for this vcpu, except the one pointed by 5773 - * vmx->loaded_vmcs. These include the VMCSs in vmcs02_pool (except the one 5774 - * currently used, if running L2), and vmcs01 when running L2. 5757 + * vmx->loaded_vmcs. We must be running L1, so vmx->loaded_vmcs 5758 + * must be &vmx->vmcs01. 5775 5759 */ 5776 5760 static void nested_free_all_saved_vmcss(struct vcpu_vmx *vmx) 5777 5761 { 5778 5762 struct vmcs02_list *item, *n; 5763 + 5764 + WARN_ON(vmx->loaded_vmcs != &vmx->vmcs01); 5779 5765 list_for_each_entry_safe(item, n, &vmx->nested.vmcs02_pool, list) { 5780 - if (vmx->loaded_vmcs != &item->vmcs02) 5781 - free_loaded_vmcs(&item->vmcs02); 5766 + /* 5767 + * Something will leak if the above WARN triggers. Better than 5768 + * a use-after-free. 5769 + */ 5770 + if (vmx->loaded_vmcs == &item->vmcs02) 5771 + continue; 5772 + 5773 + free_loaded_vmcs(&item->vmcs02); 5782 5774 list_del(&item->list); 5783 5775 kfree(item); 5776 + vmx->nested.vmcs02_num--; 5784 5777 } 5785 - vmx->nested.vmcs02_num = 0; 5786 - 5787 - if (vmx->loaded_vmcs != &vmx->vmcs01) 5788 - free_loaded_vmcs(&vmx->vmcs01); 5789 5778 } 5790 5779 5791 5780 /* ··· 5939 5918 * which replaces physical address width with 32 5940 5919 * 5941 5920 */ 5942 - if (!IS_ALIGNED(vmptr, PAGE_SIZE) || (vmptr >> maxphyaddr)) { 5921 + if (!PAGE_ALIGNED(vmptr) || (vmptr >> maxphyaddr)) { 5943 5922 nested_vmx_failInvalid(vcpu); 5944 5923 skip_emulated_instruction(vcpu); 5945 5924 return 1; ··· 5957 5936 vmx->nested.vmxon_ptr = vmptr; 5958 5937 break; 5959 5938 case EXIT_REASON_VMCLEAR: 5960 - if (!IS_ALIGNED(vmptr, PAGE_SIZE) || (vmptr >> maxphyaddr)) { 5939 + if (!PAGE_ALIGNED(vmptr) || (vmptr >> maxphyaddr)) { 5961 5940 nested_vmx_failValid(vcpu, 5962 5941 VMXERR_VMCLEAR_INVALID_ADDRESS); 5963 5942 skip_emulated_instruction(vcpu); ··· 5972 5951 } 5973 5952 break; 5974 5953 case EXIT_REASON_VMPTRLD: 5975 - if (!IS_ALIGNED(vmptr, PAGE_SIZE) || (vmptr >> maxphyaddr)) { 5954 + if (!PAGE_ALIGNED(vmptr) || (vmptr >> maxphyaddr)) { 5976 5955 nested_vmx_failValid(vcpu, 5977 5956 VMXERR_VMPTRLD_INVALID_ADDRESS); 5978 5957 skip_emulated_instruction(vcpu); ··· 6107 6086 static inline void nested_release_vmcs12(struct vcpu_vmx *vmx) 6108 6087 { 6109 6088 u32 exec_control; 6089 + if (vmx->nested.current_vmptr == -1ull) 6090 + return; 6091 + 6092 + /* current_vmptr and current_vmcs12 are always set/reset together */ 6093 + if (WARN_ON(vmx->nested.current_vmcs12 == NULL)) 6094 + return; 6095 + 6110 6096 if (enable_shadow_vmcs) { 6111 - if (vmx->nested.current_vmcs12 != NULL) { 6112 - /* copy to memory all shadowed fields in case 6113 - they were modified */ 6114 - copy_shadow_to_vmcs12(vmx); 6115 - vmx->nested.sync_shadow_vmcs = false; 6116 - exec_control = vmcs_read32(SECONDARY_VM_EXEC_CONTROL); 6117 - exec_control &= ~SECONDARY_EXEC_SHADOW_VMCS; 6118 - vmcs_write32(SECONDARY_VM_EXEC_CONTROL, exec_control); 6119 - vmcs_write64(VMCS_LINK_POINTER, -1ull); 6120 - } 6097 + /* copy to memory all shadowed fields in case 6098 + they were modified */ 6099 + copy_shadow_to_vmcs12(vmx); 6100 + vmx->nested.sync_shadow_vmcs = false; 6101 + exec_control = vmcs_read32(SECONDARY_VM_EXEC_CONTROL); 6102 + exec_control &= ~SECONDARY_EXEC_SHADOW_VMCS; 6103 + vmcs_write32(SECONDARY_VM_EXEC_CONTROL, exec_control); 6104 + vmcs_write64(VMCS_LINK_POINTER, -1ull); 6121 6105 } 6122 6106 kunmap(vmx->nested.current_vmcs12_page); 6123 6107 nested_release_page(vmx->nested.current_vmcs12_page); 6108 + vmx->nested.current_vmptr = -1ull; 6109 + vmx->nested.current_vmcs12 = NULL; 6124 6110 } 6125 6111 6126 6112 /* ··· 6138 6110 { 6139 6111 if (!vmx->nested.vmxon) 6140 6112 return; 6113 + 6141 6114 vmx->nested.vmxon = false; 6142 - if (vmx->nested.current_vmptr != -1ull) { 6143 - nested_release_vmcs12(vmx); 6144 - vmx->nested.current_vmptr = -1ull; 6145 - vmx->nested.current_vmcs12 = NULL; 6146 - } 6115 + nested_release_vmcs12(vmx); 6147 6116 if (enable_shadow_vmcs) 6148 6117 free_vmcs(vmx->nested.current_shadow_vmcs); 6149 6118 /* Unpin physical memory we referred to in current vmcs02 */ ··· 6177 6152 if (nested_vmx_check_vmptr(vcpu, EXIT_REASON_VMCLEAR, &vmptr)) 6178 6153 return 1; 6179 6154 6180 - if (vmptr == vmx->nested.current_vmptr) { 6155 + if (vmptr == vmx->nested.current_vmptr) 6181 6156 nested_release_vmcs12(vmx); 6182 - vmx->nested.current_vmptr = -1ull; 6183 - vmx->nested.current_vmcs12 = NULL; 6184 - } 6185 6157 6186 6158 page = nested_get_page(vcpu, vmptr); 6187 6159 if (page == NULL) { ··· 6406 6384 return 1; 6407 6385 6408 6386 /* Decode instruction info and find the field to read */ 6409 - field = kvm_register_read(vcpu, (((vmx_instruction_info) >> 28) & 0xf)); 6387 + field = kvm_register_readl(vcpu, (((vmx_instruction_info) >> 28) & 0xf)); 6410 6388 /* Read the field, zero-extended to a u64 field_value */ 6411 6389 if (!vmcs12_read_any(vcpu, field, &field_value)) { 6412 6390 nested_vmx_failValid(vcpu, VMXERR_UNSUPPORTED_VMCS_COMPONENT); ··· 6419 6397 * on the guest's mode (32 or 64 bit), not on the given field's length. 6420 6398 */ 6421 6399 if (vmx_instruction_info & (1u << 10)) { 6422 - kvm_register_write(vcpu, (((vmx_instruction_info) >> 3) & 0xf), 6400 + kvm_register_writel(vcpu, (((vmx_instruction_info) >> 3) & 0xf), 6423 6401 field_value); 6424 6402 } else { 6425 6403 if (get_vmx_mem_address(vcpu, exit_qualification, ··· 6456 6434 return 1; 6457 6435 6458 6436 if (vmx_instruction_info & (1u << 10)) 6459 - field_value = kvm_register_read(vcpu, 6437 + field_value = kvm_register_readl(vcpu, 6460 6438 (((vmx_instruction_info) >> 3) & 0xf)); 6461 6439 else { 6462 6440 if (get_vmx_mem_address(vcpu, exit_qualification, 6463 6441 vmx_instruction_info, &gva)) 6464 6442 return 1; 6465 6443 if (kvm_read_guest_virt(&vcpu->arch.emulate_ctxt, gva, 6466 - &field_value, (is_long_mode(vcpu) ? 8 : 4), &e)) { 6444 + &field_value, (is_64_bit_mode(vcpu) ? 8 : 4), &e)) { 6467 6445 kvm_inject_page_fault(vcpu, &e); 6468 6446 return 1; 6469 6447 } 6470 6448 } 6471 6449 6472 6450 6473 - field = kvm_register_read(vcpu, (((vmx_instruction_info) >> 28) & 0xf)); 6451 + field = kvm_register_readl(vcpu, (((vmx_instruction_info) >> 28) & 0xf)); 6474 6452 if (vmcs_field_readonly(field)) { 6475 6453 nested_vmx_failValid(vcpu, 6476 6454 VMXERR_VMWRITE_READ_ONLY_VMCS_COMPONENT); ··· 6520 6498 skip_emulated_instruction(vcpu); 6521 6499 return 1; 6522 6500 } 6523 - if (vmx->nested.current_vmptr != -1ull) 6524 - nested_release_vmcs12(vmx); 6525 6501 6502 + nested_release_vmcs12(vmx); 6526 6503 vmx->nested.current_vmptr = vmptr; 6527 6504 vmx->nested.current_vmcs12 = new_vmcs12; 6528 6505 vmx->nested.current_vmcs12_page = page; ··· 6592 6571 } 6593 6572 6594 6573 vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO); 6595 - type = kvm_register_read(vcpu, (vmx_instruction_info >> 28) & 0xf); 6574 + type = kvm_register_readl(vcpu, (vmx_instruction_info >> 28) & 0xf); 6596 6575 6597 6576 types = (nested_vmx_ept_caps >> VMX_EPT_EXTENT_SHIFT) & 6; 6598 6577 ··· 6772 6751 unsigned long exit_qualification = vmcs_readl(EXIT_QUALIFICATION); 6773 6752 int cr = exit_qualification & 15; 6774 6753 int reg = (exit_qualification >> 8) & 15; 6775 - unsigned long val = kvm_register_read(vcpu, reg); 6754 + unsigned long val = kvm_register_readl(vcpu, reg); 6776 6755 6777 6756 switch ((exit_qualification >> 4) & 3) { 6778 6757 case 0: /* mov to cr */ ··· 7133 7112 if (max_irr == -1) 7134 7113 return; 7135 7114 7136 - vmx_set_rvi(max_irr); 7115 + /* 7116 + * If a vmexit is needed, vmx_check_nested_events handles it. 7117 + */ 7118 + if (is_guest_mode(vcpu) && nested_exit_on_intr(vcpu)) 7119 + return; 7120 + 7121 + if (!is_guest_mode(vcpu)) { 7122 + vmx_set_rvi(max_irr); 7123 + return; 7124 + } 7125 + 7126 + /* 7127 + * Fall back to pre-APICv interrupt injection since L2 7128 + * is run without virtual interrupt delivery. 7129 + */ 7130 + if (!kvm_event_needs_reinjection(vcpu) && 7131 + vmx_interrupt_allowed(vcpu)) { 7132 + kvm_queue_interrupt(vcpu, max_irr, false); 7133 + vmx_inject_irq(vcpu); 7134 + } 7137 7135 } 7138 7136 7139 7137 static void vmx_load_eoi_exitmap(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap) ··· 7560 7520 vmx_complete_interrupts(vmx); 7561 7521 } 7562 7522 7523 + static void vmx_load_vmcs01(struct kvm_vcpu *vcpu) 7524 + { 7525 + struct vcpu_vmx *vmx = to_vmx(vcpu); 7526 + int cpu; 7527 + 7528 + if (vmx->loaded_vmcs == &vmx->vmcs01) 7529 + return; 7530 + 7531 + cpu = get_cpu(); 7532 + vmx->loaded_vmcs = &vmx->vmcs01; 7533 + vmx_vcpu_put(vcpu); 7534 + vmx_vcpu_load(vcpu, cpu); 7535 + vcpu->cpu = cpu; 7536 + put_cpu(); 7537 + } 7538 + 7563 7539 static void vmx_free_vcpu(struct kvm_vcpu *vcpu) 7564 7540 { 7565 7541 struct vcpu_vmx *vmx = to_vmx(vcpu); 7566 7542 7567 7543 free_vpid(vmx); 7568 - free_loaded_vmcs(vmx->loaded_vmcs); 7544 + leave_guest_mode(vcpu); 7545 + vmx_load_vmcs01(vcpu); 7569 7546 free_nested(vmx); 7547 + free_loaded_vmcs(vmx->loaded_vmcs); 7570 7548 kfree(vmx->guest_msrs); 7571 7549 kvm_vcpu_uninit(vcpu); 7572 7550 kmem_cache_free(kvm_vcpu_cache, vmx); ··· 7606 7548 goto free_vcpu; 7607 7549 7608 7550 vmx->guest_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL); 7551 + BUILD_BUG_ON(ARRAY_SIZE(vmx_msr_index) * sizeof(vmx->guest_msrs[0]) 7552 + > PAGE_SIZE); 7553 + 7609 7554 err = -ENOMEM; 7610 7555 if (!vmx->guest_msrs) { 7611 7556 goto uninit_vcpu; ··· 7897 7836 vmcs_writel(GUEST_GDTR_BASE, vmcs12->guest_gdtr_base); 7898 7837 vmcs_writel(GUEST_IDTR_BASE, vmcs12->guest_idtr_base); 7899 7838 7900 - vmcs_write64(GUEST_IA32_DEBUGCTL, vmcs12->guest_ia32_debugctl); 7839 + if (vmcs12->vm_entry_controls & VM_ENTRY_LOAD_DEBUG_CONTROLS) { 7840 + kvm_set_dr(vcpu, 7, vmcs12->guest_dr7); 7841 + vmcs_write64(GUEST_IA32_DEBUGCTL, vmcs12->guest_ia32_debugctl); 7842 + } else { 7843 + kvm_set_dr(vcpu, 7, vcpu->arch.dr7); 7844 + vmcs_write64(GUEST_IA32_DEBUGCTL, vmx->nested.vmcs01_debugctl); 7845 + } 7901 7846 vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, 7902 7847 vmcs12->vm_entry_intr_info_field); 7903 7848 vmcs_write32(VM_ENTRY_EXCEPTION_ERROR_CODE, ··· 7913 7846 vmcs_write32(GUEST_INTERRUPTIBILITY_INFO, 7914 7847 vmcs12->guest_interruptibility_info); 7915 7848 vmcs_write32(GUEST_SYSENTER_CS, vmcs12->guest_sysenter_cs); 7916 - kvm_set_dr(vcpu, 7, vmcs12->guest_dr7); 7917 7849 vmx_set_rflags(vcpu, vmcs12->guest_rflags); 7918 7850 vmcs_writel(GUEST_PENDING_DBG_EXCEPTIONS, 7919 7851 vmcs12->guest_pending_dbg_exceptions); ··· 8179 8113 } 8180 8114 8181 8115 if ((vmcs12->cpu_based_vm_exec_control & CPU_BASED_USE_MSR_BITMAPS) && 8182 - !IS_ALIGNED(vmcs12->msr_bitmap, PAGE_SIZE)) { 8116 + !PAGE_ALIGNED(vmcs12->msr_bitmap)) { 8183 8117 /*TODO: Also verify bits beyond physical address width are 0*/ 8184 8118 nested_vmx_failValid(vcpu, VMXERR_ENTRY_INVALID_CONTROL_FIELD); 8185 8119 return 1; 8186 8120 } 8187 8121 8188 8122 if (nested_cpu_has2(vmcs12, SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES) && 8189 - !IS_ALIGNED(vmcs12->apic_access_addr, PAGE_SIZE)) { 8123 + !PAGE_ALIGNED(vmcs12->apic_access_addr)) { 8190 8124 /*TODO: Also verify bits beyond physical address width are 0*/ 8191 8125 nested_vmx_failValid(vcpu, VMXERR_ENTRY_INVALID_CONTROL_FIELD); 8192 8126 return 1; ··· 8202 8136 } 8203 8137 8204 8138 if (!vmx_control_verify(vmcs12->cpu_based_vm_exec_control, 8205 - nested_vmx_procbased_ctls_low, nested_vmx_procbased_ctls_high) || 8139 + nested_vmx_true_procbased_ctls_low, 8140 + nested_vmx_procbased_ctls_high) || 8206 8141 !vmx_control_verify(vmcs12->secondary_vm_exec_control, 8207 8142 nested_vmx_secondary_ctls_low, nested_vmx_secondary_ctls_high) || 8208 8143 !vmx_control_verify(vmcs12->pin_based_vm_exec_control, 8209 8144 nested_vmx_pinbased_ctls_low, nested_vmx_pinbased_ctls_high) || 8210 8145 !vmx_control_verify(vmcs12->vm_exit_controls, 8211 - nested_vmx_exit_ctls_low, nested_vmx_exit_ctls_high) || 8146 + nested_vmx_true_exit_ctls_low, 8147 + nested_vmx_exit_ctls_high) || 8212 8148 !vmx_control_verify(vmcs12->vm_entry_controls, 8213 - nested_vmx_entry_ctls_low, nested_vmx_entry_ctls_high)) 8149 + nested_vmx_true_entry_ctls_low, 8150 + nested_vmx_entry_ctls_high)) 8214 8151 { 8215 8152 nested_vmx_failValid(vcpu, VMXERR_ENTRY_INVALID_CONTROL_FIELD); 8216 8153 return 1; ··· 8289 8220 enter_guest_mode(vcpu); 8290 8221 8291 8222 vmx->nested.vmcs01_tsc_offset = vmcs_read64(TSC_OFFSET); 8223 + 8224 + if (!(vmcs12->vm_entry_controls & VM_ENTRY_LOAD_DEBUG_CONTROLS)) 8225 + vmx->nested.vmcs01_debugctl = vmcs_read64(GUEST_IA32_DEBUGCTL); 8292 8226 8293 8227 cpu = get_cpu(); 8294 8228 vmx->loaded_vmcs = vmcs02; ··· 8470 8398 vmcs12->guest_cr0 = vmcs12_guest_cr0(vcpu, vmcs12); 8471 8399 vmcs12->guest_cr4 = vmcs12_guest_cr4(vcpu, vmcs12); 8472 8400 8473 - kvm_get_dr(vcpu, 7, (unsigned long *)&vmcs12->guest_dr7); 8474 8401 vmcs12->guest_rsp = kvm_register_read(vcpu, VCPU_REGS_RSP); 8475 8402 vmcs12->guest_rip = kvm_register_read(vcpu, VCPU_REGS_RIP); 8476 8403 vmcs12->guest_rflags = vmcs_readl(GUEST_RFLAGS); ··· 8548 8477 (vmcs12->vm_entry_controls & ~VM_ENTRY_IA32E_MODE) | 8549 8478 (vm_entry_controls_get(to_vmx(vcpu)) & VM_ENTRY_IA32E_MODE); 8550 8479 8480 + if (vmcs12->vm_exit_controls & VM_EXIT_SAVE_DEBUG_CONTROLS) { 8481 + kvm_get_dr(vcpu, 7, (unsigned long *)&vmcs12->guest_dr7); 8482 + vmcs12->guest_ia32_debugctl = vmcs_read64(GUEST_IA32_DEBUGCTL); 8483 + } 8484 + 8551 8485 /* TODO: These cannot have changed unless we have MSR bitmaps and 8552 8486 * the relevant bit asks not to trap the change */ 8553 - vmcs12->guest_ia32_debugctl = vmcs_read64(GUEST_IA32_DEBUGCTL); 8554 8487 if (vmcs12->vm_exit_controls & VM_EXIT_SAVE_IA32_PAT) 8555 8488 vmcs12->guest_ia32_pat = vmcs_read64(GUEST_IA32_PAT); 8556 8489 if (vmcs12->vm_exit_controls & VM_EXIT_SAVE_IA32_EFER) ··· 8745 8670 unsigned long exit_qualification) 8746 8671 { 8747 8672 struct vcpu_vmx *vmx = to_vmx(vcpu); 8748 - int cpu; 8749 8673 struct vmcs12 *vmcs12 = get_vmcs12(vcpu); 8750 8674 8751 8675 /* trying to cancel vmlaunch/vmresume is a bug */ ··· 8769 8695 vmcs12->vm_exit_intr_error_code, 8770 8696 KVM_ISA_VMX); 8771 8697 8772 - cpu = get_cpu(); 8773 - vmx->loaded_vmcs = &vmx->vmcs01; 8774 - vmx_vcpu_put(vcpu); 8775 - vmx_vcpu_load(vcpu, cpu); 8776 - vcpu->cpu = cpu; 8777 - put_cpu(); 8698 + vmx_load_vmcs01(vcpu); 8778 8699 8779 8700 vm_entry_controls_init(vmx, vmcs_read32(VM_ENTRY_CONTROLS)); 8780 8701 vm_exit_controls_init(vmx, vmcs_read32(VM_EXIT_CONTROLS)); ··· 8959 8890 8960 8891 rdmsrl_safe(MSR_EFER, &host_efer); 8961 8892 8962 - for (i = 0; i < NR_VMX_MSR; ++i) 8893 + for (i = 0; i < ARRAY_SIZE(vmx_msr_index); ++i) 8963 8894 kvm_define_shared_msr(i, vmx_msr_index[i]); 8964 8895 8965 8896 vmx_io_bitmap_a = (unsigned long *)__get_free_page(GFP_KERNEL);
+123 -48
arch/x86/kvm/x86.c
··· 87 87 88 88 static void update_cr8_intercept(struct kvm_vcpu *vcpu); 89 89 static void process_nmi(struct kvm_vcpu *vcpu); 90 + static void __kvm_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags); 90 91 91 92 struct kvm_x86_ops *kvm_x86_ops; 92 93 EXPORT_SYMBOL_GPL(kvm_x86_ops); ··· 212 211 213 212 void kvm_define_shared_msr(unsigned slot, u32 msr) 214 213 { 214 + BUG_ON(slot >= KVM_NR_SHARED_MSRS); 215 215 if (slot >= shared_msrs_global.nr) 216 216 shared_msrs_global.nr = slot + 1; 217 217 shared_msrs_global.msrs[slot] = msr; ··· 310 308 break; 311 309 } 312 310 return EXCPT_BENIGN; 311 + } 312 + 313 + #define EXCPT_FAULT 0 314 + #define EXCPT_TRAP 1 315 + #define EXCPT_ABORT 2 316 + #define EXCPT_INTERRUPT 3 317 + 318 + static int exception_type(int vector) 319 + { 320 + unsigned int mask; 321 + 322 + if (WARN_ON(vector > 31 || vector == NMI_VECTOR)) 323 + return EXCPT_INTERRUPT; 324 + 325 + mask = 1 << vector; 326 + 327 + /* #DB is trap, as instruction watchpoints are handled elsewhere */ 328 + if (mask & ((1 << DB_VECTOR) | (1 << BP_VECTOR) | (1 << OF_VECTOR))) 329 + return EXCPT_TRAP; 330 + 331 + if (mask & ((1 << DF_VECTOR) | (1 << MC_VECTOR))) 332 + return EXCPT_ABORT; 333 + 334 + /* Reserved exceptions will result in fault */ 335 + return EXCPT_FAULT; 313 336 } 314 337 315 338 static void kvm_multiple_exception(struct kvm_vcpu *vcpu, ··· 785 758 vcpu->arch.switch_db_regs |= KVM_DEBUGREG_BP_ENABLED; 786 759 } 787 760 761 + static u64 kvm_dr6_fixed(struct kvm_vcpu *vcpu) 762 + { 763 + u64 fixed = DR6_FIXED_1; 764 + 765 + if (!guest_cpuid_has_rtm(vcpu)) 766 + fixed |= DR6_RTM; 767 + return fixed; 768 + } 769 + 788 770 static int __kvm_set_dr(struct kvm_vcpu *vcpu, int dr, unsigned long val) 789 771 { 790 772 switch (dr) { ··· 809 773 case 6: 810 774 if (val & 0xffffffff00000000ULL) 811 775 return -1; /* #GP */ 812 - vcpu->arch.dr6 = (val & DR6_VOLATILE) | DR6_FIXED_1; 776 + vcpu->arch.dr6 = (val & DR6_VOLATILE) | kvm_dr6_fixed(vcpu); 813 777 kvm_update_dr6(vcpu); 814 778 break; 815 779 case 5: ··· 1251 1215 unsigned long flags; 1252 1216 s64 usdiff; 1253 1217 bool matched; 1218 + bool already_matched; 1254 1219 u64 data = msr->data; 1255 1220 1256 1221 raw_spin_lock_irqsave(&kvm->arch.tsc_write_lock, flags); ··· 1316 1279 pr_debug("kvm: adjusted tsc offset by %llu\n", delta); 1317 1280 } 1318 1281 matched = true; 1282 + already_matched = (vcpu->arch.this_tsc_generation == kvm->arch.cur_tsc_generation); 1319 1283 } else { 1320 1284 /* 1321 1285 * We split periods of matched TSC writes into generations. ··· 1332 1294 kvm->arch.cur_tsc_write = data; 1333 1295 kvm->arch.cur_tsc_offset = offset; 1334 1296 matched = false; 1335 - pr_debug("kvm: new tsc generation %u, clock %llu\n", 1297 + pr_debug("kvm: new tsc generation %llu, clock %llu\n", 1336 1298 kvm->arch.cur_tsc_generation, data); 1337 1299 } 1338 1300 ··· 1357 1319 raw_spin_unlock_irqrestore(&kvm->arch.tsc_write_lock, flags); 1358 1320 1359 1321 spin_lock(&kvm->arch.pvclock_gtod_sync_lock); 1360 - if (matched) 1361 - kvm->arch.nr_vcpus_matched_tsc++; 1362 - else 1322 + if (!matched) { 1363 1323 kvm->arch.nr_vcpus_matched_tsc = 0; 1324 + } else if (!already_matched) { 1325 + kvm->arch.nr_vcpus_matched_tsc++; 1326 + } 1364 1327 1365 1328 kvm_track_tsc_matching(vcpu); 1366 1329 spin_unlock(&kvm->arch.pvclock_gtod_sync_lock); ··· 2071 2032 data &= ~(u64)0x40; /* ignore flush filter disable */ 2072 2033 data &= ~(u64)0x100; /* ignore ignne emulation enable */ 2073 2034 data &= ~(u64)0x8; /* ignore TLB cache disable */ 2035 + data &= ~(u64)0x40000; /* ignore Mc status write enable */ 2074 2036 if (data != 0) { 2075 2037 vcpu_unimpl(vcpu, "unimplemented HWCR wrmsr: 0x%llx\n", 2076 2038 data); ··· 3014 2974 vcpu->arch.interrupt.pending && !vcpu->arch.interrupt.soft; 3015 2975 events->interrupt.nr = vcpu->arch.interrupt.nr; 3016 2976 events->interrupt.soft = 0; 3017 - events->interrupt.shadow = 3018 - kvm_x86_ops->get_interrupt_shadow(vcpu, 3019 - KVM_X86_SHADOW_INT_MOV_SS | KVM_X86_SHADOW_INT_STI); 2977 + events->interrupt.shadow = kvm_x86_ops->get_interrupt_shadow(vcpu); 3020 2978 3021 2979 events->nmi.injected = vcpu->arch.nmi_injected; 3022 2980 events->nmi.pending = vcpu->arch.nmi_pending != 0; ··· 4120 4082 4121 4083 if (gpa == UNMAPPED_GVA) 4122 4084 return X86EMUL_PROPAGATE_FAULT; 4123 - ret = kvm_read_guest(vcpu->kvm, gpa, data, toread); 4085 + ret = kvm_read_guest_page(vcpu->kvm, gpa >> PAGE_SHIFT, data, 4086 + offset, toread); 4124 4087 if (ret < 0) { 4125 4088 r = X86EMUL_IO_NEEDED; 4126 4089 goto out; ··· 4142 4103 { 4143 4104 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt); 4144 4105 u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0; 4106 + unsigned offset; 4107 + int ret; 4145 4108 4146 - return kvm_read_guest_virt_helper(addr, val, bytes, vcpu, 4147 - access | PFERR_FETCH_MASK, 4148 - exception); 4109 + /* Inline kvm_read_guest_virt_helper for speed. */ 4110 + gpa_t gpa = vcpu->arch.walk_mmu->gva_to_gpa(vcpu, addr, access|PFERR_FETCH_MASK, 4111 + exception); 4112 + if (unlikely(gpa == UNMAPPED_GVA)) 4113 + return X86EMUL_PROPAGATE_FAULT; 4114 + 4115 + offset = addr & (PAGE_SIZE-1); 4116 + if (WARN_ON(offset + bytes > PAGE_SIZE)) 4117 + bytes = (unsigned)PAGE_SIZE - offset; 4118 + ret = kvm_read_guest_page(vcpu->kvm, gpa >> PAGE_SHIFT, val, 4119 + offset, bytes); 4120 + if (unlikely(ret < 0)) 4121 + return X86EMUL_IO_NEEDED; 4122 + 4123 + return X86EMUL_CONTINUE; 4149 4124 } 4150 4125 4151 4126 int kvm_read_guest_virt(struct x86_emulate_ctxt *ctxt, ··· 4783 4730 if (desc->g) 4784 4731 var.limit = (var.limit << 12) | 0xfff; 4785 4732 var.type = desc->type; 4786 - var.present = desc->p; 4787 4733 var.dpl = desc->dpl; 4788 4734 var.db = desc->d; 4789 4735 var.s = desc->s; ··· 4812 4760 msr.index = msr_index; 4813 4761 msr.host_initiated = false; 4814 4762 return kvm_set_msr(emul_to_vcpu(ctxt), &msr); 4763 + } 4764 + 4765 + static int emulator_check_pmc(struct x86_emulate_ctxt *ctxt, 4766 + u32 pmc) 4767 + { 4768 + return kvm_pmu_check_pmc(emul_to_vcpu(ctxt), pmc); 4815 4769 } 4816 4770 4817 4771 static int emulator_read_pmc(struct x86_emulate_ctxt *ctxt, ··· 4896 4838 .set_dr = emulator_set_dr, 4897 4839 .set_msr = emulator_set_msr, 4898 4840 .get_msr = emulator_get_msr, 4841 + .check_pmc = emulator_check_pmc, 4899 4842 .read_pmc = emulator_read_pmc, 4900 4843 .halt = emulator_halt, 4901 4844 .wbinvd = emulator_wbinvd, ··· 4909 4850 4910 4851 static void toggle_interruptibility(struct kvm_vcpu *vcpu, u32 mask) 4911 4852 { 4912 - u32 int_shadow = kvm_x86_ops->get_interrupt_shadow(vcpu, mask); 4853 + u32 int_shadow = kvm_x86_ops->get_interrupt_shadow(vcpu); 4913 4854 /* 4914 4855 * an sti; sti; sequence only disable interrupts for the first 4915 4856 * instruction. So, if the last instruction, be it emulated or ··· 4917 4858 * means that the last instruction is an sti. We should not 4918 4859 * leave the flag on in this case. The same goes for mov ss 4919 4860 */ 4920 - if (!(int_shadow & mask)) 4861 + if (int_shadow & mask) 4862 + mask = 0; 4863 + if (unlikely(int_shadow || mask)) { 4921 4864 kvm_x86_ops->set_interrupt_shadow(vcpu, mask); 4865 + if (!mask) 4866 + kvm_make_request(KVM_REQ_EVENT, vcpu); 4867 + } 4922 4868 } 4923 4869 4924 4870 static void inject_emulated_exception(struct kvm_vcpu *vcpu) ··· 4936 4872 ctxt->exception.error_code); 4937 4873 else 4938 4874 kvm_queue_exception(vcpu, ctxt->exception.vector); 4939 - } 4940 - 4941 - static void init_decode_cache(struct x86_emulate_ctxt *ctxt) 4942 - { 4943 - memset(&ctxt->opcode_len, 0, 4944 - (void *)&ctxt->_regs - (void *)&ctxt->opcode_len); 4945 - 4946 - ctxt->fetch.start = 0; 4947 - ctxt->fetch.end = 0; 4948 - ctxt->io_read.pos = 0; 4949 - ctxt->io_read.end = 0; 4950 - ctxt->mem_read.pos = 0; 4951 - ctxt->mem_read.end = 0; 4952 4875 } 4953 4876 4954 4877 static void init_emulate_ctxt(struct kvm_vcpu *vcpu) ··· 5136 5085 return dr6; 5137 5086 } 5138 5087 5139 - static void kvm_vcpu_check_singlestep(struct kvm_vcpu *vcpu, int *r) 5088 + static void kvm_vcpu_check_singlestep(struct kvm_vcpu *vcpu, unsigned long rflags, int *r) 5140 5089 { 5141 5090 struct kvm_run *kvm_run = vcpu->run; 5142 5091 5143 5092 /* 5144 - * Use the "raw" value to see if TF was passed to the processor. 5145 - * Note that the new value of the flags has not been saved yet. 5093 + * rflags is the old, "raw" value of the flags. The new value has 5094 + * not been saved yet. 5146 5095 * 5147 5096 * This is correct even for TF set by the guest, because "the 5148 5097 * processor will not generate this exception after the instruction 5149 5098 * that sets the TF flag". 5150 5099 */ 5151 - unsigned long rflags = kvm_x86_ops->get_rflags(vcpu); 5152 - 5153 5100 if (unlikely(rflags & X86_EFLAGS_TF)) { 5154 5101 if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) { 5155 - kvm_run->debug.arch.dr6 = DR6_BS | DR6_FIXED_1; 5102 + kvm_run->debug.arch.dr6 = DR6_BS | DR6_FIXED_1 | 5103 + DR6_RTM; 5156 5104 kvm_run->debug.arch.pc = vcpu->arch.singlestep_rip; 5157 5105 kvm_run->debug.arch.exception = DB_VECTOR; 5158 5106 kvm_run->exit_reason = KVM_EXIT_DEBUG; ··· 5164 5114 * cleared by the processor". 5165 5115 */ 5166 5116 vcpu->arch.dr6 &= ~15; 5167 - vcpu->arch.dr6 |= DR6_BS; 5117 + vcpu->arch.dr6 |= DR6_BS | DR6_RTM; 5168 5118 kvm_queue_exception(vcpu, DB_VECTOR); 5169 5119 } 5170 5120 } ··· 5183 5133 vcpu->arch.eff_db); 5184 5134 5185 5135 if (dr6 != 0) { 5186 - kvm_run->debug.arch.dr6 = dr6 | DR6_FIXED_1; 5136 + kvm_run->debug.arch.dr6 = dr6 | DR6_FIXED_1 | DR6_RTM; 5187 5137 kvm_run->debug.arch.pc = kvm_rip_read(vcpu) + 5188 5138 get_segment_base(vcpu, VCPU_SREG_CS); 5189 5139 ··· 5194 5144 } 5195 5145 } 5196 5146 5197 - if (unlikely(vcpu->arch.dr7 & DR7_BP_EN_MASK)) { 5147 + if (unlikely(vcpu->arch.dr7 & DR7_BP_EN_MASK) && 5148 + !(kvm_get_rflags(vcpu) & X86_EFLAGS_RF)) { 5198 5149 dr6 = kvm_vcpu_check_hw_bp(eip, 0, 5199 5150 vcpu->arch.dr7, 5200 5151 vcpu->arch.db); 5201 5152 5202 5153 if (dr6 != 0) { 5203 5154 vcpu->arch.dr6 &= ~15; 5204 - vcpu->arch.dr6 |= dr6; 5155 + vcpu->arch.dr6 |= dr6 | DR6_RTM; 5205 5156 kvm_queue_exception(vcpu, DB_VECTOR); 5206 5157 *r = EMULATE_DONE; 5207 5158 return true; ··· 5266 5215 5267 5216 if (emulation_type & EMULTYPE_SKIP) { 5268 5217 kvm_rip_write(vcpu, ctxt->_eip); 5218 + if (ctxt->eflags & X86_EFLAGS_RF) 5219 + kvm_set_rflags(vcpu, ctxt->eflags & ~X86_EFLAGS_RF); 5269 5220 return EMULATE_DONE; 5270 5221 } 5271 5222 ··· 5318 5265 r = EMULATE_DONE; 5319 5266 5320 5267 if (writeback) { 5268 + unsigned long rflags = kvm_x86_ops->get_rflags(vcpu); 5321 5269 toggle_interruptibility(vcpu, ctxt->interruptibility); 5322 - kvm_make_request(KVM_REQ_EVENT, vcpu); 5323 5270 vcpu->arch.emulate_regs_need_sync_to_vcpu = false; 5324 5271 kvm_rip_write(vcpu, ctxt->eip); 5325 5272 if (r == EMULATE_DONE) 5326 - kvm_vcpu_check_singlestep(vcpu, &r); 5327 - kvm_set_rflags(vcpu, ctxt->eflags); 5273 + kvm_vcpu_check_singlestep(vcpu, rflags, &r); 5274 + __kvm_set_rflags(vcpu, ctxt->eflags); 5275 + 5276 + /* 5277 + * For STI, interrupts are shadowed; so KVM_REQ_EVENT will 5278 + * do nothing, and it will be requested again as soon as 5279 + * the shadow expires. But we still need to check here, 5280 + * because POPF has no interrupt shadow. 5281 + */ 5282 + if (unlikely((ctxt->eflags & ~rflags) & X86_EFLAGS_IF)) 5283 + kvm_make_request(KVM_REQ_EVENT, vcpu); 5328 5284 } else 5329 5285 vcpu->arch.emulate_regs_need_sync_to_vcpu = true; 5330 5286 ··· 5724 5662 u64 param, ingpa, outgpa, ret; 5725 5663 uint16_t code, rep_idx, rep_cnt, res = HV_STATUS_SUCCESS, rep_done = 0; 5726 5664 bool fast, longmode; 5727 - int cs_db, cs_l; 5728 5665 5729 5666 /* 5730 5667 * hypercall generates UD from non zero cpl and real mode ··· 5734 5673 return 0; 5735 5674 } 5736 5675 5737 - kvm_x86_ops->get_cs_db_l_bits(vcpu, &cs_db, &cs_l); 5738 - longmode = is_long_mode(vcpu) && cs_l == 1; 5676 + longmode = is_64_bit_mode(vcpu); 5739 5677 5740 5678 if (!longmode) { 5741 5679 param = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDX) << 32) | ··· 5799 5739 int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) 5800 5740 { 5801 5741 unsigned long nr, a0, a1, a2, a3, ret; 5802 - int r = 1; 5742 + int op_64_bit, r = 1; 5803 5743 5804 5744 if (kvm_hv_hypercall_enabled(vcpu->kvm)) 5805 5745 return kvm_hv_hypercall(vcpu); ··· 5812 5752 5813 5753 trace_kvm_hypercall(nr, a0, a1, a2, a3); 5814 5754 5815 - if (!is_long_mode(vcpu)) { 5755 + op_64_bit = is_64_bit_mode(vcpu); 5756 + if (!op_64_bit) { 5816 5757 nr &= 0xFFFFFFFF; 5817 5758 a0 &= 0xFFFFFFFF; 5818 5759 a1 &= 0xFFFFFFFF; ··· 5839 5778 break; 5840 5779 } 5841 5780 out: 5781 + if (!op_64_bit) 5782 + ret = (u32)ret; 5842 5783 kvm_register_write(vcpu, VCPU_REGS_RAX, ret); 5843 5784 ++vcpu->stat.hypercalls; 5844 5785 return r; ··· 5919 5856 trace_kvm_inj_exception(vcpu->arch.exception.nr, 5920 5857 vcpu->arch.exception.has_error_code, 5921 5858 vcpu->arch.exception.error_code); 5859 + 5860 + if (exception_type(vcpu->arch.exception.nr) == EXCPT_FAULT) 5861 + __kvm_set_rflags(vcpu, kvm_get_rflags(vcpu) | 5862 + X86_EFLAGS_RF); 5863 + 5922 5864 kvm_x86_ops->queue_exception(vcpu, vcpu->arch.exception.nr, 5923 5865 vcpu->arch.exception.has_error_code, 5924 5866 vcpu->arch.exception.error_code, ··· 6915 6847 atomic_set(&vcpu->arch.nmi_queued, 0); 6916 6848 vcpu->arch.nmi_pending = 0; 6917 6849 vcpu->arch.nmi_injected = false; 6850 + kvm_clear_interrupt_queue(vcpu); 6851 + kvm_clear_exception_queue(vcpu); 6918 6852 6919 6853 memset(vcpu->arch.db, 0, sizeof(vcpu->arch.db)); 6920 - vcpu->arch.dr6 = DR6_FIXED_1; 6854 + vcpu->arch.dr6 = DR6_INIT; 6921 6855 kvm_update_dr6(vcpu); 6922 6856 vcpu->arch.dr7 = DR7_FIXED_1; 6923 6857 kvm_update_dr7(vcpu); ··· 7475 7405 } 7476 7406 EXPORT_SYMBOL_GPL(kvm_get_rflags); 7477 7407 7478 - void kvm_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags) 7408 + static void __kvm_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags) 7479 7409 { 7480 7410 if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP && 7481 7411 kvm_is_linear_rip(vcpu, vcpu->arch.singlestep_rip)) 7482 7412 rflags |= X86_EFLAGS_TF; 7483 7413 kvm_x86_ops->set_rflags(vcpu, rflags); 7414 + } 7415 + 7416 + void kvm_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags) 7417 + { 7418 + __kvm_set_rflags(vcpu, rflags); 7484 7419 kvm_make_request(KVM_REQ_EVENT, vcpu); 7485 7420 } 7486 7421 EXPORT_SYMBOL_GPL(kvm_set_rflags);
+27
arch/x86/kvm/x86.h
··· 47 47 #endif 48 48 } 49 49 50 + static inline bool is_64_bit_mode(struct kvm_vcpu *vcpu) 51 + { 52 + int cs_db, cs_l; 53 + 54 + if (!is_long_mode(vcpu)) 55 + return false; 56 + kvm_x86_ops->get_cs_db_l_bits(vcpu, &cs_db, &cs_l); 57 + return cs_l; 58 + } 59 + 50 60 static inline bool mmu_is_nested(struct kvm_vcpu *vcpu) 51 61 { 52 62 return vcpu->arch.walk_mmu == &vcpu->arch.nested_mmu; ··· 116 106 return true; 117 107 118 108 return false; 109 + } 110 + 111 + static inline unsigned long kvm_register_readl(struct kvm_vcpu *vcpu, 112 + enum kvm_reg reg) 113 + { 114 + unsigned long val = kvm_register_read(vcpu, reg); 115 + 116 + return is_64_bit_mode(vcpu) ? val : (u32)val; 117 + } 118 + 119 + static inline void kvm_register_writel(struct kvm_vcpu *vcpu, 120 + enum kvm_reg reg, 121 + unsigned long val) 122 + { 123 + if (!is_64_bit_mode(vcpu)) 124 + val = (u32)val; 125 + return kvm_register_write(vcpu, reg, val); 119 126 } 120 127 121 128 void kvm_before_handle_nmi(struct kvm_vcpu *vcpu);
+6 -1
include/uapi/linux/kvm.h
··· 399 399 __u64 vapic_addr; 400 400 }; 401 401 402 - /* for KVM_SET_MPSTATE */ 402 + /* for KVM_SET_MP_STATE */ 403 403 404 + /* not all states are valid on all architectures */ 404 405 #define KVM_MP_STATE_RUNNABLE 0 405 406 #define KVM_MP_STATE_UNINITIALIZED 1 406 407 #define KVM_MP_STATE_INIT_RECEIVED 2 407 408 #define KVM_MP_STATE_HALTED 3 408 409 #define KVM_MP_STATE_SIPI_RECEIVED 4 410 + #define KVM_MP_STATE_STOPPED 5 411 + #define KVM_MP_STATE_CHECK_STOP 6 412 + #define KVM_MP_STATE_OPERATING 7 413 + #define KVM_MP_STATE_LOAD 8 409 414 410 415 struct kvm_mp_state { 411 416 __u32 mp_state;
+3 -4
virt/kvm/ioapic.c
··· 254 254 spin_lock(&ioapic->lock); 255 255 for (index = 0; index < IOAPIC_NUM_PINS; index++) { 256 256 e = &ioapic->redirtbl[index]; 257 - if (!e->fields.mask && 258 - (e->fields.trig_mode == IOAPIC_LEVEL_TRIG || 259 - kvm_irq_has_notifier(ioapic->kvm, KVM_IRQCHIP_IOAPIC, 260 - index) || index == RTC_GSI)) { 257 + if (e->fields.trig_mode == IOAPIC_LEVEL_TRIG || 258 + kvm_irq_has_notifier(ioapic->kvm, KVM_IRQCHIP_IOAPIC, index) || 259 + index == RTC_GSI) { 261 260 if (kvm_apic_match_dest(vcpu, NULL, 0, 262 261 e->fields.dest_id, e->fields.dest_mode)) { 263 262 __set_bit(e->fields.vector,
+2 -2
virt/kvm/irq_comm.c
··· 323 323 324 324 #define IOAPIC_ROUTING_ENTRY(irq) \ 325 325 { .gsi = irq, .type = KVM_IRQ_ROUTING_IRQCHIP, \ 326 - .u.irqchip.irqchip = KVM_IRQCHIP_IOAPIC, .u.irqchip.pin = (irq) } 326 + .u.irqchip = { .irqchip = KVM_IRQCHIP_IOAPIC, .pin = (irq) } } 327 327 #define ROUTING_ENTRY1(irq) IOAPIC_ROUTING_ENTRY(irq) 328 328 329 329 #ifdef CONFIG_X86 330 330 # define PIC_ROUTING_ENTRY(irq) \ 331 331 { .gsi = irq, .type = KVM_IRQ_ROUTING_IRQCHIP, \ 332 - .u.irqchip.irqchip = SELECT_PIC(irq), .u.irqchip.pin = (irq) % 8 } 332 + .u.irqchip = { .irqchip = SELECT_PIC(irq), .pin = (irq) % 8 } } 333 333 # define ROUTING_ENTRY2(irq) \ 334 334 IOAPIC_ROUTING_ENTRY(irq), PIC_ROUTING_ENTRY(irq) 335 335 #else