Skip to contentSkip to conversation

Questions on the task isolation patches

DISCUSSION yunhong jiang 3 participants 7 messages Dec 1, 2016 – Dec 22, 2016

lore
Share & tools
lore
#0 lore raw

Hi, Chris
I noticed your task isolation patch set at
https://lkml.org/lkml/2016/8/9/759 . Thanks a lot for the great effort.

I checked the patch and have some questions about how to use this
functionality on the NFV environment. In the NFV scenario, high speed network code runs on a VM user space and the VM is hosted by KVM hypervisor. To achieve the high speed network, not only the network code should be isolated, also the vCPU thread.

I checked your patch to think how to isolate the vCPU thread, and I have
some questions and hope your hints:

a) If the task isolation need prctl to mark itself as isolated, possibly the vCPU thread can't achieve it. First, the vCPU thread may need system service during OS booting time, also it's the application, instead of the vCPU thread to decide if the vCPU thread should be isolated. So possibly we need a mechanism so that another process can set the vCPU thread's task isolation?

b) I noticed that curently the task_isolation_prepare() is invoked on exit_to_usermode_loop(), while we may need such job on VM Exit procedure, or interrupt handling during VM exit handling.

Also, I'm also considering how to utilize this task_isolation for network
node which is not busy-loop, like the interrupt mode DPDK code. In the interrupt mode DPDK code, the application may yield the CPU if there is no network packet for a very long time and it will re-enter the busy loop mode once new packet arrived. This interrupt mode will be helpful for both power management and resource utilization. Per my understanding, the application should turn off the task isolation before yield the CPU and the restart the task isolation after the new packet, right?

Thanks
--jyh

#1 lore raw
Quoted 9 lines · yunhong jiang

Hi, Chris
I noticed your task isolation patch set at
https://lkml.org/lkml/2016/8/9/759 . Thanks a lot for the great effort.

I checked the patch and have some questions about how to use this
functionality on the NFV environment. In the NFV scenario, high speed network code runs on a VM user space and the VM is hosted by KVM hypervisor. To achieve the high speed network, not only the network code should be isolated, also the vCPU thread.

That's true.

Quoted 9 lines

I checked your patch to think how to isolate the vCPU thread, and I have
some questions and hope your hints:

a) If the task isolation need prctl to mark itself as isolated, possibly the vCPU thread can't achieve it. First, the vCPU thread may need system service during OS booting time, also it's the application, instead of the vCPU thread to decide if the vCPU thread should be isolated. So possibly we need a mechanism so that another process can set the vCPU thread's task isolation?

These are good questions. I think that the we would probably want to add a KVM mode that did the prctl() before transitioning back to the guest. But then, in the same way that we currently allow another prctl() from a task-isolated userspace process, we'd probably need to allow a KVM exit from a guest to happen without triggering any task-isolation errors.

Alternately, if we add the proposed NOSIG mode, then the hypervisor can use that, and simply stay in task-isolation mode no matter what system support is requested.

Presumably in the guest, we'd run task isolation as well, but presumably we'd only exit to the hypervisor if we were already in the guest kernel? Although I guess you could image providing trapping mmio mappings to the guest's userspace process that caused a hypervisor exit. Perhaps we extend the hypervisor to know that a guest might support task isolation, and to generate a warning on behalf of the guest if the hypervisor sees an exit from the guest's userspace and the guest task is in task-isolation mode?

Quoted 3 lines

b) I noticed that curently the task_isolation_prepare() is invoked on exit_to_usermode_loop(), while we may need such job on VM Exit procedure, or interrupt handling during VM exit handling.

Yes, something like that. I am not super-familiar with the KVM internals (I did a KVM port to the tile architecture a while back, but I'd have to swap all that memory back in before I could even have a half-educated opinion.)

Quoted 8 lines

Also, I'm also considering how to utilize this task_isolation for network
node which is not busy-loop, like the interrupt mode DPDK code. In the interrupt mode DPDK code, the application may yield the CPU if there is no network packet for a very long time and it will re-enter the busy loop mode once new packet arrived. This interrupt mode will be helpful for both power management and resource utilization. Per my understanding, the application should turn off the task isolation before yield the CPU and the restart the task isolation after the new packet, right?

Yes, exactly.

I am not likely to pursue KVM myself, at least until the basic patch series has been accepted upstream.

Signature · 2 lines
Chris Metcalf, Mellanox Technologies
http://www.mellanox.com
#2 lore raw
Quoted 24 lines · On Fri, 2 Dec 2016 13:58:08 -0500 Chris Metcalf <[email protected]> wrote:
Quoted 10 lines · yunhong jiang

Hi, Chris
I noticed your task isolation patch set at
https://lkml.org/lkml/2016/8/9/759 . Thanks a lot for the great effort.

I checked the patch and have some questions about how to use
this functionality on the NFV environment. In the NFV scenario, high speed network code runs on a VM user space and the VM is hosted by KVM hypervisor. To achieve the high speed network, not only the network code should be isolated, also the vCPU thread.

That's true.

Quoted 9 lines

I checked your patch to think how to isolate the vCPU thread,
and I have some questions and hope your hints:

a) If the task isolation need prctl to mark itself as isolated, possibly the vCPU thread can't achieve it. First, the vCPU thread may need system service during OS booting time, also it's the application, instead of the vCPU thread to decide if the vCPU thread should be isolated. So possibly we need a mechanism so that another process can set the vCPU thread's task isolation?

