Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add PTWProber #146

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

[WIP] Add PTWProber #146

wants to merge 2 commits into from

Conversation

jerryz123
Copy link
Contributor

@jerryz123 jerryz123 commented May 16, 2022

This is a RoCC "accelerator" that makes it fast and easy for user programs to determine page mappings. It supports a single instruction that performs a PTW using the PTW on the host core.

#include <stdio.h>
#include <stdint.h>
#include "rocc.h"

int main(void)
{
  int stack_val = 0;

  uint64_t vaddr = (uint64_t)&stack_val;
  uint64_t paddr;
  // opcode=0
  ROCC_INSTRUCTION_DS(0, paddr, vaddr, 0)

  printf("%lx to %lx\n", vaddr, paddr);
  
  // flush
  ROCC_INSTRUCTION_S(0, vaddr, 1);

  return 0;
}

@jerryz123 jerryz123 requested a review from a0u May 16, 2022 18:17
Copy link
Member

@a0u a0u left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A very unlikely race condition could occur where the core takes an exception after the RoCC instruction is issued and privileged code modifies the satp CSR before the walk completes. Not much could be done about this, though, with the RoCC interface being asynchronous and no way to provide a separate copy of satp to the PTW without changing rocket-chip.

resp_q.io.enq.valid := Mux(in_flight, io.ptw(0).resp.valid, !vm_enabled && in_q.valid)
resp_q.io.enq.bits.rd := in_q.bits.inst.rd
resp_q.io.enq.bits.data := Mux(in_flight,
Mux(io.ptw(0).resp.bits.pf, 0.U, Cat(io.ptw(0).resp.bits.pte.ppn, in_q.bits.rs1(pgIdxBits-1,0))),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the intent here to determine whether a mapping exists or whether an access would succeed?

As far as I know, io.ptw(0).resp.bits.pf only indicates if the PTE is invalid or the reserved bits are non-zero, not necessarily if the permissions are adequate. Of course, this suffices for the first use case but not the latter.

Access exceptions (ae_ptw and ae_final) should probably also mask the result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants