.. | .. |
---|
45 | 45 | #include <crypto/sha.h> |
---|
46 | 46 | #include "kexec_internal.h" |
---|
47 | 47 | |
---|
48 | | -DEFINE_MUTEX(kexec_mutex); |
---|
| 48 | +atomic_t __kexec_lock = ATOMIC_INIT(0); |
---|
49 | 49 | |
---|
50 | 50 | /* Per cpu memory for storing cpu states in case of system crash. */ |
---|
51 | 51 | note_buf_t __percpu *crash_notes; |
---|
.. | .. |
---|
943 | 943 | */ |
---|
944 | 944 | void __noclone __crash_kexec(struct pt_regs *regs) |
---|
945 | 945 | { |
---|
946 | | - /* Take the kexec_mutex here to prevent sys_kexec_load |
---|
| 946 | + /* Take the kexec_lock here to prevent sys_kexec_load |
---|
947 | 947 | * running on one cpu from replacing the crash kernel |
---|
948 | 948 | * we are using after a panic on a different cpu. |
---|
949 | 949 | * |
---|
.. | .. |
---|
951 | 951 | * of memory the xchg(&kexec_crash_image) would be |
---|
952 | 952 | * sufficient. But since I reuse the memory... |
---|
953 | 953 | */ |
---|
954 | | - if (mutex_trylock(&kexec_mutex)) { |
---|
| 954 | + if (kexec_trylock()) { |
---|
955 | 955 | if (kexec_crash_image) { |
---|
956 | 956 | struct pt_regs fixed_regs; |
---|
957 | 957 | |
---|
.. | .. |
---|
960 | 960 | machine_crash_shutdown(&fixed_regs); |
---|
961 | 961 | machine_kexec(kexec_crash_image); |
---|
962 | 962 | } |
---|
963 | | - mutex_unlock(&kexec_mutex); |
---|
| 963 | + kexec_unlock(); |
---|
964 | 964 | } |
---|
965 | 965 | } |
---|
966 | 966 | STACK_FRAME_NON_STANDARD(__crash_kexec); |
---|
.. | .. |
---|
989 | 989 | } |
---|
990 | 990 | } |
---|
991 | 991 | |
---|
992 | | -size_t crash_get_memory_size(void) |
---|
| 992 | +ssize_t crash_get_memory_size(void) |
---|
993 | 993 | { |
---|
994 | | - size_t size = 0; |
---|
| 994 | + ssize_t size = 0; |
---|
995 | 995 | |
---|
996 | | - mutex_lock(&kexec_mutex); |
---|
| 996 | + if (!kexec_trylock()) |
---|
| 997 | + return -EBUSY; |
---|
| 998 | + |
---|
997 | 999 | if (crashk_res.end != crashk_res.start) |
---|
998 | 1000 | size = resource_size(&crashk_res); |
---|
999 | | - mutex_unlock(&kexec_mutex); |
---|
| 1001 | + |
---|
| 1002 | + kexec_unlock(); |
---|
1000 | 1003 | return size; |
---|
1001 | 1004 | } |
---|
1002 | 1005 | |
---|
.. | .. |
---|
1016 | 1019 | unsigned long old_size; |
---|
1017 | 1020 | struct resource *ram_res; |
---|
1018 | 1021 | |
---|
1019 | | - mutex_lock(&kexec_mutex); |
---|
| 1022 | + if (!kexec_trylock()) |
---|
| 1023 | + return -EBUSY; |
---|
1020 | 1024 | |
---|
1021 | 1025 | if (kexec_crash_image) { |
---|
1022 | 1026 | ret = -ENOENT; |
---|
.. | .. |
---|
1025 | 1029 | start = crashk_res.start; |
---|
1026 | 1030 | end = crashk_res.end; |
---|
1027 | 1031 | old_size = (end == 0) ? 0 : end - start + 1; |
---|
| 1032 | + new_size = roundup(new_size, KEXEC_CRASH_MEM_ALIGN); |
---|
1028 | 1033 | if (new_size >= old_size) { |
---|
1029 | 1034 | ret = (new_size == old_size) ? 0 : -EINVAL; |
---|
1030 | 1035 | goto unlock; |
---|
.. | .. |
---|
1036 | 1041 | goto unlock; |
---|
1037 | 1042 | } |
---|
1038 | 1043 | |
---|
1039 | | - start = roundup(start, KEXEC_CRASH_MEM_ALIGN); |
---|
1040 | | - end = roundup(start + new_size, KEXEC_CRASH_MEM_ALIGN); |
---|
1041 | | - |
---|
| 1044 | + end = start + new_size; |
---|
1042 | 1045 | crash_free_reserved_phys_range(end, crashk_res.end); |
---|
1043 | 1046 | |
---|
1044 | 1047 | if ((start == end) && (crashk_res.parent != NULL)) |
---|
.. | .. |
---|
1054 | 1057 | insert_resource(&iomem_resource, ram_res); |
---|
1055 | 1058 | |
---|
1056 | 1059 | unlock: |
---|
1057 | | - mutex_unlock(&kexec_mutex); |
---|
| 1060 | + kexec_unlock(); |
---|
1058 | 1061 | return ret; |
---|
1059 | 1062 | } |
---|
1060 | 1063 | |
---|
.. | .. |
---|
1126 | 1129 | { |
---|
1127 | 1130 | int error = 0; |
---|
1128 | 1131 | |
---|
1129 | | - if (!mutex_trylock(&kexec_mutex)) |
---|
| 1132 | + if (!kexec_trylock()) |
---|
1130 | 1133 | return -EBUSY; |
---|
1131 | 1134 | if (!kexec_image) { |
---|
1132 | 1135 | error = -EINVAL; |
---|
.. | .. |
---|
1201 | 1204 | #endif |
---|
1202 | 1205 | |
---|
1203 | 1206 | Unlock: |
---|
1204 | | - mutex_unlock(&kexec_mutex); |
---|
| 1207 | + kexec_unlock(); |
---|
1205 | 1208 | return error; |
---|
1206 | 1209 | } |
---|
1207 | 1210 | |
---|