#ifndef _PKEYS_HELPER_H #define _PKEYS_HELPER_H #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #define NR_PKEYS 16 #define PKRU_BITS_PER_PKEY 2 #ifndef DEBUG_LEVEL #define DEBUG_LEVEL 0 #endif #define DPRINT_IN_SIGNAL_BUF_SIZE 4096 extern int dprint_in_signal; extern char dprint_in_signal_buffer[DPRINT_IN_SIGNAL_BUF_SIZE]; static inline void sigsafe_printf(const char *format, ...) { va_list ap; va_start(ap, format); if (!dprint_in_signal) { vprintf(format, ap); } else { int len = vsnprintf(dprint_in_signal_buffer, DPRINT_IN_SIGNAL_BUF_SIZE, format, ap); /* * len is amount that would have been printed, * but actual write is truncated at BUF_SIZE. */ if (len > DPRINT_IN_SIGNAL_BUF_SIZE) len = DPRINT_IN_SIGNAL_BUF_SIZE; write(1, dprint_in_signal_buffer, len); } va_end(ap); } #define dprintf_level(level, args...) do { \ if (level <= DEBUG_LEVEL) \ sigsafe_printf(args); \ fflush(NULL); \ } while (0) #define dprintf0(args...) dprintf_level(0, args) #define dprintf1(args...) dprintf_level(1, args) #define dprintf2(args...) dprintf_level(2, args) #define dprintf3(args...) dprintf_level(3, args) #define dprintf4(args...) dprintf_level(4, args) extern unsigned int shadow_pkru; static inline unsigned int __rdpkru(void) { unsigned int eax, edx; unsigned int ecx = 0; unsigned int pkru; asm volatile(".byte 0x0f,0x01,0xee\n\t" : "=a" (eax), "=d" (edx) : "c" (ecx)); pkru = eax; return pkru; } static inline unsigned int _rdpkru(int line) { unsigned int pkru = __rdpkru(); dprintf4("rdpkru(line=%d) pkru: %x shadow: %x\n", line, pkru, shadow_pkru); assert(pkru == shadow_pkru); return pkru; } #define rdpkru() _rdpkru(__LINE__) static inline void __wrpkru(unsigned int pkru) { unsigned int eax = pkru; unsigned int ecx = 0; unsigned int edx = 0; dprintf4("%s() changing %08x to %08x\n", __func__, __rdpkru(), pkru); asm volatile(".byte 0x0f,0x01,0xef\n\t" : : "a" (eax), "c" (ecx), "d" (edx)); assert(pkru == __rdpkru()); } static inline void wrpkru(unsigned int pkru) { dprintf4("%s() changing %08x to %08x\n", __func__, __rdpkru(), pkru); /* will do the shadow check for us: */ rdpkru(); __wrpkru(pkru); shadow_pkru = pkru; dprintf4("%s(%08x) pkru: %08x\n", __func__, pkru, __rdpkru()); } /* * These are technically racy. since something could * change PKRU between the read and the write. */ static inline void __pkey_access_allow(int pkey, int do_allow) { unsigned int pkru = rdpkru(); int bit = pkey * 2; if (do_allow) pkru &= (1<54791b276b4000b307339f269d3bf7db877d536f (patch) tree1c2616bd373ce5ea28aac2a53e32f5b5834901ce /include/acpi/ghes.h parent5d0e7705774dd412a465896d08d59a81a345c1e4 (diff)parent047487241ff59374fded8c477f21453681f5995c (diff)
Merge branch 'sparc64-non-resumable-user-error-recovery'
Liam R. Howlett says: ==================== sparc64: Recover from userspace non-resumable PIO & MEM errors A non-resumable error from userspace is able to cause a kernel panic or trap loop due to the setup and handling of the queued traps once in the kernel. This patch series addresses both of these issues. The queues are fixed by simply zeroing the memory before use. PIO errors from userspace will result in a SIGBUS being sent to the user process. The MEM errors form userspace will result in a SIGKILL and also cause the offending pages to be claimed so they are no longer used in future tasks. SIGKILL is used to ensure that the process does not try to coredump and result in an attempt to read the memory again from within kernel space. Although there is a HV call to scrub the memory (mem_scrub), there is no easy way to guarantee that the real memory address(es) are not used by other tasks. Clearing the error with mem_scrub would zero the memory and cause the other processes to proceed with bad data. The handling of other non-resumable errors remain unchanged and will cause a panic. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/acpi/ghes.h')