Skip to contentSkip to conversation

XDP offload to hypervisor

DISCUSSION Michael S. Tsirkin 4 participants 14 messages Jan 23, 2017 – Jan 25, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

I've been thinking about passing XDP programs from guest to the hypervisor. Basically, after getting an incoming packet, we could run an XDP program in host kernel.

If the result is XDP_DROP or XDP_TX we don't need to wake up the guest at all!

When using tun for networking - especially with adjust_head - this unfortunately probably means we need to do a data copy unless there is enough headroom. How much is enough though?

Another issue is around host/guest ABI. Guest BPF could add new features at any point. What if hypervisor can not support it all? I guess we could try loading program into hypervisor and run it within guest on failure to load, but this ignores question of cross-version compatibility - someone might start guest on a new host
then try to move to an old one. So we will need an option "behave like an older host" such that guest can start and then move to an older host later. This will likely mean implementing this validation of programs in qemu userspace unless linux can supply something like this. Is this (disabling some features) something that might be of interest to larger bpf community?

With a device such as macvtap there exist configurations where a single guest is in control of the device (aka passthrough mode) in that case there's a potential to run xdp on host before host skb is built, unless host already has an xdp program attached. If it does we could run the program within guest, but what if a guest program got attached first? Maybe we should pass a flag in the packet "xdp passed on this packet in host". Then, guest can skip running it. Unless we do a full reset there's always a potential for packets to slip through, e.g. on xdp program changes. Maybe a flush command is needed, or force queue or device reset to make sure nothing is going on. Does this make sense?

Thanks!

Signature · 1 line
MST
#1 lore raw
Quoted 4 lines · Michael S. Tsirkin

I've been thinking about passing XDP programs from guest to the hypervisor. Basically, after getting an incoming packet, we could run an XDP program in host kernel.

Interesting. I am planning on adding XDP to tun driver. My use case is we want to use XDP to restrict VM traffic. I was planning on pushing the xdp program execution into tun_get_user(). So different then "offloading" an xdp program into hypervisor.

Quoted 2 lines

If the result is XDP_DROP or XDP_TX we don't need to wake up the guest at all!

nice win.

Quoted 3 lines

When using tun for networking - especially with adjust_head - this unfortunately probably means we need to do a data copy unless there is enough headroom. How much is enough though?

We were looking at making headroom configurable on Intel drivers or at least matching it with XDP headroom guidelines. (although the developers had the same complaint about 256B being large). Then at least on supported drivers the copy could be an exception path.

Quoted 12 lines

Another issue is around host/guest ABI. Guest BPF could add new features at any point. What if hypervisor can not support it all? I guess we could try loading program into hypervisor and run it within guest on failure to load, but this ignores question of cross-version compatibility - someone might start guest on a new host
then try to move to an old one. So we will need an option "behave like an older host" such that guest can start and then move to an older host later. This will likely mean implementing this validation of programs in qemu userspace unless linux can supply something like this. Is this (disabling some features) something that might be of interest to larger bpf community?

This is interesting to me at least. Another interesting "feature" of running bpf in qemu userspace is it could work with vhost_user as well presumably?

Quoted 12 lines

With a device such as macvtap there exist configurations where a single guest is in control of the device (aka passthrough mode) in that case there's a potential to run xdp on host before host skb is built, unless host already has an xdp program attached. If it does we could run the program within guest, but what if a guest program got attached first? Maybe we should pass a flag in the packet "xdp passed on this packet in host". Then, guest can skip running it. Unless we do a full reset there's always a potential for packets to slip through, e.g. on xdp program changes. Maybe a flush command is needed, or force queue or device reset to make sure nothing is going on. Does this make sense?

Could the virtio driver pretend its "offloading" the XDP program to hardware? This would make it explicit in VM that the program is run before data is received by virtio_net. Then qemu is enabling the offload framework which would be interesting.

Quoted 2 lines

Thanks!

#2 lore raw
Quoted 10 lines · John Fastabend
Quoted 4 lines · Michael S. Tsirkin

