KVM
Macros | Functions
tdp_iter.c File Reference
#include "mmu_internal.h"
#include "tdp_iter.h"
#include "spte.h"
Include dependency graph for tdp_iter.c:

Go to the source code of this file.

Macros

#define pr_fmt(fmt)   KBUILD_MODNAME ": " fmt
 

Functions

static void tdp_iter_refresh_sptep (struct tdp_iter *iter)
 
void tdp_iter_restart (struct tdp_iter *iter)
 
void tdp_iter_start (struct tdp_iter *iter, struct kvm_mmu_page *root, int min_level, gfn_t next_last_level_gfn)
 
tdp_ptep_t spte_to_child_pt (u64 spte, int level)
 
static bool try_step_down (struct tdp_iter *iter)
 
static bool try_step_side (struct tdp_iter *iter)
 
static bool try_step_up (struct tdp_iter *iter)
 
void tdp_iter_next (struct tdp_iter *iter)
 

Macro Definition Documentation

◆ pr_fmt

#define pr_fmt (   fmt)    KBUILD_MODNAME ": " fmt

Definition at line 2 of file tdp_iter.c.

Function Documentation

◆ spte_to_child_pt()

tdp_ptep_t spte_to_child_pt ( u64  spte,
int  level 
)

Definition at line 62 of file tdp_iter.c.

63 {
64  /*
65  * There's no child entry if this entry isn't present or is a
66  * last-level entry.
67  */
68  if (!is_shadow_present_pte(spte) || is_last_spte(spte, level))
69  return NULL;
70 
71  return (tdp_ptep_t)__va(spte_to_pfn(spte) << PAGE_SHIFT);
72 }
u64 __rcu * tdp_ptep_t
Definition: mmu_internal.h:50
static bool is_last_spte(u64 pte, int level)
Definition: spte.h:318
static bool is_shadow_present_pte(u64 pte)
Definition: spte.h:258
static kvm_pfn_t spte_to_pfn(u64 pte)
Definition: spte.h:328
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tdp_iter_next()

void tdp_iter_next ( struct tdp_iter iter)

Definition at line 161 of file tdp_iter.c.

162 {
163  if (iter->yielded) {
164  tdp_iter_restart(iter);
165  return;
166  }
167 
168  if (try_step_down(iter))
169  return;
170 
171  do {
172  if (try_step_side(iter))
173  return;
174  } while (try_step_up(iter));
175  iter->valid = false;
176 }
bool yielded
Definition: tdp_iter.h:116
bool valid
Definition: tdp_iter.h:110
static bool try_step_up(struct tdp_iter *iter)
Definition: tdp_iter.c:133
static bool try_step_side(struct tdp_iter *iter)
Definition: tdp_iter.c:110
static bool try_step_down(struct tdp_iter *iter)
Definition: tdp_iter.c:78
void tdp_iter_restart(struct tdp_iter *iter)
Definition: tdp_iter.c:23
Here is the call graph for this function:

◆ tdp_iter_refresh_sptep()

static void tdp_iter_refresh_sptep ( struct tdp_iter iter)
static

Definition at line 12 of file tdp_iter.c.

13 {
14  iter->sptep = iter->pt_path[iter->level - 1] +
15  SPTE_INDEX(iter->gfn << PAGE_SHIFT, iter->level);
16  iter->old_spte = kvm_tdp_mmu_read_spte(iter->sptep);
17 }
#define SPTE_INDEX(address, level)
Definition: spte.h:57
tdp_ptep_t pt_path[PT64_ROOT_MAX_LEVEL]
Definition: tdp_iter.h:91
gfn_t gfn
Definition: tdp_iter.h:95
tdp_ptep_t sptep
Definition: tdp_iter.h:93
u64 old_spte
Definition: tdp_iter.h:105
int level
Definition: tdp_iter.h:101
static u64 kvm_tdp_mmu_read_spte(tdp_ptep_t sptep)
Definition: tdp_iter.h:17
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tdp_iter_restart()

void tdp_iter_restart ( struct tdp_iter iter)

Definition at line 23 of file tdp_iter.c.

