Re: [PATCH V3 21/23] xen/arm: Add mapcache invalidation handling
In reply to Stefano StabelliniOn 11.12.20 03:28, Stefano Stabellini wrote:
Hi Julien, Stefano
Quoted 165 lines · Julien Grall
Quoted 16 lines · Stefano Stabellini
Quoted 15 lines · Oleksandr Tyshchenko
Quoted 14 lines
From: Oleksandr Tyshchenko <[email protected]>
We need to send mapcache invalidation request to qemu/demu everytime the page gets removed from a guest.
At the moment, the Arm code doesn't explicitely remove the existing mapping before inserting the new mapping. Instead, this is done implicitely by
__p2m_set_entry().So we need to recognize a case when old entry is a RAM page *and* the new MFN is different in order to set the corresponding flag. The most suitable place to do this is
p2m_free_entry(), there we can find the correct leaf type. The invalidation request will be sent indo_trap_hypercall()later on.Quoted 6 lines
Quoted 1 line
Why is it sent in
do_trap_hypercall()?I believe this is following the approach used by x86. There are actually some discussion about it (see [1]).
Leaving aside the toolstack case for now, AFAIK, the only way a guest can modify its p2m is via an hypercall. Do you have an example otherwise?
OK this is a very important assumption. We should write it down for sure. I think it is true today on ARM.
Quoted 7 lines
When sending the invalidation request, the vCPU will be blocked until all the IOREQ server have acknowledged the invalidation. So the hypercall seems to be the best position to do it.
Alternatively, we could use
check_for_vcpu_work()to check if the mapcache needs to be invalidated. The inconvenience is we would execute a few more instructions in each entry/exit path.Yeah it would be more natural to call it from
check_for_vcpu_work(). If we put it between #ifdefCONFIG_IOREQ_SERVERit wouldn't be bad. But I am not a fan of increasing the instructions on the exit path either.
From this point of view, putting it at the end ofdo_trap_hypercallis a
nice trick actually. Let's just make sure it has a good comment on top.Quoted 68 lines
Quoted 57 lines
Quoted 57 lines
Signed-off-by Oleksandr Tyshchenko <[email protected]>CC Julien Grall <[email protected]>---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"Changes V1 -> V2:
- new patch, some changes were derived from (+ new explanation):
xen/ioreq: Make x86's invalidate qemu mapcache handling common
- put setting of the flag into__p2m_set_entry()
- clarify the conditions when the flag should be set
- usedomain_has_ioreq_server()
- updatedo_trap_hypercall()by adding local variableChanges V2 -> V3:
- update patch description
- move check top2m_free_entry()
- add a comment
- use "curr" instead of "v" indo_trap_hypercall()
------ xen/arch/arm/p2m.c | 24 ++++++++++++++++-------- xen/arch/arm/traps.c | 13 ++++++++++--- 2 files changed, 26 insertions(+), 11 deletions(-)xen/arch/arm/p2m.c +1
-0@@ -1,6 +1,7 @@#include <xen/cpu.h> #include <xen/domain_page.h> #include <xen/iocap.h> +#include <xen/ioreq.h> #include <xen/lib.h> #include <xen/sched.h> #include <xen/softirq.h> @@ -749,17 +750,24 @@ static void p2m_free_entry(struct p2m_domain *p2m,if ( !p2m_is_valid (entry) )return ; - /* Nothing to do but updating the stats if the entry is asuper-page. */
xen/arch/arm/p2m.c +7
-4-if (p2m_is_superpage (entry, level) ) +if (p2m_is_superpage (entry, level) || (level ==3 ) ) { - p2m->stats.mappings[level]--; -return ; - } +#ifdef CONFIG_IOREQ_SERVER +/* +* If this gets called (non-recursively) then either the entry +* was replaced by an entry with a different base (valid case) or +* the shattering of a superpage was failed (error case). +* So, at worst, the spurious mapcache invalidation might be sent.
+ */Quoted 8 lines
Quoted 4 lines
xen/arch/arm/p2m.c +2
-0+ if ( domain_has_ioreq_server(p2m->domain) && + (p2m->domain == current->domain) &&
p2m_is_ram(entry.p2m.type))
+p2m->domain->mapcache_invalidate= true;Why the (
p2m->domain==current->domain) check? Shouldn't we setmapcache_invalidateto true anyway? What happens ifp2m->domain!=current->domain? We wouldn't want the domain to lose themapcache_invalidatenotification.This is also discussed in [1]. :) The main question is why would a toolstack/device model modify the guest memory after boot?
Quoted 8 lines
If we assume it does, then the device model would need to pause the domain before modifying the RAM.
We also need to make sure that all the IOREQ servers have invalidated the mapcache before the domain run again.
This would require quite a bit of work. I am not sure the effort is worth if there are no active users today.
OK, that explains why we think
p2m->domain==current->domain, but why do we need to have a check for it right here?In other words, we don't think it is realistc to get here with
p2m->domain!=current->domain, but let's say that we do somehow. What's the best course of action? Probably, setmapcache_invalidateto true and possibly print a warning?Leaving
mapcache_invalidateto false doesn't seem to be what we want to do?Quoted 36 lines
Quoted 36 lines
Quoted 21 lines
BUILD_BUG_ON(NR_hypercalls < ARRAY_SIZE(arm_hypercall_table) ); @@ -1459,7 +1460,7 @@ static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr, return; }-
current->hcall_preempted= false;xen/arch/arm/p2m.c +2
-1+ curr->hcall_preempted = false;perfc_incra (hypercalls, *nr); call = arm_hypercall_table[*nr].fn;@@ -1472,7 +1473,7 @@ static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr,HYPERCALL_RESULT_REG (regs) =call (HYPERCALL_ARGS (regs));#ifndef NDEBUG -if ( !current->hcall_preempted ) +if ( !curr->hcall_preempted ) {/* Deliberately corrupt parameter regs used by this hypercall. */ switch ( arm_hypercall_table[*nr].nr_args ) {xen/arch/arm/p2m.c +0
-0@@ -1489,8 +1490,14 @@ static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr,xen/arch/arm/p2m.c static void do_trap_hypercall(struct cpu_user_regs · line 1499
Quoted 10 lines
xen/arch/arm/p2m.c +6
-1#endif /* Ensure the hypercall trap instruction is re-executed. */ -if ( current->hcall_preempted ) +if ( curr->hcall_preempted ) regs->pc -=4 ;/* re-execute 'hvc #XEN_HYPERCALL_TAG' */ + +#ifdef CONFIG_IOREQ_SERVER +if (unlikely (curr->domain->mapcache_invalidate) && +test_and_clear_bool (curr->domain->mapcache_invalidate) ) +ioreq_signal_mapcache_invalidate ();Why not just:
if ( unlikely(test_and_clear_bool(curr->domain->mapcache_invalidate)) )
ioreq_signal_mapcache_invalidate();
Quoted 12 lines
Quoted 6 lines
This seems to match the x86 code. My guess is they tried to prevent the cost of the atomic operation if there is no chance
mapcache_invalidateis true.I am split whether the first check is worth it. The atomic operation should be uncontended most of the time, so it should be quick. But it will always be slower than just a read because there is always a store involved.
I am not a fun of optimizations with unclear benefits :-)
Quoted 3 lines
On a related topic, Jan pointed out that the invalidation would not work properly if you have multiple vCPU modifying the P2M at the same time.
Thanks to Julien, he explained all bits in detail. Indeed I followed how it was done on x86 (place where to send the invalidation request, the code to check whether the flag is set, which at first glance, appears odd, etc) and review comments (to latch current into the local variable, and make sure that domain sends invalidation request on itself).
Regarding what to do if p2m->domain != current->domain in p2m_free_entry(). Probably we could set flag only if guest is paused, otherwise just print a warning. Thoughts?
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Re: [PATCH V3 21/23] xen/arm: Add mapcache invalidation handling
Quoted 191 lines · Oleksandr
Quoted 180 lines · Stefano Stabellini
Quoted 16 lines · Julien Grall
Quoted 15 lines · Stefano Stabellini
Quoted 14 lines · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
We need to send mapcache invalidation request to qemu/demu everytime the page gets removed from a guest.
At the moment, the Arm code doesn't explicitely remove the existing mapping before inserting the new mapping. Instead, this is done implicitely by
__p2m_set_entry().So we need to recognize a case when old entry is a RAM page *and* the new MFN is different in order to set the corresponding flag. The most suitable place to do this is
p2m_free_entry(), there we can find the correct leaf type. The invalidation request will be sent indo_trap_hypercall()later on.Quoted 7 lines
Quoted 1 line
Why is it sent in
do_trap_hypercall()?I believe this is following the approach used by x86. There are actually some
discussion about it (see [1]).Leaving aside the toolstack case for now, AFAIK, the only way a guest can modify its p2m is via an hypercall. Do you have an example otherwise?
OK this is a very important assumption. We should write it down for sure. I think it is true today on ARM.
Quoted 9 lines
When sending the invalidation request, the vCPU will be blocked until all the
IOREQ server have acknowledged the invalidation. So the hypercall seems to be
the best position to do it.Alternatively, we could use
check_for_vcpu_work()to check if the mapcache needs to be invalidated. The inconvenience is we would execute a few more instructions in each entry/exit path.Yeah it would be more natural to call it from
check_for_vcpu_work(). If we put it between #ifdefCONFIG_IOREQ_SERVERit wouldn't be bad. But I am not a fan of increasing the instructions on the exit path either.
From this point of view, putting it at the end ofdo_trap_hypercallis a
nice trick actually. Let's just make sure it has a good comment on top.Quoted 74 lines
Quoted 60 lines
Quoted 60 lines
Signed-off-by Oleksandr Tyshchenko <[email protected]>CC Julien Grall <[email protected]>---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"Changes V1 -> V2:
- new patch, some changes were derived from (+ new explanation):
xen/ioreq: Make x86's invalidate qemu mapcache handling common
- put setting of the flag into__p2m_set_entry()
- clarify the conditions when the flag should be set
- usedomain_has_ioreq_server()
- updatedo_trap_hypercall()by adding local variableChanges V2 -> V3:
- update patch description
- move check top2m_free_entry()
- add a comment
- use "curr" instead of "v" indo_trap_hypercall()
------ xen/arch/arm/p2m.c | 24 ++++++++++++++++-------- xen/arch/arm/traps.c | 13 ++++++++++--- 2 files changed, 26 insertions(+), 11 deletions(-)xen/arch/arm/p2m.c +1
-0@@ -1,6 +1,7 @@#include <xen/cpu.h> #include <xen/domain_page.h> #include <xen/iocap.h> +#include <xen/ioreq.h> #include <xen/lib.h> #include <xen/sched.h> #include <xen/softirq.h> @@ -749,17 +750,24 @@ static void p2m_free_entry(struct p2m_domain *p2m, if ( !p2m_is_valid(entry) ) return; - /* Nothing to do but updating the stats if the entry is asuper-page. */
xen/arch/arm/p2m.c +4
-4-if (p2m_is_superpage (entry, level) ) +if (p2m_is_superpage (entry, level) || (level ==3 ) ) { - p2m->stats.mappings[level]--; -return ; - } +#ifdef CONFIG_IOREQ_SERVER +/* +* If this gets called (non-recursively) then either the entry
+ * was replaced by an entry with a different base (valid
case) orxen/arch/arm/p2m.c +2
-0+* the shattering of a superpage was failed (error case). +* So, at worst, the spurious mapcache invalidation might be sent.
+ */Quoted 8 lines
Quoted 4 lines
xen/arch/arm/p2m.c +2
-0+ if ( domain_has_ioreq_server(p2m->domain) && + (p2m->domain == current->domain) &&
p2m_is_ram(entry.p2m.type))
+p2m->domain->mapcache_invalidate= true;Why the (
p2m->domain==current->domain) check? Shouldn't we setmapcache_invalidateto true anyway? What happens ifp2m->domain!=current->domain? We wouldn't want the domain to lose themapcache_invalidatenotification.This is also discussed in [1]. :) The main question is why would a toolstack/device model modify the guest memory after boot?
If we assume it does, then the device model would need to pause the domain before modifying the RAM.
Quoted 6 lines
We also need to make sure that all the IOREQ servers have invalidated the mapcache before the domain run again.
This would require quite a bit of work. I am not sure the effort is worth if
there are no active users today.OK, that explains why we think
p2m->domain==current->domain, but why do we need to have a check for it right here?In other words, we don't think it is realistc to get here with
p2m->domain!=current->domain, but let's say that we do somehow. What's the best course of action? Probably, setmapcache_invalidateto true and possibly print a warning?Leaving
mapcache_invalidateto false doesn't seem to be what we want to do?Quoted 44 lines
Quoted 37 lines
Quoted 27 lines
BUILD_BUG_ON(NR_hypercalls < ARRAY_SIZE(arm_hypercall_table) ); @@ -1459,7 +1460,7 @@ static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr, return; }-
current->hcall_preempted= false;xen/arch/arm/p2m.c +1
-0+ curr->hcall_preempted = false;perfc_incra (hypercalls, *nr); call = arm_hypercall_table[*nr].fn;@@ -1472,7 +1473,7 @@ static void do_trap_hypercall(struct
cpu_user_regs
*regs,register_t*nr,HYPERCALL_RESULT_REG(regs) = call(HYPERCALL_ARGS(regs)); #ifndef NDEBUGxen/arch/arm/p2m.c +1
-1-if ( !current->hcall_preempted ) +if ( !curr->hcall_preempted ) {/* Deliberately corrupt parameter regs used by this hypercall.
*/switch ( arm_hypercall_table[*nr].nr_args ) {xen/arch/arm/p2m.c +0
-0@@ -1489,8 +1490,14 @@ static void do_trap_hypercall(struct
cpu_user_regs
*regs,register_t*nr,#endif /* Ensure the hypercall trap instruction is re-executed. */xen/arch/arm/p2m.c
Quoted 8 lines
xen/arch/arm/p2m.c +6
-1-if ( current->hcall_preempted ) +if ( curr->hcall_preempted ) regs->pc -=4 ;/* re-execute 'hvc #XEN_HYPERCALL_TAG' */ + +#ifdef CONFIG_IOREQ_SERVER +if (unlikely (curr->domain->mapcache_invalidate) && +test_and_clear_bool (curr->domain->mapcache_invalidate) ) +ioreq_signal_mapcache_invalidate ();Why not just:
Quoted 3 lines
if ( unlikely(test_and_clear_bool(curr->domain->mapcache_invalidate)) )
ioreq_signal_mapcache_invalidate();This seems to match the x86 code. My guess is they tried to prevent the cost
of the atomic operation if there is no chancemapcache_invalidateis true.Quoted 10 lines
Quoted 4 lines
I am split whether the first check is worth it. The atomic operation should be
uncontended most of the time, so it should be quick. But it will always be slower than just a read because there is always a store involved.I am not a fun of optimizations with unclear benefits :-)
Quoted 3 lines
On a related topic, Jan pointed out that the invalidation would not work properly if you have multiple vCPU modifying the P2M at the same time.
Quoted 8 lines
Thanks to Julien, he explained all bits in detail. Indeed I followed how it was done on x86 (place where to send the invalidation request, the code to check whether the flag is set, which at first glance, appears odd, etc) and review comments (to latch current into the local variable, and make sure that domain sends invalidation request on itself).
Regarding what to do ifp2m->domain!=current->domaininp2m_free_entry(). Probably we could set flag only if guest is paused, otherwise just print a warning. Thoughts?
I'd do something like:
if ( domain_has_ioreq_server(p2m->domain) && p2m_is_ram(entry.p2m.type) )
{
WARN_ON(p2m->domain != current->domain);
p2m->domain->mapcache_invalidate = true;
}but maybe Julien has a better idea.
Re: [PATCH V3 21/23] xen/arm: Add mapcache invalidation handling
Quoted 201 lines · Stefano Stabellini
Quoted 191 lines · Oleksandr
Quoted 180 lines · Stefano Stabellini
Quoted 16 lines · Julien Grall
Quoted 15 lines · Stefano Stabellini
Quoted 14 lines · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
We need to send mapcache invalidation request to qemu/demu everytime the page gets removed from a guest.
At the moment, the Arm code doesn't explicitely remove the existing mapping before inserting the new mapping. Instead, this is done implicitely by
__p2m_set_entry().So we need to recognize a case when old entry is a RAM page *and* the new MFN is different in order to set the corresponding flag. The most suitable place to do this is
p2m_free_entry(), there we can find the correct leaf type. The invalidation request will be sent indo_trap_hypercall()later on.Quoted 7 lines
Quoted 1 line
Why is it sent in
do_trap_hypercall()?I believe this is following the approach used by x86. There are actually some
discussion about it (see [1]).Leaving aside the toolstack case for now, AFAIK, the only way a guest can modify its p2m is via an hypercall. Do you have an example otherwise?
OK this is a very important assumption. We should write it down for sure. I think it is true today on ARM.
Quoted 9 lines
When sending the invalidation request, the vCPU will be blocked until all the
IOREQ server have acknowledged the invalidation. So the hypercall seems to be
the best position to do it.Alternatively, we could use
check_for_vcpu_work()to check if the mapcache needs to be invalidated. The inconvenience is we would execute a few more instructions in each entry/exit path.Yeah it would be more natural to call it from
check_for_vcpu_work(). If we put it between #ifdefCONFIG_IOREQ_SERVERit wouldn't be bad. But I am not a fan of increasing the instructions on the exit path either.
From this point of view, putting it at the end ofdo_trap_hypercallis a
nice trick actually. Let's just make sure it has a good comment on top.Quoted 74 lines
Quoted 60 lines
Quoted 60 lines
Signed-off-by Oleksandr Tyshchenko <[email protected]>CC Julien Grall <[email protected]>---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"Changes V1 -> V2:
- new patch, some changes were derived from (+ new explanation):
xen/ioreq: Make x86's invalidate qemu mapcache handling common
- put setting of the flag into__p2m_set_entry()
- clarify the conditions when the flag should be set
- usedomain_has_ioreq_server()
- updatedo_trap_hypercall()by adding local variableChanges V2 -> V3:
- update patch description
- move check top2m_free_entry()
- add a comment
- use "curr" instead of "v" indo_trap_hypercall()
------ xen/arch/arm/p2m.c | 24 ++++++++++++++++-------- xen/arch/arm/traps.c | 13 ++++++++++--- 2 files changed, 26 insertions(+), 11 deletions(-)xen/arch/arm/p2m.c +1
-0@@ -1,6 +1,7 @@#include <xen/cpu.h> #include <xen/domain_page.h> #include <xen/iocap.h> +#include <xen/ioreq.h> #include <xen/lib.h> #include <xen/sched.h> #include <xen/softirq.h> @@ -749,17 +750,24 @@ static void p2m_free_entry(struct p2m_domain *p2m, if ( !p2m_is_valid(entry) ) return; - /* Nothing to do but updating the stats if the entry is asuper-page. */
xen/arch/arm/p2m.c +4
-4-if (p2m_is_superpage (entry, level) ) +if (p2m_is_superpage (entry, level) || (level ==3 ) ) { - p2m->stats.mappings[level]--; -return ; - } +#ifdef CONFIG_IOREQ_SERVER +/* +* If this gets called (non-recursively) then either the entry
+ * was replaced by an entry with a different base (valid
case) orxen/arch/arm/p2m.c +2
-0+* the shattering of a superpage was failed (error case). +* So, at worst, the spurious mapcache invalidation might be sent.
+ */Quoted 8 lines
Quoted 4 lines
xen/arch/arm/p2m.c +2
-0+ if ( domain_has_ioreq_server(p2m->domain) && + (p2m->domain == current->domain) &&
p2m_is_ram(entry.p2m.type))
+p2m->domain->mapcache_invalidate= true;Why the (
p2m->domain==current->domain) check? Shouldn't we setmapcache_invalidateto true anyway? What happens ifp2m->domain!=current->domain? We wouldn't want the domain to lose themapcache_invalidatenotification.This is also discussed in [1]. :) The main question is why would a toolstack/device model modify the guest memory after boot?
If we assume it does, then the device model would need to pause the domain before modifying the RAM.
Quoted 6 lines
We also need to make sure that all the IOREQ servers have invalidated the mapcache before the domain run again.
This would require quite a bit of work. I am not sure the effort is worth if
there are no active users today.OK, that explains why we think
p2m->domain==current->domain, but why do we need to have a check for it right here?In other words, we don't think it is realistc to get here with
p2m->domain!=current->domain, but let's say that we do somehow. What's the best course of action? Probably, setmapcache_invalidateto true and possibly print a warning?Leaving
mapcache_invalidateto false doesn't seem to be what we want to do?Quoted 44 lines
Quoted 37 lines
Quoted 27 lines
BUILD_BUG_ON(NR_hypercalls < ARRAY_SIZE(arm_hypercall_table) ); @@ -1459,7 +1460,7 @@ static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr, return; } - current->hcall_preempted = false;xen/arch/arm/p2m.c +1
-0+ curr->hcall_preempted = false;perfc_incra (hypercalls, *nr); call = arm_hypercall_table[*nr].fn;@@ -1472,7 +1473,7 @@ static void do_trap_hypercall(struct
cpu_user_regs
*regs,register_t*nr,HYPERCALL_RESULT_REG(regs) = call(HYPERCALL_ARGS(regs)); #ifndef NDEBUGxen/arch/arm/p2m.c +1
-1-if ( !current->hcall_preempted ) +if ( !curr->hcall_preempted ) {/* Deliberately corrupt parameter regs used by this hypercall.
*/switch ( arm_hypercall_table[*nr].nr_args ) {xen/arch/arm/p2m.c +0
-0@@ -1489,8 +1490,14 @@ static void do_trap_hypercall(struct
cpu_user_regs
*regs,register_t*nr,#endif /* Ensure the hypercall trap instruction is re-executed. */xen/arch/arm/p2m.c
Quoted 8 lines
xen/arch/arm/p2m.c +6
-1-if ( current->hcall_preempted ) +if ( curr->hcall_preempted ) regs->pc -=4 ;/* re-execute 'hvc #XEN_HYPERCALL_TAG' */ + +#ifdef CONFIG_IOREQ_SERVER +if (unlikely (curr->domain->mapcache_invalidate) && +test_and_clear_bool (curr->domain->mapcache_invalidate) ) +ioreq_signal_mapcache_invalidate ();Why not just:
Quoted 3 lines
if ( unlikely(test_and_clear_bool(curr->domain->mapcache_invalidate)) )
ioreq_signal_mapcache_invalidate();This seems to match the x86 code. My guess is they tried to prevent the cost
of the atomic operation if there is no chancemapcache_invalidateis true.Quoted 10 lines
Quoted 4 lines
I am split whether the first check is worth it. The atomic operation should be
uncontended most of the time, so it should be quick. But it will always be slower than just a read because there is always a store involved.I am not a fun of optimizations with unclear benefits :-)
Quoted 3 lines
On a related topic, Jan pointed out that the invalidation would not work properly if you have multiple vCPU modifying the P2M at the same time.
Quoted 8 lines
Thanks to Julien, he explained all bits in detail. Indeed I followed how it was done on x86 (place where to send the invalidation request, the code to check whether the flag is set, which at first glance, appears odd, etc) and review comments (to latch current into the local variable, and make sure that domain sends invalidation request on itself).
Regarding what to do ifp2m->domain!=current->domaininp2m_free_entry(). Probably we could set flag only if guest is paused, otherwise just print a warning. Thoughts?
Quoted 5 lines
I'd do something like:
if (
domain_has_ioreq_server(p2m->domain)&&p2m_is_ram(entry.p2m.type)){ WARN_ON(p2m->domain != current->domain)
IOREQ server are not trusted. Yet they will be able to reach this patch if one re-use the stubdomain model (they are allowed to modify guest layout).
So this change would hand a DoS attack to the IOREQ server on a silver platter :).
In general, we should avoid to use WARN_ON() for things that can be triggered by a domain. Instead we should use gprintk(XENLOG_WARNING, "...") to allow rate-limit.
On the cons side, it would be more difficult to spot any misue with a gprintk().
Quoted 4 lines
p2m->domain->mapcache_invalidate = true; }but maybe Julien has a better idea.
I suggested a different approach and some rationale in answer to your e-mail. Although, I am not sure if we could call it a better approach :). We can continue the discusison there.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH V3 21/23] xen/arm: Add mapcache invalidation handling
In reply to Stefano StabelliniHi Stefano,
Quoted 50 lines · Stefano Stabellini
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Signed-off-by Oleksandr Tyshchenko <[email protected]>CC Julien Grall <[email protected]>---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"Changes V1 -> V2:
- new patch, some changes were derived from (+ new explanation):
xen/ioreq: Make x86's invalidate qemu mapcache handling common
- put setting of the flag into__p2m_set_entry()
- clarify the conditions when the flag should be set
- usedomain_has_ioreq_server()
- updatedo_trap_hypercall()by adding local variableChanges V2 -> V3:
- update patch description
- move check top2m_free_entry()
- add a comment
- use "curr" instead of "v" indo_trap_hypercall()
------ xen/arch/arm/p2m.c | 24 ++++++++++++++++-------- xen/arch/arm/traps.c | 13 ++++++++++--- 2 files changed, 26 insertions(+), 11 deletions(-)xen/arch/arm/p2m.c +1
-0@@ -1,6 +1,7 @@#include <xen/cpu.h> #include <xen/domain_page.h> #include <xen/iocap.h> +#include <xen/ioreq.h> #include <xen/lib.h> #include <xen/sched.h> #include <xen/softirq.h> @@ -749,17 +750,24 @@ static void p2m_free_entry(struct p2m_domain *p2m,if ( !p2m_is_valid (entry) )return ; - /* Nothing to do but updating the stats if the entry is asuper-page. */
xen/arch/arm/p2m.c +2
-4-if (p2m_is_superpage (entry, level) ) +if (p2m_is_superpage (entry, level) || (level ==3 ) ) { - p2m->stats.mappings[level]--; -return ; - } +#ifdef CONFIG_IOREQ_SERVER
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
xen/arch/arm/p2m.c static void p2m_free_entry(struct p2m_domain *p2m, · line 762
Quoted 8 lines
xen/arch/arm/p2m.c +5
-0+/* +* If this gets called (non-recursively) then either the entry +* was replaced by an entry with a different base (valid case) or +* the shattering of a superpage was failed (error case). +* So, at worst, the spurious mapcache invalidation might be sent.
xen/arch/arm/p2m.c +2
-0+*/ + if ( domain_has_ioreq_server(p2m->domain) &&
Hmmm... I didn't realize that you were going to call domain_has_ioreq_server() here. Per your comment, this can only be called when on p2m->domain == current.
One way would be to switch the two check. However, I am not entirely sure this is necessary. I see no issue to always set mapcache_invalidate even if there are no IOREQ server available.
Quoted 18 lines
Quoted 18 lines
Quoted 8 lines
Quoted 3 lines
+ (
p2m->domain==current->domain) &&p2m_is_ram(entry.p2m.type))
+p2m->domain->mapcache_invalidate= true;Why the (
p2m->domain==current->domain) check? Shouldn't we setmapcache_invalidateto true anyway? What happens ifp2m->domain!=current->domain? We wouldn't want the domain to lose themapcache_invalidatenotification.This is also discussed in [1]. :) The main question is why would a toolstack/device model modify the guest memory after boot?
If we assume it does, then the device model would need to pause the domain before modifying the RAM.
We also need to make sure that all the IOREQ servers have invalidated the mapcache before the domain run again.
Quoted 8 lines
Quoted 2 lines
This would require quite a bit of work. I am not sure the effort is worth if there are no active users today.
OK, that explains why we think
p2m->domain==current->domain, but why do we need to have a check for it right here?In other words, we don't think it is realistc to get here with
p2m->domain!=current->domain, but let's say that we do somehow.
I am guessing by "here", you mean in the situation where a RAM entry would be removed. Is it correct? If so yes, I don't believe this should happen today (even at domain creation/destruction).
Quoted 2 lines
What's
the best course of action?
The best course of action would be to forward the invalidation to *all* the IOREQ servers and wait for it before the domain can run again.
Quoted 2 lines
Probably, set
mapcache_invalidateto true and
possibly print a warning?
So if the toolstack (or an IOREQ server ends to up use it), then we need to make sure all the IOREQ server have invalidated the mapcache before the domain can run again.
Quoted 3 lines
Leaving
mapcache_invalidateto false doesn't seem to be what we want to do?
Setting to true/false is not going to be very helful because the guest may never issue an hypercall.
Without any more work, the guest may get corrupted. So I would suggest to either prevent the P2M to be modified after the domain has been created and before it is destroyed (it more a stopgap) or fix it properly.
Quoted 38 lines
Quoted 38 lines
Quoted 37 lines
Quoted 21 lines
BUILD_BUG_ON(NR_hypercalls < ARRAY_SIZE(arm_hypercall_table) ); @@ -1459,7 +1460,7 @@ static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr, return; }-
current->hcall_preempted= false;xen/arch/arm/p2m.c +2
-1+ curr->hcall_preempted = false;perfc_incra (hypercalls, *nr); call = arm_hypercall_table[*nr].fn;@@ -1472,7 +1473,7 @@ static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr,HYPERCALL_RESULT_REG (regs) =call (HYPERCALL_ARGS (regs));#ifndef NDEBUG -if ( !current->hcall_preempted ) +if ( !curr->hcall_preempted ) {/* Deliberately corrupt parameter regs used by this hypercall. */ switch ( arm_hypercall_table[*nr].nr_args ) {xen/arch/arm/p2m.c +0
-0@@ -1489,8 +1490,14 @@ static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr,xen/arch/arm/p2m.c static void do_trap_hypercall(struct cpu_user_regs · line 1499
Quoted 10 lines
xen/arch/arm/p2m.c +6
-1#endif /* Ensure the hypercall trap instruction is re-executed. */ -if ( current->hcall_preempted ) +if ( curr->hcall_preempted ) regs->pc -=4 ;/* re-execute 'hvc #XEN_HYPERCALL_TAG' */ + +#ifdef CONFIG_IOREQ_SERVER +if (unlikely (curr->domain->mapcache_invalidate) && +test_and_clear_bool (curr->domain->mapcache_invalidate) ) +ioreq_signal_mapcache_invalidate ();Why not just:
if ( unlikely(test_and_clear_bool(curr->domain->mapcache_invalidate)) )
ioreq_signal_mapcache_invalidate();
Quoted 8 lines
Quoted 6 lines
This seems to match the x86 code. My guess is they tried to prevent the cost of the atomic operation if there is no chance
mapcache_invalidateis true.I am split whether the first check is worth it. The atomic operation should be uncontended most of the time, so it should be quick. But it will always be slower than just a read because there is always a store involved.
I am not a fun of optimizations with unclear benefits :-)
I thought a bit more about it and I am actually leaning towards keeping the first check.
The common implementation of the hypercall path is mostly (if not all) accessing per-vCPU variables. So the hypercalls can mostly work independently (at least in the common part).
Assuming we drop the first check, we would now be writing to a per-domain variable at every hypercall. You are probably going to notice performance impact if you were going to benchmark concurrent no-op hypercall, because the cache line is going to bounce (because of the write).
Arguably, this may become noise if you execute a full hypercall. But I would still like to treat the common hypercall path as the entry/exit path. IOW, I would like to be careful in what we add there.
The main reason is hypercalls may be used quite a lot by PV backends or device emulator (if we think about Virtio).
If we decided to move the change in the entry/exit path, then it would
definitely be an issue for the reasons I explained above. So I would also like to avoid the write in shared variable if we can.
FAOD, I am not saying this optmization will save the world :). I am sure there will be more (in particular in the vGIC part) in order to get Virtio performance in par with PV backends on Xen.
This discussion would also be moot if ...
Quoted 3 lines
Quoted 3 lines
On a related topic, Jan pointed out that the invalidation would not work properly if you have multiple vCPU modifying the P2M at the same time.
... we had a per-vCPU flag instead.
Cheers,
Signature · 1 line
Julien Grall
PATCH v3 22/23 libxl: Introduce basic virtio-mmio support on Arm
In reply to Oleksandr TyshchenkoFrom: Julien Grall <[email protected]>
This patch creates specific device node in the Guest device-tree with allocated MMIO range and SPI interrupt if specific 'virtio' property is present in domain config.
---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"
Changes RFC -> V1:
- was squashed with:
"[RFC PATCH V1 09/12] libxl: Handle virtio-mmio irq in more correct way" "[RFC PATCH V1 11/12] libxl: Insert "dma-coherent" property into virtio-mmio device node" "[RFC PATCH V1 12/12] libxl: Fix duplicate memory node in DT"
- move VirtIO MMIO #define-s to xen/include/public/arch-arm.h
Changes V1 -> V2:
- update the author of a patch
Changes V2 -> V3:
- no changes
---
--- tools/libs/light/libxl_arm.c | 58 ++++++++++++++++++++++++++++++++++++++-- tools/libs/light/libxl_types.idl | 1 + tools/xl/xl_parse.c | 1 + xen/include/public/arch-arm.h | 5 ++++ 4 files changed, 63 insertions(+), 2 deletions(-)
tools/libs/light/libxl_arm.c +56 -2
@@ -26,8 +26,8 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, {uint32_t nr_spis =0 ;unsigned int i; -uint32_t vuart_irq; -bool vuart_enabled = false; +uint32_t vuart_irq, virtio_irq; +bool vuart_enabled = false, virtio_enabled = false;/* * If pl011 vuart is enabled then increment the nr_spis to allow allocation
@@ -39,6 +39,17 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, vuart_enabled = true; } +/* +* XXX: Handle properly virtio +* A proper solution would be the toolstack to allocate the interrupts +* used by each virtio backend and let the backend now which one is used +*/ +if (libxl_defbool_val (d_config->b_info.arch_arm.virtio)) { + nr_spis += (GUEST_VIRTIO_MMIO_SPI -32 ) +1 ; + virtio_irq =GUEST_VIRTIO_MMIO_SPI ; + virtio_enabled = true; + } +for (i =0 ; i < d_config->b_info.num_irqs; i++) {uint32_t irq = d_config->b_info.irqs[i];uint32_t spi;
@@ -58,6 +69,12 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,return ERROR_FAIL ; } +/* The same check as for vpl011 */ +if (virtio_enabled && irq == virtio_irq) { +LOG (ERROR ,"Physical IRQ %u conflicting with virtio SPI\n" , irq); +return ERROR_FAIL ; + } +if (irq <32 )continue ;
@@ -658,6 +675,39 @@ static int make_vpl011_uart_node(libxl__gc *gc, void *fdt,return 0 ; } +static int make_virtio_mmio_node (libxl__gc *gc,void *fdt, +uint64_t base,uint32_t irq) +{ +int res; +gic_interrupt intr; +/* Placeholder for virtio@ + a 64-bit number + \0 */ +char buf[24 ]; + +snprintf (buf,sizeof (buf),"virtio@%" PRIx64, base); + res =fdt_begin_node (fdt, buf); +if (res)return res; + + res =fdt_property_compat (gc, fdt,1 ,"virtio,mmio" ); +if (res)return res; + + res =fdt_property_regs (gc, fdt,GUEST_ROOT_ADDRESS_CELLS ,GUEST_ROOT_SIZE_CELLS , +1 , base,GUEST_VIRTIO_MMIO_SIZE ); +if (res)return res; + +set_interrupt (intr, irq,0xf ,DT_IRQ_TYPE_EDGE_RISING ); + res =fdt_property_interrupts (gc, fdt, &intr,1 ); +if (res)return res; + + res =fdt_property (fdt,"dma-coherent" ,NULL ,0 ); +if (res)return res; + + res =fdt_end_node (fdt); +if (res)return res; + +return 0 ; + +} +static const struct arch_info *get_arch_info (libxl__gc *gc,const struct xc_dom_image *dom) {
@@ -961,6 +1011,9 @@ next_resize:if (info->tee ==LIBXL_TEE_TYPE_OPTEE )FDT (make_optee_node (gc, fdt) ); +if (libxl_defbool_val (info->arch_arm.virtio)) +FDT (make_virtio_mmio_node (gc, fdt,GUEST_VIRTIO_MMIO_BASE ,GUEST_VIRTIO_MMIO_SPI ) ); +if (pfdt)FDT (copy_partial_fdt (gc, fdt, pfdt) );
@@ -1178,6 +1231,7 @@ void libxl__arch_domain_build_info_setdefault(libxl__gc *gc, {/* ACPI is disabled by default */ libxl_defbool_setdefault (&b_info->acpi, false); +libxl_defbool_setdefault (&b_info->arch_arm.virtio, false);if (b_info->type !=LIBXL_DOMAIN_TYPE_PV )return ;
tools/libs/light/libxl_types.idl +1 -0
@@ -639,6 +639,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("arch_arm", Struct(None, [("gic_version", libxl_gic_version), + ("virtio", libxl_defbool), ("vuart", libxl_vuart_type), ])), # Alternate p2m is not bound to any architecture or guest type, as it is
tools/xl/xl_parse.c +1 -0
@@ -2581,6 +2581,7 @@ skip_usbdev: }xlu_cfg_get_defbool (config,"dm_restrict" , &b_info->dm_restrict,0 ); +xlu_cfg_get_defbool (config,"virtio" , &b_info->arch_arm.virtio,0 );if (c_info->type ==LIBXL_DOMAIN_TYPE_HVM ) {if (!xlu_cfg_get_string (config,"vga" , &buf,0 )) {
xen/include/public/arch-arm.h +5 -0
@@ -464,6 +464,11 @@ typedef uint64_t xen_callback_t;#define PSCI_cpu_on 2#define PSCI_migrate 3 +/* VirtIO MMIO definitions */ +#define GUEST_VIRTIO_MMIO_BASE xen_mk_ullong(0x02000000) +#define GUEST_VIRTIO_MMIO_SIZE xen_mk_ullong(0x200) +#define GUEST_VIRTIO_MMIO_SPI 33 +#endif #ifndef __ASSEMBLY__
Signature · 1 line
2.7.4
RFC PATCH v3 23/23 libxl: Add support for virtio-disk configuration
In reply to Oleksandr TyshchenkoFrom: Oleksandr Tyshchenko <[email protected]>
This patch adds basic support for configuring and assisting virtio-disk backend (emualator) which is intended to run out of Qemu and could be run in any domain.
Xenstore was chosen as a communication interface for the emulator running in non-toolstack domain to be able to get configuration either by reading Xenstore directly or by receiving command line parameters (an updated 'xl devd' running in the same domain would read Xenstore beforehand and call backend executable with the required arguments).
An example of domain configuration (two disks are assigned to the guest, the latter is in readonly mode):
vdisk = [ 'backend=DomD, disks=rw:/dev/mmcblk0p3;ro:/dev/mmcblk1p3' ]
Where per-disk Xenstore entries are:
- filename and readonly flag (configured via "vdisk" property)
- base and irq (allocated dynamically)
Besides handling 'visible' params described in configuration file, patch also allocates virtio-mmio specific ones for each device and writes them into Xenstore. virtio-mmio params (irq and base) are unique per guest domain, they allocated at the domain creation time and passed through to the emulator. Each VirtIO device has at least one pair of these params.
TODO:
1. An extra "virtio" property could be removed.
2. Update documentation.
---
Changes RFC -> V1:
- no changes
Changes V1 -> V2:
- rebase according to the new location of libxl_virtio_disk.c
Changes V2 -> V3:
- no changes
Please note, there is a real concern about VirtIO interrupts allocation. Just copy here what Stefano said in RFC thread.
So, if we end up allocating let's say 6 virtio interrupts for a domain, the chance of a clash with a physical interrupt of a passthrough device is real.
I am not entirely sure how to solve it, but these are a few ideas:
- choosing virtio interrupts that are less likely to conflict (maybe > 1000)
- make the virtio irq (optionally) configurable so that a user could override the default irq and specify one that doesn't conflict
- implementing support for virq != pirq (even the xl interface doesn't allow to specify the virq number for passthrough devices, see "irqs")
Also there is one suggestion from Wei Chen regarding a parameter for domain config file which I haven't addressed yet.
[Just copy here what Wei said in V2 thread]
Can we keep use the same 'disk' parameter for virtio-disk, but add an option like "model=virtio-disk"?
For example:
disk = [ 'backend=DomD, disks=rw:/dev/mmcblk0p3,model=virtio-disk' ] Just like what Xen has done for x86 virtio-net.
---
--- tools/libs/light/Makefile | 1 + tools/libs/light/libxl_arm.c | 56 ++++++++++++--- tools/libs/light/libxl_create.c | 1 + tools/libs/light/libxl_internal.h | 1 + tools/libs/light/libxl_types.idl | 15 ++++ tools/libs/light/libxl_types_internal.idl | 1 + tools/libs/light/libxl_virtio_disk.c | 109 ++++++++++++++++++++++++++++ tools/xl/Makefile | 2 +- tools/xl/xl.h | 3 + tools/xl/xl_cmdtable.c | 15 ++++ tools/xl/xl_parse.c | 115 ++++++++++++++++++++++++++++++ tools/xl/xl_virtio_disk.c | 46 ++++++++++++ 12 files changed, 354 insertions(+), 11 deletions(-) create mode 100644 tools/libs/light/libxl_virtio_disk.c create mode 100644 tools/xl/xl_virtio_disk.c
tools/libs/light/Makefile +1 -0
@@ -115,6 +115,7 @@ SRCS-y += libxl_genid.c SRCS-y += _libxl_types.c SRCS-y += libxl_flask.c SRCS-y += _libxl_types_internal.c +SRCS-y += libxl_virtio_disk.c ifeq ($(CONFIG_LIBNL),y) CFLAGS_LIBXL += $(LIBNL3_CFLAGS)
tools/libs/light/libxl_arm.c +46 -10
82 lines not on this page · raw message
tools/libs/light/libxl_create.c +1 -0
@@ -1821,6 +1821,7 @@ const libxl__device_type *device_type_tbl[] = { &libxl__dtdev_devtype, &libxl__vdispl_devtype, &libxl__vsnd_devtype, + &libxl__virtio_disk_devtype, NULL };
tools/libs/light/libxl_internal.h +1 -0
@@ -4000,6 +4000,7 @@ extern const libxl__device_type libxl__vdispl_devtype;extern const libxl__device_type libxl__p9_devtype;extern const libxl__device_type libxl__pvcallsif_devtype;extern const libxl__device_type libxl__vsnd_devtype; +extern const libxl__device_type libxl__virtio_disk_devtype;extern const libxl__device_type *device_type_tbl[];
tools/libs/light/libxl_types.idl +15 -0
@@ -935,6 +935,20 @@ libxl_device_vsnd = Struct("device_vsnd", [ ("pcms", Array(libxl_vsnd_pcm, "num_vsnd_pcms")) ]) +libxl_virtio_disk_param = Struct("virtio_disk_param", [ + ("filename", string), + ("readonly", bool), + ("irq", uint32), + ("base", uint64), + ]) + +libxl_device_virtio_disk = Struct("device_virtio_disk", [ + ("backend_domid", libxl_domid), + ("backend_domname", string), + ("devid", libxl_devid), + ("disks", Array(libxl_virtio_disk_param, "num_disks")), + ]) + libxl_domain_config = Struct("domain_config", [ ("c_info", libxl_domain_create_info), ("b_info", libxl_domain_build_info),
@@ -951,6 +965,7 @@ libxl_domain_config = Struct("domain_config", [ ("pvcallsifs", Array(libxl_device_pvcallsif, "num_pvcallsifs")), ("vdispls", Array(libxl_device_vdispl, "num_vdispls")), ("vsnds", Array(libxl_device_vsnd, "num_vsnds")), + ("virtio_disks", Array(libxl_device_virtio_disk, "num_virtio_disks")), # a channel manifests as a console with a name, # see docs/misc/channels.txt ("channels", Array(libxl_device_channel, "num_channels")),
tools/libs/light/libxl_types_internal.idl +1 -0
@@ -32,6 +32,7 @@ libxl__device_kind = Enumeration("device_kind", [ (14, "PVCALLS"), (15, "VSND"), (16, "VINPUT"), + (17, "VIRTIO_DISK"), ]) libxl__console_backend = Enumeration("console_backend", [
tools/libs/light/libxl_virtio_disk.c new file +109 -0
109 lines not on this page · raw message
tools/xl/Makefile +1 -1
@@ -23,7 +23,7 @@ XL_OBJS += xl_vtpm.o xl_block.o xl_nic.o xl_usb.o XL_OBJS += xl_sched.o xl_pci.o xl_vcpu.o xl_cdrom.o xl_mem.o XL_OBJS += xl_info.o xl_console.o xl_misc.o XL_OBJS += xl_vmcontrol.o xl_saverestore.o xl_migrate.o -XL_OBJS += xl_vdispl.o xl_vsnd.o xl_vkb.o +XL_OBJS += xl_vdispl.o xl_vsnd.o xl_vkb.o xl_virtio_disk.o $(XL_OBJS): CFLAGS += $(CFLAGS_libxentoollog) $(XL_OBJS): CFLAGS += $(CFLAGS_XL)
tools/xl/xl.h +3 -0
@@ -178,6 +178,9 @@ int main_vsnddetach(int argc, char **argv);int main_vkbattach (int argc,char **argv);int main_vkblist (int argc,char **argv);int main_vkbdetach (int argc,char **argv); +int main_virtio_diskattach (int argc,char **argv); +int main_virtio_disklist (int argc,char **argv); +int main_virtio_diskdetach (int argc,char **argv);int main_usbctrl_attach (int argc,char **argv);int main_usbctrl_detach (int argc,char **argv);int main_usbdev_attach (int argc,char **argv);
tools/xl/xl_cmdtable.c +15 -0
@@ -435,6 +435,21 @@ struct cmd_spec cmd_table[] = {"Destroy a domain's virtual sound device" ,"<Domain> <DevId>" , }, + { "virtio-disk-attach", + &main_virtio_diskattach,1 ,1 , +"Create a new virtio block device" , +" TBD\n" + }, + { "virtio-disk-list", + &main_virtio_disklist,0 ,0 , +"List virtio block devices for a domain" , +"<Domain(s)>" , + }, + { "virtio-disk-detach", + &main_virtio_diskdetach,0 ,1 , +"Destroy a domain's virtio block device" , +"<Domain> <DevId>" , + }, { "uptime", &main_uptime,0 ,0 , "Print uptime for all/some domains",
tools/xl/xl_parse.c +115 -0
127 lines not on this page · raw message
tools/xl/xl_virtio_disk.c new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH V3 00/23] IOREQ feature (+ virtio-mmio) on Arm
In reply to Oleksandr TyshchenkoQuoted 1 line · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
Hello all.
Added missed subject line. I am sorry for the inconvenience.
Quoted 192 lines
Date: Sat, 28 Nov 2020 22:33:51 +0200
Subject: [PATCH V3 00/23] IOREQ feature (+ virtio-mmio) on Arm
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bitHello all.
The purpose of this patch series is to add IOREQ/DM support to Xen on Arm. You can find an initial discussion at [1] and RFC/V1/V2 series at [2]/[3]/[4]. Xen on Arm requires some implementation to forward guest MMIO access to a device model in order to implement virtio-mmio backend or even mediator outside of hypervisor. As Xen on x86 already contains required support this series tries to make it common and introduce Arm specific bits plus some new functionality. Patch series is based on Julien's PoC "xen/arm: Add support for Guest IO forwarding to a device emulator". Besides splitting existing IOREQ/DM support and introducing Arm side, the series also includes virtio-mmio related changes (last 2 patches for toolstack) for the reviewers to be able to see how the whole picture could look like.
According to the initial discussion there are a few open questions/concerns regarding security, performance in VirtIO solution:
1. virtio-mmio vs virtio-pci, SPI vs MSI, different use-cases require different transport...
2. virtio backend is able to access all guest memory, some kind of protection is needed: 'virtio-iommu in Xen' vs 'pre-shared-memory & memcpys in guest'
3. interface between toolstack and 'out-of-qemu' virtio backend, avoid using Xenstore in virtio backend if possible.
4. a lot of 'foreing mapping' could lead to the memory exhaustion, Julien has some idea regarding that.Looks like all of them are valid and worth considering, but the first thing which we need on Arm is a mechanism to forward guest IO to a device emulator, so let's focus on it in the first place.
***
There are a lot of changes since RFC series, almost all TODOs were resolved on Arm, Arm code was improved and hardened, common IOREQ/DM code became really arch-agnostic (without HVM-ism), the "legacy" mechanism of mapping magic pages for the IOREQ servers was left x86 specific, etc. But one TODO still remains which is "PIO handling" on Arm. The "PIO handling" TODO is expected to left unaddressed for the current series. It is not an big issue for now while Xen doesn't have support for vPCI on Arm. On Arm64 they are only used for PCI IO Bar and we would probably want to expose them to emulator as PIO access to make a DM completely arch-agnostic. So "PIO handling" should be implemented when we add support for vPCI.
I left interface untouched in the following patch "xen/dm: Introduce
xendevicemodel_set_irq_levelDM op" since there is still an open discussion what interface to use/what information to pass to the hypervisor.There is a patch on review this series depends on:
https://patchwork.kernel.org/patch/11816689Please note, that IOREQ feature is disabled by default on Arm within current series.
***
Patch series [5] was rebased on recent "staging branch"
(181f2c2 evtchn: double per-channel locking can't hit identical channels) and tested on Renesas Salvator-X board + H3 ES3.0 SoC (Arm64) with virtio-mmio disk backend [6] running in driver domain and unmodified Linux Guest running on existing virtio-blk driver (frontend). No issues were observed. Guest domain 'reboot/destroy' use-cases work properly. Patch series was only build-tested on x86.Please note, build-test passed for the following modes:
1. x86:CONFIG_HVM=y/CONFIG_IOREQ_SERVER=y(default)
2. x86: #CONFIG_HVM is not set / #CONFIG_IOREQ_SERVER is not set
3. Arm64:CONFIG_HVM=y/CONFIG_IOREQ_SERVER=y
4. Arm64:CONFIG_HVM=y/ #CONFIG_IOREQ_SERVER is not set (default)
5. Arm32:CONFIG_HVM=y/CONFIG_IOREQ_SERVER=y
6. Arm32:CONFIG_HVM=y/ #CONFIG_IOREQ_SERVER is not set (default)***
Any feedback/help would be highly appreciated.
[1] https://lists.xenproject.org/archives/html/xen-devel/2020-07/msg00825.html
[2] https://lists.xenproject.org/archives/html/xen-devel/2020-08/msg00071.html
[3] https://lists.xenproject.org/archives/html/xen-devel/2020-09/msg00732.html
[4] https://lists.xenproject.org/archives/html/xen-devel/2020-10/msg01077.html
[5] https://github.com/otyshchenko1/xen/commits/ioreq_4.14_ml4
[6] https://github.com/xen-troops/virtio-disk/commits/ioreq_ml1Julien Grall (5):
xen/dm: Make x86's DM feature common
xen/mm: Make x86'sXENMEM_resource_ioreq_serverhandling common arm/ioreq: Introduce arch specific bits for IOREQ/DM features xen/dm: Introducexendevicemodel_set_irq_levelDM op
libxl: Introduce basic virtio-mmio support on ArmOleksandr Tyshchenko (18):
x86/ioreq: Prepare IOREQ feature for making it common x86/ioreq: Add IOREQ_STATUS_* #define-s and update code for moving x86/ioreq: Provide out-of-line wrapper for thehandle_mmio()xen/ioreq: Make x86's IOREQ feature common
xen/ioreq: Make x86'shvm_ioreq_needs_completion()common xen/ioreq: Make x86's hvm_mmio_first(last)_byte() common xen/ioreq: Make x86'shvm_ioreq_(page/vcpu/server)structs common xen/ioreq: Move x86'sioreq_serverto struct domain xen/ioreq: Move x86's io_completion/io_req fields to struct vcpu xen/ioreq: Remove "hvm" prefixes from involved function names xen/ioreq: Useguest_cmpxchg64()instead ofcmpxchg()xen/arm: Stick around inleave_hypervisor_to_guestuntil I/O has
completed
xen/mm: Handle properly reference inset_foreign_p2m_entry()on Arm xen/ioreq: Introducedomain_has_ioreq_server()
xen/arm: io: Abstract sign-extension
xen/ioreq: Make x86'ssend_invalidate_req()common xen/arm: Add mapcache invalidation handling
[RFC] libxl: Add support for virtio-disk configurationMAINTAINERS | 8 +- tools/include/xendevicemodel.h | 4 + tools/libs/devicemodel/core.c | 18 + tools/libs/devicemodel/libxendevicemodel.map | 1 + tools/libs/light/Makefile | 1 + tools/libs/light/libxl_arm.c | 94 +- tools/libs/light/libxl_create.c | 1 + tools/libs/light/libxl_internal.h | 1 + tools/libs/light/libxl_types.idl | 16 + tools/libs/light/libxl_types_internal.idl | 1 + tools/libs/light/libxl_virtio_disk.c | 109 +++ tools/xl/Makefile | 2 +- tools/xl/xl.h | 3 + tools/xl/xl_cmdtable.c | 15 + tools/xl/xl_parse.c | 116 +++ tools/xl/xl_virtio_disk.c | 46 + xen/arch/arm/Makefile | 2 + xen/arch/arm/dm.c | 89 ++ xen/arch/arm/domain.c | 9 + xen/arch/arm/hvm.c | 4 + xen/arch/arm/io.c | 29 +- xen/arch/arm/ioreq.c | 126 +++ xen/arch/arm/p2m.c | 48 +- xen/arch/arm/traps.c | 58 +- xen/arch/x86/Kconfig | 1 + xen/arch/x86/hvm/dm.c | 295 +----- xen/arch/x86/hvm/emulate.c | 80 +- xen/arch/x86/hvm/hvm.c | 12 +- xen/arch/x86/hvm/hypercall.c | 9 +- xen/arch/x86/hvm/intercept.c | 5 +- xen/arch/x86/hvm/io.c | 26 +- xen/arch/x86/hvm/ioreq.c | 1357 ++------------------------ xen/arch/x86/hvm/stdvga.c | 10 +- xen/arch/x86/hvm/svm/nestedsvm.c | 2 +- xen/arch/x86/hvm/vmx/realmode.c | 6 +- xen/arch/x86/hvm/vmx/vvmx.c | 2 +- xen/arch/x86/mm.c | 46 +- xen/arch/x86/mm/p2m.c | 13 +- xen/arch/x86/mm/shadow/common.c | 2 +- xen/common/Kconfig | 3 + xen/common/Makefile | 2 + xen/common/dm.c | 292 ++++++ xen/common/ioreq.c | 1307 +++++++++++++++++++++++++ xen/common/memory.c | 73 +- xen/include/asm-arm/domain.h | 3 + xen/include/asm-arm/hvm/ioreq.h | 139 +++ xen/include/asm-arm/mm.h | 8 - xen/include/asm-arm/mmio.h | 1 + xen/include/asm-arm/p2m.h | 19 +- xen/include/asm-arm/traps.h | 24 + xen/include/asm-x86/hvm/domain.h | 43 - xen/include/asm-x86/hvm/emulate.h | 2 +- xen/include/asm-x86/hvm/io.h | 17 - xen/include/asm-x86/hvm/ioreq.h | 58 +- xen/include/asm-x86/hvm/vcpu.h | 18 - xen/include/asm-x86/mm.h | 4 - xen/include/asm-x86/p2m.h | 24 +- xen/include/public/arch-arm.h | 5 + xen/include/public/hvm/dm_op.h | 16 + xen/include/xen/dm.h | 44 + xen/include/xen/ioreq.h | 146 +++ xen/include/xen/p2m-common.h | 4 + xen/include/xen/sched.h | 32 + xen/include/xsm/dummy.h | 4 +- xen/include/xsm/xsm.h | 6 +- xen/xsm/dummy.c | 2 +- xen/xsm/flask/hooks.c | 5 +- 67 files changed, 3084 insertions(+), 1884 deletions(-)create mode 100644
tools/libs/light/libxl_virtio_disk.ccreate mode 100644tools/xl/xl_virtio_disk.ccreate mode 100644xen/arch/arm/dm.c
create mode 100644xen/arch/arm/ioreq.c
create mode 100644xen/common/dm.c
create mode 100644xen/common/ioreq.c
create mode 100644xen/include/asm-arm/hvm/ioreq.hcreate mode 100644xen/include/xen/dm.h
create mode 100644xen/include/xen/ioreq.h
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Wei Chen
Tested-byRE: [PATCH V3 00/23] IOREQ feature (+ virtio-mmio) on Arm
Hi Oleksandr,
I have tested v3. It works well with the latest virtio-backend service[1].
[1] https://github.com/xen-troops/virtio-disk/commits/ioreq_ml1
Regards,
Wei Chen
Quoted 245 lines
-----Original Message-----
From: Oleksandr <[email protected]>
Sent: 2020年11月30日 19:23
To: [email protected]
Cc: Oleksandr Tyshchenko <[email protected]>; Paul Durrant <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Wei Liu <[email protected]>; Julien Grall <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Tim Deegan <[email protected]>; Daniel De Graaf <[email protected]>; Volodymyr Babchuk <[email protected]>; Jun Nakajima <[email protected]>; Kevin Tian <[email protected]>; Anthony PERARD <[email protected]>; Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>; Kaly Xin <[email protected]>; Artem Mygaiev <[email protected]>; Alex Bennée <[email protected]>
Subject: Re: [PATCH V3 00/23] IOREQ feature (+ virtio-mmio) on ArmQuoted 1 line · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
Hello all.
Added missed subject line. I am sorry for the inconvenience.
Quoted 8 lines
Date: Sat, 28 Nov 2020 22:33:51 +0200
Subject: [PATCH V3 00/23] IOREQ feature (+ virtio-mmio) on Arm
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bitQuoted 5 lines
Hello all.
The purpose of this patch series is to add IOREQ/DM support to Xen on Arm. You can find an initial discussion at [1] and RFC/V1/V2 series at [2]/[3]/[4]. Xen on Arm requires some implementation to forward guest MMIO access to a
device
Quoted 1 line
model in order to implement virtio-mmio backend or even mediator outside of
hypervisor.
Quoted 1 line
As Xen on x86 already contains required support this series tries to make it
common
Quoted 1 line
and introduce Arm specific bits plus some new functionality. Patch series is
based on
Quoted 1 line
Julien's PoC "xen/arm: Add support for Guest IO forwarding to a device
emulator".
Quoted 1 line
Besides splitting existing IOREQ/DM support and introducing Arm side, the
series
Quoted 14 lines
also includes virtio-mmio related changes (last 2 patches for toolstack) for the reviewers to be able to see how the whole picture could look like.
According to the initial discussion there are a few open questions/concerns regarding security, performance in VirtIO solution:
1. virtio-mmio vs virtio-pci, SPI vs MSI, different use-cases require different transport...
2. virtio backend is able to access all guest memory, some kind of protection is needed: 'virtio-iommu in Xen' vs 'pre-shared-memory & memcpys in guest'
3. interface between toolstack and 'out-of-qemu' virtio backend, avoid using Xenstore in virtio backend if possible.
4. a lot of 'foreing mapping' could lead to the memory exhaustion, Julien has some idea regarding that.Quoted 2 lines
Looks like all of them are valid and worth considering, but the first thing which we need on Arm is a mechanism to forward guest IO to a device
emulator,
Quoted 5 lines
so let's focus on it in the first place.
***
There are a lot of changes since RFC series, almost all TODOs were resolved on
Arm,
Quoted 1 line
Arm code was improved and hardened, common IOREQ/DM code became
really arch-agnostic
Quoted 1 line
(without HVM-ism), the "legacy" mechanism of mapping magic pages for the
IOREQ servers
Quoted 1 line
was left x86 specific, etc. But one TODO still remains which is "PIO handling"
on Arm.
Quoted 3 lines
The "PIO handling" TODO is expected to left unaddressed for the current series. It is not an big issue for now while Xen doesn't have support for vPCI on Arm. On Arm64 they are only used for PCI IO Bar and we would probably want to
expose
Quoted 1 line
them to emulator as PIO access to make a DM completely arch-agnostic. So
"PIO handling"
Quoted 11 lines
should be implemented when we add support for vPCI.
I left interface untouched in the following patch "xen/dm: Introduce
xendevicemodel_set_irq_levelDM op" since there is still an open discussion what interface to use/what information to pass to the hypervisor.There is a patch on review this series depends on:
https://patchwork.kernel.org/patch/11816689Please note, that IOREQ feature is disabled by default on Arm within current
series.
Quoted 5 lines
***
Patch series [5] was rebased on recent "staging branch"
(181f2c2 evtchn: double per-channel locking can't hit identical channels) andtested on
Quoted 1 line
Renesas Salvator-X board + H3 ES3.0 SoC (Arm64) with virtio-mmio disk
backend [6]
Quoted 2 lines
running in driver domain and unmodified Linux Guest running on existing virtio-blk driver (frontend). No issues were observed. Guest domain
'reboot/destroy'
Quoted 10 lines
use-cases work properly. Patch series was only build-tested on x86.
Please note, build-test passed for the following modes:
1. x86:CONFIG_HVM=y/CONFIG_IOREQ_SERVER=y(default)
2. x86: #CONFIG_HVM is not set / #CONFIG_IOREQ_SERVER is not set
3. Arm64:CONFIG_HVM=y/CONFIG_IOREQ_SERVER=y
4. Arm64:CONFIG_HVM=y/ #CONFIG_IOREQ_SERVER is not set (default)
5. Arm32:CONFIG_HVM=y/CONFIG_IOREQ_SERVER=y
6. Arm32:CONFIG_HVM=y/ #CONFIG_IOREQ_SERVER is not set (default)Quoted 5 lines
***
Any feedback/help would be highly appreciated.
[1] https://lists.xenproject.org/archives/html/xen-devel/2020-
07/msg00825.html
Quoted 1 line
[2] https://lists.xenproject.org/archives/html/xen-devel/2020-
08/msg00071.html
Quoted 1 line
[3] https://lists.xenproject.org/archives/html/xen-devel/2020-
09/msg00732.html
Quoted 1 line
[4] https://lists.xenproject.org/archives/html/xen-devel/2020-
10/msg01077.html
Quoted 99 lines
[5] https://github.com/otyshchenko1/xen/commits/ioreq_4.14_ml4
[6] https://github.com/xen-troops/virtio-disk/commits/ioreq_ml1Julien Grall (5):
xen/dm: Make x86's DM feature common
xen/mm: Make x86'sXENMEM_resource_ioreq_serverhandling common arm/ioreq: Introduce arch specific bits for IOREQ/DM features xen/dm: Introducexendevicemodel_set_irq_levelDM op
libxl: Introduce basic virtio-mmio support on ArmOleksandr Tyshchenko (18):
x86/ioreq: Prepare IOREQ feature for making it common x86/ioreq: Add IOREQ_STATUS_* #define-s and update code for moving x86/ioreq: Provide out-of-line wrapper for thehandle_mmio()xen/ioreq: Make x86's IOREQ feature common
xen/ioreq: Make x86'shvm_ioreq_needs_completion()common xen/ioreq: Make x86's hvm_mmio_first(last)_byte() common xen/ioreq: Make x86'shvm_ioreq_(page/vcpu/server)structs common xen/ioreq: Move x86'sioreq_serverto struct domain xen/ioreq: Move x86's io_completion/io_req fields to struct vcpu xen/ioreq: Remove "hvm" prefixes from involved function names xen/ioreq: Useguest_cmpxchg64()instead ofcmpxchg()xen/arm: Stick around inleave_hypervisor_to_guestuntil I/O has
completed
xen/mm: Handle properly reference inset_foreign_p2m_entry()on Arm xen/ioreq: Introducedomain_has_ioreq_server()
xen/arm: io: Abstract sign-extension
xen/ioreq: Make x86'ssend_invalidate_req()common xen/arm: Add mapcache invalidation handling
[RFC] libxl: Add support for virtio-disk configurationMAINTAINERS | 8 +- tools/include/xendevicemodel.h | 4 + tools/libs/devicemodel/core.c | 18 + tools/libs/devicemodel/libxendevicemodel.map | 1 + tools/libs/light/Makefile | 1 + tools/libs/light/libxl_arm.c | 94 +- tools/libs/light/libxl_create.c | 1 + tools/libs/light/libxl_internal.h | 1 + tools/libs/light/libxl_types.idl | 16 + tools/libs/light/libxl_types_internal.idl | 1 + tools/libs/light/libxl_virtio_disk.c | 109 +++ tools/xl/Makefile | 2 +- tools/xl/xl.h | 3 + tools/xl/xl_cmdtable.c | 15 + tools/xl/xl_parse.c | 116 +++ tools/xl/xl_virtio_disk.c | 46 + xen/arch/arm/Makefile | 2 + xen/arch/arm/dm.c | 89 ++ xen/arch/arm/domain.c | 9 + xen/arch/arm/hvm.c | 4 + xen/arch/arm/io.c | 29 +- xen/arch/arm/ioreq.c | 126 +++ xen/arch/arm/p2m.c | 48 +- xen/arch/arm/traps.c | 58 +- xen/arch/x86/Kconfig | 1 + xen/arch/x86/hvm/dm.c | 295 +----- xen/arch/x86/hvm/emulate.c | 80 +- xen/arch/x86/hvm/hvm.c | 12 +- xen/arch/x86/hvm/hypercall.c | 9 +- xen/arch/x86/hvm/intercept.c | 5 +- xen/arch/x86/hvm/io.c | 26 +- xen/arch/x86/hvm/ioreq.c | 1357 ++------------------------ xen/arch/x86/hvm/stdvga.c | 10 +- xen/arch/x86/hvm/svm/nestedsvm.c | 2 +- xen/arch/x86/hvm/vmx/realmode.c | 6 +- xen/arch/x86/hvm/vmx/vvmx.c | 2 +- xen/arch/x86/mm.c | 46 +- xen/arch/x86/mm/p2m.c | 13 +- xen/arch/x86/mm/shadow/common.c | 2 +- xen/common/Kconfig | 3 + xen/common/Makefile | 2 + xen/common/dm.c | 292 ++++++ xen/common/ioreq.c | 1307 +++++++++++++++++++++++++ xen/common/memory.c | 73 +- xen/include/asm-arm/domain.h | 3 + xen/include/asm-arm/hvm/ioreq.h | 139 +++ xen/include/asm-arm/mm.h | 8 - xen/include/asm-arm/mmio.h | 1 + xen/include/asm-arm/p2m.h | 19 +- xen/include/asm-arm/traps.h | 24 + xen/include/asm-x86/hvm/domain.h | 43 - xen/include/asm-x86/hvm/emulate.h | 2 +- xen/include/asm-x86/hvm/io.h | 17 - xen/include/asm-x86/hvm/ioreq.h | 58 +- xen/include/asm-x86/hvm/vcpu.h | 18 - xen/include/asm-x86/mm.h | 4 - xen/include/asm-x86/p2m.h | 24 +- xen/include/public/arch-arm.h | 5 + xen/include/public/hvm/dm_op.h | 16 + xen/include/xen/dm.h | 44 + xen/include/xen/ioreq.h | 146 +++ xen/include/xen/p2m-common.h | 4 + xen/include/xen/sched.h | 32 + xen/include/xsm/dummy.h | 4 +- xen/include/xsm/xsm.h | 6 +- xen/xsm/dummy.c | 2 +- xen/xsm/flask/hooks.c | 5 +- 67 files changed, 3084 insertions(+), 1884 deletions(-)Quoted 10 lines
create mode 100644
tools/libs/light/libxl_virtio_disk.ccreate mode 100644tools/xl/xl_virtio_disk.ccreate mode 100644xen/arch/arm/dm.c
create mode 100644xen/arch/arm/ioreq.c
create mode 100644xen/common/dm.c
create mode 100644xen/common/ioreq.c
create mode 100644xen/include/asm-arm/hvm/ioreq.hcreate mode 100644xen/include/xen/dm.h
create mode 100644xen/include/xen/ioreq.h--
Regards,Oleksandr Tyshchenko
Re: [PATCH V3 00/23] IOREQ feature (+ virtio-mmio) on Arm
Quoted 1 line · Wei Chen
Hi Oleksandr,
Hi Wei
Quoted 5 lines
I have tested v3. It works well with the latest virtio-backend service[1].
[1] https://github.com/xen-troops/virtio-disk/commits/ioreq_ml1Tested-by Wei Chen <[email protected]>
Thank you very much for the testing!
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Quoted 11 lines · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
Date: Sat, 28 Nov 2020 22:33:51 +0200
Subject: [PATCH V3 00/23] IOREQ feature (+ virtio-mmio) on Arm
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bitHello all.
Quoted 11 lines
The purpose of this patch series is to add IOREQ/DM support to Xen on Arm. You can find an initial discussion at [1] and RFC/V1/V2 series at [2]/[3]/[4]. Xen on Arm requires some implementation to forward guest MMIO access to a device model in order to implement virtio-mmio backend or even mediator outside of hypervisor. As Xen on x86 already contains required support this series tries to make it common and introduce Arm specific bits plus some new functionality. Patch series is based on Julien's PoC "xen/arm: Add support for Guest IO forwarding to a device emulator". Besides splitting existing IOREQ/DM support and introducing Arm side, the series also includes virtio-mmio related changes (last 2 patches for toolstack) for the reviewers to be able to see how the whole picture could look like.
Thanks for posting the latest version.
Quoted 5 lines
According to the initial discussion there are a few open questions/concerns regarding security, performance in VirtIO solution:
1. virtio-mmio vs virtio-pci, SPI vs MSI, different use-cases require different transport...
I think I'm repeating things here I've said in various ephemeral video chats over the last few weeks but I should probably put things down on the record.
I think the original intention of the virtio framers is advanced features would build on virtio-pci because you get a bunch of things "for free" - notably enumeration and MSI support. There is assumption that by the time you add these features to virtio-mmio you end up re-creating your own less well tested version of virtio-pci. I've not been terribly convinced by the argument that the guest implementation of PCI presents a sufficiently large blob of code to make the simpler MMIO desirable. My attempts to build two virtio kernels (PCI/MMIO) with otherwise the same devices wasn't terribly conclusive either way.
That said virtio-mmio still has life in it because the cloudy slimmed down guests moved to using it because the enumeration of PCI is a road block to their fast boot up requirements. I'm sure they would also appreciate a MSI implementation to reduce the overhead that handling notifications currently has on trap-and-emulate.
AIUI for Xen the other downside to PCI is you would have to emulate it in the hypervisor which would be additional code at the most privileged level.
Quoted 3 lines
2. virtio backend is able to access all guest memory, some kind of protection is needed: 'virtio-iommu in Xen' vs 'pre-shared-memory & memcpys in guest'
This is also an area of interest for Project Stratos and something we would like to be solved generally for all hypervisors. There is a good write up of some approaches that Jean Phillipe did on the stratos mailing list:
From: Jean-Philippe Brucker <[email protected]>
Subject: Limited memory sharing investigation
Message-ID: <20201002134336.GA2196245@myrica>
I suspect there is a good argument for the simplicity of a combined virt queue but it is unlikely to be very performance orientated.
Quoted 2 lines
3. interface between toolstack and 'out-of-qemu' virtio backend, avoid using Xenstore in virtio backend if possible.
I wonder how much work it would be for a rust expert to make:
https://github.com/slp/vhost-user-blk
handle an IOREQ signalling pathway instead of the vhost-user/eventfd pathway? That would give a good indication on how "hypervisor blind" these daemons could be made.
<snip>
Quoted 5 lines
Please note, build-test passed for the following modes:
1. x86:CONFIG_HVM=y/CONFIG_IOREQ_SERVER=y(default)
2. x86: #CONFIG_HVM is not set / #CONFIG_IOREQ_SERVER is not set
3. Arm64:CONFIG_HVM=y/CONFIG_IOREQ_SERVER=y
Forgive my relative newness to Xen, how do I convince the hypervisor to build with this on? I've tried variants of:
make -j9 CROSS_COMPILE=aarch64-linux-gnu- XEN_TARGET_ARCH=arm64 menuconfig XEN_EXPERT=y [CONFIG_|XEN_|_]IOREQ_SERVER=y
with no joy...
Quoted 7 lines
4. Arm64:
CONFIG_HVM=y/ #CONFIG_IOREQ_SERVER is not set (default)
5. Arm32:CONFIG_HVM=y/CONFIG_IOREQ_SERVER=y
6. Arm32:CONFIG_HVM=y/ #CONFIG_IOREQ_SERVER is not set (default)***
Any feedback/help would be highly appreciated.
<snip>
Signature · 1 line
Alex Bennée
Re: [PATCH V3 00/23] IOREQ feature (+ virtio-mmio) on Arm
On 30.11.20 18:21, Alex Bennée wrote:
Hi Alex
[added missed subject title]
Quoted 50 lines
Quoted 11 lines · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
Date: Sat, 28 Nov 2020 22:33:51 +0200
Subject: [PATCH V3 00/23] IOREQ feature (+ virtio-mmio) on Arm
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bitHello all.
Quoted 11 lines
The purpose of this patch series is to add IOREQ/DM support to Xen on Arm. You can find an initial discussion at [1] and RFC/V1/V2 series at [2]/[3]/[4]. Xen on Arm requires some implementation to forward guest MMIO access to a device model in order to implement virtio-mmio backend or even mediator outside of hypervisor. As Xen on x86 already contains required support this series tries to make it common and introduce Arm specific bits plus some new functionality. Patch series is based on Julien's PoC "xen/arm: Add support for Guest IO forwarding to a device emulator". Besides splitting existing IOREQ/DM support and introducing Arm side, the series also includes virtio-mmio related changes (last 2 patches for toolstack) for the reviewers to be able to see how the whole picture could look like.
Thanks for posting the latest version.
Quoted 4 lines
According to the initial discussion there are a few open questions/concerns regarding security, performance in VirtIO solution:
1. virtio-mmio vs virtio-pci, SPI vs MSI, different use-cases require different transport...I think I'm repeating things here I've said in various ephemeral video chats over the last few weeks but I should probably put things down on the record.
I think the original intention of the virtio framers is advanced features would build on virtio-pci because you get a bunch of things "for free" - notably enumeration and MSI support. There is assumption that by the time you add these features to virtio-mmio you end up re-creating your own less well tested version of virtio-pci. I've not been terribly convinced by the argument that the guest implementation of PCI presents a sufficiently large blob of code to make the simpler MMIO desirable. My attempts to build two virtio kernels (PCI/MMIO) with otherwise the same devices wasn't terribly conclusive either way.
That said virtio-mmio still has life in it because the cloudy slimmed down guests moved to using it because the enumeration of PCI is a road block to their fast boot up requirements. I'm sure they would also appreciate a MSI implementation to reduce the overhead that handling notifications currently has on trap-and-emulate.
Quoted 3 lines
AIUI for Xen the other downside to PCI is you would have to emulate it in the hypervisor which would be additional code at the most privileged level.
Thank you for putting things together here and valuable input. As for me, the "virtio-mmio & MSI solution" as a performance improvement sounds indeed interesting. Flipping through the virtio-mmio links I found a discussion regarding that [1].
I think this needs an additional investigation and experiments, however I am not sure there is an existing infrastructure in Xen on Arm to do so. Once we make some progress with the IOREQ series I would be able to focus on enhancements which we would consider worthwhile.
Quoted 9 lines
Quoted 4 lines
2. virtio backend is able to access all guest memory, some kind of protection is needed: 'virtio-iommu in Xen' vs 'pre-shared-memory & memcpys in guest'
This is also an area of interest for Project Stratos and something we would like to be solved generally for all hypervisors. There is a good write up of some approaches that Jean Phillipe did on the stratos mailing list:
Quoted 6 lines
From: Jean-Philippe Brucker <[email protected]>
Subject: Limited memory sharing investigation
Message-ID: <20201002134336.GA2196245@myrica>I suspect there is a good argument for the simplicity of a combined virt queue but it is unlikely to be very performance orientated.
I will look at it.
Quoted 11 lines
Quoted 2 lines
3. interface between toolstack and 'out-of-qemu' virtio backend, avoid using Xenstore in virtio backend if possible.
I wonder how much work it would be for a rust expert to make:
https://github.com/slp/vhost-user-blk
handle an IOREQ signalling pathway instead of the vhost-user/eventfd pathway? That would give a good indication on how "hypervisor blind" these daemons could be made.
<snip>
Quoted 8 lines
Quoted 4 lines
Please note, build-test passed for the following modes:
1. x86:CONFIG_HVM=y/CONFIG_IOREQ_SERVER=y(default)
2. x86: #CONFIG_HVM is not set / #CONFIG_IOREQ_SERVER is not set
3. Arm64:CONFIG_HVM=y/CONFIG_IOREQ_SERVER=yForgive my relative newness to Xen, how do I convince the hypervisor to build with this on? I've tried variants of:
make -j9 CROSS_COMPILE=aarch64-linux-gnu- XEN_TARGET_ARCH=arm64 menuconfig XEN_EXPERT=y [CONFIG_|XEN_|_]IOREQ_SERVER=y
CONFIG_IOREQ_SERVER is not protected by CONFIG_XEN_EXPERT. I mentioned how to enable CONFIG_IOREQ_SERVER on Arm (since it is disabled by default within this series) when describing how test this series to Masami, but forgot to add here. Could you apply the one-line patch [2] and rebuild. Sorry for inconvenience.
[1] https://lwn.net/Articles/812055/
[2] https://github.com/otyshchenko1/xen/commit/b371bc9a3c954595bfce01bad244260364bbcd48
Signature · 3 lines
Regards, Oleksandr Tyshchenko
Quoted 54 lines · Alex Bennée
Quoted 11 lines · Oleksandr Tyshchenko
From: Oleksandr Tyshchenko <[email protected]>
Date: Sat, 28 Nov 2020 22:33:51 +0200
Subject: [PATCH V3 00/23] IOREQ feature (+ virtio-mmio) on Arm
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bitHello all.
Quoted 11 lines
The purpose of this patch series is to add IOREQ/DM support to Xen on Arm. You can find an initial discussion at [1] and RFC/V1/V2 series at [2]/[3]/[4]. Xen on Arm requires some implementation to forward guest MMIO access to a device model in order to implement virtio-mmio backend or even mediator outside of hypervisor. As Xen on x86 already contains required support this series tries to make it common and introduce Arm specific bits plus some new functionality. Patch series is based on Julien's PoC "xen/arm: Add support for Guest IO forwarding to a device emulator". Besides splitting existing IOREQ/DM support and introducing Arm side, the series also includes virtio-mmio related changes (last 2 patches for toolstack) for the reviewers to be able to see how the whole picture could look like.
Thanks for posting the latest version.
Quoted 5 lines
According to the initial discussion there are a few open questions/concerns regarding security, performance in VirtIO solution:
1. virtio-mmio vs virtio-pci, SPI vs MSI, different use-cases require different transport...I think I'm repeating things here I've said in various ephemeral video chats over the last few weeks but I should probably put things down on the record.
I think the original intention of the virtio framers is advanced features would build on virtio-pci because you get a bunch of things "for free" - notably enumeration and MSI support. There is assumption that by the time you add these features to virtio-mmio you end up re-creating your own less well tested version of virtio-pci. I've not been terribly convinced by the argument that the guest implementation of PCI presents a sufficiently large blob of code to make the simpler MMIO desirable. My attempts to build two virtio kernels (PCI/MMIO) with otherwise the same devices wasn't terribly conclusive either way.
That said virtio-mmio still has life in it because the cloudy slimmed down guests moved to using it because the enumeration of PCI is a road block to their fast boot up requirements. I'm sure they would also appreciate a MSI implementation to reduce the overhead that handling notifications currently has on trap-and-emulate.
Quoted 3 lines
AIUI for Xen the other downside to PCI is you would have to emulate it in the hypervisor which would be additional code at the most privileged level.
Xen already emulates (or maybe it would be better to say decodes) PCI accesses on the hypervisor and forwards them to the appropriate device model using the IOREQ interface, so that's not something new. It's not really emulating the PCI config space, but just detecting accesses and forwarding them to the device model that should handle them.
You can register different emulators in user space that handle accesses to different PCI devices from a guest.
Thanks, Roger.