book3s_64_vio_hv.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License, version 2, as
  4. * published by the Free Software Foundation.
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. * GNU General Public License for more details.
  10. *
  11. * You should have received a copy of the GNU General Public License
  12. * along with this program; if not, write to the Free Software
  13. * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  14. *
  15. * Copyright 2010 Paul Mackerras, IBM Corp. <paulus@au1.ibm.com>
  16. * Copyright 2011 David Gibson, IBM Corporation <dwg@au1.ibm.com>
  17. * Copyright 2016 Alexey Kardashevskiy, IBM Corporation <aik@au1.ibm.com>
  18. */
  19. #include <linux/types.h>
  20. #include <linux/string.h>
  21. #include <linux/kvm.h>
  22. #include <linux/kvm_host.h>
  23. #include <linux/highmem.h>
  24. #include <linux/gfp.h>
  25. #include <linux/slab.h>
  26. #include <linux/hugetlb.h>
  27. #include <linux/list.h>
  28. #include <asm/tlbflush.h>
  29. #include <asm/kvm_ppc.h>
  30. #include <asm/kvm_book3s.h>
  31. #include <asm/book3s/64/mmu-hash.h>
  32. #include <asm/mmu_context.h>
  33. #include <asm/hvcall.h>
  34. #include <asm/synch.h>
  35. #include <asm/ppc-opcode.h>
  36. #include <asm/kvm_host.h>
  37. #include <asm/udbg.h>
  38. #include <asm/iommu.h>
  39. #include <asm/tce.h>
  40. #include <asm/pte-walk.h>
  41. #ifdef CONFIG_BUG
  42. #define WARN_ON_ONCE_RM(condition) ({ \
  43. static bool __section(.data.unlikely) __warned; \
  44. int __ret_warn_once = !!(condition); \
  45. \
  46. if (unlikely(__ret_warn_once && !__warned)) { \
  47. __warned = true; \
  48. pr_err("WARN_ON_ONCE_RM: (%s) at %s:%u\n", \
  49. __stringify(condition), \
  50. __func__, __LINE__); \
  51. dump_stack(); \
  52. } \
  53. unlikely(__ret_warn_once); \
  54. })
  55. #else
  56. #define WARN_ON_ONCE_RM(condition) ({ \
  57. int __ret_warn_on = !!(condition); \
  58. unlikely(__ret_warn_on); \
  59. })
  60. #endif
  61. #define TCES_PER_PAGE (PAGE_SIZE / sizeof(u64))
  62. /*
  63. * Finds a TCE table descriptor by LIOBN.
  64. *
  65. * WARNING: This will be called in real or virtual mode on HV KVM and virtual
  66. * mode on PR KVM
  67. */
  68. struct kvmppc_spapr_tce_table *kvmppc_find_table(struct kvm *kvm,
  69. unsigned long liobn)
  70. {
  71. struct kvmppc_spapr_tce_table *stt;
  72. list_for_each_entry_lockless(stt, &kvm->arch.spapr_tce_tables, list)
  73. if (stt->liobn == liobn)
  74. return stt;
  75. return NULL;
  76. }
  77. EXPORT_SYMBOL_GPL(kvmppc_find_table);
  78. /*
  79. * Validates TCE address.
  80. * At the moment flags and page mask are validated.
  81. * As the host kernel does not access those addresses (just puts them
  82. * to the table and user space is supposed to process them), we can skip
  83. * checking other things (such as TCE is a guest RAM address or the page
  84. * was actually allocated).
  85. *
  86. * WARNING: This will be called in real-mode on HV KVM and virtual
  87. * mode on PR KVM
  88. */
  89. long kvmppc_tce_validate(struct kvmppc_spapr_tce_table *stt, unsigned long tce)
  90. {
  91. unsigned long gpa = tce & ~(TCE_PCI_READ | TCE_PCI_WRITE);
  92. enum dma_data_direction dir = iommu_tce_direction(tce);
  93. /* Allow userspace to poison TCE table */
  94. if (dir == DMA_NONE)
  95. return H_SUCCESS;
  96. if (iommu_tce_check_gpa(stt->page_shift, gpa))
  97. return H_PARAMETER;
  98. return H_SUCCESS;
  99. }
  100. EXPORT_SYMBOL_GPL(kvmppc_tce_validate);
  101. /* Note on the use of page_address() in real mode,
  102. *
  103. * It is safe to use page_address() in real mode on ppc64 because
  104. * page_address() is always defined as lowmem_page_address()
  105. * which returns __va(PFN_PHYS(page_to_pfn(page))) which is arithmetic
  106. * operation and does not access page struct.
  107. *
  108. * Theoretically page_address() could be defined different
  109. * but either WANT_PAGE_VIRTUAL or HASHED_PAGE_VIRTUAL
  110. * would have to be enabled.
  111. * WANT_PAGE_VIRTUAL is never enabled on ppc32/ppc64,
  112. * HASHED_PAGE_VIRTUAL could be enabled for ppc32 only and only
  113. * if CONFIG_HIGHMEM is defined. As CONFIG_SPARSEMEM_VMEMMAP
  114. * is not expected to be enabled on ppc32, page_address()
  115. * is safe for ppc32 as well.
  116. *
  117. * WARNING: This will be called in real-mode on HV KVM and virtual
  118. * mode on PR KVM
  119. */
  120. static u64 *kvmppc_page_address(struct page *page)
  121. {
  122. #if defined(HASHED_PAGE_VIRTUAL) || defined(WANT_PAGE_VIRTUAL)
  123. #error TODO: fix to avoid page_address() here
  124. #endif
  125. return (u64 *) page_address(page);
  126. }
  127. /*
  128. * Handles TCE requests for emulated devices.
  129. * Puts guest TCE values to the table and expects user space to convert them.
  130. * Called in both real and virtual modes.
  131. * Cannot fail so kvmppc_tce_validate must be called before it.
  132. *
  133. * WARNING: This will be called in real-mode on HV KVM and virtual
  134. * mode on PR KVM
  135. */
  136. void kvmppc_tce_put(struct kvmppc_spapr_tce_table *stt,
  137. unsigned long idx, unsigned long tce)
  138. {
  139. struct page *page;
  140. u64 *tbl;
  141. idx -= stt->offset;
  142. page = stt->pages[idx / TCES_PER_PAGE];
  143. tbl = kvmppc_page_address(page);
  144. tbl[idx % TCES_PER_PAGE] = tce;
  145. }
  146. EXPORT_SYMBOL_GPL(kvmppc_tce_put);
  147. long kvmppc_gpa_to_ua(struct kvm *kvm, unsigned long gpa,
  148. unsigned long *ua, unsigned long **prmap)
  149. {
  150. unsigned long gfn = gpa >> PAGE_SHIFT;
  151. struct kvm_memory_slot *memslot;
  152. memslot = search_memslots(kvm_memslots(kvm), gfn);
  153. if (!memslot)
  154. return -EINVAL;
  155. *ua = __gfn_to_hva_memslot(memslot, gfn) |
  156. (gpa & ~(PAGE_MASK | TCE_PCI_READ | TCE_PCI_WRITE));
  157. #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  158. if (prmap)
  159. *prmap = &memslot->arch.rmap[gfn - memslot->base_gfn];
  160. #endif
  161. return 0;
  162. }
  163. EXPORT_SYMBOL_GPL(kvmppc_gpa_to_ua);
  164. #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  165. static void kvmppc_rm_clear_tce(struct iommu_table *tbl, unsigned long entry)
  166. {
  167. unsigned long hpa = 0;
  168. enum dma_data_direction dir = DMA_NONE;
  169. iommu_tce_xchg_rm(tbl, entry, &hpa, &dir);
  170. }
  171. static long kvmppc_rm_tce_iommu_mapped_dec(struct kvm *kvm,
  172. struct iommu_table *tbl, unsigned long entry)
  173. {
  174. struct mm_iommu_table_group_mem_t *mem = NULL;
  175. const unsigned long pgsize = 1ULL << tbl->it_page_shift;
  176. unsigned long *pua = IOMMU_TABLE_USERSPACE_ENTRY(tbl, entry);
  177. if (!pua)
  178. /* it_userspace allocation might be delayed */
  179. return H_TOO_HARD;
  180. pua = (void *) vmalloc_to_phys(pua);
  181. if (WARN_ON_ONCE_RM(!pua))
  182. return H_HARDWARE;
  183. mem = mm_iommu_lookup_rm(kvm->mm, *pua, pgsize);
  184. if (!mem)
  185. return H_TOO_HARD;
  186. mm_iommu_mapped_dec(mem);
  187. *pua = 0;
  188. return H_SUCCESS;
  189. }
  190. static long kvmppc_rm_tce_iommu_do_unmap(struct kvm *kvm,
  191. struct iommu_table *tbl, unsigned long entry)
  192. {
  193. enum dma_data_direction dir = DMA_NONE;
  194. unsigned long hpa = 0;
  195. long ret;
  196. if (iommu_tce_xchg_rm(tbl, entry, &hpa, &dir))
  197. /*
  198. * real mode xchg can fail if struct page crosses
  199. * a page boundary
  200. */
  201. return H_TOO_HARD;
  202. if (dir == DMA_NONE)
  203. return H_SUCCESS;
  204. ret = kvmppc_rm_tce_iommu_mapped_dec(kvm, tbl, entry);
  205. if (ret)
  206. iommu_tce_xchg_rm(tbl, entry, &hpa, &dir);
  207. return ret;
  208. }
  209. static long kvmppc_rm_tce_iommu_unmap(struct kvm *kvm,
  210. struct kvmppc_spapr_tce_table *stt, struct iommu_table *tbl,
  211. unsigned long entry)
  212. {
  213. unsigned long i, ret = H_SUCCESS;
  214. unsigned long subpages = 1ULL << (stt->page_shift - tbl->it_page_shift);
  215. unsigned long io_entry = entry * subpages;
  216. for (i = 0; i < subpages; ++i) {
  217. ret = kvmppc_rm_tce_iommu_do_unmap(kvm, tbl, io_entry + i);
  218. if (ret != H_SUCCESS)
  219. break;
  220. }
  221. return ret;
  222. }
  223. static long kvmppc_rm_tce_iommu_do_map(struct kvm *kvm, struct iommu_table *tbl,
  224. unsigned long entry, unsigned long ua,
  225. enum dma_data_direction dir)
  226. {
  227. long ret;
  228. unsigned long hpa = 0;
  229. unsigned long *pua = IOMMU_TABLE_USERSPACE_ENTRY(tbl, entry);
  230. struct mm_iommu_table_group_mem_t *mem;
  231. if (!pua)
  232. /* it_userspace allocation might be delayed */
  233. return H_TOO_HARD;
  234. mem = mm_iommu_lookup_rm(kvm->mm, ua, 1ULL << tbl->it_page_shift);
  235. if (!mem)
  236. return H_TOO_HARD;
  237. if (WARN_ON_ONCE_RM(mm_iommu_ua_to_hpa_rm(mem, ua, &hpa)))
  238. return H_HARDWARE;
  239. pua = (void *) vmalloc_to_phys(pua);
  240. if (WARN_ON_ONCE_RM(!pua))
  241. return H_HARDWARE;
  242. if (WARN_ON_ONCE_RM(mm_iommu_mapped_inc(mem)))
  243. return H_CLOSED;
  244. ret = iommu_tce_xchg_rm(tbl, entry, &hpa, &dir);
  245. if (ret) {
  246. mm_iommu_mapped_dec(mem);
  247. /*
  248. * real mode xchg can fail if struct page crosses
  249. * a page boundary
  250. */
  251. return H_TOO_HARD;
  252. }
  253. if (dir != DMA_NONE)
  254. kvmppc_rm_tce_iommu_mapped_dec(kvm, tbl, entry);
  255. *pua = ua;
  256. return 0;
  257. }
  258. static long kvmppc_rm_tce_iommu_map(struct kvm *kvm,
  259. struct kvmppc_spapr_tce_table *stt, struct iommu_table *tbl,
  260. unsigned long entry, unsigned long ua,
  261. enum dma_data_direction dir)
  262. {
  263. unsigned long i, pgoff, ret = H_SUCCESS;
  264. unsigned long subpages = 1ULL << (stt->page_shift - tbl->it_page_shift);
  265. unsigned long io_entry = entry * subpages;
  266. for (i = 0, pgoff = 0; i < subpages;
  267. ++i, pgoff += IOMMU_PAGE_SIZE(tbl)) {
  268. ret = kvmppc_rm_tce_iommu_do_map(kvm, tbl,
  269. io_entry + i, ua + pgoff, dir);
  270. if (ret != H_SUCCESS)
  271. break;
  272. }
  273. return ret;
  274. }
  275. long kvmppc_rm_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
  276. unsigned long ioba, unsigned long tce)
  277. {
  278. struct kvmppc_spapr_tce_table *stt;
  279. long ret;
  280. struct kvmppc_spapr_tce_iommu_table *stit;
  281. unsigned long entry, ua = 0;
  282. enum dma_data_direction dir;
  283. /* udbg_printf("H_PUT_TCE(): liobn=0x%lx ioba=0x%lx, tce=0x%lx\n", */
  284. /* liobn, ioba, tce); */
  285. /* For radix, we might be in virtual mode, so punt */
  286. if (kvm_is_radix(vcpu->kvm))
  287. return H_TOO_HARD;
  288. stt = kvmppc_find_table(vcpu->kvm, liobn);
  289. if (!stt)
  290. return H_TOO_HARD;
  291. ret = kvmppc_ioba_validate(stt, ioba, 1);
  292. if (ret != H_SUCCESS)
  293. return ret;
  294. ret = kvmppc_tce_validate(stt, tce);
  295. if (ret != H_SUCCESS)
  296. return ret;
  297. dir = iommu_tce_direction(tce);
  298. if ((dir != DMA_NONE) && kvmppc_gpa_to_ua(vcpu->kvm,
  299. tce & ~(TCE_PCI_READ | TCE_PCI_WRITE), &ua, NULL))
  300. return H_PARAMETER;
  301. entry = ioba >> stt->page_shift;
  302. list_for_each_entry_lockless(stit, &stt->iommu_tables, next) {
  303. if (dir == DMA_NONE)
  304. ret = kvmppc_rm_tce_iommu_unmap(vcpu->kvm, stt,
  305. stit->tbl, entry);
  306. else
  307. ret = kvmppc_rm_tce_iommu_map(vcpu->kvm, stt,
  308. stit->tbl, entry, ua, dir);
  309. if (ret == H_SUCCESS)
  310. continue;
  311. if (ret == H_TOO_HARD)
  312. return ret;
  313. WARN_ON_ONCE_RM(1);
  314. kvmppc_rm_clear_tce(stit->tbl, entry);
  315. }
  316. kvmppc_tce_put(stt, entry, tce);
  317. return H_SUCCESS;
  318. }
  319. static long kvmppc_rm_ua_to_hpa(struct kvm_vcpu *vcpu,
  320. unsigned long ua, unsigned long *phpa)
  321. {
  322. pte_t *ptep, pte;
  323. unsigned shift = 0;
  324. /*
  325. * Called in real mode with MSR_EE = 0. We are safe here.
  326. * It is ok to do the lookup with arch.pgdir here, because
  327. * we are doing this on secondary cpus and current task there
  328. * is not the hypervisor. Also this is safe against THP in the
  329. * host, because an IPI to primary thread will wait for the secondary
  330. * to exit which will agains result in the below page table walk
  331. * to finish.
  332. */
  333. ptep = __find_linux_pte(vcpu->arch.pgdir, ua, NULL, &shift);
  334. if (!ptep || !pte_present(*ptep))
  335. return -ENXIO;
  336. pte = *ptep;
  337. if (!shift)
  338. shift = PAGE_SHIFT;
  339. /* Avoid handling anything potentially complicated in realmode */
  340. if (shift > PAGE_SHIFT)
  341. return -EAGAIN;
  342. if (!pte_young(pte))
  343. return -EAGAIN;
  344. *phpa = (pte_pfn(pte) << PAGE_SHIFT) | (ua & ((1ULL << shift) - 1)) |
  345. (ua & ~PAGE_MASK);
  346. return 0;
  347. }
  348. long kvmppc_rm_h_put_tce_indirect(struct kvm_vcpu *vcpu,
  349. unsigned long liobn, unsigned long ioba,
  350. unsigned long tce_list, unsigned long npages)
  351. {
  352. struct kvmppc_spapr_tce_table *stt;
  353. long i, ret = H_SUCCESS;
  354. unsigned long tces, entry, ua = 0;
  355. unsigned long *rmap = NULL;
  356. bool prereg = false;
  357. struct kvmppc_spapr_tce_iommu_table *stit;
  358. /* For radix, we might be in virtual mode, so punt */
  359. if (kvm_is_radix(vcpu->kvm))
  360. return H_TOO_HARD;
  361. stt = kvmppc_find_table(vcpu->kvm, liobn);
  362. if (!stt)
  363. return H_TOO_HARD;
  364. entry = ioba >> stt->page_shift;
  365. /*
  366. * The spec says that the maximum size of the list is 512 TCEs
  367. * so the whole table addressed resides in 4K page
  368. */
  369. if (npages > 512)
  370. return H_PARAMETER;
  371. if (tce_list & (SZ_4K - 1))
  372. return H_PARAMETER;
  373. ret = kvmppc_ioba_validate(stt, ioba, npages);
  374. if (ret != H_SUCCESS)
  375. return ret;
  376. if (mm_iommu_preregistered(vcpu->kvm->mm)) {
  377. /*
  378. * We get here if guest memory was pre-registered which
  379. * is normally VFIO case and gpa->hpa translation does not
  380. * depend on hpt.
  381. */
  382. struct mm_iommu_table_group_mem_t *mem;
  383. if (kvmppc_gpa_to_ua(vcpu->kvm, tce_list, &ua, NULL))
  384. return H_TOO_HARD;
  385. mem = mm_iommu_lookup_rm(vcpu->kvm->mm, ua, IOMMU_PAGE_SIZE_4K);
  386. if (mem)
  387. prereg = mm_iommu_ua_to_hpa_rm(mem, ua, &tces) == 0;
  388. }
  389. if (!prereg) {
  390. /*
  391. * This is usually a case of a guest with emulated devices only
  392. * when TCE list is not in preregistered memory.
  393. * We do not require memory to be preregistered in this case
  394. * so lock rmap and do __find_linux_pte_or_hugepte().
  395. */
  396. if (kvmppc_gpa_to_ua(vcpu->kvm, tce_list, &ua, &rmap))
  397. return H_TOO_HARD;
  398. rmap = (void *) vmalloc_to_phys(rmap);
  399. if (WARN_ON_ONCE_RM(!rmap))
  400. return H_HARDWARE;
  401. /*
  402. * Synchronize with the MMU notifier callbacks in
  403. * book3s_64_mmu_hv.c (kvm_unmap_hva_range_hv etc.).
  404. * While we have the rmap lock, code running on other CPUs
  405. * cannot finish unmapping the host real page that backs
  406. * this guest real page, so we are OK to access the host
  407. * real page.
  408. */
  409. lock_rmap(rmap);
  410. if (kvmppc_rm_ua_to_hpa(vcpu, ua, &tces)) {
  411. ret = H_TOO_HARD;
  412. goto unlock_exit;
  413. }
  414. }
  415. for (i = 0; i < npages; ++i) {
  416. unsigned long tce = be64_to_cpu(((u64 *)tces)[i]);
  417. ret = kvmppc_tce_validate(stt, tce);
  418. if (ret != H_SUCCESS)
  419. goto unlock_exit;
  420. ua = 0;
  421. if (kvmppc_gpa_to_ua(vcpu->kvm,
  422. tce & ~(TCE_PCI_READ | TCE_PCI_WRITE),
  423. &ua, NULL))
  424. return H_PARAMETER;
  425. list_for_each_entry_lockless(stit, &stt->iommu_tables, next) {
  426. ret = kvmppc_rm_tce_iommu_map(vcpu->kvm, stt,
  427. stit->tbl, entry + i, ua,
  428. iommu_tce_direction(tce));
  429. if (ret == H_SUCCESS)
  430. continue;
  431. if (ret == H_TOO_HARD)
  432. goto unlock_exit;
  433. WARN_ON_ONCE_RM(1);
  434. kvmppc_rm_clear_tce(stit->tbl, entry);
  435. }
  436. kvmppc_tce_put(stt, entry + i, tce);
  437. }
  438. unlock_exit:
  439. if (rmap)
  440. unlock_rmap(rmap);
  441. return ret;
  442. }
  443. long kvmppc_rm_h_stuff_tce(struct kvm_vcpu *vcpu,
  444. unsigned long liobn, unsigned long ioba,
  445. unsigned long tce_value, unsigned long npages)
  446. {
  447. struct kvmppc_spapr_tce_table *stt;
  448. long i, ret;
  449. struct kvmppc_spapr_tce_iommu_table *stit;
  450. /* For radix, we might be in virtual mode, so punt */
  451. if (kvm_is_radix(vcpu->kvm))
  452. return H_TOO_HARD;
  453. stt = kvmppc_find_table(vcpu->kvm, liobn);
  454. if (!stt)
  455. return H_TOO_HARD;
  456. ret = kvmppc_ioba_validate(stt, ioba, npages);
  457. if (ret != H_SUCCESS)
  458. return ret;
  459. /* Check permission bits only to allow userspace poison TCE for debug */
  460. if (tce_value & (TCE_PCI_WRITE | TCE_PCI_READ))
  461. return H_PARAMETER;
  462. list_for_each_entry_lockless(stit, &stt->iommu_tables, next) {
  463. unsigned long entry = ioba >> stt->page_shift;
  464. for (i = 0; i < npages; ++i) {
  465. ret = kvmppc_rm_tce_iommu_unmap(vcpu->kvm, stt,
  466. stit->tbl, entry + i);
  467. if (ret == H_SUCCESS)
  468. continue;
  469. if (ret == H_TOO_HARD)
  470. return ret;
  471. WARN_ON_ONCE_RM(1);
  472. kvmppc_rm_clear_tce(stit->tbl, entry);
  473. }
  474. }
  475. for (i = 0; i < npages; ++i, ioba += (1ULL << stt->page_shift))
  476. kvmppc_tce_put(stt, ioba >> stt->page_shift, tce_value);
  477. return H_SUCCESS;
  478. }
  479. /* This can be called in either virtual mode or real mode */
  480. long kvmppc_h_get_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
  481. unsigned long ioba)
  482. {
  483. struct kvmppc_spapr_tce_table *stt;
  484. long ret;
  485. unsigned long idx;
  486. struct page *page;
  487. u64 *tbl;
  488. stt = kvmppc_find_table(vcpu->kvm, liobn);
  489. if (!stt)
  490. return H_TOO_HARD;
  491. ret = kvmppc_ioba_validate(stt, ioba, 1);
  492. if (ret != H_SUCCESS)
  493. return ret;
  494. idx = (ioba >> stt->page_shift) - stt->offset;
  495. page = stt->pages[idx / TCES_PER_PAGE];
  496. tbl = (u64 *)page_address(page);
  497. vcpu->arch.regs.gpr[4] = tbl[idx % TCES_PER_PAGE];
  498. return H_SUCCESS;
  499. }
  500. EXPORT_SYMBOL_GPL(kvmppc_h_get_tce);
  501. #endif /* KVM_BOOK3S_HV_POSSIBLE */