Re: [PATCH] kprobes for s390 architecture

From: Heiko Carstens
Date: Fri Jun 23 2006 - 18:21:02 EST


> On the same page it says "All copies of a prefetched instruction are
> discarded
> when: * A serializing function is performed" Would something like this in a
> smp_call_function do it? :
>
> bcr 15,0
>
> if (*p->addr != breakpoint_instruction)
> *p->addr = breakpoint_instruction;
>
>
> Alternatively, if we did a compare and swap on that location (serializing
> instruction) would that be acceptable?
>
> Thanks
> Michael

The crap below is something that could solve your problem (assumes that "a"
is the address of the instruction to be replaced and 0x42 is the opcode of
the new instruction):

- generates an irq on all other cpus -> prefetched stuff on them discarded
- catches all cpus
- writes the new instruction
- the atomic_inc(&cap.done) is a compare and swap instruction -> serialization

At least this is something that could work... completely untested and might
have some problems that I didn't think of ;)

struct capture_data {
atomic_t cpus;
atomic_t done;
};

void capture_wait(void *data)
{
struct capture_data *cap = data;

atomic_inc(&cap->cpus);
while(!atomic_read(&cap->done))
cpu_relax();
atomic_dec(&cap->cpus);
}

void replace_instr(int *a)
{
struct capture_data cap;

preempt_disable();
atomic_set(&cap.cpus, 0);
atomic_set(&cap.done, 0);
smp_call_function(capture_wait, (void *)&cap, 0, 0);
while (atomic_read(&cap.cpus) != num_online_cpus() - 1)
cpu_relax();
*a = 0x42;
atomic_inc(&cap.done);
while (atomic_read(&cap.cpus))
cpu_relax();
preempt_enable();
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/