Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCM_RIGHTS #146

Merged
merged 55 commits into from
Jan 31, 2025
Merged
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
50b7a9b
tty: Switch to tty_ops instead of embedded function pointers
heatd Dec 3, 2024
5eed4ad
apic: Fix acpi LAPIC enumeration on certain systems
heatd Dec 4, 2024
0919987
efi: Fix memory map creation before SVAM
heatd Dec 4, 2024
68c5ef2
cred: Inherit saved uid and gid
heatd Dec 4, 2024
033a677
cred: Fix setgroups crashes when clearing it
heatd Dec 4, 2024
901d48b
nvme: Don't enable MSI
heatd Dec 4, 2024
efd96d0
pagealloc: WARN_ON order > MAX_ORDER
heatd Dec 4, 2024
a3b0c8c
rlimit: Allow lowering the maximum rlimit for unpriv users
heatd Dec 5, 2024
176d3fc
loopback: Stop softirqs from hogging the CPU
heatd Dec 5, 2024
c995cd9
tcp: Add new tcp stack
heatd Dec 7, 2024
2ff1f01
dev: Add dev_printk and bus_printk helpers
heatd Dec 7, 2024
3038880
pci: Add MSI-X support (and revamp irq allocation)
heatd Dec 7, 2024
feb5c29
nvme: Add MSI-X vector support
heatd Dec 7, 2024
2eb5316
irq: Call all IRQ handlers on irq
heatd Dec 7, 2024
b110f4d
cmdline: Remove debug printk
heatd Dec 7, 2024
e3b335c
bio: Fix error code when bio_bounce fails
heatd Dec 7, 2024
12b7878
vfs: Refactor file_ops out into other structs
heatd Dec 14, 2024
140975c
af_unix: Fix un_get_name
heatd Dec 14, 2024
e8387ce
sched: Add sched_getaffinity and sched_setaffinity
heatd Dec 14, 2024
0b3ba0b
signal: Bail if no signal is found on sigtimedwait wakeup
heatd Dec 14, 2024
77d0a6c
ext2: Keep going on getdirent when we find an unused entry
heatd Dec 14, 2024
0bfd167
utimensat: Fix UTIME_NOW
heatd Dec 14, 2024
3d472a9
reclaim: Remove erroneous DCHECK_PAGE on writeback
heatd Dec 14, 2024
ac08bca
tty: Various fixes and write_room support
heatd Dec 14, 2024
6461019
unix: Add SCM_RIGHTS support
heatd Jul 10, 2024
7569312
net_tests: SCM_RIGHTS tests
heatd Jul 10, 2024
4018866
dentry: Fix d_invalidate
heatd Dec 24, 2024
c6e5c3a
vfs: Change inode_operations->stat and ->link's prototypes
heatd Dec 24, 2024
c0867b3
clock: Add extern "C"
heatd Dec 24, 2024
32f9621
iovec_iter: Add extern "C"
heatd Dec 24, 2024
30ee5cc
d_path: Fix going up mounts when mounts are stacked
heatd Dec 24, 2024
ad91596
libfs: Add libfs_put_dots and put_dir definitions
heatd Dec 24, 2024
f21a7ff
sched: Fix sched_lock
heatd Jan 19, 2025
a2df429
madvise: Fix iteration when start != vma start
heatd Jan 21, 2025
6dc28b0
pid: Rework pids and pid management
heatd Jan 21, 2025
2573d2d
mm: Add active_mm and rework mm's
heatd Jan 21, 2025
28ff45c
unix: Fix SCM_RIGHTS fd passing
heatd Jan 21, 2025
b48dda6
namei: Set namedata.dirfd in path_openat
heatd Jan 21, 2025
3107407
futex: Handle FUTEX_WAITs page faulting
heatd Jan 21, 2025
a3d3fe8
tcp: Fix SACK option parsing
heatd Jan 21, 2025
307a77e
proc: Add procfs
heatd Jan 21, 2025
7b581f6
slab: Add /proc/slabinfo
heatd Jan 21, 2025
550b7eb
ci: Install xorriso
heatd Jan 21, 2025
5cca869
musl: Update musl submodule
heatd Jan 21, 2025
fe68dc0
inet: Fix getsockname and getpeername for inet sockets
heatd Jan 25, 2025
4307b5d
slab: Fix ASAN reports on direct map caches
heatd Jan 25, 2025
52ba4a7
ubsan: Make printks pr_err
heatd Jan 25, 2025
ad87218
vector: Dont call ilog2 when size = 0
heatd Jan 25, 2025
a5486b2
tcp: Add sndbuf accounting
heatd Jan 25, 2025
c4b50d9
tcp: Add receive buffer accounting
heatd Jan 27, 2025
a883bd8
github: Install gn from apt
heatd Jan 27, 2025
ae2c219
tcp: Fix initial window handling when listening
heatd Jan 27, 2025
19a6caa
tcp: Fix send window checks
heatd Jan 28, 2025
4098752
tcp: Fix snd_next adjustments
heatd Jan 29, 2025
6838c3a
tcp: Add SIGPIPE on sendmsg for a broken connection
heatd Jan 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
mm: Add active_mm and rework mm's
mm_address_space now has two decoupled refcounts, as with Linux.
active_mm is used to delay TLB flushing when switching to kernel
threads. They keep a ref (mm_count) which holds the top level
pgd (any kernel mappings) and the mm_address_space in place.
User-level mappings are wiped out when mm_users = 0. Also make vm.cpp ->
vm.c

Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com>
heatd committed Jan 31, 2025
commit 2573d2de5a7bd7b7c65fb7677ceeab6012f4e5ec
5 changes: 3 additions & 2 deletions kernel/arch/riscv64/mmu.cpp
Original file line number Diff line number Diff line change
@@ -451,11 +451,12 @@ void riscv_invalidate_tlb(void *context)
auto addr = info->addr;
auto pages = info->pages;
auto addr_space = info->mm;
struct mm_address_space *mm;

