From 9cce829d8a794848b0699c3f9a84b2a057221a90 Mon Sep 17 00:00:00 2001 From: Louis Burda Date: Thu, 29 Sep 2022 00:32:30 +0200 Subject: Adapt kernel module for sev-snp machine --- kmod/cachepc.c | 4 ++-- kmod/kvm.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/kmod/cachepc.c b/kmod/cachepc.c index 9b2b59c..09ed705 100644 --- a/kmod/cachepc.c +++ b/kmod/cachepc.c @@ -16,14 +16,14 @@ static void build_randomized_list_for_cache_set(cache_ctx *ctx, cacheline **cach static cacheline **allocate_cache_ds(cache_ctx *ctx); static uint16_t get_virt_cache_set(cache_ctx *ctx, void *ptr); -void +void __attribute__((optimize(1))) // prevent instruction reordering cachepc_prime_vcall(uintptr_t ret, cacheline *cl) { cachepc_prime(cl); asm volatile ("mov %0, %%rax; jmp *%%rax" : : "r"(ret) : "rax"); } -void +void __attribute__((optimize(1))) // prevent instruction reordering cachepc_probe_vcall(uintptr_t ret, cacheline *cl) { cachepc_probe(cl); diff --git a/kmod/kvm.c b/kmod/kvm.c index 4c35157..4deb4fa 100644 --- a/kmod/kvm.c +++ b/kmod/kvm.c @@ -69,6 +69,26 @@ cachepc_kvm_proc_write(struct file *file, const char *buf, size_t buflen, loff_t return 0; } +loff_t +cachepc_kvm_proc_lseek(struct file *file, loff_t off, int mode) +{ + switch (mode) { + case SEEK_SET: + file->f_pos = off; + break; + case SEEK_CUR: + file->f_pos += off; + break; + case SEEK_END: + file->f_pos = cachepc_msrmts_count * sizeof(uint16_t) + off; + break; + default: + return -EINVAL; + } + + return file->f_pos; +} + void cachepc_kvm_prime_probe_test(void *p) { @@ -355,6 +375,7 @@ cachepc_kvm_init(void) cachepc_proc_ops.proc_open = cachepc_kvm_proc_open; cachepc_proc_ops.proc_read = cachepc_kvm_proc_read; cachepc_proc_ops.proc_write = cachepc_kvm_proc_write; + cachepc_proc_ops.proc_lseek = cachepc_kvm_proc_lseek; cachepc_proc_ops.proc_release = cachepc_kvm_proc_close; cachepc_proc_ops.proc_ioctl = cachepc_kvm_ioctl; proc_create("cachepc", 0644, NULL, &cachepc_proc_ops); -- cgit v1.2.3-71-gd317