diff options
author | Joerg Roedel <joerg.roedel@amd.com> | 2010-07-01 10:00:11 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2010-08-01 03:47:30 -0400 |
commit | 828554136bbacae6e39fc31b9cd7e7c660ad7530 (patch) | |
tree | 4e2ec85ff33c9c1e7245e83ed8e4fa3791007ef7 /arch | |
parent | 95c87e2b4460a488ec7ce42f273893e410ab385a (diff) |
KVM: Remove unnecessary divide operations
This patch converts unnecessary divide and modulo operations
in the KVM large page related code into logical operations.
This allows to convert gfn_t to u64 while not breaking 32
bit builds.
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/ia64/include/asm/kvm_host.h | 1 | ||||
-rw-r--r-- | arch/powerpc/include/asm/kvm_host.h | 1 | ||||
-rw-r--r-- | arch/s390/include/asm/kvm_host.h | 3 | ||||
-rw-r--r-- | arch/x86/include/asm/kvm_host.h | 3 | ||||
-rw-r--r-- | arch/x86/kvm/mmu.c | 8 |
5 files changed, 10 insertions, 6 deletions
diff --git a/arch/ia64/include/asm/kvm_host.h b/arch/ia64/include/asm/kvm_host.h index a362e67e0ca6..2f229e5de498 100644 --- a/arch/ia64/include/asm/kvm_host.h +++ b/arch/ia64/include/asm/kvm_host.h | |||
@@ -235,6 +235,7 @@ struct kvm_vm_data { | |||
235 | #define KVM_REQ_PTC_G 32 | 235 | #define KVM_REQ_PTC_G 32 |
236 | #define KVM_REQ_RESUME 33 | 236 | #define KVM_REQ_RESUME 33 |
237 | 237 | ||
238 | #define KVM_HPAGE_GFN_SHIFT(x) 0 | ||
238 | #define KVM_NR_PAGE_SIZES 1 | 239 | #define KVM_NR_PAGE_SIZES 1 |
239 | #define KVM_PAGES_PER_HPAGE(x) 1 | 240 | #define KVM_PAGES_PER_HPAGE(x) 1 |
240 | 241 | ||
diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h index e004eafcd3f0..b0b23c007d6e 100644 --- a/arch/powerpc/include/asm/kvm_host.h +++ b/arch/powerpc/include/asm/kvm_host.h | |||
@@ -35,6 +35,7 @@ | |||
35 | #define KVM_COALESCED_MMIO_PAGE_OFFSET 1 | 35 | #define KVM_COALESCED_MMIO_PAGE_OFFSET 1 |
36 | 36 | ||
37 | /* We don't currently support large pages. */ | 37 | /* We don't currently support large pages. */ |
38 | #define KVM_HPAGE_GFN_SHIFT(x) 0 | ||
38 | #define KVM_NR_PAGE_SIZES 1 | 39 | #define KVM_NR_PAGE_SIZES 1 |
39 | #define KVM_PAGES_PER_HPAGE(x) (1UL<<31) | 40 | #define KVM_PAGES_PER_HPAGE(x) (1UL<<31) |
40 | 41 | ||
diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h index b95710a1f5dd..cef7dbf69dfc 100644 --- a/arch/s390/include/asm/kvm_host.h +++ b/arch/s390/include/asm/kvm_host.h | |||
@@ -41,7 +41,8 @@ struct sca_block { | |||
41 | } __attribute__((packed)); | 41 | } __attribute__((packed)); |
42 | 42 | ||
43 | #define KVM_NR_PAGE_SIZES 2 | 43 | #define KVM_NR_PAGE_SIZES 2 |
44 | #define KVM_HPAGE_SHIFT(x) (PAGE_SHIFT + ((x) - 1) * 8) | 44 | #define KVM_HPAGE_GFN_SHIFT(x) (((x) - 1) * 8) |
45 | #define KVM_HPAGE_SHIFT(x) (PAGE_SHIFT + KVM_HPAGE_GFN_SHIFT(x)) | ||
45 | #define KVM_HPAGE_SIZE(x) (1UL << KVM_HPAGE_SHIFT(x)) | 46 | #define KVM_HPAGE_SIZE(x) (1UL << KVM_HPAGE_SHIFT(x)) |
46 | #define KVM_HPAGE_MASK(x) (~(KVM_HPAGE_SIZE(x) - 1)) | 47 | #define KVM_HPAGE_MASK(x) (~(KVM_HPAGE_SIZE(x) - 1)) |
47 | #define KVM_PAGES_PER_HPAGE(x) (KVM_HPAGE_SIZE(x) / PAGE_SIZE) | 48 | #define KVM_PAGES_PER_HPAGE(x) (KVM_HPAGE_SIZE(x) / PAGE_SIZE) |
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 2bda62485c4c..50c79b9f5c38 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h | |||
@@ -44,7 +44,8 @@ | |||
44 | 44 | ||
45 | /* KVM Hugepage definitions for x86 */ | 45 | /* KVM Hugepage definitions for x86 */ |
46 | #define KVM_NR_PAGE_SIZES 3 | 46 | #define KVM_NR_PAGE_SIZES 3 |
47 | #define KVM_HPAGE_SHIFT(x) (PAGE_SHIFT + (((x) - 1) * 9)) | 47 | #define KVM_HPAGE_GFN_SHIFT(x) (((x) - 1) * 9) |
48 | #define KVM_HPAGE_SHIFT(x) (PAGE_SHIFT + KVM_HPAGE_GFN_SHIFT(x)) | ||
48 | #define KVM_HPAGE_SIZE(x) (1UL << KVM_HPAGE_SHIFT(x)) | 49 | #define KVM_HPAGE_SIZE(x) (1UL << KVM_HPAGE_SHIFT(x)) |
49 | #define KVM_HPAGE_MASK(x) (~(KVM_HPAGE_SIZE(x) - 1)) | 50 | #define KVM_HPAGE_MASK(x) (~(KVM_HPAGE_SIZE(x) - 1)) |
50 | #define KVM_PAGES_PER_HPAGE(x) (KVM_HPAGE_SIZE(x) / PAGE_SIZE) | 51 | #define KVM_PAGES_PER_HPAGE(x) (KVM_HPAGE_SIZE(x) / PAGE_SIZE) |
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index ca07ed083b59..a20fd613acfe 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c | |||
@@ -423,8 +423,8 @@ static int *slot_largepage_idx(gfn_t gfn, | |||
423 | { | 423 | { |
424 | unsigned long idx; | 424 | unsigned long idx; |
425 | 425 | ||
426 | idx = (gfn / KVM_PAGES_PER_HPAGE(level)) - | 426 | idx = (gfn >> KVM_HPAGE_GFN_SHIFT(level)) - |
427 | (slot->base_gfn / KVM_PAGES_PER_HPAGE(level)); | 427 | (slot->base_gfn >> KVM_HPAGE_GFN_SHIFT(level)); |
428 | return &slot->lpage_info[level - 2][idx].write_count; | 428 | return &slot->lpage_info[level - 2][idx].write_count; |
429 | } | 429 | } |
430 | 430 | ||
@@ -528,8 +528,8 @@ static unsigned long *gfn_to_rmap(struct kvm *kvm, gfn_t gfn, int level) | |||
528 | if (likely(level == PT_PAGE_TABLE_LEVEL)) | 528 | if (likely(level == PT_PAGE_TABLE_LEVEL)) |
529 | return &slot->rmap[gfn - slot->base_gfn]; | 529 | return &slot->rmap[gfn - slot->base_gfn]; |
530 | 530 | ||
531 | idx = (gfn / KVM_PAGES_PER_HPAGE(level)) - | 531 | idx = (gfn >> KVM_HPAGE_GFN_SHIFT(level)) - |
532 | (slot->base_gfn / KVM_PAGES_PER_HPAGE(level)); | 532 | (slot->base_gfn >> KVM_HPAGE_GFN_SHIFT(level)); |
533 | 533 | ||
534 | return &slot->lpage_info[level - 2][idx].rmap_pde; | 534 | return &slot->lpage_info[level - 2][idx].rmap_pde; |
535 | } | 535 | } |