I've been thinking about passing XDP programs from guest to the hypervisor. Basically, after getting an incoming packet, we could run an XDP program in host kernel.

Interesting. I am planning on adding XDP to tun driver. My use case is we want to use XDP to restrict VM traffic. I was planning on pushing the xdp program execution into tun_get_user(). So different then "offloading" an xdp program into hypervisor.

tun currently supports TUNATTACHFILTER. Do you plan to extend it then?

So maybe there's need to support more than one program.

Would it work if we run one (host-supplied)
and then if we get XDP_PASS run another (guest supplied) otherwise don't wake up guest?

Quoted 9 lines
Quoted 2 lines

If the result is XDP_DROP or XDP_TX we don't need to wake up the guest at all!

nice win.

Quoted 3 lines

When using tun for networking - especially with adjust_head - this unfortunately probably means we need to do a data copy unless there is enough headroom. How much is enough though?

Quoted 5 lines

We were looking at making headroom configurable on Intel drivers or at least matching it with XDP headroom guidelines. (although the developers had the same complaint about 256B being large).
Then at least on supported
drivers the copy could be an exception path.

So I am concerned that userspace comes to depend on support for 256byte headroom that this patchset enables. How about
-#define XDP_PACKET_HEADROOM 256
+#define XDP_PACKET_HEADROOM 64
so we start with a concervative value?
In fact NET_SKB_PAD would be ideal I think but it's
platform dependent.

Or at least do the equivalent for virtio only ...

Quoted 13 lines
Quoted 12 lines

Another issue is around host/guest ABI. Guest BPF could add new features at any point. What if hypervisor can not support it all? I guess we could try loading program into hypervisor and run it within guest on failure to load, but this ignores question of cross-version compatibility - someone might start guest on a new host
then try to move to an old one. So we will need an option "behave like an older host" such that guest can start and then move to an older host later. This will likely mean implementing this validation of programs in qemu userspace unless linux can supply something like this. Is this (disabling some features) something that might be of interest to larger bpf community?

Quoted 3 lines

This is interesting to me at least. Another interesting "feature" of running bpf in qemu userspace is it could work with vhost_user as well presumably?

I think with vhost user you would want to push it out
to the switch, not run it in qemu.
IOW qemu gets the program and sends it to the switch. Response is sent to guest so it knows whether switch can support it.

Quoted 13 lines
Quoted 12 lines

With a device such as macvtap there exist configurations where a single guest is in control of the device (aka passthrough mode) in that case there's a potential to run xdp on host before host skb is built, unless host already has an xdp program attached. If it does we could run the program within guest, but what if a guest program got attached first? Maybe we should pass a flag in the packet "xdp passed on this packet in host". Then, guest can skip running it. Unless we do a full reset there's always a potential for packets to slip through, e.g. on xdp program changes. Maybe a flush command is needed, or force queue or device reset to make sure nothing is going on. Does this make sense?

Quoted 4 lines

Could the virtio driver pretend its "offloading" the XDP program to hardware? This would make it explicit in VM that the program is run before data is received by virtio_net. Then qemu is enabling the offload framework which would be interesting.

On qemu side this is not a problem a command causes
a trap and qemu could flush the queue. But the packets
are still in the rx queue and get processed by napi later. I think the cleanest interface for it might be a command consuming an rx buffer and writing a pre-defined pattern into it. This way guest can figure out how far did device get in the rx queue.

Quoted 2 lines
Quoted 2 lines

Thanks!

#3 lore raw
In reply to John Fastabend
Quoted 9 lines · John Fastabend
Quoted 4 lines · Michael S. Tsirkin

I've been thinking about passing XDP programs from guest to the hypervisor. Basically, after getting an incoming packet, we could run an XDP program in host kernel.

Interesting. I am planning on adding XDP to tun driver. My use case is we want to use XDP to restrict VM traffic. I was planning on pushing the xdp program execution into tun_get_user(). So different then "offloading" an xdp program into hypervisor.

