From 7c82ff0b6b12437bfc25d01d52308fc6fe2e1311 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 15 Aug 2024 08:46:41 +0100 Subject: [pci] Separate permission to probe buses from bus:dev.fn range discovery The UEFI device model requires us to not probe the PCI bus directly, but instead to wait to be offered the opportunity to drive devices via our driver service binding handle. We currently inhibit PCI bus probing by having pci_discover() return an empty range when using the EFI PCI I/O API. This has the unwanted side effect that scanning the bus manually using the "pciscan" command will also fail to discover any devices. Separate out the concept of being allowed to probe PCI buses from the mechanism for discovering PCI bus:dev.fn address ranges, so that this limitation may be removed. Signed-off-by: Michael Brown --- src/interface/linux/linux_pci.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/interface/linux') diff --git a/src/interface/linux/linux_pci.c b/src/interface/linux/linux_pci.c index 300844737..a3a0828c1 100644 --- a/src/interface/linux/linux_pci.c +++ b/src/interface/linux/linux_pci.c @@ -188,6 +188,7 @@ int linux_pci_write ( struct pci_device *pci, unsigned long where, return rc; } +PROVIDE_PCIAPI_INLINE ( linux, pci_can_probe ); PROVIDE_PCIAPI_INLINE ( linux, pci_discover ); PROVIDE_PCIAPI_INLINE ( linux, pci_read_config_byte ); PROVIDE_PCIAPI_INLINE ( linux, pci_read_config_word ); -- cgit v1.2.3-55-g7522 From ef038491858cb51f8aa17b1f6e50444d2e627413 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sun, 20 Apr 2025 18:45:55 +0100 Subject: [uaccess] Remove redundant userptr_add() and userptr_diff() The userptr_add() and userptr_diff() functions are now just straightforward wrappers around addition and subtraction. Remove these redundant wrappers. Signed-off-by: Michael Brown --- src/arch/x86/image/bzimage.c | 12 +++--- src/arch/x86/image/initrd.c | 25 ++++++------ src/arch/x86/image/nbi.c | 4 +- src/arch/x86/include/librm.h | 11 ------ src/arch/x86/interface/pcbios/memtop_umalloc.c | 10 ++--- src/arch/x86/transitions/librm_mgmt.c | 1 - src/core/sanboot.c | 2 +- src/core/uaccess.c | 1 - src/drivers/net/gve.c | 2 +- src/image/gzip.c | 2 +- src/include/ipxe/linux/linux_uaccess.h | 11 ------ src/include/ipxe/uaccess.h | 53 -------------------------- src/interface/linux/linux_uaccess.c | 1 - 13 files changed, 27 insertions(+), 108 deletions(-) (limited to 'src/interface/linux') diff --git a/src/arch/x86/image/bzimage.c b/src/arch/x86/image/bzimage.c index b4a78cdfc..d00b9f155 100644 --- a/src/arch/x86/image/bzimage.c +++ b/src/arch/x86/image/bzimage.c @@ -431,7 +431,7 @@ static int bzimage_check_initrds ( struct image *image, } /* Calculate lowest usable address */ - bottom = userptr_add ( bzimg->pm_kernel, bzimg->pm_sz ); + bottom = ( bzimg->pm_kernel + bzimg->pm_sz ); /* Check that total length fits within space available for * reshuffling. This is a conservative check, since CPIO @@ -471,14 +471,12 @@ static void bzimage_load_initrds ( struct image *image, size_t len; /* Reshuffle initrds into desired order */ - initrd_reshuffle ( userptr_add ( bzimg->pm_kernel, bzimg->pm_sz ) ); + initrd_reshuffle ( bzimg->pm_kernel + bzimg->pm_sz ); /* Find highest initrd */ for_each_image ( initrd ) { - if ( ( highest == NULL ) || - ( userptr_diff ( initrd->data, highest->data ) > 0 ) ) { + if ( ( highest == NULL ) || ( initrd->data > highest->data ) ) highest = initrd; - } } /* Do nothing if there are no initrds */ @@ -486,7 +484,7 @@ static void bzimage_load_initrds ( struct image *image, return; /* Find highest usable address */ - top = userptr_add ( highest->data, bzimage_align ( highest->len ) ); + top = ( highest->data + bzimage_align ( highest->len ) ); if ( user_to_phys ( top, -1 ) > bzimg->mem_limit ) { top = phys_to_user ( ( bzimg->mem_limit + 1 ) & ~( INITRD_ALIGN - 1 ) ); @@ -509,7 +507,7 @@ static void bzimage_load_initrds ( struct image *image, } /* Load initrd at this address */ - dest = userptr_add ( top, -offset ); + dest = ( top - offset ); len = bzimage_load_initrd ( image, initrd, dest ); /* Record initrd location */ diff --git a/src/arch/x86/image/initrd.c b/src/arch/x86/image/initrd.c index c0a56b7f6..e32e40341 100644 --- a/src/arch/x86/image/initrd.c +++ b/src/arch/x86/image/initrd.c @@ -61,10 +61,9 @@ static userptr_t initrd_squash_high ( userptr_t top ) { /* Find the highest image not yet in its final position */ highest = NULL; for_each_image ( initrd ) { - if ( ( userptr_diff ( initrd->data, current ) < 0 ) && + if ( ( initrd->data < current ) && ( ( highest == NULL ) || - ( userptr_diff ( initrd->data, - highest->data ) > 0 ) ) ) { + ( initrd->data > highest->data ) ) ) { highest = initrd; } } @@ -74,7 +73,7 @@ static userptr_t initrd_squash_high ( userptr_t top ) { /* Move this image to its final position */ len = ( ( highest->len + INITRD_ALIGN - 1 ) & ~( INITRD_ALIGN - 1 ) ); - current = userptr_add ( current, -len ); + current -= len; DBGC ( &images, "INITRD squashing %s [%#08lx,%#08lx)->" "[%#08lx,%#08lx)\n", highest->name, user_to_phys ( highest->data, 0 ), @@ -87,10 +86,10 @@ static userptr_t initrd_squash_high ( userptr_t top ) { /* Copy any remaining initrds (e.g. embedded images) to the region */ for_each_image ( initrd ) { - if ( userptr_diff ( initrd->data, top ) >= 0 ) { + if ( initrd->data >= top ) { len = ( ( initrd->len + INITRD_ALIGN - 1 ) & ~( INITRD_ALIGN - 1 ) ); - current = userptr_add ( current, -len ); + current -= len; DBGC ( &images, "INITRD copying %s [%#08lx,%#08lx)->" "[%#08lx,%#08lx)\n", initrd->name, user_to_phys ( initrd->data, 0 ), @@ -149,7 +148,7 @@ static void initrd_swap ( struct image *low, struct image *high, /* Adjust data pointers */ high->data = low->data; - low->data = userptr_add ( low->data, len ); + low->data += len; } /** @@ -171,7 +170,7 @@ static int initrd_swap_any ( userptr_t free, size_t free_len ) { /* Calculate location of adjacent image (if any) */ padded_len = ( ( low->len + INITRD_ALIGN - 1 ) & ~( INITRD_ALIGN - 1 ) ); - adjacent = userptr_add ( low->data, padded_len ); + adjacent = ( low->data + padded_len ); /* Search for adjacent image */ for_each_image ( high ) { @@ -235,7 +234,7 @@ void initrd_reshuffle ( userptr_t bottom ) { /* Calculate limits of available space for initrds */ top = initrd_top; - if ( userptr_diff ( initrd_bottom, bottom ) > 0 ) + if ( initrd_bottom > bottom ) bottom = initrd_bottom; /* Debug */ @@ -248,7 +247,7 @@ void initrd_reshuffle ( userptr_t bottom ) { /* Calculate available free space */ free = bottom; - free_len = userptr_diff ( used, free ); + free_len = ( used - free ); /* Bubble-sort initrds into desired order */ while ( initrd_swap_any ( free, free_len ) ) {} @@ -270,9 +269,9 @@ int initrd_reshuffle_check ( size_t len, userptr_t bottom ) { /* Calculate limits of available space for initrds */ top = initrd_top; - if ( userptr_diff ( initrd_bottom, bottom ) > 0 ) + if ( initrd_bottom > bottom ) bottom = initrd_bottom; - available = userptr_diff ( top, bottom ); + available = ( top - bottom ); /* Allow for a sensible minimum amount of free space */ len += INITRD_MIN_FREE_LEN; @@ -296,7 +295,7 @@ static void initrd_startup ( void ) { * can safely reuse when rearranging). */ len = largest_memblock ( &initrd_bottom ); - initrd_top = userptr_add ( initrd_bottom, len ); + initrd_top = ( initrd_bottom + len ); } /** initrd startup function */ diff --git a/src/arch/x86/image/nbi.c b/src/arch/x86/image/nbi.c index b691bee20..2f0d3164a 100644 --- a/src/arch/x86/image/nbi.c +++ b/src/arch/x86/image/nbi.c @@ -184,10 +184,10 @@ static int nbi_process_segments ( struct image *image, dest = phys_to_user ( sh.loadaddr ); break; case NBI_LOADADDR_AFTER: - dest = userptr_add ( dest, memsz + sh.loadaddr ); + dest = ( dest + memsz + sh.loadaddr ); break; case NBI_LOADADDR_BEFORE: - dest = userptr_add ( dest, -sh.loadaddr ); + dest = ( dest - sh.loadaddr ); break; case NBI_LOADADDR_END: /* Not correct according to the spec, but diff --git a/src/arch/x86/include/librm.h b/src/arch/x86/include/librm.h index 23ca4650f..c0d910287 100644 --- a/src/arch/x86/include/librm.h +++ b/src/arch/x86/include/librm.h @@ -137,17 +137,6 @@ UACCESS_INLINE ( librm, user_to_virt ) ( userptr_t userptr, off_t offset ) { return trivial_user_to_virt ( userptr, offset ); } -static inline __always_inline userptr_t -UACCESS_INLINE ( librm, userptr_add ) ( userptr_t userptr, off_t offset ) { - return trivial_userptr_add ( userptr, offset ); -} - -static inline __always_inline off_t -UACCESS_INLINE ( librm, userptr_diff ) ( userptr_t userptr, - userptr_t subtrahend ) { - return trivial_userptr_diff ( userptr, subtrahend ); -} - static inline __always_inline void UACCESS_INLINE ( librm, memcpy_user ) ( userptr_t dest, off_t dest_off, userptr_t src, off_t src_off, diff --git a/src/arch/x86/interface/pcbios/memtop_umalloc.c b/src/arch/x86/interface/pcbios/memtop_umalloc.c index 1cc3aff91..e76b3df93 100644 --- a/src/arch/x86/interface/pcbios/memtop_umalloc.c +++ b/src/arch/x86/interface/pcbios/memtop_umalloc.c @@ -122,7 +122,7 @@ static void init_eheap ( void ) { userptr_t base; heap_size = largest_memblock ( &base ); - bottom = top = userptr_add ( base, heap_size ); + bottom = top = ( base + heap_size ); DBG ( "External heap grows downwards from %lx (size %zx)\n", user_to_phys ( top, 0 ), heap_size ); } @@ -144,7 +144,7 @@ static void ecollect_free ( void ) { DBG ( "EXTMEM freeing [%lx,%lx)\n", user_to_phys ( bottom, 0 ), user_to_phys ( bottom, extmem.size ) ); len = ( extmem.size + sizeof ( extmem ) ); - bottom = userptr_add ( bottom, len ); + bottom += len; heap_size += len; } } @@ -179,7 +179,7 @@ static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) { DBG ( "EXTMEM out of space\n" ); return UNULL; } - ptr = bottom = userptr_add ( bottom, -sizeof ( extmem ) ); + ptr = bottom = ( bottom - sizeof ( extmem ) ); heap_size -= sizeof ( extmem ); DBG ( "EXTMEM allocating [%lx,%lx)\n", user_to_phys ( ptr, 0 ), user_to_phys ( ptr, 0 ) ); @@ -190,10 +190,10 @@ static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) { /* Expand/shrink block if possible */ if ( ptr == bottom ) { /* Update block */ - new = userptr_add ( ptr, - ( new_size - extmem.size ) ); + new = ( ptr - ( new_size - extmem.size ) ); align = ( user_to_phys ( new, 0 ) & ( EM_ALIGN - 1 ) ); new_size += align; - new = userptr_add ( new, -align ); + new -= align; if ( new_size > ( heap_size + extmem.size ) ) { DBG ( "EXTMEM out of space\n" ); return UNULL; diff --git a/src/arch/x86/transitions/librm_mgmt.c b/src/arch/x86/transitions/librm_mgmt.c index b3820589c..ec31fceb1 100644 --- a/src/arch/x86/transitions/librm_mgmt.c +++ b/src/arch/x86/transitions/librm_mgmt.c @@ -432,7 +432,6 @@ PROVIDE_UACCESS_INLINE ( librm, phys_to_user ); PROVIDE_UACCESS_INLINE ( librm, user_to_phys ); PROVIDE_UACCESS_INLINE ( librm, virt_to_user ); PROVIDE_UACCESS_INLINE ( librm, user_to_virt ); -PROVIDE_UACCESS_INLINE ( librm, userptr_add ); PROVIDE_UACCESS_INLINE ( librm, memcpy_user ); PROVIDE_UACCESS_INLINE ( librm, memmove_user ); PROVIDE_UACCESS_INLINE ( librm, memset_user ); diff --git a/src/core/sanboot.c b/src/core/sanboot.c index e49a3f92d..4facf86b8 100644 --- a/src/core/sanboot.c +++ b/src/core/sanboot.c @@ -625,7 +625,7 @@ static int sandev_rw ( struct san_device *sandev, uint64_t lba, /* Move to next fragment */ frag_len = ( sandev->capacity.blksize * params.rw.count ); - params.rw.buffer = userptr_add ( params.rw.buffer, frag_len ); + params.rw.buffer += frag_len; params.rw.lba += params.rw.count; remaining -= params.rw.count; } diff --git a/src/core/uaccess.c b/src/core/uaccess.c index d3a9ca17d..ad17a58ab 100644 --- a/src/core/uaccess.c +++ b/src/core/uaccess.c @@ -36,7 +36,6 @@ PROVIDE_UACCESS_INLINE ( flat, phys_to_user ); PROVIDE_UACCESS_INLINE ( flat, user_to_phys ); PROVIDE_UACCESS_INLINE ( flat, virt_to_user ); PROVIDE_UACCESS_INLINE ( flat, user_to_virt ); -PROVIDE_UACCESS_INLINE ( flat, userptr_add ); PROVIDE_UACCESS_INLINE ( flat, memcpy_user ); PROVIDE_UACCESS_INLINE ( flat, memmove_user ); PROVIDE_UACCESS_INLINE ( flat, memset_user ); diff --git a/src/drivers/net/gve.c b/src/drivers/net/gve.c index efc38dd21..805feee3d 100644 --- a/src/drivers/net/gve.c +++ b/src/drivers/net/gve.c @@ -807,7 +807,7 @@ static inline __attribute__ (( always_inline )) userptr_t gve_buffer ( struct gve_queue *queue, unsigned int index ) { /* Pages are currently allocated as a single contiguous block */ - return userptr_add ( queue->qpl.data, gve_address ( queue, index ) ); + return ( queue->qpl.data + gve_address ( queue, index ) ); } /** diff --git a/src/image/gzip.c b/src/image/gzip.c index 98376e113..116d912d7 100644 --- a/src/image/gzip.c +++ b/src/image/gzip.c @@ -111,7 +111,7 @@ static int gzip_extract ( struct image *image, struct image *extracted ) { } /* Initialise input chunk */ - deflate_chunk_init ( &in, userptr_add ( image->data, offset ), 0, len ); + deflate_chunk_init ( &in, ( image->data + offset ), 0, len ); /* Presize extracted image */ if ( ( rc = image_set_len ( extracted, diff --git a/src/include/ipxe/linux/linux_uaccess.h b/src/include/ipxe/linux/linux_uaccess.h index 1e31afd9c..790c75123 100644 --- a/src/include/ipxe/linux/linux_uaccess.h +++ b/src/include/ipxe/linux/linux_uaccess.h @@ -69,17 +69,6 @@ UACCESS_INLINE ( linux, user_to_virt ) ( userptr_t userptr, off_t offset ) { return trivial_user_to_virt ( userptr, offset ); } -static inline __always_inline userptr_t -UACCESS_INLINE ( linux, userptr_add ) ( userptr_t userptr, off_t offset ) { - return trivial_userptr_add ( userptr, offset ); -} - -static inline __always_inline off_t -UACCESS_INLINE ( linux, userptr_diff ) ( userptr_t userptr, - userptr_t subtrahend ) { - return trivial_userptr_diff ( userptr, subtrahend ); -} - static inline __always_inline void UACCESS_INLINE ( linux, memcpy_user ) ( userptr_t dest, off_t dest_off, userptr_t src, off_t src_off, diff --git a/src/include/ipxe/uaccess.h b/src/include/ipxe/uaccess.h index 1790e4066..93dc60d62 100644 --- a/src/include/ipxe/uaccess.h +++ b/src/include/ipxe/uaccess.h @@ -65,30 +65,6 @@ trivial_user_to_virt ( userptr_t userptr, off_t offset ) { return ( ( void * ) userptr + offset ); } -/** - * Add offset to user pointer - * - * @v userptr User pointer - * @v offset Offset - * @ret userptr New pointer value - */ -static inline __always_inline userptr_t -trivial_userptr_add ( userptr_t userptr, off_t offset ) { - return ( userptr + offset ); -} - -/** - * Subtract user pointers - * - * @v userptr User pointer - * @v subtrahend User pointer to be subtracted - * @ret offset Offset - */ -static inline __always_inline off_t -trivial_userptr_diff ( userptr_t userptr, userptr_t subtrahend ) { - return ( userptr - subtrahend ); -} - /** * Copy data between user buffers * @@ -231,17 +207,6 @@ UACCESS_INLINE ( flat, user_to_virt ) ( userptr_t userptr, off_t offset ) { return trivial_user_to_virt ( userptr, offset ); } -static inline __always_inline userptr_t -UACCESS_INLINE ( flat, userptr_add ) ( userptr_t userptr, off_t offset ) { - return trivial_userptr_add ( userptr, offset ); -} - -static inline __always_inline off_t -UACCESS_INLINE ( flat, userptr_diff ) ( userptr_t userptr, - userptr_t subtrahend ) { - return trivial_userptr_diff ( userptr, subtrahend ); -} - static inline __always_inline void UACCESS_INLINE ( flat, memcpy_user ) ( userptr_t dest, off_t dest_off, userptr_t src, off_t src_off, @@ -322,24 +287,6 @@ userptr_t virt_to_user ( volatile const void *addr ); */ void * user_to_virt ( userptr_t userptr, off_t offset ); -/** - * Add offset to user pointer - * - * @v userptr User pointer - * @v offset Offset - * @ret userptr New pointer value - */ -userptr_t userptr_add ( userptr_t userptr, off_t offset ); - -/** - * Subtract user pointers - * - * @v userptr User pointer - * @v subtrahend User pointer to be subtracted - * @ret offset Offset - */ -off_t userptr_diff ( userptr_t userptr, userptr_t subtrahend ); - /** * Convert virtual address to a physical address * diff --git a/src/interface/linux/linux_uaccess.c b/src/interface/linux/linux_uaccess.c index ea2d8057c..9fc99c5e2 100644 --- a/src/interface/linux/linux_uaccess.c +++ b/src/interface/linux/linux_uaccess.c @@ -30,7 +30,6 @@ FILE_LICENCE(GPL2_OR_LATER); PROVIDE_UACCESS_INLINE(linux, user_to_phys); PROVIDE_UACCESS_INLINE(linux, virt_to_user); PROVIDE_UACCESS_INLINE(linux, user_to_virt); -PROVIDE_UACCESS_INLINE(linux, userptr_add); PROVIDE_UACCESS_INLINE(linux, memcpy_user); PROVIDE_UACCESS_INLINE(linux, memmove_user); PROVIDE_UACCESS_INLINE(linux, memset_user); -- cgit v1.2.3-55-g7522 From 89fe7886897be76ed902317e311d60ae654057aa Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sun, 20 Apr 2025 18:29:48 +0100 Subject: [uaccess] Remove redundant memcpy_user() and related string functions The memcpy_user(), memmove_user(), memcmp_user(), memset_user(), and strlen_user() functions are now just straightforward wrappers around the corresponding standard library functions. Remove these redundant wrappers. Signed-off-by: Michael Brown --- src/arch/x86/core/runtime.c | 2 +- src/arch/x86/image/bzimage.c | 13 +- src/arch/x86/image/com32.c | 2 +- src/arch/x86/image/comboot.c | 4 +- src/arch/x86/image/initrd.c | 12 +- src/arch/x86/image/multiboot.c | 6 +- src/arch/x86/image/nbi.c | 2 +- src/arch/x86/image/pxe_image.c | 2 +- src/arch/x86/image/sdi.c | 4 +- src/arch/x86/image/ucode.c | 2 +- src/arch/x86/include/librm.h | 32 ----- src/arch/x86/interface/pcbios/memtop_umalloc.c | 4 +- src/arch/x86/interface/pxe/pxe_file.c | 6 +- src/arch/x86/interface/syslinux/com32_call.c | 20 ++- src/arch/x86/interface/syslinux/comboot_call.c | 20 +-- src/arch/x86/transitions/librm_mgmt.c | 8 +- src/core/fbcon.c | 24 ++-- src/core/image.c | 2 +- src/core/uaccess.c | 4 - src/crypto/deflate.c | 4 +- src/drivers/net/exanic.c | 2 +- src/drivers/net/gve.c | 2 +- src/drivers/usb/xhci.c | 2 +- src/image/elf.c | 2 +- src/image/segment.c | 2 +- src/include/ipxe/linux/linux_uaccess.h | 32 ----- src/include/ipxe/uaccess.h | 166 +------------------------ src/interface/efi/efi_fbcon.c | 4 +- src/interface/efi/efi_umalloc.c | 4 +- src/interface/linux/linux_uaccess.c | 4 - src/interface/smbios/smbios.c | 2 +- src/tests/cms_test.c | 4 +- src/tests/gzip_test.c | 5 +- src/tests/pixbuf_test.c | 5 +- src/tests/zlib_test.c | 5 +- 35 files changed, 83 insertions(+), 331 deletions(-) (limited to 'src/interface/linux') diff --git a/src/arch/x86/core/runtime.c b/src/arch/x86/core/runtime.c index 02072b5bf..2b803f772 100644 --- a/src/arch/x86/core/runtime.c +++ b/src/arch/x86/core/runtime.c @@ -125,7 +125,7 @@ static int cmdline_init ( void ) { return 0; } cmdline_user = phys_to_user ( cmdline_phys ); - len = ( strlen_user ( cmdline_user, 0 ) + 1 /* NUL */ ); + len = ( strlen ( cmdline_user ) + 1 /* NUL */ ); /* Allocate and copy command line */ cmdline_copy = malloc ( len ); diff --git a/src/arch/x86/image/bzimage.c b/src/arch/x86/image/bzimage.c index d00b9f155..29ebeb507 100644 --- a/src/arch/x86/image/bzimage.c +++ b/src/arch/x86/image/bzimage.c @@ -369,8 +369,8 @@ static size_t bzimage_load_initrd ( struct image *image, /* Copy in initrd image body and construct any cpio headers */ if ( address ) { - memmove_user ( address, len, initrd->data, 0, initrd->len ); - memset_user ( address, 0, 0, len ); + memmove ( ( address + len ), initrd->data, initrd->len ); + memset ( address, 0, len ); offset = 0; for ( i = 0 ; ( cpio_len = cpio_header ( initrd, i, &cpio ) ) ; i++ ) { @@ -395,7 +395,7 @@ static size_t bzimage_load_initrd ( struct image *image, /* Zero-pad to next INITRD_ALIGN boundary */ pad_len = ( ( -len ) & ( INITRD_ALIGN - 1 ) ); if ( address ) - memset_user ( address, len, 0, pad_len ); + memset ( ( address + len ), 0, pad_len ); return len; } @@ -562,10 +562,9 @@ static int bzimage_exec ( struct image *image ) { unregister_image ( image_get ( image ) ); /* Load segments */ - memcpy_user ( bzimg.rm_kernel, 0, image->data, - 0, bzimg.rm_filesz ); - memcpy_user ( bzimg.pm_kernel, 0, image->data, - bzimg.rm_filesz, bzimg.pm_sz ); + memcpy ( bzimg.rm_kernel, image->data, bzimg.rm_filesz ); + memcpy ( bzimg.pm_kernel, ( image->data + bzimg.rm_filesz ), + bzimg.pm_sz ); /* Store command line */ bzimage_set_cmdline ( image, &bzimg ); diff --git a/src/arch/x86/image/com32.c b/src/arch/x86/image/com32.c index 6f0e66041..3e38215cb 100644 --- a/src/arch/x86/image/com32.c +++ b/src/arch/x86/image/com32.c @@ -219,7 +219,7 @@ static int com32_load_image ( struct image *image ) { } /* Copy image to segment */ - memcpy_user ( buffer, 0, image->data, 0, filesz ); + memcpy ( buffer, image->data, filesz ); return 0; } diff --git a/src/arch/x86/image/comboot.c b/src/arch/x86/image/comboot.c index 9a847f0ff..8609eb0f7 100644 --- a/src/arch/x86/image/comboot.c +++ b/src/arch/x86/image/comboot.c @@ -267,10 +267,10 @@ static int comboot_prepare_segment ( struct image *image ) } /* Zero PSP */ - memset_user ( seg_userptr, 0, 0, 0x100 ); + memset ( seg_userptr, 0, 0x100 ); /* Copy image to segment:0100 */ - memcpy_user ( seg_userptr, 0x100, image->data, 0, image->len ); + memcpy ( ( seg_userptr + 0x100 ), image->data, image->len ); return 0; } diff --git a/src/arch/x86/image/initrd.c b/src/arch/x86/image/initrd.c index e32e40341..95f12d804 100644 --- a/src/arch/x86/image/initrd.c +++ b/src/arch/x86/image/initrd.c @@ -80,7 +80,7 @@ static userptr_t initrd_squash_high ( userptr_t top ) { user_to_phys ( highest->data, highest->len ), user_to_phys ( current, 0 ), user_to_phys ( current, highest->len ) ); - memmove_user ( current, 0, highest->data, 0, highest->len ); + memmove ( current, highest->data, highest->len ); highest->data = current; } @@ -96,8 +96,7 @@ static userptr_t initrd_squash_high ( userptr_t top ) { user_to_phys ( initrd->data, initrd->len ), user_to_phys ( current, 0 ), user_to_phys ( current, initrd->len ) ); - memcpy_user ( current, 0, initrd->data, 0, - initrd->len ); + memcpy ( current, initrd->data, initrd->len ); initrd->data = current; } } @@ -140,9 +139,10 @@ static void initrd_swap ( struct image *low, struct image *high, ~( INITRD_ALIGN - 1 ) ); /* Swap fragments */ - memcpy_user ( free, 0, high->data, len, frag_len ); - memmove_user ( low->data, new_len, low->data, len, low->len ); - memcpy_user ( low->data, len, free, 0, frag_len ); + memcpy ( free, ( high->data + len ), frag_len ); + memmove ( ( low->data + new_len ), ( low->data + len ), + low->len ); + memcpy ( ( low->data + len ), free, frag_len ); len = new_len; } diff --git a/src/arch/x86/image/multiboot.c b/src/arch/x86/image/multiboot.c index cada021ab..fe21f1f1a 100644 --- a/src/arch/x86/image/multiboot.c +++ b/src/arch/x86/image/multiboot.c @@ -222,8 +222,8 @@ static int multiboot_add_modules ( struct image *image, physaddr_t start, } /* Copy module */ - memcpy_user ( phys_to_user ( start ), 0, - module_image->data, 0, module_image->len ); + memcpy ( phys_to_user ( start ), module_image->data, + module_image->len ); /* Add module to list */ module = &modules[mbinfo->mods_count++]; @@ -350,7 +350,7 @@ static int multiboot_load_raw ( struct image *image, } /* Copy image to segment */ - memcpy_user ( buffer, 0, image->data, offset, filesz ); + memcpy ( buffer, ( image->data + offset ), filesz ); /* Record execution entry point and maximum used address */ *entry = hdr->mb.entry_addr; diff --git a/src/arch/x86/image/nbi.c b/src/arch/x86/image/nbi.c index 2f0d3164a..0b02a8985 100644 --- a/src/arch/x86/image/nbi.c +++ b/src/arch/x86/image/nbi.c @@ -131,7 +131,7 @@ static int nbi_prepare_segment ( struct image *image, size_t offset __unused, static int nbi_load_segment ( struct image *image, size_t offset, userptr_t dest, size_t filesz, size_t memsz __unused ) { - memcpy_user ( dest, 0, image->data, offset, filesz ); + memcpy ( dest, ( image->data + offset ), filesz ); return 0; } diff --git a/src/arch/x86/image/pxe_image.c b/src/arch/x86/image/pxe_image.c index b6bcb18b4..bdce165ca 100644 --- a/src/arch/x86/image/pxe_image.c +++ b/src/arch/x86/image/pxe_image.c @@ -66,7 +66,7 @@ static int pxe_exec ( struct image *image ) { } /* Copy image to segment */ - memcpy_user ( buffer, 0, image->data, 0, image->len ); + memcpy ( buffer, image->data, image->len ); /* Arbitrarily pick the most recently opened network device */ if ( ( netdev = last_opened_netdev() ) == NULL ) { diff --git a/src/arch/x86/image/sdi.c b/src/arch/x86/image/sdi.c index fa2d0b73f..5bb5a7569 100644 --- a/src/arch/x86/image/sdi.c +++ b/src/arch/x86/image/sdi.c @@ -97,8 +97,8 @@ static int sdi_exec ( struct image *image ) { user_to_phys ( image->data, sdi.boot_offset ), sdi.boot_size ); /* Copy boot code */ - memcpy_user ( real_to_user ( SDI_BOOT_SEG, SDI_BOOT_OFF ), 0, - image->data, sdi.boot_offset, sdi.boot_size ); + memcpy ( real_to_user ( SDI_BOOT_SEG, SDI_BOOT_OFF ), + ( image->data + sdi.boot_offset ), sdi.boot_size ); /* Jump to boot code */ sdiptr = ( user_to_phys ( image->data, 0 ) | SDI_WTF ); diff --git a/src/arch/x86/image/ucode.c b/src/arch/x86/image/ucode.c index 499c0a940..9b6b5067a 100644 --- a/src/arch/x86/image/ucode.c +++ b/src/arch/x86/image/ucode.c @@ -256,7 +256,7 @@ static int ucode_update_all ( struct image *image, rc = -ENOMEM; goto err_alloc; } - memset_user ( status, 0, 0, len ); + memset ( status, 0, len ); /* Construct control structure */ memset ( &control, 0, sizeof ( control ) ); diff --git a/src/arch/x86/include/librm.h b/src/arch/x86/include/librm.h index c0d910287..c117a8b5c 100644 --- a/src/arch/x86/include/librm.h +++ b/src/arch/x86/include/librm.h @@ -137,38 +137,6 @@ UACCESS_INLINE ( librm, user_to_virt ) ( userptr_t userptr, off_t offset ) { return trivial_user_to_virt ( userptr, offset ); } -static inline __always_inline void -UACCESS_INLINE ( librm, memcpy_user ) ( userptr_t dest, off_t dest_off, - userptr_t src, off_t src_off, - size_t len ) { - trivial_memcpy_user ( dest, dest_off, src, src_off, len ); -} - -static inline __always_inline void -UACCESS_INLINE ( librm, memmove_user ) ( userptr_t dest, off_t dest_off, - userptr_t src, off_t src_off, - size_t len ) { - trivial_memmove_user ( dest, dest_off, src, src_off, len ); -} - -static inline __always_inline int -UACCESS_INLINE ( librm, memcmp_user ) ( userptr_t first, off_t first_off, - userptr_t second, off_t second_off, - size_t len ) { - return trivial_memcmp_user ( first, first_off, second, second_off, len); -} - -static inline __always_inline void -UACCESS_INLINE ( librm, memset_user ) ( userptr_t buffer, off_t offset, - int c, size_t len ) { - trivial_memset_user ( buffer, offset, c, len ); -} - -static inline __always_inline size_t -UACCESS_INLINE ( librm, strlen_user ) ( userptr_t buffer, off_t offset ) { - return trivial_strlen_user ( buffer, offset ); -} - static inline __always_inline off_t UACCESS_INLINE ( librm, memchr_user ) ( userptr_t buffer, off_t offset, int c, size_t len ) { diff --git a/src/arch/x86/interface/pcbios/memtop_umalloc.c b/src/arch/x86/interface/pcbios/memtop_umalloc.c index e76b3df93..8239b23b8 100644 --- a/src/arch/x86/interface/pcbios/memtop_umalloc.c +++ b/src/arch/x86/interface/pcbios/memtop_umalloc.c @@ -203,8 +203,8 @@ static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) { user_to_phys ( ptr, extmem.size ), user_to_phys ( new, 0 ), user_to_phys ( new, new_size )); - memmove_user ( new, 0, ptr, 0, ( ( extmem.size < new_size ) ? - extmem.size : new_size ) ); + memmove ( new, ptr, ( ( extmem.size < new_size ) ? + extmem.size : new_size ) ); bottom = new; heap_size -= ( new_size - extmem.size ); extmem.size = new_size; diff --git a/src/arch/x86/interface/pxe/pxe_file.c b/src/arch/x86/interface/pxe/pxe_file.c index 456ffb5fd..1235520de 100644 --- a/src/arch/x86/interface/pxe/pxe_file.c +++ b/src/arch/x86/interface/pxe/pxe_file.c @@ -61,8 +61,8 @@ static PXENV_EXIT_t pxenv_file_open ( struct s_PXENV_FILE_OPEN *file_open ) { /* Copy name from external program, and open it */ filename = real_to_user ( file_open->FileName.segment, - file_open->FileName.offset ); - filename_len = strlen_user ( filename, 0 ); + file_open->FileName.offset ); + filename_len = strlen ( filename ); { char uri_string[ filename_len + 1 ]; @@ -219,7 +219,7 @@ static PXENV_EXIT_t pxenv_file_exec ( struct s_PXENV_FILE_EXEC *file_exec ) { /* Copy name from external program, and exec it */ command = real_to_user ( file_exec->Command.segment, file_exec->Command.offset ); - command_len = strlen_user ( command, 0 ); + command_len = strlen ( command ); { char command_string[ command_len + 1 ]; diff --git a/src/arch/x86/interface/syslinux/com32_call.c b/src/arch/x86/interface/syslinux/com32_call.c index 19fdbaff9..da9d6491a 100644 --- a/src/arch/x86/interface/syslinux/com32_call.c +++ b/src/arch/x86/interface/syslinux/com32_call.c @@ -49,9 +49,8 @@ void __asmcall com32_intcall ( uint8_t interrupt, physaddr_t inregs_phys, physad DBGC ( &com32_regs, "COM32 INT%x in %#08lx out %#08lx\n", interrupt, inregs_phys, outregs_phys ); - memcpy_user ( virt_to_user( &com32_regs ), 0, - phys_to_user ( inregs_phys ), 0, - sizeof(com32sys_t) ); + memcpy ( virt_to_user( &com32_regs ), phys_to_user ( inregs_phys ), + sizeof ( com32sys_t ) ); com32_int_vector = interrupt; @@ -108,9 +107,8 @@ void __asmcall com32_intcall ( uint8_t interrupt, physaddr_t inregs_phys, physad : : ); if ( outregs_phys ) { - memcpy_user ( phys_to_user ( outregs_phys ), 0, - virt_to_user( &com32_regs ), 0, - sizeof(com32sys_t) ); + memcpy ( phys_to_user ( outregs_phys ), + virt_to_user ( &com32_regs ), sizeof ( com32sys_t ) ); } } @@ -122,9 +120,8 @@ void __asmcall com32_farcall ( uint32_t proc, physaddr_t inregs_phys, physaddr_t DBGC ( &com32_regs, "COM32 farcall %04x:%04x in %#08lx out %#08lx\n", ( proc >> 16 ), ( proc & 0xffff ), inregs_phys, outregs_phys ); - memcpy_user ( virt_to_user( &com32_regs ), 0, - phys_to_user ( inregs_phys ), 0, - sizeof(com32sys_t) ); + memcpy ( virt_to_user( &com32_regs ), phys_to_user ( inregs_phys ), + sizeof ( com32sys_t ) ); com32_farcall_proc = proc; @@ -170,9 +167,8 @@ void __asmcall com32_farcall ( uint32_t proc, physaddr_t inregs_phys, physaddr_t : : ); if ( outregs_phys ) { - memcpy_user ( phys_to_user ( outregs_phys ), 0, - virt_to_user( &com32_regs ), 0, - sizeof(com32sys_t) ); + memcpy ( phys_to_user ( outregs_phys ), + virt_to_user ( &com32_regs ), sizeof ( com32sys_t ) ); } } diff --git a/src/arch/x86/interface/syslinux/comboot_call.c b/src/arch/x86/interface/syslinux/comboot_call.c index b75e8ef7c..f26fcad0a 100644 --- a/src/arch/x86/interface/syslinux/comboot_call.c +++ b/src/arch/x86/interface/syslinux/comboot_call.c @@ -119,7 +119,7 @@ static void shuffle ( unsigned int list_segment, unsigned int list_offset, unsig if ( shuf[ i ].src == 0xFFFFFFFF ) { /* Fill with 0 instead of copying */ - memset_user ( dest_u, 0, 0, shuf[ i ].len ); + memset ( dest_u, 0, shuf[ i ].len ); } else if ( shuf[ i ].dest == 0xFFFFFFFF ) { /* Copy new list of descriptors */ count = shuf[ i ].len / sizeof( comboot_shuffle_descriptor ); @@ -128,7 +128,7 @@ static void shuffle ( unsigned int list_segment, unsigned int list_offset, unsig i = -1; } else { /* Regular copy */ - memmove_user ( dest_u, 0, src_u, 0, shuf[ i ].len ); + memmove ( dest_u, src_u, shuf[ i ].len ); } } } @@ -347,7 +347,7 @@ static __asmcall __used void int22 ( struct i386_all_regs *ix86 ) { case 0x0003: /* Run command */ { userptr_t cmd_u = real_to_user ( ix86->segs.es, ix86->regs.bx ); - int len = strlen_user ( cmd_u, 0 ); + int len = strlen ( cmd_u ); char cmd[len + 1]; copy_from_user ( cmd, cmd_u, 0, len + 1 ); DBG ( "COMBOOT: executing command '%s'\n", cmd ); @@ -371,7 +371,7 @@ static __asmcall __used void int22 ( struct i386_all_regs *ix86 ) { { int fd; userptr_t file_u = real_to_user ( ix86->segs.es, ix86->regs.si ); - int len = strlen_user ( file_u, 0 ); + int len = strlen ( file_u ); char file[len + 1]; copy_from_user ( file, file_u, 0, len + 1 ); @@ -484,7 +484,7 @@ static __asmcall __used void int22 ( struct i386_all_regs *ix86 ) { case 0x0010: /* Resolve hostname */ { userptr_t hostname_u = real_to_user ( ix86->segs.es, ix86->regs.bx ); - int len = strlen_user ( hostname_u, 0 ); + int len = strlen ( hostname_u ); char hostname[len]; struct in_addr addr; @@ -551,8 +551,8 @@ static __asmcall __used void int22 ( struct i386_all_regs *ix86 ) { { userptr_t file_u = real_to_user ( ix86->segs.ds, ix86->regs.si ); userptr_t cmd_u = real_to_user ( ix86->segs.es, ix86->regs.bx ); - int file_len = strlen_user ( file_u, 0 ); - int cmd_len = strlen_user ( cmd_u, 0 ); + int file_len = strlen ( file_u ); + int cmd_len = strlen ( cmd_u ); char file[file_len + 1]; char cmd[cmd_len + 1]; @@ -595,9 +595,9 @@ static __asmcall __used void int22 ( struct i386_all_regs *ix86 ) { shuffle ( ix86->segs.es, ix86->regs.di, ix86->regs.cx ); /* Copy initial register values to .text16 */ - memcpy_user ( real_to_user ( rm_cs, (unsigned) __from_text16 ( &comboot_initial_regs ) ), 0, - real_to_user ( ix86->segs.ds, ix86->regs.si ), 0, - sizeof(syslinux_rm_regs) ); + memcpy ( real_to_user ( rm_cs, (unsigned) __from_text16 ( &comboot_initial_regs ) ), + real_to_user ( ix86->segs.ds, ix86->regs.si ), + sizeof(syslinux_rm_regs) ); /* Load initial register values */ __asm__ __volatile__ ( diff --git a/src/arch/x86/transitions/librm_mgmt.c b/src/arch/x86/transitions/librm_mgmt.c index ec31fceb1..7ebf62137 100644 --- a/src/arch/x86/transitions/librm_mgmt.c +++ b/src/arch/x86/transitions/librm_mgmt.c @@ -69,7 +69,7 @@ uint16_t copy_user_to_rm_stack ( userptr_t data, size_t size ) { userptr_t rm_stack; rm_sp -= size; rm_stack = real_to_user ( rm_ss, rm_sp ); - memcpy_user ( rm_stack, 0, data, 0, size ); + memcpy ( rm_stack, data, size ); return rm_sp; }; @@ -83,7 +83,7 @@ uint16_t copy_user_to_rm_stack ( userptr_t data, size_t size ) { void remove_user_from_rm_stack ( userptr_t data, size_t size ) { if ( data ) { userptr_t rm_stack = real_to_user ( rm_ss, rm_sp ); - memcpy_user ( rm_stack, 0, data, 0, size ); + memcpy ( rm_stack, data, size ); } rm_sp += size; }; @@ -432,10 +432,6 @@ PROVIDE_UACCESS_INLINE ( librm, phys_to_user ); PROVIDE_UACCESS_INLINE ( librm, user_to_phys ); PROVIDE_UACCESS_INLINE ( librm, virt_to_user ); PROVIDE_UACCESS_INLINE ( librm, user_to_virt ); -PROVIDE_UACCESS_INLINE ( librm, memcpy_user ); -PROVIDE_UACCESS_INLINE ( librm, memmove_user ); -PROVIDE_UACCESS_INLINE ( librm, memset_user ); -PROVIDE_UACCESS_INLINE ( librm, strlen_user ); PROVIDE_UACCESS_INLINE ( librm, memchr_user ); PROVIDE_IOMAP_INLINE ( pages, io_to_bus ); PROVIDE_IOMAP ( pages, ioremap, ioremap_pages ); diff --git a/src/core/fbcon.c b/src/core/fbcon.c index ff3132ac7..8d05484e2 100644 --- a/src/core/fbcon.c +++ b/src/core/fbcon.c @@ -185,12 +185,12 @@ static void fbcon_draw ( struct fbcon *fbcon, struct fbcon_text_cell *cell, /* Draw background picture, if applicable */ if ( transparent ) { if ( fbcon->picture.start ) { - memcpy_user ( fbcon->start, offset, - fbcon->picture.start, offset, - fbcon->character.len ); + memcpy ( ( fbcon->start + offset ), + ( fbcon->picture.start + offset ), + fbcon->character.len ); } else { - memset_user ( fbcon->start, offset, 0, - fbcon->character.len ); + memset ( ( fbcon->start + offset ), 0, + fbcon->character.len ); } } @@ -247,8 +247,8 @@ static void fbcon_scroll ( struct fbcon *fbcon ) { /* Scroll up character array */ row_len = ( fbcon->character.width * sizeof ( struct fbcon_text_cell )); - memmove_user ( fbcon->text.start, 0, fbcon->text.start, row_len, - ( row_len * ( fbcon->character.height - 1 ) ) ); + memmove ( fbcon->text.start, ( fbcon->text.start + row_len ), + ( row_len * ( fbcon->character.height - 1 ) ) ); fbcon_clear ( fbcon, ( fbcon->character.height - 1 ) ); /* Update cursor position */ @@ -552,7 +552,7 @@ static int fbcon_picture_init ( struct fbcon *fbcon, ( ygap + pixbuf->height ) ); /* Convert to frame buffer raw format */ - memset_user ( picture->start, 0, 0, len ); + memset ( picture->start, 0, len ); for ( y = 0 ; y < height ; y++ ) { offset = ( indent + ( y * pixel->stride ) ); pixbuf_offset = ( pixbuf_indent + ( y * pixbuf_stride ) ); @@ -684,7 +684,7 @@ int fbcon_init ( struct fbcon *fbcon, userptr_t start, fbcon_clear ( fbcon, 0 ); /* Set framebuffer to all black (including margins) */ - memset_user ( fbcon->start, 0, 0, fbcon->len ); + memset ( fbcon->start, 0, fbcon->len ); /* Generate pixel buffer from background image, if applicable */ if ( config->pixbuf && @@ -692,10 +692,8 @@ int fbcon_init ( struct fbcon *fbcon, userptr_t start, goto err_picture; /* Draw background picture (including margins), if applicable */ - if ( fbcon->picture.start ) { - memcpy_user ( fbcon->start, 0, fbcon->picture.start, 0, - fbcon->len ); - } + if ( fbcon->picture.start ) + memcpy ( fbcon->start, fbcon->picture.start, fbcon->len ); /* Update console width and height */ console_set_size ( fbcon->character.width, fbcon->character.height ); diff --git a/src/core/image.c b/src/core/image.c index c69c05c93..709d0da9c 100644 --- a/src/core/image.c +++ b/src/core/image.c @@ -246,7 +246,7 @@ int image_set_data ( struct image *image, userptr_t data, size_t len ) { return rc; /* Copy in new image data */ - memcpy_user ( image->data, 0, data, 0, len ); + memcpy ( image->data, data, len ); return 0; } diff --git a/src/core/uaccess.c b/src/core/uaccess.c index ad17a58ab..01089e6fa 100644 --- a/src/core/uaccess.c +++ b/src/core/uaccess.c @@ -36,8 +36,4 @@ PROVIDE_UACCESS_INLINE ( flat, phys_to_user ); PROVIDE_UACCESS_INLINE ( flat, user_to_phys ); PROVIDE_UACCESS_INLINE ( flat, virt_to_user ); PROVIDE_UACCESS_INLINE ( flat, user_to_virt ); -PROVIDE_UACCESS_INLINE ( flat, memcpy_user ); -PROVIDE_UACCESS_INLINE ( flat, memmove_user ); -PROVIDE_UACCESS_INLINE ( flat, memset_user ); -PROVIDE_UACCESS_INLINE ( flat, strlen_user ); PROVIDE_UACCESS_INLINE ( flat, memchr_user ); diff --git a/src/crypto/deflate.c b/src/crypto/deflate.c index 7ad39ec1b..c6cce7516 100644 --- a/src/crypto/deflate.c +++ b/src/crypto/deflate.c @@ -464,8 +464,8 @@ static void deflate_copy ( struct deflate_chunk *out, if ( copy_len > len ) copy_len = len; while ( copy_len-- ) { - memcpy_user ( out->data, out_offset++, - start, offset++, 1 ); + memcpy ( ( out->data + out_offset++ ), + ( start + offset++ ), 1 ); } } out->offset += len; diff --git a/src/drivers/net/exanic.c b/src/drivers/net/exanic.c index aaa6a28a1..14a17df47 100644 --- a/src/drivers/net/exanic.c +++ b/src/drivers/net/exanic.c @@ -395,7 +395,7 @@ static int exanic_open ( struct net_device *netdev ) { } /* Reset receive region contents */ - memset_user ( port->rx, 0, 0xff, EXANIC_RX_LEN ); + memset ( port->rx, 0xff, EXANIC_RX_LEN ); /* Reset transmit feedback region */ *(port->txf) = 0; diff --git a/src/drivers/net/gve.c b/src/drivers/net/gve.c index 805feee3d..2cbc401f5 100644 --- a/src/drivers/net/gve.c +++ b/src/drivers/net/gve.c @@ -980,7 +980,7 @@ static int gve_start ( struct gve_nic *gve ) { } /* Invalidate receive completions */ - memset_user ( rx->cmplt, 0, 0, ( rx->count * rx->type->cmplt_len ) ); + memset ( rx->cmplt, 0, ( rx->count * rx->type->cmplt_len ) ); /* Reset receive sequence */ gve->seq = gve_next ( 0 ); diff --git a/src/drivers/usb/xhci.c b/src/drivers/usb/xhci.c index 3247ee69c..f244086ce 100644 --- a/src/drivers/usb/xhci.c +++ b/src/drivers/usb/xhci.c @@ -1000,7 +1000,7 @@ static int xhci_scratchpad_alloc ( struct xhci_device *xhci ) { rc = -ENOMEM; goto err_alloc; } - memset_user ( scratch->buffer, 0, 0, buffer_len ); + memset ( scratch->buffer, 0, buffer_len ); /* Allocate scratchpad array */ array_len = ( scratch->count * sizeof ( scratch->array[0] ) ); diff --git a/src/image/elf.c b/src/image/elf.c index 5c2f9db25..46c9fe8eb 100644 --- a/src/image/elf.c +++ b/src/image/elf.c @@ -66,7 +66,7 @@ static int elf_load_segment ( struct image *image, Elf_Phdr *phdr, } /* Copy image to segment */ - memcpy_user ( buffer, 0, image->data, phdr->p_offset, phdr->p_filesz ); + memcpy ( buffer, ( image->data + phdr->p_offset ), phdr->p_filesz ); return 0; } diff --git a/src/image/segment.c b/src/image/segment.c index 2d0f2f0fc..b7f8ef56c 100644 --- a/src/image/segment.c +++ b/src/image/segment.c @@ -83,7 +83,7 @@ int prep_segment ( userptr_t segment, size_t filesz, size_t memsz ) { if ( ( start >= memmap.regions[i].start ) && ( end <= memmap.regions[i].end ) ) { /* Found valid region: zero bss and return */ - memset_user ( segment, filesz, 0, ( memsz - filesz ) ); + memset ( ( segment + filesz ), 0, ( memsz - filesz ) ); return 0; } } diff --git a/src/include/ipxe/linux/linux_uaccess.h b/src/include/ipxe/linux/linux_uaccess.h index 790c75123..0c680c08f 100644 --- a/src/include/ipxe/linux/linux_uaccess.h +++ b/src/include/ipxe/linux/linux_uaccess.h @@ -69,38 +69,6 @@ UACCESS_INLINE ( linux, user_to_virt ) ( userptr_t userptr, off_t offset ) { return trivial_user_to_virt ( userptr, offset ); } -static inline __always_inline void -UACCESS_INLINE ( linux, memcpy_user ) ( userptr_t dest, off_t dest_off, - userptr_t src, off_t src_off, - size_t len ) { - trivial_memcpy_user ( dest, dest_off, src, src_off, len ); -} - -static inline __always_inline void -UACCESS_INLINE ( linux, memmove_user ) ( userptr_t dest, off_t dest_off, - userptr_t src, off_t src_off, - size_t len ) { - trivial_memmove_user ( dest, dest_off, src, src_off, len ); -} - -static inline __always_inline int -UACCESS_INLINE ( linux, memcmp_user ) ( userptr_t first, off_t first_off, - userptr_t second, off_t second_off, - size_t len ) { - return trivial_memcmp_user ( first, first_off, second, second_off, len); -} - -static inline __always_inline void -UACCESS_INLINE ( linux, memset_user ) ( userptr_t buffer, off_t offset, - int c, size_t len ) { - trivial_memset_user ( buffer, offset, c, len ); -} - -static inline __always_inline size_t -UACCESS_INLINE ( linux, strlen_user ) ( userptr_t buffer, off_t offset ) { - return trivial_strlen_user ( buffer, offset ); -} - static inline __always_inline off_t UACCESS_INLINE ( linux, memchr_user ) ( userptr_t buffer, off_t offset, int c, size_t len ) { diff --git a/src/include/ipxe/uaccess.h b/src/include/ipxe/uaccess.h index 93dc60d62..e84ca3eae 100644 --- a/src/include/ipxe/uaccess.h +++ b/src/include/ipxe/uaccess.h @@ -65,80 +65,6 @@ trivial_user_to_virt ( userptr_t userptr, off_t offset ) { return ( ( void * ) userptr + offset ); } -/** - * Copy data between user buffers - * - * @v dest Destination - * @v dest_off Destination offset - * @v src Source - * @v src_off Source offset - * @v len Length - */ -static inline __always_inline void -trivial_memcpy_user ( userptr_t dest, off_t dest_off, - userptr_t src, off_t src_off, size_t len ) { - memcpy ( ( ( void * ) dest + dest_off ), - ( ( void * ) src + src_off ), len ); -} - -/** - * Copy data between user buffers, allowing for overlap - * - * @v dest Destination - * @v dest_off Destination offset - * @v src Source - * @v src_off Source offset - * @v len Length - */ -static inline __always_inline void -trivial_memmove_user ( userptr_t dest, off_t dest_off, - userptr_t src, off_t src_off, size_t len ) { - memmove ( ( ( void * ) dest + dest_off ), - ( ( void * ) src + src_off ), len ); -} - -/** - * Compare data between user buffers - * - * @v first First buffer - * @v first_off First buffer offset - * @v second Second buffer - * @v second_off Second buffer offset - * @v len Length - * @ret diff Difference - */ -static inline __always_inline int -trivial_memcmp_user ( userptr_t first, off_t first_off, - userptr_t second, off_t second_off, size_t len ) { - return memcmp ( ( ( void * ) first + first_off ), - ( ( void * ) second + second_off ), len ); -} - -/** - * Fill user buffer with a constant byte - * - * @v buffer User buffer - * @v offset Offset within buffer - * @v c Constant byte with which to fill - * @v len Length - */ -static inline __always_inline void -trivial_memset_user ( userptr_t buffer, off_t offset, int c, size_t len ) { - memset ( ( ( void * ) buffer + offset ), c, len ); -} - -/** - * Find length of NUL-terminated string in user buffer - * - * @v buffer User buffer - * @v offset Offset within buffer - * @ret len Length of string (excluding NUL) - */ -static inline __always_inline size_t -trivial_strlen_user ( userptr_t buffer, off_t offset ) { - return strlen ( ( void * ) buffer + offset ); -} - /** * Find character in user buffer * @@ -207,38 +133,6 @@ UACCESS_INLINE ( flat, user_to_virt ) ( userptr_t userptr, off_t offset ) { return trivial_user_to_virt ( userptr, offset ); } -static inline __always_inline void -UACCESS_INLINE ( flat, memcpy_user ) ( userptr_t dest, off_t dest_off, - userptr_t src, off_t src_off, - size_t len ) { - trivial_memcpy_user ( dest, dest_off, src, src_off, len ); -} - -static inline __always_inline void -UACCESS_INLINE ( flat, memmove_user ) ( userptr_t dest, off_t dest_off, - userptr_t src, off_t src_off, - size_t len ) { - trivial_memmove_user ( dest, dest_off, src, src_off, len ); -} - -static inline __always_inline int -UACCESS_INLINE ( flat, memcmp_user ) ( userptr_t first, off_t first_off, - userptr_t second, off_t second_off, - size_t len ) { - return trivial_memcmp_user ( first, first_off, second, second_off, len); -} - -static inline __always_inline void -UACCESS_INLINE ( flat, memset_user ) ( userptr_t buffer, off_t offset, - int c, size_t len ) { - trivial_memset_user ( buffer, offset, c, len ); -} - -static inline __always_inline size_t -UACCESS_INLINE ( flat, strlen_user ) ( userptr_t buffer, off_t offset ) { - return trivial_strlen_user ( buffer, offset ); -} - static inline __always_inline off_t UACCESS_INLINE ( flat, memchr_user ) ( userptr_t buffer, off_t offset, int c, size_t len ) { @@ -310,18 +204,6 @@ static inline __always_inline void * phys_to_virt ( unsigned long phys_addr ) { return user_to_virt ( phys_to_user ( phys_addr ), 0 ); } -/** - * Copy data between user buffers - * - * @v dest Destination - * @v dest_off Destination offset - * @v src Source - * @v src_off Source offset - * @v len Length - */ -void memcpy_user ( userptr_t dest, off_t dest_off, - userptr_t src, off_t src_off, size_t len ); - /** * Copy data to user buffer * @@ -332,7 +214,7 @@ void memcpy_user ( userptr_t dest, off_t dest_off, */ static inline __always_inline void copy_to_user ( userptr_t dest, off_t dest_off, const void *src, size_t len ) { - memcpy_user ( dest, dest_off, virt_to_user ( src ), 0, len ); + memcpy ( ( dest + dest_off ), src, len ); } /** @@ -345,53 +227,9 @@ copy_to_user ( userptr_t dest, off_t dest_off, const void *src, size_t len ) { */ static inline __always_inline void copy_from_user ( void *dest, userptr_t src, off_t src_off, size_t len ) { - memcpy_user ( virt_to_user ( dest ), 0, src, src_off, len ); + memcpy ( dest, ( src + src_off ), len ); } -/** - * Copy data between user buffers, allowing for overlap - * - * @v dest Destination - * @v dest_off Destination offset - * @v src Source - * @v src_off Source offset - * @v len Length - */ -void memmove_user ( userptr_t dest, off_t dest_off, - userptr_t src, off_t src_off, size_t len ); - -/** - * Compare data between user buffers - * - * @v first First buffer - * @v first_off First buffer offset - * @v second Second buffer - * @v second_off Second buffer offset - * @v len Length - * @ret diff Difference - */ -int memcmp_user ( userptr_t first, off_t first_off, - userptr_t second, off_t second_off, size_t len ); - -/** - * Fill user buffer with a constant byte - * - * @v userptr User buffer - * @v offset Offset within buffer - * @v c Constant byte with which to fill - * @v len Length - */ -void memset_user ( userptr_t userptr, off_t offset, int c, size_t len ); - -/** - * Find length of NUL-terminated string in user buffer - * - * @v userptr User buffer - * @v offset Offset within buffer - * @ret len Length of string (excluding NUL) - */ -size_t strlen_user ( userptr_t userptr, off_t offset ); - /** * Find character in user buffer * diff --git a/src/interface/efi/efi_fbcon.c b/src/interface/efi/efi_fbcon.c index d388e0317..659ebd37e 100644 --- a/src/interface/efi/efi_fbcon.c +++ b/src/interface/efi/efi_fbcon.c @@ -124,7 +124,7 @@ static int efifb_draw ( unsigned int character, unsigned int index, /* Clear existing glyph */ offset = ( index * efifb.font.height ); - memset_user ( efifb.glyphs, offset, 0, efifb.font.height ); + memset ( ( efifb.glyphs + offset ), 0, efifb.font.height ); /* Get glyph */ blt = NULL; @@ -296,7 +296,7 @@ static int efifb_glyphs ( void ) { rc = -ENOMEM; goto err_alloc; } - memset_user ( efifb.glyphs, 0, 0, len ); + memset ( efifb.glyphs, 0, len ); /* Get font data */ for ( character = 0 ; character < EFIFB_ASCII ; character++ ) { diff --git a/src/interface/efi/efi_umalloc.c b/src/interface/efi/efi_umalloc.c index 175ae367e..488c53f3d 100644 --- a/src/interface/efi/efi_umalloc.c +++ b/src/interface/efi/efi_umalloc.c @@ -87,8 +87,8 @@ static userptr_t efi_urealloc ( userptr_t old_ptr, size_t new_size ) { if ( old_ptr && ( old_ptr != UNOWHERE ) ) { copy_from_user ( &old_size, old_ptr, -EFI_PAGE_SIZE, sizeof ( old_size ) ); - memcpy_user ( new_ptr, 0, old_ptr, 0, - ( (old_size < new_size) ? old_size : new_size )); + memcpy ( new_ptr, old_ptr, + ( (old_size < new_size) ? old_size : new_size ) ); old_pages = ( EFI_SIZE_TO_PAGES ( old_size ) + 1 ); phys_addr = user_to_phys ( old_ptr, -EFI_PAGE_SIZE ); if ( ( efirc = bs->FreePages ( phys_addr, old_pages ) ) != 0 ){ diff --git a/src/interface/linux/linux_uaccess.c b/src/interface/linux/linux_uaccess.c index 9fc99c5e2..d777bf3dd 100644 --- a/src/interface/linux/linux_uaccess.c +++ b/src/interface/linux/linux_uaccess.c @@ -30,8 +30,4 @@ FILE_LICENCE(GPL2_OR_LATER); PROVIDE_UACCESS_INLINE(linux, user_to_phys); PROVIDE_UACCESS_INLINE(linux, virt_to_user); PROVIDE_UACCESS_INLINE(linux, user_to_virt); -PROVIDE_UACCESS_INLINE(linux, memcpy_user); -PROVIDE_UACCESS_INLINE(linux, memmove_user); -PROVIDE_UACCESS_INLINE(linux, memset_user); -PROVIDE_UACCESS_INLINE(linux, strlen_user); PROVIDE_UACCESS_INLINE(linux, memchr_user); diff --git a/src/interface/smbios/smbios.c b/src/interface/smbios/smbios.c index fdd14499f..3e69a0c15 100644 --- a/src/interface/smbios/smbios.c +++ b/src/interface/smbios/smbios.c @@ -277,7 +277,7 @@ int read_smbios_string ( struct smbios_structure *structure, * smbios_strings struct is constructed so as to * always end on a string boundary. */ - string_len = strlen_user ( smbios.address, offset ); + string_len = strlen ( smbios.address + offset ); if ( --index == 0 ) { /* Copy string, truncating as necessary. */ if ( len > string_len ) diff --git a/src/tests/cms_test.c b/src/tests/cms_test.c index fc4f6bd19..debbfeee7 100644 --- a/src/tests/cms_test.c +++ b/src/tests/cms_test.c @@ -1773,8 +1773,8 @@ static void cms_decrypt_okx ( struct cms_test_image *img, /* Check decrypted image matches expected plaintext */ okx ( img->image.len == expected->image.len, file, line ); - okx ( memcmp_user ( img->image.data, 0, expected->image.data, 0, - expected->image.len ) == 0, file, line ); + okx ( memcmp ( img->image.data, expected->image.data, + expected->image.len ) == 0, file, line ); } #define cms_decrypt_ok( data, envelope, keypair, expected ) \ cms_decrypt_okx ( data, envelope, keypair, expected, \ diff --git a/src/tests/gzip_test.c b/src/tests/gzip_test.c index fa76edc53..9226b4c26 100644 --- a/src/tests/gzip_test.c +++ b/src/tests/gzip_test.c @@ -128,9 +128,8 @@ static void gzip_okx ( struct gzip_test *test, const char *file, /* Verify extracted image content */ okx ( extracted->len == test->expected_len, file, line ); - okx ( memcmp_user ( extracted->data, 0, - virt_to_user ( test->expected ), 0, - test->expected_len ) == 0, file, line ); + okx ( memcmp ( extracted->data, virt_to_user ( test->expected ), + test->expected_len ) == 0, file, line ); /* Verify extracted image name */ okx ( strcmp ( extracted->name, test->expected_name ) == 0, diff --git a/src/tests/pixbuf_test.c b/src/tests/pixbuf_test.c index aaa516bb2..1f82e0018 100644 --- a/src/tests/pixbuf_test.c +++ b/src/tests/pixbuf_test.c @@ -71,9 +71,8 @@ void pixbuf_okx ( struct pixel_buffer_test *test, const char *file, /* Check pixel buffer data */ okx ( pixbuf->len == test->len, file, line ); - okx ( memcmp_user ( pixbuf->data, 0, - virt_to_user ( test->data ), 0, - test->len ) == 0, file, line ); + okx ( memcmp ( pixbuf->data, virt_to_user ( test->data ), + test->len ) == 0, file, line ); pixbuf_put ( pixbuf ); } diff --git a/src/tests/zlib_test.c b/src/tests/zlib_test.c index df52d09ac..2efdcbad8 100644 --- a/src/tests/zlib_test.c +++ b/src/tests/zlib_test.c @@ -103,9 +103,8 @@ static void zlib_okx ( struct zlib_test *test, const char *file, /* Verify extracted image content */ okx ( extracted->len == test->expected_len, file, line ); - okx ( memcmp_user ( extracted->data, 0, - virt_to_user ( test->expected ), 0, - test->expected_len ) == 0, file, line ); + okx ( memcmp ( extracted->data, virt_to_user ( test->expected ), + test->expected_len ) == 0, file, line ); /* Verify extracted image name */ okx ( strcmp ( extracted->name, test->expected_name ) == 0, -- cgit v1.2.3-55-g7522 From 4535548cba255c220719a55d02535e06da82ba47 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 21 Apr 2025 00:15:52 +0100 Subject: [uaccess] Remove redundant user_to_virt() The user_to_virt() function is now a straightforward wrapper around addition, with the addend almost invariably being zero. Remove this redundant wrapper. Signed-off-by: Michael Brown --- src/arch/x86/image/bzimage.c | 4 ++-- src/arch/x86/image/initrd.c | 2 +- src/arch/x86/include/librm.h | 5 ----- src/arch/x86/transitions/librm_mgmt.c | 1 - src/core/fdt.c | 7 +++---- src/core/uaccess.c | 1 - src/image/efi_image.c | 8 ++++---- src/include/ipxe/linux/linux_uaccess.h | 5 ----- src/include/ipxe/uaccess.h | 32 +------------------------------- src/interface/efi/efi_pci.c | 2 +- src/interface/linux/linux_acpi.c | 2 +- src/interface/linux/linux_smbios.c | 2 +- src/interface/linux/linux_sysfs.c | 3 +-- src/interface/linux/linux_uaccess.c | 1 - 14 files changed, 15 insertions(+), 60 deletions(-) (limited to 'src/interface/linux') diff --git a/src/arch/x86/image/bzimage.c b/src/arch/x86/image/bzimage.c index 29ebeb507..32598525f 100644 --- a/src/arch/x86/image/bzimage.c +++ b/src/arch/x86/image/bzimage.c @@ -388,7 +388,7 @@ static size_t bzimage_load_initrd ( struct image *image, user_to_phys ( address, ( offset + initrd->len ) ), ( filename ? " " : "" ), ( filename ? filename : "" ) ); DBGC2_MD5A ( image, user_to_phys ( address, offset ), - user_to_virt ( address, offset ), initrd->len ); + ( address + offset ), initrd->len ); } len += initrd->len; @@ -427,7 +427,7 @@ static int bzimage_check_initrds ( struct image *image, ( initrd->cmdline ? " " : "" ), ( initrd->cmdline ? initrd->cmdline : "" ) ); DBGC2_MD5A ( image, user_to_phys ( initrd->data, 0 ), - user_to_virt ( initrd->data, 0 ), initrd->len ); + initrd->data, initrd->len ); } /* Calculate lowest usable address */ diff --git a/src/arch/x86/image/initrd.c b/src/arch/x86/image/initrd.c index 95f12d804..bcf95deef 100644 --- a/src/arch/x86/image/initrd.c +++ b/src/arch/x86/image/initrd.c @@ -211,7 +211,7 @@ static void initrd_dump ( void ) { initrd->name, user_to_phys ( initrd->data, 0 ), user_to_phys ( initrd->data, initrd->len ) ); DBGC2_MD5A ( &images, user_to_phys ( initrd->data, 0 ), - user_to_virt ( initrd->data, 0 ), initrd->len ); + initrd->data, initrd->len ); } } diff --git a/src/arch/x86/include/librm.h b/src/arch/x86/include/librm.h index c117a8b5c..9ed91022e 100644 --- a/src/arch/x86/include/librm.h +++ b/src/arch/x86/include/librm.h @@ -132,11 +132,6 @@ UACCESS_INLINE ( librm, virt_to_user ) ( volatile const void *addr ) { return trivial_virt_to_user ( addr ); } -static inline __always_inline void * -UACCESS_INLINE ( librm, user_to_virt ) ( userptr_t userptr, off_t offset ) { - return trivial_user_to_virt ( userptr, offset ); -} - static inline __always_inline off_t UACCESS_INLINE ( librm, memchr_user ) ( userptr_t buffer, off_t offset, int c, size_t len ) { diff --git a/src/arch/x86/transitions/librm_mgmt.c b/src/arch/x86/transitions/librm_mgmt.c index 7ebf62137..82e8eab39 100644 --- a/src/arch/x86/transitions/librm_mgmt.c +++ b/src/arch/x86/transitions/librm_mgmt.c @@ -431,7 +431,6 @@ void setup_sipi ( unsigned int vector, uint32_t handler, PROVIDE_UACCESS_INLINE ( librm, phys_to_user ); PROVIDE_UACCESS_INLINE ( librm, user_to_phys ); PROVIDE_UACCESS_INLINE ( librm, virt_to_user ); -PROVIDE_UACCESS_INLINE ( librm, user_to_virt ); PROVIDE_UACCESS_INLINE ( librm, memchr_user ); PROVIDE_IOMAP_INLINE ( pages, io_to_bus ); PROVIDE_IOMAP ( pages, ioremap, ioremap_pages ); diff --git a/src/core/fdt.c b/src/core/fdt.c index 54f930286..4c709b342 100644 --- a/src/core/fdt.c +++ b/src/core/fdt.c @@ -734,8 +734,7 @@ static int fdt_parse_image ( struct fdt *fdt, struct image *image ) { int rc; /* Parse image */ - if ( ( rc = fdt_parse ( fdt, user_to_virt ( image->data, 0 ), - image->len ) ) != 0 ) { + if ( ( rc = fdt_parse ( fdt, image->data, image->len ) ) != 0 ) { DBGC ( fdt, "FDT image \"%s\" is invalid: %s\n", image->name, strerror ( rc ) ); return rc; @@ -1038,7 +1037,7 @@ static int fdt_urealloc ( struct fdt *fdt, size_t len ) { assert ( len >= fdt->used ); /* Attempt reallocation */ - new = user_to_virt ( urealloc ( virt_to_user ( fdt->raw ), len ), 0 ); + new = urealloc ( virt_to_user ( fdt->raw ), len ); if ( ! new ) { DBGC ( fdt, "FDT could not reallocate from +%#04zx to " "+%#04zx\n", fdt->len, len ); @@ -1112,7 +1111,7 @@ int fdt_create ( struct fdt_header **hdr, const char *cmdline ) { } /* Create modifiable copy */ - copy = user_to_virt ( umalloc ( fdt.len ), 0 ); + copy = umalloc ( fdt.len ); if ( ! copy ) { rc = -ENOMEM; goto err_alloc; diff --git a/src/core/uaccess.c b/src/core/uaccess.c index 01089e6fa..1c33c10b8 100644 --- a/src/core/uaccess.c +++ b/src/core/uaccess.c @@ -35,5 +35,4 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); PROVIDE_UACCESS_INLINE ( flat, phys_to_user ); PROVIDE_UACCESS_INLINE ( flat, user_to_phys ); PROVIDE_UACCESS_INLINE ( flat, virt_to_user ); -PROVIDE_UACCESS_INLINE ( flat, user_to_virt ); PROVIDE_UACCESS_INLINE ( flat, memchr_user ); diff --git a/src/image/efi_image.c b/src/image/efi_image.c index c87196487..2b0ff567a 100644 --- a/src/image/efi_image.c +++ b/src/image/efi_image.c @@ -245,8 +245,8 @@ static int efi_image_exec ( struct image *image ) { /* Attempt loading image */ handle = NULL; if ( ( efirc = bs->LoadImage ( FALSE, efi_image_handle, path, - user_to_virt ( exec->data, 0 ), - exec->len, &handle ) ) != 0 ) { + exec->data, exec->len, + &handle ) ) != 0 ) { /* Not an EFI image */ rc = -EEFI_LOAD ( efirc ); DBGC ( image, "EFIIMAGE %s could not load: %s\n", @@ -379,8 +379,8 @@ static int efi_image_probe ( struct image *image ) { /* Attempt loading image */ handle = NULL; if ( ( efirc = bs->LoadImage ( FALSE, efi_image_handle, &empty_path, - user_to_virt ( image->data, 0 ), - image->len, &handle ) ) != 0 ) { + image->data, image->len, + &handle ) ) != 0 ) { /* Not an EFI image */ rc = -EEFI_LOAD ( efirc ); DBGC ( image, "EFIIMAGE %s could not load: %s\n", diff --git a/src/include/ipxe/linux/linux_uaccess.h b/src/include/ipxe/linux/linux_uaccess.h index 0c680c08f..4b1257b1e 100644 --- a/src/include/ipxe/linux/linux_uaccess.h +++ b/src/include/ipxe/linux/linux_uaccess.h @@ -64,11 +64,6 @@ UACCESS_INLINE ( linux, virt_to_user ) ( volatile const void *addr ) { return trivial_virt_to_user ( addr ); } -static inline __always_inline void * -UACCESS_INLINE ( linux, user_to_virt ) ( userptr_t userptr, off_t offset ) { - return trivial_user_to_virt ( userptr, offset ); -} - static inline __always_inline off_t UACCESS_INLINE ( linux, memchr_user ) ( userptr_t buffer, off_t offset, int c, size_t len ) { diff --git a/src/include/ipxe/uaccess.h b/src/include/ipxe/uaccess.h index e84ca3eae..4b3524bab 100644 --- a/src/include/ipxe/uaccess.h +++ b/src/include/ipxe/uaccess.h @@ -51,20 +51,6 @@ trivial_virt_to_user ( volatile const void *addr ) { return ( ( userptr_t ) addr ); } -/** - * Convert user pointer to virtual address - * - * @v userptr User pointer - * @v offset Offset from user pointer - * @ret addr Virtual address - * - * This operation is not available under all memory models. - */ -static inline __always_inline void * -trivial_user_to_virt ( userptr_t userptr, off_t offset ) { - return ( ( void * ) userptr + offset ); -} - /** * Find character in user buffer * @@ -128,11 +114,6 @@ UACCESS_INLINE ( flat, virt_to_user ) ( volatile const void *addr ) { return trivial_virt_to_user ( addr ); } -static inline __always_inline void * -UACCESS_INLINE ( flat, user_to_virt ) ( userptr_t userptr, off_t offset ) { - return trivial_user_to_virt ( userptr, offset ); -} - static inline __always_inline off_t UACCESS_INLINE ( flat, memchr_user ) ( userptr_t buffer, off_t offset, int c, size_t len ) { @@ -170,17 +151,6 @@ unsigned long user_to_phys ( userptr_t userptr, off_t offset ); */ userptr_t virt_to_user ( volatile const void *addr ); -/** - * Convert user pointer to virtual address - * - * @v userptr User pointer - * @v offset Offset from user pointer - * @ret addr Virtual address - * - * This operation is not available under all memory models. - */ -void * user_to_virt ( userptr_t userptr, off_t offset ); - /** * Convert virtual address to a physical address * @@ -201,7 +171,7 @@ virt_to_phys ( volatile const void *addr ) { * This operation is not available under all memory models. */ static inline __always_inline void * phys_to_virt ( unsigned long phys_addr ) { - return user_to_virt ( phys_to_user ( phys_addr ), 0 ); + return ( phys_to_user ( phys_addr ) ); } /** diff --git a/src/interface/efi/efi_pci.c b/src/interface/efi/efi_pci.c index dd11dd342..01351df51 100644 --- a/src/interface/efi/efi_pci.c +++ b/src/interface/efi/efi_pci.c @@ -669,7 +669,7 @@ static userptr_t efipci_dma_umalloc ( struct dma_device *dma, static void efipci_dma_ufree ( struct dma_device *dma, struct dma_mapping *map, userptr_t addr, size_t len ) { - efipci_dma_free ( dma, map, user_to_virt ( addr, 0 ), len ); + efipci_dma_free ( dma, map, addr, len ); } /** diff --git a/src/interface/linux/linux_acpi.c b/src/interface/linux/linux_acpi.c index e658936f2..846db2f1f 100644 --- a/src/interface/linux/linux_acpi.c +++ b/src/interface/linux/linux_acpi.c @@ -101,7 +101,7 @@ static userptr_t linux_acpi_find ( uint32_t signature, unsigned int index ) { filename, strerror ( rc ) ); goto err_read; } - header = user_to_virt ( table->data, 0 ); + header = table->data; if ( ( ( ( size_t ) len ) < sizeof ( *header ) ) || ( ( ( size_t ) len ) < le32_to_cpu ( header->length ) ) ) { rc = -ENOENT; diff --git a/src/interface/linux/linux_smbios.c b/src/interface/linux/linux_smbios.c index 981873943..abe1b19d7 100644 --- a/src/interface/linux/linux_smbios.c +++ b/src/interface/linux/linux_smbios.c @@ -59,7 +59,7 @@ static int linux_find_smbios ( struct smbios *smbios ) { smbios_entry_filename, strerror ( rc ) ); goto err_entry; } - data = user_to_virt ( entry, 0 ); + data = entry; smbios3_entry = data; smbios_entry = data; if ( ( len >= ( ( int ) sizeof ( *smbios3_entry ) ) ) && diff --git a/src/interface/linux/linux_sysfs.c b/src/interface/linux/linux_sysfs.c index 4f0027cd4..cbb23d81d 100644 --- a/src/interface/linux/linux_sysfs.c +++ b/src/interface/linux/linux_sysfs.c @@ -70,8 +70,7 @@ int linux_sysfs_read ( const char *filename, userptr_t *data ) { *data = tmp; /* Read from file */ - read = linux_read ( fd, user_to_virt ( *data, len ), - LINUX_SYSFS_BLKSIZE ); + read = linux_read ( fd, ( *data + len ), LINUX_SYSFS_BLKSIZE ); if ( read == 0 ) break; if ( read < 0 ) { diff --git a/src/interface/linux/linux_uaccess.c b/src/interface/linux/linux_uaccess.c index d777bf3dd..e5c394365 100644 --- a/src/interface/linux/linux_uaccess.c +++ b/src/interface/linux/linux_uaccess.c @@ -29,5 +29,4 @@ FILE_LICENCE(GPL2_OR_LATER); PROVIDE_UACCESS_INLINE(linux, user_to_phys); PROVIDE_UACCESS_INLINE(linux, virt_to_user); -PROVIDE_UACCESS_INLINE(linux, user_to_virt); PROVIDE_UACCESS_INLINE(linux, memchr_user); -- cgit v1.2.3-55-g7522 From 8c31270a21a85cc87bce0e07e19e2041d2510a4c Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 21 Apr 2025 16:16:01 +0100 Subject: [uaccess] Remove user_to_phys() and phys_to_user() Remove the intermediate concept of a user pointer from physical address conversions, leaving virt_to_phys() and phys_to_virt() as the directly implemented functions. Signed-off-by: Michael Brown --- src/arch/x86/core/runtime.c | 4 +-- src/arch/x86/core/vram_settings.c | 2 +- src/arch/x86/image/bzimage.c | 36 ++++++++++---------- src/arch/x86/image/com32.c | 2 +- src/arch/x86/image/initrd.c | 32 +++++++++--------- src/arch/x86/image/multiboot.c | 6 ++-- src/arch/x86/image/nbi.c | 4 +-- src/arch/x86/image/sdi.c | 9 ++--- src/arch/x86/image/ucode.c | 11 +++--- src/arch/x86/include/librm.h | 25 +++++++------- src/arch/x86/include/realmode.h | 2 +- src/arch/x86/interface/pcbios/bios_cachedhcp.c | 2 +- src/arch/x86/interface/pcbios/bios_smbios.c | 4 +-- src/arch/x86/interface/pcbios/int13.c | 6 ++-- src/arch/x86/interface/pcbios/memtop_umalloc.c | 30 ++++++++-------- src/arch/x86/interface/pcbios/rsdp.c | 8 ++--- src/arch/x86/interface/pcbios/vesafb.c | 2 +- src/arch/x86/interface/pxe/pxe_tftp.c | 2 +- src/arch/x86/interface/syslinux/com32_call.c | 10 +++--- src/arch/x86/interface/syslinux/comboot_call.c | 4 +-- src/arch/x86/transitions/librm_mgmt.c | 4 +-- src/core/acpi.c | 24 ++++++------- src/core/blocktrans.c | 2 +- src/core/cachedhcp.c | 2 +- src/core/fbcon.c | 4 +-- src/core/image.c | 4 +-- src/core/uaccess.c | 4 +-- src/drivers/block/srp.c | 4 +-- src/drivers/infiniband/arbel.c | 4 +-- src/drivers/infiniband/golan.c | 4 +-- src/drivers/infiniband/golan.h | 4 +-- src/drivers/infiniband/hermon.c | 4 +-- src/drivers/net/exanic.c | 6 ++-- src/drivers/net/gve.c | 27 +++++++-------- src/drivers/net/thunderx.c | 21 ++++++------ src/drivers/usb/xhci.c | 7 ++-- src/hci/commands/image_mem_cmd.c | 2 +- src/image/elf.c | 2 +- src/image/segment.c | 6 ++-- src/include/ipxe/linux/linux_uaccess.h | 34 +++++++++---------- src/include/ipxe/uaccess.h | 47 +++++++------------------- src/interface/efi/efi_acpi.c | 2 +- src/interface/efi/efi_fbcon.c | 2 +- src/interface/efi/efi_smbios.c | 8 ++--- src/interface/efi/efi_umalloc.c | 4 +-- src/interface/hyperv/vmbus.c | 2 +- src/interface/linux/linux_uaccess.c | 3 +- src/interface/smbios/smbios.c | 8 ++--- 48 files changed, 211 insertions(+), 235 deletions(-) (limited to 'src/interface/linux') diff --git a/src/arch/x86/core/runtime.c b/src/arch/x86/core/runtime.c index 2b803f772..2d2a10674 100644 --- a/src/arch/x86/core/runtime.c +++ b/src/arch/x86/core/runtime.c @@ -124,7 +124,7 @@ static int cmdline_init ( void ) { DBGC ( colour, "RUNTIME found no command line\n" ); return 0; } - cmdline_user = phys_to_user ( cmdline_phys ); + cmdline_user = phys_to_virt ( cmdline_phys ); len = ( strlen ( cmdline_user ) + 1 /* NUL */ ); /* Allocate and copy command line */ @@ -193,7 +193,7 @@ static int initrd_init ( void ) { initrd_phys, ( initrd_phys + initrd_len ) ); /* Create initrd image */ - image = image_memory ( "", phys_to_user ( initrd_phys ), + image = image_memory ( "", phys_to_virt ( initrd_phys ), initrd_len ); if ( ! image ) { DBGC ( colour, "RUNTIME could not create initrd image\n" ); diff --git a/src/arch/x86/core/vram_settings.c b/src/arch/x86/core/vram_settings.c index 9c169b40c..ceeada467 100644 --- a/src/arch/x86/core/vram_settings.c +++ b/src/arch/x86/core/vram_settings.c @@ -47,7 +47,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * @ret len Length of setting data, or negative error */ static int vram_fetch ( void *data, size_t len ) { - userptr_t vram = phys_to_user ( VRAM_BASE ); + userptr_t vram = phys_to_virt ( VRAM_BASE ); /* Copy video RAM */ if ( len > VRAM_LEN ) diff --git a/src/arch/x86/image/bzimage.c b/src/arch/x86/image/bzimage.c index 32598525f..0f373c1c8 100644 --- a/src/arch/x86/image/bzimage.c +++ b/src/arch/x86/image/bzimage.c @@ -169,7 +169,7 @@ static int bzimage_parse_header ( struct image *image, bzimg->rm_memsz += BZI_CMDLINE_SIZE; /* Calculate load address of protected-mode portion */ - bzimg->pm_kernel = phys_to_user ( is_bzimage ? BZI_LOAD_HIGH_ADDR + bzimg->pm_kernel = phys_to_virt ( is_bzimage ? BZI_LOAD_HIGH_ADDR : BZI_LOAD_LOW_ADDR ); /* Extract video mode */ @@ -185,8 +185,8 @@ static int bzimage_parse_header ( struct image *image, DBGC ( image, "bzImage %p version %04x RM %#lx+%#zx PM %#lx+%#zx " "cmdlen %zd\n", image, bzimg->version, - user_to_phys ( bzimg->rm_kernel, 0 ), bzimg->rm_filesz, - user_to_phys ( bzimg->pm_kernel, 0 ), bzimg->pm_sz, + virt_to_phys ( bzimg->rm_kernel ), bzimg->rm_filesz, + virt_to_phys ( bzimg->pm_kernel ), bzimg->pm_sz, bzimg->cmdline_size ); return 0; @@ -215,8 +215,8 @@ static void bzimage_update_header ( struct image *image, /* Set command line */ if ( bzimg->version >= 0x0202 ) { - bzimg->bzhdr.cmd_line_ptr = user_to_phys ( bzimg->rm_kernel, - bzimg->rm_cmdline ); + bzimg->bzhdr.cmd_line_ptr = ( virt_to_phys ( bzimg->rm_kernel ) + + bzimg->rm_cmdline ); } else { bzimg->cmdline_magic.magic = BZI_CMDLINE_MAGIC; bzimg->cmdline_magic.offset = bzimg->rm_cmdline; @@ -383,11 +383,11 @@ static size_t bzimage_load_initrd ( struct image *image, } assert ( offset == len ); DBGC ( image, "bzImage %p initrd %p [%#08lx,%#08lx,%#08lx)" - "%s%s\n", image, initrd, user_to_phys ( address, 0 ), - user_to_phys ( address, offset ), - user_to_phys ( address, ( offset + initrd->len ) ), + "%s%s\n", image, initrd, virt_to_phys ( address ), + ( virt_to_phys ( address ) + offset ), + ( virt_to_phys ( address ) + offset + initrd->len ), ( filename ? " " : "" ), ( filename ? filename : "" ) ); - DBGC2_MD5A ( image, user_to_phys ( address, offset ), + DBGC2_MD5A ( image, ( virt_to_phys ( address ) + offset ), ( address + offset ), initrd->len ); } len += initrd->len; @@ -422,11 +422,11 @@ static int bzimage_check_initrds ( struct image *image, len = bzimage_align ( len ); DBGC ( image, "bzImage %p initrd %p from [%#08lx,%#08lx)%s%s\n", - image, initrd, user_to_phys ( initrd->data, 0 ), - user_to_phys ( initrd->data, initrd->len ), + image, initrd, virt_to_phys ( initrd->data ), + ( virt_to_phys ( initrd->data ) + initrd->len ), ( initrd->cmdline ? " " : "" ), ( initrd->cmdline ? initrd->cmdline : "" ) ); - DBGC2_MD5A ( image, user_to_phys ( initrd->data, 0 ), + DBGC2_MD5A ( image, virt_to_phys ( initrd->data ), initrd->data, initrd->len ); } @@ -445,7 +445,7 @@ static int bzimage_check_initrds ( struct image *image, } /* Check that total length fits within kernel's memory limit */ - if ( user_to_phys ( bottom, len ) > bzimg->mem_limit ) { + if ( ( virt_to_phys ( bottom ) + len ) > bzimg->mem_limit ) { DBGC ( image, "bzImage %p not enough space for initrds\n", image ); return -ENOBUFS; @@ -485,12 +485,12 @@ static void bzimage_load_initrds ( struct image *image, /* Find highest usable address */ top = ( highest->data + bzimage_align ( highest->len ) ); - if ( user_to_phys ( top, -1 ) > bzimg->mem_limit ) { - top = phys_to_user ( ( bzimg->mem_limit + 1 ) & + if ( ( virt_to_phys ( top ) - 1UL ) > bzimg->mem_limit ) { + top = phys_to_virt ( ( bzimg->mem_limit + 1 ) & ~( INITRD_ALIGN - 1 ) ); } DBGC ( image, "bzImage %p loading initrds from %#08lx downwards\n", - image, user_to_phys ( top, -1 ) ); + image, ( virt_to_phys ( top ) - 1UL ) ); /* Load initrds in order */ for_each_image ( initrd ) { @@ -512,8 +512,8 @@ static void bzimage_load_initrds ( struct image *image, /* Record initrd location */ if ( ! bzimg->ramdisk_image ) - bzimg->ramdisk_image = user_to_phys ( dest, 0 ); - bzimg->ramdisk_size = ( user_to_phys ( dest, len ) - + bzimg->ramdisk_image = virt_to_phys ( dest ); + bzimg->ramdisk_size = ( virt_to_phys ( dest ) + len - bzimg->ramdisk_image ); } DBGC ( image, "bzImage %p initrds at [%#08lx,%#08lx)\n", diff --git a/src/arch/x86/image/com32.c b/src/arch/x86/image/com32.c index 3e38215cb..a2b60987d 100644 --- a/src/arch/x86/image/com32.c +++ b/src/arch/x86/image/com32.c @@ -211,7 +211,7 @@ static int com32_load_image ( struct image *image ) { filesz = image->len; memsz = filesz; - buffer = phys_to_user ( COM32_START_PHYS ); + buffer = phys_to_virt ( COM32_START_PHYS ); if ( ( rc = prep_segment ( buffer, filesz, memsz ) ) != 0 ) { DBGC ( image, "COM32 %p: could not prepare segment: %s\n", image, strerror ( rc ) ); diff --git a/src/arch/x86/image/initrd.c b/src/arch/x86/image/initrd.c index bcf95deef..fff40dd14 100644 --- a/src/arch/x86/image/initrd.c +++ b/src/arch/x86/image/initrd.c @@ -76,10 +76,10 @@ static userptr_t initrd_squash_high ( userptr_t top ) { current -= len; DBGC ( &images, "INITRD squashing %s [%#08lx,%#08lx)->" "[%#08lx,%#08lx)\n", highest->name, - user_to_phys ( highest->data, 0 ), - user_to_phys ( highest->data, highest->len ), - user_to_phys ( current, 0 ), - user_to_phys ( current, highest->len ) ); + virt_to_phys ( highest->data ), + ( virt_to_phys ( highest->data ) + highest->len ), + virt_to_phys ( current ), + ( virt_to_phys ( current ) + highest->len ) ); memmove ( current, highest->data, highest->len ); highest->data = current; } @@ -92,10 +92,10 @@ static userptr_t initrd_squash_high ( userptr_t top ) { current -= len; DBGC ( &images, "INITRD copying %s [%#08lx,%#08lx)->" "[%#08lx,%#08lx)\n", initrd->name, - user_to_phys ( initrd->data, 0 ), - user_to_phys ( initrd->data, initrd->len ), - user_to_phys ( current, 0 ), - user_to_phys ( current, initrd->len ) ); + virt_to_phys ( initrd->data ), + ( virt_to_phys ( initrd->data ) + initrd->len ), + virt_to_phys ( current ), + ( virt_to_phys ( current ) + initrd->len ) ); memcpy ( current, initrd->data, initrd->len ); initrd->data = current; } @@ -119,10 +119,10 @@ static void initrd_swap ( struct image *low, struct image *high, size_t new_len; DBGC ( &images, "INITRD swapping %s [%#08lx,%#08lx)<->[%#08lx,%#08lx) " - "%s\n", low->name, user_to_phys ( low->data, 0 ), - user_to_phys ( low->data, low->len ), - user_to_phys ( high->data, 0 ), - user_to_phys ( high->data, high->len ), high->name ); + "%s\n", low->name, virt_to_phys ( low->data ), + ( virt_to_phys ( low->data ) + low->len ), + virt_to_phys ( high->data ), + ( virt_to_phys ( high->data ) + high->len ), high->name ); /* Round down length of free space */ free_len &= ~( INITRD_ALIGN - 1 ); @@ -208,9 +208,9 @@ static void initrd_dump ( void ) { /* Dump initrd locations */ for_each_image ( initrd ) { DBGC ( &images, "INITRD %s at [%#08lx,%#08lx)\n", - initrd->name, user_to_phys ( initrd->data, 0 ), - user_to_phys ( initrd->data, initrd->len ) ); - DBGC2_MD5A ( &images, user_to_phys ( initrd->data, 0 ), + initrd->name, virt_to_phys ( initrd->data ), + ( virt_to_phys ( initrd->data ) + initrd->len ) ); + DBGC2_MD5A ( &images, virt_to_phys ( initrd->data ), initrd->data, initrd->len ); } } @@ -239,7 +239,7 @@ void initrd_reshuffle ( userptr_t bottom ) { /* Debug */ DBGC ( &images, "INITRD region [%#08lx,%#08lx)\n", - user_to_phys ( bottom, 0 ), user_to_phys ( top, 0 ) ); + virt_to_phys ( bottom ), virt_to_phys ( top ) ); initrd_dump(); /* Squash initrds as high as possible in memory */ diff --git a/src/arch/x86/image/multiboot.c b/src/arch/x86/image/multiboot.c index fe21f1f1a..24f67e02f 100644 --- a/src/arch/x86/image/multiboot.c +++ b/src/arch/x86/image/multiboot.c @@ -212,7 +212,7 @@ static int multiboot_add_modules ( struct image *image, physaddr_t start, start = ( ( start + 0xfff ) & ~0xfff ); /* Prepare segment */ - if ( ( rc = prep_segment ( phys_to_user ( start ), + if ( ( rc = prep_segment ( phys_to_virt ( start ), module_image->len, module_image->len ) ) != 0 ) { DBGC ( image, "MULTIBOOT %p could not prepare module " @@ -222,7 +222,7 @@ static int multiboot_add_modules ( struct image *image, physaddr_t start, } /* Copy module */ - memcpy ( phys_to_user ( start ), module_image->data, + memcpy ( phys_to_virt ( start ), module_image->data, module_image->len ); /* Add module to list */ @@ -342,7 +342,7 @@ static int multiboot_load_raw ( struct image *image, ( image->len - offset ) ); memsz = ( hdr->mb.bss_end_addr ? ( hdr->mb.bss_end_addr - hdr->mb.load_addr ) : filesz ); - buffer = phys_to_user ( hdr->mb.load_addr ); + buffer = phys_to_virt ( hdr->mb.load_addr ); if ( ( rc = prep_segment ( buffer, filesz, memsz ) ) != 0 ) { DBGC ( image, "MULTIBOOT %p could not prepare segment: %s\n", image, strerror ( rc ) ); diff --git a/src/arch/x86/image/nbi.c b/src/arch/x86/image/nbi.c index 0b02a8985..1f72c1287 100644 --- a/src/arch/x86/image/nbi.c +++ b/src/arch/x86/image/nbi.c @@ -181,7 +181,7 @@ static int nbi_process_segments ( struct image *image, /* Calculate segment load address */ switch ( NBI_LOADADDR_FLAGS ( sh.flags ) ) { case NBI_LOADADDR_ABS: - dest = phys_to_user ( sh.loadaddr ); + dest = phys_to_virt ( sh.loadaddr ); break; case NBI_LOADADDR_AFTER: dest = ( dest + memsz + sh.loadaddr ); @@ -194,7 +194,7 @@ static int nbi_process_segments ( struct image *image, * maintains backwards compatibility with * previous versions of Etherboot. */ - dest = phys_to_user ( ( extmemsize() + 1024 ) * 1024 + dest = phys_to_virt ( ( extmemsize() + 1024 ) * 1024 - sh.loadaddr ); break; default: diff --git a/src/arch/x86/image/sdi.c b/src/arch/x86/image/sdi.c index 5bb5a7569..5e22daeb3 100644 --- a/src/arch/x86/image/sdi.c +++ b/src/arch/x86/image/sdi.c @@ -92,16 +92,17 @@ static int sdi_exec ( struct image *image ) { return -ENOTTY; } DBGC ( image, "SDI %p image at %08lx+%08zx\n", - image, user_to_phys ( image->data, 0 ), image->len ); - DBGC ( image, "SDI %p boot code at %08lx+%llx\n", image, - user_to_phys ( image->data, sdi.boot_offset ), sdi.boot_size ); + image, virt_to_phys ( image->data ), image->len ); + DBGC ( image, "SDI %p boot code at %08llx+%llx\n", image, + ( virt_to_phys ( image->data ) + sdi.boot_offset ), + sdi.boot_size ); /* Copy boot code */ memcpy ( real_to_user ( SDI_BOOT_SEG, SDI_BOOT_OFF ), ( image->data + sdi.boot_offset ), sdi.boot_size ); /* Jump to boot code */ - sdiptr = ( user_to_phys ( image->data, 0 ) | SDI_WTF ); + sdiptr = ( virt_to_phys ( image->data ) | SDI_WTF ); __asm__ __volatile__ ( REAL_CODE ( "ljmp %0, %1\n\t" ) : : "i" ( SDI_BOOT_SEG ), "i" ( SDI_BOOT_OFF ), diff --git a/src/arch/x86/image/ucode.c b/src/arch/x86/image/ucode.c index 9b6b5067a..a9fa8b8c4 100644 --- a/src/arch/x86/image/ucode.c +++ b/src/arch/x86/image/ucode.c @@ -165,7 +165,7 @@ static int ucode_status ( struct ucode_update *update, assert ( id <= control->apic_max ); /* Read status report */ - copy_from_user ( &status, phys_to_user ( control->status ), + copy_from_user ( &status, phys_to_virt ( control->status ), ( id * sizeof ( status ) ), sizeof ( status ) ); /* Ignore empty optional status reports */ @@ -261,7 +261,7 @@ static int ucode_update_all ( struct image *image, /* Construct control structure */ memset ( &control, 0, sizeof ( control ) ); control.desc = virt_to_phys ( update->desc ); - control.status = user_to_phys ( status, 0 ); + control.status = virt_to_phys ( status ); vendor = update->vendor; if ( vendor ) { control.ver_clear = vendor->ver_clear; @@ -446,8 +446,8 @@ static int ucode_parse_intel ( struct image *image, size_t start, /* Populate descriptor */ desc.signature = hdr.signature; desc.version = hdr.version; - desc.address = user_to_phys ( image->data, - ( start + sizeof ( hdr ) ) ); + desc.address = ( virt_to_phys ( image->data ) + + start + sizeof ( hdr ) ); /* Add non-extended descriptor, if applicable */ ucode_describe ( image, start, &ucode_intel, &desc, hdr.platforms, @@ -589,7 +589,8 @@ static int ucode_parse_amd ( struct image *image, size_t start, copy_from_user ( &patch, image->data, ( start + offset ), sizeof ( patch ) ); desc.version = patch.version; - desc.address = user_to_phys ( image->data, ( start + offset ) ); + desc.address = ( virt_to_phys ( image->data ) + + start + offset ); offset += phdr.len; /* Parse equivalence table to find matching signatures */ diff --git a/src/arch/x86/include/librm.h b/src/arch/x86/include/librm.h index 9ed91022e..7755abdcf 100644 --- a/src/arch/x86/include/librm.h +++ b/src/arch/x86/include/librm.h @@ -85,33 +85,32 @@ extern const unsigned long virt_offset; /** * Convert physical address to user pointer * - * @v phys_addr Physical address - * @ret userptr User pointer + * @v phys Physical address + * @ret virt Virtual address */ -static inline __always_inline userptr_t -UACCESS_INLINE ( librm, phys_to_user ) ( unsigned long phys_addr ) { +static inline __always_inline void * +UACCESS_INLINE ( librm, phys_to_virt ) ( unsigned long phys ) { /* In a 64-bit build, any valid physical address is directly * usable as a virtual address, since the low 4GB is * identity-mapped. */ if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) ) - return ( ( userptr_t ) phys_addr ); + return ( ( void * ) phys ); /* In a 32-bit build, subtract virt_offset */ - return ( ( userptr_t ) ( phys_addr - virt_offset ) ); + return ( ( void * ) ( phys - virt_offset ) ); } /** - * Convert user buffer to physical address + * Convert virtual address to physical address * - * @v userptr User pointer - * @v offset Offset from user pointer - * @ret phys_addr Physical address + * @v virt Virtual address + * @ret phys Physical address */ -static inline __always_inline unsigned long -UACCESS_INLINE ( librm, user_to_phys ) ( userptr_t userptr, off_t offset ) { - unsigned long addr = ( ( unsigned long ) ( userptr + offset ) ); +static inline __always_inline physaddr_t +UACCESS_INLINE ( librm, virt_to_phys ) ( volatile const void *virt ) { + physaddr_t addr = ( ( physaddr_t ) virt ); /* In a 64-bit build, any virtual address in the low 4GB is * directly usable as a physical address, since the low 4GB is diff --git a/src/arch/x86/include/realmode.h b/src/arch/x86/include/realmode.h index 4defd3b97..616db5eb9 100644 --- a/src/arch/x86/include/realmode.h +++ b/src/arch/x86/include/realmode.h @@ -73,7 +73,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); */ static inline __always_inline userptr_t real_to_user ( unsigned int segment, unsigned int offset ) { - return ( phys_to_user ( ( segment << 4 ) + offset ) ); + return ( phys_to_virt ( ( segment << 4 ) + offset ) ); } /** diff --git a/src/arch/x86/interface/pcbios/bios_cachedhcp.c b/src/arch/x86/interface/pcbios/bios_cachedhcp.c index bea803d6e..05d89b3b7 100644 --- a/src/arch/x86/interface/pcbios/bios_cachedhcp.c +++ b/src/arch/x86/interface/pcbios/bios_cachedhcp.c @@ -60,7 +60,7 @@ static void cachedhcp_init ( void ) { /* Record cached DHCPACK */ if ( ( rc = cachedhcp_record ( &cached_dhcpack, 0, - phys_to_user ( cached_dhcpack_phys ), + phys_to_virt ( cached_dhcpack_phys ), sizeof ( BOOTPLAYER_t ) ) ) != 0 ) { DBGC ( colour, "CACHEDHCP could not record DHCPACK: %s\n", strerror ( rc ) ); diff --git a/src/arch/x86/interface/pcbios/bios_smbios.c b/src/arch/x86/interface/pcbios/bios_smbios.c index 366679d36..ab53d424b 100644 --- a/src/arch/x86/interface/pcbios/bios_smbios.c +++ b/src/arch/x86/interface/pcbios/bios_smbios.c @@ -54,7 +54,7 @@ static int bios_find_smbios2 ( struct smbios *smbios ) { return rc; /* Fill in entry point descriptor structure */ - smbios->address = phys_to_user ( entry.smbios_address ); + smbios->address = phys_to_virt ( entry.smbios_address ); smbios->len = entry.smbios_len; smbios->count = entry.smbios_count; smbios->version = SMBIOS_VERSION ( entry.major, entry.minor ); @@ -85,7 +85,7 @@ static int bios_find_smbios3 ( struct smbios *smbios ) { } /* Fill in entry point descriptor structure */ - smbios->address = phys_to_user ( entry.smbios_address ); + smbios->address = phys_to_virt ( entry.smbios_address ); smbios->len = entry.smbios_len; smbios->count = 0; smbios->version = SMBIOS_VERSION ( entry.major, entry.minor ); diff --git a/src/arch/x86/interface/pcbios/int13.c b/src/arch/x86/interface/pcbios/int13.c index 372d40ba3..d60f7c7cc 100644 --- a/src/arch/x86/interface/pcbios/int13.c +++ b/src/arch/x86/interface/pcbios/int13.c @@ -743,7 +743,7 @@ static int int13_extended_rw ( struct san_device *sandev, if ( ( addr.count == 0xff ) || ( ( addr.buffer.segment == 0xffff ) && ( addr.buffer.offset == 0xffff ) ) ) { - buffer = phys_to_user ( addr.buffer_phys ); + buffer = phys_to_virt ( addr.buffer_phys ); DBGC2 ( sandev->drive, "%08llx", ( ( unsigned long long ) addr.buffer_phys ) ); } else { @@ -1058,7 +1058,7 @@ static int int13_cdrom_read_boot_catalog ( struct san_device *sandev, /* Read from boot catalog */ if ( ( rc = sandev_read ( sandev, start, command.count, - phys_to_user ( command.buffer ) ) ) != 0 ) { + phys_to_virt ( command.buffer ) ) ) != 0 ) { DBGC ( sandev->drive, "INT13 drive %02x could not read boot " "catalog: %s\n", sandev->drive, strerror ( rc ) ); return -INT13_STATUS_READ_ERROR; @@ -1455,7 +1455,7 @@ static int int13_load_eltorito ( unsigned int drive, struct segoff *address ) { "catalog (status %04x)\n", drive, status ); return -EIO; } - copy_from_user ( &catalog, phys_to_user ( eltorito_cmd.buffer ), 0, + copy_from_user ( &catalog, phys_to_virt ( eltorito_cmd.buffer ), 0, sizeof ( catalog ) ); /* Sanity checks */ diff --git a/src/arch/x86/interface/pcbios/memtop_umalloc.c b/src/arch/x86/interface/pcbios/memtop_umalloc.c index 8239b23b8..b87d22516 100644 --- a/src/arch/x86/interface/pcbios/memtop_umalloc.c +++ b/src/arch/x86/interface/pcbios/memtop_umalloc.c @@ -106,7 +106,7 @@ size_t largest_memblock ( userptr_t *start ) { /* Use largest block */ if ( region_len > len ) { DBG ( "...new best block found\n" ); - *start = phys_to_user ( region_start ); + *start = phys_to_virt ( region_start ); len = region_len; } } @@ -124,7 +124,7 @@ static void init_eheap ( void ) { heap_size = largest_memblock ( &base ); bottom = top = ( base + heap_size ); DBG ( "External heap grows downwards from %lx (size %zx)\n", - user_to_phys ( top, 0 ), heap_size ); + virt_to_phys ( top ), heap_size ); } /** @@ -141,8 +141,8 @@ static void ecollect_free ( void ) { sizeof ( extmem ) ); if ( extmem.used ) break; - DBG ( "EXTMEM freeing [%lx,%lx)\n", user_to_phys ( bottom, 0 ), - user_to_phys ( bottom, extmem.size ) ); + DBG ( "EXTMEM freeing [%lx,%lx)\n", virt_to_phys ( bottom ), + ( virt_to_phys ( bottom ) + extmem.size ) ); len = ( extmem.size + sizeof ( extmem ) ); bottom += len; heap_size += len; @@ -182,7 +182,7 @@ static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) { ptr = bottom = ( bottom - sizeof ( extmem ) ); heap_size -= sizeof ( extmem ); DBG ( "EXTMEM allocating [%lx,%lx)\n", - user_to_phys ( ptr, 0 ), user_to_phys ( ptr, 0 ) ); + virt_to_phys ( ptr ), virt_to_phys ( ptr ) ); extmem.size = 0; } extmem.used = ( new_size > 0 ); @@ -191,7 +191,7 @@ static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) { if ( ptr == bottom ) { /* Update block */ new = ( ptr - ( new_size - extmem.size ) ); - align = ( user_to_phys ( new, 0 ) & ( EM_ALIGN - 1 ) ); + align = ( virt_to_phys ( new ) & ( EM_ALIGN - 1 ) ); new_size += align; new -= align; if ( new_size > ( heap_size + extmem.size ) ) { @@ -199,10 +199,10 @@ static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) { return UNULL; } DBG ( "EXTMEM expanding [%lx,%lx) to [%lx,%lx)\n", - user_to_phys ( ptr, 0 ), - user_to_phys ( ptr, extmem.size ), - user_to_phys ( new, 0 ), - user_to_phys ( new, new_size )); + virt_to_phys ( ptr ), + ( virt_to_phys ( ptr ) + extmem.size ), + virt_to_phys ( new ), + ( virt_to_phys ( new ) + new_size ) ); memmove ( new, ptr, ( ( extmem.size < new_size ) ? extmem.size : new_size ) ); bottom = new; @@ -213,8 +213,8 @@ static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) { if ( new_size > extmem.size ) { /* Refuse to expand */ DBG ( "EXTMEM cannot expand [%lx,%lx)\n", - user_to_phys ( ptr, 0 ), - user_to_phys ( ptr, extmem.size ) ); + virt_to_phys ( ptr ), + ( virt_to_phys ( ptr ) + extmem.size ) ); return UNULL; } } @@ -225,9 +225,9 @@ static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) { /* Collect any free blocks and update hidden memory region */ ecollect_free(); - hide_umalloc ( user_to_phys ( bottom, ( ( bottom == top ) ? - 0 : -sizeof ( extmem ) ) ), - user_to_phys ( top, 0 ) ); + hide_umalloc ( ( virt_to_phys ( bottom ) - + ( ( bottom == top ) ? 0 : sizeof ( extmem ) ) ), + virt_to_phys ( top ) ); return ( new_size ? new : UNOWHERE ); } diff --git a/src/arch/x86/interface/pcbios/rsdp.c b/src/arch/x86/interface/pcbios/rsdp.c index 3c67b7525..02c58c780 100644 --- a/src/arch/x86/interface/pcbios/rsdp.c +++ b/src/arch/x86/interface/pcbios/rsdp.c @@ -78,10 +78,10 @@ static userptr_t rsdp_find_rsdt_range ( userptr_t start, size_t len ) { continue; /* Extract RSDT */ - rsdt = phys_to_user ( le32_to_cpu ( rsdp.rsdt ) ); + rsdt = phys_to_virt ( le32_to_cpu ( rsdp.rsdt ) ); DBGC ( rsdt, "RSDT %#08lx found via RSDP %#08lx\n", - user_to_phys ( rsdt, 0 ), - user_to_phys ( start, offset ) ); + virt_to_phys ( rsdt ), + ( virt_to_phys ( start ) + offset ) ); return rsdt; } @@ -114,7 +114,7 @@ static userptr_t rsdp_find_rsdt ( void ) { } /* Search fixed BIOS area */ - rsdt = rsdp_find_rsdt_range ( phys_to_user ( RSDP_BIOS_START ), + rsdt = rsdp_find_rsdt_range ( phys_to_virt ( RSDP_BIOS_START ), RSDP_BIOS_LEN ); if ( rsdt ) return rsdt; diff --git a/src/arch/x86/interface/pcbios/vesafb.c b/src/arch/x86/interface/pcbios/vesafb.c index 86edbda42..61609fa8c 100644 --- a/src/arch/x86/interface/pcbios/vesafb.c +++ b/src/arch/x86/interface/pcbios/vesafb.c @@ -473,7 +473,7 @@ static int vesafb_init ( struct console_configuration *config ) { vesafb_font(); /* Initialise frame buffer console */ - if ( ( rc = fbcon_init ( &vesafb.fbcon, phys_to_user ( vesafb.start ), + if ( ( rc = fbcon_init ( &vesafb.fbcon, phys_to_virt ( vesafb.start ), &vesafb.pixel, &vesafb.map, &vesafb.font, config ) ) != 0 ) goto err_fbcon_init; diff --git a/src/arch/x86/interface/pxe/pxe_tftp.c b/src/arch/x86/interface/pxe/pxe_tftp.c index 3b4c6d847..2c2eccca4 100644 --- a/src/arch/x86/interface/pxe/pxe_tftp.c +++ b/src/arch/x86/interface/pxe/pxe_tftp.c @@ -492,7 +492,7 @@ PXENV_EXIT_t pxenv_tftp_read_file ( struct s_PXENV_TFTP_READ_FILE } /* Read entire file */ - pxe_tftp.buffer = phys_to_user ( tftp_read_file->Buffer ); + pxe_tftp.buffer = phys_to_virt ( tftp_read_file->Buffer ); pxe_tftp.size = tftp_read_file->BufferSize; while ( ( rc = pxe_tftp.rc ) == -EINPROGRESS ) step(); diff --git a/src/arch/x86/interface/syslinux/com32_call.c b/src/arch/x86/interface/syslinux/com32_call.c index da9d6491a..47be69f9f 100644 --- a/src/arch/x86/interface/syslinux/com32_call.c +++ b/src/arch/x86/interface/syslinux/com32_call.c @@ -49,7 +49,7 @@ void __asmcall com32_intcall ( uint8_t interrupt, physaddr_t inregs_phys, physad DBGC ( &com32_regs, "COM32 INT%x in %#08lx out %#08lx\n", interrupt, inregs_phys, outregs_phys ); - memcpy ( virt_to_user( &com32_regs ), phys_to_user ( inregs_phys ), + memcpy ( virt_to_user( &com32_regs ), phys_to_virt ( inregs_phys ), sizeof ( com32sys_t ) ); com32_int_vector = interrupt; @@ -107,7 +107,7 @@ void __asmcall com32_intcall ( uint8_t interrupt, physaddr_t inregs_phys, physad : : ); if ( outregs_phys ) { - memcpy ( phys_to_user ( outregs_phys ), + memcpy ( phys_to_virt ( outregs_phys ), virt_to_user ( &com32_regs ), sizeof ( com32sys_t ) ); } } @@ -120,7 +120,7 @@ void __asmcall com32_farcall ( uint32_t proc, physaddr_t inregs_phys, physaddr_t DBGC ( &com32_regs, "COM32 farcall %04x:%04x in %#08lx out %#08lx\n", ( proc >> 16 ), ( proc & 0xffff ), inregs_phys, outregs_phys ); - memcpy ( virt_to_user( &com32_regs ), phys_to_user ( inregs_phys ), + memcpy ( virt_to_user( &com32_regs ), phys_to_virt ( inregs_phys ), sizeof ( com32sys_t ) ); com32_farcall_proc = proc; @@ -167,7 +167,7 @@ void __asmcall com32_farcall ( uint32_t proc, physaddr_t inregs_phys, physaddr_t : : ); if ( outregs_phys ) { - memcpy ( phys_to_user ( outregs_phys ), + memcpy ( phys_to_virt ( outregs_phys ), virt_to_user ( &com32_regs ), sizeof ( com32sys_t ) ); } } @@ -181,7 +181,7 @@ int __asmcall com32_cfarcall ( uint32_t proc, physaddr_t stack, size_t stacksz ) DBGC ( &com32_regs, "COM32 cfarcall %04x:%04x params %#08lx+%#zx\n", ( proc >> 16 ), ( proc & 0xffff ), stack, stacksz ); - copy_user_to_rm_stack ( phys_to_user ( stack ), stacksz ); + copy_user_to_rm_stack ( phys_to_virt ( stack ), stacksz ); com32_farcall_proc = proc; __asm__ __volatile__ ( diff --git a/src/arch/x86/interface/syslinux/comboot_call.c b/src/arch/x86/interface/syslinux/comboot_call.c index f26fcad0a..d7e923b70 100644 --- a/src/arch/x86/interface/syslinux/comboot_call.c +++ b/src/arch/x86/interface/syslinux/comboot_call.c @@ -114,8 +114,8 @@ static void shuffle ( unsigned int list_segment, unsigned int list_offset, unsig /* Do the copies */ for ( i = 0; i < count; i++ ) { - userptr_t src_u = phys_to_user ( shuf[ i ].src ); - userptr_t dest_u = phys_to_user ( shuf[ i ].dest ); + userptr_t src_u = phys_to_virt ( shuf[ i ].src ); + userptr_t dest_u = phys_to_virt ( shuf[ i ].dest ); if ( shuf[ i ].src == 0xFFFFFFFF ) { /* Fill with 0 instead of copying */ diff --git a/src/arch/x86/transitions/librm_mgmt.c b/src/arch/x86/transitions/librm_mgmt.c index 82e8eab39..fbc653969 100644 --- a/src/arch/x86/transitions/librm_mgmt.c +++ b/src/arch/x86/transitions/librm_mgmt.c @@ -428,8 +428,8 @@ void setup_sipi ( unsigned int vector, uint32_t handler, copy_to_real ( ( vector << 8 ), 0, sipi, ( ( size_t ) sipi_len ) ); } -PROVIDE_UACCESS_INLINE ( librm, phys_to_user ); -PROVIDE_UACCESS_INLINE ( librm, user_to_phys ); +PROVIDE_UACCESS_INLINE ( librm, phys_to_virt ); +PROVIDE_UACCESS_INLINE ( librm, virt_to_phys ); PROVIDE_UACCESS_INLINE ( librm, virt_to_user ); PROVIDE_UACCESS_INLINE ( librm, memchr_user ); PROVIDE_IOMAP_INLINE ( pages, io_to_bus ); diff --git a/src/core/acpi.c b/src/core/acpi.c index 526bf8555..d7da0ccc1 100644 --- a/src/core/acpi.c +++ b/src/core/acpi.c @@ -128,16 +128,16 @@ userptr_t acpi_find_via_rsdt ( uint32_t signature, unsigned int index ) { copy_from_user ( &acpi, rsdt, 0, sizeof ( acpi ) ); if ( acpi.signature != cpu_to_le32 ( RSDT_SIGNATURE ) ) { DBGC ( colour, "RSDT %#08lx has invalid signature:\n", - user_to_phys ( rsdt, 0 ) ); - DBGC_HDA ( colour, user_to_phys ( rsdt, 0 ), &acpi, + virt_to_phys ( rsdt ) ); + DBGC_HDA ( colour, virt_to_phys ( rsdt ), &acpi, sizeof ( acpi ) ); return UNULL; } len = le32_to_cpu ( acpi.length ); if ( len < sizeof ( rsdtab->acpi ) ) { DBGC ( colour, "RSDT %#08lx has invalid length:\n", - user_to_phys ( rsdt, 0 ) ); - DBGC_HDA ( colour, user_to_phys ( rsdt, 0 ), &acpi, + virt_to_phys ( rsdt ) ); + DBGC_HDA ( colour, virt_to_phys ( rsdt ), &acpi, sizeof ( acpi ) ); return UNULL; } @@ -154,7 +154,7 @@ userptr_t acpi_find_via_rsdt ( uint32_t signature, unsigned int index ) { sizeof ( entry ) ); /* Read table header */ - table = phys_to_user ( entry ); + table = phys_to_virt ( entry ); copy_from_user ( &acpi.signature, table, 0, sizeof ( acpi.signature ) ); @@ -169,20 +169,20 @@ userptr_t acpi_find_via_rsdt ( uint32_t signature, unsigned int index ) { /* Check table integrity */ if ( acpi_checksum ( table ) != 0 ) { DBGC ( colour, "RSDT %#08lx found %s with bad " - "checksum at %08lx\n", user_to_phys ( rsdt, 0 ), + "checksum at %08lx\n", virt_to_phys ( rsdt ), acpi_name ( signature ), - user_to_phys ( table, 0 ) ); + virt_to_phys ( table ) ); break; } DBGC ( colour, "RSDT %#08lx found %s at %08lx\n", - user_to_phys ( rsdt, 0 ), acpi_name ( signature ), - user_to_phys ( table, 0 ) ); + virt_to_phys ( rsdt ), acpi_name ( signature ), + virt_to_phys ( table ) ); return table; } DBGC ( colour, "RSDT %#08lx could not find %s\n", - user_to_phys ( rsdt, 0 ), acpi_name ( signature ) ); + virt_to_phys ( rsdt ), acpi_name ( signature ) ); return UNULL; } @@ -218,7 +218,7 @@ static int acpi_zsdt ( userptr_t zsdt, uint32_t signature, void *data, if ( buf != cpu_to_le32 ( signature ) ) continue; DBGC ( zsdt, "DSDT/SSDT %#08lx found %s at offset %#zx\n", - user_to_phys ( zsdt, 0 ), acpi_name ( signature ), + virt_to_phys ( zsdt ), acpi_name ( signature ), offset ); /* Attempt to extract data */ @@ -251,7 +251,7 @@ int acpi_extract ( uint32_t signature, void *data, fadt = acpi_table ( FADT_SIGNATURE, 0 ); if ( fadt ) { copy_from_user ( &fadtab, fadt, 0, sizeof ( fadtab ) ); - dsdt = phys_to_user ( fadtab.dsdt ); + dsdt = phys_to_virt ( fadtab.dsdt ); if ( ( rc = acpi_zsdt ( dsdt, signature, data, extract ) ) == 0 ) return 0; diff --git a/src/core/blocktrans.c b/src/core/blocktrans.c index f9dcb95d2..f3be2ba2b 100644 --- a/src/core/blocktrans.c +++ b/src/core/blocktrans.c @@ -248,7 +248,7 @@ int block_translate ( struct interface *block, userptr_t buffer, size_t size ) { DBGC2 ( blktrans, "BLKTRANS %p created", blktrans ); if ( buffer ) { DBGC2 ( blktrans, " for %#lx+%#zx", - user_to_phys ( buffer, 0 ), size ); + virt_to_phys ( buffer ), size ); } DBGC2 ( blktrans, "\n" ); return 0; diff --git a/src/core/cachedhcp.c b/src/core/cachedhcp.c index 04945e646..07589f0b8 100644 --- a/src/core/cachedhcp.c +++ b/src/core/cachedhcp.c @@ -251,7 +251,7 @@ int cachedhcp_record ( struct cached_dhcp_packet *cache, unsigned int vlan, /* Store as cached packet */ DBGC ( colour, "CACHEDHCP %s at %#08lx+%#zx/%#zx\n", cache->name, - user_to_phys ( data, 0 ), len, max_len ); + virt_to_phys ( data ), len, max_len ); cache->dhcppkt = dhcppkt; cache->vlan = vlan; diff --git a/src/core/fbcon.c b/src/core/fbcon.c index 8d05484e2..6d08ac419 100644 --- a/src/core/fbcon.c +++ b/src/core/fbcon.c @@ -613,8 +613,8 @@ int fbcon_init ( struct fbcon *fbcon, userptr_t start, /* Derive overall length */ fbcon->len = ( pixel->height * pixel->stride ); DBGC ( fbcon, "FBCON %p at [%08lx,%08lx)\n", fbcon, - user_to_phys ( fbcon->start, 0 ), - user_to_phys ( fbcon->start, fbcon->len ) ); + virt_to_phys ( fbcon->start ), + ( virt_to_phys ( fbcon->start ) + fbcon->len ) ); /* Calculate margin. If the actual screen size is larger than * the requested screen size, then update the margins so that diff --git a/src/core/image.c b/src/core/image.c index 709d0da9c..e90d82ffb 100644 --- a/src/core/image.c +++ b/src/core/image.c @@ -300,8 +300,8 @@ int register_image ( struct image *image ) { image->flags |= IMAGE_REGISTERED; list_add_tail ( &image->list, &images ); DBGC ( image, "IMAGE %s at [%lx,%lx) registered\n", - image->name, user_to_phys ( image->data, 0 ), - user_to_phys ( image->data, image->len ) ); + image->name, virt_to_phys ( image->data ), + ( virt_to_phys ( image->data ) + image->len ) ); /* Try to detect image type, if applicable. Ignore failures, * since we expect to handle some unrecognised images diff --git a/src/core/uaccess.c b/src/core/uaccess.c index 1c33c10b8..32bd1ac38 100644 --- a/src/core/uaccess.c +++ b/src/core/uaccess.c @@ -32,7 +32,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); */ /* Flat address space user access API */ -PROVIDE_UACCESS_INLINE ( flat, phys_to_user ); -PROVIDE_UACCESS_INLINE ( flat, user_to_phys ); +PROVIDE_UACCESS_INLINE ( flat, phys_to_virt ); +PROVIDE_UACCESS_INLINE ( flat, virt_to_phys ); PROVIDE_UACCESS_INLINE ( flat, virt_to_user ); PROVIDE_UACCESS_INLINE ( flat, memchr_user ); diff --git a/src/drivers/block/srp.c b/src/drivers/block/srp.c index ab4812519..c12f230f7 100644 --- a/src/drivers/block/srp.c +++ b/src/drivers/block/srp.c @@ -428,7 +428,7 @@ static int srp_cmd ( struct srp_device *srpdev, cmd->data_buffer_formats |= SRP_CMD_DO_FMT_DIRECT; data_out = iob_put ( iobuf, sizeof ( *data_out ) ); data_out->address = - cpu_to_be64 ( user_to_phys ( command->data_out, 0 ) ); + cpu_to_be64 ( virt_to_phys ( command->data_out ) ); data_out->handle = ntohl ( srpdev->memory_handle ); data_out->len = ntohl ( command->data_out_len ); } @@ -438,7 +438,7 @@ static int srp_cmd ( struct srp_device *srpdev, cmd->data_buffer_formats |= SRP_CMD_DI_FMT_DIRECT; data_in = iob_put ( iobuf, sizeof ( *data_in ) ); data_in->address = - cpu_to_be64 ( user_to_phys ( command->data_in, 0 ) ); + cpu_to_be64 ( virt_to_phys ( command->data_in ) ); data_in->handle = ntohl ( srpdev->memory_handle ); data_in->len = ntohl ( command->data_in_len ); } diff --git a/src/drivers/infiniband/arbel.c b/src/drivers/infiniband/arbel.c index 8be06d93d..4cb4167e0 100644 --- a/src/drivers/infiniband/arbel.c +++ b/src/drivers/infiniband/arbel.c @@ -2079,7 +2079,7 @@ static int arbel_start_firmware ( struct arbel *arbel ) { } else { assert ( arbel->firmware_len == fw_len ); } - fw_base = user_to_phys ( arbel->firmware_area, 0 ); + fw_base = virt_to_phys ( arbel->firmware_area ); DBGC ( arbel, "Arbel %p firmware area at [%08lx,%08lx)\n", arbel, fw_base, ( fw_base + fw_len ) ); if ( ( rc = arbel_map_vpm ( arbel, arbel_cmd_map_fa, @@ -2452,7 +2452,7 @@ static int arbel_alloc_icm ( struct arbel *arbel, assert ( arbel->icm_len == icm_len ); assert ( arbel->icm_aux_len == icm_aux_len ); } - icm_phys = user_to_phys ( arbel->icm, 0 ); + icm_phys = virt_to_phys ( arbel->icm ); /* Allocate doorbell UAR */ arbel->db_rec = malloc_phys ( ARBEL_PAGE_SIZE, ARBEL_PAGE_SIZE ); diff --git a/src/drivers/infiniband/golan.c b/src/drivers/infiniband/golan.c index 81fc6c0f0..a33bad9ff 100755 --- a/src/drivers/infiniband/golan.c +++ b/src/drivers/infiniband/golan.c @@ -486,8 +486,8 @@ static inline int golan_provide_pages ( struct golan *golan , uint32_t pages for ( i = 0 , j = MANAGE_PAGES_PSA_OFFSET; i < pas_num; ++i ,++j, next_page_addr += GOLAN_PAGE_SIZE ) { addr = next_page_addr; - if (GOLAN_PAGE_MASK & user_to_phys(addr, 0)) { - DBGC (golan ,"Addr not Page alligned [%lx]\n", user_to_phys(addr, 0)); + if (GOLAN_PAGE_MASK & virt_to_phys(addr)) { + DBGC (golan ,"Addr not Page alligned [%lx]\n", virt_to_phys(addr)); } mailbox->mblock.data[j] = USR_2_BE64_BUS(addr); } diff --git a/src/drivers/infiniband/golan.h b/src/drivers/infiniband/golan.h index 2fd06ecf0..f7da1e960 100755 --- a/src/drivers/infiniband/golan.h +++ b/src/drivers/infiniband/golan.h @@ -69,8 +69,8 @@ FILE_LICENCE ( GPL2_OR_LATER ); #define VIRT_2_BE64_BUS( addr ) cpu_to_be64(((unsigned long long )virt_to_bus(addr))) #define BE64_BUS_2_VIRT( addr ) bus_to_virt(be64_to_cpu(addr)) -#define USR_2_BE64_BUS( addr ) cpu_to_be64(((unsigned long long )user_to_phys(addr, 0))) -#define BE64_BUS_2_USR( addr ) be64_to_cpu(phys_to_user(addr)) +#define USR_2_BE64_BUS( addr ) cpu_to_be64(((unsigned long long )virt_to_phys(addr))) +#define BE64_BUS_2_USR( addr ) be64_to_cpu(phys_to_virt(addr)) #define GET_INBOX(golan, idx) (&(((struct mbox *)(golan->mboxes.inbox))[idx])) #define GET_OUTBOX(golan, idx) (&(((struct mbox *)(golan->mboxes.outbox))[idx])) diff --git a/src/drivers/infiniband/hermon.c b/src/drivers/infiniband/hermon.c index e5c3544fa..3138d8bfb 100644 --- a/src/drivers/infiniband/hermon.c +++ b/src/drivers/infiniband/hermon.c @@ -2382,7 +2382,7 @@ static int hermon_start_firmware ( struct hermon *hermon ) { } else { assert ( hermon->firmware_len == fw_len ); } - fw_base = user_to_phys ( hermon->firmware_area, 0 ); + fw_base = virt_to_phys ( hermon->firmware_area ); DBGC ( hermon, "Hermon %p firmware area at physical [%08lx,%08lx)\n", hermon, fw_base, ( fw_base + fw_len ) ); if ( ( rc = hermon_map_vpm ( hermon, hermon_cmd_map_fa, @@ -2752,7 +2752,7 @@ static int hermon_map_icm ( struct hermon *hermon, assert ( hermon->icm_len == icm_len ); assert ( hermon->icm_aux_len == icm_aux_len ); } - icm_phys = user_to_phys ( hermon->icm, 0 ); + icm_phys = virt_to_phys ( hermon->icm ); /* Map ICM auxiliary area */ DBGC ( hermon, "Hermon %p mapping ICM AUX => %08lx\n", diff --git a/src/drivers/net/exanic.c b/src/drivers/net/exanic.c index 14a17df47..b3148e090 100644 --- a/src/drivers/net/exanic.c +++ b/src/drivers/net/exanic.c @@ -406,7 +406,7 @@ static int exanic_open ( struct net_device *netdev ) { port->rx_cons = 0; /* Map receive region */ - exanic_write_base ( phys_to_bus ( user_to_phys ( port->rx, 0 ) ), + exanic_write_base ( phys_to_bus ( virt_to_phys ( port->rx ) ), ( port->regs + EXANIC_PORT_RX_BASE ) ); /* Enable promiscuous mode */ @@ -729,8 +729,8 @@ static int exanic_probe_port ( struct exanic *exanic, struct device *dev, DBGC ( port, "EXANIC %s port %d TX [%#05zx,%#05zx) TXF %#02x RX " "[%#lx,%#lx)\n", netdev->name, index, port->tx_offset, ( port->tx_offset + tx_len ), port->txf_slot, - user_to_phys ( port->rx, 0 ), - user_to_phys ( port->rx, EXANIC_RX_LEN ) ); + virt_to_phys ( port->rx ), + ( virt_to_phys ( port->rx ) + EXANIC_RX_LEN ) ); /* Set initial link state */ exanic_check_link ( netdev ); diff --git a/src/drivers/net/gve.c b/src/drivers/net/gve.c index 2cbc401f5..f9ec388a4 100644 --- a/src/drivers/net/gve.c +++ b/src/drivers/net/gve.c @@ -521,14 +521,14 @@ static int gve_deconfigure ( struct gve_nic *gve ) { static int gve_register ( struct gve_nic *gve, struct gve_qpl *qpl ) { struct gve_pages *pages = &gve->scratch.buf->pages; union gve_admin_command *cmd; - physaddr_t addr; + void *addr; unsigned int i; int rc; /* Build page address list */ for ( i = 0 ; i < qpl->count ; i++ ) { - addr = user_to_phys ( qpl->data, ( i * GVE_PAGE_SIZE ) ); - pages->addr[i] = cpu_to_be64 ( dma_phys ( &qpl->map, addr ) ); + addr = ( qpl->data + ( i * GVE_PAGE_SIZE ) ); + pages->addr[i] = cpu_to_be64 ( dma ( &qpl->map, addr ) ); } /* Construct request */ @@ -575,11 +575,10 @@ static void gve_create_tx_param ( struct gve_queue *queue, union gve_admin_command *cmd ) { struct gve_admin_create_tx *create = &cmd->create_tx; const struct gve_queue_type *type = queue->type; - physaddr_t desc = user_to_phys ( queue->desc, 0 ); /* Construct request parameters */ create->res = cpu_to_be64 ( dma ( &queue->res_map, queue->res ) ); - create->desc = cpu_to_be64 ( dma_phys ( &queue->desc_map, desc ) ); + create->desc = cpu_to_be64 ( dma ( &queue->desc_map, queue->desc ) ); create->qpl_id = cpu_to_be32 ( type->qpl ); create->notify_id = cpu_to_be32 ( type->irq ); } @@ -594,14 +593,12 @@ static void gve_create_rx_param ( struct gve_queue *queue, union gve_admin_command *cmd ) { struct gve_admin_create_rx *create = &cmd->create_rx; const struct gve_queue_type *type = queue->type; - physaddr_t desc = user_to_phys ( queue->desc, 0 ); - physaddr_t cmplt = user_to_phys ( queue->cmplt, 0 ); /* Construct request parameters */ create->notify_id = cpu_to_be32 ( type->irq ); create->res = cpu_to_be64 ( dma ( &queue->res_map, queue->res ) ); - create->desc = cpu_to_be64 ( dma_phys ( &queue->desc_map, desc ) ); - create->cmplt = cpu_to_be64 ( dma_phys ( &queue->cmplt_map, cmplt ) ); + create->desc = cpu_to_be64 ( dma ( &queue->desc_map, queue->desc ) ); + create->cmplt = cpu_to_be64 ( dma ( &queue->cmplt_map, queue->cmplt )); create->qpl_id = cpu_to_be32 ( type->qpl ); create->bufsz = cpu_to_be16 ( GVE_BUF_SIZE ); } @@ -760,8 +757,8 @@ static int gve_alloc_qpl ( struct gve_nic *gve, struct gve_qpl *qpl, return -ENOMEM; DBGC ( gve, "GVE %p QPL %#08x at [%08lx,%08lx)\n", - gve, qpl->id, user_to_phys ( qpl->data, 0 ), - user_to_phys ( qpl->data, len ) ); + gve, qpl->id, virt_to_phys ( qpl->data ), + ( virt_to_phys ( qpl->data ) + len ) ); return 0; } @@ -883,8 +880,8 @@ static int gve_alloc_queue ( struct gve_nic *gve, struct gve_queue *queue ) { goto err_desc; } DBGC ( gve, "GVE %p %s descriptors at [%08lx,%08lx)\n", - gve, type->name, user_to_phys ( queue->desc, 0 ), - user_to_phys ( queue->desc, desc_len ) ); + gve, type->name, virt_to_phys ( queue->desc ), + ( virt_to_phys ( queue->desc ) + desc_len ) ); /* Allocate completions */ if ( cmplt_len ) { @@ -895,8 +892,8 @@ static int gve_alloc_queue ( struct gve_nic *gve, struct gve_queue *queue ) { goto err_cmplt; } DBGC ( gve, "GVE %p %s completions at [%08lx,%08lx)\n", - gve, type->name, user_to_phys ( queue->cmplt, 0 ), - user_to_phys ( queue->cmplt, cmplt_len ) ); + gve, type->name, virt_to_phys ( queue->cmplt ), + ( virt_to_phys ( queue->cmplt ) + cmplt_len ) ); } /* Allocate queue resources */ diff --git a/src/drivers/net/thunderx.c b/src/drivers/net/thunderx.c index 1865a9b91..3d213b167 100644 --- a/src/drivers/net/thunderx.c +++ b/src/drivers/net/thunderx.c @@ -118,14 +118,14 @@ static int txnic_create_sq ( struct txnic *vnic ) { writeq ( TXNIC_QS_SQ_CFG_RESET, ( vnic->regs + TXNIC_QS_SQ_CFG(0) ) ); /* Configure and enable send queue */ - writeq ( user_to_phys ( vnic->sq.sqe, 0 ), + writeq ( virt_to_phys ( vnic->sq.sqe ), ( vnic->regs + TXNIC_QS_SQ_BASE(0) ) ); writeq ( ( TXNIC_QS_SQ_CFG_ENA | TXNIC_QS_SQ_CFG_QSIZE_1K ), ( vnic->regs + TXNIC_QS_SQ_CFG(0) ) ); DBGC ( vnic, "TXNIC %s SQ at [%08lx,%08lx)\n", - vnic->name, user_to_phys ( vnic->sq.sqe, 0 ), - user_to_phys ( vnic->sq.sqe, TXNIC_SQ_SIZE ) ); + vnic->name, virt_to_phys ( vnic->sq.sqe ), + ( virt_to_phys ( vnic->sq.sqe ) + TXNIC_SQ_SIZE ) ); return 0; } @@ -277,7 +277,7 @@ static int txnic_create_rq ( struct txnic *vnic ) { ( vnic->regs + TXNIC_QS_RBDR_CFG(0) ) ); /* Configure and enable receive buffer descriptor ring */ - writeq ( user_to_phys ( vnic->rq.rqe, 0 ), + writeq ( virt_to_phys ( vnic->rq.rqe ), ( vnic->regs + TXNIC_QS_RBDR_BASE(0) ) ); writeq ( ( TXNIC_QS_RBDR_CFG_ENA | TXNIC_QS_RBDR_CFG_QSIZE_8K | TXNIC_QS_RBDR_CFG_LINES ( TXNIC_RQE_SIZE / @@ -288,8 +288,8 @@ static int txnic_create_rq ( struct txnic *vnic ) { writeq ( TXNIC_QS_RQ_CFG_ENA, ( vnic->regs + TXNIC_QS_RQ_CFG(0) ) ); DBGC ( vnic, "TXNIC %s RQ at [%08lx,%08lx)\n", - vnic->name, user_to_phys ( vnic->rq.rqe, 0 ), - user_to_phys ( vnic->rq.rqe, TXNIC_RQ_SIZE ) ); + vnic->name, virt_to_phys ( vnic->rq.rqe ), + ( virt_to_phys ( vnic->rq.rqe ) + TXNIC_RQ_SIZE ) ); return 0; } @@ -463,14 +463,14 @@ static int txnic_create_cq ( struct txnic *vnic ) { writeq ( TXNIC_QS_CQ_CFG_RESET, ( vnic->regs + TXNIC_QS_CQ_CFG(0) ) ); /* Configure and enable completion queue */ - writeq ( user_to_phys ( vnic->cq.cqe, 0 ), + writeq ( virt_to_phys ( vnic->cq.cqe ), ( vnic->regs + TXNIC_QS_CQ_BASE(0) ) ); writeq ( ( TXNIC_QS_CQ_CFG_ENA | TXNIC_QS_CQ_CFG_QSIZE_256 ), ( vnic->regs + TXNIC_QS_CQ_CFG(0) ) ); DBGC ( vnic, "TXNIC %s CQ at [%08lx,%08lx)\n", - vnic->name, user_to_phys ( vnic->cq.cqe, 0 ), - user_to_phys ( vnic->cq.cqe, TXNIC_CQ_SIZE ) ); + vnic->name, virt_to_phys ( vnic->cq.cqe ), + ( virt_to_phys ( vnic->cq.cqe ) + TXNIC_CQ_SIZE ) ); return 0; } @@ -559,7 +559,8 @@ static void txnic_poll_cq ( struct txnic *vnic ) { default: DBGC ( vnic, "TXNIC %s unknown completion type %d\n", vnic->name, cqe.common.cqe_type ); - DBGC_HDA ( vnic, user_to_phys ( vnic->cq.cqe, offset ), + DBGC_HDA ( vnic, + ( virt_to_phys ( vnic->cq.cqe ) + offset ), &cqe, sizeof ( cqe ) ); break; } diff --git a/src/drivers/usb/xhci.c b/src/drivers/usb/xhci.c index f244086ce..30ee09bbb 100644 --- a/src/drivers/usb/xhci.c +++ b/src/drivers/usb/xhci.c @@ -1014,8 +1014,7 @@ static int xhci_scratchpad_alloc ( struct xhci_device *xhci ) { } /* Populate scratchpad array */ - addr = dma_phys ( &scratch->buffer_map, - user_to_phys ( scratch->buffer, 0 ) ); + addr = dma ( &scratch->buffer_map, scratch->buffer ); for ( i = 0 ; i < scratch->count ; i++ ) { scratch->array[i] = cpu_to_le64 ( addr ); addr += xhci->pagesize; @@ -1027,8 +1026,8 @@ static int xhci_scratchpad_alloc ( struct xhci_device *xhci ) { scratch->array ) ); DBGC2 ( xhci, "XHCI %s scratchpad [%08lx,%08lx) array [%08lx,%08lx)\n", - xhci->name, user_to_phys ( scratch->buffer, 0 ), - user_to_phys ( scratch->buffer, buffer_len ), + xhci->name, virt_to_phys ( scratch->buffer ), + ( virt_to_phys ( scratch->buffer ) + buffer_len ), virt_to_phys ( scratch->array ), ( virt_to_phys ( scratch->array ) + array_len ) ); return 0; diff --git a/src/hci/commands/image_mem_cmd.c b/src/hci/commands/image_mem_cmd.c index c8bfab1ad..5f8363461 100644 --- a/src/hci/commands/image_mem_cmd.c +++ b/src/hci/commands/image_mem_cmd.c @@ -81,7 +81,7 @@ static int imgmem_exec ( int argc, char **argv ) { return rc; /* Create image */ - if ( ( rc = imgmem ( opts.name, phys_to_user ( data ), len ) ) != 0 ) + if ( ( rc = imgmem ( opts.name, phys_to_virt ( data ), len ) ) != 0 ) return rc; return 0; diff --git a/src/image/elf.c b/src/image/elf.c index 46c9fe8eb..fa714b15f 100644 --- a/src/image/elf.c +++ b/src/image/elf.c @@ -50,7 +50,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); */ static int elf_load_segment ( struct image *image, Elf_Phdr *phdr, physaddr_t dest ) { - userptr_t buffer = phys_to_user ( dest ); + userptr_t buffer = phys_to_virt ( dest ); int rc; DBGC ( image, "ELF %p loading segment [%x,%x) to [%lx,%lx,%lx)\n", diff --git a/src/image/segment.c b/src/image/segment.c index b7f8ef56c..ebc2b703d 100644 --- a/src/image/segment.c +++ b/src/image/segment.c @@ -59,9 +59,9 @@ struct errortab segment_errors[] __errortab = { */ int prep_segment ( userptr_t segment, size_t filesz, size_t memsz ) { struct memory_map memmap; - physaddr_t start = user_to_phys ( segment, 0 ); - physaddr_t mid = user_to_phys ( segment, filesz ); - physaddr_t end = user_to_phys ( segment, memsz ); + physaddr_t start = virt_to_phys ( segment ); + physaddr_t mid = ( start + filesz ); + physaddr_t end = ( start + memsz ); unsigned int i; DBG ( "Preparing segment [%lx,%lx,%lx)\n", start, mid, end ); diff --git a/src/include/ipxe/linux/linux_uaccess.h b/src/include/ipxe/linux/linux_uaccess.h index 4b1257b1e..b4f7e2fc6 100644 --- a/src/include/ipxe/linux/linux_uaccess.h +++ b/src/include/ipxe/linux/linux_uaccess.h @@ -10,10 +10,9 @@ * * We have no concept of the underlying physical addresses, since * these are not exposed to userspace. We provide a stub - * implementation of user_to_phys() since this is required by - * alloc_memblock(). We provide no implementation of phys_to_user(); - * any code attempting to access physical addresses will therefore - * (correctly) fail to link. + * implementation of virt_to_phys() since this is required by + * alloc_memblock(). We provide a matching stub implementation of + * phys_to_virt(). */ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); @@ -25,14 +24,13 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #endif /** - * Convert user pointer to physical address + * Convert virtual address to physical address * - * @v userptr User pointer - * @v offset Offset from user pointer - * @ret phys_addr Physical address + * @v virt Virtual address + * @ret phys Physical address */ -static inline __always_inline unsigned long -UACCESS_INLINE ( linux, user_to_phys ) ( userptr_t userptr, off_t offset ) { +static inline __always_inline physaddr_t +UACCESS_INLINE ( linux, virt_to_phys ) ( volatile const void *virt ) { /* We do not know the real underlying physical address. We * provide this stub implementation only because it is @@ -43,20 +41,20 @@ UACCESS_INLINE ( linux, user_to_phys ) ( userptr_t userptr, off_t offset ) { * virtual address will suffice for the purpose of determining * alignment. */ - return ( ( unsigned long ) ( userptr + offset ) ); + return ( ( physaddr_t ) virt ); } /** - * Convert physical address to user pointer + * Convert physical address to virtual address * - * @v phys_addr Physical address - * @ret userptr User pointer + * @v phys Physical address + * @ret virt Virtual address */ -static inline __always_inline userptr_t -UACCESS_INLINE ( linux, phys_to_user ) ( physaddr_t phys_addr ) { +static inline __always_inline void * +UACCESS_INLINE ( linux, phys_to_virt ) ( physaddr_t phys ) { - /* For symmetry with the stub user_to_phys() */ - return ( ( userptr_t ) phys_addr ); + /* For symmetry with the stub virt_to_phys() */ + return ( ( void * ) phys ); } static inline __always_inline userptr_t diff --git a/src/include/ipxe/uaccess.h b/src/include/ipxe/uaccess.h index 4b3524bab..62030dd8a 100644 --- a/src/include/ipxe/uaccess.h +++ b/src/include/ipxe/uaccess.h @@ -99,14 +99,14 @@ trivial_memchr_user ( userptr_t buffer, off_t offset, int c, size_t len ) { #define PROVIDE_UACCESS_INLINE( _subsys, _api_func ) \ PROVIDE_SINGLE_API_INLINE ( UACCESS_PREFIX_ ## _subsys, _api_func ) -static inline __always_inline userptr_t -UACCESS_INLINE ( flat, phys_to_user ) ( unsigned long phys_addr ) { - return ( ( userptr_t ) phys_addr ); +static inline __always_inline void * +UACCESS_INLINE ( flat, phys_to_virt ) ( physaddr_t phys ) { + return ( ( void * ) phys ); } -static inline __always_inline unsigned long -UACCESS_INLINE ( flat, user_to_phys ) ( userptr_t userptr, off_t offset ) { - return ( ( unsigned long ) ( userptr + offset ) ); +static inline __always_inline physaddr_t +UACCESS_INLINE ( flat, virt_to_phys ) ( volatile const void *virt ) { + return ( ( physaddr_t ) virt ); } static inline __always_inline userptr_t @@ -126,23 +126,6 @@ UACCESS_INLINE ( flat, memchr_user ) ( userptr_t buffer, off_t offset, /* Include all architecture-dependent user access API headers */ #include -/** - * Convert physical address to user pointer - * - * @v phys_addr Physical address - * @ret userptr User pointer - */ -userptr_t phys_to_user ( unsigned long phys_addr ); - -/** - * Convert user pointer to physical address - * - * @v userptr User pointer - * @v offset Offset from user pointer - * @ret phys_addr Physical address - */ -unsigned long user_to_phys ( userptr_t userptr, off_t offset ); - /** * Convert virtual address to user pointer * @@ -154,25 +137,21 @@ userptr_t virt_to_user ( volatile const void *addr ); /** * Convert virtual address to a physical address * - * @v addr Virtual address - * @ret phys_addr Physical address + * @v virt Virtual address + * @ret phys Physical address */ -static inline __always_inline unsigned long -virt_to_phys ( volatile const void *addr ) { - return user_to_phys ( virt_to_user ( addr ), 0 ); -} +physaddr_t __attribute__ (( const )) +virt_to_phys ( volatile const void *virt ); /** * Convert physical address to a virtual address * - * @v addr Virtual address - * @ret phys_addr Physical address + * @v phys Physical address + * @ret virt Virtual address * * This operation is not available under all memory models. */ -static inline __always_inline void * phys_to_virt ( unsigned long phys_addr ) { - return ( phys_to_user ( phys_addr ) ); -} +void * __attribute__ (( const )) phys_to_virt ( physaddr_t phys ); /** * Copy data to user buffer diff --git a/src/interface/efi/efi_acpi.c b/src/interface/efi/efi_acpi.c index 07a225632..c1046c01a 100644 --- a/src/interface/efi/efi_acpi.c +++ b/src/interface/efi/efi_acpi.c @@ -48,7 +48,7 @@ static userptr_t efi_find_rsdt ( void ) { /* Locate RSDT via ACPI configuration table, if available */ if ( rsdp ) - return phys_to_user ( rsdp->RsdtAddress ); + return phys_to_virt ( rsdp->RsdtAddress ); return UNULL; } diff --git a/src/interface/efi/efi_fbcon.c b/src/interface/efi/efi_fbcon.c index 659ebd37e..09cfde4c2 100644 --- a/src/interface/efi/efi_fbcon.c +++ b/src/interface/efi/efi_fbcon.c @@ -583,7 +583,7 @@ static int efifb_init ( struct console_configuration *config ) { mode, efifb.pixel.width, efifb.pixel.height, bpp, efifb.start ); /* Initialise frame buffer console */ - if ( ( rc = fbcon_init ( &efifb.fbcon, phys_to_user ( efifb.start ), + if ( ( rc = fbcon_init ( &efifb.fbcon, phys_to_virt ( efifb.start ), &efifb.pixel, &efifb.map, &efifb.font, config ) ) != 0 ) goto err_fbcon_init; diff --git a/src/interface/efi/efi_smbios.c b/src/interface/efi/efi_smbios.c index d7877b0aa..3c1b77bdc 100644 --- a/src/interface/efi/efi_smbios.c +++ b/src/interface/efi/efi_smbios.c @@ -48,27 +48,27 @@ static int efi_find_smbios ( struct smbios *smbios ) { /* Use 64-bit table if present */ if ( smbios3_entry && ( smbios3_entry->signature == SMBIOS3_SIGNATURE ) ) { - smbios->address = phys_to_user ( smbios3_entry->smbios_address ); + smbios->address = phys_to_virt ( smbios3_entry->smbios_address ); smbios->len = smbios3_entry->smbios_len; smbios->count = 0; smbios->version = SMBIOS_VERSION ( smbios3_entry->major, smbios3_entry->minor ); DBG ( "Found 64-bit SMBIOS v%d.%d entry point at %p (%lx+%zx)\n", smbios3_entry->major, smbios3_entry->minor, smbios3_entry, - user_to_phys ( smbios->address, 0 ), smbios->len ); + virt_to_phys ( smbios->address ), smbios->len ); return 0; } /* Otherwise, use 32-bit table if present */ if ( smbios_entry && ( smbios_entry->signature == SMBIOS_SIGNATURE ) ) { - smbios->address = phys_to_user ( smbios_entry->smbios_address ); + smbios->address = phys_to_virt ( smbios_entry->smbios_address ); smbios->len = smbios_entry->smbios_len; smbios->count = smbios_entry->smbios_count; smbios->version = SMBIOS_VERSION ( smbios_entry->major, smbios_entry->minor ); DBG ( "Found 32-bit SMBIOS v%d.%d entry point at %p (%lx+%zx)\n", smbios_entry->major, smbios_entry->minor, smbios_entry, - user_to_phys ( smbios->address, 0 ), smbios->len ); + virt_to_phys ( smbios->address ), smbios->len ); return 0; } diff --git a/src/interface/efi/efi_umalloc.c b/src/interface/efi/efi_umalloc.c index 488c53f3d..0636cb7fd 100644 --- a/src/interface/efi/efi_umalloc.c +++ b/src/interface/efi/efi_umalloc.c @@ -72,7 +72,7 @@ static userptr_t efi_urealloc ( userptr_t old_ptr, size_t new_size ) { return UNULL; } assert ( phys_addr != 0 ); - new_ptr = phys_to_user ( phys_addr + EFI_PAGE_SIZE ); + new_ptr = phys_to_virt ( phys_addr + EFI_PAGE_SIZE ); copy_to_user ( new_ptr, -EFI_PAGE_SIZE, &new_size, sizeof ( new_size ) ); DBG ( "EFI allocated %d pages at %llx\n", @@ -90,7 +90,7 @@ static userptr_t efi_urealloc ( userptr_t old_ptr, size_t new_size ) { memcpy ( new_ptr, old_ptr, ( (old_size < new_size) ? old_size : new_size ) ); old_pages = ( EFI_SIZE_TO_PAGES ( old_size ) + 1 ); - phys_addr = user_to_phys ( old_ptr, -EFI_PAGE_SIZE ); + phys_addr = virt_to_phys ( old_ptr - EFI_PAGE_SIZE ); if ( ( efirc = bs->FreePages ( phys_addr, old_pages ) ) != 0 ){ rc = -EEFI ( efirc ); DBG ( "EFI could not free %d pages at %llx: %s\n", diff --git a/src/interface/hyperv/vmbus.c b/src/interface/hyperv/vmbus.c index 86d2a08d7..49ccf69c8 100644 --- a/src/interface/hyperv/vmbus.c +++ b/src/interface/hyperv/vmbus.c @@ -277,7 +277,7 @@ int vmbus_establish_gpadl ( struct vmbus_device *vmdev, userptr_t data, size_t len ) { struct hv_hypervisor *hv = vmdev->hv; struct vmbus *vmbus = hv->vmbus; - physaddr_t addr = user_to_phys ( data, 0 ); + physaddr_t addr = virt_to_phys ( data ); unsigned int pfn_count = hv_pfn_count ( addr, len ); struct { struct vmbus_gpadl_header gpadlhdr; diff --git a/src/interface/linux/linux_uaccess.c b/src/interface/linux/linux_uaccess.c index e5c394365..4fdd8c03a 100644 --- a/src/interface/linux/linux_uaccess.c +++ b/src/interface/linux/linux_uaccess.c @@ -27,6 +27,7 @@ FILE_LICENCE(GPL2_OR_LATER); * */ -PROVIDE_UACCESS_INLINE(linux, user_to_phys); +PROVIDE_UACCESS_INLINE(linux, phys_to_virt); +PROVIDE_UACCESS_INLINE(linux, virt_to_phys); PROVIDE_UACCESS_INLINE(linux, virt_to_user); PROVIDE_UACCESS_INLINE(linux, memchr_user); diff --git a/src/interface/smbios/smbios.c b/src/interface/smbios/smbios.c index 3e69a0c15..89fa4d7ca 100644 --- a/src/interface/smbios/smbios.c +++ b/src/interface/smbios/smbios.c @@ -86,14 +86,14 @@ int find_smbios_entry ( userptr_t start, size_t len, if ( ( sum = smbios_checksum ( start, offset, entry->len ) ) != 0 ) { DBG ( "SMBIOS at %08lx has bad checksum %02x\n", - user_to_phys ( start, offset ), sum ); + virt_to_phys ( start + offset ), sum ); continue; } /* Fill result structure */ DBG ( "Found SMBIOS v%d.%d entry point at %08lx\n", entry->major, entry->minor, - user_to_phys ( start, offset ) ); + virt_to_phys ( start + offset ) ); return 0; } @@ -126,14 +126,14 @@ int find_smbios3_entry ( userptr_t start, size_t len, if ( ( sum = smbios_checksum ( start, offset, entry->len ) ) != 0 ) { DBG ( "SMBIOS3 at %08lx has bad checksum %02x\n", - user_to_phys ( start, offset ), sum ); + virt_to_phys ( start + offset ), sum ); continue; } /* Fill result structure */ DBG ( "Found SMBIOS3 v%d.%d entry point at %08lx\n", entry->major, entry->minor, - user_to_phys ( start, offset ) ); + virt_to_phys ( start + offset ) ); return 0; } -- cgit v1.2.3-55-g7522 From 0b3fc48fefd311b17b666fecf3a34688717727e8 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 22 Apr 2025 14:13:45 +0100 Subject: [acpi] Remove userptr_t from ACPI table parsing Simplify the ACPI table parsing code by assuming that all table content is fully accessible via pointer dereferences. Signed-off-by: Michael Brown --- src/arch/x86/include/ipxe/rsdp.h | 4 +- src/arch/x86/interface/pcbios/acpi_timer.c | 9 +-- src/arch/x86/interface/pcbios/acpipwr.c | 18 ++--- src/arch/x86/interface/pcbios/rsdp.c | 33 ++++---- src/core/acpi.c | 116 +++++++++++++---------------- src/core/acpi_settings.c | 21 +++--- src/core/acpimac.c | 17 +++-- src/drivers/bus/ecam.c | 34 ++++----- src/include/ipxe/acpi.h | 24 +++--- src/include/ipxe/efi/efi_acpi.h | 4 +- src/include/ipxe/null_acpi.h | 6 +- src/interface/efi/efi_acpi.c | 7 +- src/interface/linux/linux_acpi.c | 9 ++- src/tests/acpi_test.c | 12 +-- 14 files changed, 152 insertions(+), 162 deletions(-) (limited to 'src/interface/linux') diff --git a/src/arch/x86/include/ipxe/rsdp.h b/src/arch/x86/include/ipxe/rsdp.h index 14afcd774..daaa43077 100644 --- a/src/arch/x86/include/ipxe/rsdp.h +++ b/src/arch/x86/include/ipxe/rsdp.h @@ -20,9 +20,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * * @v signature Requested table signature * @v index Requested index of table with this signature - * @ret table Table, or UNULL if not found + * @ret table Table, or NULL if not found */ -static inline __attribute__ (( always_inline )) userptr_t +static inline __attribute__ (( always_inline )) const struct acpi_header * ACPI_INLINE ( rsdp, acpi_find ) ( uint32_t signature, unsigned int index ) { return acpi_find_via_rsdt ( signature, index ); diff --git a/src/arch/x86/interface/pcbios/acpi_timer.c b/src/arch/x86/interface/pcbios/acpi_timer.c index 2e4047e38..e1523578b 100644 --- a/src/arch/x86/interface/pcbios/acpi_timer.c +++ b/src/arch/x86/interface/pcbios/acpi_timer.c @@ -102,20 +102,19 @@ static void acpi_udelay ( unsigned long usecs ) { * @ret rc Return status code */ static int acpi_timer_probe ( void ) { - struct acpi_fadt fadtab; - userptr_t fadt; + const struct acpi_fadt *fadt; unsigned int pm_tmr_blk; /* Locate FADT */ - fadt = acpi_table ( FADT_SIGNATURE, 0 ); + fadt = container_of ( acpi_table ( FADT_SIGNATURE, 0 ), + struct acpi_fadt, acpi ); if ( ! fadt ) { DBGC ( &acpi_timer, "ACPI could not find FADT\n" ); return -ENOENT; } /* Read FADT */ - copy_from_user ( &fadtab, fadt, 0, sizeof ( fadtab ) ); - pm_tmr_blk = le32_to_cpu ( fadtab.pm_tmr_blk ); + pm_tmr_blk = le32_to_cpu ( fadt->pm_tmr_blk ); if ( ! pm_tmr_blk ) { DBGC ( &acpi_timer, "ACPI has no timer\n" ); return -ENOENT; diff --git a/src/arch/x86/interface/pcbios/acpipwr.c b/src/arch/x86/interface/pcbios/acpipwr.c index f08b4af25..bff53806b 100644 --- a/src/arch/x86/interface/pcbios/acpipwr.c +++ b/src/arch/x86/interface/pcbios/acpipwr.c @@ -62,8 +62,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * uglier hacks I have ever implemented, but it's still prettier than * the ACPI specification itself. */ -static int acpi_extract_sx ( userptr_t zsdt, size_t len, size_t offset, - void *data ) { +static int acpi_extract_sx ( const struct acpi_header *zsdt, size_t len, + size_t offset, void *data ) { unsigned int *sx = data; uint8_t bytes[4]; uint8_t *byte; @@ -77,7 +77,8 @@ static int acpi_extract_sx ( userptr_t zsdt, size_t len, size_t offset, } /* Read first four bytes of value */ - copy_from_user ( bytes, zsdt, offset, sizeof ( bytes ) ); + memcpy ( bytes, ( ( ( const void * ) zsdt ) + offset ), + sizeof ( bytes ) ); DBGC ( colour, "ACPI found \\_Sx containing %02x:%02x:%02x:%02x\n", bytes[0], bytes[1], bytes[2], bytes[3] ); @@ -111,8 +112,7 @@ static int acpi_extract_sx ( userptr_t zsdt, size_t len, size_t offset, * @ret rc Return status code */ int acpi_poweroff ( void ) { - struct acpi_fadt fadtab; - userptr_t fadt; + const struct acpi_fadt *fadt; unsigned int pm1a_cnt_blk; unsigned int pm1b_cnt_blk; unsigned int pm1a_cnt; @@ -123,16 +123,16 @@ int acpi_poweroff ( void ) { int rc; /* Locate FADT */ - fadt = acpi_table ( FADT_SIGNATURE, 0 ); + fadt = container_of ( acpi_table ( FADT_SIGNATURE, 0 ), + struct acpi_fadt, acpi ); if ( ! fadt ) { DBGC ( colour, "ACPI could not find FADT\n" ); return -ENOENT; } /* Read FADT */ - copy_from_user ( &fadtab, fadt, 0, sizeof ( fadtab ) ); - pm1a_cnt_blk = le32_to_cpu ( fadtab.pm1a_cnt_blk ); - pm1b_cnt_blk = le32_to_cpu ( fadtab.pm1b_cnt_blk ); + pm1a_cnt_blk = le32_to_cpu ( fadt->pm1a_cnt_blk ); + pm1b_cnt_blk = le32_to_cpu ( fadt->pm1b_cnt_blk ); pm1a_cnt = ( pm1a_cnt_blk + ACPI_PM1_CNT ); pm1b_cnt = ( pm1b_cnt_blk + ACPI_PM1_CNT ); diff --git a/src/arch/x86/interface/pcbios/rsdp.c b/src/arch/x86/interface/pcbios/rsdp.c index c2534c7f6..6bcf19b18 100644 --- a/src/arch/x86/interface/pcbios/rsdp.c +++ b/src/arch/x86/interface/pcbios/rsdp.c @@ -53,50 +53,51 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * * @v start Start address to search * @v len Length to search - * @ret rsdt ACPI root system description table, or UNULL + * @ret rsdt ACPI root system description table, or NULL */ -static userptr_t rsdp_find_rsdt_range ( userptr_t start, size_t len ) { +static const struct acpi_rsdt * rsdp_find_rsdt_range ( const void *start, + size_t len ) { static const char signature[8] = RSDP_SIGNATURE; - struct acpi_rsdp rsdp; - userptr_t rsdt; + const struct acpi_rsdp *rsdp; + const struct acpi_rsdt *rsdt; size_t offset; uint8_t sum; unsigned int i; /* Search for RSDP */ - for ( offset = 0 ; ( ( offset + sizeof ( rsdp ) ) < len ) ; + for ( offset = 0 ; ( ( offset + sizeof ( *rsdp ) ) < len ) ; offset += RSDP_STRIDE ) { /* Check signature and checksum */ - copy_from_user ( &rsdp, start, offset, sizeof ( rsdp ) ); - if ( memcmp ( rsdp.signature, signature, + rsdp = ( start + offset ); + if ( memcmp ( rsdp->signature, signature, sizeof ( signature ) ) != 0 ) continue; - for ( sum = 0, i = 0 ; i < sizeof ( rsdp ) ; i++ ) - sum += *( ( ( uint8_t * ) &rsdp ) + i ); + for ( sum = 0, i = 0 ; i < sizeof ( *rsdp ) ; i++ ) + sum += *( ( ( uint8_t * ) rsdp ) + i ); if ( sum != 0 ) continue; /* Extract RSDT */ - rsdt = phys_to_virt ( le32_to_cpu ( rsdp.rsdt ) ); + rsdt = phys_to_virt ( le32_to_cpu ( rsdp->rsdt ) ); DBGC ( rsdt, "RSDT %#08lx found via RSDP %#08lx\n", virt_to_phys ( rsdt ), ( virt_to_phys ( start ) + offset ) ); return rsdt; } - return UNULL; + return NULL; } /** * Locate ACPI root system description table * - * @ret rsdt ACPI root system description table, or UNULL + * @ret rsdt ACPI root system description table, or NULL */ -static userptr_t rsdp_find_rsdt ( void ) { - static userptr_t rsdt; +static const struct acpi_rsdt * rsdp_find_rsdt ( void ) { + static const struct acpi_rsdt *rsdt; + const void *ebda; uint16_t ebda_seg; - userptr_t ebda; size_t ebda_len; /* Return existing RSDT if already found */ @@ -119,7 +120,7 @@ static userptr_t rsdp_find_rsdt ( void ) { if ( rsdt ) return rsdt; - return UNULL; + return NULL; } PROVIDE_ACPI ( rsdp, acpi_find_rsdt, rsdp_find_rsdt ); diff --git a/src/core/acpi.c b/src/core/acpi.c index d7da0ccc1..6c5d1e079 100644 --- a/src/core/acpi.c +++ b/src/core/acpi.c @@ -23,6 +23,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); +#include #include #include #include @@ -54,25 +55,17 @@ typeof ( acpi_find ) *acpi_finder __attribute__ (( weak )) = acpi_find; /** * Compute ACPI table checksum * - * @v table Any ACPI table + * @v acpi Any ACPI table header * @ret checksum 0 if checksum is good */ -static uint8_t acpi_checksum ( userptr_t table ) { - struct acpi_header acpi; +static uint8_t acpi_checksum ( const struct acpi_header *acpi ) { + const uint8_t *byte = ( ( const void * ) acpi ); + size_t len = le32_to_cpu ( acpi->length ); uint8_t sum = 0; - uint8_t data = 0; - unsigned int i; - - /* Read table length */ - copy_from_user ( &acpi.length, table, - offsetof ( typeof ( acpi ), length ), - sizeof ( acpi.length ) ); /* Compute checksum */ - for ( i = 0 ; i < le32_to_cpu ( acpi.length ) ; i++ ) { - copy_from_user ( &data, table, i, sizeof ( data ) ); - sum += data; - } + while ( len-- ) + sum += *(byte++); return sum; } @@ -85,7 +78,7 @@ static uint8_t acpi_checksum ( userptr_t table ) { void acpi_fix_checksum ( struct acpi_header *acpi ) { /* Update checksum */ - acpi->checksum -= acpi_checksum ( virt_to_user ( acpi ) ); + acpi->checksum -= acpi_checksum ( acpi ); } /** @@ -93,9 +86,10 @@ void acpi_fix_checksum ( struct acpi_header *acpi ) { * * @v signature Requested table signature * @v index Requested index of table with this signature - * @ret table Table, or UNULL if not found + * @ret table Table, or NULL if not found */ -userptr_t acpi_table ( uint32_t signature, unsigned int index ) { +const struct acpi_header * acpi_table ( uint32_t signature, + unsigned int index ) { return ( *acpi_finder ) ( signature, index ); } @@ -105,14 +99,12 @@ userptr_t acpi_table ( uint32_t signature, unsigned int index ) { * * @v signature Requested table signature * @v index Requested index of table with this signature - * @ret table Table, or UNULL if not found + * @ret table Table, or NULL if not found */ -userptr_t acpi_find_via_rsdt ( uint32_t signature, unsigned int index ) { - struct acpi_header acpi; - struct acpi_rsdt *rsdtab; - typeof ( rsdtab->entry[0] ) entry; - userptr_t rsdt; - userptr_t table; +const struct acpi_header * acpi_find_via_rsdt ( uint32_t signature, + unsigned int index ) { + const struct acpi_rsdt *rsdt; + const struct acpi_header *table; size_t len; unsigned int count; unsigned int i; @@ -121,45 +113,38 @@ userptr_t acpi_find_via_rsdt ( uint32_t signature, unsigned int index ) { rsdt = acpi_find_rsdt(); if ( ! rsdt ) { DBG ( "RSDT not found\n" ); - return UNULL; + return NULL; } /* Read RSDT header */ - copy_from_user ( &acpi, rsdt, 0, sizeof ( acpi ) ); - if ( acpi.signature != cpu_to_le32 ( RSDT_SIGNATURE ) ) { + if ( rsdt->acpi.signature != cpu_to_le32 ( RSDT_SIGNATURE ) ) { DBGC ( colour, "RSDT %#08lx has invalid signature:\n", virt_to_phys ( rsdt ) ); - DBGC_HDA ( colour, virt_to_phys ( rsdt ), &acpi, - sizeof ( acpi ) ); - return UNULL; + DBGC_HDA ( colour, virt_to_phys ( rsdt ), &rsdt->acpi, + sizeof ( rsdt->acpi ) ); + return NULL; } - len = le32_to_cpu ( acpi.length ); - if ( len < sizeof ( rsdtab->acpi ) ) { + len = le32_to_cpu ( rsdt->acpi.length ); + if ( len < sizeof ( rsdt->acpi ) ) { DBGC ( colour, "RSDT %#08lx has invalid length:\n", virt_to_phys ( rsdt ) ); - DBGC_HDA ( colour, virt_to_phys ( rsdt ), &acpi, - sizeof ( acpi ) ); - return UNULL; + DBGC_HDA ( colour, virt_to_phys ( rsdt ), &rsdt->acpi, + sizeof ( rsdt->acpi ) ); + return NULL; } /* Calculate number of entries */ - count = ( ( len - sizeof ( rsdtab->acpi ) ) / sizeof ( entry ) ); + count = ( ( len - sizeof ( rsdt->acpi ) ) / + sizeof ( rsdt->entry[0] ) ); /* Search through entries */ for ( i = 0 ; i < count ; i++ ) { - /* Get table address */ - copy_from_user ( &entry, rsdt, - offsetof ( typeof ( *rsdtab ), entry[i] ), - sizeof ( entry ) ); - /* Read table header */ - table = phys_to_virt ( entry ); - copy_from_user ( &acpi.signature, table, 0, - sizeof ( acpi.signature ) ); + table = phys_to_virt ( rsdt->entry[i] ); /* Check table signature */ - if ( acpi.signature != cpu_to_le32 ( signature ) ) + if ( table->signature != cpu_to_le32 ( signature ) ) continue; /* Check index */ @@ -169,13 +154,13 @@ userptr_t acpi_find_via_rsdt ( uint32_t signature, unsigned int index ) { /* Check table integrity */ if ( acpi_checksum ( table ) != 0 ) { DBGC ( colour, "RSDT %#08lx found %s with bad " - "checksum at %08lx\n", virt_to_phys ( rsdt ), + "checksum at %#08lx\n", virt_to_phys ( rsdt ), acpi_name ( signature ), virt_to_phys ( table ) ); break; } - DBGC ( colour, "RSDT %#08lx found %s at %08lx\n", + DBGC ( colour, "RSDT %#08lx found %s at %#08lx\n", virt_to_phys ( rsdt ), acpi_name ( signature ), virt_to_phys ( table ) ); return table; @@ -183,7 +168,7 @@ userptr_t acpi_find_via_rsdt ( uint32_t signature, unsigned int index ) { DBGC ( colour, "RSDT %#08lx could not find %s\n", virt_to_phys ( rsdt ), acpi_name ( signature ) ); - return UNULL; + return NULL; } /** @@ -195,26 +180,27 @@ userptr_t acpi_find_via_rsdt ( uint32_t signature, unsigned int index ) { * @v extract Extraction method * @ret rc Return status code */ -static int acpi_zsdt ( userptr_t zsdt, uint32_t signature, void *data, - int ( * extract ) ( userptr_t zsdt, size_t len, - size_t offset, void *data ) ) { - struct acpi_header acpi; +static int acpi_zsdt ( const struct acpi_header *zsdt, + uint32_t signature, void *data, + int ( * extract ) ( const struct acpi_header *zsdt, + size_t len, size_t offset, + void *data ) ) { uint32_t buf; size_t offset; size_t len; int rc; /* Read table header */ - copy_from_user ( &acpi, zsdt, 0, sizeof ( acpi ) ); - len = le32_to_cpu ( acpi.length ); + len = le32_to_cpu ( zsdt->length ); /* Locate signature */ - for ( offset = sizeof ( acpi ) ; + for ( offset = sizeof ( *zsdt ) ; ( ( offset + sizeof ( buf ) /* signature */ ) < len ) ; offset++ ) { /* Check signature */ - copy_from_user ( &buf, zsdt, offset, sizeof ( buf ) ); + memcpy ( &buf, ( ( ( const void * ) zsdt ) + offset ), + sizeof ( buf ) ); if ( buf != cpu_to_le32 ( signature ) ) continue; DBGC ( zsdt, "DSDT/SSDT %#08lx found %s at offset %#zx\n", @@ -238,20 +224,20 @@ static int acpi_zsdt ( userptr_t zsdt, uint32_t signature, void *data, * @ret rc Return status code */ int acpi_extract ( uint32_t signature, void *data, - int ( * extract ) ( userptr_t zsdt, size_t len, - size_t offset, void *data ) ) { - struct acpi_fadt fadtab; - userptr_t fadt; - userptr_t dsdt; - userptr_t ssdt; + int ( * extract ) ( const struct acpi_header *zsdt, + size_t len, size_t offset, + void *data ) ) { + const struct acpi_fadt *fadt; + const struct acpi_header *dsdt; + const struct acpi_header *ssdt; unsigned int i; int rc; /* Try DSDT first */ - fadt = acpi_table ( FADT_SIGNATURE, 0 ); + fadt = container_of ( acpi_table ( FADT_SIGNATURE, 0 ), + struct acpi_fadt, acpi ); if ( fadt ) { - copy_from_user ( &fadtab, fadt, 0, sizeof ( fadtab ) ); - dsdt = phys_to_virt ( fadtab.dsdt ); + dsdt = phys_to_virt ( fadt->dsdt ); if ( ( rc = acpi_zsdt ( dsdt, signature, data, extract ) ) == 0 ) return 0; diff --git a/src/core/acpi_settings.c b/src/core/acpi_settings.c index b9e2b7f61..cdee1f865 100644 --- a/src/core/acpi_settings.c +++ b/src/core/acpi_settings.c @@ -64,14 +64,15 @@ static int acpi_settings_applies ( struct settings *settings __unused, static int acpi_settings_fetch ( struct settings *settings, struct setting *setting, void *data, size_t len ) { - struct acpi_header acpi; + const struct acpi_header *acpi; + const uint8_t *src; + uint8_t *dst; uint32_t tag_high; uint32_t tag_low; uint32_t tag_signature; unsigned int tag_index; size_t tag_offset; size_t tag_len; - userptr_t table; size_t offset; size_t max_len; int delta; @@ -88,15 +89,12 @@ static int acpi_settings_fetch ( struct settings *settings, acpi_name ( tag_signature ), tag_index, tag_offset, tag_len ); /* Locate ACPI table */ - table = acpi_table ( tag_signature, tag_index ); - if ( ! table ) + acpi = acpi_table ( tag_signature, tag_index ); + if ( ! acpi ) return -ENOENT; - /* Read table header */ - copy_from_user ( &acpi, table, 0, sizeof ( acpi ) ); - /* Calculate starting offset and maximum available length */ - max_len = le32_to_cpu ( acpi.length ); + max_len = le32_to_cpu ( acpi->length ); if ( tag_offset > max_len ) return -ENOENT; offset = tag_offset; @@ -115,10 +113,11 @@ static int acpi_settings_fetch ( struct settings *settings, } /* Read data */ + src = ( ( ( const void * ) acpi ) + offset ); + dst = data; for ( i = 0 ; ( ( i < max_len ) && ( i < len ) ) ; i++ ) { - copy_from_user ( data, table, offset, 1 ); - data++; - offset += delta; + *(dst++) = *src; + src += delta; } /* Set type if not already specified */ diff --git a/src/core/acpimac.c b/src/core/acpimac.c index e0074ba43..11ac3243e 100644 --- a/src/core/acpimac.c +++ b/src/core/acpimac.c @@ -142,8 +142,9 @@ static struct acpimac_extractor acpimac_rtxmac = { * string that appears shortly after an "AMAC" or "MACA" signature. * This should work for most implementations encountered in practice. */ -static int acpimac_extract ( userptr_t zsdt, size_t len, size_t offset, - void *data, struct acpimac_extractor *extractor ){ +static int acpimac_extract ( const struct acpi_header *zsdt, size_t len, + size_t offset, void *data, + struct acpimac_extractor *extractor ) { size_t prefix_len = strlen ( extractor->prefix ); uint8_t *hw_addr = data; size_t skip = 0; @@ -161,8 +162,8 @@ static int acpimac_extract ( userptr_t zsdt, size_t len, size_t offset, skip++ ) { /* Read value */ - copy_from_user ( buf, zsdt, ( offset + skip ), - sizeof ( buf ) ); + memcpy ( buf, ( ( ( const void * ) zsdt ) + offset + skip ), + sizeof ( buf ) ); /* Check for expected format */ if ( memcmp ( buf, extractor->prefix, prefix_len ) != 0 ) @@ -203,8 +204,8 @@ static int acpimac_extract ( userptr_t zsdt, size_t len, size_t offset, * @v data Data buffer * @ret rc Return status code */ -static int acpimac_extract_auxmac ( userptr_t zsdt, size_t len, size_t offset, - void *data ) { +static int acpimac_extract_auxmac ( const struct acpi_header *zsdt, + size_t len, size_t offset, void *data ) { return acpimac_extract ( zsdt, len, offset, data, &acpimac_auxmac ); } @@ -218,8 +219,8 @@ static int acpimac_extract_auxmac ( userptr_t zsdt, size_t len, size_t offset, * @v data Data buffer * @ret rc Return status code */ -static int acpimac_extract_rtxmac ( userptr_t zsdt, size_t len, size_t offset, - void *data ) { +static int acpimac_extract_rtxmac ( const struct acpi_header *zsdt, + size_t len, size_t offset, void *data ) { return acpimac_extract ( zsdt, len, offset, data, &acpimac_rtxmac ); } diff --git a/src/drivers/bus/ecam.c b/src/drivers/bus/ecam.c index cde5952b8..58d513e88 100644 --- a/src/drivers/bus/ecam.c +++ b/src/drivers/bus/ecam.c @@ -46,49 +46,43 @@ static struct ecam_mapping ecam; */ static int ecam_find ( uint32_t busdevfn, struct pci_range *range, struct ecam_allocation *alloc ) { - struct ecam_allocation tmp; + struct ecam_table *mcfg; + struct ecam_allocation *tmp; unsigned int best = 0; - unsigned int offset; unsigned int count; unsigned int index; - userptr_t mcfg; - uint32_t length; + unsigned int i; uint32_t start; /* Return empty range on error */ range->count = 0; /* Locate MCFG table */ - mcfg = acpi_table ( ECAM_SIGNATURE, 0 ); + mcfg = container_of ( acpi_table ( ECAM_SIGNATURE, 0 ), + struct ecam_table, acpi ); if ( ! mcfg ) { DBGC ( &ecam, "ECAM found no MCFG table\n" ); return -ENOTSUP; } - /* Get length of table */ - copy_from_user ( &length, mcfg, - offsetof ( struct ecam_table, acpi.length ), - sizeof ( length ) ); - /* Iterate over allocations */ - for ( offset = offsetof ( struct ecam_table, alloc ) ; - ( offset + sizeof ( tmp ) ) <= le32_to_cpu ( length ) ; - offset += sizeof ( tmp ) ) { + for ( i = 0 ; ( offsetof ( typeof ( *mcfg ), alloc[ i + 1 ] ) <= + le32_to_cpu ( mcfg->acpi.length ) ) ; i++ ) { /* Read allocation */ - copy_from_user ( &tmp, mcfg, offset, sizeof ( tmp ) ); + tmp = &mcfg->alloc[i]; DBGC2 ( &ecam, "ECAM %04x:[%02x-%02x] has base %08llx\n", - le16_to_cpu ( tmp.segment ), tmp.start, tmp.end, - ( ( unsigned long long ) le64_to_cpu ( tmp.base ) ) ); - start = PCI_BUSDEVFN ( le16_to_cpu ( tmp.segment ), - tmp.start, 0, 0 ); - count = PCI_BUSDEVFN ( 0, ( tmp.end - tmp.start + 1 ), 0, 0 ); + le16_to_cpu ( tmp->segment ), tmp->start, tmp->end, + ( ( unsigned long long ) le64_to_cpu ( tmp->base ) ) ); + start = PCI_BUSDEVFN ( le16_to_cpu ( tmp->segment ), + tmp->start, 0, 0 ); + count = PCI_BUSDEVFN ( 0, ( tmp->end - tmp->start + 1 ), 0, 0 ); /* Check for a matching or new closest allocation */ index = ( busdevfn - start ); if ( ( index < count ) || ( index > best ) ) { if ( alloc ) - memcpy ( alloc, &tmp, sizeof ( *alloc ) ); + memcpy ( alloc, tmp, sizeof ( *alloc ) ); range->start = start; range->count = count; best = index; diff --git a/src/include/ipxe/acpi.h b/src/include/ipxe/acpi.h index c34681238..40a44cffc 100644 --- a/src/include/ipxe/acpi.h +++ b/src/include/ipxe/acpi.h @@ -14,7 +14,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include #include -#include #include #include #include @@ -355,7 +354,8 @@ struct acpi_model { #define PROVIDE_ACPI_INLINE( _subsys, _api_func ) \ PROVIDE_SINGLE_API_INLINE ( ACPI_PREFIX_ ## _subsys, _api_func ) -extern userptr_t acpi_find_via_rsdt ( uint32_t signature, unsigned int index ); +extern const struct acpi_header * acpi_find_via_rsdt ( uint32_t signature, + unsigned int index ); /* Include all architecture-independent ACPI API headers */ #include @@ -368,31 +368,35 @@ extern userptr_t acpi_find_via_rsdt ( uint32_t signature, unsigned int index ); /** * Locate ACPI root system description table * - * @ret rsdt ACPI root system description table, or UNULL + * @ret rsdt ACPI root system description table, or NULL */ -userptr_t acpi_find_rsdt ( void ); +const struct acpi_rsdt * acpi_find_rsdt ( void ); /** * Locate ACPI table * * @v signature Requested table signature * @v index Requested index of table with this signature - * @ret table Table, or UNULL if not found + * @ret table Table, or NULL if not found */ -userptr_t acpi_find ( uint32_t signature, unsigned int index ); +const struct acpi_header * acpi_find ( uint32_t signature, + unsigned int index ); extern struct acpi_descriptor * acpi_describe ( struct interface *interface ); #define acpi_describe_TYPE( object_type ) \ typeof ( struct acpi_descriptor * ( object_type ) ) -extern userptr_t ( * acpi_finder ) ( uint32_t signature, unsigned int index ); +extern const struct acpi_header * ( * acpi_finder ) ( uint32_t signature, + unsigned int index ); extern void acpi_fix_checksum ( struct acpi_header *acpi ); -extern userptr_t acpi_table ( uint32_t signature, unsigned int index ); +extern const struct acpi_header * acpi_table ( uint32_t signature, + unsigned int index ); extern int acpi_extract ( uint32_t signature, void *data, - int ( * extract ) ( userptr_t zsdt, size_t len, - size_t offset, void *data ) ); + int ( * extract ) ( const struct acpi_header *zsdt, + size_t len, size_t offset, + void *data ) ); extern void acpi_add ( struct acpi_descriptor *desc ); extern void acpi_del ( struct acpi_descriptor *desc ); extern int acpi_install ( int ( * install ) ( struct acpi_header *acpi ) ); diff --git a/src/include/ipxe/efi/efi_acpi.h b/src/include/ipxe/efi/efi_acpi.h index a698863a6..68f9c5be7 100644 --- a/src/include/ipxe/efi/efi_acpi.h +++ b/src/include/ipxe/efi/efi_acpi.h @@ -20,9 +20,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * * @v signature Requested table signature * @v index Requested index of table with this signature - * @ret table Table, or UNULL if not found + * @ret table Table, or NULL if not found */ -static inline __attribute__ (( always_inline )) userptr_t +static inline __attribute__ (( always_inline )) const struct acpi_header * ACPI_INLINE ( efi, acpi_find ) ( uint32_t signature, unsigned int index ) { return acpi_find_via_rsdt ( signature, index ); diff --git a/src/include/ipxe/null_acpi.h b/src/include/ipxe/null_acpi.h index cedb02839..18f059964 100644 --- a/src/include/ipxe/null_acpi.h +++ b/src/include/ipxe/null_acpi.h @@ -9,17 +9,19 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); +#include + #ifdef ACPI_NULL #define ACPI_PREFIX_null #else #define ACPI_PREFIX_null __null_ #endif -static inline __attribute__ (( always_inline )) userptr_t +static inline __attribute__ (( always_inline )) const struct acpi_header * ACPI_INLINE ( null, acpi_find ) ( uint32_t signature __unused, unsigned int index __unused ) { - return UNULL; + return NULL; } #endif /* _IPXE_NULL_ACPI_H */ diff --git a/src/interface/efi/efi_acpi.c b/src/interface/efi/efi_acpi.c index c1046c01a..a2021a4f6 100644 --- a/src/interface/efi/efi_acpi.c +++ b/src/interface/efi/efi_acpi.c @@ -31,6 +31,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); */ #include +#include #include #include #include @@ -42,15 +43,15 @@ EFI_USE_TABLE ( ACPI_10_TABLE, &rsdp, 0 ); /** * Locate ACPI root system description table * - * @ret rsdt ACPI root system description table, or UNULL + * @ret rsdt ACPI root system description table, or NULL */ -static userptr_t efi_find_rsdt ( void ) { +static const struct acpi_rsdt * efi_find_rsdt ( void ) { /* Locate RSDT via ACPI configuration table, if available */ if ( rsdp ) return phys_to_virt ( rsdp->RsdtAddress ); - return UNULL; + return NULL; } PROVIDE_ACPI ( efi, acpi_find_rsdt, efi_find_rsdt ); diff --git a/src/interface/linux/linux_acpi.c b/src/interface/linux/linux_acpi.c index 846db2f1f..a2a8bf12e 100644 --- a/src/interface/linux/linux_acpi.c +++ b/src/interface/linux/linux_acpi.c @@ -42,7 +42,7 @@ struct linux_acpi_table { /** Index */ unsigned int index; /** Cached data */ - userptr_t data; + void *data; }; /** List of cached ACPI tables */ @@ -53,9 +53,10 @@ static LIST_HEAD ( linux_acpi_tables ); * * @v signature Requested table signature * @v index Requested index of table with this signature - * @ret table Table, or UNULL if not found + * @ret table Table, or NULL if not found */ -static userptr_t linux_acpi_find ( uint32_t signature, unsigned int index ) { +static const struct acpi_header * linux_acpi_find ( uint32_t signature, + unsigned int index ) { struct linux_acpi_table *table; struct acpi_header *header; union { @@ -121,7 +122,7 @@ static userptr_t linux_acpi_find ( uint32_t signature, unsigned int index ) { err_read: free ( table ); err_alloc: - return UNULL; + return NULL; } /** diff --git a/src/tests/acpi_test.c b/src/tests/acpi_test.c index 1ca5befaf..6e8840217 100644 --- a/src/tests/acpi_test.c +++ b/src/tests/acpi_test.c @@ -32,6 +32,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); /* Forcibly enable assertions */ #undef NDEBUG +#include #include #include #include @@ -185,26 +186,27 @@ static struct acpi_test_tables *acpi_test_tables; * * @v signature Requested table signature * @v index Requested index of table with this signature - * @ret table Table, or UNULL if not found + * @ret table Table, or NULL if not found */ -static userptr_t acpi_test_find ( uint32_t signature, unsigned int index ) { +static const struct acpi_header * acpi_test_find ( uint32_t signature, + unsigned int index ) { struct acpi_test_table *table; unsigned int i; /* Fail if no test tables are installed */ if ( ! acpi_test_tables ) - return UNULL; + return NULL; /* Scan through test tables */ for ( i = 0 ; i < acpi_test_tables->count ; i++ ) { table = acpi_test_tables->table[i]; if ( ( signature == le32_to_cpu ( table->signature.raw ) ) && ( index-- == 0 ) ) { - return virt_to_user ( table->data ); + return table->data; } } - return UNULL; + return NULL; } /** Override ACPI table finder */ -- cgit v1.2.3-55-g7522 From 0bf0f8716a3c7f85455707d8c2d727d130ee1024 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Wed, 23 Apr 2025 09:53:38 +0100 Subject: [smbios] Remove userptr_t from SMBIOS structure parsing Simplify the SMBIOS structure parsing code by assuming that all structure content is fully accessible via pointer dereferences. In particular, this allows the convoluted find_smbios_structure() and read_smbios_structure() to be combined into a single function smbios_structure() that just returns a direct pointer to the SMBIOS structure, with smbios_string() similarly now returning a direct pointer to the relevant string. Signed-off-by: Michael Brown --- src/arch/x86/interface/pcbios/bios_smbios.c | 36 ++-- src/drivers/net/smsc95xx.c | 93 ++++------- src/include/ipxe/smbios.h | 32 +--- src/interface/efi/efi_smbios.c | 1 + src/interface/linux/linux_smbios.c | 6 +- src/interface/smbios/smbios.c | 249 +++++++++++++--------------- src/interface/smbios/smbios_settings.c | 152 +++++++++-------- 7 files changed, 256 insertions(+), 313 deletions(-) (limited to 'src/interface/linux') diff --git a/src/arch/x86/interface/pcbios/bios_smbios.c b/src/arch/x86/interface/pcbios/bios_smbios.c index e43c74bad..aaec1eea1 100644 --- a/src/arch/x86/interface/pcbios/bios_smbios.c +++ b/src/arch/x86/interface/pcbios/bios_smbios.c @@ -45,19 +45,18 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * @ret rc Return status code */ static int bios_find_smbios2 ( struct smbios *smbios ) { - struct smbios_entry entry; - int rc; + const struct smbios_entry *entry; /* Scan through BIOS segment to find SMBIOS 32-bit entry point */ - if ( ( rc = find_smbios_entry ( real_to_virt ( BIOS_SEG, 0 ), 0x10000, - &entry ) ) != 0 ) - return rc; + entry = find_smbios_entry ( real_to_virt ( BIOS_SEG, 0 ), 0x10000 ); + if ( ! entry ) + return -ENOENT; /* Fill in entry point descriptor structure */ - smbios->address = phys_to_virt ( entry.smbios_address ); - smbios->len = entry.smbios_len; - smbios->count = entry.smbios_count; - smbios->version = SMBIOS_VERSION ( entry.major, entry.minor ); + smbios->address = phys_to_virt ( entry->smbios_address ); + smbios->len = entry->smbios_len; + smbios->count = entry->smbios_count; + smbios->version = SMBIOS_VERSION ( entry->major, entry->minor ); return 0; } @@ -69,26 +68,25 @@ static int bios_find_smbios2 ( struct smbios *smbios ) { * @ret rc Return status code */ static int bios_find_smbios3 ( struct smbios *smbios ) { - struct smbios3_entry entry; - int rc; + const struct smbios3_entry *entry; /* Scan through BIOS segment to find SMBIOS 64-bit entry point */ - if ( ( rc = find_smbios3_entry ( real_to_virt ( BIOS_SEG, 0 ), 0x10000, - &entry ) ) != 0 ) - return rc; + entry = find_smbios3_entry ( real_to_virt ( BIOS_SEG, 0 ), 0x10000 ); + if ( ! entry ) + return -ENOENT; /* Check that address is accessible */ - if ( entry.smbios_address > ~( ( physaddr_t ) 0 ) ) { + if ( entry->smbios_address > ~( ( physaddr_t ) 0 ) ) { DBG ( "SMBIOS3 at %08llx is inaccessible\n", - ( ( unsigned long long ) entry.smbios_address ) ); + ( ( unsigned long long ) entry->smbios_address ) ); return -ENOTSUP; } /* Fill in entry point descriptor structure */ - smbios->address = phys_to_virt ( entry.smbios_address ); - smbios->len = entry.smbios_len; + smbios->address = phys_to_virt ( entry->smbios_address ); + smbios->len = entry->smbios_len; smbios->count = 0; - smbios->version = SMBIOS_VERSION ( entry.major, entry.minor ); + smbios->version = SMBIOS_VERSION ( entry->major, entry->minor ); return 0; } diff --git a/src/drivers/net/smsc95xx.c b/src/drivers/net/smsc95xx.c index 3ec49584d..0210e9240 100644 --- a/src/drivers/net/smsc95xx.c +++ b/src/drivers/net/smsc95xx.c @@ -64,92 +64,67 @@ static struct profiler smsc95xx_out_profiler __profiler = */ static int smsc95xx_vm3_fetch_mac ( struct smscusb_device *smscusb ) { struct net_device *netdev = smscusb->netdev; - struct smbios_structure structure; - struct smbios_system_information system; - struct { - char manufacturer[ 10 /* "Honeywell" + NUL */ ]; - char product[ 4 /* "VM3" + NUL */ ]; - char mac[ base16_encoded_len ( ETH_ALEN ) + 1 /* NUL */ ]; - } strings; + const struct smbios_header *structure; + const struct smbios_system_information *system; + const char *manufacturer; + const char *product; + const char *mac; int len; int rc; /* Find system information */ - if ( ( rc = find_smbios_structure ( SMBIOS_TYPE_SYSTEM_INFORMATION, 0, - &structure ) ) != 0 ) { + structure = smbios_structure ( SMBIOS_TYPE_SYSTEM_INFORMATION, 0 ); + if ( ! structure ) { DBGC ( smscusb, "SMSC95XX %p could not find system " - "information: %s\n", smscusb, strerror ( rc ) ); - return rc; - } - - /* Read system information */ - if ( ( rc = read_smbios_structure ( &structure, &system, - sizeof ( system ) ) ) != 0 ) { - DBGC ( smscusb, "SMSC95XX %p could not read system " - "information: %s\n", smscusb, strerror ( rc ) ); - return rc; + "information\n", smscusb ); + return -ENOENT; } - - /* NUL-terminate all strings to be fetched */ - memset ( &strings, 0, sizeof ( strings ) ); + system = container_of ( structure, struct smbios_system_information, + header ); /* Fetch system manufacturer name */ - len = read_smbios_string ( &structure, system.manufacturer, - strings.manufacturer, - ( sizeof ( strings.manufacturer ) - 1 ) ); - if ( len < 0 ) { - rc = len; + manufacturer = smbios_string ( structure, system->manufacturer ); + if ( ! manufacturer ) { DBGC ( smscusb, "SMSC95XX %p could not read manufacturer " - "name: %s\n", smscusb, strerror ( rc ) ); - return rc; + "name\n", smscusb ); + return -ENOENT; } /* Fetch system product name */ - len = read_smbios_string ( &structure, system.product, strings.product, - ( sizeof ( strings.product ) - 1 ) ); - if ( len < 0 ) { - rc = len; - DBGC ( smscusb, "SMSC95XX %p could not read product name: " - "%s\n", smscusb, strerror ( rc ) ); - return rc; + product = smbios_string ( structure, system->product ); + if ( ! product ) { + DBGC ( smscusb, "SMSC95XX %p could not read product name\n", + smscusb ); + return -ENOENT; } /* Ignore non-VM3 devices */ - if ( ( strcmp ( strings.manufacturer, "Honeywell" ) != 0 ) || - ( strcmp ( strings.product, "VM3" ) != 0 ) ) + if ( ( strcmp ( manufacturer, "Honeywell" ) != 0 ) || + ( strcmp ( product, "VM3" ) != 0 ) ) return -ENOTTY; /* Find OEM strings */ - if ( ( rc = find_smbios_structure ( SMBIOS_TYPE_OEM_STRINGS, 0, - &structure ) ) != 0 ) { - DBGC ( smscusb, "SMSC95XX %p could not find OEM strings: %s\n", - smscusb, strerror ( rc ) ); - return rc; + structure = smbios_structure ( SMBIOS_TYPE_OEM_STRINGS, 0 ); + if ( ! structure ) { + DBGC ( smscusb, "SMSC95XX %p could not find OEM strings\n", + smscusb ); + return -ENOENT; } /* Fetch MAC address */ - len = read_smbios_string ( &structure, SMSC95XX_VM3_OEM_STRING_MAC, - strings.mac, ( sizeof ( strings.mac ) - 1 )); - if ( len < 0 ) { - rc = len; - DBGC ( smscusb, "SMSC95XX %p could not read OEM string: %s\n", - smscusb, strerror ( rc ) ); - return rc; - } - - /* Sanity check */ - if ( len != ( ( int ) ( sizeof ( strings.mac ) - 1 ) ) ) { - DBGC ( smscusb, "SMSC95XX %p invalid MAC address \"%s\"\n", - smscusb, strings.mac ); - return -EINVAL; + mac = smbios_string ( structure, SMSC95XX_VM3_OEM_STRING_MAC ); + if ( ! mac ) { + DBGC ( smscusb, "SMSC95XX %p could not read OEM string\n", + smscusb ); + return -ENOENT; } /* Decode MAC address */ - len = base16_decode ( strings.mac, netdev->hw_addr, ETH_ALEN ); + len = base16_decode ( mac, netdev->hw_addr, ETH_ALEN ); if ( len < 0 ) { rc = len; DBGC ( smscusb, "SMSC95XX %p invalid MAC address \"%s\"\n", - smscusb, strings.mac ); + smscusb, mac ); return rc; } diff --git a/src/include/ipxe/smbios.h b/src/include/ipxe/smbios.h index f36a5ad40..d9e2c38ed 100644 --- a/src/include/ipxe/smbios.h +++ b/src/include/ipxe/smbios.h @@ -12,7 +12,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include #include -#include /** * Provide an SMBIOS API implementation @@ -126,16 +125,6 @@ struct smbios_header { uint16_t handle; } __attribute__ (( packed )); -/** SMBIOS structure descriptor */ -struct smbios_structure { - /** Copy of SMBIOS structure header */ - struct smbios_header header; - /** Offset of structure within SMBIOS */ - size_t offset; - /** Length of strings section */ - size_t strings_len; -}; - /** SMBIOS system information structure */ struct smbios_system_information { /** SMBIOS structure header */ @@ -207,7 +196,7 @@ struct smbios_enclosure_information { */ struct smbios { /** Start of SMBIOS structures */ - userptr_t address; + const void *address; /** Length of SMBIOS structures */ size_t len; /** Number of SMBIOS structures */ @@ -226,17 +215,14 @@ struct smbios { #define SMBIOS_VERSION( major, minor ) ( ( (major) << 8 ) | (minor) ) extern int find_smbios ( struct smbios *smbios ); -extern int find_smbios_entry ( userptr_t start, size_t len, - struct smbios_entry *entry ); -extern int find_smbios3_entry ( userptr_t start, size_t len, - struct smbios3_entry *entry ); -extern int find_smbios_structure ( unsigned int type, unsigned int instance, - struct smbios_structure *structure ); -extern int read_smbios_structure ( struct smbios_structure *structure, - void *data, size_t len ); -extern int read_smbios_string ( struct smbios_structure *structure, - unsigned int index, - void *data, size_t len ); +extern const struct smbios_entry * find_smbios_entry ( const void *start, + size_t len ); +extern const struct smbios3_entry * find_smbios3_entry ( const void *start, + size_t len ); +extern const struct smbios_header * smbios_structure ( unsigned int type, + unsigned int instance ); +extern const char * smbios_string ( const struct smbios_header *header, + unsigned int index ); extern int smbios_version ( void ); extern void smbios_clear ( void ); diff --git a/src/interface/efi/efi_smbios.c b/src/interface/efi/efi_smbios.c index 3c1b77bdc..5d0e69d6b 100644 --- a/src/interface/efi/efi_smbios.c +++ b/src/interface/efi/efi_smbios.c @@ -20,6 +20,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include +#include #include #include #include diff --git a/src/interface/linux/linux_smbios.c b/src/interface/linux/linux_smbios.c index abe1b19d7..a12c936ed 100644 --- a/src/interface/linux/linux_smbios.c +++ b/src/interface/linux/linux_smbios.c @@ -35,7 +35,7 @@ static const char smbios_entry_filename[] = static const char smbios_filename[] = "/sys/firmware/dmi/tables/DMI"; /** Cache SMBIOS data */ -static userptr_t smbios_data; +static void *smbios_data; /** * Find SMBIOS @@ -46,7 +46,7 @@ static userptr_t smbios_data; static int linux_find_smbios ( struct smbios *smbios ) { struct smbios3_entry *smbios3_entry; struct smbios_entry *smbios_entry; - userptr_t entry; + void *entry; void *data; int len; int rc; @@ -98,6 +98,7 @@ static int linux_find_smbios ( struct smbios *smbios ) { return 0; ufree ( smbios_data ); + smbios_data = NULL; err_read: err_version: ufree ( entry ); @@ -116,6 +117,7 @@ static void linux_smbios_shutdown ( int booting __unused ) { /* Free SMBIOS data */ ufree ( smbios_data ); + smbios_data = NULL; } /** SMBIOS shutdown function */ diff --git a/src/interface/smbios/smbios.c b/src/interface/smbios/smbios.c index 89fa4d7ca..3a1a98b17 100644 --- a/src/interface/smbios/smbios.c +++ b/src/interface/smbios/smbios.c @@ -38,26 +38,24 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); /** SMBIOS entry point descriptor */ static struct smbios smbios = { - .address = UNULL, + .address = NULL, }; /** * Calculate SMBIOS entry point structure checksum * * @v start Start address of region - * @v offset Offset of SMBIOS entry point structure * @v len Length of entry point structure * @ret sum Byte checksum */ -static uint8_t smbios_checksum ( userptr_t start, size_t offset, size_t len ) { - size_t end = ( offset + len ); - uint8_t sum; - uint8_t byte; +static uint8_t smbios_checksum ( const void *start, size_t len ) { + const uint8_t *byte = start; + uint8_t sum = 0; + + /* Compute checksum */ + while ( len-- ) + sum += *(byte++); - for ( sum = 0 ; offset < end ; offset++ ) { - copy_from_user ( &byte, start, offset, sizeof ( byte ) ); - sum += byte; - } return sum; } @@ -66,39 +64,45 @@ static uint8_t smbios_checksum ( userptr_t start, size_t offset, size_t len ) { * * @v start Start address of region to scan * @v len Length of region to scan - * @v entry SMBIOS entry point structure to fill in - * @ret rc Return status code + * @ret entry SMBIOS entry point structure, or NULL if not found */ -int find_smbios_entry ( userptr_t start, size_t len, - struct smbios_entry *entry ) { +const struct smbios_entry * find_smbios_entry ( const void *start, + size_t len ) { static size_t offset = 0; /* Avoid repeated attempts to locate SMBIOS */ + const struct smbios_entry *entry; uint8_t sum; /* Try to find SMBIOS */ for ( ; ( offset + sizeof ( *entry ) ) <= len ; offset += 0x10 ) { - /* Read start of header and verify signature */ - copy_from_user ( entry, start, offset, sizeof ( *entry ) ); + /* Verify signature */ + entry = ( start + offset ); if ( entry->signature != SMBIOS_SIGNATURE ) continue; + /* Verify length */ + if ( ( entry->len < sizeof ( *entry ) ) || + ( ( offset + entry->len ) > len ) ) { + DBGC ( &smbios, "SMBIOS at %#08lx has bad length " + "%#02x\n", virt_to_phys ( entry ), entry->len ); + continue; + } + /* Verify checksum */ - if ( ( sum = smbios_checksum ( start, offset, - entry->len ) ) != 0 ) { - DBG ( "SMBIOS at %08lx has bad checksum %02x\n", - virt_to_phys ( start + offset ), sum ); + if ( ( sum = smbios_checksum ( entry, entry->len ) ) != 0 ) { + DBGC ( &smbios, "SMBIOS at %#08lx has bad checksum " + "%#02x\n", virt_to_phys ( entry ), sum ); continue; } /* Fill result structure */ - DBG ( "Found SMBIOS v%d.%d entry point at %08lx\n", - entry->major, entry->minor, - virt_to_phys ( start + offset ) ); - return 0; + DBGC ( &smbios, "Found SMBIOS v%d.%d entry point at %#08lx\n", + entry->major, entry->minor, virt_to_phys ( entry ) ); + return entry; } - DBG ( "No SMBIOS found\n" ); - return -ENODEV; + DBGC ( &smbios, "No SMBIOS found\n" ); + return NULL; } /** @@ -106,39 +110,45 @@ int find_smbios_entry ( userptr_t start, size_t len, * * @v start Start address of region to scan * @v len Length of region to scan - * @v entry SMBIOS entry point structure to fill in - * @ret rc Return status code + * @ret entry SMBIOS entry point structure, or NULL if not found */ -int find_smbios3_entry ( userptr_t start, size_t len, - struct smbios3_entry *entry ) { +const struct smbios3_entry * find_smbios3_entry ( const void *start, + size_t len ) { static size_t offset = 0; /* Avoid repeated attempts to locate SMBIOS */ + const struct smbios3_entry *entry; uint8_t sum; /* Try to find SMBIOS */ for ( ; ( offset + sizeof ( *entry ) ) <= len ; offset += 0x10 ) { - /* Read start of header and verify signature */ - copy_from_user ( entry, start, offset, sizeof ( *entry ) ); + /* Verify signature */ + entry = ( start + offset ); if ( entry->signature != SMBIOS3_SIGNATURE ) continue; + /* Verify length */ + if ( ( entry->len < sizeof ( *entry ) ) || + ( ( offset + entry->len ) > len ) ) { + DBGC ( &smbios, "SMBIOS at %#08lx has bad length " + "%#02x\n", virt_to_phys ( entry ), entry->len ); + continue; + } + /* Verify checksum */ - if ( ( sum = smbios_checksum ( start, offset, - entry->len ) ) != 0 ) { - DBG ( "SMBIOS3 at %08lx has bad checksum %02x\n", - virt_to_phys ( start + offset ), sum ); + if ( ( sum = smbios_checksum ( entry, entry->len ) ) != 0 ) { + DBGC ( &smbios, "SMBIOS3 at %#08lx has bad checksum " + "%#02x\n", virt_to_phys ( entry ), sum ); continue; } /* Fill result structure */ - DBG ( "Found SMBIOS3 v%d.%d entry point at %08lx\n", - entry->major, entry->minor, - virt_to_phys ( start + offset ) ); - return 0; + DBGC ( &smbios, "Found SMBIOS3 v%d.%d entry point at %#08lx\n", + entry->major, entry->minor, virt_to_phys ( entry ) ); + return entry; } - DBG ( "No SMBIOS3 found\n" ); - return -ENODEV; + DBGC ( &smbios, "No SMBIOS3 found\n" ); + return NULL; } /** @@ -148,12 +158,15 @@ int find_smbios3_entry ( userptr_t start, size_t len, * @ret offset Offset to strings terminator, or 0 if not found */ static size_t find_strings_terminator ( size_t offset ) { - size_t max_offset = ( smbios.len - 2 ); - uint16_t nulnul; + const uint16_t *nulnul __attribute__ (( aligned ( 1 ) )); - for ( ; offset <= max_offset ; offset++ ) { - copy_from_user ( &nulnul, smbios.address, offset, 2 ); - if ( nulnul == 0 ) + /* Sanity checks */ + assert ( smbios.address != NULL ); + + /* Check for presence of terminating empty string */ + for ( ; ( offset + sizeof ( *nulnul ) ) <= smbios.len ; offset++ ) { + nulnul = ( smbios.address + offset ); + if ( *nulnul == 0 ) return ( offset + 1 ); } return 0; @@ -164,61 +177,59 @@ static size_t find_strings_terminator ( size_t offset ) { * * @v type Structure type to search for * @v instance Instance of this type of structure - * @v structure SMBIOS structure descriptor to fill in - * @ret rc Return status code + * @ret structure SMBIOS structure header, or NULL if not found */ -int find_smbios_structure ( unsigned int type, unsigned int instance, - struct smbios_structure *structure ) { +const struct smbios_header * smbios_structure ( unsigned int type, + unsigned int instance ) { + const struct smbios_header *structure; unsigned int count = 0; size_t offset = 0; size_t strings_offset; size_t terminator_offset; + size_t strings_len; int rc; /* Find SMBIOS */ - if ( ( smbios.address == UNULL ) && + if ( ( smbios.address == NULL ) && ( ( rc = find_smbios ( &smbios ) ) != 0 ) ) - return rc; - assert ( smbios.address != UNULL ); + return NULL; + assert ( smbios.address != NULL ); /* Scan through list of structures */ - while ( ( ( offset + sizeof ( structure->header ) ) < smbios.len ) && + while ( ( ( offset + sizeof ( *structure ) ) < smbios.len ) && ( ( smbios.count == 0 ) || ( count < smbios.count ) ) ) { - /* Read next SMBIOS structure header */ - copy_from_user ( &structure->header, smbios.address, offset, - sizeof ( structure->header ) ); + /* Access next SMBIOS structure header */ + structure = ( smbios.address + offset ); /* Determine start and extent of strings block */ - strings_offset = ( offset + structure->header.len ); + strings_offset = ( offset + structure->len ); if ( strings_offset > smbios.len ) { - DBG ( "SMBIOS structure at offset %zx with length " - "%x extends beyond SMBIOS\n", offset, - structure->header.len ); - return -ENOENT; + DBGC ( &smbios, "SMBIOS structure at offset %#zx " + "with length %#x extends beyond SMBIOS\n", + offset, structure->len ); + return NULL; } terminator_offset = find_strings_terminator ( strings_offset ); if ( ! terminator_offset ) { - DBG ( "SMBIOS structure at offset %zx has " - "unterminated strings section\n", offset ); - return -ENOENT; + DBGC ( &smbios, "SMBIOS structure at offset %#zx has " + "unterminated strings section\n", offset ); + return NULL; } - structure->strings_len = ( terminator_offset - strings_offset); - - DBG ( "SMBIOS structure at offset %zx has type %d, length %x, " - "strings length %zx\n", offset, structure->header.type, - structure->header.len, structure->strings_len ); + strings_len = ( terminator_offset - strings_offset); + DBGC ( &smbios, "SMBIOS structure at offset %#zx has type %d, " + "length %#x, strings length %#zx\n", offset, + structure->type, structure->len, strings_len ); /* Stop if we have reached an end-of-table marker */ if ( ( smbios.count == 0 ) && - ( structure->header.type == SMBIOS_TYPE_END ) ) + ( structure->type == SMBIOS_TYPE_END ) ) break; /* If this is the structure we want, return */ - if ( ( structure->header.type == type ) && + if ( ( structure->type == type ) && ( instance-- == 0 ) ) { - structure->offset = offset; - return 0; + return structure; } /* Move to next SMBIOS structure */ @@ -226,69 +237,43 @@ int find_smbios_structure ( unsigned int type, unsigned int instance, count++; } - DBG ( "SMBIOS structure type %d not found\n", type ); - return -ENOENT; + DBGC ( &smbios, "SMBIOS structure type %d not found\n", type ); + return NULL; } /** - * Copy SMBIOS structure + * Get indexed string within SMBIOS structure * - * @v structure SMBIOS structure descriptor - * @v data Buffer to hold SMBIOS structure - * @v len Length of buffer - * @ret rc Return status code - */ -int read_smbios_structure ( struct smbios_structure *structure, - void *data, size_t len ) { - - assert ( smbios.address != UNULL ); - - if ( len > structure->header.len ) - len = structure->header.len; - copy_from_user ( data, smbios.address, structure->offset, len ); - return 0; -} - -/** - * Find indexed string within SMBIOS structure - * - * @v structure SMBIOS structure descriptor + * @v structure SMBIOS structure header * @v index String index - * @v data Buffer for string - * @v len Length of string buffer - * @ret rc Length of string, or negative error + * @ret string SMBIOS string, or NULL if not fond */ -int read_smbios_string ( struct smbios_structure *structure, - unsigned int index, void *data, size_t len ) { - size_t strings_start = ( structure->offset + structure->header.len ); - size_t strings_end = ( strings_start + structure->strings_len ); - size_t offset; - size_t string_len; - - assert ( smbios.address != UNULL ); - - /* String numbers start at 1 (0 is used to indicate "no string") */ - if ( ! index ) - return -ENOENT; - - for ( offset = strings_start ; offset < strings_end ; - offset += ( string_len + 1 ) ) { - /* Get string length. This is known safe, since the - * smbios_strings struct is constructed so as to - * always end on a string boundary. +const char * smbios_string ( const struct smbios_header *structure, + unsigned int index ) { + const char *string; + unsigned int i; + size_t len; + + /* Sanity check */ + assert ( smbios.address != NULL ); + + /* Step through strings */ + string = ( ( ( const void * ) structure ) + structure->len ); + for ( i = index ; i-- ; ) { + /* Get string length. This is known safe, since we + * check for the empty-string terminator in + * smbios_structure(). */ - string_len = strlen ( smbios.address + offset ); - if ( --index == 0 ) { - /* Copy string, truncating as necessary. */ - if ( len > string_len ) - len = string_len; - copy_from_user ( data, smbios.address, offset, len ); - return string_len; - } + len = strlen ( string ); + if ( ! len ) + break; + if ( i == 0 ) + return string; + string += ( len + 1 /* NUL */ ); } - DBG ( "SMBIOS string index %d not found\n", index ); - return -ENOENT; + DBGC ( &smbios, "SMBIOS string index %d not found\n", index ); + return NULL; } /** @@ -300,10 +285,10 @@ int smbios_version ( void ) { int rc; /* Find SMBIOS */ - if ( ( smbios.address == UNULL ) && + if ( ( smbios.address == NULL ) && ( ( rc = find_smbios ( &smbios ) ) != 0 ) ) return rc; - assert ( smbios.address != UNULL ); + assert ( smbios.address != NULL ); return smbios.version; } @@ -315,5 +300,5 @@ int smbios_version ( void ) { void smbios_clear ( void ) { /* Clear address */ - smbios.address = UNULL; + smbios.address = NULL; } diff --git a/src/interface/smbios/smbios_settings.c b/src/interface/smbios/smbios_settings.c index 095c35d37..1fe545f38 100644 --- a/src/interface/smbios/smbios_settings.c +++ b/src/interface/smbios/smbios_settings.c @@ -81,15 +81,17 @@ static int smbios_applies ( struct settings *settings __unused, * @v len Length of buffer * @ret len Length of setting data, or negative error */ -static int smbios_fetch ( struct settings *settings __unused, - struct setting *setting, +static int smbios_fetch ( struct settings *settings, struct setting *setting, void *data, size_t len ) { - struct smbios_structure structure; + const struct smbios_header *structure; unsigned int tag_instance; unsigned int tag_type; unsigned int tag_offset; unsigned int tag_len; - int rc; + const void *src; + size_t src_len; + unsigned int string; + union uuid uuid; /* Split tag into instance, type, offset and length */ tag_instance = ( ( setting->tag >> 24 ) & 0xff ); @@ -98,81 +100,75 @@ static int smbios_fetch ( struct settings *settings __unused, tag_len = ( setting->tag & 0xff ); /* Find SMBIOS structure */ - if ( ( rc = find_smbios_structure ( tag_type, tag_instance, - &structure ) ) != 0 ) - return rc; - - { - uint8_t buf[structure.header.len]; - const void *raw; - union uuid uuid; - unsigned int index; - - /* Read SMBIOS structure */ - if ( ( rc = read_smbios_structure ( &structure, buf, - sizeof ( buf ) ) ) != 0 ) - return rc; + structure = smbios_structure ( tag_type, tag_instance ); + if ( ! structure ) + return -ENOENT; + src = structure; + src_len = structure->len; + string = 0; - /* A of zero indicates that the byte at - * contains a string index. An of - * zero indicates that the contains a literal - * string index. - * - * Since the byte at offset zero can never contain a - * string index, and a literal string index can never - * be zero, the combination of both and - * being zero indicates that the entire - * structure is to be read. - */ - if ( ( tag_len == 0 ) && ( tag_offset == 0 ) ) { - tag_len = sizeof ( buf ); - } else if ( ( tag_len == 0 ) || ( tag_offset == 0 ) ) { - index = ( ( tag_offset == 0 ) ? - tag_len : buf[tag_offset] ); - if ( ( rc = read_smbios_string ( &structure, index, - data, len ) ) < 0 ) { - return rc; - } - if ( ! setting->type ) - setting->type = &setting_type_string; - return rc; - } + /* A of zero indicates that the byte at + * contains a string index. An of zero indicates + * that the contains a literal string index. + * + * Since the byte at offset zero can never contain a string + * index, and a literal string index can never be zero, the + * combination of both and being zero + * indicates that the entire structure is to be read. + */ + if ( ( tag_len == 0 ) && ( tag_offset == 0 ) ) { + /* Read whole structure */ + } else if ( ( tag_len == 0 ) || ( tag_offset == 0 ) ) { + /* Read string */ + string = tag_len; + if ( ( string == 0 ) && ( tag_offset < src_len ) ) + string = *( ( uint8_t * ) src + tag_offset ); + src = smbios_string ( structure, string ); + if ( ! src ) + return -ENOENT; + assert ( string > 0 ); + src_len = strlen ( src ); + } else if ( tag_offset > src_len ) { + /* Empty read beyond end of structure */ + src_len = 0; + } else { + /* Read partial structure */ + src += tag_offset; + src_len -= tag_offset; + if ( src_len > tag_len ) + src_len = tag_len; + } - /* Limit length */ - if ( tag_offset > sizeof ( buf ) ) { - tag_len = 0; - } else if ( ( tag_offset + tag_len ) > sizeof ( buf ) ) { - tag_len = ( sizeof ( buf ) - tag_offset ); - } + /* Mangle UUIDs if necessary. iPXE treats UUIDs as being in + * network byte order (big-endian). SMBIOS specification + * version 2.6 states that UUIDs are stored with little-endian + * values in the first three fields; earlier versions did not + * specify an endianness. dmidecode assumes that the byte + * order is little-endian if and only if the SMBIOS version is + * 2.6 or higher; we match this behaviour. + */ + if ( ( ( setting->type == &setting_type_uuid ) || + ( setting->type == &setting_type_guid ) ) && + ( src_len == sizeof ( uuid ) ) && + ( smbios_version() >= SMBIOS_VERSION ( 2, 6 ) ) ) { + DBGC ( settings, "SMBIOS detected mangled UUID\n" ); + memcpy ( &uuid, src, sizeof ( uuid ) ); + uuid_mangle ( &uuid ); + src = &uuid; + } - /* Mangle UUIDs if necessary. iPXE treats UUIDs as - * being in network byte order (big-endian). SMBIOS - * specification version 2.6 states that UUIDs are - * stored with little-endian values in the first three - * fields; earlier versions did not specify an - * endianness. dmidecode assumes that the byte order - * is little-endian if and only if the SMBIOS version - * is 2.6 or higher; we match this behaviour. - */ - raw = &buf[tag_offset]; - if ( ( ( setting->type == &setting_type_uuid ) || - ( setting->type == &setting_type_guid ) ) && - ( tag_len == sizeof ( uuid ) ) && - ( smbios_version() >= SMBIOS_VERSION ( 2, 6 ) ) ) { - DBG ( "SMBIOS detected mangled UUID\n" ); - memcpy ( &uuid, &buf[tag_offset], sizeof ( uuid ) ); - uuid_mangle ( &uuid ); - raw = &uuid; - } + /* Return data */ + if ( len > src_len ) + len = src_len; + memcpy ( data, src, len ); - /* Return data */ - if ( len > tag_len ) - len = tag_len; - memcpy ( data, raw, len ); - if ( ! setting->type ) - setting->type = &setting_type_hex; - return tag_len; + /* Set default type */ + if ( ! setting->type ) { + setting->type = ( string ? &setting_type_string : + &setting_type_hex ); } + + return src_len; } /** SMBIOS settings operations */ @@ -192,12 +188,12 @@ static struct settings smbios_settings = { /** Initialise SMBIOS settings */ static void smbios_init ( void ) { + struct settings *settings = &smbios_settings; int rc; - if ( ( rc = register_settings ( &smbios_settings, NULL, - "smbios" ) ) != 0 ) { - DBG ( "SMBIOS could not register settings: %s\n", - strerror ( rc ) ); + if ( ( rc = register_settings ( settings, NULL, "smbios" ) ) != 0 ) { + DBGC ( settings, "SMBIOS could not register settings: %s\n", + strerror ( rc ) ); return; } } -- cgit v1.2.3-55-g7522 From 839540cb95a310ebf96d6302afecc3ac97ccf746 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Wed, 23 Apr 2025 12:47:53 +0100 Subject: [umalloc] Remove userptr_t from user memory allocations Use standard void pointers for umalloc(), urealloc(), and ufree(), with the "u" prefix retained to indicate that these allocations are made from external ("user") memory rather than from the internal heap. Signed-off-by: Michael Brown --- src/arch/riscv/interface/sbi/sbi_umalloc.c | 11 +++---- src/arch/x86/interface/pcbios/memtop_umalloc.c | 42 ++++++++++++-------------- src/core/dma.c | 9 +++--- src/core/malloc.c | 17 ----------- src/core/xferbuf.c | 12 ++++---- src/include/ipxe/dma.h | 20 ++++++------ src/include/ipxe/malloc.h | 18 +++++++++++ src/include/ipxe/umalloc.h | 23 +++++++------- src/include/ipxe/xferbuf.h | 3 +- src/interface/efi/efi_pci.c | 36 ++-------------------- src/interface/efi/efi_umalloc.c | 25 ++++++++------- src/interface/linux/linux_umalloc.c | 31 +++++++------------ src/tests/umalloc_test.c | 5 ++- 13 files changed, 101 insertions(+), 151 deletions(-) (limited to 'src/interface/linux') diff --git a/src/arch/riscv/interface/sbi/sbi_umalloc.c b/src/arch/riscv/interface/sbi/sbi_umalloc.c index 2f9935adb..0e351748b 100644 --- a/src/arch/riscv/interface/sbi/sbi_umalloc.c +++ b/src/arch/riscv/interface/sbi/sbi_umalloc.c @@ -32,23 +32,20 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * */ -/** Equivalent of NOWHERE for user pointers */ -#define UNOWHERE ( ~UNULL ) - /** * Reallocate external memory * - * @v old_ptr Memory previously allocated by umalloc(), or UNULL + * @v old_ptr Memory previously allocated by umalloc(), or NULL * @v new_size Requested size - * @ret new_ptr Allocated memory, or UNULL + * @ret new_ptr Allocated memory, or NULL * * Calling realloc() with a new size of zero is a valid way to free a * memory block. */ -static userptr_t sbi_urealloc ( userptr_t old_ptr, size_t new_size ) { +static void * sbi_urealloc ( void * old_ptr, size_t new_size ) { /* External allocation not yet implemented: allocate from heap */ - return ( ( userptr_t ) realloc ( ( ( void * ) old_ptr ), new_size ) ); + return ( realloc ( old_ptr, new_size ) ); } PROVIDE_UMALLOC ( sbi, urealloc, sbi_urealloc ); diff --git a/src/arch/x86/interface/pcbios/memtop_umalloc.c b/src/arch/x86/interface/pcbios/memtop_umalloc.c index b87d22516..d4489fb01 100644 --- a/src/arch/x86/interface/pcbios/memtop_umalloc.c +++ b/src/arch/x86/interface/pcbios/memtop_umalloc.c @@ -44,9 +44,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); /** Alignment of external allocated memory */ #define EM_ALIGN ( 4 * 1024 ) -/** Equivalent of NOWHERE for user pointers */ -#define UNOWHERE ( ( userptr_t ) ~( ( intptr_t ) 0 ) ) - /** An external memory block */ struct external_memory { /** Size of this memory block (excluding this header) */ @@ -56,10 +53,10 @@ struct external_memory { }; /** Top of heap */ -static userptr_t top = UNULL; +static void *top = NULL; /** Bottom of heap (current lowest allocated block) */ -static userptr_t bottom = UNULL; +static void *bottom = NULL; /** Remaining space on heap */ static size_t heap_size; @@ -70,7 +67,7 @@ static size_t heap_size; * @ret start Start of region * @ret len Length of region */ -size_t largest_memblock ( userptr_t *start ) { +size_t largest_memblock ( void **start ) { struct memory_map memmap; struct memory_region *region; physaddr_t max = EM_MAX_ADDRESS; @@ -81,7 +78,7 @@ size_t largest_memblock ( userptr_t *start ) { size_t len = 0; /* Avoid returning uninitialised data on error */ - *start = UNULL; + *start = NULL; /* Scan through all memory regions */ get_memmap ( &memmap ); @@ -119,7 +116,7 @@ size_t largest_memblock ( userptr_t *start ) { * */ static void init_eheap ( void ) { - userptr_t base; + void *base; heap_size = largest_memblock ( &base ); bottom = top = ( base + heap_size ); @@ -137,8 +134,8 @@ static void ecollect_free ( void ) { /* Walk the free list and collect empty blocks */ while ( bottom != top ) { - copy_from_user ( &extmem, bottom, -sizeof ( extmem ), - sizeof ( extmem ) ); + memcpy ( &extmem, ( bottom - sizeof ( extmem ) ), + sizeof ( extmem ) ); if ( extmem.used ) break; DBG ( "EXTMEM freeing [%lx,%lx)\n", virt_to_phys ( bottom ), @@ -152,16 +149,16 @@ static void ecollect_free ( void ) { /** * Reallocate external memory * - * @v old_ptr Memory previously allocated by umalloc(), or UNULL + * @v old_ptr Memory previously allocated by umalloc(), or NULL * @v new_size Requested size - * @ret new_ptr Allocated memory, or UNULL + * @ret new_ptr Allocated memory, or NULL * * Calling realloc() with a new size of zero is a valid way to free a * memory block. */ -static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) { +static void * memtop_urealloc ( void *ptr, size_t new_size ) { struct external_memory extmem; - userptr_t new = ptr; + void *new = ptr; size_t align; /* (Re)initialise external memory allocator if necessary */ @@ -169,15 +166,15 @@ static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) { init_eheap(); /* Get block properties into extmem */ - if ( ptr && ( ptr != UNOWHERE ) ) { + if ( ptr && ( ptr != NOWHERE ) ) { /* Determine old size */ - copy_from_user ( &extmem, ptr, -sizeof ( extmem ), - sizeof ( extmem ) ); + memcpy ( &extmem, ( ptr - sizeof ( extmem ) ), + sizeof ( extmem ) ); } else { /* Create a zero-length block */ if ( heap_size < sizeof ( extmem ) ) { DBG ( "EXTMEM out of space\n" ); - return UNULL; + return NULL; } ptr = bottom = ( bottom - sizeof ( extmem ) ); heap_size -= sizeof ( extmem ); @@ -196,7 +193,7 @@ static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) { new -= align; if ( new_size > ( heap_size + extmem.size ) ) { DBG ( "EXTMEM out of space\n" ); - return UNULL; + return NULL; } DBG ( "EXTMEM expanding [%lx,%lx) to [%lx,%lx)\n", virt_to_phys ( ptr ), @@ -215,13 +212,12 @@ static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) { DBG ( "EXTMEM cannot expand [%lx,%lx)\n", virt_to_phys ( ptr ), ( virt_to_phys ( ptr ) + extmem.size ) ); - return UNULL; + return NULL; } } /* Write back block properties */ - copy_to_user ( new, -sizeof ( extmem ), &extmem, - sizeof ( extmem ) ); + memcpy ( ( new - sizeof ( extmem ) ), &extmem, sizeof ( extmem ) ); /* Collect any free blocks and update hidden memory region */ ecollect_free(); @@ -229,7 +225,7 @@ static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) { ( ( bottom == top ) ? 0 : sizeof ( extmem ) ) ), virt_to_phys ( top ) ); - return ( new_size ? new : UNOWHERE ); + return ( new_size ? new : NOWHERE ); } PROVIDE_UMALLOC ( memtop, urealloc, memtop_urealloc ); diff --git a/src/core/dma.c b/src/core/dma.c index 5d6868216..1f3c1d8a6 100644 --- a/src/core/dma.c +++ b/src/core/dma.c @@ -130,9 +130,9 @@ static void dma_op_free ( struct dma_mapping *map, void *addr, size_t len ) { * @v align Physical alignment * @ret addr Buffer address, or NULL on error */ -static userptr_t dma_op_umalloc ( struct dma_device *dma, - struct dma_mapping *map, - size_t len, size_t align ) { +static void * dma_op_umalloc ( struct dma_device *dma, + struct dma_mapping *map, + size_t len, size_t align ) { struct dma_operations *op = dma->op; if ( ! op ) @@ -147,8 +147,7 @@ static userptr_t dma_op_umalloc ( struct dma_device *dma, * @v addr Buffer address * @v len Length of buffer */ -static void dma_op_ufree ( struct dma_mapping *map, userptr_t addr, - size_t len ) { +static void dma_op_ufree ( struct dma_mapping *map, void *addr, size_t len ) { struct dma_device *dma = map->dma; assert ( dma != NULL ); diff --git a/src/core/malloc.c b/src/core/malloc.c index c499ce6fd..ec29513ef 100644 --- a/src/core/malloc.c +++ b/src/core/malloc.c @@ -71,23 +71,6 @@ struct autosized_block { char data[0]; }; -/** - * Address for zero-length memory blocks - * - * @c malloc(0) or @c realloc(ptr,0) will return the special value @c - * NOWHERE. Calling @c free(NOWHERE) will have no effect. - * - * This is consistent with the ANSI C standards, which state that - * "either NULL or a pointer suitable to be passed to free()" must be - * returned in these cases. Using a special non-NULL value means that - * the caller can take a NULL return value to indicate failure, - * without first having to check for a requested size of zero. - * - * Code outside of malloc.c do not ever need to refer to the actual - * value of @c NOWHERE; this is an internal definition. - */ -#define NOWHERE ( ( void * ) ~( ( intptr_t ) 0 ) ) - /** List of free memory blocks */ static LIST_HEAD ( free_blocks ); diff --git a/src/core/xferbuf.c b/src/core/xferbuf.c index 240118557..1c08f8bc3 100644 --- a/src/core/xferbuf.c +++ b/src/core/xferbuf.c @@ -237,8 +237,8 @@ struct xfer_buffer_operations xferbuf_malloc_operations = { * @ret rc Return status code */ static int xferbuf_umalloc_realloc ( struct xfer_buffer *xferbuf, size_t len ) { - userptr_t *udata = xferbuf->data; - userptr_t new_udata; + void **udata = xferbuf->data; + void *new_udata; new_udata = urealloc ( *udata, len ); if ( ! new_udata ) @@ -257,9 +257,9 @@ static int xferbuf_umalloc_realloc ( struct xfer_buffer *xferbuf, size_t len ) { */ static void xferbuf_umalloc_write ( struct xfer_buffer *xferbuf, size_t offset, const void *data, size_t len ) { - userptr_t *udata = xferbuf->data; + void **udata = xferbuf->data; - copy_to_user ( *udata, offset, data, len ); + memcpy ( ( *udata + offset ), data, len ); } /** @@ -272,9 +272,9 @@ static void xferbuf_umalloc_write ( struct xfer_buffer *xferbuf, size_t offset, */ static void xferbuf_umalloc_read ( struct xfer_buffer *xferbuf, size_t offset, void *data, size_t len ) { - userptr_t *udata = xferbuf->data; + void **udata = xferbuf->data; - copy_from_user ( data, *udata, offset, len ); + memcpy ( data, ( *udata + offset ), len ); } /** umalloc()-based data buffer operations */ diff --git a/src/include/ipxe/dma.h b/src/include/ipxe/dma.h index 385e4baf7..6e5c43289 100644 --- a/src/include/ipxe/dma.h +++ b/src/include/ipxe/dma.h @@ -106,9 +106,9 @@ struct dma_operations { * @v align Physical alignment * @ret addr Buffer address, or NULL on error */ - userptr_t ( * umalloc ) ( struct dma_device *dma, - struct dma_mapping *map, - size_t len, size_t align ); + void * ( * umalloc ) ( struct dma_device *dma, + struct dma_mapping *map, + size_t len, size_t align ); /** * Unmap and free DMA-coherent buffer from external (user) memory * @@ -118,7 +118,7 @@ struct dma_operations { * @v len Length of buffer */ void ( * ufree ) ( struct dma_device *dma, struct dma_mapping *map, - userptr_t addr, size_t len ); + void *addr, size_t len ); /** * Set addressable space mask * @@ -265,11 +265,11 @@ DMAAPI_INLINE ( flat, dma_free ) ( struct dma_mapping *map, * @v align Physical alignment * @ret addr Buffer address, or NULL on error */ -static inline __always_inline userptr_t +static inline __always_inline void * DMAAPI_INLINE ( flat, dma_umalloc ) ( struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align __unused ) { - userptr_t addr; + void *addr; /* Allocate buffer */ addr = umalloc ( len ); @@ -292,7 +292,7 @@ DMAAPI_INLINE ( flat, dma_umalloc ) ( struct dma_device *dma, */ static inline __always_inline void DMAAPI_INLINE ( flat, dma_ufree ) ( struct dma_mapping *map, - userptr_t addr, size_t len __unused ) { + void *addr, size_t len __unused ) { /* Free buffer */ ufree ( addr ); @@ -397,8 +397,8 @@ void dma_free ( struct dma_mapping *map, void *addr, size_t len ); * @v align Physical alignment * @ret addr Buffer address, or NULL on error */ -userptr_t dma_umalloc ( struct dma_device *dma, struct dma_mapping *map, - size_t len, size_t align ); +void * dma_umalloc ( struct dma_device *dma, struct dma_mapping *map, + size_t len, size_t align ); /** * Unmap and free DMA-coherent buffer from external (user) memory @@ -407,7 +407,7 @@ userptr_t dma_umalloc ( struct dma_device *dma, struct dma_mapping *map, * @v addr Buffer address * @v len Length of buffer */ -void dma_ufree ( struct dma_mapping *map, userptr_t addr, size_t len ); +void dma_ufree ( struct dma_mapping *map, void *addr, size_t len ); /** * Set addressable space mask diff --git a/src/include/ipxe/malloc.h b/src/include/ipxe/malloc.h index f0fde0bc3..8c3a7769d 100644 --- a/src/include/ipxe/malloc.h +++ b/src/include/ipxe/malloc.h @@ -21,6 +21,24 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include +/** + * Address for zero-length memory blocks + * + * @c malloc(0) or @c realloc(ptr,0) will return the special value @c + * NOWHERE. Calling @c free(NOWHERE) will have no effect. + * + * This is consistent with the ANSI C standards, which state that + * "either NULL or a pointer suitable to be passed to free()" must be + * returned in these cases. Using a special non-NULL value means that + * the caller can take a NULL return value to indicate failure, + * without first having to check for a requested size of zero. + * + * Code outside of the memory allocators themselves does not ever need + * to refer to the actual value of @c NOWHERE; this is an internal + * definition. + */ +#define NOWHERE ( ( void * ) ~( ( intptr_t ) 0 ) ) + extern size_t freemem; extern size_t usedmem; extern size_t maxusedmem; diff --git a/src/include/ipxe/umalloc.h b/src/include/ipxe/umalloc.h index 3892ef53b..a6476a390 100644 --- a/src/include/ipxe/umalloc.h +++ b/src/include/ipxe/umalloc.h @@ -10,9 +10,10 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); +#include #include +#include #include -#include /** * Provide a user memory allocation API implementation @@ -34,36 +35,36 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); /** * Reallocate external memory * - * @v userptr Memory previously allocated by umalloc(), or UNULL + * @v old_ptr Memory previously allocated by umalloc(), or NULL * @v new_size Requested size - * @ret userptr Allocated memory, or UNULL + * @ret new_ptr Allocated memory, or NULL * * Calling realloc() with a new size of zero is a valid way to free a * memory block. */ -userptr_t urealloc ( userptr_t userptr, size_t new_size ); +void * urealloc ( void *ptr, size_t new_size ); /** * Allocate external memory * * @v size Requested size - * @ret userptr Memory, or UNULL + * @ret ptr Memory, or NULL * * Memory is guaranteed to be aligned to a page boundary. */ -static inline __always_inline userptr_t umalloc ( size_t size ) { - return urealloc ( UNULL, size ); +static inline __always_inline void * umalloc ( size_t size ) { + return urealloc ( NULL, size ); } /** * Free external memory * - * @v userptr Memory allocated by umalloc(), or UNULL + * @v ptr Memory allocated by umalloc(), or NULL * - * If @c ptr is UNULL, no action is taken. + * If @c ptr is NULL, no action is taken. */ -static inline __always_inline void ufree ( userptr_t userptr ) { - urealloc ( userptr, 0 ); +static inline __always_inline void ufree ( void *ptr ) { + urealloc ( ptr, 0 ); } #endif /* _IPXE_UMALLOC_H */ diff --git a/src/include/ipxe/xferbuf.h b/src/include/ipxe/xferbuf.h index cb0b1a0e8..04635999d 100644 --- a/src/include/ipxe/xferbuf.h +++ b/src/include/ipxe/xferbuf.h @@ -11,7 +11,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include -#include #include #include @@ -84,7 +83,7 @@ xferbuf_malloc_init ( struct xfer_buffer *xferbuf ) { * @v data User pointer */ static inline __attribute__ (( always_inline )) void -xferbuf_umalloc_init ( struct xfer_buffer *xferbuf, userptr_t *data ) { +xferbuf_umalloc_init ( struct xfer_buffer *xferbuf, void **data ) { xferbuf->data = data; xferbuf->op = &xferbuf_umalloc_operations; } diff --git a/src/interface/efi/efi_pci.c b/src/interface/efi/efi_pci.c index 01351df51..b8c7df38d 100644 --- a/src/interface/efi/efi_pci.c +++ b/src/interface/efi/efi_pci.c @@ -640,38 +640,6 @@ static void efipci_dma_free ( struct dma_device *dma, struct dma_mapping *map, dma->allocated--; } -/** - * Allocate and map DMA-coherent buffer from external (user) memory - * - * @v dma DMA device - * @v map DMA mapping to fill in - * @v len Length of buffer - * @v align Physical alignment - * @ret addr Buffer address, or NULL on error - */ -static userptr_t efipci_dma_umalloc ( struct dma_device *dma, - struct dma_mapping *map, - size_t len, size_t align ) { - void *addr; - - addr = efipci_dma_alloc ( dma, map, len, align ); - return virt_to_user ( addr ); -} - -/** - * Unmap and free DMA-coherent buffer from external (user) memory - * - * @v dma DMA device - * @v map DMA mapping - * @v addr Buffer address - * @v len Length of buffer - */ -static void efipci_dma_ufree ( struct dma_device *dma, struct dma_mapping *map, - userptr_t addr, size_t len ) { - - efipci_dma_free ( dma, map, addr, len ); -} - /** * Set addressable space mask * @@ -710,8 +678,8 @@ static struct dma_operations efipci_dma_operations = { .unmap = efipci_dma_unmap, .alloc = efipci_dma_alloc, .free = efipci_dma_free, - .umalloc = efipci_dma_umalloc, - .ufree = efipci_dma_ufree, + .umalloc = efipci_dma_alloc, + .ufree = efipci_dma_free, .set_mask = efipci_dma_set_mask, }; diff --git a/src/interface/efi/efi_umalloc.c b/src/interface/efi/efi_umalloc.c index 0636cb7fd..419d9b294 100644 --- a/src/interface/efi/efi_umalloc.c +++ b/src/interface/efi/efi_umalloc.c @@ -26,6 +26,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include #include +#include #include #include @@ -35,25 +36,23 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * */ -/** Equivalent of NOWHERE for user pointers */ -#define UNOWHERE ( ( userptr_t ) ~( ( intptr_t ) 0 ) ) - /** * Reallocate external memory * - * @v old_ptr Memory previously allocated by umalloc(), or UNULL + * @v old_ptr Memory previously allocated by umalloc(), or NULL * @v new_size Requested size - * @ret new_ptr Allocated memory, or UNULL + * @ret new_ptr Allocated memory, or NULL * * Calling realloc() with a new size of zero is a valid way to free a * memory block. */ -static userptr_t efi_urealloc ( userptr_t old_ptr, size_t new_size ) { +static void * efi_urealloc ( void *old_ptr, size_t new_size ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_PHYSICAL_ADDRESS phys_addr; unsigned int new_pages, old_pages; - userptr_t new_ptr = UNOWHERE; + void *new_ptr = NOWHERE; size_t old_size; + size_t *info; EFI_STATUS efirc; int rc; @@ -69,12 +68,12 @@ static userptr_t efi_urealloc ( userptr_t old_ptr, size_t new_size ) { rc = -EEFI ( efirc ); DBG ( "EFI could not allocate %d pages: %s\n", new_pages, strerror ( rc ) ); - return UNULL; + return NULL; } assert ( phys_addr != 0 ); new_ptr = phys_to_virt ( phys_addr + EFI_PAGE_SIZE ); - copy_to_user ( new_ptr, -EFI_PAGE_SIZE, - &new_size, sizeof ( new_size ) ); + info = ( new_ptr - EFI_PAGE_SIZE ); + *info = new_size; DBG ( "EFI allocated %d pages at %llx\n", new_pages, phys_addr ); } @@ -84,9 +83,9 @@ static userptr_t efi_urealloc ( userptr_t old_ptr, size_t new_size ) { * is valid, or (b) new_size is 0; either way, the memcpy() is * valid. */ - if ( old_ptr && ( old_ptr != UNOWHERE ) ) { - copy_from_user ( &old_size, old_ptr, -EFI_PAGE_SIZE, - sizeof ( old_size ) ); + if ( old_ptr && ( old_ptr != NOWHERE ) ) { + info = ( old_ptr - EFI_PAGE_SIZE ); + old_size = *info; memcpy ( new_ptr, old_ptr, ( (old_size < new_size) ? old_size : new_size ) ); old_pages = ( EFI_SIZE_TO_PAGES ( old_size ) + 1 ); diff --git a/src/interface/linux/linux_umalloc.c b/src/interface/linux/linux_umalloc.c index a7250fa5b..ab5770e9c 100644 --- a/src/interface/linux/linux_umalloc.c +++ b/src/interface/linux/linux_umalloc.c @@ -31,9 +31,6 @@ FILE_LICENCE(GPL2_OR_LATER); #include -/** Special address returned for empty allocations */ -#define NOWHERE ((void *)-1) - /** Poison to make the metadata more unique */ #define POISON 0xa5a5a5a5 #define min(a,b) (((a)<(b))?(a):(b)) @@ -47,7 +44,16 @@ struct metadata #define SIZE_MD (sizeof(struct metadata)) -/** Simple realloc which passes most of the work to mmap(), mremap() and munmap() */ +/** + * Reallocate external memory + * + * @v old_ptr Memory previously allocated by umalloc(), or NULL + * @v new_size Requested size + * @ret new_ptr Allocated memory, or NULL + * + * Calling realloc() with a new size of zero is a valid way to free a + * memory block. + */ static void * linux_realloc(void *ptr, size_t size) { struct metadata md = {0, 0}; @@ -136,19 +142,4 @@ static void * linux_realloc(void *ptr, size_t size) return ptr; } -/** - * Reallocate external memory - * - * @v old_ptr Memory previously allocated by umalloc(), or UNULL - * @v new_size Requested size - * @ret new_ptr Allocated memory, or UNULL - * - * Calling realloc() with a new size of zero is a valid way to free a - * memory block. - */ -static userptr_t linux_urealloc(userptr_t old_ptr, size_t new_size) -{ - return (userptr_t)linux_realloc((void *)old_ptr, new_size); -} - -PROVIDE_UMALLOC(linux, urealloc, linux_urealloc); +PROVIDE_UMALLOC(linux, urealloc, linux_realloc); diff --git a/src/tests/umalloc_test.c b/src/tests/umalloc_test.c index 53810833c..1a32a0531 100644 --- a/src/tests/umalloc_test.c +++ b/src/tests/umalloc_test.c @@ -1,12 +1,11 @@ #include -#include #include #include void umalloc_test ( void ) { struct memory_map memmap; - userptr_t bob; - userptr_t fred; + void *bob; + void *fred; printf ( "Before allocation:\n" ); get_memmap ( &memmap ); -- cgit v1.2.3-55-g7522 From e8ffe2cd644000c1cca51c40ba14edb546ca769b Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 24 Apr 2025 01:30:50 +0100 Subject: [uaccess] Remove trivial uses of userptr_t Signed-off-by: Michael Brown --- src/arch/x86/core/vram_settings.c | 5 +++-- src/arch/x86/image/pxe_image.c | 2 +- src/arch/x86/include/realmode.h | 4 ++-- src/arch/x86/interface/pxe/pxe_preboot.c | 5 ++--- src/arch/x86/interface/pxe/pxe_tftp.c | 12 +++++------- src/arch/x86/interface/pxe/pxe_udp.c | 9 ++++----- src/core/cachedhcp.c | 4 ++-- src/core/dma.c | 2 +- src/core/fdt.c | 6 +++--- src/drivers/infiniband/arbel.c | 2 +- src/drivers/infiniband/arbel.h | 5 ++--- src/drivers/infiniband/golan.c | 12 ++++++------ src/drivers/infiniband/golan.h | 2 +- src/drivers/infiniband/hermon.c | 2 +- src/drivers/infiniband/hermon.h | 5 ++--- src/drivers/net/efi/nii.c | 2 +- src/drivers/net/netvsc.c | 2 +- src/drivers/net/netvsc.h | 2 +- src/drivers/usb/xhci.h | 3 +-- src/image/segment.c | 2 +- src/include/ipxe/cachedhcp.h | 3 +-- src/include/ipxe/linux_sysfs.h | 4 +--- src/include/ipxe/memblock.h | 3 +-- src/include/ipxe/segment.h | 4 ++-- src/include/ipxe/vmbus.h | 3 +-- src/interface/efi/efi_block.c | 3 +-- src/interface/efi/efi_bofm.c | 3 +-- src/interface/efi/efi_cachedhcp.c | 10 ++++------ src/interface/efi/efi_file.c | 17 +++++++---------- src/interface/hyperv/vmbus.c | 4 ++-- src/interface/linux/linux_acpi.c | 1 + src/interface/linux/linux_smbios.c | 1 + src/interface/linux/linux_sysfs.c | 6 +++--- src/tests/bofm_test.c | 5 ++--- 34 files changed, 69 insertions(+), 86 deletions(-) (limited to 'src/interface/linux') diff --git a/src/arch/x86/core/vram_settings.c b/src/arch/x86/core/vram_settings.c index ceeada467..a97a463fe 100644 --- a/src/arch/x86/core/vram_settings.c +++ b/src/arch/x86/core/vram_settings.c @@ -23,6 +23,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); +#include #include #include @@ -47,12 +48,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * @ret len Length of setting data, or negative error */ static int vram_fetch ( void *data, size_t len ) { - userptr_t vram = phys_to_virt ( VRAM_BASE ); + const void *vram = phys_to_virt ( VRAM_BASE ); /* Copy video RAM */ if ( len > VRAM_LEN ) len = VRAM_LEN; - copy_from_user ( data, vram, 0, len ); + memcpy ( data, vram, len ); return VRAM_LEN; } diff --git a/src/arch/x86/image/pxe_image.c b/src/arch/x86/image/pxe_image.c index 5472ea594..9f8044fa1 100644 --- a/src/arch/x86/image/pxe_image.c +++ b/src/arch/x86/image/pxe_image.c @@ -54,7 +54,7 @@ const char *pxe_cmdline; * @ret rc Return status code */ static int pxe_exec ( struct image *image ) { - userptr_t buffer = real_to_virt ( 0, 0x7c00 ); + void *buffer = real_to_virt ( 0, 0x7c00 ); struct net_device *netdev; int rc; diff --git a/src/arch/x86/include/realmode.h b/src/arch/x86/include/realmode.h index 0017b42c0..75f7d16e7 100644 --- a/src/arch/x86/include/realmode.h +++ b/src/arch/x86/include/realmode.h @@ -87,7 +87,7 @@ real_to_virt ( unsigned int segment, unsigned int offset ) { static inline __always_inline void copy_to_real ( unsigned int dest_seg, unsigned int dest_off, void *src, size_t n ) { - copy_to_user ( real_to_virt ( dest_seg, dest_off ), 0, src, n ); + memcpy ( real_to_virt ( dest_seg, dest_off ), src, n ); } /** @@ -101,7 +101,7 @@ copy_to_real ( unsigned int dest_seg, unsigned int dest_off, static inline __always_inline void copy_from_real ( void *dest, unsigned int src_seg, unsigned int src_off, size_t n ) { - copy_from_user ( dest, real_to_virt ( src_seg, src_off ), 0, n ); + memcpy ( dest, real_to_virt ( src_seg, src_off ), n ); } /** diff --git a/src/arch/x86/interface/pxe/pxe_preboot.c b/src/arch/x86/interface/pxe/pxe_preboot.c index 727d8e1ea..77dcf66e7 100644 --- a/src/arch/x86/interface/pxe/pxe_preboot.c +++ b/src/arch/x86/interface/pxe/pxe_preboot.c @@ -33,7 +33,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include #include -#include #include #include #include @@ -184,7 +183,7 @@ pxenv_get_cached_info ( struct s_PXENV_GET_CACHED_INFO *get_cached_info ) { union pxe_cached_info *info; unsigned int idx; size_t len; - userptr_t buffer; + void *buffer; DBGC ( &pxe_netdev, "PXENV_GET_CACHED_INFO %s to %04x:%04x+%x", pxenv_get_cached_info_name ( get_cached_info->PacketType ), @@ -245,7 +244,7 @@ pxenv_get_cached_info ( struct s_PXENV_GET_CACHED_INFO *get_cached_info ) { DBGC ( &pxe_netdev, " buffer may be too short" ); buffer = real_to_virt ( get_cached_info->Buffer.segment, get_cached_info->Buffer.offset ); - copy_to_user ( buffer, 0, info, len ); + memcpy ( buffer, info, len ); get_cached_info->BufferSize = len; } diff --git a/src/arch/x86/interface/pxe/pxe_tftp.c b/src/arch/x86/interface/pxe/pxe_tftp.c index 073414dce..aa675fd13 100644 --- a/src/arch/x86/interface/pxe/pxe_tftp.c +++ b/src/arch/x86/interface/pxe/pxe_tftp.c @@ -33,7 +33,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include #include -#include #include #include #include @@ -49,7 +48,7 @@ struct pxe_tftp_connection { /** Data transfer interface */ struct interface xfer; /** Data buffer */ - userptr_t buffer; + void *buffer; /** Size of data buffer */ size_t size; /** Starting offset of data buffer */ @@ -121,9 +120,8 @@ static int pxe_tftp_xfer_deliver ( struct pxe_tftp_connection *pxe_tftp, ( pxe_tftp->start + pxe_tftp->size ) ); rc = -ENOBUFS; } else { - copy_to_user ( pxe_tftp->buffer, - ( pxe_tftp->offset - pxe_tftp->start ), - iobuf->data, len ); + memcpy ( ( pxe_tftp->buffer + pxe_tftp->offset - + pxe_tftp->start ), iobuf->data, len ); } /* Calculate new buffer position */ @@ -385,7 +383,7 @@ static PXENV_EXIT_t pxenv_tftp_read ( struct s_PXENV_TFTP_READ *tftp_read ) { while ( ( ( rc = pxe_tftp.rc ) == -EINPROGRESS ) && ( pxe_tftp.offset == pxe_tftp.start ) ) step(); - pxe_tftp.buffer = UNULL; + pxe_tftp.buffer = NULL; tftp_read->BufferSize = ( pxe_tftp.offset - pxe_tftp.start ); tftp_read->PacketNumber = ++pxe_tftp.blkidx; @@ -496,7 +494,7 @@ PXENV_EXIT_t pxenv_tftp_read_file ( struct s_PXENV_TFTP_READ_FILE pxe_tftp.size = tftp_read_file->BufferSize; while ( ( rc = pxe_tftp.rc ) == -EINPROGRESS ) step(); - pxe_tftp.buffer = UNULL; + pxe_tftp.buffer = NULL; tftp_read_file->BufferSize = pxe_tftp.max_offset; /* Close TFTP file */ diff --git a/src/arch/x86/interface/pxe/pxe_udp.c b/src/arch/x86/interface/pxe/pxe_udp.c index 47abb7df4..61c858dde 100644 --- a/src/arch/x86/interface/pxe/pxe_udp.c +++ b/src/arch/x86/interface/pxe/pxe_udp.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -296,7 +295,7 @@ pxenv_udp_write ( struct s_PXENV_UDP_WRITE *pxenv_udp_write ) { }; size_t len; struct io_buffer *iobuf; - userptr_t buffer; + const void *buffer; int rc; DBG ( "PXENV_UDP_WRITE" ); @@ -330,7 +329,7 @@ pxenv_udp_write ( struct s_PXENV_UDP_WRITE *pxenv_udp_write ) { } buffer = real_to_virt ( pxenv_udp_write->buffer.segment, pxenv_udp_write->buffer.offset ); - copy_from_user ( iob_put ( iobuf, len ), buffer, 0, len ); + memcpy ( iob_put ( iobuf, len ), buffer, len ); DBG ( " %04x:%04x+%x %d->%s:%d\n", pxenv_udp_write->buffer.segment, pxenv_udp_write->buffer.offset, pxenv_udp_write->buffer_size, @@ -400,7 +399,7 @@ static PXENV_EXIT_t pxenv_udp_read ( struct s_PXENV_UDP_READ *pxenv_udp_read ) { struct pxe_udp_pseudo_header *pshdr; uint16_t d_port_wanted = pxenv_udp_read->d_port; uint16_t d_port; - userptr_t buffer; + void *buffer; size_t len; /* Try receiving a packet, if the queue is empty */ @@ -443,7 +442,7 @@ static PXENV_EXIT_t pxenv_udp_read ( struct s_PXENV_UDP_READ *pxenv_udp_read ) { len = iob_len ( iobuf ); if ( len > pxenv_udp_read->buffer_size ) len = pxenv_udp_read->buffer_size; - copy_to_user ( buffer, 0, iobuf->data, len ); + memcpy ( buffer, iobuf->data, len ); pxenv_udp_read->buffer_size = len; /* Fill in source/dest information */ diff --git a/src/core/cachedhcp.c b/src/core/cachedhcp.c index 07589f0b8..0d400db16 100644 --- a/src/core/cachedhcp.c +++ b/src/core/cachedhcp.c @@ -198,7 +198,7 @@ static int cachedhcp_apply ( struct cached_dhcp_packet *cache, * @ret rc Return status code */ int cachedhcp_record ( struct cached_dhcp_packet *cache, unsigned int vlan, - userptr_t data, size_t max_len ) { + const void *data, size_t max_len ) { struct dhcp_packet *dhcppkt; struct dhcp_packet *tmp; struct dhcphdr *dhcphdr; @@ -216,7 +216,7 @@ int cachedhcp_record ( struct cached_dhcp_packet *cache, unsigned int vlan, return -ENOMEM; } dhcphdr = ( ( ( void * ) dhcppkt ) + sizeof ( *dhcppkt ) ); - copy_from_user ( dhcphdr, data, 0, max_len ); + memcpy ( dhcphdr, data, max_len ); dhcppkt_init ( dhcppkt, dhcphdr, max_len ); /* Shrink packet to required length. If reallocation fails, diff --git a/src/core/dma.c b/src/core/dma.c index 1f3c1d8a6..cf4b20379 100644 --- a/src/core/dma.c +++ b/src/core/dma.c @@ -136,7 +136,7 @@ static void * dma_op_umalloc ( struct dma_device *dma, struct dma_operations *op = dma->op; if ( ! op ) - return UNULL; + return NULL; return op->umalloc ( dma, map, len, align ); } diff --git a/src/core/fdt.c b/src/core/fdt.c index 4c709b342..7c7127aed 100644 --- a/src/core/fdt.c +++ b/src/core/fdt.c @@ -1037,7 +1037,7 @@ static int fdt_urealloc ( struct fdt *fdt, size_t len ) { assert ( len >= fdt->used ); /* Attempt reallocation */ - new = urealloc ( virt_to_user ( fdt->raw ), len ); + new = urealloc ( fdt->raw, len ); if ( ! new ) { DBGC ( fdt, "FDT could not reallocate from +%#04zx to " "+%#04zx\n", fdt->len, len ); @@ -1129,7 +1129,7 @@ int fdt_create ( struct fdt_header **hdr, const char *cmdline ) { return 0; err_bootargs: - ufree ( virt_to_user ( fdt.raw ) ); + ufree ( fdt.raw ); err_alloc: err_image: return rc; @@ -1143,7 +1143,7 @@ int fdt_create ( struct fdt_header **hdr, const char *cmdline ) { void fdt_remove ( struct fdt_header *hdr ) { /* Free modifiable copy */ - ufree ( virt_to_user ( hdr ) ); + ufree ( hdr ); } /* Drag in objects via fdt_describe() */ diff --git a/src/drivers/infiniband/arbel.c b/src/drivers/infiniband/arbel.c index 4cb4167e0..0789ea593 100644 --- a/src/drivers/infiniband/arbel.c +++ b/src/drivers/infiniband/arbel.c @@ -2119,7 +2119,7 @@ static void arbel_stop_firmware ( struct arbel *arbel ) { DBGC ( arbel, "Arbel %p FATAL could not stop firmware: %s\n", arbel, strerror ( rc ) ); /* Leak memory and return; at least we avoid corruption */ - arbel->firmware_area = UNULL; + arbel->firmware_area = NULL; return; } } diff --git a/src/drivers/infiniband/arbel.h b/src/drivers/infiniband/arbel.h index 8a5a996a3..a31e59934 100644 --- a/src/drivers/infiniband/arbel.h +++ b/src/drivers/infiniband/arbel.h @@ -10,7 +10,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include -#include #include #include "mlx_bitops.h" #include "MT25218_PRM.h" @@ -492,7 +491,7 @@ struct arbel { * final teardown, in order to avoid memory map changes at * runtime. */ - userptr_t firmware_area; + void *firmware_area; /** ICM size */ size_t icm_len; /** ICM AUX size */ @@ -503,7 +502,7 @@ struct arbel { * final teardown, in order to avoid memory map changes at * runtime. */ - userptr_t icm; + void *icm; /** Offset within ICM of doorbell records */ size_t db_rec_offset; /** Doorbell records */ diff --git a/src/drivers/infiniband/golan.c b/src/drivers/infiniband/golan.c index a33bad9ff..ffa78fabf 100755 --- a/src/drivers/infiniband/golan.c +++ b/src/drivers/infiniband/golan.c @@ -52,7 +52,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); struct golan_page { struct list_head list; - userptr_t addr; + void *addr; }; static void golan_free_fw_areas ( struct golan *golan ) { @@ -61,7 +61,7 @@ static void golan_free_fw_areas ( struct golan *golan ) { for (i = 0; i < GOLAN_FW_AREAS_NUM; i++) { if ( golan->fw_areas[i].area ) { ufree ( golan->fw_areas[i].area ); - golan->fw_areas[i].area = UNULL; + golan->fw_areas[i].area = NULL; } } } @@ -75,7 +75,7 @@ static int golan_init_fw_areas ( struct golan *golan ) { } for (i = 0; i < GOLAN_FW_AREAS_NUM; i++) - golan->fw_areas[i].area = UNULL; + golan->fw_areas[i].area = NULL; return rc; @@ -448,12 +448,12 @@ static inline int golan_provide_pages ( struct golan *golan , uint32_t pages int size_ibox = 0; int size_obox = 0; int rc = 0; - userptr_t next_page_addr = UNULL; + void *next_page_addr = NULL; DBGC(golan, "%s\n", __FUNCTION__); if ( ! fw_area->area ) { fw_area->area = umalloc ( GOLAN_PAGE_SIZE * pages ); - if ( fw_area->area == UNULL ) { + if ( fw_area->area == NULL ) { rc = -ENOMEM; DBGC (golan ,"Failed to allocated %d pages \n",pages); goto err_golan_alloc_fw_area; @@ -467,7 +467,7 @@ static inline int golan_provide_pages ( struct golan *golan , uint32_t pages unsigned i, j; struct golan_cmd_layout *cmd; struct golan_manage_pages_inbox *in; - userptr_t addr = 0; + void *addr = NULL; mailbox = GET_INBOX(golan, MEM_MBOX); size_ibox = sizeof(struct golan_manage_pages_inbox) + (pas_num * GOLAN_PAS_SIZE); diff --git a/src/drivers/infiniband/golan.h b/src/drivers/infiniband/golan.h index f7da1e960..8122f8d38 100755 --- a/src/drivers/infiniband/golan.h +++ b/src/drivers/infiniband/golan.h @@ -121,7 +121,7 @@ struct golan_firmware_area { * final teardown, in order to avoid memory map changes at * runtime. */ - userptr_t area; + void *area; }; /* Queue Pair */ #define GOLAN_SEND_WQE_BB_SIZE 64 diff --git a/src/drivers/infiniband/hermon.c b/src/drivers/infiniband/hermon.c index 3138d8bfb..d25f4f011 100644 --- a/src/drivers/infiniband/hermon.c +++ b/src/drivers/infiniband/hermon.c @@ -2422,7 +2422,7 @@ static void hermon_stop_firmware ( struct hermon *hermon ) { DBGC ( hermon, "Hermon %p FATAL could not stop firmware: %s\n", hermon, strerror ( rc ) ); /* Leak memory and return; at least we avoid corruption */ - hermon->firmware_area = UNULL; + hermon->firmware_area = NULL; return; } } diff --git a/src/drivers/infiniband/hermon.h b/src/drivers/infiniband/hermon.h index a952bbd81..be79ff9d0 100644 --- a/src/drivers/infiniband/hermon.h +++ b/src/drivers/infiniband/hermon.h @@ -10,7 +10,6 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include -#include #include #include #include @@ -887,7 +886,7 @@ struct hermon { * final teardown, in order to avoid memory map changes at * runtime. */ - userptr_t firmware_area; + void *firmware_area; /** ICM map */ struct hermon_icm_map icm_map[HERMON_ICM_NUM_REGIONS]; /** ICM size */ @@ -900,7 +899,7 @@ struct hermon { * final teardown, in order to avoid memory map changes at * runtime. */ - userptr_t icm; + void *icm; /** Event queue */ struct hermon_event_queue eq; diff --git a/src/drivers/net/efi/nii.c b/src/drivers/net/efi/nii.c index 6381fb2dd..c60d4ca18 100644 --- a/src/drivers/net/efi/nii.c +++ b/src/drivers/net/efi/nii.c @@ -177,7 +177,7 @@ struct nii_nic { size_t mtu; /** Hardware transmit/receive buffer */ - userptr_t buffer; + void *buffer; /** Hardware transmit/receive buffer length */ size_t buffer_len; diff --git a/src/drivers/net/netvsc.c b/src/drivers/net/netvsc.c index 5be52fb8e..4bdf7b517 100644 --- a/src/drivers/net/netvsc.c +++ b/src/drivers/net/netvsc.c @@ -622,7 +622,7 @@ static int netvsc_buffer_copy ( struct vmbus_xfer_pages *pages, void *data, return -ERANGE; /* Copy data from buffer */ - copy_from_user ( data, buffer->data, offset, len ); + memcpy ( data, ( buffer->data + offset ), len ); return 0; } diff --git a/src/drivers/net/netvsc.h b/src/drivers/net/netvsc.h index 93192357f..41db49af7 100644 --- a/src/drivers/net/netvsc.h +++ b/src/drivers/net/netvsc.h @@ -305,7 +305,7 @@ struct netvsc_buffer { /** Buffer length */ size_t len; /** Buffer */ - userptr_t data; + void *data; /** GPADL ID */ unsigned int gpadl; }; diff --git a/src/drivers/usb/xhci.h b/src/drivers/usb/xhci.h index a3c8888af..22bc115c2 100644 --- a/src/drivers/usb/xhci.h +++ b/src/drivers/usb/xhci.h @@ -11,7 +11,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include -#include #include /** Minimum alignment required for data structures @@ -1054,7 +1053,7 @@ struct xhci_scratchpad { /** Number of page-sized scratchpad buffers */ unsigned int count; /** Scratchpad buffer area */ - userptr_t buffer; + void *buffer; /** Buffer DMA mapping */ struct dma_mapping buffer_map; /** Scratchpad array */ diff --git a/src/image/segment.c b/src/image/segment.c index ebc2b703d..2cb637dc2 100644 --- a/src/image/segment.c +++ b/src/image/segment.c @@ -57,7 +57,7 @@ struct errortab segment_errors[] __errortab = { * @v memsz Size of the segment * @ret rc Return status code */ -int prep_segment ( userptr_t segment, size_t filesz, size_t memsz ) { +int prep_segment ( void *segment, size_t filesz, size_t memsz ) { struct memory_map memmap; physaddr_t start = virt_to_phys ( segment ); physaddr_t mid = ( start + filesz ); diff --git a/src/include/ipxe/cachedhcp.h b/src/include/ipxe/cachedhcp.h index 8ebee3b7b..5b19bc59e 100644 --- a/src/include/ipxe/cachedhcp.h +++ b/src/include/ipxe/cachedhcp.h @@ -10,7 +10,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include -#include struct net_device; struct cached_dhcp_packet; @@ -20,7 +19,7 @@ extern struct cached_dhcp_packet cached_proxydhcp; extern struct cached_dhcp_packet cached_pxebs; extern int cachedhcp_record ( struct cached_dhcp_packet *cache, - unsigned int vlan, userptr_t data, + unsigned int vlan, const void *data, size_t max_len ); extern void cachedhcp_recycle ( struct net_device *netdev ); diff --git a/src/include/ipxe/linux_sysfs.h b/src/include/ipxe/linux_sysfs.h index d97b649c0..fbe1e6e8a 100644 --- a/src/include/ipxe/linux_sysfs.h +++ b/src/include/ipxe/linux_sysfs.h @@ -9,8 +9,6 @@ FILE_LICENCE ( GPL2_OR_LATER ); -#include - -extern int linux_sysfs_read ( const char *filename, userptr_t *data ); +extern int linux_sysfs_read ( const char *filename, void **data ); #endif /* _IPXE_LINUX_SYSFS_H */ diff --git a/src/include/ipxe/memblock.h b/src/include/ipxe/memblock.h index 2bb38c460..4b6c64156 100644 --- a/src/include/ipxe/memblock.h +++ b/src/include/ipxe/memblock.h @@ -10,8 +10,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include -#include -extern size_t largest_memblock ( userptr_t *start ); +extern size_t largest_memblock ( void **start ); #endif /* _IPXE_MEMBLOCK_H */ diff --git a/src/include/ipxe/segment.h b/src/include/ipxe/segment.h index 9d5ecbd9b..b37c93c93 100644 --- a/src/include/ipxe/segment.h +++ b/src/include/ipxe/segment.h @@ -10,8 +10,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); -#include +#include -extern int prep_segment ( userptr_t segment, size_t filesz, size_t memsz ); +extern int prep_segment ( void *segment, size_t filesz, size_t memsz ); #endif /* _IPXE_SEGMENT_H */ diff --git a/src/include/ipxe/vmbus.h b/src/include/ipxe/vmbus.h index 682441857..5eee230fe 100644 --- a/src/include/ipxe/vmbus.h +++ b/src/include/ipxe/vmbus.h @@ -13,7 +13,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include #include -#include #include #include @@ -634,7 +633,7 @@ vmbus_gpadl_is_obsolete ( unsigned int gpadl ) { return ( gpadl <= vmbus_obsolete_gpadl ); } -extern int vmbus_establish_gpadl ( struct vmbus_device *vmdev, userptr_t data, +extern int vmbus_establish_gpadl ( struct vmbus_device *vmdev, void *data, size_t len ); extern int vmbus_gpadl_teardown ( struct vmbus_device *vmdev, unsigned int gpadl ); diff --git a/src/interface/efi/efi_block.c b/src/interface/efi/efi_block.c index 5165bd804..94e2aae06 100644 --- a/src/interface/efi/efi_block.c +++ b/src/interface/efi/efi_block.c @@ -110,8 +110,7 @@ static int efi_block_rw ( struct san_device *sandev, uint64_t lba, } /* Read from / write to block device */ - if ( ( rc = sandev_rw ( sandev, lba, count, - virt_to_user ( data ) ) ) != 0 ) { + if ( ( rc = sandev_rw ( sandev, lba, count, data ) ) != 0 ) { DBGC ( sandev->drive, "EFIBLK %#02x I/O failed: %s\n", sandev->drive, strerror ( rc ) ); return rc; diff --git a/src/interface/efi/efi_bofm.c b/src/interface/efi/efi_bofm.c index b64770d8a..7d1d3619f 100644 --- a/src/interface/efi/efi_bofm.c +++ b/src/interface/efi/efi_bofm.c @@ -284,8 +284,7 @@ static int efi_bofm_start ( struct efi_device *efidev ) { efi_handle_name ( device ) ); DBGC2_HD ( device, bofmtab2, bofmtab2->Parameters.Length ); } - bofmrc = bofm ( virt_to_user ( bofmtab2 ? bofmtab2 : bofmtab ), - &efipci.pci ); + bofmrc = bofm ( ( bofmtab2 ? bofmtab2 : bofmtab ), &efipci.pci ); DBGC ( device, "EFIBOFM %s status %08x\n", efi_handle_name ( device ), bofmrc ); DBGC2 ( device, "EFIBOFM %s version 1 after processing:\n", diff --git a/src/interface/efi/efi_cachedhcp.c b/src/interface/efi/efi_cachedhcp.c index eb41a8e43..6bba4173a 100644 --- a/src/interface/efi/efi_cachedhcp.c +++ b/src/interface/efi/efi_cachedhcp.c @@ -72,8 +72,7 @@ int efi_cachedhcp_record ( EFI_HANDLE device, /* Record DHCPACK, if present */ if ( mode->DhcpAckReceived && - ( ( rc = cachedhcp_record ( &cached_dhcpack, vlan, - virt_to_user ( &mode->DhcpAck ), + ( ( rc = cachedhcp_record ( &cached_dhcpack, vlan, &mode->DhcpAck, sizeof ( mode->DhcpAck ) ) ) != 0 ) ) { DBGC ( device, "EFI %s could not record DHCPACK: %s\n", efi_handle_name ( device ), strerror ( rc ) ); @@ -83,7 +82,7 @@ int efi_cachedhcp_record ( EFI_HANDLE device, /* Record ProxyDHCPOFFER, if present */ if ( mode->ProxyOfferReceived && ( ( rc = cachedhcp_record ( &cached_proxydhcp, vlan, - virt_to_user ( &mode->ProxyOffer ), + &mode->ProxyOffer, sizeof ( mode->ProxyOffer ) ) ) != 0)){ DBGC ( device, "EFI %s could not record ProxyDHCPOFFER: %s\n", efi_handle_name ( device ), strerror ( rc ) ); @@ -92,9 +91,8 @@ int efi_cachedhcp_record ( EFI_HANDLE device, /* Record PxeBSACK, if present */ if ( mode->PxeReplyReceived && - ( ( rc = cachedhcp_record ( &cached_pxebs, vlan, - virt_to_user ( &mode->PxeReply ), - sizeof ( mode->PxeReply ) ) ) != 0)){ + ( ( rc = cachedhcp_record ( &cached_pxebs, vlan, &mode->PxeReply, + sizeof ( mode->PxeReply ) ) ) != 0 )){ DBGC ( device, "EFI %s could not record PXEBSACK: %s\n", efi_handle_name ( device ), strerror ( rc ) ); return rc; diff --git a/src/interface/efi/efi_file.c b/src/interface/efi/efi_file.c index b7b97aee7..79330641d 100644 --- a/src/interface/efi/efi_file.c +++ b/src/interface/efi/efi_file.c @@ -177,12 +177,12 @@ static size_t efi_file_len ( struct efi_file *file ) { * Read chunk of EFI file * * @v reader EFI file reader - * @v data Input data, or UNULL to zero-fill + * @v data Input data, or NULL to zero-fill * @v len Length of input data * @ret len Length of output data */ static size_t efi_file_read_chunk ( struct efi_file_reader *reader, - userptr_t data, size_t len ) { + const void *data, size_t len ) { struct efi_file *file = reader->file; size_t offset; @@ -203,7 +203,7 @@ static size_t efi_file_read_chunk ( struct efi_file_reader *reader, /* Copy or zero output data */ if ( data ) { - copy_from_user ( reader->data, data, offset, len ); + memcpy ( reader->data, ( data + offset ), len ); } else { memset ( reader->data, 0, len ); } @@ -262,7 +262,7 @@ static size_t efi_file_read_initrd ( struct efi_file_reader *reader ) { efi_file_name ( file ), reader->pos, ( reader->pos + pad_len ) ); } - len += efi_file_read_chunk ( reader, UNULL, pad_len ); + len += efi_file_read_chunk ( reader, NULL, pad_len ); /* Read CPIO header(s), if applicable */ name = cpio_name ( image ); @@ -274,13 +274,10 @@ static size_t efi_file_read_initrd ( struct efi_file_reader *reader ) { efi_file_name ( file ), reader->pos, ( reader->pos + cpio_len + pad_len ), image->name ); - len += efi_file_read_chunk ( reader, - virt_to_user ( &cpio ), + len += efi_file_read_chunk ( reader, &cpio, sizeof ( cpio ) ); - len += efi_file_read_chunk ( reader, - virt_to_user ( name ), - name_len ); - len += efi_file_read_chunk ( reader, UNULL, pad_len ); + len += efi_file_read_chunk ( reader, name, name_len ); + len += efi_file_read_chunk ( reader, NULL, pad_len ); } /* Read file data */ diff --git a/src/interface/hyperv/vmbus.c b/src/interface/hyperv/vmbus.c index 49ccf69c8..1c44cab5e 100644 --- a/src/interface/hyperv/vmbus.c +++ b/src/interface/hyperv/vmbus.c @@ -273,7 +273,7 @@ static int vmbus_negotiate_version ( struct hv_hypervisor *hv ) { * @v len Length of data buffer * @ret gpadl GPADL ID, or negative error */ -int vmbus_establish_gpadl ( struct vmbus_device *vmdev, userptr_t data, +int vmbus_establish_gpadl ( struct vmbus_device *vmdev, void *data, size_t len ) { struct hv_hypervisor *hv = vmdev->hv; struct vmbus *vmbus = hv->vmbus; @@ -442,7 +442,7 @@ int vmbus_open ( struct vmbus_device *vmdev, memset ( ring, 0, len ); /* Establish GPADL for ring buffer */ - gpadl = vmbus_establish_gpadl ( vmdev, virt_to_user ( ring ), len ); + gpadl = vmbus_establish_gpadl ( vmdev, ring, len ); if ( gpadl < 0 ) { rc = gpadl; goto err_establish; diff --git a/src/interface/linux/linux_acpi.c b/src/interface/linux/linux_acpi.c index a2a8bf12e..21a2e27cc 100644 --- a/src/interface/linux/linux_acpi.c +++ b/src/interface/linux/linux_acpi.c @@ -21,6 +21,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include #include +#include #include #include #include diff --git a/src/interface/linux/linux_smbios.c b/src/interface/linux/linux_smbios.c index a12c936ed..1450fcf1b 100644 --- a/src/interface/linux/linux_smbios.c +++ b/src/interface/linux/linux_smbios.c @@ -19,6 +19,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); +#include #include #include #include diff --git a/src/interface/linux/linux_sysfs.c b/src/interface/linux/linux_sysfs.c index cbb23d81d..321824ba9 100644 --- a/src/interface/linux/linux_sysfs.c +++ b/src/interface/linux/linux_sysfs.c @@ -42,8 +42,8 @@ FILE_LICENCE ( GPL2_OR_LATER ); * @v data Data to fill in * @ret len Length read, or negative error */ -int linux_sysfs_read ( const char *filename, userptr_t *data ) { - userptr_t tmp; +int linux_sysfs_read ( const char *filename, void **data ) { + void *tmp; ssize_t read; size_t len; int fd; @@ -59,7 +59,7 @@ int linux_sysfs_read ( const char *filename, userptr_t *data ) { } /* Read file */ - for ( *data = UNULL, len = 0 ; ; len += read ) { + for ( *data = NULL, len = 0 ; ; len += read ) { /* (Re)allocate space */ tmp = urealloc ( *data, ( len + LINUX_SYSFS_BLKSIZE ) ); diff --git a/src/tests/bofm_test.c b/src/tests/bofm_test.c index 829924887..dbef1eb90 100644 --- a/src/tests/bofm_test.c +++ b/src/tests/bofm_test.c @@ -26,7 +26,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include #include -#include #include #include #include @@ -111,7 +110,7 @@ void bofm_test ( struct pci_device *pci ) { printf ( "BOFMTEST performing harvest\n" ); bofmtab_harvest.en.busdevfn = pci->busdevfn; DBG_HDA ( 0, &bofmtab_harvest, sizeof ( bofmtab_harvest ) ); - bofmrc = bofm ( virt_to_user ( &bofmtab_harvest ), pci ); + bofmrc = bofm ( &bofmtab_harvest, pci ); printf ( "BOFMTEST harvest result %08x\n", bofmrc ); if ( bofmtab_harvest.en.options & BOFM_EN_HVST ) { printf ( "BOFMTEST harvested MAC address %s\n", @@ -125,7 +124,7 @@ void bofm_test ( struct pci_device *pci ) { printf ( "BOFMTEST performing update\n" ); bofmtab_update.en.busdevfn = pci->busdevfn; DBG_HDA ( 0, &bofmtab_update, sizeof ( bofmtab_update ) ); - bofmrc = bofm ( virt_to_user ( &bofmtab_update ), pci ); + bofmrc = bofm ( &bofmtab_update, pci ); printf ( "BOFMTEST update result %08x\n", bofmrc ); if ( bofmtab_update.en.options & BOFM_EN_CSM_SUCCESS ) { printf ( "BOFMTEST updated MAC address to %s\n", -- cgit v1.2.3-55-g7522 From 2742ed5d77e1dd6cdcf20800d2b43295874ac621 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 24 Apr 2025 16:35:49 +0100 Subject: [uaccess] Remove now-obsolete memchr_user() Signed-off-by: Michael Brown --- src/arch/x86/include/librm.h | 7 ------- src/arch/x86/transitions/librm_mgmt.c | 1 - src/core/uaccess.c | 1 - src/include/ipxe/linux/linux_uaccess.h | 6 ------ src/include/ipxe/uaccess.h | 34 ---------------------------------- src/interface/linux/linux_uaccess.c | 1 - 6 files changed, 50 deletions(-) (limited to 'src/interface/linux') diff --git a/src/arch/x86/include/librm.h b/src/arch/x86/include/librm.h index 7755abdcf..379b6d849 100644 --- a/src/arch/x86/include/librm.h +++ b/src/arch/x86/include/librm.h @@ -131,13 +131,6 @@ UACCESS_INLINE ( librm, virt_to_user ) ( volatile const void *addr ) { return trivial_virt_to_user ( addr ); } -static inline __always_inline off_t -UACCESS_INLINE ( librm, memchr_user ) ( userptr_t buffer, off_t offset, - int c, size_t len ) { - return trivial_memchr_user ( buffer, offset, c, len ); -} - - /****************************************************************************** * * Access to variables in .data16 and .text16 diff --git a/src/arch/x86/transitions/librm_mgmt.c b/src/arch/x86/transitions/librm_mgmt.c index e0679f0ff..5a6942825 100644 --- a/src/arch/x86/transitions/librm_mgmt.c +++ b/src/arch/x86/transitions/librm_mgmt.c @@ -431,7 +431,6 @@ void setup_sipi ( unsigned int vector, uint32_t handler, PROVIDE_UACCESS_INLINE ( librm, phys_to_virt ); PROVIDE_UACCESS_INLINE ( librm, virt_to_phys ); PROVIDE_UACCESS_INLINE ( librm, virt_to_user ); -PROVIDE_UACCESS_INLINE ( librm, memchr_user ); PROVIDE_IOMAP_INLINE ( pages, io_to_bus ); PROVIDE_IOMAP ( pages, ioremap, ioremap_pages ); PROVIDE_IOMAP ( pages, iounmap, iounmap_pages ); diff --git a/src/core/uaccess.c b/src/core/uaccess.c index 32bd1ac38..bf922f66d 100644 --- a/src/core/uaccess.c +++ b/src/core/uaccess.c @@ -35,4 +35,3 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); PROVIDE_UACCESS_INLINE ( flat, phys_to_virt ); PROVIDE_UACCESS_INLINE ( flat, virt_to_phys ); PROVIDE_UACCESS_INLINE ( flat, virt_to_user ); -PROVIDE_UACCESS_INLINE ( flat, memchr_user ); diff --git a/src/include/ipxe/linux/linux_uaccess.h b/src/include/ipxe/linux/linux_uaccess.h index b4f7e2fc6..7d5f5f642 100644 --- a/src/include/ipxe/linux/linux_uaccess.h +++ b/src/include/ipxe/linux/linux_uaccess.h @@ -62,10 +62,4 @@ UACCESS_INLINE ( linux, virt_to_user ) ( volatile const void *addr ) { return trivial_virt_to_user ( addr ); } -static inline __always_inline off_t -UACCESS_INLINE ( linux, memchr_user ) ( userptr_t buffer, off_t offset, - int c, size_t len ) { - return trivial_memchr_user ( buffer, offset, c, len ); -} - #endif /* _IPXE_LINUX_UACCESS_H */ diff --git a/src/include/ipxe/uaccess.h b/src/include/ipxe/uaccess.h index 62030dd8a..d0c6882ed 100644 --- a/src/include/ipxe/uaccess.h +++ b/src/include/ipxe/uaccess.h @@ -51,23 +51,6 @@ trivial_virt_to_user ( volatile const void *addr ) { return ( ( userptr_t ) addr ); } -/** - * Find character in user buffer - * - * @v buffer User buffer - * @v offset Starting offset within buffer - * @v c Character to search for - * @v len Length of user buffer - * @ret offset Offset of character, or <0 if not found - */ -static inline __always_inline off_t -trivial_memchr_user ( userptr_t buffer, off_t offset, int c, size_t len ) { - void *found; - - found = memchr ( ( ( void * ) buffer + offset ), c, len ); - return ( found ? ( found - ( void * ) buffer ) : -1 ); -} - /** @} */ /** @@ -114,12 +97,6 @@ UACCESS_INLINE ( flat, virt_to_user ) ( volatile const void *addr ) { return trivial_virt_to_user ( addr ); } -static inline __always_inline off_t -UACCESS_INLINE ( flat, memchr_user ) ( userptr_t buffer, off_t offset, - int c, size_t len ) { - return trivial_memchr_user ( buffer, offset, c, len ); -} - /* Include all architecture-independent user access API headers */ #include @@ -179,15 +156,4 @@ copy_from_user ( void *dest, userptr_t src, off_t src_off, size_t len ) { memcpy ( dest, ( src + src_off ), len ); } -/** - * Find character in user buffer - * - * @v userptr User buffer - * @v offset Starting offset within buffer - * @v c Character to search for - * @v len Length of user buffer - * @ret offset Offset of character, or <0 if not found - */ -off_t memchr_user ( userptr_t userptr, off_t offset, int c, size_t len ); - #endif /* _IPXE_UACCESS_H */ diff --git a/src/interface/linux/linux_uaccess.c b/src/interface/linux/linux_uaccess.c index 4fdd8c03a..436707757 100644 --- a/src/interface/linux/linux_uaccess.c +++ b/src/interface/linux/linux_uaccess.c @@ -30,4 +30,3 @@ FILE_LICENCE(GPL2_OR_LATER); PROVIDE_UACCESS_INLINE(linux, phys_to_virt); PROVIDE_UACCESS_INLINE(linux, virt_to_phys); PROVIDE_UACCESS_INLINE(linux, virt_to_user); -PROVIDE_UACCESS_INLINE(linux, memchr_user); -- cgit v1.2.3-55-g7522 From 024439f3393e5c8335036efb898116b6500b3426 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sun, 27 Apr 2025 23:28:51 +0100 Subject: [linux] Add missing return statement to linux_poll() Signed-off-by: Michael Brown --- src/interface/linux/linux_api.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/interface/linux') diff --git a/src/interface/linux/linux_api.c b/src/interface/linux/linux_api.c index 21024ede1..459e39fd5 100644 --- a/src/interface/linux/linux_api.c +++ b/src/interface/linux/linux_api.c @@ -225,6 +225,7 @@ int __asmcall linux_poll ( struct pollfd *fds, unsigned int nfds, ret = poll ( fds, nfds, timeout ); if ( ret == -1 ) linux_errno = errno; + return ret; } /** -- cgit v1.2.3-55-g7522 From 1534b0a6e9545d3a75ef6ca7cf0e4d89704582a2 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Wed, 30 Apr 2025 16:07:04 +0100 Subject: [uaccess] Remove redundant virt_to_user() and userptr_t Remove the last remaining traces of the concept of a user pointer, leaving iPXE with a simpler and cleaner memory model that implicitly assumes that all memory locations can be reached through pointer dereferences. Signed-off-by: Michael Brown --- src/arch/x86/include/librm.h | 5 ---- src/arch/x86/transitions/librm_mgmt.c | 1 - src/core/uaccess.c | 1 - src/include/ipxe/linux/linux_uaccess.h | 8 ------- src/include/ipxe/uaccess.h | 42 ---------------------------------- src/interface/linux/linux_uaccess.c | 1 - 6 files changed, 58 deletions(-) (limited to 'src/interface/linux') diff --git a/src/arch/x86/include/librm.h b/src/arch/x86/include/librm.h index 22b7e3933..4fce7e8c8 100644 --- a/src/arch/x86/include/librm.h +++ b/src/arch/x86/include/librm.h @@ -126,11 +126,6 @@ UACCESS_INLINE ( librm, virt_to_phys ) ( volatile const void *virt ) { return ( addr + virt_offset ); } -static inline __always_inline userptr_t -UACCESS_INLINE ( librm, virt_to_user ) ( volatile const void *addr ) { - return trivial_virt_to_user ( addr ); -} - /****************************************************************************** * * Access to variables in .data16 and .text16 diff --git a/src/arch/x86/transitions/librm_mgmt.c b/src/arch/x86/transitions/librm_mgmt.c index da5055cd8..14e00eda8 100644 --- a/src/arch/x86/transitions/librm_mgmt.c +++ b/src/arch/x86/transitions/librm_mgmt.c @@ -431,7 +431,6 @@ void setup_sipi ( unsigned int vector, uint32_t handler, PROVIDE_UACCESS_INLINE ( librm, phys_to_virt ); PROVIDE_UACCESS_INLINE ( librm, virt_to_phys ); -PROVIDE_UACCESS_INLINE ( librm, virt_to_user ); PROVIDE_IOMAP_INLINE ( pages, io_to_bus ); PROVIDE_IOMAP ( pages, ioremap, ioremap_pages ); PROVIDE_IOMAP ( pages, iounmap, iounmap_pages ); diff --git a/src/core/uaccess.c b/src/core/uaccess.c index bf922f66d..e73f4d7fb 100644 --- a/src/core/uaccess.c +++ b/src/core/uaccess.c @@ -34,4 +34,3 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); /* Flat address space user access API */ PROVIDE_UACCESS_INLINE ( flat, phys_to_virt ); PROVIDE_UACCESS_INLINE ( flat, virt_to_phys ); -PROVIDE_UACCESS_INLINE ( flat, virt_to_user ); diff --git a/src/include/ipxe/linux/linux_uaccess.h b/src/include/ipxe/linux/linux_uaccess.h index 7d5f5f642..a5d7d73f3 100644 --- a/src/include/ipxe/linux/linux_uaccess.h +++ b/src/include/ipxe/linux/linux_uaccess.h @@ -5,9 +5,6 @@ * * iPXE user access API for Linux * - * We run with no distinction between internal and external addresses, - * so can use trivial_virt_to_user() et al. - * * We have no concept of the underlying physical addresses, since * these are not exposed to userspace. We provide a stub * implementation of virt_to_phys() since this is required by @@ -57,9 +54,4 @@ UACCESS_INLINE ( linux, phys_to_virt ) ( physaddr_t phys ) { return ( ( void * ) phys ); } -static inline __always_inline userptr_t -UACCESS_INLINE ( linux, virt_to_user ) ( volatile const void *addr ) { - return trivial_virt_to_user ( addr ); -} - #endif /* _IPXE_LINUX_UACCESS_H */ diff --git a/src/include/ipxe/uaccess.h b/src/include/ipxe/uaccess.h index 82f29f793..8d93cbf4f 100644 --- a/src/include/ipxe/uaccess.h +++ b/src/include/ipxe/uaccess.h @@ -20,35 +20,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define UACCESS_PREFIX_flat __flat_ #endif -/** - * A pointer to a user buffer - * - */ -typedef void * userptr_t; - -/** - * @defgroup uaccess_trivial Trivial user access API implementations - * - * User access API implementations that can be used by environments in - * which virtual addresses allow access to all of memory. - * - * @{ - * - */ - -/** - * Convert virtual address to user pointer - * - * @v addr Virtual address - * @ret userptr User pointer - */ -static inline __always_inline userptr_t -trivial_virt_to_user ( volatile const void *addr ) { - return ( ( userptr_t ) addr ); -} - -/** @} */ - /** * Calculate static inline user access API function name * @@ -88,25 +59,12 @@ UACCESS_INLINE ( flat, virt_to_phys ) ( volatile const void *virt ) { return ( ( physaddr_t ) virt ); } -static inline __always_inline userptr_t -UACCESS_INLINE ( flat, virt_to_user ) ( volatile const void *addr ) { - return trivial_virt_to_user ( addr ); -} - /* Include all architecture-independent user access API headers */ #include /* Include all architecture-dependent user access API headers */ #include -/** - * Convert virtual address to user pointer - * - * @v addr Virtual address - * @ret userptr User pointer - */ -userptr_t virt_to_user ( volatile const void *addr ); - /** * Convert virtual address to a physical address * diff --git a/src/interface/linux/linux_uaccess.c b/src/interface/linux/linux_uaccess.c index 436707757..7f7f8931b 100644 --- a/src/interface/linux/linux_uaccess.c +++ b/src/interface/linux/linux_uaccess.c @@ -29,4 +29,3 @@ FILE_LICENCE(GPL2_OR_LATER); PROVIDE_UACCESS_INLINE(linux, phys_to_virt); PROVIDE_UACCESS_INLINE(linux, virt_to_phys); -PROVIDE_UACCESS_INLINE(linux, virt_to_user); -- cgit v1.2.3-55-g7522