x86/PV: conditionally avoid raising #GP for early guest MSR accesses
PATCH 1/1 x86/PV: conditionally avoid raising #GP for early guest MSR accesses
Prior to 4.15 Linux, when running in PV mode, did not install a #GP handler early enough to cover for example the rdmsrl_safe() of MSR_K8_TSEG_ADDR in bsp_init_amd() (not to speak of the unguarded read of MSR_K7_HWCR later in the same function). The respective change (42b3a4cb5609 "x86/xen: Support early interrupts in xen pv guests") was backported to 4.14, but no further - presumably since it wasn't really easy because of other dependencies.
Therefore, to prevent our change in the handling of guest MSR accesses to render PV Linux 4.13 and older unusable on at least AMD systems, make the raising of #GP on these paths conditional upon the guest having installed a handler. Producing zero for reads and discarding writes isn't necessarily correct and may trip code trying to detect presence of MSRs early, but since such detection logic won't work without a #GP handler anyway, this ought to be a fair workaround.
xen/arch/x86/pv/emul-priv-op.c +21 -4
@@ -886,7 +886,7 @@ static int read_msr(unsigned int reg, uiif ( ret ==X86EMUL_EXCEPTION )x86_emul_hw_exception (TRAP_gp_fault,0 , ctxt); -return ret; + goto done; } switch ( reg )
@@ -999,7 +999,16 @@ static int read_msr(unsigned int reg, uireturn X86EMUL_OKAY ; } -return X86EMUL_UNHANDLEABLE ; + done: +if ( ret !=X86EMUL_OKAY && !curr->arch.pv.trap_ctxt[X86_EXC_GP ].address ) + { +gprintk (XENLOG_WARNING ,"faking RDMSR 0x%08x\n" , reg); + *val =0 ; +x86_emul_reset_event (ctxt); + ret =X86EMUL_OKAY ; + } + +return ret; } static int write_msr(unsigned int reg, uint64_t val,
@@ -1016,7 +1025,7 @@ static int write_msr(unsigned int reg, uif ( ret ==X86EMUL_EXCEPTION )x86_emul_hw_exception (TRAP_gp_fault,0 , ctxt); -return ret; + goto done; } switch ( reg )
@@ -1172,7 +1181,15 @@ static int write_msr(unsigned int reg, ureturn X86EMUL_OKAY ; } -return X86EMUL_UNHANDLEABLE ; + done: +if ( ret !=X86EMUL_OKAY && !curr->arch.pv.trap_ctxt[X86_EXC_GP ].address ) + { +gprintk (XENLOG_WARNING ,"dropping WRMSR 0x%08x\n" , reg); +x86_emul_reset_event (ctxt); + ret =X86EMUL_OKAY ; + } + +return ret; } static int cache_op(enum x86emul_cache_op op, enum x86_segment seg,
Quoted 16 lines · Jan Beulich
Prior to 4.15 Linux, when running in PV mode, did not install a #GP handler early enough to cover for example the
rdmsrl_safe()ofMSR_K8_TSEG_ADDRinbsp_init_amd()(not to speak of the unguarded read ofMSR_K7_HWCRlater in the same function). The respective change (42b3a4cb5609"x86/xen: Support early interrupts in xen pv guests") was backported to 4.14, but no further - presumably since it wasn't really easy because of other dependencies.Therefore, to prevent our change in the handling of guest MSR accesses to render PV Linux 4.13 and older unusable on at least AMD systems, make the raising of #GP on these paths conditional upon the guest having installed a handler. Producing zero for reads and discarding writes isn't necessarily correct and may trip code trying to detect presence of MSRs early, but since such detection logic won't work without a #GP handler anyway, this ought to be a fair workaround.
Quoted 1 line
Signed-off-by Jan Beulich <[email protected]>
I appreciate that we probably have to do something, but I don't think this is a wise move.
Linux is fundamentally buggy. It is deliberately looking for a potential #GP fault given its use of rdmsrl_safe(). The reason this bug stayed hidden for so long was as a consequence of Xen's inappropriate MSR handling for guests, and the reasons for changing Xen's behaviour still stand.
This change, in particular, does not apply to any explicitly handled MSRs, and therefore is not a comprehensive fix. Nor is it robust to someone adding code to explicitly handling the impacted MSRs at a later date (which are are likely to need to do for HWCR), and which would reintroduce this failure to boot.
We should have the impacted MSRs handled explicitly, with a note stating this was a bug in Linux 4.14 and older. We already have workaround for similar bugs in Windows, and it also gives us a timeline to eventually removing support for obsolete workarounds, rather than having a "now and in the future, we'll explicitly tolerate broken PV behaviour for one bug back in ancient linux".
~Andrew
Quoted 17 lines · Andrew Cooper
Quoted 16 lines · Jan Beulich
Prior to 4.15 Linux, when running in PV mode, did not install a #GP handler early enough to cover for example the
rdmsrl_safe()ofMSR_K8_TSEG_ADDRinbsp_init_amd()(not to speak of the unguarded read ofMSR_K7_HWCRlater in the same function). The respective change (42b3a4cb5609"x86/xen: Support early interrupts in xen pv guests") was backported to 4.14, but no further - presumably since it wasn't really easy because of other dependencies.Therefore, to prevent our change in the handling of guest MSR accesses to render PV Linux 4.13 and older unusable on at least AMD systems, make the raising of #GP on these paths conditional upon the guest having installed a handler. Producing zero for reads and discarding writes isn't necessarily correct and may trip code trying to detect presence of MSRs early, but since such detection logic won't work without a #GP handler anyway, this ought to be a fair workaround.
Quoted 4 lines
Quoted 1 line
Signed-off-by Jan Beulich <[email protected]>I appreciate that we probably have to do something, but I don't think this is a wise move.
I wouldn't call it wise either, but I'm afraid something along these lines is necessary.
Quoted 5 lines
Linux is fundamentally buggy. It is deliberately looking for a potential #GP fault given its use of rdmsrl_safe(). The reason this bug stayed hidden for so long was as a consequence of Xen's inappropriate MSR handling for guests, and the reasons for changing Xen's behaviour still stand.
I agree.
Quoted 2 lines
This change, in particular, does not apply to any explicitly handled MSRs, and therefore is not a comprehensive fix.
But it's intentional that this deals with the situation in a generic way, not on a per-MSR basis. If we did as you suggest further down, we'd have to audit all Linux versions up to 4.14 for similar issues with other MSRs. I don't think this would be a practical thing to do, and I also don't think that leaving things as they are until we have concrete reports of problems is a viable option either.
Adding explicit handling for the two offending MSRs (and any possible further ones we discover) would imo only be to avoid issuing the respective log messages.
Quoted 4 lines
Nor is it robust to
someone adding code to explicitly handling the impacted MSRs at a later date (which are are likely to need to do for HWCR), and which would reintroduce this failure to boot.
I'm afraid I don't understand. Looking at the two functions the patch alters, only X86EMUL_OKAY is used in return statements other than the final one. If this model is to be followed by future additions (which I think it ought to be; perhaps we should add comments to this effect), the code introduced here will take care of the situation nevertheless.
Quoted 6 lines
We should have the impacted MSRs handled explicitly, with a note stating this was a bug in Linux 4.14 and older. We already have workaround for similar bugs in Windows, and it also gives us a timeline to eventually removing support for obsolete workarounds, rather than having a "now and in the future, we'll explicitly tolerate broken PV behaviour for one bug back in ancient linux".
Comparing with Windows isn't very helpful; the patch here is specifically about PV, and would help other OSes as well in case they would have missed setting up exceptions early in just the PV-on-Xen case. For the HVM case I'd indeed rather see us go the route we've gone for Windows, if need be.
There's one adjustment to the logic here that I've been considering, but I'm still undecided due to the downsides:
Without exposing the value, we could make the decision to zap the #GP dependent upon us being able to read the MSR.
The other possible adjustment would be to avoid issuing two log messages for the same operation (affecting debug builds only). But the code structure (which isn't really consistent about when the pre-existing message would get issued) doesn't directly lend itself to such an adjustment without altering the behavior for some of the MSRs explicitly handled.
As a tangent, while discussing this situation, please let's not forget about this code in Linux:
static u64 xen_read_msr(unsigned int msr)
{
/*
* This will silently swallow a #GP from RDMSR. It may be worth
* changing that.
*/
int err;
return xen_read_msr_safe(msr, &err);
}static void xen_write_msr(unsigned int msr, unsigned low, unsigned high)
{
/*
* This will silently swallow a #GP from WRMSR. It may be worth
* changing that.
*/
xen_write_msr_safe(msr, low, high);
}Imo this "silent swallowing" has always been the wrong thing to do, and hence ought to be dropped. Of course right now it saves the kernel from dying on the HWCR read.
Jan
Ping: [PATCH] x86/PV: conditionally avoid raising #GP for early guest MSR accesses
Quoted 68 lines · Jan Beulich
Quoted 17 lines · Andrew Cooper
Quoted 16 lines · Jan Beulich
Prior to 4.15 Linux, when running in PV mode, did not install a #GP handler early enough to cover for example the
rdmsrl_safe()ofMSR_K8_TSEG_ADDRinbsp_init_amd()(not to speak of the unguarded read ofMSR_K7_HWCRlater in the same function). The respective change (42b3a4cb5609"x86/xen: Support early interrupts in xen pv guests") was backported to 4.14, but no further - presumably since it wasn't really easy because of other dependencies.Therefore, to prevent our change in the handling of guest MSR accesses to render PV Linux 4.13 and older unusable on at least AMD systems, make the raising of #GP on these paths conditional upon the guest having installed a handler. Producing zero for reads and discarding writes isn't necessarily correct and may trip code trying to detect presence of MSRs early, but since such detection logic won't work without a #GP handler anyway, this ought to be a fair workaround.
Quoted 4 lines
Quoted 1 line
Signed-off-by Jan Beulich <[email protected]>I appreciate that we probably have to do something, but I don't think this is a wise move.
I wouldn't call it wise either, but I'm afraid something along these lines is necessary.
Quoted 5 lines
Linux is fundamentally buggy. It is deliberately looking for a potential #GP fault given its use of rdmsrl_safe(). The reason this bug stayed hidden for so long was as a consequence of Xen's inappropriate MSR handling for guests, and the reasons for changing Xen's behaviour still stand.
I agree.
Quoted 2 lines
This change, in particular, does not apply to any explicitly handled MSRs, and therefore is not a comprehensive fix.
But it's intentional that this deals with the situation in a generic way, not on a per-MSR basis. If we did as you suggest further down, we'd have to audit all Linux versions up to 4.14 for similar issues with other MSRs. I don't think this would be a practical thing to do, and I also don't think that leaving things as they are until we have concrete reports of problems is a viable option either.
Adding explicit handling for the two offending MSRs (and any possible further ones we discover) would imo only be to avoid issuing the respective log messages.
Quoted 4 lines
Nor is it robust to
someone adding code to explicitly handling the impacted MSRs at a later date (which are are likely to need to do for HWCR), and which would reintroduce this failure to boot.I'm afraid I don't understand. Looking at the two functions the patch alters, only
X86EMUL_OKAYis used in return statements other than the final one. If this model is to be followed by future additions (which I think it ought to be; perhaps we should add comments to this effect), the code introduced here will take care of the situation nevertheless.Quoted 6 lines
We should have the impacted MSRs handled explicitly, with a note stating this was a bug in Linux 4.14 and older. We already have workaround for similar bugs in Windows, and it also gives us a timeline to eventually removing support for obsolete workarounds, rather than having a "now and in the future, we'll explicitly tolerate broken PV behaviour for one bug back in ancient linux".
Quoted 5 lines
Comparing with Windows isn't very helpful; the patch here is specifically about PV, and would help other OSes as well in case they would have missed setting up exceptions early in just the PV-on-Xen case. For the HVM case I'd indeed rather see us go the route we've gone for Windows, if need be.
As can be seen from this reply, we're not in agreement what to do here. But we need to do something. I'm not sure how to get unstuck discussions like this one ...
Besides this suggestion of yours I also continue to have trouble seeing what good it will do to record an exception to inject into a guest when we know it didn't install a handler yet.
Jan
Quoted 42 lines
There's one adjustment to the logic here that I've been considering, but I'm still undecided due to the downsides:
Without exposing the value, we could make the decision to zap the #GP dependent upon us being able to read the MSR.The other possible adjustment would be to avoid issuing two log messages for the same operation (affecting debug builds only). But the code structure (which isn't really consistent about when the pre-existing message would get issued) doesn't directly lend itself to such an adjustment without altering the behavior for some of the MSRs explicitly handled.
As a tangent, while discussing this situation, please let's not forget about this code in Linux:
static u64
xen_read_msr(unsigned int msr){ /* * This will silently swallow a #GP from RDMSR. It may be worth * changing that. */ int err; return xen_read_msr_safe(msr, &err); }static void
xen_write_msr(unsigned int msr, unsigned low, unsigned high){ /* * This will silently swallow a #GP from WRMSR. It may be worth * changing that. */ xen_write_msr_safe(msr, low, high); }Imo this "silent swallowing" has always been the wrong thing to do, and hence ought to be dropped. Of course right now it saves the kernel from dying on the HWCR read.
Jan
Ping²: [PATCH] x86/PV: conditionally avoid raising #GP for early guest MSR accesses
In reply to Jan Beulich(simply re-sending what was sent over 2 months ago)
Quoted 68 lines · Jan Beulich
Quoted 17 lines · Andrew Cooper
Quoted 16 lines · Jan Beulich
Prior to 4.15 Linux, when running in PV mode, did not install a #GP handler early enough to cover for example the
rdmsrl_safe()ofMSR_K8_TSEG_ADDRinbsp_init_amd()(not to speak of the unguarded read ofMSR_K7_HWCRlater in the same function). The respective change (42b3a4cb5609"x86/xen: Support early interrupts in xen pv guests") was backported to 4.14, but no further - presumably since it wasn't really easy because of other dependencies.Therefore, to prevent our change in the handling of guest MSR accesses to render PV Linux 4.13 and older unusable on at least AMD systems, make the raising of #GP on these paths conditional upon the guest having installed a handler. Producing zero for reads and discarding writes isn't necessarily correct and may trip code trying to detect presence of MSRs early, but since such detection logic won't work without a #GP handler anyway, this ought to be a fair workaround.
Quoted 4 lines
Quoted 1 line
Signed-off-by Jan Beulich <[email protected]>I appreciate that we probably have to do something, but I don't think this is a wise move.
I wouldn't call it wise either, but I'm afraid something along these lines is necessary.
Quoted 5 lines
Linux is fundamentally buggy. It is deliberately looking for a potential #GP fault given its use of rdmsrl_safe(). The reason this bug stayed hidden for so long was as a consequence of Xen's inappropriate MSR handling for guests, and the reasons for changing Xen's behaviour still stand.
I agree.
Quoted 2 lines
This change, in particular, does not apply to any explicitly handled MSRs, and therefore is not a comprehensive fix.
But it's intentional that this deals with the situation in a generic way, not on a per-MSR basis. If we did as you suggest further down, we'd have to audit all Linux versions up to 4.14 for similar issues with other MSRs. I don't think this would be a practical thing to do, and I also don't think that leaving things as they are until we have concrete reports of problems is a viable option either.
Adding explicit handling for the two offending MSRs (and any possible further ones we discover) would imo only be to avoid issuing the respective log messages.
Quoted 4 lines
Nor is it robust to
someone adding code to explicitly handling the impacted MSRs at a later date (which are are likely to need to do for HWCR), and which would reintroduce this failure to boot.I'm afraid I don't understand. Looking at the two functions the patch alters, only
X86EMUL_OKAYis used in return statements other than the final one. If this model is to be followed by future additions (which I think it ought to be; perhaps we should add comments to this effect), the code introduced here will take care of the situation nevertheless.Quoted 6 lines
We should have the impacted MSRs handled explicitly, with a note stating this was a bug in Linux 4.14 and older. We already have workaround for similar bugs in Windows, and it also gives us a timeline to eventually removing support for obsolete workarounds, rather than having a "now and in the future, we'll explicitly tolerate broken PV behaviour for one bug back in ancient linux".
Quoted 5 lines
Comparing with Windows isn't very helpful; the patch here is specifically about PV, and would help other OSes as well in case they would have missed setting up exceptions early in just the PV-on-Xen case. For the HVM case I'd indeed rather see us go the route we've gone for Windows, if need be.
As can be seen from this reply, we're not in agreement what to do here. But we need to do something. I'm not sure how to get unstuck discussions like this one ...
Besides this suggestion of yours I also continue to have trouble seeing what good it will do to record an exception to inject into a guest when we know it didn't install a handler yet.
Jan
Quoted 42 lines
There's one adjustment to the logic here that I've been considering, but I'm still undecided due to the downsides:
Without exposing the value, we could make the decision to zap the #GP dependent upon us being able to read the MSR.The other possible adjustment would be to avoid issuing two log messages for the same operation (affecting debug builds only). But the code structure (which isn't really consistent about when the pre-existing message would get issued) doesn't directly lend itself to such an adjustment without altering the behavior for some of the MSRs explicitly handled.
As a tangent, while discussing this situation, please let's not forget about this code in Linux:
static u64
xen_read_msr(unsigned int msr){ /* * This will silently swallow a #GP from RDMSR. It may be worth * changing that. */ int err; return xen_read_msr_safe(msr, &err); }static void
xen_write_msr(unsigned int msr, unsigned low, unsigned high){ /* * This will silently swallow a #GP from WRMSR. It may be worth * changing that. */ xen_write_msr_safe(msr, low, high); }Imo this "silent swallowing" has always been the wrong thing to do, and hence ought to be dropped. Of course right now it saves the kernel from dying on the HWCR read.
Jan
Re: Ping²: [PATCH] x86/PV: conditionally avoid raising #GP for early guest MSR accesses
Quoted 77 lines · Jan Beulich
(simply re-sending what was sent over 2 months ago)
Quoted 68 lines · Jan Beulich
Quoted 17 lines · Andrew Cooper
Quoted 16 lines · Jan Beulich
Prior to 4.15 Linux, when running in PV mode, did not install a #GP handler early enough to cover for example the
rdmsrl_safe()ofMSR_K8_TSEG_ADDRinbsp_init_amd()(not to speak of the unguarded read ofMSR_K7_HWCRlater in the same function). The respective change (42b3a4cb5609"x86/xen: Support early interrupts in xen pv guests") was backported to 4.14, but no further - presumably since it wasn't really easy because of other dependencies.Therefore, to prevent our change in the handling of guest MSR accesses to render PV Linux 4.13 and older unusable on at least AMD systems, make the raising of #GP on these paths conditional upon the guest having installed a handler. Producing zero for reads and discarding writes isn't necessarily correct and may trip code trying to detect presence of MSRs early, but since such detection logic won't work without a #GP handler anyway, this ought to be a fair workaround.
Quoted 4 lines
Quoted 1 line
Signed-off-by Jan Beulich <[email protected]>I appreciate that we probably have to do something, but I don't think this is a wise move.
I wouldn't call it wise either, but I'm afraid something along these lines is necessary.
Quoted 5 lines
Linux is fundamentally buggy. It is deliberately looking for a potential #GP fault given its use of rdmsrl_safe(). The reason this bug stayed hidden for so long was as a consequence of Xen's inappropriate MSR handling for guests, and the reasons for changing Xen's behaviour still stand.
I agree.
Quoted 2 lines
This change, in particular, does not apply to any explicitly handled MSRs, and therefore is not a comprehensive fix.
But it's intentional that this deals with the situation in a generic way, not on a per-MSR basis. If we did as you suggest further down, we'd have to audit all Linux versions up to 4.14 for similar issues with other MSRs. I don't think this would be a practical thing to do, and I also don't think that leaving things as they are until we have concrete reports of problems is a viable option either.
Adding explicit handling for the two offending MSRs (and any possible further ones we discover) would imo only be to avoid issuing the respective log messages.
Quoted 4 lines
Nor is it robust to
someone adding code to explicitly handling the impacted MSRs at a later date (which are are likely to need to do for HWCR), and which would reintroduce this failure to boot.I'm afraid I don't understand. Looking at the two functions the patch alters, only
X86EMUL_OKAYis used in return statements other than the final one. If this model is to be followed by future additions (which I think it ought to be; perhaps we should add comments to this effect), the code introduced here will take care of the situation nevertheless.Quoted 6 lines
We should have the impacted MSRs handled explicitly, with a note stating this was a bug in Linux 4.14 and older. We already have workaround for similar bugs in Windows, and it also gives us a timeline to eventually removing support for obsolete workarounds, rather than having a "now and in the future, we'll explicitly tolerate broken PV behaviour for one bug back in ancient linux".
Quoted 5 lines
Comparing with Windows isn't very helpful; the patch here is specifically about PV, and would help other OSes as well in case they would have missed setting up exceptions early in just the PV-on-Xen case. For the HVM case I'd indeed rather see us go the route we've gone for Windows, if need be.
Quoted 8 lines
As can be seen from this reply, we're not in agreement what to do here. But we need to do something. I'm not sure how to get unstuck discussions like this one ...
Besides this suggestion of yours I also continue to have trouble seeing what good it will do to record an exception to inject into a guest when we know it didn't install a handler yet.
As we need to consider backports of processor bug mitigations in old guests, too, I think we need to have a "catch-all" fallback.
Not being able to run an old updated guest until we add handling for a new MSR isn't a viable option IMO.
Juergen
Re: Ping²: [PATCH] x86/PV: conditionally avoid raising #GP for early guest MSR accesses
Quoted 99 lines · Jürgen Groß
Quoted 89 lines · Jan Beulich
(simply re-sending what was sent over 2 months ago)
Quoted 80 lines · Jan Beulich
Quoted 23 lines · Andrew Cooper
Quoted 22 lines · Jan Beulich
Prior to 4.15 Linux, when running in PV mode, did not install a #GP handler early enough to cover for example the
rdmsrl_safe()ofMSR_K8_TSEG_ADDRinbsp_init_amd()(not to speak of the unguarded read
ofMSR_K7_HWCRlater in the same function). The respective change (42b3a4cb5609"x86/xen: Support early interrupts in xen pv guests") was
backported to 4.14, but no further - presumably since it wasn't really
easy because of other dependencies.Therefore, to prevent our change in the handling of guest MSR accesses
to render PV Linux 4.13 and older unusable on at least AMD systems, make
the raising of #GP on these paths conditional upon the guest having installed a handler. Producing zero for reads and discarding writes isn't necessarily correct and may trip code trying to detect presence of
MSRs early, but since such detection logic won't work without a #GP handler anyway, this ought to be a fair workaround.Quoted 4 lines
Quoted 1 line
Signed-off-by Jan Beulich <[email protected]>I appreciate that we probably have to do something, but I don't think this is a wise move.
I wouldn't call it wise either, but I'm afraid something along these lines is necessary.
Quoted 6 lines
Linux is fundamentally buggy. It is deliberately looking for a potential #GP fault given its use of rdmsrl_safe(). The reason this bug
stayed hidden for so long was as a consequence of Xen's inappropriate MSR handling for guests, and the reasons for changing Xen's behaviour still stand.I agree.
Quoted 2 lines
This change, in particular, does not apply to any explicitly handled MSRs, and therefore is not a comprehensive fix.
But it's intentional that this deals with the situation in a generic way, not on a per-MSR basis. If we did as you suggest further down, we'd have to audit all Linux versions up to 4.14 for similar issues with other MSRs. I don't think this would be a practical thing to do, and I also don't think that leaving things as they are until we have concrete reports of problems is a viable option either.
Adding explicit handling for the two offending MSRs (and any possible further ones we discover) would imo only be to avoid issuing the respective log messages.
Quoted 5 lines
Nor is it robust to
someone adding code to explicitly handling the impacted MSRs at a later
date (which are are likely to need to do for HWCR), and which would reintroduce this failure to boot.I'm afraid I don't understand. Looking at the two functions the patch alters, only
X86EMUL_OKAYis used in return statements other than the final one. If this model is to be followed by future additions (which I think it ought to be; perhaps we should add comments to this effect), the code introduced here will take care of the situation nevertheless.Quoted 10 lines
We should have the impacted MSRs handled explicitly, with a note stating
this was a bug in Linux 4.14 and older. We already have workaround for
similar bugs in Windows, and it also gives us a timeline to eventually removing support for obsolete workarounds, rather than having a "now and
in the future, we'll explicitly tolerate broken PV behaviour for one bug
back in ancient linux".Quoted 5 lines
Comparing with Windows isn't very helpful; the patch here is specifically about PV, and would help other OSes as well in case they would have missed setting up exceptions early in just the PV-on-Xen case. For the HVM case I'd indeed rather see us go the route we've gone for Windows, if need be.
Quoted 8 lines
As can be seen from this reply, we're not in agreement what to do here. But we need to do something. I'm not sure how to get unstuck discussions like this one ...
Besides this suggestion of yours I also continue to have trouble seeing what good it will do to record an exception to inject into a guest when we know it didn't install a handler yet.
Quoted 6 lines
As we need to consider backports of processor bug mitigations in old guests, too, I think we need to have a "catch-all" fallback.
Not being able to run an old updated guest until we add handling for a new MSR isn't a viable option IMO.
You're trading off against issuing XSAs for all the unknown quantities of sensitive in MSRs on all past and future platforms. This has unbounded scope.
Xen's previous behaviour was astoundingly stupid, and yes - we're playing more than a decades worth of catchup in one release cycle.
I'll absolutely take "care/tweaks need to happen crossing the Xen 4.14=>4.15 boundary" over whack-a-mole for MSRs in the form of security advisories.
~Andrew
Re: Ping²: [PATCH] x86/PV: conditionally avoid raising #GP for early guest MSR accesses
Quoted 111 lines · Andrew Cooper
Quoted 99 lines · Jürgen Groß
Quoted 89 lines · Jan Beulich
(simply re-sending what was sent over 2 months ago)
Quoted 80 lines · Jan Beulich
Quoted 23 lines · Andrew Cooper
Quoted 22 lines · Jan Beulich
Prior to 4.15 Linux, when running in PV mode, did not install a #GP handler early enough to cover for example the
rdmsrl_safe()ofMSR_K8_TSEG_ADDRinbsp_init_amd()(not to speak of the unguarded read
ofMSR_K7_HWCRlater in the same function). The respective change (42b3a4cb5609"x86/xen: Support early interrupts in xen pv guests") was
backported to 4.14, but no further - presumably since it wasn't really
easy because of other dependencies.Therefore, to prevent our change in the handling of guest MSR accesses
to render PV Linux 4.13 and older unusable on at least AMD systems, make
the raising of #GP on these paths conditional upon the guest having installed a handler. Producing zero for reads and discarding writes isn't necessarily correct and may trip code trying to detect presence of
MSRs early, but since such detection logic won't work without a #GP handler anyway, this ought to be a fair workaround.Quoted 4 lines
Quoted 1 line
Signed-off-by Jan Beulich <[email protected]>I appreciate that we probably have to do something, but I don't think this is a wise move.
I wouldn't call it wise either, but I'm afraid something along these lines is necessary.
Quoted 6 lines
Linux is fundamentally buggy. It is deliberately looking for a potential #GP fault given its use of rdmsrl_safe(). The reason this bug
stayed hidden for so long was as a consequence of Xen's inappropriate MSR handling for guests, and the reasons for changing Xen's behaviour still stand.I agree.
Quoted 2 lines
This change, in particular, does not apply to any explicitly handled MSRs, and therefore is not a comprehensive fix.
But it's intentional that this deals with the situation in a generic way, not on a per-MSR basis. If we did as you suggest further down, we'd have to audit all Linux versions up to 4.14 for similar issues with other MSRs. I don't think this would be a practical thing to do, and I also don't think that leaving things as they are until we have concrete reports of problems is a viable option either.
Adding explicit handling for the two offending MSRs (and any possible further ones we discover) would imo only be to avoid issuing the respective log messages.
Quoted 5 lines
Nor is it robust to
someone adding code to explicitly handling the impacted MSRs at a later
date (which are are likely to need to do for HWCR), and which would reintroduce this failure to boot.I'm afraid I don't understand. Looking at the two functions the patch alters, only
X86EMUL_OKAYis used in return statements other than the final one. If this model is to be followed by future additions (which I think it ought to be; perhaps we should add comments to this effect), the code introduced here will take care of the situation nevertheless.Quoted 10 lines
We should have the impacted MSRs handled explicitly, with a note stating
this was a bug in Linux 4.14 and older. We already have workaround for
similar bugs in Windows, and it also gives us a timeline to eventually removing support for obsolete workarounds, rather than having a "now and
in the future, we'll explicitly tolerate broken PV behaviour for one bug
back in ancient linux".Quoted 5 lines
Comparing with Windows isn't very helpful; the patch here is specifically about PV, and would help other OSes as well in case they would have missed setting up exceptions early in just the PV-on-Xen case. For the HVM case I'd indeed rather see us go the route we've gone for Windows, if need be.
Quoted 8 lines
As can be seen from this reply, we're not in agreement what to do here. But we need to do something. I'm not sure how to get unstuck discussions like this one ...
Besides this suggestion of yours I also continue to have trouble seeing what good it will do to record an exception to inject into a guest when we know it didn't install a handler yet.
Quoted 6 lines
As we need to consider backports of processor bug mitigations in old guests, too, I think we need to have a "catch-all" fallback.
Not being able to run an old updated guest until we add handling for a new MSR isn't a viable option IMO.
You're trading off against issuing XSAs for all the unknown quantities of sensitive in MSRs on all past and future platforms. This has unbounded scope.
Quoted 6 lines
Xen's previous behaviour was astoundingly stupid, and yes - we're playing more than a decades worth of catchup in one release cycle.
I'll absolutely take "care/tweaks need to happen crossing the Xen 4.14=>4.15 boundary" over whack-a-mole for MSRs in the form of security advisories.
What about making this behavior controllable via a boot parameter?
Selecting that could result in a boot warning issued via warning_add().
Juergen
Re: Ping²: [PATCH] x86/PV: conditionally avoid raising #GP for early guest MSR accesses
In reply to Andrew CooperQuoted 111 lines · Andrew Cooper
Quoted 99 lines · Jürgen Groß
Quoted 89 lines · Jan Beulich
(simply re-sending what was sent over 2 months ago)
Quoted 80 lines · Jan Beulich
Quoted 23 lines · Andrew Cooper
Quoted 22 lines · Jan Beulich
Prior to 4.15 Linux, when running in PV mode, did not install a #GP handler early enough to cover for example the
rdmsrl_safe()ofMSR_K8_TSEG_ADDRinbsp_init_amd()(not to speak of the unguarded read
ofMSR_K7_HWCRlater in the same function). The respective change (42b3a4cb5609"x86/xen: Support early interrupts in xen pv guests") was
backported to 4.14, but no further - presumably since it wasn't really
easy because of other dependencies.Therefore, to prevent our change in the handling of guest MSR accesses
to render PV Linux 4.13 and older unusable on at least AMD systems, make
the raising of #GP on these paths conditional upon the guest having installed a handler. Producing zero for reads and discarding writes isn't necessarily correct and may trip code trying to detect presence of
MSRs early, but since such detection logic won't work without a #GP handler anyway, this ought to be a fair workaround.Quoted 4 lines
Quoted 1 line
Signed-off-by Jan Beulich <[email protected]>I appreciate that we probably have to do something, but I don't think this is a wise move.
I wouldn't call it wise either, but I'm afraid something along these lines is necessary.
Quoted 6 lines
Linux is fundamentally buggy. It is deliberately looking for a potential #GP fault given its use of rdmsrl_safe(). The reason this bug
stayed hidden for so long was as a consequence of Xen's inappropriate MSR handling for guests, and the reasons for changing Xen's behaviour still stand.I agree.
Quoted 2 lines
This change, in particular, does not apply to any explicitly handled MSRs, and therefore is not a comprehensive fix.
But it's intentional that this deals with the situation in a generic way, not on a per-MSR basis. If we did as you suggest further down, we'd have to audit all Linux versions up to 4.14 for similar issues with other MSRs. I don't think this would be a practical thing to do, and I also don't think that leaving things as they are until we have concrete reports of problems is a viable option either.
Adding explicit handling for the two offending MSRs (and any possible further ones we discover) would imo only be to avoid issuing the respective log messages.
Quoted 5 lines
Nor is it robust to
someone adding code to explicitly handling the impacted MSRs at a later
date (which are are likely to need to do for HWCR), and which would reintroduce this failure to boot.I'm afraid I don't understand. Looking at the two functions the patch alters, only
X86EMUL_OKAYis used in return statements other than the final one. If this model is to be followed by future additions (which I think it ought to be; perhaps we should add comments to this effect), the code introduced here will take care of the situation nevertheless.Quoted 10 lines
We should have the impacted MSRs handled explicitly, with a note stating
this was a bug in Linux 4.14 and older. We already have workaround for
similar bugs in Windows, and it also gives us a timeline to eventually removing support for obsolete workarounds, rather than having a "now and
in the future, we'll explicitly tolerate broken PV behaviour for one bug
back in ancient linux".Quoted 5 lines
Comparing with Windows isn't very helpful; the patch here is specifically about PV, and would help other OSes as well in case they would have missed setting up exceptions early in just the PV-on-Xen case. For the HVM case I'd indeed rather see us go the route we've gone for Windows, if need be.
Quoted 8 lines
As can be seen from this reply, we're not in agreement what to do here. But we need to do something. I'm not sure how to get unstuck discussions like this one ...
Besides this suggestion of yours I also continue to have trouble seeing what good it will do to record an exception to inject into a guest when we know it didn't install a handler yet.
Quoted 6 lines
As we need to consider backports of processor bug mitigations in old guests, too, I think we need to have a "catch-all" fallback.
Not being able to run an old updated guest until we add handling for a new MSR isn't a viable option IMO.
You're trading off against issuing XSAs for all the unknown quantities of sensitive in MSRs on all past and future platforms. This has unbounded scope.
Quoted 6 lines
Xen's previous behaviour was astoundingly stupid, and yes - we're playing more than a decades worth of catchup in one release cycle.
I'll absolutely take "care/tweaks need to happen crossing the Xen 4.14=>4.15 boundary" over whack-a-mole for MSRs in the form of security advisories.
I think I'm likely missing part of the point here - Jan's patch would just return 0 for reads, so there's no leak of unhandled MSRs? Hence I'm not seeing the XSA aspect of this.
Roger.
Re: Ping²: [PATCH] x86/PV: conditionally avoid raising #GP for early guest MSR accesses
In reply to Andrew CooperQuoted 41 lines · Andrew Cooper
Quoted 29 lines · Jürgen Groß
Quoted 19 lines · Jan Beulich
Quoted 12 lines · Jan Beulich
Quoted 10 lines · Andrew Cooper
We should have the impacted MSRs handled explicitly, with a note stating
this was a bug in Linux 4.14 and older. We already have workaround for
similar bugs in Windows, and it also gives us a timeline to eventually removing support for obsolete workarounds, rather than having a "now and
in the future, we'll explicitly tolerate broken PV behaviour for one bug
back in ancient linux".Quoted 5 lines
Comparing with Windows isn't very helpful; the patch here is specifically about PV, and would help other OSes as well in case they would have missed setting up exceptions early in just the PV-on-Xen case. For the HVM case I'd indeed rather see us go the route we've gone for Windows, if need be.
Quoted 8 lines
As can be seen from this reply, we're not in agreement what to do here. But we need to do something. I'm not sure how to get unstuck discussions like this one ...
Besides this suggestion of yours I also continue to have trouble seeing what good it will do to record an exception to inject into a guest when we know it didn't install a handler yet.
Quoted 6 lines
As we need to consider backports of processor bug mitigations in old guests, too, I think we need to have a "catch-all" fallback.
Not being able to run an old updated guest until we add handling for a new MSR isn't a viable option IMO.
You're trading off against issuing XSAs for all the unknown quantities of sensitive in MSRs on all past and future platforms. This has unbounded scope.
Quoted 6 lines
Xen's previous behaviour was astoundingly stupid, and yes - we're playing more than a decades worth of catchup in one release cycle.
I'll absolutely take "care/tweaks need to happen crossing the Xen 4.14=>4.15 boundary" over whack-a-mole for MSRs in the form of security advisories.
All of this reads as if someone was asking to re-introduce the blind leaking of MSRs. I'm pretty sure though you realize that this isn't the case, so I guess I'm confused ...
Note that while I have just disagreed with Jürgen's specific case, I still think the conclusion is right: Where possible _without_ reintroducing tjhe bad original behavior, we should try to not put ourselves in the position of needing to update Xen once guests want to access new MSRs (or even us simply being unaware of present guests having rarely used code paths leading to such MSR accesses).
Jan
Re: Ping²: [PATCH] x86/PV: conditionally avoid raising #GP for early guest MSR accesses
In reply to Jürgen GroßQuoted 6 lines · Jürgen Groß
As we need to consider backports of processor bug mitigations in old guests, too, I think we need to have a "catch-all" fallback.
Not being able to run an old updated guest until we add handling for a new MSR isn't a viable option IMO.
I'm not sure I follow you here: Such backports should still make use of the respective CPUID bits, and hence shouldn't contain "blind" MSR accesses. And if there's really something needing to probe an MSR, then I'd expect such a backport to make sure the probing actually works in a prereq (presumably) backport.
Jan
Re: Ping²: [PATCH] x86/PV: conditionally avoid raising #GP for early guest MSR accesses
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Jürgen Groß
As we need to consider backports of processor bug mitigations in old guests, too, I think we need to have a "catch-all" fallback.
Quoted 8 lines
Quoted 2 lines
Not being able to run an old updated guest until we add handling for a new MSR isn't a viable option IMO.
I'm not sure I follow you here: Such backports should still make use of the respective CPUID bits, and hence shouldn't contain "blind" MSR accesses. And if there's really something needing to probe an MSR, then I'd expect such a backport to make sure the probing actually works in a prereq (presumably) backport.
We know that Linux partially relies on blind MSR accesses to be tolerated on bare metal. With this and older Xen versions having worked by _not_ faulting when the guest accesses illegal MSRs it is not that unlikely that some guests will suddenly fail to boot.
Especially when backporting processor bug mitigations I could envision not all distros will thoroughly test the kernel to still run as PV guest on newest Xen.
Juergen