From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFDB2C3A5A2 for ; Thu, 22 Aug 2019 15:28:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AAB5123401 for ; Thu, 22 Aug 2019 15:28:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732057AbfHVP2z (ORCPT ); Thu, 22 Aug 2019 11:28:55 -0400 Received: from mga06.intel.com ([134.134.136.31]:50937 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728964AbfHVP2z (ORCPT ); Thu, 22 Aug 2019 11:28:55 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Aug 2019 08:28:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,417,1559545200"; d="scan'208";a="186601083" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.41]) by FMSMGA003.fm.intel.com with ESMTP; 22 Aug 2019 08:28:54 -0700 Date: Thu, 22 Aug 2019 08:28:54 -0700 From: Sean Christopherson To: Steven Price Cc: Marc Zyngier , Will Deacon , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, Catalin Marinas , Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , Russell King , James Morse , Julien Thierry , Suzuki K Pouloze , Mark Rutland , kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 04/10] KVM: Implement kvm_put_guest() Message-ID: <20190822152854.GE25467@linux.intel.com> References: <20190821153656.33429-1-steven.price@arm.com> <20190821153656.33429-5-steven.price@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190821153656.33429-5-steven.price@arm.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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? > > Signed-off-by: Steven Price > --- > include/linux/kvm_host.h | 24 ++++++++++++++++++++++++ > 1 file changed, 24 insertions(+) > > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > index fcb46b3374c6..e154a1897e20 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -746,6 +746,30 @@ int kvm_write_guest_offset_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc, > unsigned long len); > int kvm_gfn_to_hva_cache_init(struct kvm *kvm, struct gfn_to_hva_cache *ghc, > gpa_t gpa, unsigned long len); > + > +#define __kvm_put_guest(kvm, gfn, offset, value, type) \ > +({ \ > + unsigned long __addr = gfn_to_hva(kvm, gfn); \ > + type __user *__uaddr = (type __user *)(__addr + offset); \ > + int __ret = 0; \ > + \ > + if (kvm_is_error_hva(__addr)) \ > + __ret = -EFAULT; \ > + else \ > + __ret = put_user(value, __uaddr); \ > + if (!__ret) \ > + mark_page_dirty(kvm, gfn); \ > + __ret; \ > +}) > + > +#define kvm_put_guest(kvm, gpa, value, type) \ > +({ \ > + gpa_t __gpa = gpa; \ > + struct kvm *__kvm = kvm; \ > + __kvm_put_guest(__kvm, __gpa >> PAGE_SHIFT, \ > + offset_in_page(__gpa), (value), type); \ > +}) > + > int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len); > int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len); > struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn); > -- > 2.20.1 >