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

qemu-targetstep_guest.c (1339B)


      1#include "cachepc/uapi.h"
      2
      3#include <sys/time.h>
      4#include <sys/resource.h>
      5#include <errno.h>
      6#include <err.h>
      7#include <unistd.h>
      8#include <stdint.h>
      9#include <string.h>
     10#include <stdio.h>
     11#include <stdlib.h>
     12
     13int
     14main(int argc, const char **argv)
     15{
     16	void *buf;
     17	int ret;
     18
     19	buf = NULL;
     20	if (posix_memalign(&buf, L1_LINESIZE * L1_SETS, L1_LINESIZE * L1_SETS))
     21		err(1, "memalign");
     22	memset(buf, 0, L1_LINESIZE * L1_SETS);
     23
     24	errno = 0;
     25	ret = setpriority(PRIO_PROCESS, 0, -20);
     26	if (errno) err(1, "setpriority");
     27	printf("NICE %i\n", ret);
     28
     29	while (1) {
     30		printf("LOOP\n");
     31		CPC_DO_VMMCALL(KVM_HC_CPC_VMMCALL_SIGNAL,
     32			CPC_GUEST_START_TRACK, 0);
     33		*(uint8_t *)(buf + L1_LINESIZE * 9) = 1;
     34		*(uint8_t *)(buf + L1_LINESIZE * 10) = 1;
     35		*(uint8_t *)(buf + L1_LINESIZE * 11) = 1;
     36		*(uint8_t *)(buf + L1_LINESIZE * 12) = 1;
     37		*(uint8_t *)(buf + L1_LINESIZE * 13) = 1;
     38		*(uint8_t *)(buf + L1_LINESIZE * 14) = 1;
     39		*(uint8_t *)(buf + L1_LINESIZE * 15) = 1;
     40		*(uint8_t *)(buf + L1_LINESIZE * 9) = 1;
     41		*(uint8_t *)(buf + L1_LINESIZE * 10) = 1;
     42		*(uint8_t *)(buf + L1_LINESIZE * 11) = 1;
     43		*(uint8_t *)(buf + L1_LINESIZE * 12) = 1;
     44		*(uint8_t *)(buf + L1_LINESIZE * 13) = 1;
     45		*(uint8_t *)(buf + L1_LINESIZE * 14) = 1;
     46		*(uint8_t *)(buf + L1_LINESIZE * 15) = 1;
     47		CPC_DO_VMMCALL(KVM_HC_CPC_VMMCALL_SIGNAL,
     48			CPC_GUEST_STOP_TRACK, 0);
     49	}
     50}