From b80fd10a70dee842834c5305965c3bfdef0bd7a5 Mon Sep 17 00:00:00 2001 From: Christian Helmuth Date: Wed, 6 Dec 2023 08:57:47 +0100 Subject: [PATCH] wireguard: don't shadow lx_emul memory backend Issue #4809 --- .../lib/mk/wireguard_lx_inc_dirs.inc | 8 - repos/dde_linux/src/app/wireguard/dep.list | 1 + .../src/app/wireguard/lx_emul/alloc.cc | 84 --------- .../src/app/wireguard/lx_kit/memory.cc | 171 ------------------ .../wireguard/spec/x86_64/generated_dummies.c | 28 +-- .../src/app/wireguard/spec/x86_64/source.list | 5 + 6 files changed, 7 insertions(+), 290 deletions(-) delete mode 100644 repos/dde_linux/src/app/wireguard/lx_emul/alloc.cc delete mode 100644 repos/dde_linux/src/app/wireguard/lx_kit/memory.cc diff --git a/repos/dde_linux/lib/mk/wireguard_lx_inc_dirs.inc b/repos/dde_linux/lib/mk/wireguard_lx_inc_dirs.inc index 24a9be102c..7d3c862518 100644 --- a/repos/dde_linux/lib/mk/wireguard_lx_inc_dirs.inc +++ b/repos/dde_linux/lib/mk/wireguard_lx_inc_dirs.inc @@ -26,14 +26,6 @@ INC_DIR += $(GEN_PRG_DIR) LIBS += virt_lx_emul virt_linux_generated -# -# We shadow some files of lx_emul and lx_kit in order to locally apply -# modifications. -# - -vpath lx_emul/alloc.cc $(GEN_PRG_DIR) -vpath lx_kit/memory.cc $(GEN_PRG_DIR) - # # Some local files include linux headers that expect the KBUILD_* symbols to # be defined. However, the lx_emul mechanism for adding the definitions doesn't diff --git a/repos/dde_linux/src/app/wireguard/dep.list b/repos/dde_linux/src/app/wireguard/dep.list index 25f10824c5..2b620356e8 100644 --- a/repos/dde_linux/src/app/wireguard/dep.list +++ b/repos/dde_linux/src/app/wireguard/dep.list @@ -427,6 +427,7 @@ include/linux/cacheflush.h include/linux/capability.h include/linux/cc_platform.h include/linux/cdev.h +include/linux/cfi_types.h include/linux/cgroup-defs.h include/linux/cgroup.h include/linux/cgroup_api.h diff --git a/repos/dde_linux/src/app/wireguard/lx_emul/alloc.cc b/repos/dde_linux/src/app/wireguard/lx_emul/alloc.cc deleted file mode 100644 index 1458d18fe1..0000000000 --- a/repos/dde_linux/src/app/wireguard/lx_emul/alloc.cc +++ /dev/null @@ -1,84 +0,0 @@ -/* - * \brief This file shadows repos/dde_linux/src/lib/lx_emul/alloc.cc - * \author Martin Stein - * \author Stefan Kalkowski - * \date 2021-03-22 - */ - -/* - * Copyright (C) 2021 Genode Labs GmbH - * - * This file is distributed under the terms of the GNU General Public License - * version 2. - */ - -#include -#include -#include -#include -#include - -extern "C" void * lx_emul_mem_alloc_aligned(unsigned long size, unsigned long align) -{ - void * const ptr = Lx_kit::env().memory.alloc(size, align); - return ptr; -}; - - -extern "C" void * lx_emul_mem_alloc_aligned_uncached(unsigned long size, - unsigned long align) -{ - void * const ptr = Lx_kit::env().uncached_memory.alloc(size, align); - return ptr; -}; - - -extern "C" unsigned long lx_emul_mem_dma_addr(void * addr) -{ - return (unsigned long)addr; -} - - -extern "C" unsigned long lx_emul_mem_virt_addr(void * dma_addr) -{ - return (unsigned long)dma_addr; -} - - -extern "C" void lx_emul_mem_free(const void * ptr) -{ - if (!ptr) - return; - if (Lx_kit::env().memory.free(ptr)) - return; - if (Lx_kit::env().uncached_memory.free(ptr)) - return; - Genode::error(__func__, " called with invalid ptr ", ptr); -}; - - -extern "C" unsigned long lx_emul_mem_size(const void * ptr) -{ - unsigned long ret = 0; - if (!ptr) - return ret; - if ((ret = Lx_kit::env().memory.size(ptr))) - return ret; - if (!(ret = Lx_kit::env().uncached_memory.size(ptr))) - Genode::error(__func__, " called with invalid ptr ", ptr); - return ret; -}; - - -extern "C" void lx_emul_mem_cache_clean_invalidate(const void * addr, - unsigned long size) -{ - Genode::cache_clean_invalidate_data((Genode::addr_t)addr, size); -} - - -extern "C" void lx_emul_mem_cache_invalidate(const void * addr, - unsigned long size) -{ - Genode::cache_invalidate_data((Genode::addr_t)addr, size); -} diff --git a/repos/dde_linux/src/app/wireguard/lx_kit/memory.cc b/repos/dde_linux/src/app/wireguard/lx_kit/memory.cc deleted file mode 100644 index df48c99a8f..0000000000 --- a/repos/dde_linux/src/app/wireguard/lx_kit/memory.cc +++ /dev/null @@ -1,171 +0,0 @@ -/* - * \brief This file shadows repos/dde_linux/src/lib/lx_kit/memory.cc - * \author Martin Stein - * \author Stefan Kalkowski - * \date 2021-03-25 - */ - -/* - * Copyright (C) 2021 Genode Labs GmbH - * - * This file is distributed under the terms of the GNU General Public License - * version 2. - */ - -/* Genode includes */ -#include - -/* local includes */ -#include -#include -#include -#include - - -void Lx_kit::Mem_allocator::free_buffer(void * addr) -{ - Buffer * buffer = nullptr; - - _virt_to_dma.apply(Buffer_info::Query_addr(addr), - [&] (Buffer_info const & info) { - buffer = &info.buffer; - }); - - if (!buffer) { - warning(__func__, ": no memory buffer for addr: ", addr, " found"); - return; - } - - void const * virt_addr = (void const *)buffer->virt_addr(); - void const * dma_addr = (void const *)buffer->dma_addr(); - - _virt_to_dma.remove(Buffer_info::Query_addr(virt_addr)); - _dma_to_virt.remove(Buffer_info::Query_addr(dma_addr)); - - destroy(_heap, buffer); -} - - -Genode::Dataspace_capability Lx_kit::Mem_allocator::attached_dataspace_cap(void * addr) -{ - Genode::Dataspace_capability ret { }; - - _virt_to_dma.apply(Buffer_info::Query_addr(addr), - [&] (Buffer_info const & info) { - ret = info.buffer.cap(); - }); - - return ret; -} - - -void * Lx_kit::Mem_allocator::alloc(size_t size, size_t align) -{ - if (!size) - return nullptr; - - return _mem.alloc_aligned(size, (unsigned)log2(align)).convert( - - [&] (void *ptr) { - memset(ptr, 0, size); - return ptr; }, - - [&] (Range_allocator::Alloc_error) { - - /* - * Restrict the minimum buffer size to avoid the creation of - * a separate dataspaces for tiny allocations. - */ - size_t const min_buffer_size = 256*1024; - - /* - * Allocate one excess byte that is not officially registered at - * the '_mem' ranges. This way, two virtual consecutive ranges - * (that must be assumed to belong to non-contiguous physical - * ranges) can never be merged when freeing an allocation. Such - * a merge would violate the assumption that a both the virtual - * and physical addresses of a multi-page allocation are always - * contiguous. - */ - Buffer & buffer = alloc_buffer(max(size + 1, min_buffer_size)); - - _mem.add_range(buffer.virt_addr(), buffer.size() - 1); - - lx_emul_forget_pages((void*)buffer.virt_addr(), buffer.size()); - lx_emul_virt_to_pages((void*)buffer.virt_addr(), (buffer.size() + 0xfff) >> 12); - - /* re-try allocation */ - return _mem.alloc_aligned(size, (unsigned)log2(align)).convert( - - [&] (void *ptr) { - memset(ptr, 0, size); - return ptr; }, - - [&] (Range_allocator::Alloc_error) -> void * { - error("memory allocation failed for ", size, " align ", align); - return nullptr; } - ); - } - ); -} - - -Genode::addr_t Lx_kit::Mem_allocator::dma_addr(void * addr) -{ - addr_t ret = 0UL; - - _virt_to_dma.apply(Buffer_info::Query_addr(addr), - [&] (Buffer_info const & info) { - addr_t const offset = (addr_t)addr - info.buffer.virt_addr(); - ret = info.buffer.dma_addr() + offset; - }); - - return ret; -} - - -Genode::addr_t Lx_kit::Mem_allocator::virt_addr(void * dma_addr) -{ - addr_t ret = 0UL; - - _dma_to_virt.apply(Buffer_info::Query_addr(dma_addr), - [&] (Buffer_info const & info) { - addr_t const offset = (addr_t)dma_addr - info.buffer.dma_addr(); - ret = info.buffer.virt_addr() + offset; - }); - - return ret; -} - - -bool Lx_kit::Mem_allocator::free(const void * ptr) -{ - if (!_mem.valid_addr((addr_t)ptr)) - return false; - - using Size_at_error = Allocator_avl::Size_at_error; - - _mem.size_at(ptr).with_result( - [&] (size_t) { _mem.free(const_cast(ptr)); }, - [ ] (Size_at_error) { }); - - return true; -} - - -Genode::size_t Lx_kit::Mem_allocator::size(const void * ptr) -{ - if (!ptr) return 0; - - using Size_at_error = Allocator_avl::Size_at_error; - - return _mem.size_at(ptr).convert([ ] (size_t s) { return s; }, - [ ] (Size_at_error) { return 0U; }); -} - - -Lx_kit::Mem_allocator::Mem_allocator(Genode::Env & env, - Heap & heap, - Platform::Connection & platform, - Cache cache_attr) -: _env(env), _heap(heap), _platform(platform), _cache_attr(cache_attr) {} diff --git a/repos/dde_linux/src/app/wireguard/spec/x86_64/generated_dummies.c b/repos/dde_linux/src/app/wireguard/spec/x86_64/generated_dummies.c index 87ab89cdbb..4b4fd55d0c 100644 --- a/repos/dde_linux/src/app/wireguard/spec/x86_64/generated_dummies.c +++ b/repos/dde_linux/src/app/wireguard/spec/x86_64/generated_dummies.c @@ -1,7 +1,7 @@ /* * \brief Dummy definitions of Linux Kernel functions * \author Automatically generated file - do no edit - * \date 2023-03-27 + * \date 2023-12-06 */ #include @@ -250,16 +250,6 @@ bool gfp_pfmemalloc_allowed(gfp_t gfp_mask) const u8 guid_index[16] = {}; -#include - -const char hex_asc[] = {}; - - -#include - -const char hex_asc_upper[] = {}; - - #include void icmp6_send(struct sk_buff * skb,u8 type,u8 code,__u32 info,const struct in6_addr * force_saddr,const struct inet6_skb_parm * parm) @@ -493,14 +483,6 @@ void skb_set_owner_w(struct sk_buff * skb,struct sock * sk) } -#include - -char * skip_spaces(const char * str) -{ - lx_emul_trace_and_stop(__func__); -} - - #include void smp_call_function_many(const struct cpumask * mask,smp_call_func_t func,void * info,bool wait) @@ -530,14 +512,6 @@ void sock_edemux(struct sk_buff * skb) bool static_key_initialized; -#include - -int string_escape_mem(const char * src,size_t isz,char * dst,size_t osz,unsigned int flags,const char * only) -{ - lx_emul_trace_and_stop(__func__); -} - - #include bool timerqueue_add(struct timerqueue_head * head,struct timerqueue_node * node) diff --git a/repos/dde_linux/src/app/wireguard/spec/x86_64/source.list b/repos/dde_linux/src/app/wireguard/spec/x86_64/source.list index 87050eb743..86793dd88f 100644 --- a/repos/dde_linux/src/app/wireguard/spec/x86_64/source.list +++ b/repos/dde_linux/src/app/wireguard/spec/x86_64/source.list @@ -8,6 +8,9 @@ arch/x86/crypto/curve25519-x86_64.c arch/x86/crypto/poly1305-x86_64-cryptogams.pl arch/x86/crypto/poly1305_glue.c arch/x86/lib/hweight.S +arch/x86/lib/memcpy_64.S +arch/x86/lib/memmove_64.S +arch/x86/lib/memset_64.S crypto/algapi.c crypto/api.c crypto/scatterwalk.c @@ -61,6 +64,7 @@ lib/crypto/memneq.c lib/crypto/utils.c lib/ctype.c lib/find_bit.c +lib/hexdump.c lib/idr.c lib/nlattr.c lib/radix-tree.c @@ -68,6 +72,7 @@ lib/refcount.c lib/scatterlist.c lib/siphash.c lib/string.c +lib/string_helpers.c lib/vsprintf.c lib/xarray.c net/core/dst.c