This looks interesting to me. BTW, I was playing a patch and tries to make use of XDP to accelerate macvtap in passthrough mode rx on host. With the patch, XDP buffer instead of sbk could be used for vhost rx, and tests shows nice results.

But this seems conflict with XDP offload idea here.

Thanks

Quoted 46 lines
Quoted 3 lines

If the result is XDP_DROP or XDP_TX we don't need to wake up the guest at all!

nice win.

Quoted 3 lines

When using tun for networking - especially with adjust_head - this unfortunately probably means we need to do a data copy unless there is enough headroom. How much is enough though?

We were looking at making headroom configurable on Intel drivers or at least matching it with XDP headroom guidelines. (although the developers had the same complaint about 256B being large). Then at least on supported drivers the copy could be an exception path.

Quoted 11 lines

Another issue is around host/guest ABI. Guest BPF could add new features at any point. What if hypervisor can not support it all? I guess we could try loading program into hypervisor and run it within guest on failure to load, but this ignores question of cross-version compatibility - someone might start guest on a new host
then try to move to an old one. So we will need an option "behave like an older host" such that guest can start and then move to an older host later. This will likely mean implementing this validation of programs in qemu userspace unless linux can supply something like this. Is this (disabling some features) something that might be of interest to larger bpf community?

This is interesting to me at least. Another interesting "feature" of running bpf in qemu userspace is it could work with vhost_user as well presumably?

Quoted 11 lines

With a device such as macvtap there exist configurations where a single guest is in control of the device (aka passthrough mode) in that case there's a potential to run xdp on host before host skb is built, unless host already has an xdp program attached. If it does we could run the program within guest, but what if a guest program got attached first? Maybe we should pass a flag in the packet "xdp passed on this packet in host". Then, guest can skip running it. Unless we do a full reset there's always a potential for packets to slip through, e.g. on xdp program changes. Maybe a flush command is needed, or force queue or device reset to make sure nothing is going on. Does this make sense?

Could the virtio driver pretend its "offloading" the XDP program to hardware? This would make it explicit in VM that the program is run before data is received by virtio_net. Then qemu is enabling the offload framework which would be interesting.

Quoted 2 lines

Thanks!

#4 lore raw
Quoted 13 lines · Jason Wang
Quoted 9 lines · John Fastabend
Quoted 4 lines · Michael S. Tsirkin

I've been thinking about passing XDP programs from guest to the hypervisor. Basically, after getting an incoming packet, we could run an XDP program in host kernel.

Interesting. I am planning on adding XDP to tun driver. My use case is we want to use XDP to restrict VM traffic. I was planning on pushing the xdp program execution into tun_get_user(). So different then "offloading" an xdp program into hypervisor.

Quoted 8 lines

This looks interesting to me. BTW, I was playing a patch and tries to make use of XDP to accelerate macvtap in passthrough mode rx on host. With the patch, XDP buffer instead of sbk could be used for vhost rx, and tests shows nice results.

But this seems conflict with XDP offload idea here.

Thanks

One way is to add ability to attach two XDP
programs to macvtap: guest and host. Run host first on XDP_PASS run guest.

Quoted 46 lines
Quoted 46 lines
Quoted 3 lines

If the result is XDP_DROP or XDP_TX we don't need to wake up the guest at all!

nice win.

Quoted 3 lines

When using tun for networking - especially with adjust_head - this unfortunately probably means we need to do a data copy unless there is enough headroom. How much is enough though?

We were looking at making headroom configurable on Intel drivers or at least matching it with XDP headroom guidelines. (although the developers had the same complaint about 256B being large). Then at least on supported drivers the copy could be an exception path.

Quoted 11 lines

Another issue is around host/guest ABI. Guest BPF could add new features at any point. What if hypervisor can not support it all? I guess we could try loading program into hypervisor and run it within guest on failure to load, but this ignores question of cross-version compatibility - someone might start guest on a new host
then try to move to an old one. So we will need an option "behave like an older host" such that guest can start and then move to an older host later. This will likely mean implementing this validation of programs in qemu userspace unless linux can supply something like this. Is this (disabling some features) something that might be of interest to larger bpf community?

