opentitan icon indicating copy to clipboard operation
opentitan copied to clipboard

Instantiating PMPs outside of ibex

Open tjaychen opened this issue 7 years ago • 16 comments

Is it possible to make PMP modularized such that we can instantiate it elsewhere as well? When we eventually introduce other hosts into our system (for example dma's, spi host capability etc), it will be good to extend the same privilege containment model. We could design something separate, but it feels like it would be the most clean if everyone followed the same programming model and HW that the processor actually uses.

What do you think?

tjaychen avatar Aug 07 '19 19:08 tjaychen

I haven't studied PMPs well enough to know how extendable they are, but it sounds like a good goal to have all access control logic look the same to software

sjgitty avatar Aug 07 '19 19:08 sjgitty

i think their region construction is not as flexible as i would like (you either move in powers of 2, or you consume a previous region to know what the lower bounds are), but is not unreasonable.

They have a locking option, which I think is great. If we move these outside of ibex, obviously there will be no concept of M or U, so we'd need to wrap the PMP a bit with some extra logic so that the core can set what privilege an incoming transaction is.

Alex I think had commented on the possibility of passing out the M / U information over the bus, that might be helpful.

tjaychen avatar Aug 07 '19 20:08 tjaychen

Maybe we implement the PMP as more flexible than the spec, then the one that is attached to Ibex follows per restrictions, and the others provide the extra flexibility. Or maybe we just have everyone use the PMP-extended, as long as it contains all the functionality. Again, spoken without really knowing the spec yet.

On Wed, Aug 7, 2019 at 1:08 PM tjaychen [email protected] wrote:

i think their region construction is not as flexible as i would like (you either move in powers of 2, or you consume a previous region to know what the lower bounds are), but is not unreasonable.

They have a locking option, which I think is great. If we move these outside of ibex, obviously there will be no concept of M or U, so we'd need to wrap the PMP a bit with some extra logic so that the core can set what privilege an incoming transaction is.

Alex I think had commented on the possibility of passing out the M / U information over the bus, that might be helpful.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/lowRISC/opentitan/issues/17?email_source=notifications&email_token=AJZQKVLGEXWK7J7YA7A7GKLQDMTSNA5CNFSM4IKDNH7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3ZR6VI#issuecomment-519249749, or mute the thread https://github.com/notifications/unsubscribe-auth/AJZQKVJVUJLRG4222UVMSWDQDMTSNANCNFSM4IKDNH7A .

sjgitty avatar Aug 07 '19 20:08 sjgitty

CCing in @tomroberts-lowrisc who is starting to look at PMPs for Ibex.

Just for clarity, is the main objective for this code reuse? i.e. we believe that we will likely want control registers that restrict access of other bus masters, and that we'll want at least similar flexibility so would have the same config register encoding etc. Given that, the thought is we might be able to reuse the code from Ibex?

As long as we're not delegating device access to unprivileged processes this sounds somewhat workable (or as Tim mentioned, we also discussed the possibility that U/M mode information could be sent over the bus - haven't thought about it enough to advocate it, but that's one logical possibility).

asb avatar Aug 08 '19 08:08 asb

Alex, actually maybe this is worth exploring a bit more.

If we assume for now, that access to devices (USB, spi or whatever block with host functionality) will be strictly under the control of privileged process, is it even necessary to have pmps for other hosts? My assumption here is that the region checking would all be done in software

In some of the other security discussions I'm having with Miguel / Chris, we think it's likely there are regions earlier stage software (ROM, boot loaders) might attempt to permanently lock off (this is where the lock function in pmp is handy), but if that is the only use case, instantiating a bunch of pmps may not be the right solution.

When I was thinking about putting pmps everywhere, it was more inline with the thinking that individual hosts might have their own processing element.

tjaychen avatar Aug 08 '19 15:08 tjaychen

Maybe this is obvious, but if it don't have other autonomous bus-mastering (sorry, not sure what the right term would be, bus-hosting?) bus hosts then I agree with @tjaychen that maybe PMP everywhere is overkill. If there's any possibility of a DMA controller/data-mover we'll probably need PMP almost everywhere - on all the hosts for sure.

At that point I agree with normalizing the semantics as much as possible, probably preferring @sjgitty's second idea (everyone use PMP-extended) based on my extremely brief tour of the PMP spec it seems possible/permissible to extend PMP to a superset.

I think there's two different sets of code re-use as well, the Verilog side and the C/device driver side, though they are closely linked.

cdgori avatar Aug 08 '19 23:08 cdgori

@cdgori totally agree. If the hosts do not just randomly start fetching on the bus, I don't think we need it. I'm a bit conflicted here... normally, hosts in this scale of chip should not behave that way..they are more or less extensions of SW's will.

I have however seen in bad reset / power-up scenarios where USB bus hosts would go out and start reading / writing data. So I am currently leaning towards just having the PMPs... since it would help with sandboxing unexpected faulty behavior.

I'm not very convinced though...

tjaychen avatar Aug 08 '19 23:08 tjaychen

@tjaychen yes I've seen similar bad power-up situations, the on-boot-read situations are potentially exploitable. That makes me think some PMPs will be necessary here.

cdgori avatar Aug 08 '19 23:08 cdgori

Let's separate the issues here:

  • Should there be control registers of some sort that restrict non-CPU bus hosts ability to access certain memory regions?
  • If so, should those control registers be similar in format and functionality to RISC-V PMPs?
  • And if so, is it worth trying to re-use the same RTL from the Ibex implementation?

One way it might be different for bus hosts is that there may be scope for setting a much, much more restricted ability to access the address space - i.e. a simple and very short (maybe single entry in the common case?) whitelist, updated by the core as necessary (and set at reset to allow no access). Of course having the ability to mark "never accessible" regions may be a useful belt-and-braces protection if we're concerned about the whitelist set by the CPU becoming corrupted.

asb avatar Aug 09 '19 03:08 asb

@asb Assuming we all agree the answer to bullet 1 is yes, I think the answer to the others should be yes as well. I really do think re-using the same programmer's model and code where we can makes sense.

You are right that the hosts may not need that much flexibility, and really are looking for something simpler, but I don't think the flexibility will hurt, especially if someone comes up with a different case in the future.

tjaychen avatar Aug 09 '19 03:08 tjaychen

Hi all - I currently have a PR open on Ibex to add the PMP module. Following this discussion I tried to make it as generic as possible in case we do want to reuse it in other places. Off the top of my head, it doesn't have its own register interface, that lives elsewhere in Ibex, and it doesn't support a larger transaction sizes (all accesses are 4 bytes in Ibex). If there are any features or extensions we think we need, I can add them as required.

tomeroberts avatar Aug 22 '19 08:08 tomeroberts

Thanks Tom!

Does the 4B alignment mean that we should probably just align whatever access we're issuing to the closest 4B boundary when performing the check? Im not suggesting we need byte granularity, but just wanted to confirm.

On Thu, Aug 22, 2019, 01:03 Tom Roberts [email protected] wrote:

Hi all - I currently have a PR open on Ibex to add the PMP module. Following this discussion I tried to make it as generic as possible in case we do want to reuse it in other places. Off the top of my head, it doesn't have its own register interface, that lives elsewhere in Ibex, and it doesn't support a larger transaction sizes (all accesses are 4 bytes in Ibex). If there are any features or extensions we think we need, I can add them as required.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lowRISC/opentitan/issues/17?email_source=notifications&email_token=AAH2RSQKPN2OLOKAYAZSVELQFZB55A5CNFSM4IKDNH7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD44IBQA#issuecomment-523796672, or mute the thread https://github.com/notifications/unsubscribe-auth/AAH2RSXWWXWJAFZGELZ37L3QFZB55ANCNFSM4IKDNH7A .

tjaychen avatar Aug 22 '19 16:08 tjaychen

Yes the accesses will need to be aligned to 4B boundaries. The issue I was getting at was that if the accesses are larger than 4B (say a DMA engine that does large bursts or something) then the checking in the Ibex module cannot take that into account at the moment. It would be easy enough to add though.

tomeroberts avatar Aug 22 '19 16:08 tomeroberts

o i see. I think that is okay for the time being. OpenTitan's bus structure does not at the moment support bursting, so we'll always get an address for each beat of data (i'm guessing you're referring to PMP not tracking successive beats based on the initial address, is that right?) In the future if we work on more complex systems and bursting then comes in, we can add the ability then (although I have to imagine in that kind of system, we'll also want translation abilities, which would be something else altogether).

On Thu, Aug 22, 2019 at 9:53 AM Tom Roberts [email protected] wrote:

Yes the accesses will need to be aligned to 4B boundaries. The issue I was getting at was that if the accesses are larger than 4B (say a DMA engine that does large bursts or something) then the checking in the Ibex module cannot take that into account at the moment. It would be easy enough to add though.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lowRISC/opentitan/issues/17?email_source=notifications&email_token=AAH2RSQPGN5FCXBJMVTCL3DQF2775A5CNFSM4IKDNH7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD45WXGY#issuecomment-523987867, or mute the thread https://github.com/notifications/unsubscribe-auth/AAH2RSXVZ7KYA7IUUMDDFD3QF2775ANCNFSM4IKDNH7A .

tjaychen avatar Aug 22 '19 17:08 tjaychen

PMP suppport has now been merged into Ibex.

asb avatar Aug 30 '19 06:08 asb

thanks for the update Alex! I'll make sure to try it out.

On Thu, Aug 29, 2019 at 11:35 PM Alex Bradbury [email protected] wrote:

PMP suppport has now been merged into Ibex https://github.com/lowRISC/ibex/pull/252.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lowRISC/opentitan/issues/17?email_source=notifications&email_token=AAH2RSRZIBPOWU5L7MHA2NLQHC5SVA5CNFSM4IKDNH7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5QWS5A#issuecomment-526477684, or mute the thread https://github.com/notifications/unsubscribe-auth/AAH2RSV4GWZM3J7MREQDZTLQHC5SVANCNFSM4IKDNH7A .

tjaychen avatar Aug 30 '19 16:08 tjaychen