hw/net: move allocation to the heap due to very large stack frame
PATCH 1/1 hw/net: move allocation to the heap due to very large stack frame
From 09905773a00e417d3a37c12350d9e55466fdce8a Mon Sep 17 00:00:00 2001
From: Elena Afanasova <[email protected]>
Date: Fri, 9 Oct 2020 06:41:36 -0700
Subject: [PATCH] hw/net: move allocation to the heap due to very large stack
frame
--- hw/net/spapr_llan.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
hw/net/spapr_llan.c +3 -2
@@ -688,7 +688,8 @@ static target_ulong h_send_logical_lan(PowerPCCPU *cpu,SpaprVioDevice *sdev =spapr_vio_find_by_reg (spapr->vio_bus, reg);SpaprVioVlan *dev =VIO_SPAPR_VLAN_DEVICE (sdev);unsigned total_len; -uint8_t *lbuf, *p; +uint8_t *p; + g_autofree uint8_t *lbuf = NULL;int i, nbufs;int ret;
@@ -729,7 +730,7 @@ static target_ulong h_send_logical_lan(PowerPCCPU *cpu,return H_RESOURCE ; } - lbuf =alloca (total_len); + lbuf =g_malloc (total_len); p = lbuf;for (i =0 ; i < nbufs; i++) { ret = spapr_vio_dma_read(sdev, VLAN_BD_ADDR(bufs[i]),
Signature · 1 line
2.25.1
Quoted 10 lines · Elena Afanasova
From
09905773a00e417d3a37c12350d9e55466fdce8aMon Sep 17 00:00:00 2001
From: Elena Afanasova <[email protected]>
Date: Fri, 9 Oct 2020 06:41:36 -0700
Subject: [PATCH] hw/net: move allocation to the heap due to very large stack
frameSigned-off-by Elena Afanasova <[email protected]>--- hw/net/spapr_llan.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
r~
Quoted 7 lines · Elena Afanasova
From
09905773a00e417d3a37c12350d9e55466fdce8aMon Sep 17 00:00:00 2001
From: Elena Afanasova <[email protected]>
Date: Fri, 9 Oct 2020 06:41:36 -0700
Subject: [PATCH] hw/net: move allocation to the heap due to very large stack
frameSigned-off-by Elena Afanasova <[email protected]>
Quoted 28 lines
--- hw/net/spapr_llan.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)hw/net/spapr_llan.c +3
-2@@ -688,7 +688,8 @@ static target_ulong h_send_logical_lan(PowerPCCPU *cpu,SpaprVioDevice *sdev =spapr_vio_find_by_reg (spapr->vio_bus, reg);SpaprVioVlan *dev =VIO_SPAPR_VLAN_DEVICE (sdev);unsigned total_len; -uint8_t *lbuf, *p; +uint8_t *p; + g_autofree uint8_t *lbuf = NULL;int i, nbufs;int ret;@@ -729,7 +730,7 @@ static target_ulong h_send_logical_lan(PowerPCCPU *cpu,return H_RESOURCE ; } - lbuf =alloca (total_len); + lbuf =g_malloc (total_len); p = lbuf;for (i =0 ; i < nbufs; i++) { ret = spapr_vio_dma_read(sdev, VLAN_BD_ADDR(bufs[i]),
Quoted 6 lines · On Fri, 09 Oct 2020 07:02:56 -0700 Elena Afanasova <[email protected]> wrote:
From
09905773a00e417d3a37c12350d9e55466fdce8aMon Sep 17 00:00:00 2001
From: Elena Afanasova <[email protected]>
Date: Fri, 9 Oct 2020 06:41:36 -0700
Subject: [PATCH] hw/net: move allocation to the heap due to very large stack
frame
Something seems to have gone wrong with the message body here, which results in an awkward changelog... but maybe someone can fix that when applying the patch.
Quoted 2 lines
Signed-off-by Elena Afanasova <[email protected]>---
Quoted 26 lines
hw/net/spapr_llan.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)hw/net/spapr_llan.c +3
-2@@ -688,7 +688,8 @@ static target_ulong h_send_logical_lan(PowerPCCPU *cpu,SpaprVioDevice *sdev =spapr_vio_find_by_reg (spapr->vio_bus, reg);SpaprVioVlan *dev =VIO_SPAPR_VLAN_DEVICE (sdev);unsigned total_len; -uint8_t *lbuf, *p; +uint8_t *p; + g_autofree uint8_t *lbuf = NULL;int i, nbufs;int ret;@@ -729,7 +730,7 @@ static target_ulong h_send_logical_lan(PowerPCCPU *cpu,return H_RESOURCE ; } - lbuf =alloca (total_len); + lbuf =g_malloc (total_len); p = lbuf;for (i =0 ; i < nbufs; i++) { ret = spapr_vio_dma_read(sdev, VLAN_BD_ADDR(bufs[i]),
Quoted 8 lines · Elena Afanasova <[email protected]> 于2020年10月9日周五 下午10:03写道:
From
09905773a00e417d3a37c12350d9e55466fdce8aMon Sep 17 00:00:00 2001
From: Elena Afanasova <[email protected]>
Date: Fri, 9 Oct 2020 06:41:36 -0700
Subject: [PATCH] hw/net: move allocation to the heap due to very large stack
frameSigned-off-by Elena Afanasova <[email protected]>
Quoted 32 lines
--- hw/net/spapr_llan.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)hw/net/spapr_llan.c +3
-3@@ -688,7 +688,8 @@ static target_ulong h_send_logical_lan(PowerPCCPU *cpu,SpaprVioDevice *sdev =spapr_vio_find_by_reg (spapr->vio_bus, reg);SpaprVioVlan *dev =VIO_SPAPR_VLAN_DEVICE (sdev);unsigned total_len; -uint8_t *lbuf, *p; +uint8_t *p; + g_autofree uint8_t *lbuf = NULL;int i, nbufs;int ret;@@ -729,7 +730,7 @@ static target_ulong h_send_logical_lan(PowerPCCPU *cpu,return H_RESOURCE ; } - lbuf =alloca (total_len); + lbuf =g_malloc (total_len); p = lbuf;for (i =0 ; i < nbufs; i++) { ret = spapr_vio_dma_read(sdev, VLAN_BD_ADDR(bufs[i]), --2.25.1
Quoted 5 lines · Elena Afanasova
Quoted 1 line
From
09905773a00e417d3a37c12350d9e55466fdce8aMon Sep 17 00:00:00 2001From: Elena Afanasova <[email protected]>
Date: Fri, 9 Oct 2020 06:41:36 -0700
Subject: [PATCH] hw/net: move allocation to the heap due to very large stack
frame
Patch looks fine, but some more details of the motivation would be nice. I wouldn't have thought that the size of a network packet counted as a "very large" stack frame by userspace standards.
Quoted 28 lines
Signed-off-by Elena Afanasova <[email protected]>--- hw/net/spapr_llan.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)hw/net/spapr_llan.c +3
-2@@ -688,7 +688,8 @@ static target_ulong h_send_logical_lan(PowerPCCPU *cpu,SpaprVioDevice *sdev =spapr_vio_find_by_reg (spapr->vio_bus, reg);SpaprVioVlan *dev =VIO_SPAPR_VLAN_DEVICE (sdev);unsigned total_len; -uint8_t *lbuf, *p; +uint8_t *p; + g_autofree uint8_t *lbuf = NULL;int i, nbufs;int ret;@@ -729,7 +730,7 @@ static target_ulong h_send_logical_lan(PowerPCCPU *cpu,return H_RESOURCE ; } - lbuf =alloca (total_len); + lbuf =g_malloc (total_len); p = lbuf;for (i =0 ; i < nbufs; i++) { ret = spapr_vio_dma_read(sdev, VLAN_BD_ADDR(bufs[i]),
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 9 lines · David Gibson
Quoted 7 lines · Elena Afanasova
Quoted 2 lines
From
09905773a00e417d3a37c12350d9e55466fdce8aMon Sep 17 00:00:00 2001From: Elena Afanasova <[email protected]>
Date: Fri, 9 Oct 2020 06:41:36 -0700
Subject: [PATCH] hw/net: move allocation to the heap due to very large stack
frame
Quoted 4 lines
Patch looks fine, but some more details of the motivation would be nice. I wouldn't have thought that the size of a network packet counted as a "very large" stack frame by userspace standards.
gcc with wstack-usage warns that stack frame size may be ~65Kbytes
Quoted 31 lines
Quoted 31 lines
Signed-off-by Elena Afanasova <[email protected]>--- hw/net/spapr_llan.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)hw/net/spapr_llan.c +2
-1@@ -688,7 +688,8 @@ static target_ulongh_send_logical_lan (PowerPCCPU *cpu, SpaprVioDevice *sdev =spapr_vio_find_by_reg (spapr->vio_bus, reg);SpaprVioVlan *dev =VIO_SPAPR_VLAN_DEVICE (sdev);unsigned total_len; -uint8_t *lbuf, *p; +uint8_t *p; + g_autofree uint8_t *lbuf = NULL;int i, nbufs;int ret;hw/net/spapr_llan.c +1
-1@@ -729,7 +730,7 @@ static target_ulongh_send_logical_lan (PowerPCCPU *cpu, return H_RESOURCE; } - lbuf = alloca(total_len); + lbuf = g_malloc(total_len); p = lbuf;for (i =0 ; i < nbufs; i++) {ret = spapr_vio_dma_read(sdev,
VLAN_BD_ADDR(bufs[i]),
Quoted 10 lines · Elena Afanasova
Quoted 9 lines · David Gibson
Quoted 7 lines · Elena Afanasova
Quoted 2 lines
From
09905773a00e417d3a37c12350d9e55466fdce8aMon Sep 17 00:00:00 2001From: Elena Afanasova <[email protected]>
Date: Fri, 9 Oct 2020 06:41:36 -0700
Subject: [PATCH] hw/net: move allocation to the heap due to very large stack
frame
Quoted 6 lines
Quoted 4 lines
Patch looks fine, but some more details of the motivation would be nice. I wouldn't have thought that the size of a network packet counted as a "very large" stack frame by userspace standards.
gcc with wstack-usage warns that stack frame size may be ~65Kbytes
AFAICT, -Wstack-usage takes a parameter giving what size it will complain about. What was that value, and what was the rationale for choosing it?
Quoted 33 lines
Quoted 32 lines
Quoted 32 lines
Signed-off-by Elena Afanasova <[email protected]>--- hw/net/spapr_llan.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)hw/net/spapr_llan.c +2
-1@@ -688,7 +688,8 @@ static target_ulongh_send_logical_lan (PowerPCCPU *cpu, SpaprVioDevice *sdev =spapr_vio_find_by_reg (spapr->vio_bus, reg);SpaprVioVlan *dev =VIO_SPAPR_VLAN_DEVICE (sdev);unsigned total_len; -uint8_t *lbuf, *p; +uint8_t *p; + g_autofree uint8_t *lbuf = NULL;int i, nbufs;int ret;hw/net/spapr_llan.c +1
-1@@ -729,7 +730,7 @@ static target_ulongh_send_logical_lan (PowerPCCPU *cpu, return H_RESOURCE; } - lbuf = alloca(total_len); + lbuf = g_malloc(total_len); p = lbuf;for (i =0 ; i < nbufs; i++) {ret = spapr_vio_dma_read(sdev,
VLAN_BD_ADDR(bufs[i]),
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 16 lines · David Gibson
Quoted 15 lines · Elena Afanasova
Quoted 13 lines · David Gibson
Quoted 7 lines · Elena Afanasova
Quoted 2 lines
From
09905773a00e417d3a37c12350d9e55466fdce8aMon Sep 17 00:00:00 2001From: Elena Afanasova <[email protected]>
Date: Fri, 9 Oct 2020 06:41:36 -0700
Subject: [PATCH] hw/net: move allocation to the heap due to very large stack
framePatch looks fine, but some more details of the motivation would be nice. I wouldn't have thought that the size of a network packet counted as a "very large" stack frame by userspace standards.
Quoted 5 lines
Quoted 1 line
gcc with wstack-usage warns that stack frame size may be ~65Kbytes
AFAICT, -Wstack-usage takes a parameter giving what size it will complain about. What was that value, and what was the rationale for choosing it?
I think this is one of the tasks from:
https://wiki.qemu.org/Contribute/BiteSizedTasks#Compiler-driven_cleanups
It has been added by Paolo in 2016:
https://wiki.qemu.org/index.php?title=Contribute/BiteSizedTasks&diff=5368&oldid=5367
... so maybe Paolo can comment on the size that has been chosen here...?
Thomas
Quoted 9 lines · Thomas Huth
I think this is one of the tasks from:
https://wiki.qemu.org/Contribute/BiteSizedTasks#Compiler-driven_cleanups
It has been added by Paolo in 2016:
https://wiki.qemu.org/index.php?title=Contribute/BiteSizedTasks&diff=5368&oldid=5367
... so maybe Paolo can comment on the size that has been chosen here...?
I used 16K, mostly because it is a nice round number. 8k is too small due to PATH_MAX-sized variables. 16k seemed to be plenty and triggered in few-enough places that the cleanup is viable.
Paolo
Quoted 7 lines · Paolo Bonzini
Quoted 6 lines · Thomas Huth
I think this is one of the tasks from:
https://wiki.qemu.org/Contribute/BiteSizedTasks#Compiler-driven_cleanups
It has been added by Paolo in 2016:
Quoted 7 lines
Quoted 3 lines
https://wiki.qemu.org/index.php?title=Contribute/BiteSizedTasks&diff=5368&oldid=5367
... so maybe Paolo can comment on the size that has been chosen here...?
I used 16K, mostly because it is a nice round number. 8k is too small due to PATH_MAX-sized variables. 16k seemed to be plenty and triggered in few-enough places that the cleanup is viable.
Ok. Why are large stack frames bad in qemu?
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 15 lines · David Gibson
Quoted 14 lines · Paolo Bonzini
Quoted 12 lines · Thomas Huth
I think this is one of the tasks from:
https://wiki.qemu.org/Contribute/BiteSizedTasks#Compiler-driven_cleanups
It has been added by Paolo in 2016:
https://wiki.qemu.org/index.php?title=Contribute/BiteSizedTasks&diff=5368&oldid=5367
... so maybe Paolo can comment on the size that has been chosen here...?
Quoted 8 lines
Quoted 5 lines
I used 16K, mostly because it is a nice round number. 8k is too small
due to PATH_MAX-sized variables. 16k seemed to be plenty and triggered
in few-enough places that the cleanup is viable.Ok. Why are large stack frames bad in qemu?
I think that the main issue here is alloca() because it can lead to UB.
Quoted 22 lines · Elena Afanasova
Quoted 21 lines · David Gibson
Quoted 19 lines · Paolo Bonzini
Quoted 5 lines · Thomas Huth
I think this is one of the tasks from:
https://wiki.qemu.org/Contribute/BiteSizedTasks#Compiler-driven_cleanups
Quoted 7 lines
It has been added by Paolo in 2016:
https://wiki.qemu.org/index.php?title=Contribute/BiteSizedTasks&diff=5368&oldid=5367
... so maybe Paolo can comment on the size that has been chosen here...?
I used 16K, mostly because it is a nice round number. 8k is too small
due to PATH_MAX-sized variables. 16k seemed to be plenty and triggered
in few-enough places that the cleanup is viable.
Quoted 4 lines
Quoted 2 lines
Ok. Why are large stack frames bad in qemu?
I think that the main issue here is
alloca()because it can lead to UB.
That's a fair point. I've applied the patch to ppc-for-5.2, with a tweak to the commit message.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 12 lines · David Gibson <[email protected]> 于2020年10月10日周六 下午2:34写道:
Quoted 5 lines · Elena Afanasova
Quoted 1 line
From
09905773a00e417d3a37c12350d9e55466fdce8aMon Sep 17 00:00:00 2001From: Elena Afanasova <[email protected]>
Date: Fri, 9 Oct 2020 06:41:36 -0700
Subject: [PATCH] hw/net: move allocation to the heap due to very large stack
framePatch looks fine, but some more details of the motivation would be nice. I wouldn't have thought that the size of a network packet counted as a "very large" stack frame by userspace standards.
It is also a best practice to avoid large stack allocation according. -->https://wiki.sei.cmu.edu/confluence/display/c/MEM05-C.+Avoid+large+stack+allocations
Though I don't see any issue here.
Thanks,
Li Qiang
Quoted 34 lines
Quoted 20 lines
Signed-off-by Elena Afanasova <[email protected]>--- hw/net/spapr_llan.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)hw/net/spapr_llan.c +2
-1@@ -688,7 +688,8 @@ static target_ulong h_send_logical_lan(PowerPCCPU *cpu,SpaprVioDevice *sdev =spapr_vio_find_by_reg (spapr->vio_bus, reg);SpaprVioVlan *dev =VIO_SPAPR_VLAN_DEVICE (sdev);unsigned total_len; -uint8_t *lbuf, *p; +uint8_t *p; + g_autofree uint8_t *lbuf = NULL;int i, nbufs;int ret;hw/net/spapr_llan.c static target_ulong h_send_logical_lan(PowerPCCPU *cpu, · line 736
Quoted 8 lines
hw/net/spapr_llan.c +1
-1@@ -729,7 +730,7 @@ static target_ulong h_send_logical_lan(PowerPCCPU *cpu,return H_RESOURCE ; } - lbuf =alloca (total_len); + lbuf =g_malloc (total_len); p = lbuf;for (i =0 ; i < nbufs; i++) { ret = spapr_vio_dma_read(sdev, VLAN_BD_ADDR(bufs[i]),--
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_!
Quoted 9 lines · Li Qiang
Quoted 8 lines · David Gibson <[email protected]> 于2020年10月10日周六 下午2:34写道:
Quoted 5 lines · Elena Afanasova
Quoted 1 line
From
09905773a00e417d3a37c12350d9e55466fdce8aMon Sep 17 00:00:00 2001From: Elena Afanasova <[email protected]>
Date: Fri, 9 Oct 2020 06:41:36 -0700
Subject: [PATCH] hw/net: move allocation to the heap due to very large stack
frame
Quoted 7 lines
Quoted 4 lines
Patch looks fine, but some more details of the motivation would be nice. I wouldn't have thought that the size of a network packet counted as a "very large" stack frame by userspace standards.
It is also a best practice to avoid large stack allocation according. -->https://wiki.sei.cmu.edu/confluence/display/c/MEM05-C.+Avoid+large+stack+allocations
Hm, yeah, it's not really clear what "large" means in that context. It mostly seems to be concerned with allocations controlled by an external attacker, in which case we could be talking up to INT_MAX. Even with jumbo frames the most we're talking here is ~64kiB.
Quoted 36 lines
Though I don't see any issue here.
Thanks,
Li QiangQuoted 29 lines
Quoted 28 lines
Signed-off-by Elena Afanasova <[email protected]>--- hw/net/spapr_llan.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)hw/net/spapr_llan.c +3
-2@@ -688,7 +688,8 @@ static target_ulong h_send_logical_lan(PowerPCCPU *cpu,SpaprVioDevice *sdev =spapr_vio_find_by_reg (spapr->vio_bus, reg);SpaprVioVlan *dev =VIO_SPAPR_VLAN_DEVICE (sdev);unsigned total_len; -uint8_t *lbuf, *p; +uint8_t *p; + g_autofree uint8_t *lbuf = NULL;int i, nbufs;int ret;@@ -729,7 +730,7 @@ static target_ulong h_send_logical_lan(PowerPCCPU *cpu,return H_RESOURCE ; } - lbuf =alloca (total_len); + lbuf =g_malloc (total_len); p = lbuf;for (i =0 ; i < nbufs; i++) { ret = spapr_vio_dma_read(sdev, VLAN_BD_ADDR(bufs[i]),
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 10 lines · David Gibson
Quoted 5 lines · Elena Afanasova
Quoted 1 line
From
09905773a00e417d3a37c12350d9e55466fdce8aMon Sep 17 00:00:00 2001From: Elena Afanasova <[email protected]>
Date: Fri, 9 Oct 2020 06:41:36 -0700
Subject: [PATCH] hw/net: move allocation to the heap due to very large stack
framePatch looks fine, but some more details of the motivation would be nice. I wouldn't have thought that the size of a network packet counted as a "very large" stack frame by userspace standards.
Maybe academia doing research on "super jumbo frames"?
"Super jumbo frames ... increase the path MTU of high-performance national research and education networks from 1500 bytes to 9000 bytes or so, a subsequent increase, possibly to 64,000 bytes"
(https://en.wikipedia.org/wiki/Jumbo_frame#Super_jumbo_frames)
Quoted 30 lines
Quoted 29 lines
Signed-off-by Elena Afanasova <[email protected]>--- hw/net/spapr_llan.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)hw/net/spapr_llan.c +3
-2@@ -688,7 +688,8 @@ static target_ulong h_send_logical_lan(PowerPCCPU *cpu,SpaprVioDevice *sdev =spapr_vio_find_by_reg (spapr->vio_bus, reg);SpaprVioVlan *dev =VIO_SPAPR_VLAN_DEVICE (sdev);unsigned total_len; -uint8_t *lbuf, *p; +uint8_t *p; + g_autofree uint8_t *lbuf = NULL;int i, nbufs;int ret;@@ -729,7 +730,7 @@ static target_ulong h_send_logical_lan(PowerPCCPU *cpu,return H_RESOURCE ; } - lbuf =alloca (total_len); + lbuf =g_malloc (total_len); p = lbuf;for (i =0 ; i < nbufs; i++) { ret = spapr_vio_dma_read(sdev, VLAN_BD_ADDR(bufs[i]),
Quoted 12 lines · Philippe Mathieu-Daudé
Quoted 10 lines · David Gibson
Quoted 5 lines · Elena Afanasova
Quoted 1 line
From
09905773a00e417d3a37c12350d9e55466fdce8aMon Sep 17 00:00:00 2001From: Elena Afanasova <[email protected]>
Date: Fri, 9 Oct 2020 06:41:36 -0700
Subject: [PATCH] hw/net: move allocation to the heap due to very large stack framePatch looks fine, but some more details of the motivation would be nice. I wouldn't have thought that the size of a network packet counted as a "very large" stack frame by userspace standards.
Quoted 7 lines
Maybe academia doing research on "super jumbo frames"?
"Super jumbo frames ... increase the path MTU of high-performance national research and education networks from 1500 bytes to 9000 bytes or so, a subsequent increase, possibly to 64,000 bytes"
(https://en.wikipedia.org/wiki/Jumbo_frame#Super_jumbo_frames)
The one I was actually looking for is the IPv6 jumbogram:
"An optional feature of IPv6, the jumbo payload option, allows the exchange of packets with payloads of up to one byte less than 4 GiB, by making use of a 32-bit length field."