auto curr_thread = get_current_thread();
mm = curr_thread->active_mm ?: curr_thread->aspace;

if (is_higher_half(addr) ||
(curr_thread->owner && curr_thread->owner->get_aspace() == addr_space))
if (is_higher_half(addr) || mm == addr_space)
{
paging_invalidate((void *) addr, pages);
add_per_cpu(tlb_nr_invals, 1);
1 change: 1 addition & 0 deletions kernel/arch/riscv64/stubs.cpp
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
* SPDX-License-Identifier: GPL-2.0-only
*/

#include <onyx/arch.h>
#include <onyx/irq.h>
#include <onyx/ktrace.h>
#include <onyx/panic.h>
21 changes: 14 additions & 7 deletions kernel/arch/riscv64/syscall_table.json
Original file line number Diff line number Diff line change
@@ -180,7 +180,8 @@
"offset"
]
],
"return_type": "void *"
"return_type": "void *",
"abi": "c"
},
{
"name": "munmap",
@@ -196,7 +197,8 @@
"length"
]
],
"return_type": "int"
"return_type": "int",
"abi": "c"
},
{
"name": "mprotect",
@@ -216,7 +218,8 @@
"prot"
]
],
"return_type": "int"
"return_type": "int",
"abi": "c"
},
{
"name": "mount",
@@ -277,7 +280,8 @@
"addr"
]
],
"return_type": "uint64_t"
"return_type": "uint64_t",
"abi": "c"
},
{
"name": "kill",
@@ -608,7 +612,8 @@
"new_address"
]
],
"return_type": "void *"
"return_type": "void *",
"abi": "c"
},
{
"name": "sigreturn",
@@ -847,7 +852,8 @@
"memstat"
]
],
"return_type": "int"
"return_type": "int",
"abi": "c"
},
{
"name": "chdir",
@@ -2594,7 +2600,8 @@
"flags"
]
],
"return_type": "int"
"return_type": "int",
"abi": "c"
},
{
"name": "statfs",
2 changes: 2 additions & 0 deletions kernel/arch/x86_64/code_patch.cpp
Original file line number Diff line number Diff line change
@@ -12,6 +12,8 @@
#include <onyx/smp.h>
#include <onyx/x86/control_regs.h>

#include <onyx/atomic.hpp>

namespace code_patch
{

2 changes: 1 addition & 1 deletion kernel/arch/x86_64/isr.cpp
Original file line number Diff line number Diff line change
@@ -225,7 +225,7 @@ void stack_segment_fault(struct registers *ctx)
#ifdef CONFIG_VERBOSE_SEGV
#undef REQUIRES_SHARED
#define REQUIRES_SHARED(...)
vm_area_struct *vm_search(struct mm_address_space *mm, void *addr, size_t length)
extern "C" vm_area_struct *vm_search(struct mm_address_space *mm, void *addr, size_t length)
REQUIRES_SHARED(mm->vm_lock);

#define dumpprint printk
7 changes: 5 additions & 2 deletions kernel/arch/x86_64/mmu.cpp
Original file line number Diff line number Diff line change
@@ -679,10 +679,13 @@ void x86_invalidate_tlb(void *context)
auto addr = info->addr;
auto pages = info->pages;
auto addr_space = info->mm;

struct mm_address_space *mm = NULL;
auto curr_thread = get_current_thread();

if (is_higher_half(addr) || (curr_thread->owner && curr_thread->get_aspace() == addr_space))
if (curr_thread)
mm = curr_thread->active_mm ?: curr_thread->aspace;

if (is_higher_half(addr) || mm == addr_space)
{
paging_invalidate((void *) addr, pages);
add_per_cpu(tlb_nr_invals, 1);
21 changes: 14 additions & 7 deletions kernel/arch/x86_64/syscall_table.json
Original file line number Diff line number Diff line change
@@ -180,7 +180,8 @@
"offset"
]
],
"return_type": "void *"
"return_type": "void *",
"abi": "c"
},
{
"name": "munmap",
@@ -196,7 +197,8 @@
"length"
]
],
"return_type": "int"
"return_type": "int",
"abi": "c"
},
{
"name": "mprotect",
@@ -216,7 +218,8 @@
"prot"
]
],
"return_type": "int"
"return_type": "int",
"abi": "c"
},
{
"name": "mount",
@@ -277,7 +280,8 @@
"addr"
]
],
"return_type": "uint64_t"
"return_type": "uint64_t",
"abi": "c"
},
{
"name": "kill",
@@ -608,7 +612,8 @@
"new_address"
]
],
"return_type": "void *"
"return_type": "void *",
"abi": "c"
},
{
"name": "sigreturn",
@@ -863,7 +868,8 @@
"memstat"
]
],
"return_type": "int"
"return_type": "int",
"abi": "c"
},
{
"name": "chdir",
@@ -2638,7 +2644,8 @@
"flags"
]
],
"return_type": "int"
"return_type": "int",
"abi": "c"
},
{
"name": "statfs",
16 changes: 9 additions & 7 deletions kernel/drivers/firmware/efi/efi.cpp
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@

#include <stdio.h>

#include <onyx/err.h>
#include <onyx/mm/slab.h>
#include <onyx/process.h>
#include <onyx/utf8.h>
@@ -17,7 +18,7 @@

#include <efi/efi.h>

static ref_guard<mm_address_space> efi_aspace;
static mm_address_space *efi_aspace;

namespace efi::internal
{
@@ -37,7 +38,7 @@ class efi_guard
public:
efi_guard()
{
old_aspace = vm_set_aspace(efi_aspace.get());
old_aspace = vm_set_aspace(efi_aspace);
}

EFI_SYSTEM_TABLE *system_table() const
@@ -96,8 +97,8 @@ void efi_remap_efi_region(EFI_MEMORY_DESCRIPTOR &desc)

auto flags = efi_memory_desc_flags_to_vm(desc.Attribute);
auto ptr =
__map_pages_to_vaddr(efi_aspace.get(), (void *) desc.PhysicalStart,
(void *) desc.PhysicalStart, desc.NumberOfPages << PAGE_SHIFT, flags);
__map_pages_to_vaddr(efi_aspace, (void *) desc.PhysicalStart, (void *) desc.PhysicalStart,
desc.NumberOfPages << PAGE_SHIFT, flags);
desc.VirtualStart = desc.PhysicalStart;
if (!ptr && !mapping_over_null)
panic("Failed to map EFI region [%016lx, %016lx] attributes %016lx\n", desc.PhysicalStart,
@@ -115,7 +116,7 @@ void efi_remap_efi_region(EFI_MEMORY_DESCRIPTOR &desc)
*/
void efi_quirk_map_zero_region()
{
__map_pages_to_vaddr(efi_aspace.get(), nullptr, nullptr, PAGE_SIZE, VM_READ | VM_NOFLUSH);
__map_pages_to_vaddr(efi_aspace, nullptr, nullptr, PAGE_SIZE, VM_READ | VM_NOFLUSH);
}

/**
@@ -140,7 +141,7 @@ static void efi_print_info()

static void efi_dump_mem_desc(const EFI_MEMORY_DESCRIPTOR *desc)
{
pr_debug(
pr_warn(
"Descriptor type %u physical start %lx virtual start %lx nr_pages %lx attributes %08lx\n",
desc->Type, desc->PhysicalStart, desc->VirtualStart, desc->NumberOfPages, desc->Attribute);
}
@@ -198,7 +199,8 @@ void efi_init(EFI_SYSTEM_TABLE *system_table, EFI_MEMORY_DESCRIPTOR *descriptors
efi_set_enabled();

efi::internal::system_table = system_table;
efi_aspace = mm_address_space::create().unwrap();
efi_aspace = mm_create();
CHECK(!IS_ERR(efi_aspace));
// EFI firmware out in the wild frequently "accidentally" touch NULL,
// such that we need to map NULL
efi_quirk_map_zero_region();
1 change: 1 addition & 0 deletions kernel/drivers/net/rtl8168/rtl8168.cpp
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
#include <onyx/driver.h>
#include <onyx/net/ethernet.h>
#include <onyx/net/netif.h>
#include <onyx/refcount.h>
#include <onyx/wait_queue.h>

#include <pci/pci.h>
2 changes: 2 additions & 0 deletions kernel/include/onyx/arch.h
Original file line number Diff line number Diff line change
@@ -11,7 +11,9 @@
#include <onyx/process.h>
#include <onyx/thread.h>

__BEGIN_CDECLS
void arch_vm_init(void);
__END_CDECLS

#ifdef __cplusplus

5 changes: 5 additions & 0 deletions kernel/include/onyx/bootmem.h
Original file line number Diff line number Diff line change
@@ -12,13 +12,18 @@
#include <stddef.h>
#include <stdint.h>

#include <onyx/compiler.h>

#define BOOTMEM_FLAG_LOW_MEM (1 << 0)

__BEGIN_CDECLS

void *alloc_boot_page(size_t nr_pgs, long flags);

void bootmem_reserve(unsigned long start, size_t size);
void bootmem_add_range(unsigned long start, size_t size);

void for_every_phys_region(void (*callback)(unsigned long start, size_t size));
__END_CDECLS

#endif
7 changes: 6 additions & 1 deletion kernel/include/onyx/exec.h
Original file line number Diff line number Diff line change
@@ -10,8 +10,13 @@

struct exec_state
{
ref_guard<mm_address_space> new_address_space{};
mm_address_space *new_address_space{};
bool flushed{false};
~exec_state()
{
if (new_address_space)
mmput(new_address_space);
}
};

int exec_state_create(struct exec_state *state);
5 changes: 5 additions & 0 deletions kernel/include/onyx/mm/shmem.h
Original file line number Diff line number Diff line change
@@ -11,8 +11,11 @@

#include <stddef.h>

#include <onyx/compiler.h>

struct file;

__BEGIN_CDECLS
/**
* @brief Create a new shmem file
*
@@ -21,4 +24,6 @@ struct file;
*/
struct file *anon_get_shmem(size_t len);

__END_CDECLS

#endif
Loading