linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Use u64 for gfn_t in KVM
@ 2010-07-01 14:00 Joerg Roedel
  2010-07-01 14:00 ` [PATCH 1/2] KVM: Remove unnecessary divide operations Joerg Roedel
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Joerg Roedel @ 2010-07-01 14:00 UTC (permalink / raw)
  To: Avi Kivity, Marcelo Tosatti; +Cc: kvm, linux-kernel

Hi, Avi, Marcelo,

these two patches currently lie on the bottom of my npt-npt patch set. They
came out of a discussion on the mailing list about the last version of the
npt-npt patchset. These patches are independent of the rest of the patchset, so
I post and discuss them seperatly. The changes to make gfn_t an u64 were
larger than I expected which is another reason for the seperate post. Please
let me know what you think about this change.

Thanks,

	Joerg

Diffstat:

 arch/ia64/include/asm/kvm_host.h    |    1 +
 arch/powerpc/include/asm/kvm_host.h |    1 +
 arch/s390/include/asm/kvm_host.h    |    3 ++-
 arch/x86/include/asm/kvm_host.h     |    3 ++-
 arch/x86/kvm/mmu.c                  |    8 ++++----
 include/linux/kvm_types.h           |    4 ++--
 virt/kvm/iommu.c                    |    2 +-
 virt/kvm/kvm_main.c                 |   10 +++++-----
 8 files changed, 18 insertions(+), 14 deletions(-)

Shortlog:

Joerg Roedel (2):
      KVM: Remove unnecessary divide operations
      KVM: Use u64 for frame data types



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] KVM: Remove unnecessary divide operations
  2010-07-01 14:00 [PATCH 0/2] Use u64 for gfn_t in KVM Joerg Roedel
@ 2010-07-01 14:00 ` Joerg Roedel
  2010-07-01 14:18   ` Avi Kivity
  2010-07-01 14:00 ` [PATCH 2/2] KVM: Use u64 for frame data types Joerg Roedel
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Joerg Roedel @ 2010-07-01 14:00 UTC (permalink / raw)
  To: Avi Kivity, Marcelo Tosatti; +Cc: kvm, linux-kernel, Joerg Roedel

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>
---
 arch/ia64/include/asm/kvm_host.h    |    1 +
 arch/powerpc/include/asm/kvm_host.h |    1 +
 arch/s390/include/asm/kvm_host.h    |    3 ++-
 arch/x86/include/asm/kvm_host.h     |    3 ++-
 arch/x86/kvm/mmu.c                  |    8 ++++----
 virt/kvm/kvm_main.c                 |   10 +++++-----
 6 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/arch/ia64/include/asm/kvm_host.h b/arch/ia64/include/asm/kvm_host.h
