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

fix instruction synchronization bug on a real RISC-V processor #5

Closed
wants to merge 1 commit into from

Conversation

sashimi-yzh
Copy link

  • RISC-V does not guarantee that a stored instruction can be seen by the
    subsequent instruction fetches. This is a case of loading user
    programs in an operating system. The original kernel can run on QEMU.
    But to run on a real RISC-V processor, we should use FENCE.I to let
    subsequent instruction fetches see the stored instructions.

  • Fork() will also copy pages containing instructions. We should add a
    FENCE.I before uvmcopy() returns.

  • NOTE: The current solution only works for a single-processor system.
    According to the RISC-V manual, for a multiprocess system, we should

    1. copy the code (in exec() or uvmcopy())
    2. execute a FENCE instruciton to let the data stream of other harts
      see the copied code
    3. use IPI to notify other harts to execute a FENCE.I to let their
      instruction stream see the copied code

* RISC-V does not guarantee that a stored instruction can be seen by the
  subsequent instruction fetches. This is a case of loading user
  programs in an operating system. The original kernel can run on QEMU.
  But to run on a real RISC-V processor, we should use FENCE.I to let
  subsequent instruction fetches see the stored instructions.

* Fork() will also copy pages containing instructions. We should add a
  FENCE.I before uvmcopy() returns.

* NOTE: The current solution only works for a single-processor system.
  According to the RISC-V manual, for a multiprocess system, we should
    1. copy the code (in exec() or uvmcopy())
    2. execute a FENCE instruciton to let the data stream of other harts
       see the copied code
    3. use IPI to notify other harts to execute a FENCE.I to let their
       instruction stream see the copied code
@kaashoek
Copy link
Member

Thanks for the comment, and a good observation. We believe, however, that xv6 already handles this correctly, because the child cannot run until the parent releases the lock of the child and the release has a memory barrier. (We have a short discussion about this at the end of section 9.3 in the text book.)

@kaashoek kaashoek closed this Aug 10, 2020
sudokara added a commit to sudokara/xv6.1-riscv that referenced this pull request Dec 18, 2022
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.

None yet

2 participants