This is interesting to me at least. Another interesting "feature" of running bpf in qemu userspace is it could work with vhost_user as well presumably?

Quoted 11 lines

With a device such as macvtap there exist configurations where a single guest is in control of the device (aka passthrough mode) in that case there's a potential to run xdp on host before host skb is built, unless host already has an xdp program attached. If it does we could run the program within guest, but what if a guest program got attached first? Maybe we should pass a flag in the packet "xdp passed on this packet in host". Then, guest can skip running it. Unless we do a full reset there's always a potential for packets to slip through, e.g. on xdp program changes. Maybe a flush command is needed, or force queue or device reset to make sure nothing is going on. Does this make sense?

Could the virtio driver pretend its "offloading" the XDP program to hardware? This would make it explicit in VM that the program is run before data is received by virtio_net. Then qemu is enabling the offload framework which would be interesting.

Quoted 2 lines

Thanks!

#5 lore raw
In reply to Michael S. Tsirkin
Quoted 5 lines · Michael S. Tsirkin

I've been thinking about passing XDP programs from guest to the hypervisor. Basically, after getting an incoming packet, we could run an XDP program in host kernel.

If the result is XDP_DROP or XDP_TX we don't need to wake up the guest at all!

that's an interesting idea!
Long term 'xdp offload' needs to be defined, since NICs become smarter and can accelerate xdp programs.
So pushing the xdp program down from virtio in the guest into host and from x86 into nic cpu should probably be handled through the same api.

Quoted 3 lines

When using tun for networking - especially with adjust_head - this unfortunately probably means we need to do a data copy unless there is enough headroom. How much is enough though?

Frankly I don't understand the whole virtio nit picking that was happening. imo virtio+xdp by itself is only useful for debugging, development and testing of xdp programs in a VM. The discussion about performance of virtio+xdp will only be meaningful when corresponding host part is done. Likely in the form of vhost extensions and may be driver changes. Trying to optimize virtio+xdp when host is doing traditional skb+vhost isn't going to be impactful.
But when host can do xdp in phyiscal NIC that can deliver raw pages into vhost that gets picked up by guest virtio, then we hopefully will be around 10G line rate. page pool is likely needed in such scenario. Some new xdp action like xdp_tx_into_vhost or whatever.
And guest will be seeing full pages that host nic provided and discussion about headroom will be automatically solved.
Arguing that skb has 64-byte headroom and therefore we need to reduce XDP_PACKET_HEADROOM is really upside down.

Quoted 11 lines

Another issue is around host/guest ABI. Guest BPF could add new features at any point. What if hypervisor can not support it all? I guess we could try loading program into hypervisor and run it within guest on failure to load, but this ignores question of cross-version compatibility - someone might start guest on a new host
then try to move to an old one. So we will need an option "behave like an older host" such that guest can start and then move to an older host later. This will likely mean implementing this validation of programs in qemu userspace unless linux can supply something like this. Is this (disabling some features) something that might be of interest to larger bpf community?

In case of x86->nic offload not all xdp features will be supported by the nic and that is expected. The user will request 'offload of xdp prog' in some form and if it cannot be done, then xdp programs will run on x86 as before. Same thing, I imagine, is applicable to virtio->host offload. Therefore I don't see a need for user space visible feature negotiation.

Quoted 10 lines

With a device such as macvtap there exist configurations where a single guest is in control of the device (aka passthrough mode) in that case there's a potential to run xdp on host before host skb is built, unless host already has an xdp program attached. If it does we could run the program within guest, but what if a guest program got attached first? Maybe we should pass a flag in the packet "xdp passed on this packet in host". Then, guest can skip running it. Unless we do a full reset there's always a potential for packets to slip through, e.g. on xdp program changes. Maybe a flush command is needed, or force queue or device reset to make sure nothing is going on. Does this make sense?

All valid questions and concerns.
Since there is still no xdp_adjust_head support in virtio, it feels kinda early to get into detailed 'virtio offload' discussion.

