Skip to content

Commit 2ebc8ec

Browse files
committed
Merge branch 'for-linus' of git://git390.marist.edu/pub/scm/linux-2.6
* 'for-linus' of git://git390.marist.edu/pub/scm/linux-2.6: [S390] kprobes: Fix the return address of multiple kretprobes [S390] kprobes: disable interrupts throughout [S390] ftrace: build without frame pointers on s390 [S390] mm: add devmem_is_allowed() for STRICT_DEVMEM checking [S390] vmlogrdr: purge after recording is switched off [S390] cio: fix incorrect ccw_device_init_count [S390] tape: add medium state notifications [S390] fix get_user_pages_fast
2 parents df6e61d + 8948080 commit 2ebc8ec

8 files changed

Lines changed: 167 additions & 44 deletions

File tree

‎arch/s390/Kconfig.debug‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ config TRACE_IRQFLAGS_SUPPORT
66

77
source "lib/Kconfig.debug"
88

9+
config STRICT_DEVMEM
10+
def_bool y
11+
prompt "Filter access to /dev/mem"
12+
---help---
13+
This option restricts access to /dev/mem. If this option is
14+
disabled, you allow userspace access to all memory, including
15+
kernel and userspace memory. Accidental memory access is likely
16+
to be disastrous.
17+
Memory access is required for experts who want to debug the kernel.
18+
19+
If you are unsure, say Y.
20+
921
config DEBUG_STRICT_USER_COPY_CHECKS
1022
bool "Strict user copy size checks"
1123
---help---

‎arch/s390/include/asm/page.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ struct page;
130130
void arch_free_page(struct page *page, int order);
131131
void arch_alloc_page(struct page *page, int order);
132132

133+
static inline int devmem_is_allowed(unsigned long pfn)
134+
{
135+
return 0;
136+
}
137+
133138
#define HAVE_ARCH_FREE_PAGE
134139
#define HAVE_ARCH_ALLOC_PAGE
135140

‎arch/s390/kernel/kprobes.c‎

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <asm/sections.h>
3131
#include <linux/module.h>
3232
#include <linux/slab.h>
33+
#include <linux/hardirq.h>
3334

3435
DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
3536
DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
@@ -212,7 +213,7 @@ static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
212213
/* Set the PER control regs, turns on single step for this address */
213214
__ctl_load(kprobe_per_regs, 9, 11);
214215
regs->psw.mask |= PSW_MASK_PER;
215-
regs->psw.mask &= ~(PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK);
216+
regs->psw.mask &= ~(PSW_MASK_IO | PSW_MASK_EXT);
216217
}
217218

218219
static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
@@ -239,7 +240,7 @@ static void __kprobes set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
239240
__get_cpu_var(current_kprobe) = p;
240241
/* Save the interrupt and per flags */
241242
kcb->kprobe_saved_imask = regs->psw.mask &
242-
(PSW_MASK_PER | PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK);
243+
(PSW_MASK_PER | PSW_MASK_IO | PSW_MASK_EXT);
243244
/* Save the control regs that govern PER */
244245
__ctl_store(kcb->kprobe_saved_ctl, 9, 11);
245246
}
@@ -316,8 +317,6 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
316317
return 1;
317318

