[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 <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2025-04-21 16:16:01 +01:00
parent 4535548cba
commit 8c31270a21
48 changed files with 211 additions and 235 deletions

View File

@@ -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

View File

@@ -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 <bits/uaccess.h>
/**
* 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