hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/arch/mips/kvm/emulate.c
....@@ -15,7 +15,7 @@
1515 #include <linux/kvm_host.h>
1616 #include <linux/vmalloc.h>
1717 #include <linux/fs.h>
18
-#include <linux/bootmem.h>
18
+#include <linux/memblock.h>
1919 #include <linux/random.h>
2020 #include <asm/page.h>
2121 #include <asm/cacheflush.h>
....@@ -64,7 +64,7 @@
6464 switch (insn.r_format.func) {
6565 case jalr_op:
6666 arch->gprs[insn.r_format.rd] = epc + 8;
67
- /* Fall through */
67
+ fallthrough;
6868 case jr_op:
6969 nextpc = arch->gprs[insn.r_format.rs];
7070 break;
....@@ -140,6 +140,7 @@
140140 /* These are unconditional and in j_format. */
141141 case jal_op:
142142 arch->gprs[31] = instpc + 8;
143
+ fallthrough;
143144 case j_op:
144145 epc += 4;
145146 epc >>= 28;
....@@ -1016,10 +1017,10 @@
10161017 */
10171018 preempt_disable();
10181019 cpu = smp_processor_id();
1019
- get_new_mmu_context(kern_mm, cpu);
1020
+ get_new_mmu_context(kern_mm);
10201021 for_each_possible_cpu(i)
10211022 if (i != cpu)
1022
- cpu_context(i, kern_mm) = 0;
1023
+ set_cpu_context(i, kern_mm, 0);
10231024 preempt_enable();
10241025 }
10251026 kvm_write_c0_guest_entryhi(cop0, entryhi);
....@@ -1090,8 +1091,8 @@
10901091 if (i == cpu)
10911092 continue;
10921093 if (user)
1093
- cpu_context(i, user_mm) = 0;
1094
- cpu_context(i, kern_mm) = 0;
1094
+ set_cpu_context(i, user_mm, 0);
1095
+ set_cpu_context(i, kern_mm, 0);
10951096 }
10961097
10971098 preempt_enable();
....@@ -1141,9 +1142,7 @@
11411142 unsigned long pc = vcpu->arch.pc;
11421143 int index;
11431144
1144
- get_random_bytes(&index, sizeof(index));
1145
- index &= (KVM_MIPS_GUEST_TLB_SIZE - 1);
1146
-
1145
+ index = prandom_u32_max(KVM_MIPS_GUEST_TLB_SIZE);
11471146 tlb = &vcpu->arch.guest_tlb[index];
11481147
11491148 kvm_mips_invalidate_guest_tlb(vcpu, tlb);
....@@ -1263,7 +1262,6 @@
12631262
12641263 enum emulation_result kvm_mips_emulate_CP0(union mips_instruction inst,
12651264 u32 *opc, u32 cause,
1266
- struct kvm_run *run,
12671265 struct kvm_vcpu *vcpu)
12681266 {
12691267 struct mips_coproc *cop0 = vcpu->arch.cop0;
....@@ -1598,12 +1596,14 @@
15981596
15991597 enum emulation_result kvm_mips_emulate_store(union mips_instruction inst,
16001598 u32 cause,
1601
- struct kvm_run *run,
16021599 struct kvm_vcpu *vcpu)
16031600 {
1601
+ int r;
16041602 enum emulation_result er;
16051603 u32 rt;
1604
+ struct kvm_run *run = vcpu->run;
16061605 void *data = run->mmio.data;
1606
+ unsigned int imme;
16071607 unsigned long curr_pc;
16081608
16091609 /*
....@@ -1661,15 +1661,231 @@
16611661 vcpu->arch.gprs[rt], *(u8 *)data);
16621662 break;
16631663
1664
+ case swl_op:
1665
+ run->mmio.phys_addr = kvm_mips_callbacks->gva_to_gpa(
1666
+ vcpu->arch.host_cp0_badvaddr) & (~0x3);
1667
+ run->mmio.len = 4;
1668
+ imme = vcpu->arch.host_cp0_badvaddr & 0x3;
1669
+ switch (imme) {
1670
+ case 0:
1671
+ *(u32 *)data = ((*(u32 *)data) & 0xffffff00) |
1672
+ (vcpu->arch.gprs[rt] >> 24);
1673
+ break;
1674
+ case 1:
1675
+ *(u32 *)data = ((*(u32 *)data) & 0xffff0000) |
1676
+ (vcpu->arch.gprs[rt] >> 16);
1677
+ break;
1678
+ case 2:
1679
+ *(u32 *)data = ((*(u32 *)data) & 0xff000000) |
1680
+ (vcpu->arch.gprs[rt] >> 8);
1681
+ break;
1682
+ case 3:
1683
+ *(u32 *)data = vcpu->arch.gprs[rt];
1684
+ break;
1685
+ default:
1686
+ break;
1687
+ }
1688
+
1689
+ kvm_debug("[%#lx] OP_SWL: eaddr: %#lx, gpr: %#lx, data: %#x\n",
1690
+ vcpu->arch.pc, vcpu->arch.host_cp0_badvaddr,
1691
+ vcpu->arch.gprs[rt], *(u32 *)data);
1692
+ break;
1693
+
1694
+ case swr_op:
1695
+ run->mmio.phys_addr = kvm_mips_callbacks->gva_to_gpa(
1696
+ vcpu->arch.host_cp0_badvaddr) & (~0x3);
1697
+ run->mmio.len = 4;
1698
+ imme = vcpu->arch.host_cp0_badvaddr & 0x3;
1699
+ switch (imme) {
1700
+ case 0:
1701
+ *(u32 *)data = vcpu->arch.gprs[rt];
1702
+ break;
1703
+ case 1:
1704
+ *(u32 *)data = ((*(u32 *)data) & 0xff) |
1705
+ (vcpu->arch.gprs[rt] << 8);
1706
+ break;
1707
+ case 2:
1708
+ *(u32 *)data = ((*(u32 *)data) & 0xffff) |
1709
+ (vcpu->arch.gprs[rt] << 16);
1710
+ break;
1711
+ case 3:
1712
+ *(u32 *)data = ((*(u32 *)data) & 0xffffff) |
1713
+ (vcpu->arch.gprs[rt] << 24);
1714
+ break;
1715
+ default:
1716
+ break;
1717
+ }
1718
+
1719
+ kvm_debug("[%#lx] OP_SWR: eaddr: %#lx, gpr: %#lx, data: %#x\n",
1720
+ vcpu->arch.pc, vcpu->arch.host_cp0_badvaddr,
1721
+ vcpu->arch.gprs[rt], *(u32 *)data);
1722
+ break;
1723
+
1724
+#if defined(CONFIG_64BIT) && defined(CONFIG_KVM_MIPS_VZ)
1725
+ case sdl_op:
1726
+ run->mmio.phys_addr = kvm_mips_callbacks->gva_to_gpa(
1727
+ vcpu->arch.host_cp0_badvaddr) & (~0x7);
1728
+
1729
+ run->mmio.len = 8;
1730
+ imme = vcpu->arch.host_cp0_badvaddr & 0x7;
1731
+ switch (imme) {
1732
+ case 0:
1733
+ *(u64 *)data = ((*(u64 *)data) & 0xffffffffffffff00) |
1734
+ ((vcpu->arch.gprs[rt] >> 56) & 0xff);
1735
+ break;
1736
+ case 1:
1737
+ *(u64 *)data = ((*(u64 *)data) & 0xffffffffffff0000) |
1738
+ ((vcpu->arch.gprs[rt] >> 48) & 0xffff);
1739
+ break;
1740
+ case 2:
1741
+ *(u64 *)data = ((*(u64 *)data) & 0xffffffffff000000) |
1742
+ ((vcpu->arch.gprs[rt] >> 40) & 0xffffff);
1743
+ break;
1744
+ case 3:
1745
+ *(u64 *)data = ((*(u64 *)data) & 0xffffffff00000000) |
1746
+ ((vcpu->arch.gprs[rt] >> 32) & 0xffffffff);
1747
+ break;
1748
+ case 4:
1749
+ *(u64 *)data = ((*(u64 *)data) & 0xffffff0000000000) |
1750
+ ((vcpu->arch.gprs[rt] >> 24) & 0xffffffffff);
1751
+ break;
1752
+ case 5:
1753
+ *(u64 *)data = ((*(u64 *)data) & 0xffff000000000000) |
1754
+ ((vcpu->arch.gprs[rt] >> 16) & 0xffffffffffff);
1755
+ break;
1756
+ case 6:
1757
+ *(u64 *)data = ((*(u64 *)data) & 0xff00000000000000) |
1758
+ ((vcpu->arch.gprs[rt] >> 8) & 0xffffffffffffff);
1759
+ break;
1760
+ case 7:
1761
+ *(u64 *)data = vcpu->arch.gprs[rt];
1762
+ break;
1763
+ default:
1764
+ break;
1765
+ }
1766
+
1767
+ kvm_debug("[%#lx] OP_SDL: eaddr: %#lx, gpr: %#lx, data: %llx\n",
1768
+ vcpu->arch.pc, vcpu->arch.host_cp0_badvaddr,
1769
+ vcpu->arch.gprs[rt], *(u64 *)data);
1770
+ break;
1771
+
1772
+ case sdr_op:
1773
+ run->mmio.phys_addr = kvm_mips_callbacks->gva_to_gpa(
1774
+ vcpu->arch.host_cp0_badvaddr) & (~0x7);
1775
+
1776
+ run->mmio.len = 8;
1777
+ imme = vcpu->arch.host_cp0_badvaddr & 0x7;
1778
+ switch (imme) {
1779
+ case 0:
1780
+ *(u64 *)data = vcpu->arch.gprs[rt];
1781
+ break;
1782
+ case 1:
1783
+ *(u64 *)data = ((*(u64 *)data) & 0xff) |
1784
+ (vcpu->arch.gprs[rt] << 8);
1785
+ break;
1786
+ case 2:
1787
+ *(u64 *)data = ((*(u64 *)data) & 0xffff) |
1788
+ (vcpu->arch.gprs[rt] << 16);
1789
+ break;
1790
+ case 3:
1791
+ *(u64 *)data = ((*(u64 *)data) & 0xffffff) |
1792
+ (vcpu->arch.gprs[rt] << 24);
1793
+ break;
1794
+ case 4:
1795
+ *(u64 *)data = ((*(u64 *)data) & 0xffffffff) |
1796
+ (vcpu->arch.gprs[rt] << 32);
1797
+ break;
1798
+ case 5:
1799
+ *(u64 *)data = ((*(u64 *)data) & 0xffffffffff) |
1800
+ (vcpu->arch.gprs[rt] << 40);
1801
+ break;
1802
+ case 6:
1803
+ *(u64 *)data = ((*(u64 *)data) & 0xffffffffffff) |
1804
+ (vcpu->arch.gprs[rt] << 48);
1805
+ break;
1806
+ case 7:
1807
+ *(u64 *)data = ((*(u64 *)data) & 0xffffffffffffff) |
1808
+ (vcpu->arch.gprs[rt] << 56);
1809
+ break;
1810
+ default:
1811
+ break;
1812
+ }
1813
+
1814
+ kvm_debug("[%#lx] OP_SDR: eaddr: %#lx, gpr: %#lx, data: %llx\n",
1815
+ vcpu->arch.pc, vcpu->arch.host_cp0_badvaddr,
1816
+ vcpu->arch.gprs[rt], *(u64 *)data);
1817
+ break;
1818
+#endif
1819
+
1820
+#ifdef CONFIG_CPU_LOONGSON64
1821
+ case sdc2_op:
1822
+ rt = inst.loongson3_lsdc2_format.rt;
1823
+ switch (inst.loongson3_lsdc2_format.opcode1) {
1824
+ /*
1825
+ * Loongson-3 overridden sdc2 instructions.
1826
+ * opcode1 instruction
1827
+ * 0x0 gssbx: store 1 bytes from GPR
1828
+ * 0x1 gsshx: store 2 bytes from GPR
1829
+ * 0x2 gsswx: store 4 bytes from GPR
1830
+ * 0x3 gssdx: store 8 bytes from GPR
1831
+ */
1832
+ case 0x0:
1833
+ run->mmio.len = 1;
1834
+ *(u8 *)data = vcpu->arch.gprs[rt];
1835
+
1836
+ kvm_debug("[%#lx] OP_GSSBX: eaddr: %#lx, gpr: %#lx, data: %#x\n",
1837
+ vcpu->arch.pc, vcpu->arch.host_cp0_badvaddr,
1838
+ vcpu->arch.gprs[rt], *(u8 *)data);
1839
+ break;
1840
+ case 0x1:
1841
+ run->mmio.len = 2;
1842
+ *(u16 *)data = vcpu->arch.gprs[rt];
1843
+
1844
+ kvm_debug("[%#lx] OP_GSSSHX: eaddr: %#lx, gpr: %#lx, data: %#x\n",
1845
+ vcpu->arch.pc, vcpu->arch.host_cp0_badvaddr,
1846
+ vcpu->arch.gprs[rt], *(u16 *)data);
1847
+ break;
1848
+ case 0x2:
1849
+ run->mmio.len = 4;
1850
+ *(u32 *)data = vcpu->arch.gprs[rt];
1851
+
1852
+ kvm_debug("[%#lx] OP_GSSWX: eaddr: %#lx, gpr: %#lx, data: %#x\n",
1853
+ vcpu->arch.pc, vcpu->arch.host_cp0_badvaddr,
1854
+ vcpu->arch.gprs[rt], *(u32 *)data);
1855
+ break;
1856
+ case 0x3:
1857
+ run->mmio.len = 8;
1858
+ *(u64 *)data = vcpu->arch.gprs[rt];
1859
+
1860
+ kvm_debug("[%#lx] OP_GSSDX: eaddr: %#lx, gpr: %#lx, data: %#llx\n",
1861
+ vcpu->arch.pc, vcpu->arch.host_cp0_badvaddr,
1862
+ vcpu->arch.gprs[rt], *(u64 *)data);
1863
+ break;
1864
+ default:
1865
+ kvm_err("Godson Extended GS-Store not yet supported (inst=0x%08x)\n",
1866
+ inst.word);
1867
+ break;
1868
+ }
1869
+ break;
1870
+#endif
16641871 default:
16651872 kvm_err("Store not yet supported (inst=0x%08x)\n",
16661873 inst.word);
16671874 goto out_fail;
16681875 }
16691876
1670
- run->mmio.is_write = 1;
16711877 vcpu->mmio_needed = 1;
1878
+ run->mmio.is_write = 1;
16721879 vcpu->mmio_is_write = 1;
1880
+
1881
+ r = kvm_io_bus_write(vcpu, KVM_MMIO_BUS,
1882
+ run->mmio.phys_addr, run->mmio.len, data);
1883
+
1884
+ if (!r) {
1885
+ vcpu->mmio_needed = 0;
1886
+ return EMULATE_DONE;
1887
+ }
1888
+
16731889 return EMULATE_DO_MMIO;
16741890
16751891 out_fail:
....@@ -1679,12 +1895,14 @@
16791895 }
16801896
16811897 enum emulation_result kvm_mips_emulate_load(union mips_instruction inst,
1682
- u32 cause, struct kvm_run *run,
1683
- struct kvm_vcpu *vcpu)
1898
+ u32 cause, struct kvm_vcpu *vcpu)
16841899 {
1900
+ struct kvm_run *run = vcpu->run;
1901
+ int r;
16851902 enum emulation_result er;
16861903 unsigned long curr_pc;
16871904 u32 op, rt;
1905
+ unsigned int imme;
16881906
16891907 rt = inst.i_format.rt;
16901908 op = inst.i_format.opcode;
....@@ -1717,7 +1935,7 @@
17171935
17181936 case lwu_op:
17191937 vcpu->mmio_needed = 1; /* unsigned */
1720
- /* fall through */
1938
+ fallthrough;
17211939 #endif
17221940 case lw_op:
17231941 run->mmio.len = 4;
....@@ -1725,17 +1943,175 @@
17251943
17261944 case lhu_op:
17271945 vcpu->mmio_needed = 1; /* unsigned */
1728
- /* fall through */
1946
+ fallthrough;
17291947 case lh_op:
17301948 run->mmio.len = 2;
17311949 break;
17321950
17331951 case lbu_op:
17341952 vcpu->mmio_needed = 1; /* unsigned */
1735
- /* fall through */
1953
+ fallthrough;
17361954 case lb_op:
17371955 run->mmio.len = 1;
17381956 break;
1957
+
1958
+ case lwl_op:
1959
+ run->mmio.phys_addr = kvm_mips_callbacks->gva_to_gpa(
1960
+ vcpu->arch.host_cp0_badvaddr) & (~0x3);
1961
+
1962
+ run->mmio.len = 4;
1963
+ imme = vcpu->arch.host_cp0_badvaddr & 0x3;
1964
+ switch (imme) {
1965
+ case 0:
1966
+ vcpu->mmio_needed = 3; /* 1 byte */
1967
+ break;
1968
+ case 1:
1969
+ vcpu->mmio_needed = 4; /* 2 bytes */
1970
+ break;
1971
+ case 2:
1972
+ vcpu->mmio_needed = 5; /* 3 bytes */
1973
+ break;
1974
+ case 3:
1975
+ vcpu->mmio_needed = 6; /* 4 bytes */
1976
+ break;
1977
+ default:
1978
+ break;
1979
+ }
1980
+ break;
1981
+
1982
+ case lwr_op:
1983
+ run->mmio.phys_addr = kvm_mips_callbacks->gva_to_gpa(
1984
+ vcpu->arch.host_cp0_badvaddr) & (~0x3);
1985
+
1986
+ run->mmio.len = 4;
1987
+ imme = vcpu->arch.host_cp0_badvaddr & 0x3;
1988
+ switch (imme) {
1989
+ case 0:
1990
+ vcpu->mmio_needed = 7; /* 4 bytes */
1991
+ break;
1992
+ case 1:
1993
+ vcpu->mmio_needed = 8; /* 3 bytes */
1994
+ break;
1995
+ case 2:
1996
+ vcpu->mmio_needed = 9; /* 2 bytes */
1997
+ break;
1998
+ case 3:
1999
+ vcpu->mmio_needed = 10; /* 1 byte */
2000
+ break;
2001
+ default:
2002
+ break;
2003
+ }
2004
+ break;
2005
+
2006
+#if defined(CONFIG_64BIT) && defined(CONFIG_KVM_MIPS_VZ)
2007
+ case ldl_op:
2008
+ run->mmio.phys_addr = kvm_mips_callbacks->gva_to_gpa(
2009
+ vcpu->arch.host_cp0_badvaddr) & (~0x7);
2010
+
2011
+ run->mmio.len = 8;
2012
+ imme = vcpu->arch.host_cp0_badvaddr & 0x7;
2013
+ switch (imme) {
2014
+ case 0:
2015
+ vcpu->mmio_needed = 11; /* 1 byte */
2016
+ break;
2017
+ case 1:
2018
+ vcpu->mmio_needed = 12; /* 2 bytes */
2019
+ break;
2020
+ case 2:
2021
+ vcpu->mmio_needed = 13; /* 3 bytes */
2022
+ break;
2023
+ case 3:
2024
+ vcpu->mmio_needed = 14; /* 4 bytes */
2025
+ break;
2026
+ case 4:
2027
+ vcpu->mmio_needed = 15; /* 5 bytes */
2028
+ break;
2029
+ case 5:
2030
+ vcpu->mmio_needed = 16; /* 6 bytes */
2031
+ break;
2032
+ case 6:
2033
+ vcpu->mmio_needed = 17; /* 7 bytes */
2034
+ break;
2035
+ case 7:
2036
+ vcpu->mmio_needed = 18; /* 8 bytes */
2037
+ break;
2038
+ default:
2039
+ break;
2040
+ }
2041
+ break;
2042
+
2043
+ case ldr_op:
2044
+ run->mmio.phys_addr = kvm_mips_callbacks->gva_to_gpa(
2045
+ vcpu->arch.host_cp0_badvaddr) & (~0x7);
2046
+
2047
+ run->mmio.len = 8;
2048
+ imme = vcpu->arch.host_cp0_badvaddr & 0x7;
2049
+ switch (imme) {
2050
+ case 0:
2051
+ vcpu->mmio_needed = 19; /* 8 bytes */
2052
+ break;
2053
+ case 1:
2054
+ vcpu->mmio_needed = 20; /* 7 bytes */
2055
+ break;
2056
+ case 2:
2057
+ vcpu->mmio_needed = 21; /* 6 bytes */
2058
+ break;
2059
+ case 3:
2060
+ vcpu->mmio_needed = 22; /* 5 bytes */
2061
+ break;
2062
+ case 4:
2063
+ vcpu->mmio_needed = 23; /* 4 bytes */
2064
+ break;
2065
+ case 5:
2066
+ vcpu->mmio_needed = 24; /* 3 bytes */
2067
+ break;
2068
+ case 6:
2069
+ vcpu->mmio_needed = 25; /* 2 bytes */
2070
+ break;
2071
+ case 7:
2072
+ vcpu->mmio_needed = 26; /* 1 byte */
2073
+ break;
2074
+ default:
2075
+ break;
2076
+ }
2077
+ break;
2078
+#endif
2079
+
2080
+#ifdef CONFIG_CPU_LOONGSON64
2081
+ case ldc2_op:
2082
+ rt = inst.loongson3_lsdc2_format.rt;
2083
+ switch (inst.loongson3_lsdc2_format.opcode1) {
2084
+ /*
2085
+ * Loongson-3 overridden ldc2 instructions.
2086
+ * opcode1 instruction
2087
+ * 0x0 gslbx: store 1 bytes from GPR
2088
+ * 0x1 gslhx: store 2 bytes from GPR
2089
+ * 0x2 gslwx: store 4 bytes from GPR
2090
+ * 0x3 gsldx: store 8 bytes from GPR
2091
+ */
2092
+ case 0x0:
2093
+ run->mmio.len = 1;
2094
+ vcpu->mmio_needed = 27; /* signed */
2095
+ break;
2096
+ case 0x1:
2097
+ run->mmio.len = 2;
2098
+ vcpu->mmio_needed = 28; /* signed */
2099
+ break;
2100
+ case 0x2:
2101
+ run->mmio.len = 4;
2102
+ vcpu->mmio_needed = 29; /* signed */
2103
+ break;
2104
+ case 0x3:
2105
+ run->mmio.len = 8;
2106
+ vcpu->mmio_needed = 30; /* signed */
2107
+ break;
2108
+ default:
2109
+ kvm_err("Godson Extended GS-Load for float not yet supported (inst=0x%08x)\n",
2110
+ inst.word);
2111
+ break;
2112
+ }
2113
+ break;
2114
+#endif
17392115
17402116 default:
17412117 kvm_err("Load not yet supported (inst=0x%08x)\n",
....@@ -1746,6 +2122,16 @@
17462122
17472123 run->mmio.is_write = 0;
17482124 vcpu->mmio_is_write = 0;
2125
+
2126
+ r = kvm_io_bus_read(vcpu, KVM_MMIO_BUS,
2127
+ run->mmio.phys_addr, run->mmio.len, run->mmio.data);
2128
+
2129
+ if (!r) {
2130
+ kvm_mips_complete_mmio_load(vcpu);
2131
+ vcpu->mmio_needed = 0;
2132
+ return EMULATE_DONE;
2133
+ }
2134
+
17492135 return EMULATE_DO_MMIO;
17502136 }
17512137
....@@ -1753,7 +2139,6 @@
17532139 static enum emulation_result kvm_mips_guest_cache_op(int (*fn)(unsigned long),
17542140 unsigned long curr_pc,
17552141 unsigned long addr,
1756
- struct kvm_run *run,
17572142 struct kvm_vcpu *vcpu,
17582143 u32 cause)
17592144 {
....@@ -1781,23 +2166,22 @@
17812166 /* no matching guest TLB */
17822167 vcpu->arch.host_cp0_badvaddr = addr;
17832168 vcpu->arch.pc = curr_pc;
1784
- kvm_mips_emulate_tlbmiss_ld(cause, NULL, run, vcpu);
2169
+ kvm_mips_emulate_tlbmiss_ld(cause, NULL, vcpu);
17852170 return EMULATE_EXCEPT;
17862171 case KVM_MIPS_TLBINV:
17872172 /* invalid matching guest TLB */
17882173 vcpu->arch.host_cp0_badvaddr = addr;
17892174 vcpu->arch.pc = curr_pc;
1790
- kvm_mips_emulate_tlbinv_ld(cause, NULL, run, vcpu);
2175
+ kvm_mips_emulate_tlbinv_ld(cause, NULL, vcpu);
17912176 return EMULATE_EXCEPT;
17922177 default:
17932178 break;
1794
- };
2179
+ }
17952180 }
17962181 }
17972182
17982183 enum emulation_result kvm_mips_emulate_cache(union mips_instruction inst,
17992184 u32 *opc, u32 cause,
1800
- struct kvm_run *run,
18012185 struct kvm_vcpu *vcpu)
18022186 {
18032187 enum emulation_result er = EMULATE_DONE;
....@@ -1887,7 +2271,7 @@
18872271 * guest's behalf.
18882272 */
18892273 er = kvm_mips_guest_cache_op(protected_writeback_dcache_line,
1890
- curr_pc, va, run, vcpu, cause);
2274
+ curr_pc, va, vcpu, cause);
18912275 if (er != EMULATE_DONE)
18922276 goto done;
18932277 #ifdef CONFIG_KVM_MIPS_DYN_TRANS
....@@ -1900,11 +2284,11 @@
19002284 } else if (op_inst == Hit_Invalidate_I) {
19012285 /* Perform the icache synchronisation on the guest's behalf */
19022286 er = kvm_mips_guest_cache_op(protected_writeback_dcache_line,
1903
- curr_pc, va, run, vcpu, cause);
2287
+ curr_pc, va, vcpu, cause);
19042288 if (er != EMULATE_DONE)
19052289 goto done;
19062290 er = kvm_mips_guest_cache_op(protected_flush_icache_line,
1907
- curr_pc, va, run, vcpu, cause);
2291
+ curr_pc, va, vcpu, cause);
19082292 if (er != EMULATE_DONE)
19092293 goto done;
19102294
....@@ -1930,7 +2314,6 @@
19302314 }
19312315
19322316 enum emulation_result kvm_mips_emulate_inst(u32 cause, u32 *opc,
1933
- struct kvm_run *run,
19342317 struct kvm_vcpu *vcpu)
19352318 {
19362319 union mips_instruction inst;
....@@ -1946,14 +2329,14 @@
19462329
19472330 switch (inst.r_format.opcode) {
19482331 case cop0_op:
1949
- er = kvm_mips_emulate_CP0(inst, opc, cause, run, vcpu);
2332
+ er = kvm_mips_emulate_CP0(inst, opc, cause, vcpu);
19502333 break;
19512334
19522335 #ifndef CONFIG_CPU_MIPSR6
19532336 case cache_op:
19542337 ++vcpu->stat.cache_exits;
19552338 trace_kvm_exit(vcpu, KVM_TRACE_EXIT_CACHE);
1956
- er = kvm_mips_emulate_cache(inst, opc, cause, run, vcpu);
2339
+ er = kvm_mips_emulate_cache(inst, opc, cause, vcpu);
19572340 break;
19582341 #else
19592342 case spec3_op:
....@@ -1961,12 +2344,12 @@
19612344 case cache6_op:
19622345 ++vcpu->stat.cache_exits;
19632346 trace_kvm_exit(vcpu, KVM_TRACE_EXIT_CACHE);
1964
- er = kvm_mips_emulate_cache(inst, opc, cause, run,
2347
+ er = kvm_mips_emulate_cache(inst, opc, cause,
19652348 vcpu);
19662349 break;
19672350 default:
19682351 goto unknown;
1969
- };
2352
+ }
19702353 break;
19712354 unknown:
19722355 #endif
....@@ -2001,7 +2384,6 @@
20012384
20022385 enum emulation_result kvm_mips_emulate_syscall(u32 cause,
20032386 u32 *opc,
2004
- struct kvm_run *run,
20052387 struct kvm_vcpu *vcpu)
20062388 {
20072389 struct mips_coproc *cop0 = vcpu->arch.cop0;
....@@ -2036,7 +2418,6 @@
20362418
20372419 enum emulation_result kvm_mips_emulate_tlbmiss_ld(u32 cause,
20382420 u32 *opc,
2039
- struct kvm_run *run,
20402421 struct kvm_vcpu *vcpu)
20412422 {
20422423 struct mips_coproc *cop0 = vcpu->arch.cop0;
....@@ -2080,7 +2461,6 @@
20802461
20812462 enum emulation_result kvm_mips_emulate_tlbinv_ld(u32 cause,
20822463 u32 *opc,
2083
- struct kvm_run *run,
20842464 struct kvm_vcpu *vcpu)
20852465 {
20862466 struct mips_coproc *cop0 = vcpu->arch.cop0;
....@@ -2122,7 +2502,6 @@
21222502
21232503 enum emulation_result kvm_mips_emulate_tlbmiss_st(u32 cause,
21242504 u32 *opc,
2125
- struct kvm_run *run,
21262505 struct kvm_vcpu *vcpu)
21272506 {
21282507 struct mips_coproc *cop0 = vcpu->arch.cop0;
....@@ -2164,7 +2543,6 @@
21642543
21652544 enum emulation_result kvm_mips_emulate_tlbinv_st(u32 cause,
21662545 u32 *opc,
2167
- struct kvm_run *run,
21682546 struct kvm_vcpu *vcpu)
21692547 {
21702548 struct mips_coproc *cop0 = vcpu->arch.cop0;
....@@ -2205,7 +2583,6 @@
22052583
22062584 enum emulation_result kvm_mips_emulate_tlbmod(u32 cause,
22072585 u32 *opc,
2208
- struct kvm_run *run,
22092586 struct kvm_vcpu *vcpu)
22102587 {
22112588 struct mips_coproc *cop0 = vcpu->arch.cop0;
....@@ -2245,7 +2622,6 @@
22452622
22462623 enum emulation_result kvm_mips_emulate_fpu_exc(u32 cause,
22472624 u32 *opc,
2248
- struct kvm_run *run,
22492625 struct kvm_vcpu *vcpu)
22502626 {
22512627 struct mips_coproc *cop0 = vcpu->arch.cop0;
....@@ -2274,7 +2650,6 @@
22742650
22752651 enum emulation_result kvm_mips_emulate_ri_exc(u32 cause,
22762652 u32 *opc,
2277
- struct kvm_run *run,
22782653 struct kvm_vcpu *vcpu)
22792654 {
22802655 struct mips_coproc *cop0 = vcpu->arch.cop0;
....@@ -2309,7 +2684,6 @@
23092684
23102685 enum emulation_result kvm_mips_emulate_bp_exc(u32 cause,
23112686 u32 *opc,
2312
- struct kvm_run *run,
23132687 struct kvm_vcpu *vcpu)
23142688 {
23152689 struct mips_coproc *cop0 = vcpu->arch.cop0;
....@@ -2344,7 +2718,6 @@
23442718
23452719 enum emulation_result kvm_mips_emulate_trap_exc(u32 cause,
23462720 u32 *opc,
2347
- struct kvm_run *run,
23482721 struct kvm_vcpu *vcpu)
23492722 {
23502723 struct mips_coproc *cop0 = vcpu->arch.cop0;
....@@ -2379,7 +2752,6 @@
23792752
23802753 enum emulation_result kvm_mips_emulate_msafpe_exc(u32 cause,
23812754 u32 *opc,
2382
- struct kvm_run *run,
23832755 struct kvm_vcpu *vcpu)
23842756 {
23852757 struct mips_coproc *cop0 = vcpu->arch.cop0;
....@@ -2414,7 +2786,6 @@
24142786
24152787 enum emulation_result kvm_mips_emulate_fpe_exc(u32 cause,
24162788 u32 *opc,
2417
- struct kvm_run *run,
24182789 struct kvm_vcpu *vcpu)
24192790 {
24202791 struct mips_coproc *cop0 = vcpu->arch.cop0;
....@@ -2449,7 +2820,6 @@
24492820
24502821 enum emulation_result kvm_mips_emulate_msadis_exc(u32 cause,
24512822 u32 *opc,
2452
- struct kvm_run *run,
24532823 struct kvm_vcpu *vcpu)
24542824 {
24552825 struct mips_coproc *cop0 = vcpu->arch.cop0;
....@@ -2483,7 +2853,6 @@
24832853 }
24842854
24852855 enum emulation_result kvm_mips_handle_ri(u32 cause, u32 *opc,
2486
- struct kvm_run *run,
24872856 struct kvm_vcpu *vcpu)
24882857 {
24892858 struct mips_coproc *cop0 = vcpu->arch.cop0;
....@@ -2572,12 +2941,12 @@
25722941 * branch target), and pass the RI exception to the guest OS.
25732942 */
25742943 vcpu->arch.pc = curr_pc;
2575
- return kvm_mips_emulate_ri_exc(cause, opc, run, vcpu);
2944
+ return kvm_mips_emulate_ri_exc(cause, opc, vcpu);
25762945 }
25772946
2578
-enum emulation_result kvm_mips_complete_mmio_load(struct kvm_vcpu *vcpu,
2579
- struct kvm_run *run)
2947
+enum emulation_result kvm_mips_complete_mmio_load(struct kvm_vcpu *vcpu)
25802948 {
2949
+ struct kvm_run *run = vcpu->run;
25812950 unsigned long *gpr = &vcpu->arch.gprs[vcpu->arch.io_gpr];
25822951 enum emulation_result er = EMULATE_DONE;
25832952
....@@ -2592,28 +2961,125 @@
25922961
25932962 switch (run->mmio.len) {
25942963 case 8:
2595
- *gpr = *(s64 *)run->mmio.data;
2964
+ switch (vcpu->mmio_needed) {
2965
+ case 11:
2966
+ *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffffffffffffff) |
2967
+ (((*(s64 *)run->mmio.data) & 0xff) << 56);
2968
+ break;
2969
+ case 12:
2970
+ *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffffffffffff) |
2971
+ (((*(s64 *)run->mmio.data) & 0xffff) << 48);
2972
+ break;
2973
+ case 13:
2974
+ *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffffffffff) |
2975
+ (((*(s64 *)run->mmio.data) & 0xffffff) << 40);
2976
+ break;
2977
+ case 14:
2978
+ *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffffffff) |
2979
+ (((*(s64 *)run->mmio.data) & 0xffffffff) << 32);
2980
+ break;
2981
+ case 15:
2982
+ *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffffff) |
2983
+ (((*(s64 *)run->mmio.data) & 0xffffffffff) << 24);
2984
+ break;
2985
+ case 16:
2986
+ *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffff) |
2987
+ (((*(s64 *)run->mmio.data) & 0xffffffffffff) << 16);
2988
+ break;
2989
+ case 17:
2990
+ *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xff) |
2991
+ (((*(s64 *)run->mmio.data) & 0xffffffffffffff) << 8);
2992
+ break;
2993
+ case 18:
2994
+ case 19:
2995
+ *gpr = *(s64 *)run->mmio.data;
2996
+ break;
2997
+ case 20:
2998
+ *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xff00000000000000) |
2999
+ ((((*(s64 *)run->mmio.data)) >> 8) & 0xffffffffffffff);
3000
+ break;
3001
+ case 21:
3002
+ *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffff000000000000) |
3003
+ ((((*(s64 *)run->mmio.data)) >> 16) & 0xffffffffffff);
3004
+ break;
3005
+ case 22:
3006
+ *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffffff0000000000) |
3007
+ ((((*(s64 *)run->mmio.data)) >> 24) & 0xffffffffff);
3008
+ break;
3009
+ case 23:
3010
+ *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffffffff00000000) |
3011
+ ((((*(s64 *)run->mmio.data)) >> 32) & 0xffffffff);
3012
+ break;
3013
+ case 24:
3014
+ *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffffffffff000000) |
3015
+ ((((*(s64 *)run->mmio.data)) >> 40) & 0xffffff);
3016
+ break;
3017
+ case 25:
3018
+ *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffffffffffff0000) |
3019
+ ((((*(s64 *)run->mmio.data)) >> 48) & 0xffff);
3020
+ break;
3021
+ case 26:
3022
+ *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffffffffffffff00) |
3023
+ ((((*(s64 *)run->mmio.data)) >> 56) & 0xff);
3024
+ break;
3025
+ default:
3026
+ *gpr = *(s64 *)run->mmio.data;
3027
+ }
25963028 break;
25973029
25983030 case 4:
2599
- if (vcpu->mmio_needed == 2)
2600
- *gpr = *(s32 *)run->mmio.data;
2601
- else
3031
+ switch (vcpu->mmio_needed) {
3032
+ case 1:
26023033 *gpr = *(u32 *)run->mmio.data;
3034
+ break;
3035
+ case 2:
3036
+ *gpr = *(s32 *)run->mmio.data;
3037
+ break;
3038
+ case 3:
3039
+ *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffffff) |
3040
+ (((*(s32 *)run->mmio.data) & 0xff) << 24);
3041
+ break;
3042
+ case 4:
3043
+ *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffff) |
3044
+ (((*(s32 *)run->mmio.data) & 0xffff) << 16);
3045
+ break;
3046
+ case 5:
3047
+ *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xff) |
3048
+ (((*(s32 *)run->mmio.data) & 0xffffff) << 8);
3049
+ break;
3050
+ case 6:
3051
+ case 7:
3052
+ *gpr = *(s32 *)run->mmio.data;
3053
+ break;
3054
+ case 8:
3055
+ *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xff000000) |
3056
+ ((((*(s32 *)run->mmio.data)) >> 8) & 0xffffff);
3057
+ break;
3058
+ case 9:
3059
+ *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffff0000) |
3060
+ ((((*(s32 *)run->mmio.data)) >> 16) & 0xffff);
3061
+ break;
3062
+ case 10:
3063
+ *gpr = (vcpu->arch.gprs[vcpu->arch.io_gpr] & 0xffffff00) |
3064
+ ((((*(s32 *)run->mmio.data)) >> 24) & 0xff);
3065
+ break;
3066
+ default:
3067
+ *gpr = *(s32 *)run->mmio.data;
3068
+ }
26033069 break;
26043070
26053071 case 2:
2606
- if (vcpu->mmio_needed == 2)
2607
- *gpr = *(s16 *) run->mmio.data;
2608
- else
3072
+ if (vcpu->mmio_needed == 1)
26093073 *gpr = *(u16 *)run->mmio.data;
3074
+ else
3075
+ *gpr = *(s16 *)run->mmio.data;
26103076
26113077 break;
26123078 case 1:
2613
- if (vcpu->mmio_needed == 2)
2614
- *gpr = *(s8 *) run->mmio.data;
3079
+ if (vcpu->mmio_needed == 1)
3080
+ *gpr = *(u8 *)run->mmio.data;
26153081 else
2616
- *gpr = *(u8 *) run->mmio.data;
3082
+ *gpr = *(s8 *)run->mmio.data;
26173083 break;
26183084 }
26193085
....@@ -2623,7 +3089,6 @@
26233089
26243090 static enum emulation_result kvm_mips_emulate_exc(u32 cause,
26253091 u32 *opc,
2626
- struct kvm_run *run,
26273092 struct kvm_vcpu *vcpu)
26283093 {
26293094 u32 exccode = (cause >> CAUSEB_EXCCODE) & 0x1f;
....@@ -2661,7 +3126,6 @@
26613126
26623127 enum emulation_result kvm_mips_check_privilege(u32 cause,
26633128 u32 *opc,
2664
- struct kvm_run *run,
26653129 struct kvm_vcpu *vcpu)
26663130 {
26673131 enum emulation_result er = EMULATE_DONE;
....@@ -2743,7 +3207,7 @@
27433207 }
27443208
27453209 if (er == EMULATE_PRIV_FAIL)
2746
- kvm_mips_emulate_exc(cause, opc, run, vcpu);
3210
+ kvm_mips_emulate_exc(cause, opc, vcpu);
27473211
27483212 return er;
27493213 }
....@@ -2757,7 +3221,6 @@
27573221 */
27583222 enum emulation_result kvm_mips_handle_tlbmiss(u32 cause,
27593223 u32 *opc,
2760
- struct kvm_run *run,
27613224 struct kvm_vcpu *vcpu,
27623225 bool write_fault)
27633226 {
....@@ -2781,9 +3244,9 @@
27813244 KVM_ENTRYHI_ASID));
27823245 if (index < 0) {
27833246 if (exccode == EXCCODE_TLBL) {
2784
- er = kvm_mips_emulate_tlbmiss_ld(cause, opc, run, vcpu);
3247
+ er = kvm_mips_emulate_tlbmiss_ld(cause, opc, vcpu);
27853248 } else if (exccode == EXCCODE_TLBS) {
2786
- er = kvm_mips_emulate_tlbmiss_st(cause, opc, run, vcpu);
3249
+ er = kvm_mips_emulate_tlbmiss_st(cause, opc, vcpu);
27873250 } else {
27883251 kvm_err("%s: invalid exc code: %d\n", __func__,
27893252 exccode);
....@@ -2798,10 +3261,10 @@
27983261 */
27993262 if (!TLB_IS_VALID(*tlb, va)) {
28003263 if (exccode == EXCCODE_TLBL) {
2801
- er = kvm_mips_emulate_tlbinv_ld(cause, opc, run,
3264
+ er = kvm_mips_emulate_tlbinv_ld(cause, opc,
28023265 vcpu);
28033266 } else if (exccode == EXCCODE_TLBS) {
2804
- er = kvm_mips_emulate_tlbinv_st(cause, opc, run,
3267
+ er = kvm_mips_emulate_tlbinv_st(cause, opc,
28053268 vcpu);
28063269 } else {
28073270 kvm_err("%s: invalid exc code: %d\n", __func__,