cachepc

Prime+Probe cache-based side-channel attack on AMD SEV-SNP protected virtual machines
git clone https://git.sinitax.com/sinitax/cachepc
Log | Files | Refs | Submodules | README | sfeed.txt

eviction.c (935B)


      1#include "test/util.h"
      2#include "cachepc/uapi.h"
      3
      4#include <sys/ioctl.h>
      5#include <fcntl.h>
      6#include <assert.h>
      7#include <unistd.h>
      8#include <err.h>
      9#include <stdint.h>
     10#include <stdio.h>
     11#include <stdlib.h>
     12
     13int
     14main(int argc, const char **argv)
     15{
     16	uint8_t counts[L1_SETS];
     17	uint32_t arg, set;
     18	int fd, ret;
     19
     20	fd = open("/dev/kvm", O_RDONLY);
     21	if (fd < 0) err(1, "open");
     22
     23	set = 48;
     24	if (argc > 1) set = atoi(argv[1]);
     25	if (set >= L1_SETS) errx(1, "set out-of-bounds");
     26
     27	ret = ioctl(fd, KVM_CPC_RESET, &arg);
     28	if (ret == -1) err(1, "KVM_CPC_RESET");
     29
     30	arg = set;
     31	ret = ioctl(fd, KVM_CPC_TEST_EVICTION, &arg);
     32	if (ret == -1) err(1, "KVM_CPC_TEST_EVICTION");
     33
     34	ret = ioctl(fd, KVM_CPC_READ_COUNTS, counts);
     35	if (ret == -1) err(1, "KVM_CPC_READ_COUNTS");
     36
     37	print_counts(counts);
     38	printf("\n");
     39	print_counts_raw(counts);
     40
     41	ret = ioctl(fd, KVM_CPC_DEINIT, &arg);
     42	if (ret == -1) err(1, "KVM_CPC_DEINIT");
     43
     44	close(fd);
     45
     46	return arg;
     47}