summaryrefslogtreecommitdiffstats
path: root/src/arch/x86/interface
diff options
context:
space:
mode:
authorSimon Rettberg2023-04-04 15:12:41 +0200
committerSimon Rettberg2023-04-04 15:12:41 +0200
commit5ba496dce11d10198a0eae0c8440dccb256fbf32 (patch)
tree549903f1dab893870335a6e4767a4530444d2e83 /src/arch/x86/interface
parent[vesafb] Map Unicode characters to CP437 if possible (diff)
parent[tls] Handle fragmented handshake records (diff)
downloadipxe-5ba496dce11d10198a0eae0c8440dccb256fbf32.tar.gz
ipxe-5ba496dce11d10198a0eae0c8440dccb256fbf32.tar.xz
ipxe-5ba496dce11d10198a0eae0c8440dccb256fbf32.zip
Merge branch 'master' into openslx
Diffstat (limited to 'src/arch/x86/interface')
-rw-r--r--src/arch/x86/interface/pcbios/bios_cachedhcp.c2
-rw-r--r--src/arch/x86/interface/pcbios/rtc_entropy.c52
-rw-r--r--src/arch/x86/interface/pxe/pxe_udp.c26
3 files changed, 68 insertions, 12 deletions
diff --git a/src/arch/x86/interface/pcbios/bios_cachedhcp.c b/src/arch/x86/interface/pcbios/bios_cachedhcp.c
index 277c40d6f..bea803d6e 100644
--- a/src/arch/x86/interface/pcbios/bios_cachedhcp.c
+++ b/src/arch/x86/interface/pcbios/bios_cachedhcp.c
@@ -59,7 +59,7 @@ static void cachedhcp_init ( void ) {
}
/* Record cached DHCPACK */
- if ( ( rc = cachedhcp_record ( &cached_dhcpack,
+ if ( ( rc = cachedhcp_record ( &cached_dhcpack, 0,
phys_to_user ( cached_dhcpack_phys ),
sizeof ( BOOTPLAYER_t ) ) ) != 0 ) {
DBGC ( colour, "CACHEDHCP could not record DHCPACK: %s\n",
diff --git a/src/arch/x86/interface/pcbios/rtc_entropy.c b/src/arch/x86/interface/pcbios/rtc_entropy.c
index e0c175685..8f47ff6b8 100644
--- a/src/arch/x86/interface/pcbios/rtc_entropy.c
+++ b/src/arch/x86/interface/pcbios/rtc_entropy.c
@@ -39,9 +39,14 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/cpuid.h>
#include <ipxe/entropy.h>
+struct entropy_source rtc_entropy __entropy_source ( ENTROPY_NORMAL );
+
/** Maximum time to wait for an RTC interrupt, in milliseconds */
#define RTC_MAX_WAIT_MS 100
+/** Number of RTC interrupts to check for */
+#define RTC_CHECK_COUNT 3
+
/** RTC interrupt handler */
extern void rtc_isr ( void );
@@ -145,6 +150,7 @@ static void rtc_disable_int ( void ) {
* @ret rc Return status code
*/
static int rtc_entropy_check ( void ) {
+ unsigned int count = 0;
unsigned int i;
/* Check that RTC interrupts are working */
@@ -158,14 +164,18 @@ static int rtc_entropy_check ( void ) {
"cli\n\t" );
/* Check for RTC interrupt flag */
- if ( rtc_flag )
- return 0;
+ if ( rtc_flag ) {
+ rtc_flag = 0;
+ if ( ++count >= RTC_CHECK_COUNT )
+ return 0;
+ }
/* Delay */
mdelay ( 1 );
}
- DBGC ( &rtc_flag, "RTC timed out waiting for interrupt\n" );
+ DBGC ( &rtc_flag, "RTC timed out waiting for interrupt %d/%d\n",
+ ( count + 1 ), RTC_CHECK_COUNT );
return -ETIMEDOUT;
}
@@ -195,6 +205,21 @@ static int rtc_entropy_enable ( void ) {
if ( ( rc = rtc_entropy_check() ) != 0 )
goto err_check;
+ /* The min-entropy has been measured on several platforms
+ * using the entropy_sample test code. Modelling the samples
+ * as independent, and using a confidence level of 99.99%, the
+ * measurements were as follows:
+ *
+ * qemu-kvm : 7.38 bits
+ * VMware : 7.46 bits
+ * Physical hardware : 2.67 bits
+ *
+ * We choose the lowest of these (2.67 bits) and apply a 50%
+ * safety margin to allow for some potential non-independence
+ * of samples.
+ */
+ entropy_init ( &rtc_entropy, MIN_ENTROPY ( 1.3 ) );
+
return 0;
err_check:
@@ -218,11 +243,12 @@ static void rtc_entropy_disable ( void ) {
}
/**
- * Measure a single RTC tick
+ * Get noise sample
*
- * @ret delta Length of RTC tick (in TSC units)
+ * @ret noise Noise sample
+ * @ret rc Return status code
*/
-uint8_t rtc_sample ( void ) {
+static int rtc_get_noise ( noise_sample_t *noise ) {
uint32_t before;
uint32_t after;
uint32_t temp;
@@ -257,10 +283,14 @@ uint8_t rtc_sample ( void ) {
: "=a" ( after ), "=d" ( before ), "=Q" ( temp )
: "2" ( 0 ) );
- return ( after - before );
+ *noise = ( after - before );
+ return 0;
}
-PROVIDE_ENTROPY_INLINE ( rtc, min_entropy_per_sample );
-PROVIDE_ENTROPY ( rtc, entropy_enable, rtc_entropy_enable );
-PROVIDE_ENTROPY ( rtc, entropy_disable, rtc_entropy_disable );
-PROVIDE_ENTROPY_INLINE ( rtc, get_noise );
+/** RTC entropy source */
+struct entropy_source rtc_entropy __entropy_source ( ENTROPY_NORMAL ) = {
+ .name = "rtc",
+ .enable = rtc_entropy_enable,
+ .disable = rtc_entropy_disable,
+ .get_noise = rtc_get_noise,
+};
diff --git a/src/arch/x86/interface/pxe/pxe_udp.c b/src/arch/x86/interface/pxe/pxe_udp.c
index 5a04f0865..a5d5eb77b 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,
+};