powerpc: Expose BookE debug registers through extended ptrace interface
Quoted 1 line
From shaggy at linux.vnet.ibm.com Tue Jan 19 08:57:04 2010
From: shaggy at linux.vnet.ibm.com (Dave Kleikamp)
Date: Mon, 18 Jan 2010 14:57:04 -0700
Subject: [RFC:PATCH 00/03] powerpc: Expose BookE debug registers through
extended ptrace interface
Message-ID: <[email protected]>
Quoted 2 lines
These patches implement an extention to the ptrace interface proposed by Thiago Bauermann and the the PowerPC gdb team.
(Using the plain text from mail archive..mail may not be in the usual mail-reply format...kindly bear).
Hi,
First of all, thanks for bringing this patch that puts the debug
registers in BookE to good use! I learnt about this patch submission only recently...please see some of my concerns as under.
Given that there now exists generic kernel interfaces to use hw-breakpoints - register_user_hw_breakpoint() and unregister_hw_breakpoint() (available in mainline since 2.6.33-rc1), it would be prudent to use them for the ptrace requests (that are made in arch_ptrace()).
This would mean that some of the arch-specific debug register code that read/write from/to the debug registers of Book-E may have to be in a form that closely resembles arch/<x86><power>/kernel/hw_breakpoint.c
A patch that enables arch-specific code for PPC64 is already submitted (linuxppc-dev ref: [email protected]). This converts ptrace requests for PTRACE_<GET><SET>_DEBUGREG flags to use the above-mentioned interfaces for PPC64.
If you intend to re-write this patch to use the generic hw-breakpoint interfaces (which I strongly recommend you to do, for the reasons mentioned below), I would be more than glad to help you port them.
Some of the benefits of using these generic interfaces include:
- Interoperability with other users of debug register (such as parallel kernel requests) i.e. non-exclusive use of debug registers.
- Enables debugging/tracing tools such as perf-events and ftrace to make use of debug registers.
- Re-use of common code available in kernel (kernel/hw_breakpoint.c).
Let me know what you think.
Thanks,
K.Prasad
Quoted 11 lines · K.Prasad
Some of the benefits of using these generic interfaces include:
- Interoperability with other users of debug register (such as parallel
kernel requests) i.e. non-exclusive use of debug registers.
- Enables debugging/tracing tools such as perf-events and ftrace to make
use of debug registers.
- Re-use of common code available in kernel (kernel/hw_breakpoint.c).Let me know what you think.
This might have changed but last I looked the "generic" breakpoint interface was still too x86-centric and wasn't capable of expressing some of the features of the BookE debug register set such as the data value compare, the ranged breakpoints, etc...
I'd rather have this more dedicated and more complete interface merged for gdb's sake, and in a second step look at unifying.
I believe that the generic breakpoint infrastructure should not be the mid-layer. IE. It cannot be made in any clean shape of form, to express all of the subtle features that a given architecture or platform can support and as such would always be inferior to a dedicated one.
I can see the interest in exposing some kind of generic API that implements a common subset of breakpoint or watchpoint facilities to generic code such as the event tracer. This could be layered on top of an arch specific mechanism
But having the generic mechanism at the core for everybody is another attempt of "make everybody look like x86" which I believe in this case is sub optimal.
Again, I might have missed some evolutions of the latest versions of your infrastructure that would make it good enough to fully bridge the gap with our requirements, and I'll let Shaggy decide here what he wants to do. But I will not block his current patches neither if he thinks that they are good enough as is.
Cheers,
Ben.
Quoted 13 lines · Benjamin Herrenschmidt
Quoted 11 lines · K.Prasad
Some of the benefits of using these generic interfaces include:
- Interoperability with other users of debug register (such as parallel
kernel requests) i.e. non-exclusive use of debug registers.
- Enables debugging/tracing tools such as perf-events and ftrace to make
use of debug registers.
- Re-use of common code available in kernel (kernel/hw_breakpoint.c).Let me know what you think.
Quoted 8 lines
This might have changed but last I looked the "generic" breakpoint interface was still too x86-centric and wasn't capable of expressing some of the features of the BookE debug register set such as the data value compare, the ranged breakpoints, etc...
I'd rather have this more dedicated and more complete interface merged for gdb's sake, and in a second step look at unifying.
While the hw-breakpoint infrastructure is more generic (than what can be termed x86-centric), it cannot support sophisticated features like DVC register - atleast in its present form.
My idea was to align the Book-E processor's use of debug registers with the existing breakpoint framework, and in the process make improvements/ changes to the common framework as necessitated.
It could be done in a two-step process to ease the development and review process (more on this below).
Quoted 10 lines
I believe that the generic breakpoint infrastructure should not be the mid-layer. IE. It cannot be made in any clean shape of form, to express all of the subtle features that a given architecture or platform can support and as such would always be inferior to a dedicated one.
I can see the interest in exposing some kind of generic API that implements a common subset of breakpoint or watchpoint facilities to generic code such as the event tracer. This could be layered on top of an arch specific mechanism
Given the diversity of debug register implementation (across processors), concerns about having a poorly-featured mid-layer is understandable.
But our design goal is to be as flexible as required to accomodate newer architectures, while providing them the benefit of using the common framework - such as register arbitration (existing implementation would assume mutually exclusive access to debug registers), scheduling and abstraction through generic interfaces.
Quoted 4 lines
But having the generic mechanism at the core for everybody is another attempt of "make everybody look like x86" which I believe in this case is sub optimal.
No, it is not! In fact patches that port the framework to PPC64 and S390 have already been posted to the respective communities and are under review.
Quoted 6 lines
Again, I might have missed some evolutions of the latest versions of your infrastructure that would make it good enough to fully bridge the gap with our requirements, and I'll let Shaggy decide here what he wants to do. But I will not block his current patches neither if he thinks that they are good enough as is.
As I mentioned above, the generic framework may need to be extended to support all features required by processors such as Book-E. Any feature that is very unique to a given processor and exotic to the hw-breakpoint framework can be kept outside its purview (and implemented to support only ptrace with exclusive access to those registers).
Sure, let's wait to hear from Shaggy to know how he'd like to proceed.
Thanks,
K.Prasad
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 10 lines · K.Prasad
Some of the benefits of using these generic interfaces include:
- Interoperability with other users of debug register (such as parallel
kernel requests) i.e. non-exclusive use of debug registers.
- Enables debugging/tracing tools such as perf-events and ftrace to make
use of debug registers.
- Re-use of common code available in kernel (kernel/hw_breakpoint.c).
Quoted 6 lines
Quoted 1 line
Let me know what you think.
This might have changed but last I looked the "generic" breakpoint interface was still too x86-centric and wasn't capable of expressing some of the features of the BookE debug register set such as the data value compare, the ranged breakpoints, etc...
We have one field for addr, one for len and one for the memory access type.
I think that those three are enough to express breakpoint ranges. Basically a breakpoint range is a breakpoint that can have a high len.
I've looked at the G2 PowerPc core breakpoint implementation, just to face one of such tricky examples.
We have DABR and DABR2 for watchpoint (and respectively IABR and IABR2 for ins breakpoints). Those host the addresses to target, or well, let's rather call them "address operand" registers. To generalize, I call these xABR and xABR2 as it seems instruction and data breakpoint work the same, they just have their own dedicated registers.
Then you have DBCR/IBCR (let's call them xBCR) which control the breakpoints, with two fields in each that detail the operators to affect in the address operands registers. You can choose betwen ==, <, or >= .
Another field in the operator is the SIG_TYPE, which describes the combination, either "matches xABR AND xABR2" or "matches xABR OR xABR2".
If you choose the "OR" SIG_TYPE, it makes no sense to use the < or >= operators on the addresses operands in practice. Who needs the following matches?
addr < xABR || addr >= xABR2 addr < xABR || addr < xABR2 addr >= xABR || addr >= xABR2
The only operator that makes sense in a OR type is ==, which basically provides you two breakpoints:
addr == xABR || addr == xABR2
Now if you choose the "AND" SIG_TYPE, the following matches make no sense:
addr < xABR && addr < xABR2 addr < xABR && addr >= xABR2 (if xABR < xABR2) addr == xABR && addr (>=,<) xABR2
Basically, it's only usable for delimited ranges:
addr >= xABR && addr < xABR2 (xABR < xABR2)
So the comparison is a trick that can actually only have a practical use to define two exact matching breakpoints or a delimited breakpoint range.
Hence, unless I'm missing something obvious, the current generic interface is sufficient to express that.
I may also miss other kind of implementation that could have other requirements.
Quoted 2 lines
I'd rather have this more dedicated and more complete interface merged for gdb's sake, and in a second step look at unifying.
Perhaps. Supporting ptrace breakpoints should be an easy first step as it's basically the responsibility of the user to fill the registers, but it's a pretty limited scope work, especially you won't have perf support.
Quoted 4 lines
I believe that the generic breakpoint infrastructure should not be the mid-layer. IE. It cannot be made in any clean shape of form, to express all of the subtle features that a given architecture or platform can support and as such would always be inferior to a dedicated one.
Actually I think the current interface already does, as I explained above.
What is broken for any other architectures than x86 is the set of constraints, but I can easily move it to the arch, unless I find a good generic solution (or a cool combination between both).
Quoted 8 lines
I can see the interest in exposing some kind of generic API that implements a common subset of breakpoint or watchpoint facilities to generic code such as the event tracer. This could be layered on top of an arch specific mechanism
But having the generic mechanism at the core for everybody is another attempt of "make everybody look like x86" which I believe in this case is sub optimal.
Not at all. It's an attempt to make a generic interface that can exploit at best _each_ arch specific features. Other than the set of constraints that I'm going to rework, the generic interface is powerful enough to host what I've seen in term of cpu breakpoints implementations for now. But if it's actually not and I'm missing other cases, please report it to me.
The reason that makes the current generic constraints x86 oriented only is that I've only x86 boxes at home and I needed to make a first shot without knowing anything about other archs constraints, but in the long term, our motivations (Prasad's and mines) are definetely not archX-centric.
Quoted 10 lines
We have one field for addr, one for len and one for the memory access type.
I think that those three are enough to express breakpoint ranges. Basically a breakpoint range is a breakpoint that can have a high len.
I've looked at the G2 PowerPc core breakpoint implementation, just to face one of such tricky examples.
BookE has a richer semantic. We have watchpoints with data value compare for example, we also have instruction value compare for breakpoints, and a few other niceties. There's also subtle differences between what processor variants support.
.../...
Quoted 8 lines
Quoted 2 lines
I'd rather have this more dedicated and more complete interface merged for gdb's sake, and in a second step look at unifying.
Perhaps. Supporting ptrace breakpoints should be an easy first step as it's basically the responsibility of the user to fill the registers, but it's a pretty limited scope work, especially you won't have perf support.
But we can add it later.
Quoted 6 lines
Quoted 4 lines
I believe that the generic breakpoint infrastructure should not be the mid-layer. IE. It cannot be made in any clean shape of form, to express all of the subtle features that a given architecture or platform can support and as such would always be inferior to a dedicated one.
Quoted 7 lines
Actually I think the current interface already does, as I explained above.
What is broken for any other architectures than x86 is the set of constraints, but I can easily move it to the arch, unless I find a good generic solution (or a cool combination between both).
Again, this is all "can do" vs. "already done and working". May I point you to Linus recent rant against magic infrastructures that try to do everything and do nothing right ? :-) I much prefer starting with something dedicated that does exactly what is expected, have that upstream (and in that regard the patches are good for the next merge window) and -then- maybe look at how some of it could be re-used for perf.
Quoted 2 lines
Not at all. It's an attempt to make a generic interface that can exploit at best _each_ arch specific features.
That reminds me of the justifications for utrace :-) It might well be but I very much doubt that is possible. In any case, it doesn't appear to be there yet. So let's just get that stuff in so we have our interface finally working, and we can look at doing fancy things with perf in a second pass.
Quoted 11 lines
Other than the set
of constraints that I'm going to rework, the generic interface is powerful enough to host what I've seen in term of cpu breakpoints implementations for now. But if it's actually not and I'm missing other cases, please report it to me.The reason that makes the current generic constraints x86 oriented only is that I've only x86 boxes at home and I needed to make a first shot without knowing anything about other archs constraints, but in the long term, our motivations (Prasad's and mines) are definetely not archX-centric.
Cheers,
Ben.
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 10 lines
We have one field for addr, one for len and one for the memory access type.
I think that those three are enough to express breakpoint ranges. Basically a breakpoint range is a breakpoint that can have a high len.
I've looked at the G2 PowerPc core breakpoint implementation, just to face one of such tricky examples.
Quoted 6 lines
BookE has a richer semantic. We have watchpoints with data value compare for example, we also have instruction value compare for breakpoints, and a few other niceties. There's also subtle differences between what processor variants support.
.../...
Ah indeed, I missed the data value compare thing. Especially how it is implemented won't make things easy.
This is basically a comparison against chosen bytes of the data, with or/and patterns.
Not sure what the "or" can be useful for.
That won't be easy to implement in the generic interface, looking at how it is done in the BookE.
There is also the address comparison by mask.
Anyway, I think we can add fields in the interface to provide such features, but we can't support all of them given, as you said, the subtle differences between different cpu.
For example I think it can be useful to implement support for data comparison, by mask for example. But I don't imagine useful usecases to compare byte 4 and byte1 and trigger an event if one OR other match.
I think we are going to implement what has obvious usecases (parts of such data comparisons, parts of address mask comparison) in the generic interface: the fields in perf_attr that can be filled by perf in userspace.
And the rest can be implemented from the hw_perf_event structure which contains the arch structure and can then be filled by ptrace at will.
Quoted 11 lines
Quoted 9 lines
Quoted 3 lines
I'd rather have this more dedicated and more complete interface merged for gdb's sake, and in a second step look at unifying.
Perhaps. Supporting ptrace breakpoints should be an easy first step as it's basically the responsibility of the user to fill the registers, but it's a pretty limited scope work, especially you won't have perf support.
But we can add it later.
Yeah you're right. Having a raw ptrace support is a first useful step that won't be a barrier to enhance it further through the generic API.
Quoted 14 lines
Quoted 6 lines
Quoted 4 lines
I believe that the generic breakpoint infrastructure should not be the mid-layer. IE. It cannot be made in any clean shape of form, to express all of the subtle features that a given architecture or platform can support and as such would always be inferior to a dedicated one.
Quoted 7 lines
Actually I think the current interface already does, as I explained above.
What is broken for any other architectures than x86 is the set of constraints, but I can easily move it to the arch, unless I find a good generic solution (or a cool combination between both).
Quoted 7 lines
Again, this is all "can do" vs. "already done and working". May I point you to Linus recent rant against magic infrastructures that try to do everything and do nothing right ? :-) I much prefer starting with something dedicated that does exactly what is expected, have that upstream (and in that regard the patches are good for the next merge window) and -then- maybe look at how some of it could be re-used for perf.
Sure I'm not against a first raw ptrace support. As I said, this is not a barrier for what comes next.
Now for the rest, I don't think this is the same story than utrace.
Trying to have a generic layer for a hardware feature implemented differently across archs can't be called something that tries to do everything. Otherwise you can oppose these arguments to everything that is not in the arch/ directories. No generic irq layer, no generic timer, etc...
We need this generic layer because we want the breakpoints to be available for wider uses than ptrace. If there was only ptrace, I would really agree with you that it's not worth the generic layer.
It's just that breakpoints are a set of possible features, but each archs implement its own subset among the possible features. x86 is one of the weakest there, and since this generic layer has been first x86 oriented, it looks too weak to host the most interesting possibilities.
Let it grow a bit, it's still young.
Quoted 6 lines
Quoted 2 lines
Not at all. It's an attempt to make a generic interface that can exploit at best _each_ arch specific features.
That reminds me of the justifications for utrace :-) It might well be but I very much doubt that is possible. In any case, it doesn't appear to be there yet.
You are too pessimistic ;-)
I don't think we can express every possibilities through the generic interface. But we can express the most interesting ones for profiling uses.
The rest (ptrace) can still be expressed through the arch part of the perf events.
Quoted 3 lines
So let's just get that stuff in so we have our
interface finally working, and we can look at doing fancy things with perf in a second pass.
Sure.