318319
ss_probe:
319-
if (regs->psw.mask & (PSW_MASK_PER | PSW_MASK_IO))
320-
local_irq_disable();
321320
prepare_singlestep(p, regs);
322321
kcb->kprobe_status = KPROBE_HIT_SS;
323322
return 1;
@@ -350,6 +349,7 @@ static int __kprobes trampoline_probe_handler(struct kprobe *p,
350349
struct hlist_node *node, *tmp;
351350
unsigned long flags, orig_ret_address = 0;
352351
unsigned long trampoline_address = (unsigned long)&kretprobe_trampoline;
352+
kprobe_opcode_t *correct_ret_addr = NULL;
353353

354354
INIT_HLIST_HEAD(&empty_rp);
355355
kretprobe_hash_lock(current, &head, &flags);
@@ -372,10 +372,32 @@ static int __kprobes trampoline_probe_handler(struct kprobe *p,
372372
/* another task is sharing our hash bucket */
373373
continue;
374374

375-
if (ri->rp && ri->rp->handler)
376-
ri->rp->handler(ri, regs);
375+
orig_ret_address = (unsigned long)ri->ret_addr;
376+
377+
if (orig_ret_address != trampoline_address)
378+
/*
379+
* This is the real return address. Any other
380+
* instances associated with this task are for
381+
* other calls deeper on the call stack
382+
*/
383+
break;
384+
}
385+
386+
kretprobe_assert(ri, orig_ret_address, trampoline_address);
387+
388+
correct_ret_addr = ri->ret_addr;
389+
hlist_for_each_entry_safe(ri, node, tmp, head, hlist) {
390+
if (ri->task != current)
391+
/* another task is sharing our hash bucket */
392+
continue;
377393

378394
orig_ret_address = (unsigned long)ri->ret_addr;
395+
396+
if (ri->rp && ri->rp->handler) {
397+
ri->ret_addr = correct_ret_addr;
398+
ri->rp->handler(ri, regs);
399+
}
400+
379401
recycle_rp_inst(ri, &empty_rp);
380402

381403
if (orig_ret_address != trampoline_address) {
@@ -387,7 +409,7 @@ static int __kprobes trampoline_probe_handler(struct kprobe *p,
387409
break;
388410
}
389411
}
390-
kretprobe_assert(ri, orig_ret_address, trampoline_address);
412+
391413
regs->psw.addr = orig_ret_address | PSW_ADDR_AMODE;
392414

393415
reset_current_kprobe();
@@ -465,8 +487,6 @@ static int __kprobes post_kprobe_handler(struct pt_regs *regs)
465487
goto out;
466488
}
467489
reset_current_kprobe();
468-
if (regs->psw.mask & (PSW_MASK_PER | PSW_MASK_IO))
469-
local_irq_enable();
470490
out:
471491
preempt_enable_no_resched();
472492

@@ -482,7 +502,7 @@ static int __kprobes post_kprobe_handler(struct pt_regs *regs)
482502
return 1;
483503
}
484504

485-
int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
505+
static int __kprobes kprobe_trap_handler(struct pt_regs *regs, int trapnr)
486506
{
487507
struct kprobe *cur = kprobe_running();
488508
struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
@@ -508,8 +528,6 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
508528
restore_previous_kprobe(kcb);
509529
else {
510530
reset_current_kprobe();
511-
if (regs->psw.mask & (PSW_MASK_PER | PSW_MASK_IO))
512-
local_irq_enable();
513531
}
514532
preempt_enable_no_resched();
515533
break;
@@ -553,15 +571,31 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
553571
return 0;
554572
}
555573

574+
int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
575+
{
576+
int ret;
577+
578+
if (regs->psw.mask & (PSW_MASK_IO | PSW_MASK_EXT))
579+
local_irq_disable();
580+
ret = kprobe_trap_handler(regs, trapnr);
581+
if (regs->psw.mask & (PSW_MASK_IO | PSW_MASK_EXT))
582+
local_irq_restore(regs->psw.mask & ~PSW_MASK_PER);
583+
return ret;
584+
}
585+
556586
/*
557587
* Wrapper routine to for handling exceptions.
558588
*/
559589
int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
560590
unsigned long val, void *data)
561591
{
562592
struct die_args *args = (struct die_args *)data;
593+
struct pt_regs *regs = args->regs;
563594
int ret = NOTIFY_DONE;
564595

596+
if (regs->psw.mask & (PSW_MASK_IO | PSW_MASK_EXT))
597+
local_irq_disable();
598+
565599
switch (val) {
566600
case DIE_BPT:
567601
if (kprobe_handler(args->regs))
@@ -572,16 +606,17 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
572606
ret = NOTIFY_STOP;
573607
break;
574608
case DIE_TRAP:
575-
/* kprobe_running() needs smp_processor_id() */
576-
preempt_disable();
577-
if (kprobe_running() &&
578-
kprobe_fault_handler(args->regs, args->trapnr))
609+
if (!preemptible() && kprobe_running() &&
610+
kprobe_trap_handler(args->regs, args->trapnr))
579611
ret = NOTIFY_STOP;
580-
preempt_enable();
581612
break;
582613
default:
583614
break;
584615
}
616+
617+
if (regs->psw.mask & (PSW_MASK_IO | PSW_MASK_EXT))
618+
local_irq_restore(regs->psw.mask & ~PSW_MASK_PER);
619+
585620
return ret;
586621
}
587622

