aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakuya Yoshikawa <yoshikawa_takuya_b1@lab.ntt.co.jp>2015-11-20 03:43:13 -0500
committerPaolo Bonzini <pbonzini@redhat.com>2015-11-25 11:26:15 -0500
commitfd9514572f721acbabb0ff24f6b5294a2449d492 (patch)
tree77462fd96a52b6ebdf87a849156a59d1d4f2f7e3
parent7ee0e5b29d275ac299cdf8ef67e60bf1648c8c6a (diff)
KVM: x86: MMU: Add helper function to clear a bit in unsync child bitmap
Both __mmu_unsync_walk() and mmu_pages_clear_parents() have three line code which clears a bit in the unsync child bitmap; the former places it inside a loop block and uses a few goto statements to jump to it. A new helper function, clear_unsync_child_bit(), makes the code cleaner. Signed-off-by: Takuya Yoshikawa <yoshikawa_takuya_b1@lab.ntt.co.jp> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--arch/x86/kvm/mmu.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 8a1593f985df..9832bc9e937e 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -1809,6 +1809,13 @@ static int mmu_pages_add(struct kvm_mmu_pages *pvec, struct kvm_mmu_page *sp,
1809 return (pvec->nr == KVM_PAGE_ARRAY_NR); 1809 return (pvec->nr == KVM_PAGE_ARRAY_NR);
1810} 1810}
1811 1811
1812static inline void clear_unsync_child_bit(struct kvm_mmu_page *sp, int idx)
1813{
1814 --sp->unsync_children;
1815 WARN_ON((int)sp->unsync_children < 0);
1816 __clear_bit(idx, sp->unsync_child_bitmap);
1817}
1818
1812static int __mmu_unsync_walk(struct kvm_mmu_page *sp, 1819static int __mmu_unsync_walk(struct kvm_mmu_page *sp,
1813 struct kvm_mmu_pages *pvec) 1820 struct kvm_mmu_pages *pvec)
1814{ 1821{
@@ -1818,8 +1825,10 @@ static int __mmu_unsync_walk(struct kvm_mmu_page *sp,
1818 struct kvm_mmu_page *child; 1825 struct kvm_mmu_page *child;
1819 u64 ent = sp->spt[i]; 1826 u64 ent = sp->spt[i];
1820 1827
1821 if (!is_shadow_present_pte(ent) || is_large_pte(ent)) 1828 if (!is_shadow_present_pte(ent) || is_large_pte(ent)) {
1822 goto clear_child_bitmap; 1829 clear_unsync_child_bit(sp, i);
1830 continue;
1831 }
1823 1832
1824 child = page_header(ent & PT64_BASE_ADDR_MASK); 1833 child = page_header(ent & PT64_BASE_ADDR_MASK);
1825 1834
@@ -1828,28 +1837,21 @@ static int __mmu_unsync_walk(struct kvm_mmu_page *sp,
1828 return -ENOSPC; 1837 return -ENOSPC;
1829 1838
1830 ret = __mmu_unsync_walk(child, pvec); 1839 ret = __mmu_unsync_walk(child, pvec);
1831 if (!ret) 1840 if (!ret) {
1832 goto clear_child_bitmap; 1841 clear_unsync_child_bit(sp, i);
1833 else if (ret > 0) 1842 continue;
1843 } else if (ret > 0) {
1834 nr_unsync_leaf += ret; 1844 nr_unsync_leaf += ret;
1835 else 1845 } else
1836 return ret; 1846 return ret;
1837 } else if (child->unsync) { 1847 } else if (child->unsync) {
1838 nr_unsync_leaf++; 1848 nr_unsync_leaf++;
1839 if (mmu_pages_add(pvec, child, i)) 1849 if (mmu_pages_add(pvec, child, i))
1840 return -ENOSPC; 1850 return -ENOSPC;
1841 } else 1851 } else
1842 goto clear_child_bitmap; 1852 clear_unsync_child_bit(sp, i);
1843
1844 continue;
1845
1846clear_child_bitmap:
1847 __clear_bit(i, sp->unsync_child_bitmap);
1848 sp->unsync_children--;
1849 WARN_ON((int)sp->unsync_children < 0);
1850 } 1853 }
1851 1854
1852
1853 return nr_unsync_leaf; 1855 return nr_unsync_leaf;
1854} 1856}
1855 1857
@@ -2012,9 +2014,7 @@ static void mmu_pages_clear_parents(struct mmu_page_path *parents)
2012 if (!sp) 2014 if (!sp)
2013 return; 2015 return;
2014 2016
2015 --sp->unsync_children; 2017 clear_unsync_child_bit(sp, idx);
2016 WARN_ON((int)sp->unsync_children < 0);
2017 __clear_bit(idx, sp->unsync_child_bitmap);
2018 level++; 2018 level++;
2019 } while (level < PT64_ROOT_LEVEL-1 && !sp->unsync_children); 2019 } while (level < PT64_ROOT_LEVEL-1 && !sp->unsync_children);
2020} 2020}