xen: only clobber multicall elements without error
PATCH 1/1 xen: only clobber multicall elements without error
In debug builds the hypervisor will deliberately clobber processed elements of the multicall structure. In order to ease diagnostic data printout in the affected guest only clobber elements which didn't return an error.
--- xen/common/multicall.c | 1 + 1 file changed, 1 insertion(+)
xen/common/multicall.c +1 -0
@@ -74,6 +74,7 @@ do_multicall(ASSERT_NOT_IN_ATOMIC ();#ifndef NDEBUG +if ( (long )mcs->call.result >=0 ) {/* * Deliberately corrupt the contents of the multicall structure.
Signature · 7 lines
2.16.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 15 lines · Juergen Gross
In debug builds the hypervisor will deliberately clobber processed elements of the multicall structure. In order to ease diagnostic data printout in the affected guest only clobber elements which didn't return an error.
Signed-off-by Juergen Gross <[email protected]>--- xen/common/multicall.c | 1 + 1 file changed, 1 insertion(+)xen/common/multicall.c +0
-0
xen/common/multicall.c do_multicall( · line 77
Quoted 4 lines
xen/common/multicall.c +1
-0@@ -74,6 +74,7 @@ do_multicall(ASSERT_NOT_IN_ATOMIC ();#ifndef NDEBUG +if ( (long )mcs->call.result >=0 )
While I appreciate your point and agree that this is good in principle, the failure condition is per-hypercall, and not always negative.
I've tried playing a similar game before and couldn't come up with a viable option.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 18 lines · Andrew Cooper
Quoted 17 lines · Juergen Gross
In debug builds the hypervisor will deliberately clobber processed elements of the multicall structure. In order to ease diagnostic data printout in the affected guest only clobber elements which didn't return an error.
Signed-off-by Juergen Gross <[email protected]>--- xen/common/multicall.c | 1 + 1 file changed, 1 insertion(+)xen/common/multicall.c +0
-0@@ -74,6 +74,7 @@ do_multicall(ASSERT_NOT_IN_ATOMIC ();
Quoted 5 lines
xen/common/multicall.c do_multicall( · line 77
Quoted 2 lines
xen/common/multicall.c +1
-0#ifndef NDEBUG +if ( (long )mcs->call.result >=0 )While I appreciate your point and agree that this is good in principle, the failure condition is per-hypercall, and not always negative.
In theory you may be right.
OTOH the related code in the Linux kernel checks exactly what I am aiming at: In case any multicall element has a negative result this is regarded to be an error and a WARN is issued.
A negative return value of the multicall hypercall is regarded to be a BUG().
Quoted 2 lines
I've tried playing a similar game before and couldn't come up with a viable option.
In the end the result will be better than today, even if the heuristic for detecting an error in a multicall entry might be not optimal.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 23.11.18 at 14:25, <[email protected]> wrote:
In debug builds the hypervisor will deliberately clobber processed elements of the multicall structure. In order to ease diagnostic data printout in the affected guest only clobber elements which didn't return an error.
Besides what Andrew has said such a relaxation reduces the guarding against bad guest side code. If a guest really wishes to produce diagnostics, I think it should go to the lengths of copying arguments (if they can't be re-calculated anyway). Suppressing the clobbering in more cases merely invites guests to read the arguments after the call, which they simply should not do. Not clobbering the values in release builds is a performance choice, and we ought to be allowed to change our opinion regarding this implementation detail at any point in time.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Jan Beulich writes ("Re: [PATCH] xen: only clobber multicall elements without error"):
Quoted 6 lines · On 23.11.18 at 14:25, <[email protected]> wrote:
Quoted 4 lines
In debug builds the hypervisor will deliberately clobber processed elements of the multicall structure. In order to ease diagnostic data printout in the affected guest only clobber elements which didn't return an error.
Quoted 10 lines
Besides what Andrew has said such a relaxation reduces the guarding against bad guest side code. If a guest really wishes to produce diagnostics, I think it should go to the lengths of copying arguments (if they can't be re-calculated anyway). Suppressing the clobbering in more cases merely invites guests to read the arguments after the call, which they simply should not do. Not clobbering the values in release builds is a performance choice, and we ought to be allowed to change our opinion regarding this implementation detail at any point in time.
Maybe they could be clobbered losslessly ? Eg, by xoring with 0xaa or something.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 18 lines · Ian Jackson
Jan Beulich writes ("Re: [PATCH] xen: only clobber multicall elements without error"):
Quoted 6 lines · On 23.11.18 at 14:25, <[email protected]> wrote:
Quoted 4 lines
In debug builds the hypervisor will deliberately clobber processed elements of the multicall structure. In order to ease diagnostic data printout in the affected guest only clobber elements which didn't return an error.
Quoted 10 lines
Besides what Andrew has said such a relaxation reduces the guarding against bad guest side code. If a guest really wishes to produce diagnostics, I think it should go to the lengths of copying arguments (if they can't be re-calculated anyway). Suppressing the clobbering in more cases merely invites guests to read the arguments after the call, which they simply should not do. Not clobbering the values in release builds is a performance choice, and we ought to be allowed to change our opinion regarding this implementation detail at any point in time.
Quoted 2 lines
Maybe they could be clobbered losslessly ? Eg, by xoring with
0xaaor something.
This would be rather hacky: I'd need to find out if clobbering was performed or not and the way of clobbering would be kind of an interface which I guess we'd like to avoid.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Juergen Gross writes ("Re: [PATCH] xen: only clobber multicall elements without error"):
Quoted 7 lines · Ian Jackson
Quoted 2 lines
Maybe they could be clobbered losslessly ? Eg, by xoring with
0xaaor something.This would be rather hacky: I'd need to find out if clobbering was performed or not and the way of clobbering would be kind of an interface which I guess we'd like to avoid.
You can bake the precise method of clobbering into your kernel debugging dump stuff, along with a mechanism which guesses whether things have been clobbered, so long as you don't go utterly wrong if your guesses are wrong.
Since after all Xen doesn't guarantee to preserve the arguments at all, and therefore you mustn't rely on it anyway.
This seems fine for a debug dump mechanism - debug dump mechanisms are generally best effort anyway.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 6 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 23.11.18 at 14:25, <[email protected]> wrote:
In debug builds the hypervisor will deliberately clobber processed elements of the multicall structure. In order to ease diagnostic data printout in the affected guest only clobber elements which didn't return an error.
Quoted 10 lines
Besides what Andrew has said such a relaxation reduces the guarding against bad guest side code. If a guest really wishes to produce diagnostics, I think it should go to the lengths of copying arguments (if they can't be re-calculated anyway). Suppressing the clobbering in more cases merely invites guests to read the arguments after the call, which they simply should not do. Not clobbering the values in release builds is a performance choice, and we ought to be allowed to change our opinion regarding this implementation detail at any point in time.
Right. And not copying the values before the call is a performance choice on guest side, as errors are not the common case.
I know there is no guarantee for the guest that the values are preserved after the call, but in the error case (which should be _very_ rare) it will make diagnosis of that case much easier.
I don't think the hypervisor should explicitly try to make it as hard as possible for the guest to find problems in the code.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 26.11.18 at 14:52, <[email protected]> wrote:
I don't think the hypervisor should explicitly try to make it as hard as possible for the guest to find problems in the code.
That's indeed not the hypervisor's goal. Instead it tries to make it as hard as possible for the guest (developer) to make wrong assumptions.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 7 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 26.11.18 at 14:52, <[email protected]> wrote:
I don't think the hypervisor should explicitly try to make it as hard as possible for the guest to find problems in the code.
That's indeed not the hypervisor's goal. Instead it tries to make it as hard as possible for the guest (developer) to make wrong assumptions.
Let's look at the current example why I wrote this patch:
The Linux kernel's use of multicalls should never trigger any single call to return an error (return value < 0). A kernel compiled for productive use will catch such errors, but has no knowledge which single call has failed, as it doesn't keep track of the single entries (non-productive kernels have an option available in the respective source to copy the entries before doing the multicall in order to have some diagnostic data available in case of such an error). Catching an error from a multicall right now means a WARN() with a stack backtrace (for the multicall itself, not for the entry causing the error).
I have a customer report for a case where such a backtrace was produced and a kernel crash some seconds later, obviously due to illegally unmapped memory pages resulting from the failed multicall. Unfortunately there are multiple possibilities what might have gone wrong and I don't know which one was the culprit. The problem can't be a very common one, because there is only one such report right now, which might depend on a special driver.
Finding this bug without a known reproducer and the current amount of diagnostic data is next to impossible. So I'd like to have more data available without having to hurt performance for the 99.999999% of the cases where nothing bad happens.
In case you have an idea how to solve this problem in another way I'd be happy to follow that route. I'd really like to be able to have a better clue in case such an error occurs in future.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 30 lines
Quoted 1 line
Quoted 1 line · On 26.11.18 at 15:23, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 26.11.18 at 14:52, <[email protected]> wrote:
I don't think the hypervisor should explicitly try to make it as hard as possible for the guest to find problems in the code.
That's indeed not the hypervisor's goal. Instead it tries to make it as hard as possible for the guest (developer) to make wrong assumptions.
Let's look at the current example why I wrote this patch:
The Linux kernel's use of multicalls should never trigger any single call to return an error (return value < 0). A kernel compiled for productive use will catch such errors, but has no knowledge which single call has failed, as it doesn't keep track of the single entries (non-productive kernels have an option available in the respective source to copy the entries before doing the multicall in order to have some diagnostic data available in case of such an error). Catching an error from a multicall right now means a
WARN()with a stack backtrace (for the multicall itself, not for the entry causing the error).I have a customer report for a case where such a backtrace was produced and a kernel crash some seconds later, obviously due to illegally unmapped memory pages resulting from the failed multicall. Unfortunately there are multiple possibilities what might have gone wrong and I don't know which one was the culprit. The problem can't be a very common one, because there is only one such report right now, which might depend on a special driver.
Quoted 8 lines
Finding this bug without a known reproducer and the current amount of diagnostic data is next to impossible. So I'd like to have more data available without having to hurt performance for the 99.999999% of the cases where nothing bad happens.
In case you have an idea how to solve this problem in another way I'd be happy to follow that route. I'd really like to be able to have a better clue in case such an error occurs in future.
Since you have a production kernel, I assume you also have a production hypervisor. This hypervisor doesn't clobber the arguments if I'm not mistaken. Therefore
- in the debugging scenario you (can) have all data available by virtue of the information getting copied in the kernel,
- in the release scenario you have all data available since it's left un-clobbered.
Am I missing anything (I don't view mixed debug/release setups of kernel and hypervisor as overly important here)?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 39 lines · Jan Beulich
Quoted 30 lines
Quoted 1 line
Quoted 1 line · On 26.11.18 at 15:23, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 26.11.18 at 14:52, <[email protected]> wrote:
I don't think the hypervisor should explicitly try to make it as hard as possible for the guest to find problems in the code.
That's indeed not the hypervisor's goal. Instead it tries to make it as hard as possible for the guest (developer) to make wrong assumptions.
Let's look at the current example why I wrote this patch:
The Linux kernel's use of multicalls should never trigger any single call to return an error (return value < 0). A kernel compiled for productive use will catch such errors, but has no knowledge which single call has failed, as it doesn't keep track of the single entries (non-productive kernels have an option available in the respective source to copy the entries before doing the multicall in order to have some diagnostic data available in case of such an error). Catching an error from a multicall right now means a
WARN()with a stack backtrace (for the multicall itself, not for the entry causing the error).I have a customer report for a case where such a backtrace was produced and a kernel crash some seconds later, obviously due to illegally unmapped memory pages resulting from the failed multicall. Unfortunately there are multiple possibilities what might have gone wrong and I don't know which one was the culprit. The problem can't be a very common one, because there is only one such report right now, which might depend on a special driver.
Quoted 8 lines
Finding this bug without a known reproducer and the current amount of diagnostic data is next to impossible. So I'd like to have more data available without having to hurt performance for the 99.999999% of the cases where nothing bad happens.
In case you have an idea how to solve this problem in another way I'd be happy to follow that route. I'd really like to be able to have a better clue in case such an error occurs in future.
Quoted 9 lines
Since you have a production kernel, I assume you also have a production hypervisor. This hypervisor doesn't clobber the arguments if I'm not mistaken. Therefore
- in the debugging scenario you (can) have all data available by virtue of the information getting copied in the kernel,
- in the release scenario you have all data available since it's left un-clobbered.
Am I missing anything (I don't view mixed debug/release setups of kernel and hypervisor as overly important here)?
No, you are missing nothing here. OTOH a debug hypervisor destroying debug data is kind of weird, so I posted this patch.
I'll add the related Linux kernel patch (in case it is acked by Boris) with or without this hypervisor patch, but I thought it would be better to have the hypervisor patch in place, especially as e.g. a hypervisor from xen-unstable might have a bug which could be easier to diagnose with this patch in place.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 50 lines · Juergen Gross
Quoted 39 lines · Jan Beulich
Quoted 30 lines
Quoted 1 line
Quoted 1 line · On 26.11.18 at 15:23, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 26.11.18 at 14:52, <[email protected]> wrote:
I don't think the hypervisor should explicitly try to make it as hard as possible for the guest to find problems in the code.
That's indeed not the hypervisor's goal. Instead it tries to make it as hard as possible for the guest (developer) to make wrong assumptions.
Let's look at the current example why I wrote this patch:
The Linux kernel's use of multicalls should never trigger any single call to return an error (return value < 0). A kernel compiled for productive use will catch such errors, but has no knowledge which single call has failed, as it doesn't keep track of the single entries (non-productive kernels have an option available in the respective source to copy the entries before doing the multicall in order to have some diagnostic data available in case of such an error). Catching an error from a multicall right now means a
WARN()with a stack backtrace (for the multicall itself, not for the entry causing the error).I have a customer report for a case where such a backtrace was produced and a kernel crash some seconds later, obviously due to illegally unmapped memory pages resulting from the failed multicall. Unfortunately there are multiple possibilities what might have gone wrong and I don't know which one was the culprit. The problem can't be a very common one, because there is only one such report right now, which might depend on a special driver.
Quoted 8 lines
Finding this bug without a known reproducer and the current amount of diagnostic data is next to impossible. So I'd like to have more data available without having to hurt performance for the 99.999999% of the cases where nothing bad happens.
In case you have an idea how to solve this problem in another way I'd be happy to follow that route. I'd really like to be able to have a better clue in case such an error occurs in future.
Quoted 9 lines
Since you have a production kernel, I assume you also have a production hypervisor. This hypervisor doesn't clobber the arguments if I'm not mistaken. Therefore
- in the debugging scenario you (can) have all data available by virtue of the information getting copied in the kernel,
- in the release scenario you have all data available since it's left un-clobbered.
Am I missing anything (I don't view mixed debug/release setups of kernel and hypervisor as overly important here)?
Quoted 2 lines
No, you are missing nothing here. OTOH a debug hypervisor destroying debug data is kind of weird, so I posted this patch.
This is a quite common approach if you want to enforce the other entity to not rely on some fields. This also follows what we do for hypercalls (at least on Arm).
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 56 lines · Julien Grall
Quoted 53 lines · Juergen Gross
Quoted 51 lines · Jan Beulich
Quoted 37 lines
Quoted 1 line
Quoted 1 line · On 26.11.18 at 15:23, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 26.11.18 at 14:52, <[email protected]> wrote:
I don't think the hypervisor should explicitly try to make it as hard as
possible for the guest to find problems in the code.That's indeed not the hypervisor's goal. Instead it tries to make it as hard as possible for the guest (developer) to make wrong assumptions.
Let's look at the current example why I wrote this patch:
The Linux kernel's use of multicalls should never trigger any single call to return an error (return value < 0). A kernel compiled for productive use will catch such errors, but has no knowledge which single call has failed, as it doesn't keep track of the single entries (non-productive kernels have an option available in the respective source to copy the entries before doing the multicall in order to have some diagnostic data available in case of such an error). Catching an error from a multicall right now means a
WARN()with a stack backtrace (for the multicall itself, not for the entry causing the error).I have a customer report for a case where such a backtrace was produced and a kernel crash some seconds later, obviously due to illegally unmapped memory pages resulting from the failed multicall. Unfortunately
there are multiple possibilities what might have gone wrong and I don't know which one was the culprit. The problem can't be a very common one, because there is only one such report right now, which might depend on a special driver.Finding this bug without a known reproducer and the current amount of diagnostic data is next to impossible. So I'd like to have more data available without having to hurt performance for the 99.999999% of the cases where nothing bad happens.
Quoted 4 lines
In case you have an idea how to solve this problem in another way I'd be
happy to follow that route. I'd really like to be able to have a better clue in case such an error occurs in future.Since you have a production kernel, I assume you also have a production hypervisor. This hypervisor doesn't clobber the arguments if I'm not mistaken. Therefore
- in the debugging scenario you (can) have all data available by virtue of the information getting copied in the kernel,
- in the release scenario you have all data available since it's left un-clobbered.
Am I missing anything (I don't view mixed debug/release setups of kernel and hypervisor as overly important here)?
Quoted 6 lines
Quoted 2 lines
No, you are missing nothing here. OTOH a debug hypervisor destroying debug data is kind of weird, so I posted this patch.
This is a quite common approach if you want to enforce the other entity to not rely on some fields. This also follows what we do for hypercalls (at least on Arm).
I don't question that general mechanism.
What I question is doing the clobbering in this case where the caller would need to take special measures for copying the needed debug data which will hit performance. So not doing the clobbering would only be in the very rare error case, not in the common case where the guest should really have no need to see the preserved data.
I really fail to see why it is so bad to not clobber data in a case which normally should never occur. The only outcome of clobbering the data in the error case is making diagnosis of that error much harder. Its not as if there would be secret data suddenly made available to the guest. Its just avoiding the need for the guest to copy the data for each multicall for the very unlikely chance an error might occur. And we are not speaking of a hypercall issued then and now, but of the path hit for nearly every memory-management action and context switch of PV guests. So doing always the copy would really be visible.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 26.11.18 at 17:17, <[email protected]> wrote:
I really fail to see why it is so bad to not clobber data in a case which normally should never occur.
See Andrew's original reply. You're also clobbering on potential success paths.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 6 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 26.11.18 at 17:17, <[email protected]> wrote:
I really fail to see why it is so bad to not clobber data in a case which normally should never occur.
See Andrew's original reply. You're also clobbering on potential success paths.
I think you are missing a "not" here.
But yes, I agree. This is a downside _I_ think we can live with.
How many cases (with productive hypervisors) are known where multicall parameters have been illegally re-used? I guess the number is exactly 0.
I know of least one case where not clobbering would be useful for diagnostic reasons.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 27.11.18 at 08:37, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 26.11.18 at 17:17, <[email protected]> wrote:
I really fail to see why it is so bad to not clobber data in a case which normally should never occur.
See Andrew's original reply. You're also clobbering on potential success paths.
Quoted 6 lines
I think you are missing a "not" here.
But yes, I agree. This is a downside _I_ think we can live with.
How many cases (with productive hypervisors) are known where multicall parameters have been illegally re-used? I guess the number is exactly 0.
I'm not aware of any either, but this means exactly nothing.
Quoted 2 lines
I know of least one case where not clobbering would be useful for diagnostic reasons.
Well, I'm in agreement with Julien that the behavior between ordinary hypercalls and multicalls would better be as consistent as possible.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel