Skip to content

Commit 60187bd

Browse files
committed
Merge branch 'fixes' of git://git.armlinux.org.uk/~rmk/linux-arm
Pull ARM fixes from Russell King: "Two areas addressed by these fixes: - Fixes from Dave Martin for the signal frames that were broken with certain configurations. No one noticed until recently. - More kexec fixes to ensure that the crashkernel region is correctly allocated, and a fix for the location of the device tree when several kexec kernels are loaded" * 'fixes' of git://git.armlinux.org.uk/~rmk/linux-arm: ARM: 8687/1: signal: Fix unparseable iwmmxt_sigframe in uc_regspace[] ARM: 8686/1: iwmmxt: Add missing __user annotations to sigframe accessors ARM: kexec: fix failure to boot crash kernel ARM: kexec: avoid allocating crashkernel region outside lowmem
2 parents da08f35 + ce184a0 commit 60187bd

5 files changed

Lines changed: 80 additions & 23 deletions

File tree

‎arch/arm/include/asm/kexec.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919

2020
#ifndef __ASSEMBLY__
2121

22+
#define ARCH_HAS_KIMAGE_ARCH
23+
struct kimage_arch {
24+
u32 kernel_r2;
25+
};
26+
2227
/**
2328
* crash_setup_regs() - save registers for the panic kernel
2429
* @newregs: registers are saved here

‎arch/arm/include/asm/ucontext.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ struct ucontext {
3535
* bytes, to prevent unpredictable padding in the signal frame.
3636
*/
3737

38+
/*
39+
* Dummy padding block: if this magic is encountered, the block should
40+
* be skipped using the corresponding size field.
41+
*/
42+
#define DUMMY_MAGIC 0xb0d9ed01
43+
3844
#ifdef CONFIG_CRUNCH
3945
#define CRUNCH_MAGIC 0x5065cf03
4046
#define CRUNCH_STORAGE_SIZE (CRUNCH_SIZE + 8)

‎arch/arm/kernel/machine_kexec.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ extern unsigned long kexec_boot_atags;
3030

3131
static atomic_t waiting_for_crash_ipi;
3232

