wireguard: don't shadow lx_emul memory backend

Issue #4809
This commit is contained in:
Christian Helmuth 2023-12-06 08:57:47 +01:00 committed by Norman Feske
parent 1e7116fcc1
commit b80fd10a70
6 changed files with 7 additions and 290 deletions

View File

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

View File

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

View File

@ -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 <base/log.h>
#include <cpu/cache.h>
#include <lx_emul/alloc.h>
#include <lx_emul/page_virt.h>
#include <lx_kit/env.h>
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);
}

View File

@ -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 <base/log.h>
/* local includes */
#include <lx_kit/memory.h>
#include <lx_kit/map.h>
#include <lx_kit/byte_range.h>
#include <lx_emul/page_virt.h>
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 *>(
[&] (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 *>(
[&] (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<void*>(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>([ ] (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) {}

View File

@ -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 <lx_emul.h>
@ -250,16 +250,6 @@ bool gfp_pfmemalloc_allowed(gfp_t gfp_mask)
const u8 guid_index[16] = {};
#include <linux/kernel.h>
const char hex_asc[] = {};
#include <linux/kernel.h>
const char hex_asc_upper[] = {};
#include <linux/icmpv6.h>
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 <linux/string.h>
char * skip_spaces(const char * str)
{
lx_emul_trace_and_stop(__func__);
}
#include <linux/smp.h>
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 <linux/string_helpers.h>
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 <linux/timerqueue.h>
bool timerqueue_add(struct timerqueue_head * head,struct timerqueue_node * node)

View File

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