index a362e67..2f229e5 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 {
 #define KVM_REQ_PTC_G		32
 #define KVM_REQ_RESUME		33
 
+#define KVM_HPAGE_GFN_SHIFT(x)	0
 #define KVM_NR_PAGE_SIZES	1
 #define KVM_PAGES_PER_HPAGE(x)	1
 
diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h
index 0c9ad86..3452dac 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -35,6 +35,7 @@
 #define KVM_COALESCED_MMIO_PAGE_OFFSET 1
 
 /* We don't currently support large pages. */
+#define KVM_HPAGE_GFN_SHIFT(x)	0
 #define KVM_NR_PAGE_SIZES	1
 #define KVM_PAGES_PER_HPAGE(x)	(1UL<<31)
 
diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index b95710a..cef7dbf 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -41,7 +41,8 @@ struct sca_block {
 } __attribute__((packed));
 
 #define KVM_NR_PAGE_SIZES 2
-#define KVM_HPAGE_SHIFT(x) (PAGE_SHIFT + ((x) - 1) * 8)
+#define KVM_HPAGE_GFN_SHIFT(x) (((x) - 1) * 8)
+#define KVM_HPAGE_SHIFT(x) (PAGE_SHIFT + KVM_HPAGE_GFN_SHIFT(x))
 #define KVM_HPAGE_SIZE(x) (1UL << KVM_HPAGE_SHIFT(x))
 #define KVM_HPAGE_MASK(x)	(~(KVM_HPAGE_SIZE(x) - 1))
 #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 a57cdea..2b3452f 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -43,7 +43,8 @@
 
 /* KVM Hugepage definitions for x86 */
 #define KVM_NR_PAGE_SIZES	3
-#define KVM_HPAGE_SHIFT(x)	(PAGE_SHIFT + (((x) - 1) * 9))
+#define KVM_HPAGE_GFN_SHIFT(x)	(((x) - 1) * 9)
+#define KVM_HPAGE_SHIFT(x)	(PAGE_SHIFT + KVM_HPAGE_GFN_SHIFT(x))
 #define KVM_HPAGE_SIZE(x)	(1UL << KVM_HPAGE_SHIFT(x))
 #define KVM_HPAGE_MASK(x)	(~(KVM_HPAGE_SIZE(x) - 1))
 #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 045a0f9..8e0a325 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,
 {
 	unsigned long idx;
 
-	idx = (gfn / KVM_PAGES_PER_HPAGE(level)) -
-	      (slot->base_gfn / KVM_PAGES_PER_HPAGE(level));
+	idx = (gfn >> KVM_HPAGE_GFN_SHIFT(level)) -
+	      (slot->base_gfn >> KVM_HPAGE_GFN_SHIFT(level));
 	return &slot->lpage_info[level - 2][idx].write_count;
 }
 
@@ -528,8 +528,8 @@ static unsigned long *gfn_to_rmap(struct kvm *kvm, gfn_t gfn, int level)
 	if (likely(level == PT_PAGE_TABLE_LEVEL))
 		return &slot->rmap[gfn - slot->base_gfn];
 
-	idx = (gfn / KVM_PAGES_PER_HPAGE(level)) -
-		(slot->base_gfn / KVM_PAGES_PER_HPAGE(level));
+	idx = (gfn >> KVM_HPAGE_GFN_SHIFT(level)) -
+		(slot->base_gfn >> KVM_HPAGE_GFN_SHIFT(level));
 
 	return &slot->lpage_info[level - 2][idx].rmap_pde;
 }
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 885d3f5..57e3a6b 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -626,9 +626,9 @@ int __kvm_set_memory_region(struct kvm *kvm,
 		if (new.lpage_info[i])
 			continue;
 
-		lpages = 1 + (base_gfn + npages - 1) /
-			     KVM_PAGES_PER_HPAGE(level);
-		lpages -= base_gfn / KVM_PAGES_PER_HPAGE(level);
+		lpages = 1 + ((base_gfn + npages - 1)
+			     >> KVM_HPAGE_GFN_SHIFT(level));
+		lpages -= base_gfn >> KVM_HPAGE_GFN_SHIFT(level);
 
 		new.lpage_info[i] = vmalloc(lpages * sizeof(*new.lpage_info[i]));
 
@@ -638,9 +638,9 @@ int __kvm_set_memory_region(struct kvm *kvm,
 		memset(new.lpage_info[i], 0,
 		       lpages * sizeof(*new.lpage_info[i]));
 
-		if (base_gfn % KVM_PAGES_PER_HPAGE(level))
+		if (base_gfn & (KVM_PAGES_PER_HPAGE(level) - 1))
 			new.lpage_info[i][0].write_count = 1;
-		if ((base_gfn+npages) % KVM_PAGES_PER_HPAGE(level))
+		if ((base_gfn+npages) & (KVM_PAGES_PER_HPAGE(level) - 1))
 			new.lpage_info[i][lpages - 1].write_count = 1;
 		ugfn = new.userspace_addr >> PAGE_SHIFT;
 		/*
-- 
1.7.0.4



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] KVM: Use u64 for frame data types
  2010-07-01 14:00 [PATCH 0/2] Use u64 for gfn_t in KVM Joerg Roedel
  2010-07-01 14:00 ` [PATCH 1/2] KVM: Remove unnecessary divide operations Joerg Roedel
@ 2010-07-01 14:00 ` Joerg Roedel
  2010-07-01 14:18 ` [PATCH 0/2] Use u64 for gfn_t in KVM Avi Kivity
  2010-07-02 17:19 ` Marcelo Tosatti
  3 siblings, 0 replies; 6+ messages in thread
From: Joerg Roedel @ 2010-07-01 14:00 UTC (permalink / raw)
  To: Avi Kivity, Marcelo Tosatti; +Cc: kvm, linux-kernel, Joerg Roedel

For 32bit machines where the physical address width is
larger than the virtual address width the frame number types
in KVM may overflow. Fix this by changing them to u64.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
 include/linux/kvm_types.h |    4 ++--
 virt/kvm/iommu.c          |    2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h
index fb46efb..7ac0d4e 100644
--- a/include/linux/kvm_types.h
+++ b/include/linux/kvm_types.h
@@ -32,11 +32,11 @@
 
 typedef unsigned long  gva_t;
 typedef u64            gpa_t;
-typedef unsigned long  gfn_t;
+typedef u64            gfn_t;
 
 typedef unsigned long  hva_t;
 typedef u64            hpa_t;
-typedef unsigned long  hfn_t;
+typedef u64            hfn_t;
 
 typedef hfn_t pfn_t;
 
diff --git a/virt/kvm/iommu.c b/virt/kvm/iommu.c
index 673c88a..22fc28b 100644
--- a/virt/kvm/iommu.c
+++ b/virt/kvm/iommu.c
@@ -108,7 +108,7 @@ int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot)
 			      get_order(page_size), flags);
 		if (r) {
 			printk(KERN_ERR "kvm_iommu_map_address:"
-			       "iommu failed to map pfn=%lx\n", pfn);
+			       "iommu failed to map pfn=%llx\n", pfn);
 			goto unmap_pages;
 		}
 
-- 
1.7.0.4



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] KVM: Remove unnecessary divide operations
  2010-07-01 14:00 ` [PATCH 1/2] KVM: Remove unnecessary divide operations Joerg Roedel
@ 2010-07-01 14:18   ` Avi Kivity
  0 siblings, 0 replies; 6+ messages in thread
From: Avi Kivity @ 2010-07-01 14:18 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: Marcelo Tosatti, kvm, linux-kernel

On 07/01/2010 05:00 PM, Joerg Roedel wrote:
> 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.
>
>
>   #define KVM_NR_PAGE_SIZES 2
> -#define KVM_HPAGE_SHIFT(x) (PAGE_SHIFT + ((x) - 1) * 8)
> +#define KVM_HPAGE_GFN_SHIFT(x) (((x) - 1) * 8)
> +#define KVM_HPAGE_SHIFT(x) (PAGE_SHIFT + KVM_HPAGE_GFN_SHIFT(x))
>   #define KVM_HPAGE_SIZE(x) (1UL<<  KVM_HPAGE_SHIFT(x))
>   #define KVM_HPAGE_MASK(x)	(~(KVM_HPAGE_SIZE(x) - 1))
>    

In theory, KVM_HPAGE_SIZE() needs s/1UL/(u64)1/, or KVM_HPAGE_MASK 
becomes truncated if used against a gfn_t.  In practice, KVM_HPAGE_MASK 
is not used at all, so this doesn't matter.

-- 
error compiling committee.c: too many arguments to function


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] Use u64 for gfn_t in KVM
  2010-07-01 14:00 [PATCH 0/2] Use u64 for gfn_t in KVM Joerg Roedel
  2010-07-01 14:00 ` [PATCH 1/2] KVM: Remove unnecessary divide operations Joerg Roedel
  2010-07-01 14:00 ` [PATCH 2/2] KVM: Use u64 for frame data types Joerg Roedel
@ 2010-07-01 14:18 ` Avi Kivity
  2010-07-02 17:19 ` Marcelo Tosatti
  3 siblings, 0 replies; 6+ messages in thread
From: Avi Kivity @ 2010-07-01 14:18 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: Marcelo Tosatti, kvm, linux-kernel

On 07/01/2010 05:00 PM, Joerg Roedel wrote:
> Hi, Avi, Marcelo,
>
> these two patches currently lie on the bottom of my npt-npt patch set. They
> came out of a discussion on the mailing list about the last version of the
> npt-npt patchset. These patches are independent of the rest of the patchset, so
> I post and discuss them seperatly. The changes to make gfn_t an u64 were
> larger than I expected which is another reason for the seperate post. Please
> let me know what you think about this change.
>
>    

Looks good.

-- 
error compiling committee.c: too many arguments to function


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] Use u64 for gfn_t in KVM
  2010-07-01 14:00 [PATCH 0/2] Use u64 for gfn_t in KVM Joerg Roedel
                   ` (2 preceding siblings ...)
  2010-07-01 14:18 ` [PATCH 0/2] Use u64 for gfn_t in KVM Avi Kivity
@ 2010-07-02 17:19 ` Marcelo Tosatti
  3 siblings, 0 replies; 6+ messages in thread
From: Marcelo Tosatti @ 2010-07-02 17:19 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: Avi Kivity, kvm, linux-kernel

On Thu, Jul 01, 2010 at 04:00:10PM +0200, Joerg Roedel wrote:
> Hi, Avi, Marcelo,
> 
> these two patches currently lie on the bottom of my npt-npt patch set. They
> came out of a discussion on the mailing list about the last version of the
> npt-npt patchset. These patches are independent of the rest of the patchset, so
> I post and discuss them seperatly. The changes to make gfn_t an u64 were
> larger than I expected which is another reason for the seperate post. Please
> let me know what you think about this change.
> 
> Thanks,
> 
> 	Joerg
> 
> Diffstat:
> 
>  arch/ia64/include/asm/kvm_host.h    |    1 +
>  arch/powerpc/include/asm/kvm_host.h |    1 +
>  arch/s390/include/asm/kvm_host.h    |    3 ++-
>  arch/x86/include/asm/kvm_host.h     |    3 ++-
>  arch/x86/kvm/mmu.c                  |    8 ++++----
>  include/linux/kvm_types.h           |    4 ++--
>  virt/kvm/iommu.c                    |    2 +-
>  virt/kvm/kvm_main.c                 |   10 +++++-----
>  8 files changed, 18 insertions(+), 14 deletions(-)
> 
> Shortlog:
> 
> Joerg Roedel (2):
>       KVM: Remove unnecessary divide operations
>       KVM: Use u64 for frame data types

Applied, thanks.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-07-02 17:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-01 14:00 [PATCH 0/2] Use u64 for gfn_t in KVM Joerg Roedel
2010-07-01 14:00 ` [PATCH 1/2] KVM: Remove unnecessary divide operations Joerg Roedel
2010-07-01 14:18   ` Avi Kivity
2010-07-01 14:00 ` [PATCH 2/2] KVM: Use u64 for frame data types Joerg Roedel
2010-07-01 14:18 ` [PATCH 0/2] Use u64 for gfn_t in KVM Avi Kivity
2010-07-02 17:19 ` Marcelo Tosatti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).