#6 lore raw
Quoted 12 lines · Alexei Starovoitov
Quoted 11 lines

Another issue is around host/guest ABI. Guest BPF could add new features at any point. What if hypervisor can not support it all? I guess we could try loading program into hypervisor and run it within guest on failure to load, but this ignores question of cross-version compatibility - someone might start guest on a new host
then try to move to an old one. So we will need an option "behave like an older host" such that guest can start and then move to an older host later. This will likely mean implementing this validation of programs in qemu userspace unless linux can supply something like this. Is this (disabling some features) something that might be of interest to larger bpf community?

Quoted 6 lines

In case of x86->nic offload not all xdp features will be supported by the nic and that is expected. The user will request 'offload of xdp prog' in some form and if it cannot be done, then xdp programs will run on x86 as before. Same thing, I imagine, is applicable to virtio->host offload. Therefore I don't see a need for user space visible feature negotiation.

Not userspace visible - guest visible. As guests move between hosts, you need to make sure source host does not commit to a feature that destination host does not support.

Signature · 1 line
MST
#7 lore raw
In reply to Alexei Starovoitov
Quoted 7 lines · Alexei Starovoitov

Frankly I don't understand the whole virtio nit picking that was happening. imo virtio+xdp by itself is only useful for debugging, development and testing of xdp programs in a VM. The discussion about performance of virtio+xdp will only be meaningful when corresponding host part is done. Likely in the form of vhost extensions and may be driver changes. Trying to optimize virtio+xdp when host is doing traditional skb+vhost isn't going to be impactful.

Well if packets can be dropped without a host/guest transition then yes, that will have an impact even with traditional skbs.

Signature · 1 line
MST
#8 lore raw
Quoted 9 lines · Michael S. Tsirkin
Quoted 7 lines · Alexei Starovoitov

Frankly I don't understand the whole virtio nit picking that was happening. imo virtio+xdp by itself is only useful for debugging, development and testing of xdp programs in a VM. The discussion about performance of virtio+xdp will only be meaningful when corresponding host part is done. Likely in the form of vhost extensions and may be driver changes. Trying to optimize virtio+xdp when host is doing traditional skb+vhost isn't going to be impactful.

Quoted 3 lines

Well if packets can be dropped without a host/guest transition then yes, that will have an impact even with traditional skbs.

I don't think it's worth optimizing for though, since the speed of drop matters for ddos-like use case and if we let host be flooded with skbs, we already lost, since the only thing cpu is doing is allocating skbs and moving them around. Whether drop is happening upon entry into VM or host does it in some post-vhost layer doesn't change the picture much. That said, I do like the idea of offloading virto+xdp into host somehow.

#9 lore raw
Quoted 10 lines · Alexei Starovoitov
Quoted 9 lines · Michael S. Tsirkin
Quoted 7 lines · Alexei Starovoitov

Frankly I don't understand the whole virtio nit picking that was happening. imo virtio+xdp by itself is only useful for debugging, development and testing of xdp programs in a VM. The discussion about performance of virtio+xdp will only be meaningful when corresponding host part is done. Likely in the form of vhost extensions and may be driver changes. Trying to optimize virtio+xdp when host is doing traditional skb+vhost isn't going to be impactful.

Quoted 6 lines
Quoted 3 lines

Well if packets can be dropped without a host/guest transition then yes, that will have an impact even with traditional skbs.

I don't think it's worth optimizing for though, since the speed of drop matters for ddos-like use case

It's not just drops. adjust head + xmit can handle bridging without entering the VM.

Quoted 5 lines

and if we let host be flooded with skbs,
we already lost, since the only thing cpu is doing is allocating skbs and moving them around. Whether drop is happening upon entry into VM or host does it in some post-vhost layer doesn't change the picture much. That said, I do like the idea of offloading virto+xdp into host somehow.

#10 lore raw
In reply to Alexei Starovoitov
Quoted 12 lines · Alexei Starovoitov
Quoted 5 lines · Michael S. Tsirkin

I've been thinking about passing XDP programs from guest to the hypervisor. Basically, after getting an incoming packet, we could run an XDP program in host kernel.

