[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH] x86: store cr4 during suspend/resume


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Thu, 12 Dec 2019 12:37:12 +0000
  • Authentication-results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@xxxxxxxxxx; spf=Pass smtp.mailfrom=Andrew.Cooper3@xxxxxxxxxx; spf=None smtp.helo=postmaster@xxxxxxxxxxxxxxx
  • Autocrypt: addr=andrew.cooper3@xxxxxxxxxx; prefer-encrypt=mutual; keydata= mQINBFLhNn8BEADVhE+Hb8i0GV6mihnnr/uiQQdPF8kUoFzCOPXkf7jQ5sLYeJa0cQi6Penp VtiFYznTairnVsN5J+ujSTIb+OlMSJUWV4opS7WVNnxHbFTPYZVQ3erv7NKc2iVizCRZ2Kxn srM1oPXWRic8BIAdYOKOloF2300SL/bIpeD+x7h3w9B/qez7nOin5NzkxgFoaUeIal12pXSR Q354FKFoy6Vh96gc4VRqte3jw8mPuJQpfws+Pb+swvSf/i1q1+1I4jsRQQh2m6OTADHIqg2E ofTYAEh7R5HfPx0EXoEDMdRjOeKn8+vvkAwhviWXTHlG3R1QkbE5M/oywnZ83udJmi+lxjJ5 YhQ5IzomvJ16H0Bq+TLyVLO/VRksp1VR9HxCzItLNCS8PdpYYz5TC204ViycobYU65WMpzWe LFAGn8jSS25XIpqv0Y9k87dLbctKKA14Ifw2kq5OIVu2FuX+3i446JOa2vpCI9GcjCzi3oHV e00bzYiHMIl0FICrNJU0Kjho8pdo0m2uxkn6SYEpogAy9pnatUlO+erL4LqFUO7GXSdBRbw5 gNt25XTLdSFuZtMxkY3tq8MFss5QnjhehCVPEpE6y9ZjI4XB8ad1G4oBHVGK5LMsvg22PfMJ ISWFSHoF/B5+lHkCKWkFxZ0gZn33ju5n6/FOdEx4B8cMJt+cWwARAQABtCl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9Sl9IAKFu29RSo d5bD8kMSCYsTqtTfT6W4A3qHGvIDta3ptLYpIAOD2sY3GYq2nf3Bbzx81wZK14JdDDHUX2Rs 6+ahAA==
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, Wei Liu <wl@xxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Delivery-date: Thu, 12 Dec 2019 12:37:45 +0000
  • Ironport-sdr: PQe0oz5kAygfytoeqmdCauai1vJmtlKrqczyv5RyX8y817zPzfJvE786UB+ouplsjP7k2uxU67 p8HWF+Z15NbxCcyuTTGzQgiundvbynwJ1RZx5r7pIg/uOTFTi8RZj8Qbj32IHfG4/k7+8rjEqo zCUKBTxOXZxev1gKuBbIH2obLOj1gS/mey/tUMzADMOkT/gZfU9vbGIAlc1dl5KPgec2k3PE8H 0mwnPJFDBXjKXig+HgzsrsmcuI5dQyKRWq0Va3hqthgdx4ZmaC90KmarRWAePp7Lsnfrbuv/+v G/U=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Openpgp: preference=signencrypt

On 12/12/2019 09:52, Jan Beulich wrote:
> On 11.12.2019 20:36, Andrew Cooper wrote:
>> On 10/12/2019 10:07, Jan Beulich wrote:
>>> On 10.12.2019 10:59, Andrew Cooper wrote:
>>>> On 09/12/2019 18:06, Roger Pau Monne wrote:
>>>>> Currently cr4 is not cached before suspension, and mmu_cr4_features is
>>>>> used in order to restore the expected cr4 value. This is correct so
>>>>> far because the tasklet that executes the suspend/resume code is
>>>>> running in the idle vCPU context.
>>>>>
>>>>> In order to make the code less fragile, explicitly save the current
>>>>> cr4 value before suspension, so that it can be restored afterwards.
>>>>> This ensures that the cr4 value cached in the cpu_info doesn't get out
>>>>> of sync after resume from suspension.
>>>>>
>>>>> Suggested-by: Jan Beulich <jbeulich@xxxxxxxx>
>>>>> Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
>>>> Why?  There is nothing fragile here.  Suspend/resume is always in idle
>>>> context and loads of other logic already depends on this.
>>>>
>>>> I've been slowly stripping out redundant saved state like this.
>>> Where it's clearly redundant, this is fine. But I don't think it's
>>> sufficiently clear here
>> There is a reason I made it explicitly crystal clear with c/s 87e7b4d5b
> Well, this makes clear we're in idle context, yes. But there's
> still a disconnect between this and the use of mmu_cr4_features
> (up to and including the somewhat misleading comment saying
> "mmu_cr4_features contains latest cr4 setting" without it really
> being clear what "latest" means, now that we run with varying
> CR4 values. Yes, write_ptbase() does use the variable when
> switching to idle, but the variable name lack any connection to
> this fact.

The name of the variable should probably be improved - I'm not a fan of
its current name.

Perhaps this seems more obvious to me than others because I did all the
work for XSA-293, but the commit message of c/s b2dd00574a4 is relevant:

> First of all, modify write_ptbase() to always use mmu_cr4_features for
> IDLE
> and HVM contexts.  mmu_cr4_features *is* the correct value to use, and
> makes
> the ASSERT() obviously redundant.

and the same applies to S3 path.

>
>>> , and going back to what was there before
>>> is imo generally less error prone than going to some fixed state.
>> It is demonstrably more error prone, which is why I'm slowly killing it.
>>
>> Stashing state wastes unnecessary space, and adds an error case where
>> state is either stashed incorrectly, or gets modified before restore,
>> and we'll blindly use.
> The waste of space is entirely secondary here, I think. A value
> getting modified before restore is no different from a value
> going out of sync with the variable we reload from. It's a blind
> use in either case.
>
>> Two examples of real bugs caused by this are c/s 0c30171cb and 4ee0ad72d
> I see your point for the former, but the latter seems to be unrelated.

Oh - quite right.  I wasn't paying quite enough attention when doing
archaeology.

>
>> Absolutely nothing remaining in suspend.c should be spilled.  It can all
>> be (re)caluclated from the same information source as the AP boot path,
>> and the result will be strictly smaller in RAM, and more robust.
> Robustness to me would imply using the same code for doing the
> calculations, not re-calculating from the same information source.
> This could be as simple as an idle_cr4() wrapper around the read
> of mmu_cr4_features for the case at hand (suitably used wherever
> applicable).
>
> Anyway - together with your subsequent mail I accept your objections.
> Once the code changes proposed there have gone in, I think it'll
> become more clear to readers that indeed state saving/restoring is to
> be the exception, not the rule (current code doesn't give this
> impression, I think).

It was all inherited from Linux, and is slowly being stripped out there
as well.

I'll try and do some more cleanup in some free time.

~Andrew

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.