| .. | .. | 
|---|
| 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); | 
|---|
| .. | .. | 
|---|
| 978 | 978 | old_cpu = atomic_cmpxchg(&panic_cpu, PANIC_CPU_INVALID, this_cpu); | 
|---|
| 979 | 979 | if (old_cpu == PANIC_CPU_INVALID) { | 
|---|
| 980 | 980 | /* This is the 1st CPU which comes here, so go ahead. */ | 
|---|
|  | 981 | +		printk_safe_flush_on_panic(); | 
|---|
| 981 | 982 | __crash_kexec(regs); | 
|---|
| 982 | 983 |  | 
|---|
| 983 | 984 | /* | 
|---|
| .. | .. | 
|---|
| 988 | 989 | } | 
|---|
| 989 | 990 | } | 
|---|
| 990 | 991 |  | 
|---|
| 991 |  | -size_t crash_get_memory_size(void) | 
|---|
|  | 992 | +ssize_t crash_get_memory_size(void) | 
|---|
| 992 | 993 | { | 
|---|
| 993 |  | -	size_t size = 0; | 
|---|
|  | 994 | +	ssize_t size = 0; | 
|---|
| 994 | 995 |  | 
|---|
| 995 |  | -	mutex_lock(&kexec_mutex); | 
|---|
|  | 996 | +	if (!kexec_trylock()) | 
|---|
|  | 997 | +		return -EBUSY; | 
|---|
|  | 998 | + | 
|---|
| 996 | 999 | if (crashk_res.end != crashk_res.start) | 
|---|
| 997 | 1000 | size = resource_size(&crashk_res); | 
|---|
| 998 |  | -	mutex_unlock(&kexec_mutex); | 
|---|
|  | 1001 | + | 
|---|
|  | 1002 | +	kexec_unlock(); | 
|---|
| 999 | 1003 | return size; | 
|---|
| 1000 | 1004 | } | 
|---|
| 1001 | 1005 |  | 
|---|
| .. | .. | 
|---|
| 1015 | 1019 | unsigned long old_size; | 
|---|
| 1016 | 1020 | struct resource *ram_res; | 
|---|
| 1017 | 1021 |  | 
|---|
| 1018 |  | -	mutex_lock(&kexec_mutex); | 
|---|
|  | 1022 | +	if (!kexec_trylock()) | 
|---|
|  | 1023 | +		return -EBUSY; | 
|---|
| 1019 | 1024 |  | 
|---|
| 1020 | 1025 | if (kexec_crash_image) { | 
|---|
| 1021 | 1026 | ret = -ENOENT; | 
|---|
| .. | .. | 
|---|
| 1024 | 1029 | start = crashk_res.start; | 
|---|
| 1025 | 1030 | end = crashk_res.end; | 
|---|
| 1026 | 1031 | old_size = (end == 0) ? 0 : end - start + 1; | 
|---|
|  | 1032 | +	new_size = roundup(new_size, KEXEC_CRASH_MEM_ALIGN); | 
|---|
| 1027 | 1033 | if (new_size >= old_size) { | 
|---|
| 1028 | 1034 | ret = (new_size == old_size) ? 0 : -EINVAL; | 
|---|
| 1029 | 1035 | goto unlock; | 
|---|
| .. | .. | 
|---|
| 1035 | 1041 | goto unlock; | 
|---|
| 1036 | 1042 | } | 
|---|
| 1037 | 1043 |  | 
|---|
| 1038 |  | -	start = roundup(start, KEXEC_CRASH_MEM_ALIGN); | 
|---|
| 1039 |  | -	end = roundup(start + new_size, KEXEC_CRASH_MEM_ALIGN); | 
|---|
| 1040 |  | - | 
|---|
|  | 1044 | +	end = start + new_size; | 
|---|
| 1041 | 1045 | crash_free_reserved_phys_range(end, crashk_res.end); | 
|---|
| 1042 | 1046 |  | 
|---|
| 1043 | 1047 | if ((start == end) && (crashk_res.parent != NULL)) | 
|---|
| .. | .. | 
|---|
| 1053 | 1057 | insert_resource(&iomem_resource, ram_res); | 
|---|
| 1054 | 1058 |  | 
|---|
| 1055 | 1059 | unlock: | 
|---|
| 1056 |  | -	mutex_unlock(&kexec_mutex); | 
|---|
|  | 1060 | +	kexec_unlock(); | 
|---|
| 1057 | 1061 | return ret; | 
|---|
| 1058 | 1062 | } | 
|---|
| 1059 | 1063 |  | 
|---|
| .. | .. | 
|---|
| 1125 | 1129 | { | 
|---|
| 1126 | 1130 | int error = 0; | 
|---|
| 1127 | 1131 |  | 
|---|
| 1128 |  | -	if (!mutex_trylock(&kexec_mutex)) | 
|---|
|  | 1132 | +	if (!kexec_trylock()) | 
|---|
| 1129 | 1133 | return -EBUSY; | 
|---|
| 1130 | 1134 | if (!kexec_image) { | 
|---|
| 1131 | 1135 | error = -EINVAL; | 
|---|
| .. | .. | 
|---|
| 1200 | 1204 | #endif | 
|---|
| 1201 | 1205 |  | 
|---|
| 1202 | 1206 | Unlock: | 
|---|
| 1203 |  | -	mutex_unlock(&kexec_mutex); | 
|---|
|  | 1207 | +	kexec_unlock(); | 
|---|
| 1204 | 1208 | return error; | 
|---|
| 1205 | 1209 | } | 
|---|
| 1206 | 1210 |  | 
|---|