aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2023-01-23 22:20:36 +0000
committerMichael Brown <mcb30@ipxe.org>2023-01-25 10:03:09 +0000
commit4bffe0f0d9d0e1496ae5cfb7579e813277c29b0f (patch)
tree77bc6149c1832272ec56fe271b6e2bbea6a7c1d3
parentc5426cdaa943a14183edb424b472d7e0d7e55cc3 (diff)
downloadipxe-4bffe0f0d9d0e1496ae5cfb7579e813277c29b0f.zip
ipxe-4bffe0f0d9d0e1496ae5cfb7579e813277c29b0f.tar.gz
ipxe-4bffe0f0d9d0e1496ae5cfb7579e813277c29b0f.tar.bz2
[pxe] Discard queued PXE UDP packets when under memory pressure
The PXE UDP receive queue may grow without limit if the PXE NBP does not call PXENV_UDP_READ sufficiently frequently. Fix by implementing a cache discarder for received PXE UDP packets (similar to the TCP cache discarder). Reported-by: Tal Shorer <shorer@amazon.com> Signed-off-by: Michael Brown <mcb30@ipxe.org>
-rw-r--r--src/arch/x86/interface/pxe/pxe_udp.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/arch/x86/interface/pxe/pxe_udp.c b/src/arch/x86/interface/pxe/pxe_udp.c
index 5a04f08..a5d5eb7 100644
--- a/src/arch/x86/interface/pxe/pxe_udp.c
+++ b/src/arch/x86/interface/pxe/pxe_udp.c
@@ -12,6 +12,7 @@
#include <ipxe/uaccess.h>
#include <ipxe/process.h>
#include <ipxe/netdevice.h>
+#include <ipxe/malloc.h>
#include <realmode.h>
#include <pxe.h>
@@ -482,3 +483,28 @@ struct pxe_api_call pxe_udp_api[] __pxe_api_call = {
PXE_API_CALL ( PXENV_UDP_READ, pxenv_udp_read,
struct s_PXENV_UDP_READ ),
};
+
+/**
+ * Discard some cached PXE UDP data
+ *
+ * @ret discarded Number of cached items discarded
+ */
+static unsigned int pxe_udp_discard ( void ) {
+ struct io_buffer *iobuf;
+ unsigned int discarded = 0;
+
+ /* Try to discard the oldest received UDP packet */
+ iobuf = list_first_entry ( &pxe_udp.list, struct io_buffer, list );
+ if ( iobuf ) {
+ list_del ( &iobuf->list );
+ free_iob ( iobuf );
+ discarded++;
+ }
+
+ return discarded;
+}
+
+/** PXE UDP cache discarder */
+struct cache_discarder pxe_udp_discarder __cache_discarder ( CACHE_NORMAL ) = {
+ .discard = pxe_udp_discard,
+};