Skip to contentSkip to conversation

xen: add gntdev

PATCH Roger Pau Monné 3 participants 10 messages Dec 4, 2012 – Dec 5, 2012 7 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 10 lines · Roger Pau Monne

This is a basic (and experimental) gntdev implementation for NetBSD.

The gnt device allows usermode applications to map grant references in userspace. It is mainly used by Qemu to implement a Xen backend (that runs in userspace).

Due to the fact that qemu-upstream is not yet functional in NetBSD, the only way to try this gntdev is to use the old qemu (qemu-traditional).

Quoted 5 lines

Performance is not that bad (given that we are using qemu-traditional and running a backend in userspace), the throughput of write operations is 64.7 MB/s, while in the Dom0 it is 104.6 MB/s. Regarding read operations, the throughput inside the DomU is 76.0 MB/s, while on the Dom0 it is 108.8 MB/s.

Independently of what we end up doing as default for handling raw file disks, could someone review this code?

It's the first time I've done a device, so someone with more experience should review it.

Thanks, Roger.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 6 lines · Roger Pau Monn?

Independently of what we end up doing as default for handling raw file disks, could someone review this code?

It's the first time I've done a device, so someone with more experience should review it.

I am not sure I entirely follow what this code's doing, but it seems to me it may allow arbitrary physical pages to be exposed to userspace processes in dom0 -- or in a domU, albeit only if dom0 userspace says so.

Is that a correct understanding of one of its effects? If so, there's a problem, since not being able to do precisely that is one important assumption of the 4.4BSD security model.

Thor

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw
Quoted 11 lines · Thor Lancelot Simon
Quoted 6 lines · Roger Pau Monn?

Independently of what we end up doing as default for handling raw file disks, could someone review this code?

It's the first time I've done a device, so someone with more experience should review it.

I am not sure I entirely follow what this code's doing, but it seems to me it may allow arbitrary physical pages to be exposed to userspace processes in dom0 -- or in a domU, albeit only if dom0 userspace says so.

This device allows to map memory pages shared with another domain to a userspace process, provided that the other domain has granted all the necessary permissions to the remote domain wishing to access this pages.

This device does not allow to share pages from the current domain to a remote domain, only allows the mapping of pages shared with another domain, and they are not "arbritary", you need an abstract reference (grant reference) to that memory page to be able to map it, which is provided by the remote domain.

Quoted 6 lines

Is that a correct understanding of one of its effects? If so, there's a problem, since not being able to do precisely that is one important assumption of the 4.4BSD security model.

Thor

#6 lore raw
In reply to a message not in the archive
Quoted 8 lines · Thor Lancelot Simon
Quoted 6 lines · Roger Pau Monn?

Independently of what we end up doing as default for handling raw file disks, could someone review this code?

It's the first time I've done a device, so someone with more experience should review it.

Quoted 7 lines

I am not sure I entirely follow what this code's doing, but it seems to me it may allow arbitrary physical pages to be exposed to userspace processes in dom0 -- or in a domU, albeit only if dom0 userspace says so.

Is that a correct understanding of one of its effects? If so, there's a problem, since not being able to do precisely that is one important assumption of the 4.4BSD security model.

If I read it properly, It allows only to map pages that are part of a grant. You provide the ioctl a grant reference, and this is what the driver uses to find the physical pages. So it should be limited to pages that are referenced by a grant.

Signature · 3 lines
Manuel Bouyer <[email protected]>
     NetBSD: 26 ans d'experience feront toujours la difference
--

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw
Quoted 13 lines · Manuel Bouyer
Quoted 12 lines · Thor Lancelot Simon
Quoted 6 lines · Roger Pau Monn?

Independently of what we end up doing as default for handling raw file disks, could someone review this code?

It's the first time I've done a device, so someone with more experience should review it.

I am not sure I entirely follow what this code's doing, but it seems to me it may allow arbitrary physical pages to be exposed to userspace processes in dom0 -- or in a domU, albeit only if dom0 userspace says so.

