Skip to content

Commit 99feaa7

Browse files
Philipp RudoMartin Schwidefsky
authored andcommitted
s390/kexec_file: Create ipl report and pass to next kernel
Signed-off-by: Philipp Rudo <[email protected]> Signed-off-by: Martin Schwidefsky <[email protected]>
1 parent e23a802 commit 99feaa7

File tree

5 files changed

+86
-9
lines changed

5 files changed

+86
-9
lines changed

arch/s390/include/asm/ipl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ struct ipl_parameter_block {
3636

3737
#define IPL_MAX_SUPPORTED_VERSION (0)
3838

39+
#define IPL_RB_CERT_UNKNOWN ((unsigned short)-1)
40+
3941
#define DIAG308_VMPARM_SIZE (64)
4042
#define DIAG308_SCPDATA_OFFSET offsetof(struct ipl_parameter_block, \
4143
fcp.scp_data)

arch/s390/include/asm/kexec.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ struct s390_load_data {
6363

6464
/* Total size of loaded segments in memory. Used as an offset. */
6565
size_t memsz;
66+
67+
struct ipl_report *report;
6668
};
6769

6870
int s390_verify_sig(const char *kernel, unsigned long kernel_len);

arch/s390/kernel/kexec_elf.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/errno.h>
1111
#include <linux/kernel.h>
1212
#include <linux/kexec.h>
13+
#include <asm/ipl.h>
1314
#include <asm/setup.h>
1415