Quoted 2 lines

These are good questions. I think that the we would probably want to add a KVM mode that did the prctl() before transitioning back to the

Would prctl() when back to gues be too heavy?

Quoted 2 lines

guest. But then, in the same way that we currently allow another prctl() from a task-isolated userspace process, we'd probably need to

You mean currently in your patch we alraedy can do the prctl from 3rd party process to task-isolate a userspace process? Sorry that I didn't notice that part.

Quoted 2 lines

allow a KVM exit from a guest to happen without triggering any task-isolation errors.

yes.

Quoted 4 lines

Alternately, if we add the proposed NOSIG mode, then the hypervisor can use that, and simply stay in task-isolation mode no matter what system support is requested.

Yes, possibly we will keep the vCPU thread as always NOSIG mode.

Quoted 10 lines

Presumably in the guest, we'd run task isolation as well, but presumably we'd only exit to the hypervisor if we were already in the guest kernel? Although I guess you could image providing trapping mmio mappings to the guest's userspace process that caused a hypervisor exit. Perhaps we extend the hypervisor to know that a guest might support task isolation, and to generate a warning on behalf of the guest if the hypervisor sees an exit from the guest's userspace and the guest task is in task-isolation mode?

Quoted 8 lines
Quoted 3 lines

b) I noticed that curently the task_isolation_prepare() is invoked on exit_to_usermode_loop(), while we may need such job on VM Exit procedure, or interrupt handling during VM exit handling.

Yes, something like that. I am not super-familiar with the KVM internals (I did a KVM port to the tile architecture a while back, but I'd have to swap all that memory back in before I could even have a half-educated opinion.)

Got it.

Quoted 11 lines
Quoted 10 lines

Also, I'm also considering how to utilize this task_isolation
for network node which is not busy-loop, like the interrupt mode DPDK code. In the interrupt mode DPDK code, the application may yield the CPU if there is no network packet for a very long time and it will re-enter the busy loop mode once new packet arrived. This interrupt mode will be helpful for both power management and resource utilization. Per my understanding, the application should turn off the task isolation before yield the CPU and the restart the task isolation after the new packet, right?

Quoted 4 lines

Yes, exactly.

I am not likely to pursue KVM myself, at least until the basic patch series has been accepted upstream.

Yes, and I will be more than happy to help on this.

Thanks
-jyh

Quoted 1 line
#3 lore raw

Sorry for the slow response - I have been busy with some other things.

Quoted 10 lines · yunhong jiang
Quoted 7 lines · On Fri, 2 Dec 2016 13:58:08 -0500 Chris Metcalf <[email protected]> wrote:
Quoted 6 lines · yunhong jiang

a) If the task isolation need prctl to mark itself as isolated, possibly the vCPU thread can't achieve it. First, the vCPU thread may need system service during OS booting time, also it's the application, instead of the vCPU thread to decide if the vCPU thread should be isolated. So possibly we need a mechanism so that another process can set the vCPU thread's task isolation?

Quoted 3 lines
Quoted 2 lines

These are good questions. I think that the we would probably want to add a KVM mode that did the prctl() before transitioning back to the

Would prctl() when back to guest be too heavy?

It's a good question; it can be heavy. But the design for task isolation is that the task isolated process is always running in userspace anyway. If you are transitioning in and out of the guest or host kernels frequently, you probably should not be using task isolation, but just regular NOHZ_FULL.

Quoted 5 lines
Quoted 2 lines

guest. But then, in the same way that we currently allow another prctl() from a task-isolated userspace process, we'd probably need to

You mean currently in your patch we alraedy can do the prctl from 3rd party process to task-isolate a userspace process? Sorry that I didn't notice that part.

Sorry, I think I wasn't clear. Normally when you are running task isolated and you enter the kernel, you will get a fatal signal. The exception is if you call prctl itself (or exit), the kernel tolerates it without a signal, since obviously that's how you need to cleanly tell the kernel you are done with task isolation.

My point in the previous email was that we might need to similarly tolerate a guest exit without causing a fatal signal to the userspace process. But as I think about it, that's probably not true; we probably would want to notify the guest kernel of the task isolation violation and have it kill the userspace process just as if it had entered the guest kernel.

Perhaps the way to drive this is to have task isolation be triggered from the guest's prctl up to the host, so there's some kind of KVM exit to the host that indicates that the guest has a userspace process that wants to run task isolated, at which point qemu invokes task isolation on behalf of the guest then returns to the guest to set up its own virtualized task isolation. It does get confusing!