Quoted 8 lines
Quoted 3 lines

Is that a correct understanding of one of its effects? If so, there's a problem, since not being able to do precisely that is one important assumption of the 4.4BSD security model.

If I read it properly, It allows only to map pages that are part of a grant. You provide the ioctl a grant reference, and this is what the driver uses to find the physical pages. So it should be limited to pages that are referenced by a grant.

Yes, it should be limited to grant pages, you are not able to map arbitrary mfns.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#10 lore raw
Quoted 18 lines · Roger Pau Monn?
Quoted 17 lines · Manuel Bouyer
Quoted 15 lines · Thor Lancelot Simon
Quoted 6 lines · Roger Pau Monn?

Independently of what we end up doing as default for handling raw file disks, could someone review this code?

It's the first time I've done a device, so someone with more experience should review it.

I am not sure I entirely follow what this code's doing, but it seems to me it may allow arbitrary physical pages to be exposed to userspace processes in dom0 -- or in a domU, albeit only if dom0 userspace says so.

Is that a correct understanding of one of its effects? If so, there's a problem, since not being able to do precisely that is one important assumption of the 4.4BSD security model.

Quoted 7 lines
Quoted 4 lines

If I read it properly, It allows only to map pages that are part of a grant. You provide the ioctl a grant reference, and this is what the driver uses to find the physical pages. So it should be limited to pages that are referenced by a grant.

Yes, it should be limited to grant pages, you are not able to map arbitrary mfns.

So, can dom0 give away arbitrary physical pages to a domU which can then hand them back as a "grant", or is there other protection against that? That was my concern. I'm sorry I don't understand some of the fundamental terminology very well.

Signature · 4 lines
 Thor Lancelot Simon	                                      [email protected]

   	It's very complicated.  It's very cumbersome.  There's a
   	lot of numbers involved with it.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#12 lore raw
Quoted 24 lines · Thor Lancelot Simon
Quoted 23 lines · Roger Pau Monn?
Quoted 21 lines · Manuel Bouyer
Quoted 8 lines · Thor Lancelot Simon
Quoted 6 lines · Roger Pau Monn?

Independently of what we end up doing as default for handling raw file disks, could someone review this code?

It's the first time I've done a device, so someone with more experience should review it.

Quoted 7 lines

I am not sure I entirely follow what this code's doing, but it seems to me it may allow arbitrary physical pages to be exposed to userspace processes in dom0 -- or in a domU, albeit only if dom0 userspace says so.

Is that a correct understanding of one of its effects? If so, there's a problem, since not being able to do precisely that is one important assumption of the 4.4BSD security model.

If I read it properly, It allows only to map pages that are part of a grant. You provide the ioctl a grant reference, and this is what the driver uses to find the physical pages. So it should be limited to pages that are referenced by a grant.

Quoted 7 lines
Quoted 2 lines

Yes, it should be limited to grant pages, you are not able to map arbitrary mfns.

So, can dom0 give away arbitrary physical pages to a domU which can then hand them back as a "grant", or is there other protection against that? That was my concern. I'm sorry I don't understand some of the fundamental terminology very well.

All this "grants" thing is done at the hypervisor level, the hypervisor is the one that assigns and manages grant pages, so the Dom0 is only able to map certain pages that the remote DomU has permited the Dom0 to map, and all this is done using HYPERVISOR_grant_table_op calls.

The code that does this is already inside the NetBSD kernel (because it is used by the backends inside the NetBSD kernel). What this patch does is allowing userspace processes to also map this grants into their own virtual address space.

#13 lore raw
In reply to a message not in the archive
Quoted 2 lines · Roger Pau Monné

Independently of what we end up doing as default for handling raw file disks, could someone review this code?

As this interracts with UVM, I think it would be better to post this to tech-kern@.
I'm not sure UVM experts are listening here.

