Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /*---------------------------------------------------------------------------+ |
| 3 | | fpu_system.h | |
| 4 | | | |
| 5 | | Copyright (C) 1992,1994,1997 | |
| 6 | | W. Metzenthen, 22 Parker St, Ormond, Vic 3163, | |
| 7 | | Australia. E-mail billm@suburbia.net | |
| 8 | | | |
| 9 | +---------------------------------------------------------------------------*/ |
| 10 | |
| 11 | #ifndef _FPU_SYSTEM_H |
| 12 | #define _FPU_SYSTEM_H |
| 13 | |
| 14 | /* system dependent definitions */ |
| 15 | |
| 16 | #include <linux/sched.h> |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/mm.h> |
| 19 | |
Juergen Gross | 4809146 | 2015-08-06 19:54:34 +0200 | [diff] [blame] | 20 | #include <asm/desc.h> |
| 21 | #include <asm/mmu_context.h> |
| 22 | |
| 23 | static inline struct desc_struct FPU_get_ldt_descriptor(unsigned seg) |
| 24 | { |
| 25 | static struct desc_struct zero_desc; |
| 26 | struct desc_struct ret = zero_desc; |
| 27 | |
| 28 | #ifdef CONFIG_MODIFY_LDT_SYSCALL |
| 29 | seg >>= 3; |
| 30 | mutex_lock(¤t->mm->context.lock); |
Borislav Petkov | bbf79d2 | 2017-06-06 19:31:16 +0200 | [diff] [blame] | 31 | if (current->mm->context.ldt && seg < current->mm->context.ldt->nr_entries) |
Juergen Gross | 4809146 | 2015-08-06 19:54:34 +0200 | [diff] [blame] | 32 | ret = current->mm->context.ldt->entries[seg]; |
| 33 | mutex_unlock(¤t->mm->context.lock); |
| 34 | #endif |
| 35 | return ret; |
| 36 | } |
| 37 | |
Thomas Gleixner | 718f5d0 | 2017-08-28 08:47:39 +0200 | [diff] [blame] | 38 | #define SEG_TYPE_WRITABLE (1U << 1) |
| 39 | #define SEG_TYPE_EXPANDS_DOWN (1U << 2) |
| 40 | #define SEG_TYPE_EXECUTE (1U << 3) |
| 41 | #define SEG_TYPE_EXPAND_MASK (SEG_TYPE_EXPANDS_DOWN | SEG_TYPE_EXECUTE) |
| 42 | #define SEG_TYPE_EXECUTE_MASK (SEG_TYPE_WRITABLE | SEG_TYPE_EXECUTE) |
| 43 | |
| 44 | static inline unsigned long seg_get_base(struct desc_struct *d) |
| 45 | { |
| 46 | unsigned long base = (unsigned long)d->base2 << 24; |
| 47 | |
| 48 | return base | ((unsigned long)d->base1 << 16) | d->base0; |
| 49 | } |
| 50 | |
| 51 | static inline unsigned long seg_get_limit(struct desc_struct *d) |
| 52 | { |
Thomas Gleixner | 38e9e81 | 2017-08-28 08:47:41 +0200 | [diff] [blame] | 53 | return ((unsigned long)d->limit1 << 16) | d->limit0; |
Thomas Gleixner | 718f5d0 | 2017-08-28 08:47:39 +0200 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | static inline unsigned long seg_get_granularity(struct desc_struct *d) |
| 57 | { |
| 58 | return d->g ? 4096 : 1; |
| 59 | } |
| 60 | |
| 61 | static inline bool seg_expands_down(struct desc_struct *d) |
| 62 | { |
| 63 | return (d->type & SEG_TYPE_EXPAND_MASK) == SEG_TYPE_EXPANDS_DOWN; |
| 64 | } |
| 65 | |
| 66 | static inline bool seg_execute_only(struct desc_struct *d) |
| 67 | { |
| 68 | return (d->type & SEG_TYPE_EXECUTE_MASK) == SEG_TYPE_EXECUTE; |
| 69 | } |
| 70 | |
| 71 | static inline bool seg_writable(struct desc_struct *d) |
| 72 | { |
| 73 | return (d->type & SEG_TYPE_EXECUTE_MASK) == SEG_TYPE_WRITABLE; |
| 74 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Ingo Molnar | 7366ed7 | 2015-04-27 04:19:39 +0200 | [diff] [blame] | 76 | #define I387 (¤t->thread.fpu.state) |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 77 | #define FPU_info (I387->soft.info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
Tejun Heo | d315760 | 2009-02-09 22:17:39 +0900 | [diff] [blame] | 79 | #define FPU_CS (*(unsigned short *) &(FPU_info->regs->cs)) |
| 80 | #define FPU_SS (*(unsigned short *) &(FPU_info->regs->ss)) |
| 81 | #define FPU_DS (*(unsigned short *) &(FPU_info->regs->ds)) |
| 82 | #define FPU_EAX (FPU_info->regs->ax) |
| 83 | #define FPU_EFLAGS (FPU_info->regs->flags) |
| 84 | #define FPU_EIP (FPU_info->regs->ip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | #define FPU_ORIG_EIP (FPU_info->___orig_eip) |
| 86 | |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 87 | #define FPU_lookahead (I387->soft.lookahead) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | /* nz if ip_offset and cs_selector are not to be set for the current |
| 90 | instruction. */ |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 91 | #define no_ip_update (*(u_char *)&(I387->soft.no_update)) |
| 92 | #define FPU_rm (*(u_char *)&(I387->soft.rm)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | /* Number of bytes of data which can be legally accessed by the current |
| 95 | instruction. This only needs to hold a number <= 108, so a byte will do. */ |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 96 | #define access_limit (*(u_char *)&(I387->soft.alimit)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 98 | #define partial_status (I387->soft.swd) |
| 99 | #define control_word (I387->soft.cwd) |
| 100 | #define fpu_tag_word (I387->soft.twd) |
| 101 | #define registers (I387->soft.st_space) |
| 102 | #define top (I387->soft.ftop) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 104 | #define instruction_address (*(struct address *)&I387->soft.fip) |
| 105 | #define operand_address (*(struct address *)&I387->soft.foo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | #define FPU_access_ok(x,y,z) if ( !access_ok(x,y,z) ) \ |
| 108 | math_abort(FPU_info,SIGSEGV) |
Randy Dunlap | d606f88 | 2006-12-07 02:14:00 +0100 | [diff] [blame] | 109 | #define FPU_abort math_abort(FPU_info, SIGSEGV) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
| 111 | #undef FPU_IGNORE_CODE_SEGV |
| 112 | #ifdef FPU_IGNORE_CODE_SEGV |
| 113 | /* access_ok() is very expensive, and causes the emulator to run |
| 114 | about 20% slower if applied to the code. Anyway, errors due to bad |
| 115 | code addresses should be much rarer than errors due to bad data |
| 116 | addresses. */ |
| 117 | #define FPU_code_access_ok(z) |
| 118 | #else |
| 119 | /* A simpler test than access_ok() can probably be done for |
| 120 | FPU_code_access_ok() because the only possible error is to step |
| 121 | past the upper boundary of a legal code area. */ |
| 122 | #define FPU_code_access_ok(z) FPU_access_ok(VERIFY_READ,(void __user *)FPU_EIP,z) |
| 123 | #endif |
| 124 | |
| 125 | #define FPU_get_user(x,y) get_user((x),(y)) |
| 126 | #define FPU_put_user(x,y) put_user((x),(y)) |
| 127 | |
| 128 | #endif |