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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F55EC433FE for ; Fri, 12 Nov 2021 05:51:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C33B461051 for ; Fri, 12 Nov 2021 05:51:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C33B461051 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id CD89A6B0074; Fri, 12 Nov 2021 00:51:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C60BE6B0078; Fri, 12 Nov 2021 00:51:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B01386B007B; Fri, 12 Nov 2021 00:51:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0092.hostedemail.com [216.40.44.92]) by kanga.kvack.org (Postfix) with ESMTP id 9B61C6B0074 for ; Fri, 12 Nov 2021 00:51:39 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4B34D8249980 for ; Fri, 12 Nov 2021 05:51:39 +0000 (UTC) X-FDA: 78799206444.05.D8E188F Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf31.hostedemail.com (Postfix) with ESMTP id 43D711056AB7 for ; Fri, 12 Nov 2021 05:51:24 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6200,9189,10165"; a="213806525" X-IronPort-AV: E=Sophos;i="5.87,228,1631602800"; d="scan'208";a="213806525" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2021 21:51:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,228,1631602800"; d="scan'208";a="492855072" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.192.101]) by orsmga007.jf.intel.com with ESMTP; 11 Nov 2021 21:51:27 -0800 Date: Fri, 12 Nov 2021 13:50:38 +0800 From: Chao Peng To: Mika =?iso-8859-1?Q?Penttil=E4?= Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, qemu-devel@nongnu.org, Wanpeng Li , luto@kernel.org, david@redhat.com, "J . Bruce Fields" , dave.hansen@intel.com, "H . Peter Anvin" , ak@linux.intel.com, Jonathan Corbet , Joerg Roedel , x86@kernel.org, Hugh Dickins , Ingo Molnar , Borislav Petkov , jun.nakajima@intel.com, Thomas Gleixner , Vitaly Kuznetsov , Jim Mattson , Sean Christopherson , susie.li@intel.com, Jeff Layton , john.ji@intel.com, Yu Zhang , Paolo Bonzini , Andrew Morton , "Kirill A . Shutemov" Subject: Re: [RFC PATCH 5/6] kvm: x86: add KVM_EXIT_MEMORY_ERROR exit Message-ID: <20211112055038.GB27969@chaop.bj.intel.com> Reply-To: Chao Peng References: <20211111141352.26311-1-chao.p.peng@linux.intel.com> <20211111141352.26311-6-chao.p.peng@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 43D711056AB7 X-Stat-Signature: i8nagcan3h9sjridpyyqqpr3y4s1q97i Authentication-Results: imf31.hostedemail.com; dkim=none; spf=none (imf31.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 192.55.52.151) smtp.mailfrom=chao.p.peng@linux.intel.com; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=intel.com (policy=none) X-HE-Tag: 1636696284-574380 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Nov 11, 2021 at 05:08:47PM +0200, Mika Penttil=E4 wrote: >=20 >=20 > On 11.11.2021 16.13, Chao Peng wrote: > > Currently support to exit to userspace for private/shared memory > > conversion. > >=20 > > Signed-off-by: Sean Christopherson > > Signed-off-by: Yu Zhang > > Signed-off-by: Chao Peng > > --- > > arch/x86/kvm/mmu/mmu.c | 20 ++++++++++++++++++++ > > include/uapi/linux/kvm.h | 15 +++++++++++++++ > > 2 files changed, 35 insertions(+) > >=20 > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > > index af5ecf4ef62a..780868888aa8 100644 > > --- a/arch/x86/kvm/mmu/mmu.c > > +++ b/arch/x86/kvm/mmu/mmu.c > > @@ -3950,6 +3950,17 @@ static bool try_async_pf(struct kvm_vcpu *vcpu= , bool prefault, gfn_t gfn, > > slot =3D __kvm_vcpu_gfn_to_memslot(vcpu, gfn, private); > > + /* > > + * Exit to userspace to map the requested private/shared memory reg= ion > > + * if there is no memslot and (a) the access is private or (b) ther= e is > > + * an existing private memslot. Emulated MMIO must be accessed thr= ough > > + * shared GPAs, thus a memslot miss on a private GPA is always hand= led > > + * as an implicit conversion "request". > > + */ > > + if (!slot && > > + (private || __kvm_vcpu_gfn_to_memslot(vcpu, gfn, true))) > > + goto out_convert; > > + > > /* Don't expose aliases for no slot GFNs or private memslots */ > > if ((cr2_or_gpa & vcpu_gpa_stolen_mask(vcpu)) && > > !kvm_is_visible_memslot(slot)) { > > @@ -3994,6 +4005,15 @@ static bool try_async_pf(struct kvm_vcpu *vcpu= , bool prefault, gfn_t gfn, > > *pfn =3D __gfn_to_pfn_memslot(slot, gfn, false, NULL, > > write, writable, hva); > > return false; > > + > > +out_convert: > > + vcpu->run->exit_reason =3D KVM_EXIT_MEMORY_ERROR; > > + vcpu->run->mem.type =3D private ? KVM_EXIT_MEM_MAP_PRIVATE > > + : KVM_EXIT_MEM_MAP_SHARE; > > + vcpu->run->mem.u.map.gpa =3D cr2_or_gpa; > > + vcpu->run->mem.u.map.size =3D PAGE_SIZE; > > + return true; > > + > I think this does just retry, no exit to user space? Good catch, thanks. Chao >=20 >=20 >=20 >=20 > > } > > static int direct_page_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u32 = error_code, > > diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h > > index 8d20caae9180..470c472a9451 100644 > > --- a/include/uapi/linux/kvm.h > > +++ b/include/uapi/linux/kvm.h > > @@ -233,6 +233,18 @@ struct kvm_xen_exit { > > } u; > > }; > > +struct kvm_memory_exit { > > +#define KVM_EXIT_MEM_MAP_SHARE 1 > > +#define KVM_EXIT_MEM_MAP_PRIVATE 2 > > + __u32 type; > > + union { > > + struct { > > + __u64 gpa; > > + __u64 size; > > + } map; > > + } u; > > +}; > > + > > #define KVM_S390_GET_SKEYS_NONE 1 > > #define KVM_S390_SKEYS_MAX 1048576 > > @@ -272,6 +284,7 @@ struct kvm_xen_exit { > > #define KVM_EXIT_X86_BUS_LOCK 33 > > #define KVM_EXIT_XEN 34 > > #define KVM_EXIT_TDVMCALL 35 > > +#define KVM_EXIT_MEMORY_ERROR 36 > > /* For KVM_EXIT_INTERNAL_ERROR */ > > /* Emulate instruction failed. */ > > @@ -455,6 +468,8 @@ struct kvm_run { > > __u64 subfunc; > > __u64 param[4]; > > } tdvmcall; > > + /* KVM_EXIT_MEMORY_ERROR */ > > + struct kvm_memory_exit mem; > > /* Fix the size of the union. */ > > char padding[256]; > > }; >=20