Signature · 3 lines
Manuel Bouyer <[email protected]>
     NetBSD: 26 ans d'experience feront toujours la difference
--
#14 lore raw
In reply to a message not in the archive
Quoted 16 lines · Roger Pau Monne

This is a basic (and experimental) gntdev implementation for NetBSD.

The gnt device allows usermode applications to map grant references in userspace. It is mainly used by Qemu to implement a Xen backend (that runs in userspace).

Due to the fact that qemu-upstream is not yet functional in NetBSD, the only way to try this gntdev is to use the old qemu (qemu-traditional).

Performance is not that bad (given that we are using qemu-traditional and running a backend in userspace), the throughput of write operations is 64.7 MB/s, while in the Dom0 it is 104.6 MB/s. Regarding read operations, the throughput inside the DomU is 76.0 MB/s, while on the Dom0 it is 108.8 MB/s.

Quoted 4 lines

Patches to libxc and libxl are also comming soon.

[...]
+map_grant_ref(struct gntmap *map);

please, prefix all struct, global variables and functions of the driver with gnt

Review

Quoted 4 lines
(quoted diff) +4 -0
+		if (pmap_extract_ma(pmap_kernel(), k_va, &ma) == false) {
+			debug("unable to extract kernel MA");
+			return EFAULT;
+		}

Can't you get the pa or ma directly from the grant reference ? Adding a kernel mapping only to run pmap_extract_ma() on it looks like an innefficient way of doing it (this will require TLB shootdown IPIs).

Or maybe GNTTABOP_map_grant_ref could map directly in user space ?

Signature · 3 lines
Manuel Bouyer <[email protected]>
     NetBSD: 26 ans d'experience feront toujours la difference
--

A message that is not in the archive (sent off-list or not yet received): [email protected]

#16 lore raw
Quoted 25 lines · Manuel Bouyer
Quoted 16 lines · Roger Pau Monne

This is a basic (and experimental) gntdev implementation for NetBSD.

The gnt device allows usermode applications to map grant references in userspace. It is mainly used by Qemu to implement a Xen backend (that runs in userspace).

Due to the fact that qemu-upstream is not yet functional in NetBSD, the only way to try this gntdev is to use the old qemu (qemu-traditional).

Performance is not that bad (given that we are using qemu-traditional and running a backend in userspace), the throughput of write operations is 64.7 MB/s, while in the Dom0 it is 104.6 MB/s. Regarding read operations, the throughput inside the DomU is 76.0 MB/s, while on the Dom0 it is 108.8 MB/s.

Quoted 4 lines

Patches to libxc and libxl are also comming soon.

[...]
+map_grant_ref(struct gntmap *map);

please, prefix all struct, global variables and functions of the driver with gnt

Quoted 8 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+		if (pmap_extract_ma(pmap_kernel(), k_va, &ma) == false) {
+			debug("unable to extract kernel MA");
+			return EFAULT;
+		}

Can't you get the pa or ma directly from the grant reference ? Adding a kernel mapping only to run pmap_extract_ma() on it looks like an innefficient way of doing it (this will require TLB shootdown IPIs).

I think I can get the mfn as a result from the GNTTABOP_map_grant_ref operation, according to
http://xenbits.xen.org/docs/unstable/misc/grant-tables.txt it should be the dev_bus_addr field, but I'm not sure how updated that document is (I'm afraid it's not really maintained).

I've just found that document now, but it looks like it is possible to update the pfn -> mfn mappings to point to the right mfn, so we might be able to use the regular mmap device handler to perform the mappings.

On a different question, does someone know why fileops doesn't implement a mmap handler?

Quoted 1 line

Or maybe GNTTABOP_map_grant_ref could map directly in user space ?

GNTTABOP_map_grant_ref has an option that's GNTMAP_application_map, but there's no documentation about how that works, and the Linux code is not trivial to understand (at least for me).