1516
static int kexec_file_add_kernel_elf(struct kimage *image,
@@ -50,6 +51,10 @@ static int kexec_file_add_kernel_elf(struct kimage *image,
5051
data->parm = buf.buffer + PARMAREA;
5152
}
5253

54+
ipl_report_add_component(data->report, &buf,
55+
IPL_RB_COMPONENT_FLAG_SIGNED |
56+
IPL_RB_COMPONENT_FLAG_VERIFIED,
57+
IPL_RB_CERT_UNKNOWN);
5358
ret = kexec_add_buffer(&buf);
5459
if (ret)
5560
return ret;

arch/s390/kernel/kexec_image.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/errno.h>
1111
#include <linux/kernel.h>
1212
#include <linux/kexec.h>
13+
#include <asm/ipl.h>
1314
#include <asm/setup.h>
1415

1516
static int kexec_file_add_kernel_image(struct kimage *image,
@@ -32,6 +33,10 @@ static int kexec_file_add_kernel_image(struct kimage *image,
3233
data->parm = image->kernel_buf + PARMAREA;
3334
data->memsz += buf.memsz;
3435

36+
ipl_report_add_component(data->report, &buf,
37+
IPL_RB_COMPONENT_FLAG_SIGNED |
38+
IPL_RB_COMPONENT_FLAG_VERIFIED,
39+
IPL_RB_CERT_UNKNOWN);
3540
return kexec_add_buffer(&buf);
3641
}
3742

arch/s390/kernel/machine_kexec_file.c

Lines changed: 72 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/kexec.h>
1313
#include <linux/module.h>
1414
#include <linux/verification.h>
15+
#include <asm/boot_data.h>
1516
#include <asm/ipl.h>
1617
#include <asm/setup.h>
1718

@@ -150,9 +151,9 @@ static int kexec_file_add_purgatory(struct kimage *image,
150151
ret = kexec_load_purgatory(image, &buf);
151152
if (ret)
152153
return ret;
154+
data->memsz += buf.memsz;
153155

154-
ret = kexec_file_update_purgatory(image, data);
155-
return ret;
156+
return kexec_file_update_purgatory(image, data);
156157
}
157158

158159
static int kexec_file_add_initrd(struct kimage *image,
@@ -177,7 +178,60 @@ static int kexec_file_add_initrd(struct kimage *image,
177178
data->memsz += buf.memsz;
178179

179180
ret = kexec_add_buffer(&buf);
180-
return ret;
181+
if (ret)
182+
return ret;
183+
184+
return ipl_report_add_component(data->report, &buf, 0, 0);
185+
}
186+
187+
static int kexec_file_add_ipl_report(struct kimage *image,
188+
struct s390_load_data *data)
189+
{
190+
__u32 *lc_ipl_parmblock_ptr;
191+
unsigned int len, ncerts;
192+
struct kexec_buf buf;
193+
unsigned long addr;
194+
void *ptr, *end;
195+
196+
buf.image = image;
197+
198+
data->memsz = ALIGN(data->memsz, PAGE_SIZE);
199+
buf.mem = data->memsz;
200+
if (image->type == KEXEC_TYPE_CRASH)
201+
buf.mem += crashk_res.start;
202+
203+
ptr = (void *)ipl_cert_list_addr;
204+
end = ptr + ipl_cert_list_size;
205+
ncerts = 0;
206+
while (ptr < end) {
207+
ncerts++;
208+
len = *(unsigned int *)ptr;
209+
ptr += sizeof(len);
210+
ptr += len;
211+
}
212+
213+
addr = data->memsz + data->report->size;
214+
addr += ncerts * sizeof(struct ipl_rb_certificate_entry);
215+
ptr = (void *)ipl_cert_list_addr;
216+
while (ptr < end) {
217+
len = *(unsigned int *)ptr;
218+
ptr += sizeof(len);
219+
ipl_report_add_certificate(data->report, ptr, addr, len);
220+
addr += len;
221+
ptr += len;
222+
}
223+
224+
buf.buffer = ipl_report_finish(data->report);
225+
buf.bufsz = data->report->size;
226+
buf.memsz = buf.bufsz;
227+
228+
data->memsz += buf.memsz;
229+
230+
lc_ipl_parmblock_ptr =
231+
data->kernel_buf + offsetof(struct lowcore, ipl_parmblock_ptr);
232+
*lc_ipl_parmblock_ptr = (__u32)buf.mem;
233+
234+
return kexec_add_buffer(&buf);
181235
}
182236

183237
void *kexec_file_add_components(struct kimage *image,
@@ -187,12 +241,18 @@ void *kexec_file_add_components(struct kimage *image,
187241
struct s390_load_data data = {0};
188242
int ret;
189243

244+
data.report = ipl_report_init(&ipl_block);
245+
if (IS_ERR(data.report))
246+
return data.report;
247+
190248
ret = add_kernel(image, &data);
191249
if (ret)
192-
return ERR_PTR(ret);
250+
goto out;
193251

194-
if (image->cmdline_buf_len >= ARCH_COMMAND_LINE_SIZE)
195-
return ERR_PTR(-EINVAL);
252+
if (image->cmdline_buf_len >= ARCH_COMMAND_LINE_SIZE) {
253+
ret = -EINVAL;
254+
goto out;
255+
}
196256
memcpy(data.parm->command_line, image->cmdline_buf,
197257
image->cmdline_buf_len);
198258

@@ -204,12 +264,12 @@ void *kexec_file_add_components(struct kimage *image,
204264
if (image->initrd_buf) {
205265
ret = kexec_file_add_initrd(image, &data);
206266
if (ret)
207-
return ERR_PTR(ret);
267+
goto out;
208268
}
209269

210270
ret = kexec_file_add_purgatory(image, &data);
211271
if (ret)
212-
return ERR_PTR(ret);
272+
goto out;
213273

214274
if (data.kernel_mem == 0) {
215275
unsigned long restart_psw = 0x0008000080000000UL;
@@ -218,7 +278,10 @@ void *kexec_file_add_components(struct kimage *image,
218278
image->start = 0;
219279
}
220280

221-
return NULL;
281+
ret = kexec_file_add_ipl_report(image, &data);
282+
out:
283+
ipl_report_free(data.report);
284+
return ERR_PTR(ret);
222285
}
223286

224287
int arch_kexec_apply_relocations_add(struct purgatory_info *pi,

0 commit comments

Comments
 (0)