From: Steven Price <email@example.com> To: Sean Christopherson <firstname.lastname@example.org> Cc: "Mark Rutland" <email@example.com>, firstname.lastname@example.org, "Radim Krčmář" <email@example.com>, "Marc Zyngier" <firstname.lastname@example.org>, "Suzuki K Pouloze" <email@example.com>, firstname.lastname@example.org, "Russell King" <email@example.com>, firstname.lastname@example.org, "James Morse" <email@example.com>, "Julien Thierry" <firstname.lastname@example.org>, "Catalin Marinas" <email@example.com>, "Paolo Bonzini" <firstname.lastname@example.org>, "Will Deacon" <email@example.com>, firstname.lastname@example.org, email@example.com Subject: Re: [PATCH v3 04/10] KVM: Implement kvm_put_guest() Date: Fri, 23 Aug 2019 11:33:49 +0100 [thread overview] Message-ID: <firstname.lastname@example.org> (raw) In-Reply-To: <20190822162449.GF25467@linux.intel.com> On 22/08/2019 17:24, Sean Christopherson wrote: > On Thu, Aug 22, 2019 at 04:46:10PM +0100, Steven Price wrote: >> On 22/08/2019 16:28, Sean Christopherson wrote: >>> On Wed, Aug 21, 2019 at 04:36:50PM +0100, Steven Price wrote: >>>> kvm_put_guest() is analogous to put_user() - it writes a single value to >>>> the guest physical address. The implementation is built upon put_user() >>>> and so it has the same single copy atomic properties. >>> >>> What you mean by "single copy atomic"? I.e. what guarantees does >>> put_user() provide that __copy_to_user() does not? >> >> Single-copy atomicity is defined by the Arm architecture and I'm not >> going to try to go into the full details here, so this is a summary. >> >> For the sake of this feature what we care about is that the value >> written/read cannot be "torn". In other words if there is a read (in >> this case from another VCPU) that is racing with the write then the read >> will either get the old value or the new value. It cannot return a >> mixture. (This is of course assuming that the read is using a >> single-copy atomic safe method). > > Thanks for the explanation. I assumed that's what you were referring to, > but wanted to double check. > >> __copy_to_user() is implemented as a memcpy() and as such cannot provide >> single-copy atomicity in the general case (the buffer could easily be >> bigger than the architecture can guarantee). >> >> put_user() on the other hand is implemented (on arm64) as an explicit >> store instruction and therefore is guaranteed by the architecture to be >> single-copy atomic (i.e. another CPU cannot see a half-written value). > > I don't think kvm_put_guest() belongs in generic code, at least not with > the current changelog explanation about it providing single-copy atomic > semantics. AFAICT, the single-copy thing is very much an arm64 > implementation detail, e.g. the vast majority of 32-bit architectures, > including x86, do not provide any guarantees, and x86-64 generates more > or less the same code for put_user() and __copy_to_user() for 8-byte and > smaller accesses. > > As an alternative to kvm_put_guest() entirely, is it an option to change > arm64's raw_copy_to_user() to redirect to __put_user() for sizes that are > constant at compile time and can be handled by __put_user()? That would > allow using kvm_write_guest() to update stolen time, albeit with > arguably an even bigger dependency on the uaccess implementation details. I think it's important to in some way ensure that the desire that this is a single write is shown. copy_to_user() is effectively "setup();memcpy();finish();" and while a good memcpy() implementation would be identical to put_user() there's a lot more room for this being broken in the future by changes to the memcpy() implementation. (And I don't want to require that memcpy() has to detect this case). One suggestion is to call it something like kvm_put_guest_atomic() to reflect the atomicity requirement. Presumably that would be based on a new put_user_atomic() which architectures could override as necessary if put_user() doesn't provide the necessary guarantees. Steve
next prev parent reply other threads:[~2019-08-23 10:33 UTC|newest] Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-08-21 15:36 [PATCH v3 00/10] arm64: Stolen time support Steven Price 2019-08-21 15:36 ` [PATCH v3 01/10] KVM: arm64: Document PV-time interface Steven Price 2019-08-27 8:44 ` Christoffer Dall 2019-08-28 11:23 ` Steven Price 2019-08-27 8:57 ` Christoffer Dall 2019-08-28 12:09 ` Steven Price 2019-08-30 9:22 ` Christoffer Dall 2019-08-28 13:49 ` Christoffer Dall 2019-08-29 15:21 ` Steven Price 2019-08-29 17:15 ` Andrew Jones 2019-08-30 8:35 ` Steven Price 2019-08-21 15:36 ` [PATCH v3 02/10] KVM: arm/arm64: Factor out hypercall handling from PSCI code Steven Price 2019-08-21 15:36 ` [PATCH v3 03/10] KVM: arm64: Implement PV_FEATURES call Steven Price 2019-08-21 15:36 ` [PATCH v3 04/10] KVM: Implement kvm_put_guest() Steven Price 2019-08-22 10:29 ` Jonathan Cameron 2019-08-22 10:37 ` Steven Price 2019-08-22 15:28 ` Sean Christopherson 2019-08-22 15:46 ` Steven Price 2019-08-22 16:24 ` Sean Christopherson 2019-08-23 10:33 ` Steven Price [this message] 2019-08-21 15:36 ` [PATCH v3 05/10] KVM: arm64: Support stolen time reporting via shared structure Steven Price 2019-08-22 10:39 ` Jonathan Cameron 2019-08-22 11:00 ` Steven Price 2019-08-23 12:07 ` Zenghui Yu 2019-08-23 13:23 ` Steven Price 2019-08-21 15:36 ` [PATCH v3 06/10] KVM: Allow kvm_device_ops to be const Steven Price 2019-08-21 15:36 ` [PATCH v3 07/10] KVM: arm64: Provide a PV_TIME device to user space Steven Price 2019-08-22 10:57 ` Jonathan Cameron 2019-08-22 11:11 ` Steven Price 2019-08-22 11:48 ` Jonathan Cameron 2019-08-21 15:36 ` [PATCH v3 08/10] arm/arm64: Provide a wrapper for SMCCC 1.1 calls Steven Price 2019-08-21 15:36 ` [PATCH v3 09/10] arm/arm64: Make use of the SMCCC 1.1 wrapper Steven Price 2019-08-21 15:36 ` [PATCH v3 10/10] arm64: Retrieve stolen time as paravirtualized guest Steven Price 2019-08-23 11:45 ` Zenghui Yu 2019-08-23 14:22 ` Steven Price 2019-08-27 12:43 ` Zenghui Yu
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --subject='Re: [PATCH v3 04/10] KVM: Implement kvm_put_guest()' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).