2 /* SPDX-License-Identifier: GPL-2.0-or-later */
14 static int fd_msr
= 0;
16 static int rdmsr(int addr
, uint64_t *msr
)
18 if (lseek(fd_msr
, (off_t
) addr
, SEEK_SET
) == -1) {
19 perror("Could not lseek() to MSR");
24 if (read(fd_msr
, msr
, 8) == 8) {
30 perror("IO error couldn't read MSR.");
32 /* On older platforms the MSR might not exists */
36 perror("Couldn't read() MSR");
42 int msr_bootguard(uint64_t *msr
)
46 fd_msr
= open("/dev/cpu/0/msr", O_RDONLY
);
48 perror("Error while opening /dev/cpu/0/msr");
49 printf("Did you run 'modprobe msr'?\n");
53 if (rdmsr(MSR_BOOTGUARD
, msr
) < 0)