@@ -595,6 +630,7 @@ int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
595630

596631
/* setup return addr to the jprobe handler routine */
597632
regs->psw.addr = (unsigned long)(jp->entry) | PSW_ADDR_AMODE;
633+
regs->psw.mask &= ~(PSW_MASK_IO | PSW_MASK_EXT);
598634

599635
/* r14 is the function return address */
600636
kcb->jprobe_saved_r14 = (unsigned long)regs->gprs[14];

‎arch/s390/mm/gup.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,17 @@
2020
static inline int gup_pte_range(pmd_t *pmdp, pmd_t pmd, unsigned long addr,
2121
unsigned long end, int write, struct page **pages, int *nr)
2222
{
23-
unsigned long mask, result;
23+
unsigned long mask;
2424
pte_t *ptep, pte;
2525
struct page *page;
2626

27-
result = write ? 0 : _PAGE_RO;
28-
mask = result | _PAGE_INVALID | _PAGE_SPECIAL;
27+
mask = (write ? _PAGE_RO : 0) | _PAGE_INVALID | _PAGE_SPECIAL;
2928

3029
ptep = ((pte_t *) pmd_deref(pmd)) + pte_index(addr);
3130
do {
3231
pte = *ptep;
3332
barrier();
34-
if ((pte_val(pte) & mask) != result)
33+
if ((pte_val(pte) & mask) != 0)
3534
return 0;
3635
VM_BUG_ON(!pfn_valid(pte_pfn(pte)));
3736
page = pte_page(pte);

‎drivers/s390/char/tape_core.c‎

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,29 +209,79 @@ tape_state_set(struct tape_device *device, enum tape_state newstate)
209209
wake_up(&device->state_change_wq);
210210
}
211211

212+
struct tape_med_state_work_data {
213+
struct tape_device *device;
214+
enum tape_medium_state state;
215+
struct work_struct work;
216+
};
217+
218+
static void
219+
tape_med_state_work_handler(struct work_struct *work)
220+
{
221+
static char env_state_loaded[] = "MEDIUM_STATE=LOADED";
222+
static char env_state_unloaded[] = "MEDIUM_STATE=UNLOADED";
223+
struct tape_med_state_work_data *p =
224+
container_of(work, struct tape_med_state_work_data, work);
225+
struct tape_device *device = p->device;
226+
char *envp[] = { NULL, NULL };
227+
228+
switch (p->state) {
229+
case MS_UNLOADED:
230+
pr_info("%s: The tape cartridge has been successfully "
231+
"unloaded\n", dev_name(&device->cdev->dev));
232+
envp[0] = env_state_unloaded;
233+
kobject_uevent_env(&device->cdev->dev.kobj, KOBJ_CHANGE, envp);
234+
break;
235+
case MS_LOADED:
236+
pr_info("%s: A tape cartridge has been mounted\n",
237+
dev_name(&device->cdev->dev));
238+
envp[0] = env_state_loaded;
239+
kobject_uevent_env(&device->cdev->dev.kobj, KOBJ_CHANGE, envp);
240+
break;
241+
default:
242+
break;
243+
}
244+
tape_put_device(device);
245+
kfree(p);
246+
}
247+
248+
static void
249+
tape_med_state_work(struct tape_device *device, enum tape_medium_state state)
250+
{
251+
struct tape_med_state_work_data *p;
252+
253+
p = kzalloc(sizeof(*p), GFP_ATOMIC);
254+
if (p) {
255+
INIT_WORK(&p->work, tape_med_state_work_handler);
256+
p->device = tape_get_device(device);
257+
p->state = state;
258+
schedule_work(&p->work);
259+
}
260+
}
261+
212262
void
213263
tape_med_state_set(struct tape_device *device, enum tape_medium_state newstate)
214264
{
215-
if (device->medium_state == newstate)
265+
enum tape_medium_state oldstate;
266+
267+
oldstate = device->medium_state;
268+
if (oldstate == newstate)
216269
return;
270+
device->medium_state = newstate;
217271
switch(newstate){
218272
case MS_UNLOADED:
219273
device->tape_generic_status |= GMT_DR_OPEN(~0);
220-
if (device->medium_state == MS_LOADED)
221-
pr_info("%s: The tape cartridge has been successfully "
222-
"unloaded\n", dev_name(&device->cdev->dev));
274+
if (oldstate == MS_LOADED)
275+
tape_med_state_work(device, MS_UNLOADED);
223276
break;
224277
case MS_LOADED:
225278
device->tape_generic_status &= ~GMT_DR_OPEN(~0);
226-
if (device->medium_state == MS_UNLOADED)
227-
pr_info("%s: A tape cartridge has been mounted\n",
228-
dev_name(&device->cdev->dev));
279+
if (oldstate == MS_UNLOADED)
280+
tape_med_state_work(device, MS_LOADED);
229281
break;
230282
default:
231-
// print nothing
232283
break;
233284
}
234-
device->medium_state = newstate;
235285
wake_up(&device->state_change_wq);
236286
}
237287

‎drivers/s390/char/vmlogrdr.c‎

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,27 +249,25 @@ static int vmlogrdr_recording(struct vmlogrdr_priv_t * logptr,
249249
char cp_command[80];
250250
char cp_response[160];
251251
char *onoff, *qid_string;
252+
int rc;
252253

253-
memset(cp_command, 0x00, sizeof(cp_command));
254-
memset(cp_response, 0x00, sizeof(cp_response));
255-
256-
onoff = ((action == 1) ? "ON" : "OFF");
254+
onoff = ((action == 1) ? "ON" : "OFF");
257255
qid_string = ((recording_class_AB == 1) ? " QID * " : "");
258256

259-
/*
257+
/*
260258
* The recording commands needs to be called with option QID
261259
* for guests that have previlege classes A or B.
262260
* Purging has to be done as separate step, because recording
263261
* can't be switched on as long as records are on the queue.
264262
* Doing both at the same time doesn't work.
265263
*/
266-
267-
if (purge) {
264+
if (purge && (action == 1)) {
265+
memset(cp_command, 0x00, sizeof(cp_command));
266+
memset(cp_response, 0x00, sizeof(cp_response));
268267
snprintf(cp_command, sizeof(cp_command),
269268
"RECORDING %s PURGE %s",
270269
logptr->recording_name,
271270
qid_string);
272-
273271
cpcmd(cp_command, cp_response, sizeof(cp_response), NULL);
274272
}
275273

@@ -279,19 +277,33 @@ static int vmlogrdr_recording(struct vmlogrdr_priv_t * logptr,
279277
logptr->recording_name,
280278
onoff,
281279
qid_string);
282-
283280
cpcmd(cp_command, cp_response, sizeof(cp_response), NULL);
284281
/* The recording command will usually answer with 'Command complete'
285282
* on success, but when the specific service was never connected
286283
* before then there might be an additional informational message
287284
* 'HCPCRC8072I Recording entry not found' before the
288-
* 'Command complete'. So I use strstr rather then the strncmp.
285+
* 'Command complete'. So I use strstr rather then the strncmp.
289286
*/
290287
if (strstr(cp_response,"Command complete"))
291-
return 0;
288+
rc = 0;
292289
else
293-
return -EIO;
290+
rc = -EIO;
291+
/*
292+
* If we turn recording off, we have to purge any remaining records
293+
* afterwards, as a large number of queued records may impact z/VM
294+
* performance.
295+
*/
296+
if (purge && (action == 0)) {
297+
memset(cp_command, 0x00, sizeof(cp_command));
298+
memset(cp_response, 0x00, sizeof(cp_response));
299+
snprintf(cp_command, sizeof(cp_command),
300+
"RECORDING %s PURGE %s",
301+
logptr->recording_name,
302+
qid_string);
303+
cpcmd(cp_command, cp_response, sizeof(cp_response), NULL);
304+
}
294305

306+
return rc;
295307
}
296308

297309

0 commit comments

Comments
 (0)