-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from 0xhilbert/master
Map IRQ handlers to the kernel address space
- Loading branch information
Showing
9 changed files
with
397 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
app | ||
measurements.txt | ||
measurements_raw.txt | ||
outlier_idx.txt | ||
plot.pdf | ||
xlabels.gp | ||
|
||
*.swp | ||
|
||
out.txt | ||
parsed.txt | ||
parsed_zz.txt | ||
parsed_strlen.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
LIBSGXSTEP_DIR = ../.. | ||
LIBSGXSTEP = $(LIBSGXSTEP_DIR)/libsgxstep | ||
-include $(LIBSGXSTEP)/Makefile.config | ||
|
||
URTS_LIB_PATH = $(LIBSGXSTEP_DIR)/linux-sgx/psw/urts/linux | ||
|
||
ifeq ($(SGX_SDK),) | ||
SGX_SDK = /opt/intel/sgxsdk | ||
endif | ||
export SGX_SDK | ||
ifneq ($(SGX_SDK), /opt/intel/sgxsdk) | ||
URTS_LD_LIBRARY_PATH = LD_LIBRARY_PATH=$(LIBSGXSTEP_DIR)/linux-sgx/psw/urts/linux | ||
endif | ||
|
||
SUBDIRS = $(LIBSGXSTEP) | ||
|
||
CC = gcc | ||
AS = gcc | ||
LD = gcc | ||
|
||
CFLAGS += -fPIC -fno-stack-protector -fno-builtin -fno-jump-tables \ | ||
-fno-common -Wno-attributes -g -D_GNU_SOURCE -O0 | ||
INCLUDE = -I$(SGX_SDK)/include/ -I$(LIBSGXSTEP_DIR) | ||
LDFLAGS += -lsgx-step -lsgx_urts \ | ||
-lsgx_uae_service -pthread $(SUBDIRS:%=-L %) -L$(SGX_SDK)/lib64/ | ||
|
||
SOURCES = $(shell ls *.c) | ||
OBJECTS = $(SOURCES:.c=.o) | ||
OUTPUT = app | ||
|
||
BUILDDIRS = $(SUBDIRS:%=build-%) | ||
CLEANDIRS = $(SUBDIRS:%=clean-%) | ||
|
||
|
||
MAKEFLAGS += --silent | ||
|
||
all: $(OUTPUT) | ||
|
||
run: clean all | ||
sudo $(URTS_LD_LIBRARY_PATH) ./app | ||
|
||
$(OUTPUT): $(BUILDDIRS) $(OBJECTS) | ||
echo "$(INDENT)[LD]" $(OBJECTS) $(LIBS) -o $(OUTPUT) | ||
$(LD) $(OBJECTS) $(LDFLAGS) -o $(OUTPUT) | ||
|
||
%.o : %.c | ||
echo "$(INDENT)[CC] " $< | ||
$(CC) $(CFLAGS) $(INCLUDE) -c $< | ||
|
||
%.o : %.S | ||
echo "$(INDENT)[AS] " $< | ||
$(AS) $(INCLUDE) -c $< -o $@ | ||
|
||
clean: $(CLEANDIRS) | ||
echo "$(INDENT)[RM]" $(OBJECTS) $(OUTPUT) | ||
rm -f $(OBJECTS) $(OUTPUT) | ||
|
||
$(BUILDDIRS): | ||
echo "$(INDENT)[===] $(@:build-%=%) [===]" | ||
$(MAKE) -C $(@:build-%=%) INDENT+="$(INDENT_STEP)" curr-dir=$(curr-dir)/$(@:build-%=%) | ||
|
||
$(CLEANDIRS): | ||
echo "$(INDENT)[===] $(@:clean-%=%) [===]" | ||
$(MAKE) clean -C $(@:clean-%=%) INDENT+="$(INDENT_STEP)" curr-dir=$(curr-dir)/$(@:build-%=%) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Test for the kernel mapped interupt handlers | ||
|
||
This test uses the kernel mapped ISR region to demonstrate sw IRQ handling from other processes and cores. | ||
|
||
## Usage: | ||
Start the listener: | ||
``` | ||
sudo ./app | ||
``` | ||
|
||
Trigger the SW IRQ from another process: | ||
``` | ||
taskset -c 1 ./app trigger | ||
``` | ||
|
||
|
||
# Sample output: | ||
|
||
|
||
``` | ||
[idt.c] locking IRQ handler pages 0x564b69f22000/0x564b69f21000 | ||
[idt.c] setting up isr mapping: from 0x564b69f21000 to 0x564b69f2205b | ||
[pt.c] /dev/sgx-step opened! | ||
[idt.c] we received the base address from kernel 0xffffc900201ea000 | ||
[idt.c] the offset to the kernel mapped ISR region is 0xffff72b4b62c9000 | ||
[pt.c] /dev/mem opened! | ||
[sched.c] continuing on CPU 1 | ||
[idt.c] DTR.base=0xfffffe0000000000/size=4095 (256 entries) | ||
[idt.c] established user space IDT mapping at 0x7f4302014000 | ||
-------------------------------------------------------------------------------- | ||
[main.c] Installing and testing ring0 IDT handler | ||
-------------------------------------------------------------------------------- | ||
[idt.c] using kernel mapped ISR handler: 0x564b69f22000 -> 0xffffc900201eb000 | ||
[idt.c] installed asm IRQ handler at 10:0x564b69f22000 | ||
[idt.c] IDT[ 45] @0x7f43020142d0 = 0xffffc900201eb000 (seg sel 0x10); p=1; dpl=3; type=14; ist=0 | ||
[main.c] wating for sw IRQ on vector 45 ... | ||
[main.c] returned from IRQ: my_cpl=3; irq_cpl=0; count=01; flags=0x246; nemesis=835151372 | ||
[main.c] all is well; irq_count=1; exiting.. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* This file is part of the SGX-Step enclave execution control framework. | ||
* | ||
* Copyright (C) 2017 Jo Van Bulck <jo.vanbulck@cs.kuleuven.be>, | ||
* Raoul Strackx <raoul.strackx@cs.kuleuven.be> | ||
* | ||
* SGX-Step is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* SGX-Step is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with SGX-Step. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "libsgxstep/idt.h" | ||
#include "libsgxstep/gdt.h" | ||
#include "libsgxstep/apic.h" | ||
#include "libsgxstep/cpu.h" | ||
#include "libsgxstep/sched.h" | ||
#include "libsgxstep/config.h" | ||
#include <unistd.h> | ||
|
||
#define DO_APIC_SW_IRQ 1 | ||
#define DO_APIC_TMR_IRQ 0 | ||
#define DO_EXEC_PRIV 0 | ||
#define NUM 1000 | ||
#define NEMESIS_HIGH 1 | ||
|
||
/* ------------------------------------------------------------ */ | ||
/* This code may execute with ring0 privileges */ | ||
int my_cpl = -1; | ||
extern uint64_t nemesis_tsc_aex, nemesis_tsc_eresume; | ||
|
||
void pre_irq(void) | ||
{ | ||
my_cpl = get_cpl(); | ||
__ss_irq_fired = 0; | ||
nemesis_tsc_eresume = rdtsc_begin(); | ||
} | ||
|
||
void do_irq_sw(void) | ||
{ | ||
asm("int %0\n\t" ::"i"(IRQ_VECTOR):); | ||
} | ||
|
||
|
||
/* ------------------------------------------------------------ */ | ||
|
||
void post_irq(void) | ||
{ | ||
ASSERT(__ss_irq_fired); | ||
info("returned from IRQ: my_cpl=%d; irq_cpl=%d; count=%02d; flags=%p; nemesis=%d", | ||
my_cpl, __ss_irq_cpl, __ss_irq_count, read_flags(), nemesis_tsc_aex - nemesis_tsc_eresume); | ||
} | ||
|
||
int main( int argc, char **argv ) | ||
{ | ||
if (argc == 2) { | ||
info("triggering sw IRQ on vector %d!", IRQ_VECTOR); | ||
do_irq_sw(); | ||
return 0; | ||
} | ||
|
||
idt_t idt = {0}; | ||
ASSERT( !claim_cpu(VICTIM_CPU) ); | ||
map_idt(&idt); | ||
|
||
info_event("Installing and testing ring0 IDT handler"); | ||
install_kernel_irq_handler(&idt, __ss_irq_handler, IRQ_VECTOR); | ||
|
||
info("wating for sw IRQ on vector %d ...", IRQ_VECTOR); | ||
|
||
pre_irq(); | ||
|
||
while (__ss_irq_fired == 0) { | ||
sleep(1); | ||
} | ||
|
||
post_irq(); | ||
|
||
info("all is well; irq_count=%d; exiting..", __ss_irq_count); | ||
return 0; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.