Signature · 2 lines
Chris Metcalf, Mellanox Technologies
http://www.mellanox.com
#4 lore raw
Quoted 1 line · On Fri, 16 Dec 2016 16:00:48 -0500 Chris Metcalf <[email protected]> wrote:

Sorry for the slow response - I have been busy with some other things.

Thanks for the reply.

Quoted 15 lines · yunhong jiang
Quoted 13 lines
Quoted 10 lines · On Fri, 2 Dec 2016 13:58:08 -0500 Chris Metcalf <[email protected]> wrote:
Quoted 6 lines · yunhong jiang

a) If the task isolation need prctl to mark itself as isolated, possibly the vCPU thread can't achieve it. First, the vCPU thread may need system service during OS booting time, also it's the application, instead of the vCPU thread to decide if the vCPU thread should be isolated. So possibly we need a mechanism so that another process can set the vCPU thread's task isolation?

These are good questions. I think that the we would probably want to add a KVM mode that did the prctl() before transitioning back to the

Quoted 7 lines
Quoted 1 line

Would prctl() when back to guest be too heavy?

It's a good question; it can be heavy. But the design for task isolation is that the task isolated process is always running in userspace anyway. If you are transitioning in and out of the guest or host kernels frequently, you probably should not be using task isolation, but just regular NOHZ_FULL.

As you pointed out late, the guest task isolation does not gurantee no guest VM exit to host, although we hope we can achieve vmexit free situation in future.

Quoted 14 lines
Quoted 7 lines
Quoted 4 lines

guest. But then, in the same way that we currently allow another prctl() from a task-isolated userspace process, we'd probably need to

You mean currently in your patch we alraedy can do the prctl from 3rd party process to task-isolate a userspace process? Sorry that I didn't notice that part.

Sorry, I think I wasn't clear. Normally when you are running task isolated and you enter the kernel, you will get a fatal signal. The exception is if you call prctl itself (or exit), the kernel tolerates it without a signal, since obviously that's how you need to cleanly tell the kernel you are done with task isolation.

Quoted 6 lines

My point in the previous email was that we might need to similarly tolerate a guest exit without causing a fatal signal to the userspace process. But as I think about it, that's probably not true; we probably would want to notify the guest kernel of the task isolation violation and have it kill the userspace process just as if it had entered the guest kernel.

Thanks for the clarification. It's clear now.

Quoted 7 lines

Perhaps the way to drive this is to have task isolation be triggered from the guest's prctl up to the host, so there's some kind of KVM exit to the host that indicates that the guest has a userspace process that wants to run task isolated, at which point qemu invokes task isolation on behalf of the guest then returns to the guest to set up its own virtualized task isolation. It does get confusing!

Hmm, PV solution is always a choice on virtualization world.

Quoted 1 line

BTW, currently both the isolated CPU and task isolation requires the kernel parameter to reserve CPUs in advance. Possibly we can extend it to be dynamic like through sysfs in future, to avoid resource wast.

--jyh

#5 lore raw
In reply to Chris Metcalf
Quoted 6 lines · Chris Metcalf

Sorry, I think I wasn't clear. Normally when you are running task isolated and you enter the kernel, you will get a fatal signal. The exception is if you call prctl itself (or exit), the kernel tolerates it without a signal, since obviously that's how you need to cleanly tell the kernel you are done with task isolation.

Running in a guest is pretty much the same as running in userspace. Would it be possible to exclude the KVM_RUN ioctl as well? QEMU would still have to run prctl when a CPU goes to sleep, and KVM_RUN would have to enable/disable isolated mode when a VM executes HLT (which should never happen anyway in NFV scenarios).

Paolo

#6 lore raw
Quoted 11 lines · Paolo Bonzini
Quoted 5 lines · Chris Metcalf

Sorry, I think I wasn't clear. Normally when you are running task isolated and you enter the kernel, you will get a fatal signal. The exception is if you call prctl itself (or exit), the kernel tolerates it without a signal, since obviously that's how you need to cleanly tell the kernel you are done with task isolation.

Running in a guest is pretty much the same as running in userspace. Would it be possible to exclude the KVM_RUN ioctl as well? QEMU would still have to run prctl when a CPU goes to sleep, and KVM_RUN would have to enable/disable isolated mode when a VM executes HLT (which should never happen anyway in NFV scenarios).

I think that probably makes sense. The flow would be that qemu executes first the prctl() for task isolation, then the KVM_RUN ioctl. We obviously can't do it in the other order, so we'd need to make task isolation tolerate KVM_RUN.

I won't try to do it for my next patch series (based on 4.10) though, since I'd like to get the basic support upstreamed before trying to extend it.

Signature · 2 lines
Chris Metcalf, Mellanox Technologies
http://www.mellanox.com