33-
static unsigned long dt_mem;
3433
/*
3534
* Provide a dummy crash_notes definition while crash dump arrives to arm.
3635
* This prevents breakage of crash_notes attribute in kernel/ksysfs.c.
@@ -42,6 +41,9 @@ int machine_kexec_prepare(struct kimage *image)
4241
__be32 header;
4342
int i, err;
4443

44+
image->arch.kernel_r2 = image->start - KEXEC_ARM_ZIMAGE_OFFSET
45+
+ KEXEC_ARM_ATAGS_OFFSET;
46+
4547
/*
4648
* Validate that if the current HW supports SMP, then the SW supports
4749
* and implements CPU hotplug for the current HW. If not, we won't be
@@ -66,8 +68,8 @@ int machine_kexec_prepare(struct kimage *image)
6668
if (err)
6769
return err;
6870

69-
if (be32_to_cpu(header) == OF_DT_HEADER)
70-
dt_mem = current_segment->mem;
71+
if (header == cpu_to_be32(OF_DT_HEADER))
72+
image->arch.kernel_r2 = current_segment->mem;
7173
}
7274
return 0;
7375
}
@@ -165,8 +167,7 @@ void machine_kexec(struct kimage *image)
165167
kexec_start_address = image->start;
166168
kexec_indirection_page = page_list;
167169
kexec_mach_type = machine_arch_type;
168-
kexec_boot_atags = dt_mem ?: image->start - KEXEC_ARM_ZIMAGE_OFFSET
169-
+ KEXEC_ARM_ATAGS_OFFSET;
170+
kexec_boot_atags = image->arch.kernel_r2;
170171

171172
/* copy our kernel relocation code to the control code page */
172173
reboot_entry = fncpy(reboot_code_buffer,

‎arch/arm/kernel/setup.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,9 @@ static void __init reserve_crashkernel(void)
987987

988988
if (crash_base <= 0) {
989989
unsigned long long crash_max = idmap_to_phys((u32)~0);
990+
unsigned long long lowmem_max = __pa(high_memory - 1) + 1;
991+
if (crash_max > lowmem_max)
992+
crash_max = lowmem_max;
990993
crash_base = memblock_find_in_range(CRASH_ALIGN, crash_max,
991994
crash_size, CRASH_ALIGN);
992995
if (!crash_base) {

‎arch/arm/kernel/signal.c‎

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ static int preserve_crunch_context(struct crunch_sigframe __user *frame)
4040
return __copy_to_user(frame, kframe, sizeof(*frame));
4141
}
4242

43-
static int restore_crunch_context(struct crunch_sigframe __user *frame)
43+
static int restore_crunch_context(char __user **auxp)
4444
{
45+
struct crunch_sigframe __user *frame =
46+
(struct crunch_sigframe __user *)*auxp;
4547
char kbuf[sizeof(*frame) + 8];
4648
struct crunch_sigframe *kframe;
4749

@@ -52,39 +54,76 @@ static int restore_crunch_context(struct crunch_sigframe __user *frame)
5254
if (kframe->magic != CRUNCH_MAGIC ||
5355
kframe->size != CRUNCH_STORAGE_SIZE)
5456
return -1;
57+
*auxp += CRUNCH_STORAGE_SIZE;
5558
crunch_task_restore(current_thread_info(), &kframe->storage);
5659
return 0;
5760
}
5861
#endif
5962

6063
#ifdef CONFIG_IWMMXT
6164

62-
static int preserve_iwmmxt_context(struct iwmmxt_sigframe *frame)
65+
static int preserve_iwmmxt_context(struct iwmmxt_sigframe __user *frame)
6366
{
6467
char kbuf[sizeof(*frame) + 8];
6568
struct iwmmxt_sigframe *kframe;
69+
int err = 0;
6670

6771
/* the iWMMXt context must be 64 bit aligned */
6872
kframe = (struct iwmmxt_sigframe *)((unsigned long)(kbuf + 8) & ~7);
69-
kframe->magic = IWMMXT_MAGIC;
70-
kframe->size = IWMMXT_STORAGE_SIZE;
71-
iwmmxt_task_copy(current_thread_info(), &kframe->storage);
72-
return __copy_to_user(frame, kframe, sizeof(*frame));
73+
74+
if (test_thread_flag(TIF_USING_IWMMXT)) {
75+
kframe->magic = IWMMXT_MAGIC;
76+
kframe->size = IWMMXT_STORAGE_SIZE;
77+
iwmmxt_task_copy(current_thread_info(), &kframe->storage);
78+
79+
err = __copy_to_user(frame, kframe, sizeof(*frame));
80+
} else {
81+
/*
82+
* For bug-compatibility with older kernels, some space
83+
* has to be reserved for iWMMXt even if it's not used.
84+
* Set the magic and size appropriately so that properly
85+
* written userspace can skip it reliably:
86+
*/
87+
__put_user_error(DUMMY_MAGIC, &frame->magic, err);
88+
__put_user_error(IWMMXT_STORAGE_SIZE, &frame->size, err);
89+
}
90+
91+
return err;
7392
}
7493

75-
static int restore_iwmmxt_context(struct iwmmxt_sigframe *frame)
94+
static int restore_iwmmxt_context(char __user **auxp)
7695
{
96+
struct iwmmxt_sigframe __user *frame =
97+
(struct iwmmxt_sigframe __user *)*auxp;
7798
char kbuf[sizeof(*frame) + 8];
7899
struct iwmmxt_sigframe *kframe;
79100

80101
/* the iWMMXt context must be 64 bit aligned */
81102
kframe = (struct iwmmxt_sigframe *)((unsigned long)(kbuf + 8) & ~7);
82103
if (__copy_from_user(kframe, frame, sizeof(*frame)))
83104
return -1;
84-
if (kframe->magic != IWMMXT_MAGIC ||
85-
kframe->size != IWMMXT_STORAGE_SIZE)
105+
106+
/*
107+
* For non-iWMMXt threads: a single iwmmxt_sigframe-sized dummy
108+
* block is discarded for compatibility with setup_sigframe() if
109+
* present, but we don't mandate its presence. If some other
110+
* magic is here, it's not for us:
111+
*/
112+
if (!test_thread_flag(TIF_USING_IWMMXT) &&
113+
kframe->magic != DUMMY_MAGIC)
114+
return 0;
115+
116+
if (kframe->size != IWMMXT_STORAGE_SIZE)
86117
return -1;
87-
iwmmxt_task_restore(current_thread_info(), &kframe->storage);
118+
119+
if (test_thread_flag(TIF_USING_IWMMXT)) {
120+
if (kframe->magic != IWMMXT_MAGIC)
121+
return -1;
122+
123+
iwmmxt_task_restore(current_thread_info(), &kframe->storage);
124+
}
125+
126+
*auxp += IWMMXT_STORAGE_SIZE;
88127
return 0;
89128
}
90129

@@ -107,8 +146,10 @@ static int preserve_vfp_context(struct vfp_sigframe __user *frame)
107146
return vfp_preserve_user_clear_hwstate(&frame->ufp, &frame->ufp_exc);
108147
}
109148

110-
static int restore_vfp_context(struct vfp_sigframe __user *frame)
149+
static int restore_vfp_context(char __user **auxp)
111150
{
151+
struct vfp_sigframe __user *frame =
152+
(struct vfp_sigframe __user *)*auxp;
112153
unsigned long magic;
113154
unsigned long size;
114155
int err = 0;
@@ -121,6 +162,7 @@ static int restore_vfp_context(struct vfp_sigframe __user *frame)
121162
if (magic != VFP_MAGIC || size != VFP_STORAGE_SIZE)
122163
return -EINVAL;
123164

165+
*auxp += size;
124166
return vfp_restore_user_hwstate(&frame->ufp, &frame->ufp_exc);
125167
}
126168

@@ -141,7 +183,7 @@ struct rt_sigframe {
141183

142184
static int restore_sigframe(struct pt_regs *regs, struct sigframe __user *sf)
143185
{
144-
struct aux_sigframe __user *aux;
186+
char __user *aux;
145187
sigset_t set;
146188
int err;
147189

@@ -169,18 +211,18 @@ static int restore_sigframe(struct pt_regs *regs, struct sigframe __user *sf)
169211

170212
err |= !valid_user_regs(regs);
171213

172-
aux = (struct aux_sigframe __user *) sf->uc.uc_regspace;
214+
aux = (char __user *) sf->uc.uc_regspace;
173215
#ifdef CONFIG_CRUNCH
174216
if (err == 0)
175-
err |= restore_crunch_context(&aux->crunch);
217+
err |= restore_crunch_context(&aux);
176218
#endif
177219
#ifdef CONFIG_IWMMXT
178-
if (err == 0 && test_thread_flag(TIF_USING_IWMMXT))
179-
err |= restore_iwmmxt_context(&aux->iwmmxt);
220+
if (err == 0)
221+
err |= restore_iwmmxt_context(&aux);
180222
#endif
181223
#ifdef CONFIG_VFP
182224
if (err == 0)
183-
err |= restore_vfp_context(&aux->vfp);
225+
err |= restore_vfp_context(&aux);
184226
#endif
185227

186228
return err;
@@ -286,7 +328,7 @@ setup_sigframe(struct sigframe __user *sf, struct pt_regs *regs, sigset_t *set)
286328
err |= preserve_crunch_context(&aux->crunch);
287329
#endif
288330
#ifdef CONFIG_IWMMXT
289-
if (err == 0 && test_thread_flag(TIF_USING_IWMMXT))
331+
if (err == 0)
290332
err |= preserve_iwmmxt_context(&aux->iwmmxt);
291333
#endif
292334
#ifdef CONFIG_VFP

0 commit comments

Comments
 (0)