Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 9 additions & 1 deletion arch/x86/extables.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2021 Amazon.com, Inc. or its affiliates.
* Copyright (c) 2021 Open Source Security, Inc.
* All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand All @@ -23,5 +24,12 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

void init_extables(void) { /* no-op */
#include <mm/regions.h>

void init_extables(void) {
for (extable_entry_t *cur = __start_extables; cur < __stop_extables; ++cur) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea to have them sanity checked. Thanks!

Next step could be to sort them and use bsearch to speed up lookup.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now we've only like 8 entries, so a linear search should still be fast enough. ;) But yeah, when we get more users and especially ones in hot code, speeding up the search might make sense.

if (!cur->fixup && !cur->cb)
panic("extable entry #%d for addr 0x%lx lacks fixup and callback!\n",
cur - __start_extables, cur->fault_addr);
}
}
1 change: 1 addition & 0 deletions arch/x86/link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ SECTIONS
{
__start_extables = .;
*(.extables)
__stop_extables = .;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice catch. Thanks!

. = ALIGN(4K);
__end_extables = .;
} :kernel
Expand Down
32 changes: 15 additions & 17 deletions arch/x86/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,29 +289,27 @@ void print_callstack(const void *sp, const void *ip) {
printk("\n");
}

static inline void use_extables(struct cpu_regs *regs) {
for (extable_entry_t *cur = __start_extables; cur < __end_extables; ++cur) {
if (regs->_ASM_IP == cur->fault_addr) {
if (cur->fixup) {
regs->_ASM_IP = cur->fixup;
}
if (cur->cb) {
cur->cb(regs);
}
if (cur->fixup || cur->cb) {
return;
}
else {
panic("fixup or cb must be set in the extable_entry\n");
}
}
static bool extables_fixup(struct cpu_regs *regs) {
for (extable_entry_t *cur = __start_extables; cur < __stop_extables; ++cur) {
if (regs->_ASM_IP != cur->fault_addr)
continue;

if (cur->fixup)
regs->_ASM_IP = cur->fixup;
else if (cur->cb)
cur->cb(regs);

return true;
}

return false;
}

void do_exception(struct cpu_regs *regs) {
static char ec_str[32], panic_str[128];

use_extables(regs);
if (extables_fixup(regs))
return;
Comment on lines -314 to +312
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh... Thanks!


dump_regs(regs);
print_callstack(_ptr(regs->_ASM_SP), _ptr(regs->_ASM_IP));
Expand Down
3 changes: 3 additions & 0 deletions include/arch/x86/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@
#define X86_EX_SEL_TLB_IDT2 0x11

#ifndef __ASSEMBLY__
#include <stdbool.h>
#include <stdint.h>

union x86_ex_error_code {
uint32_t error_code;
struct __packed {
Expand Down
3 changes: 2 additions & 1 deletion include/cmdline.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define KTF_CMDLINE_H

#ifndef __ASSEMBLY__
#include <compiler.h>

#define PARAM_MAX_LENGTH 32

Expand All @@ -52,4 +53,4 @@ struct __packed ktf_param {

#endif /* __ASSEMBLY__ */

#endif /* KTF_CMDLINE_H */
#endif /* KTF_CMDLINE_H */
2 changes: 2 additions & 0 deletions include/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
#define GHZ(x) (MHZ(x) * 1000)

#ifndef __ASSEMBLY__
#include <inttypes.h>

typedef uint64_t off_t;
#define _ptr(val) ((void *) (unsigned long) (val))
#define _ul(val) ((unsigned long) (val))
Expand Down
31 changes: 16 additions & 15 deletions include/mm/regions.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,28 @@
#include <page.h>
#include <string.h>

extern unsigned long __start_text[], __end_text[];
extern unsigned long __start_data[], __end_data[];
extern unsigned long __start_bss[], __end_bss[];
extern unsigned long __start_rodata[], __end_rodata[];
extern unsigned char __start_text[], __end_text[];
extern unsigned char __start_data[], __end_data[];
extern unsigned char __start_bss[], __end_bss[];
extern unsigned char __start_rodata[], __end_rodata[];

extern unsigned long __start_text_user[], __end_text_user[];
extern unsigned long __start_data_user[], __end_data_user[];
extern unsigned long __start_bss_user[], __end_bss_user[];
extern unsigned char __start_text_user[], __end_text_user[];
extern unsigned char __start_data_user[], __end_data_user[];
extern unsigned char __start_bss_user[], __end_bss_user[];

extern unsigned long __start_text_init[], __end_text_init[];
extern unsigned long __start_data_init[], __end_data_init[];
extern unsigned long __start_bss_init[], __end_bss_init[];
extern unsigned char __start_text_init[], __end_text_init[];
extern unsigned char __start_data_init[], __end_data_init[];
extern unsigned char __start_bss_init[], __end_bss_init[];

extern unsigned long __start_text_rmode[], __end_text_rmode[];
extern unsigned long __start_data_rmode[], __end_data_rmode[];
extern struct extable_entry __start_extables[], __end_extables[];
extern unsigned long __start_bss_rmode[], __end_bss_rmode[];
extern unsigned char __start_text_rmode[], __end_text_rmode[];
extern unsigned char __start_data_rmode[], __end_data_rmode[];
extern struct extable_entry __start_extables[], __stop_extables[];
extern unsigned char __end_extables[];
extern unsigned char __start_bss_rmode[], __end_bss_rmode[];

extern struct ktf_param __start_cmdline[], __end_cmdline[];

extern unsigned long __weak __start_symbols[], __end_symbols[];
extern unsigned char __weak __start_symbols[], __end_symbols[];

struct addr_range {
const char *name;
Expand Down