Skip to contentSkip to conversation

hw/igd: fix calculation of graphics stolen memory

PATCH Applied Corvin Köhne 4 participants 4 messages Nov 8, 2024 – Nov 9, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/igd: fix calculation of graphics stolen memory

From: Corvin Köhne <[email protected]>

When copying the calculation of the stolen memory size for Intels integrated graphics device of gen 9 and later from the Linux kernel [1], we missed subtracting 0xf0 from the graphics mode select value for values above 0xf0. This leads to QEMU reporting a very large size of the graphics stolen memory area. That's just a waste of memory. Additionally the guest firmware might be unable to allocate such a large buffer.

[1] https://github.com/torvalds/linux/blob/7c626ce4bae1ac14f60076d00eafe71af30450ba/arch/x86/kernel/early-quirks.c#L455-L460

Fixes 8719224166832ff8230d7dd8599f42bd60e2eb96
---
 hw/vfio/igd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/vfio/igd.c +1 -1
index a95d441f68..732f9c37a6 100644
@@ -498,7 +498,7 @@ static int igd_get_stolen_mb(int gen, uint32_t gmch)
         if (gms < 0xf0)
             return gms * 32;
         else
-            return gms * 4 + 4;
+            return (gms - 0xf0) * 4 + 4;
     }
 }
 
Signature · 1 line
2.47.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Corvin Köhne

From: Corvin Köhne <[email protected]>

When copying the calculation of the stolen memory size for Intels integrated graphics device of gen 9 and later from the Linux kernel [1], we missed subtracting 0xf0 from the graphics mode select value for values above 0xf0. This leads to QEMU reporting a very large size of the graphics stolen memory area. That's just a waste of memory. Additionally the guest firmware might be unable to allocate such a large buffer.

Quoted 7 lines

[1] https://github.com/torvalds/linux/blob/7c626ce4bae1ac14f60076d00eafe71af30450ba/arch/x86/kernel/early-quirks.c#L455-L460

Fixes 8719224166832ff8230d7dd8599f42bd60e2eb96
---
  hw/vfio/igd.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by on v1 1/1
#2 lore raw
In reply to Corvin Köhne
Quoted 3 lines · On Fri, 8 Nov 2024 13:49:04 +0100 Corvin Köhne <[email protected]> wrote:

From: Corvin Köhne <[email protected]>

When copying the calculation of the stolen memory size for Intels integrated

* Intel's

Quoted 9 lines

graphics device of gen 9 and later from the Linux kernel [1], we missed subtracting 0xf0 from the graphics mode select value for values above 0xf0. This leads to QEMU reporting a very large size of the graphics stolen memory area. That's just a waste of memory. Additionally the guest firmware might be unable to allocate such a large buffer.

[1] https://github.com/torvalds/linux/blob/7c626ce4bae1ac14f60076d00eafe71af30450ba/arch/x86/kernel/early-quirks.c#L455-L460

Fixes 8719224166832ff8230d7dd8599f42bd60e2eb96
Fixes 871922416683 ("vfio/igd: correctly calculate stolen memory size for gen 9 and later")
Quoted 10 lines
---
 hw/vfio/igd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/vfio/igd.c +0 -0
index a95d441f68..732f9c37a6 100644

hw/vfio/igd.c static int igd_get_stolen_mb(int gen, uint32_t gmch) · line 504

Quoted 8 lines
hw/vfio/igd.c +1 -1
@@ -498,7 +498,7 @@ static int igd_get_stolen_mb(int gen, uint32_t gmch)
         if (gms < 0xf0)
             return gms * 32;
         else
-            return gms * 4 + 4;
+            return (gms - 0xf0) * 4 + 4;
     }
 }
 
#3 lore raw
In reply to Corvin Köhne
Quoted 9 lines · Corvin Köhne

From: Corvin Köhne <[email protected]>

When copying the calculation of the stolen memory size for Intels integrated graphics device of gen 9 and later from the Linux kernel [1], we missed subtracting 0xf0 from the graphics mode select value for values above 0xf0. This leads to QEMU reporting a very large size of the graphics stolen memory area. That's just a waste of memory. Additionally the guest firmware might be unable to allocate such a large buffer.

Quoted 4 lines

[1] https://github.com/torvalds/linux/blob/7c626ce4bae1ac14f60076d00eafe71af30450ba/arch/x86/kernel/early-quirks.c#L455-L460

Fixes 8719224166832ff8230d7dd8599f42bd60e2eb96

I changed the subject to "vfio/igd: ...."

Applied to vfio-next.

Thanks,

C.