If the result is XDP_DROP or XDP_TX we don't need to wake up the guest at all!

that's an interesting idea!
Long term 'xdp offload' needs to be defined, since NICs become smarter and can accelerate xdp programs.
So pushing the xdp program down from virtio in the guest into host and from x86 into nic cpu should probably be handled through the same api.

Quoted 7 lines
Quoted 3 lines

When using tun for networking - especially with adjust_head - this unfortunately probably means we need to do a data copy unless there is enough headroom. How much is enough though?

Frankly I don't understand the whole virtio nit picking that was happening. imo virtio+xdp by itself is only useful for debugging, development and testing of xdp programs in a VM. The discussion about performance of virtio+xdp will only be meaningful when corresponding host part is done.

I was doing a prototype to make XDP rx works for macvtap (with minor changes in the driver e.g mlx4). Tests shows improvements, plan to post as RFC after spring festival holiday in China. This is even useful for nested VM but can not work well for XDP offload.

Quoted 7 lines

Likely in the form of vhost extensions and may be driver changes. Trying to optimize virtio+xdp when host is doing traditional skb+vhost isn't going to be impactful.
But when host can do xdp in phyiscal NIC that can deliver raw pages into vhost that gets picked up by guest virtio, then we hopefully will be around 10G line rate. page pool is likely needed in such scenario. Some new xdp action like xdp_tx_into_vhost or whatever.

Yes, in my prototype, mlx4 XDP rx page pool were reused.

Thanks

Quoted 37 lines

And guest will be seeing full pages that host nic provided and discussion about headroom will be automatically solved.
Arguing that skb has 64-byte headroom and therefore we need to reduce XDP_PACKET_HEADROOM is really upside down.

Quoted 11 lines

Another issue is around host/guest ABI. Guest BPF could add new features at any point. What if hypervisor can not support it all? I guess we could try loading program into hypervisor and run it within guest on failure to load, but this ignores question of cross-version compatibility - someone might start guest on a new host
then try to move to an old one. So we will need an option "behave like an older host" such that guest can start and then move to an older host later. This will likely mean implementing this validation of programs in qemu userspace unless linux can supply something like this. Is this (disabling some features) something that might be of interest to larger bpf community?

In case of x86->nic offload not all xdp features will be supported by the nic and that is expected. The user will request 'offload of xdp prog' in some form and if it cannot be done, then xdp programs will run on x86 as before. Same thing, I imagine, is applicable to virtio->host offload. Therefore I don't see a need for user space visible feature negotiation.

Quoted 10 lines

With a device such as macvtap there exist configurations where a single guest is in control of the device (aka passthrough mode) in that case there's a potential to run xdp on host before host skb is built, unless host already has an xdp program attached. If it does we could run the program within guest, but what if a guest program got attached first? Maybe we should pass a flag in the packet "xdp passed on this packet in host". Then, guest can skip running it. Unless we do a full reset there's always a potential for packets to slip through, e.g. on xdp program changes. Maybe a flush command is needed, or force queue or device reset to make sure nothing is going on. Does this make sense?

All valid questions and concerns.
Since there is still no xdp_adjust_head support in virtio, it feels kinda early to get into detailed 'virtio offload' discussion.

#11 lore raw
In reply to Alexei Starovoitov
Quoted 4 lines · Alexei Starovoitov

Frankly I don't understand the whole virtio nit picking that was happening. imo virtio+xdp by itself is only useful for debugging, development and testing of xdp programs in a VM. The discussion about performance of virtio+xdp will only be meaningful when corresponding host part is done.

Maybe not, consider you may have dpdk backend on host.

Thanks

#12 lore raw
In reply to Michael S. Tsirkin
Quoted 5 lines · Michael S. Tsirkin

I've been thinking about passing XDP programs from guest to the hypervisor. Basically, after getting an incoming packet, we could run an XDP program in host kernel.

If the result is XDP_DROP or XDP_TX we don't need to wake up the guest at all!

Interesting, but there're some questions:

- This may work well for XDP_DROP and XDP_TX, and manage to work for XDP_PASS. But what if XDP were extend for other capabilities in the future? E.g forward to other interface or userspace?
- For XDP_DROP, it can be done through socket filter.
- Need to translate XDP_TX as something like XDP_RX at least for tun. Or it may bring some confusion if tun support XDP or XDP were supported in tx patch in the future.

Quoted 4 lines

When using tun for networking - especially with adjust_head - this unfortunately probably means we need to do a data copy unless there is enough headroom. How much is enough though?

Not a tun specific issue I believe?

Quoted 9 lines

Another issue is around host/guest ABI. Guest BPF could add new features at any point. What if hypervisor can not support it all? I guess we could try loading program into hypervisor and run it within guest on failure to load, but this ignores question of cross-version compatibility - someone might start guest on a new host
then try to move to an old one. So we will need an option "behave like an older host" such that guest can start and then move to an older host later.

I'm suspect whether or not this can be done easily.

Quoted 18 lines

This will likely mean
implementing this validation of programs in qemu userspace unless linux can supply something like this. Is this (disabling some features) something that might be of interest to larger bpf community?

With a device such as macvtap there exist configurations where a single guest is in control of the device (aka passthrough mode) in that case there's a potential to run xdp on host before host skb is built, unless host already has an xdp program attached. If it does we could run the program within guest, but what if a guest program got attached first? Maybe we should pass a flag in the packet "xdp passed on this packet in host". Then, guest can skip running it. Unless we do a full reset there's always a potential for packets to slip through, e.g. on xdp program changes. Maybe a flush command is needed, or force queue or device reset to make sure nothing is going on. Does this make sense?

Thanks!

#13 lore raw
Quoted 7 lines · Jason Wang
Quoted 4 lines · Michael S. Tsirkin

I've been thinking about passing XDP programs from guest to the hypervisor. Basically, after getting an incoming packet, we could run an XDP program in host kernel.

Quoted 7 lines
Quoted 1 line

If the result is XDP_DROP or XDP_TX we don't need to wake up the guest at all!

Interesting, but there're some questions:

- This may work well for XDP_DROP and XDP_TX, and manage to work for XDP_PASS. But what if XDP were extend for other capabilities in the future? E.g forward to other interface or userspace?

This is exactly what I am saying. Any future extensions will need feature negotiation.

Quoted 11 lines

- For XDP_DROP, it can be done through socket filter.
- Need to translate XDP_TX as something like XDP_RX at least for tun. Or it may bring some confusion if tun support XDP or XDP were supported in tx patch in the future.

Quoted 4 lines

When using tun for networking - especially with adjust_head - this unfortunately probably means we need to do a data copy unless there is enough headroom. How much is enough though?

Not a tun specific issue I believe?

It is tun specific because tun gets skbs from linux net core while XDP expects pre-skb pages.

Quoted 30 lines
Quoted 9 lines

Another issue is around host/guest ABI. Guest BPF could add new features at any point. What if hypervisor can not support it all? I guess we could try loading program into hypervisor and run it within guest on failure to load, but this ignores question of cross-version compatibility - someone might start guest on a new host
then try to move to an old one. So we will need an option "behave like an older host" such that guest can start and then move to an older host later.

I'm suspect whether or not this can be done easily.

Quoted 18 lines

This will likely mean
implementing this validation of programs in qemu userspace unless linux can supply something like this. Is this (disabling some features) something that might be of interest to larger bpf community?

With a device such as macvtap there exist configurations where a single guest is in control of the device (aka passthrough mode) in that case there's a potential to run xdp on host before host skb is built, unless host already has an xdp program attached. If it does we could run the program within guest, but what if a guest program got attached first? Maybe we should pass a flag in the packet "xdp passed on this packet in host". Then, guest can skip running it. Unless we do a full reset there's always a potential for packets to slip through, e.g. on xdp program changes. Maybe a flush command is needed, or force queue or device reset to make sure nothing is going on. Does this make sense?

Thanks!