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

hv: Add 9P virtio peripheral #228

Merged
merged 10 commits into from Jan 13, 2023
Merged

hv: Add 9P virtio peripheral #228

merged 10 commits into from Jan 13, 2023

Conversation

povik
Copy link
Member

@povik povik commented Jun 29, 2022

This allows one to access host m1n1 sources from within the system running in hypervisor. Once you arrange for the virtio peripheral both in hypervisor code (self.attach_virtio(Virtio9PTransport(), 0x2_2000_0000, 382)) and in the devicetree, you run

mount -t 9p -o transp=virtio m1n1 /mnt

to mount the sources on guest. One use case of it is using m1n1 regmaps over kernel's internal regmap structures (as alluded to by the extra commit).

Performance is not great since the hypervisor stops to handle each 9P call but it's not impractical.

Direction I think this should be expanded in:

  • Allocate the IRQs/register range automatically
  • Insert the peripheral into ADT
  • Have guest m1n1 transfer it from ADT to FDT

Let me know if you think this is fine for inclusion.

@marcan
Copy link
Member

marcan commented Jun 29, 2022

Very cute. I like it :)

I was going to say I'm not sure about putting this in the ADT, but on further thought there's no reason not to do that (as long as the mutation happens in Python, since we already have code for that there). So sure, why not!

@marcan
Copy link
Member

marcan commented Jun 29, 2022

Just sort of direction-wise: I'm fine with anything in m1n1/the hypervisor as long as it helps with development. I don't think it should become a general-purpose hypervisor or veer off towards production usage, but sharing files with the host is very obviously useful for a ton of reasons (e.g. you can avoid building initramfses all the time for development, develop kernel modules and load/reload them from the guest without a full reboot, etc.). I've been doing this over sshfs in the past (host to guest, which sucks a bit), but the other way around with 9p should be nicer for a bunch of workflows.

@povik
Copy link
Member Author

povik commented Aug 1, 2022

Okay, I implemented the hypervisor->ADT->FDT path to pass information on the existence of the virtio device, and added allocation of IRQ/register range. The allocation looks for numbers/ranges that are free per ADT -- for MMIO that should be foolproof, and I guess the AIC isn't to any degree shared with the coprocessors, so for IRQs that should be okay too.

So, about usage: One passes a path and a tag to the hypervisor, so for example

./proxyclient/tools/run_guest.py \
    -v ~/repos/m1n1:m1n1 \
    -v ~/music:tunes \
    m1n1-payload.macho

to export one tree under tag m1n1 and another under tunes. To then mount the tags on guest:

mount -t 9p -o transp=virtio tunes /mnt
mount -t 9p -o transp=virtio m1n1 /mnt2

You need a u9fs program installed on the host to do the 9P speaking, and these options on the guest kernel (let me know anybody if some are missing):

CONFIG_NET_9P_VIRTIO
CONFIG_VIRTIO_MMIO
CONFIG_9P_FS

@povik povik marked this pull request as ready for review August 1, 2022 15:27
@@ -1114,6 +1182,10 @@ int kboot_prepare_dt(void *fdt)
return -1;
if (dt_disable_missing_devs("i2c", "i2c@", 8))
return -1;
#ifndef RELEASE
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if we want !RELEASE or some other gate here

@povik
Copy link
Member Author

povik commented Aug 29, 2022

Rebased

@povik
Copy link
Member Author

povik commented Sep 19, 2022

Rebased

@povik
Copy link
Member Author

povik commented Dec 14, 2022

Ping @marcan

@marcan
Copy link
Member

marcan commented Jan 13, 2023

Looks good, can you fix the conflict so I can merge?

@povik
Copy link
Member Author

povik commented Jan 13, 2023

Sure, thanks for the review!

Add some minimal implementation of virtio peripherals. At the level
of on-target hypervisor code we implement the MMIO layout and
maintain virtqueues. Once a buffer is available, we break into the
host proxyclient to deal with it.

Specific device-classes of the virtio spec ought to be implemented in
the proxyclient. Here the one device implemented is 9P transport,
exporting the m1n1 source directory.

Signed-off-by: Martin Povišer <povik@cutebit.org>
Used for sys.stderr later on.

Signed-off-by: Martin Povišer <povik@cutebit.org>
So that one can check for children, like:

  >>> "/arm-io/aic" in u.adt
  True

Signed-off-by: Martin Povišer <povik@cutebit.org>
Signed-off-by: Martin Povišer <povik@cutebit.org>
So that one knows what to put in reg properties.

Signed-off-by: Martin Povišer <povik@cutebit.org>
Signed-off-by: Martin Povišer <povik@cutebit.org>
Signed-off-by: Martin Povišer <povik@cutebit.org>
This is to fix

  OverflowError: Python int too large to convert to C ssize_t

in case the upper bound of a range is 1<<64.

Signed-off-by: Martin Povišer <povik@cutebit.org>
Signed-off-by: Martin Povišer <povik@cutebit.org>
Signed-off-by: Martin Povišer <povik@cutebit.org>
@povik
Copy link
Member Author

povik commented Jan 13, 2023

Rebased (and removed a stray definition in uartproxy.h)

@marcan marcan merged commit 2cb6cb4 into AsahiLinux:main Jan 13, 2023
@povik povik deleted the 9p branch January 23, 2023 18:45
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