Skip to contentSkip to conversation

fix bits 39:32 of the final physical address when using 4M page

PATCH Applied Wen Congyang 4 participants 5 messages Dec 22, 2012 – Jan 9, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix bits 39:32 of the final physical address when using 4M page

((pde & 0x1fe000) << 19) is the bits 39:32 of the final physical address, and we shouldn't use unit32_t to calculate it. Convert the type to hwaddr to fix this problem.

---
 target-i386/arch_memory_mapping.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
target-i386/arch_memory_mapping.c +8 -3
index c6c7874..844893f 100644
@@ -115,7 +115,7 @@ static void walk_pde2(MemoryMappingList *list,
                       hwaddr pde_start_addr, int32_t a20_mask,
                       bool pse)
 {
-    hwaddr pde_addr, pte_start_addr, start_paddr;
+    hwaddr pde_addr, pte_start_addr, start_paddr, high_paddr;
     uint32_t pde;
     target_ulong line_addr, start_vaddr;
     int i;
@@ -130,8 +130,13 @@ static void walk_pde2(MemoryMappingList *list,
 
         line_addr = (((unsigned int)i & 0x3ff) << 22);
         if ((pde & PG_PSE_MASK) && pse) {
-            /* 4 MB page */
-            start_paddr = (pde & ~0x3fffff) | ((pde & 0x1fe000) << 19);
+            /*
+             * 4 MB page:
+             * bits 39:32 are bits 20:13 of the PDE
+             * bit3 31:22 are bits 31:22 of the PDE
+             */
+            high_paddr = ((hwaddr)(pde & 0x1fe000) << 19);
+            start_paddr = (pde & ~0x3fffff) | high_paddr;
             if (cpu_physical_memory_is_io(start_paddr)) {
                 /* I/O region */
                 continue;
Signature · 1 line
1.8.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Wen Congyang

((pde & 0x1fe000) << 19) is the bits 39:32 of the final physical address, and we shouldn't use unit32_t to calculate it. Convert the type to hwaddr to fix this problem.

Spotted by Coverity.

Quoted 25 lines
---
 target-i386/arch_memory_mapping.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
target-i386/arch_memory_mapping.c +1 -3
index c6c7874..844893f 100644
@@ -115,7 +115,7 @@ static void walk_pde2(MemoryMappingList *list,
                       hwaddr pde_start_addr, int32_t a20_mask,
                       bool pse)
 {
-    hwaddr pde_addr, pte_start_addr, start_paddr;
+    hwaddr pde_addr, pte_start_addr, start_paddr, high_paddr;
     uint32_t pde;
     target_ulong line_addr, start_vaddr;
     int i;
@@ -130,8 +130,13 @@ static void walk_pde2(MemoryMappingList *list,
 
         line_addr = (((unsigned int)i & 0x3ff) << 22);
         if ((pde & PG_PSE_MASK) && pse) {
-            /* 4 MB page */
-            start_paddr = (pde & ~0x3fffff) | ((pde & 0x1fe000) << 19);

target-i386/arch_memory_mapping.c static void walk_pde2(MemoryMappingList *list, · line 142

Quoted 10 lines
target-i386/arch_memory_mapping.c +7 -0
+            /*
+             * 4 MB page:
+             * bits 39:32 are bits 20:13 of the PDE
+             * bit3 31:22 are bits 31:22 of the PDE
+             */
+            high_paddr = ((hwaddr)(pde & 0x1fe000) << 19);
+            start_paddr = (pde & ~0x3fffff) | high_paddr;
             if (cpu_physical_memory_is_io(start_paddr)) {
                 /* I/O region */
                 continue;

Extra points for extending the comment.

#2 lore raw

Am 07.01.2013 13:06, schrieb Markus Armbruster:

Quoted 29 lines
Quoted 3 lines · Wen Congyang

((pde & 0x1fe000) << 19) is the bits 39:32 of the final physical address, and we shouldn't use unit32_t to calculate it. Convert the type to hwaddr to fix this problem.

Spotted by Coverity.

Quoted 21 lines
---
 target-i386/arch_memory_mapping.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
target-i386/arch_memory_mapping.c +1 -1
index c6c7874..844893f 100644
@@ -115,7 +115,7 @@ static void walk_pde2(MemoryMappingList *list,
                       hwaddr pde_start_addr, int32_t a20_mask,
                       bool pse)
 {
-    hwaddr pde_addr, pte_start_addr, start_paddr;
+    hwaddr pde_addr, pte_start_addr, start_paddr, high_paddr;
     uint32_t pde;
     target_ulong line_addr, start_vaddr;
     int i;
@@ -130,8 +130,13 @@ static void walk_pde2(MemoryMappingList *list,
 
Quoted 16 lines
Quoted 4 lines
target-i386/arch_memory_mapping.c +0 -2
         line_addr = (((unsigned int)i & 0x3ff) << 22);
         if ((pde & PG_PSE_MASK) && pse) {
-            /* 4 MB page */
-            start_paddr = (pde & ~0x3fffff) | ((pde & 0x1fe000) << 19);

target-i386/arch_memory_mapping.c static void walk_pde2(MemoryMappingList *list, · line 142

Quoted 10 lines
target-i386/arch_memory_mapping.c +7 -0
+            /*
+             * 4 MB page:
+             * bits 39:32 are bits 20:13 of the PDE
+             * bit3 31:22 are bits 31:22 of the PDE
+             */
+            high_paddr = ((hwaddr)(pde & 0x1fe000) << 19);
+            start_paddr = (pde & ~0x3fffff) | high_paddr;
             if (cpu_physical_memory_is_io(start_paddr)) {
                 /* I/O region */
                 continue;

Extra points for extending the comment.

...and a "target-i386: " prefix in the subject would be appreciated, since it does not seem to fix a general issue.

Andreas

Quoted 3 lines
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#3 lore raw
Quoted 47 lines · On Mon, 07 Jan 2013 14:10:46 +0100 Andreas Färber <[email protected]> wrote:

Am 07.01.2013 13:06, schrieb Markus Armbruster:

Quoted 29 lines
Quoted 3 lines · Wen Congyang

((pde & 0x1fe000) << 19) is the bits 39:32 of the final physical address, and we shouldn't use unit32_t to calculate it. Convert the type to hwaddr to fix this problem.

Spotted by Coverity.

Quoted 21 lines
---
 target-i386/arch_memory_mapping.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
target-i386/arch_memory_mapping.c +1 -1
index c6c7874..844893f 100644
@@ -115,7 +115,7 @@ static void walk_pde2(MemoryMappingList *list,
                       hwaddr pde_start_addr, int32_t a20_mask,
                       bool pse)
 {
-    hwaddr pde_addr, pte_start_addr, start_paddr;
+    hwaddr pde_addr, pte_start_addr, start_paddr, high_paddr;
     uint32_t pde;
     target_ulong line_addr, start_vaddr;
     int i;
@@ -130,8 +130,13 @@ static void walk_pde2(MemoryMappingList *list,
 
Quoted 16 lines
Quoted 4 lines
target-i386/arch_memory_mapping.c +0 -2
         line_addr = (((unsigned int)i & 0x3ff) << 22);
         if ((pde & PG_PSE_MASK) && pse) {
-            /* 4 MB page */
-            start_paddr = (pde & ~0x3fffff) | ((pde & 0x1fe000) << 19);

target-i386/arch_memory_mapping.c static void walk_pde2(MemoryMappingList *list, · line 142

Quoted 10 lines
target-i386/arch_memory_mapping.c +7 -0
+            /*
+             * 4 MB page:
+             * bits 39:32 are bits 20:13 of the PDE
+             * bit3 31:22 are bits 31:22 of the PDE
+             */
+            high_paddr = ((hwaddr)(pde & 0x1fe000) << 19);
+            start_paddr = (pde & ~0x3fffff) | high_paddr;
             if (cpu_physical_memory_is_io(start_paddr)) {
                 /* I/O region */
                 continue;

Extra points for extending the comment.

Quoted 2 lines

...and a "target-i386: " prefix in the subject would be appreciated, since it does not seem to fix a general issue.

I can do that myself when I apply the patch (which will take a little bit, as I'm just back from vacation).

Quoted 8 lines

Andreas

Quoted 3 lines
#4 lore raw
In reply to Wen Congyang
Quoted 5 lines · On Sat, 22 Dec 2012 15:13:54 +0800 Wen Congyang <[email protected]> wrote:

((pde & 0x1fe000) << 19) is the bits 39:32 of the final physical address, and we shouldn't use unit32_t to calculate it. Convert the type to hwaddr to fix this problem.

Applied to the qmp branch, thanks.

Quoted 34 lines
---
 target-i386/arch_memory_mapping.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
target-i386/arch_memory_mapping.c +8 -3
index c6c7874..844893f 100644
@@ -115,7 +115,7 @@ static void walk_pde2(MemoryMappingList *list,
                       hwaddr pde_start_addr, int32_t a20_mask,
                       bool pse)
 {
-    hwaddr pde_addr, pte_start_addr, start_paddr;
+    hwaddr pde_addr, pte_start_addr, start_paddr, high_paddr;
     uint32_t pde;
     target_ulong line_addr, start_vaddr;
     int i;
@@ -130,8 +130,13 @@ static void walk_pde2(MemoryMappingList *list,
 
         line_addr = (((unsigned int)i & 0x3ff) << 22);
         if ((pde & PG_PSE_MASK) && pse) {
-            /* 4 MB page */
-            start_paddr = (pde & ~0x3fffff) | ((pde & 0x1fe000) << 19);
+            /*
+             * 4 MB page:
+             * bits 39:32 are bits 20:13 of the PDE
+             * bit3 31:22 are bits 31:22 of the PDE
+             */
+            high_paddr = ((hwaddr)(pde & 0x1fe000) << 19);
+            start_paddr = (pde & ~0x3fffff) | high_paddr;
             if (cpu_physical_memory_is_io(start_paddr)) {
                 /* I/O region */
                 continue;