24 {
25  iter->yielded = false;
26  iter->yielded_gfn = iter->next_last_level_gfn;
27  iter->level = iter->root_level;
28 
29  iter->gfn = gfn_round_for_level(iter->next_last_level_gfn, iter->level);
31 
32  iter->valid = true;
33 }
static gfn_t gfn_round_for_level(gfn_t gfn, int level)
Definition: mmu_internal.h:161
int root_level
Definition: tdp_iter.h:97
gfn_t yielded_gfn
Definition: tdp_iter.h:89
gfn_t next_last_level_gfn
Definition: tdp_iter.h:83
static void tdp_iter_refresh_sptep(struct tdp_iter *iter)
Definition: tdp_iter.c:12
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tdp_iter_start()

void tdp_iter_start ( struct tdp_iter iter,
struct kvm_mmu_page root,
int  min_level,
gfn_t  next_last_level_gfn 
)

Definition at line 39 of file tdp_iter.c.

41 {
42  if (WARN_ON_ONCE(!root || (root->role.level < 1) ||
43  (root->role.level > PT64_ROOT_MAX_LEVEL))) {
44  iter->valid = false;
45  return;
46  }
47 
48  iter->next_last_level_gfn = next_last_level_gfn;
49  iter->root_level = root->role.level;
50  iter->min_level = min_level;
51  iter->pt_path[iter->root_level - 1] = (tdp_ptep_t)root->spt;
52  iter->as_id = kvm_mmu_page_as_id(root);
53 
54  tdp_iter_restart(iter);
55 }
static int kvm_mmu_page_as_id(struct kvm_mmu_page *sp)
Definition: mmu_internal.h:143
union kvm_mmu_page_role role
Definition: mmu_internal.h:80
int as_id
Definition: tdp_iter.h:103
int min_level
Definition: tdp_iter.h:99
Here is the call graph for this function:

◆ try_step_down()

static bool try_step_down ( struct tdp_iter iter)
static

Definition at line 78 of file tdp_iter.c.

79 {
80  tdp_ptep_t child_pt;
81 
82  if (iter->level == iter->min_level)
83  return false;
84 
85  /*
86  * Reread the SPTE before stepping down to avoid traversing into page
87  * tables that are no longer linked from this entry.
88  */
89  iter->old_spte = kvm_tdp_mmu_read_spte(iter->sptep);
90 
91  child_pt = spte_to_child_pt(iter->old_spte, iter->level);
92  if (!child_pt)
93  return false;
94 
95  iter->level--;
96  iter->pt_path[iter->level - 1] = child_pt;
97  iter->gfn = gfn_round_for_level(iter->next_last_level_gfn, iter->level);
99 
100  return true;
101 }
tdp_ptep_t spte_to_child_pt(u64 spte, int level)
Definition: tdp_iter.c:62
Here is the call graph for this function:
Here is the caller graph for this function:

◆ try_step_side()

static bool try_step_side ( struct tdp_iter iter)
static

Definition at line 110 of file tdp_iter.c.

111 {
112  /*
113  * Check if the iterator is already at the end of the current page
114  * table.
115  */
116  if (SPTE_INDEX(iter->gfn << PAGE_SHIFT, iter->level) ==
117  (SPTE_ENT_PER_PAGE - 1))
118  return false;
119 
120  iter->gfn += KVM_PAGES_PER_HPAGE(iter->level);
121  iter->next_last_level_gfn = iter->gfn;
122  iter->sptep++;
123  iter->old_spte = kvm_tdp_mmu_read_spte(iter->sptep);
124 
125  return true;
126 }
#define SPTE_ENT_PER_PAGE
Definition: spte.h:58
Here is the call graph for this function:
Here is the caller graph for this function:

◆ try_step_up()

static bool try_step_up ( struct tdp_iter iter)
static

Definition at line 133 of file tdp_iter.c.

134 {
135  if (iter->level == iter->root_level)
136  return false;
137 
138  iter->level++;
139  iter->gfn = gfn_round_for_level(iter->gfn, iter->level);
141 
142  return true;
143 }
Here is the call graph for this function:
Here is the caller graph for this function: