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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9845C4332F for ; Fri, 8 Apr 2022 14:00:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236671AbiDHOCZ (ORCPT ); Fri, 8 Apr 2022 10:02:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234068AbiDHOCX (ORCPT ); Fri, 8 Apr 2022 10:02:23 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B222C1066C6; Fri, 8 Apr 2022 07:00:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649426419; x=1680962419; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=vzRh1a2g1teZIO284W8xK+WsiWROyR/t9wQMFIz6/+E=; b=QOzLlZGujWLt30xDoiZCQjIiNQYcmUitOuwquovOequamxxufeQOC/6B llpW2A60Pt+Cs3AyhTQkT6D1FCRU+goYw+Lswu4IE/sYZNBBP9f4mIskM rkuXlbKr7mbzvAEOzyn2kigniaCFKnCse0/GobFsH4/e2HCDjaF5s8Kl8 pxOmsOYizsZ6tgFu+QdipCBtGrR1K87xEUwyQy4CGNb/N/kJ0Q5REgjdL 7cGKClkmvnmmoN31NunJdSwvW6xidjfCS+gBSiXOwoCsmTw1xvy6T2+wV PCQyU2vMvo9m7tMSzWs0FIOc6BmA9EZTtb2RH8BXs/OVNhniwerY6U7YR g==; X-IronPort-AV: E=McAfee;i="6400,9594,10310"; a="286586632" X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="286586632" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2022 06:59:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="698190261" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.192.101]) by fmsmga001.fm.intel.com with ESMTP; 08 Apr 2022 06:59:52 -0700 Date: Fri, 8 Apr 2022 21:59:41 +0800 From: Chao Peng To: Sean Christopherson Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, qemu-devel@nongnu.org, Paolo Bonzini , Jonathan Corbet , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H . Peter Anvin" , Hugh Dickins , Jeff Layton , "J . Bruce Fields" , Andrew Morton , Mike Rapoport , Steven Price , "Maciej S . Szmigiero" , Vlastimil Babka , Vishal Annapurve , Yu Zhang , "Kirill A . Shutemov" , luto@kernel.org, jun.nakajima@intel.com, dave.hansen@intel.com, ak@linux.intel.com, david@redhat.com Subject: Re: [PATCH v5 07/13] KVM: Add KVM_EXIT_MEMORY_ERROR exit Message-ID: <20220408135941.GF57095@chaop.bj.intel.com> Reply-To: Chao Peng References: <20220310140911.50924-1-chao.p.peng@linux.intel.com> <20220310140911.50924-8-chao.p.peng@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 28, 2022 at 10:33:37PM +0000, Sean Christopherson wrote: > On Thu, Mar 10, 2022, Chao Peng wrote: > > This new KVM exit allows userspace to handle memory-related errors. It > > indicates an error happens in KVM at guest memory range [gpa, gpa+size). > > The flags includes additional information for userspace to handle the > > error. Currently bit 0 is defined as 'private memory' where '1' > > indicates error happens due to private memory access and '0' indicates > > error happens due to shared memory access. > > > > After private memory is enabled, this new exit will be used for KVM to > > exit to userspace for shared memory <-> private memory conversion in > > memory encryption usage. > > > > In such usage, typically there are two kind of memory conversions: > > - explicit conversion: happens when guest explicitly calls into KVM to > > map a range (as private or shared), KVM then exits to userspace to > > do the map/unmap operations. > > - implicit conversion: happens in KVM page fault handler. > > * if the fault is due to a private memory access then causes a > > userspace exit for a shared->private conversion request when the > > page has not been allocated in the private memory backend. > > * If the fault is due to a shared memory access then causes a > > userspace exit for a private->shared conversion request when the > > page has already been allocated in the private memory backend. > > > > Signed-off-by: Yu Zhang > > Signed-off-by: Chao Peng > > --- > > Documentation/virt/kvm/api.rst | 22 ++++++++++++++++++++++ > > include/uapi/linux/kvm.h | 9 +++++++++ > > 2 files changed, 31 insertions(+) > > > > diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst > > index f76ac598606c..bad550c2212b 100644 > > --- a/Documentation/virt/kvm/api.rst > > +++ b/Documentation/virt/kvm/api.rst > > @@ -6216,6 +6216,28 @@ array field represents return values. The userspace should update the return > > values of SBI call before resuming the VCPU. For more details on RISC-V SBI > > spec refer, https://github.com/riscv/riscv-sbi-doc. > > > > +:: > > + > > + /* KVM_EXIT_MEMORY_ERROR */ > > + struct { > > + #define KVM_MEMORY_EXIT_FLAG_PRIVATE (1 << 0) > > + __u32 flags; > > + __u32 padding; > > + __u64 gpa; > > + __u64 size; > > + } memory; > > +If exit reason is KVM_EXIT_MEMORY_ERROR then it indicates that the VCPU has > > Doh, I'm pretty sure I suggested KVM_EXIT_MEMORY_ERROR. Any objection to using > KVM_EXIT_MEMORY_FAULT instead of KVM_EXIT_MEMORY_ERROR? "ERROR" makes me think > of ECC errors, i.e. uncorrected #MC in x86 land, not more generic "faults". That > would align nicely with -EFAULT. Sure. > > > +encountered a memory error which is not handled by KVM kernel module and > > +userspace may choose to handle it. The 'flags' field indicates the memory > > +properties of the exit. 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E7FEAC433FE for ; Fri, 8 Apr 2022 14:08:00 +0000 (UTC) Received: from localhost ([::1]:54140 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncpHL-0008Pk-Lf for qemu-devel@archiver.kernel.org; Fri, 08 Apr 2022 10:07:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37424) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncp9e-0000aF-QW for qemu-devel@nongnu.org; Fri, 08 Apr 2022 10:00:06 -0400 Received: from mga17.intel.com ([192.55.52.151]:37690) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncp9c-0007kw-MS for qemu-devel@nongnu.org; Fri, 08 Apr 2022 10:00:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649426400; x=1680962400; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=vzRh1a2g1teZIO284W8xK+WsiWROyR/t9wQMFIz6/+E=; b=R+iFzD7Jag2yOhwoTGzbzGq0rNr2cHGyZs2plEFSXOPv7C0+gQBQFc+g B6qU7dI8ubimvLLVM4WxAfPTMzTGAT7z4ni9JFxN+5+3WeCKoFl2QYOh5 5RH7WeCHw/8pKqpvhkDc+zUJuiwD7wdt3Ta7e64mblKvHSd7pJJGOwjEL GjRNHuu6ocnGFCN0CcIjvIuZYe2zkJOHdqAZy48gGR6u42n2cD5LVdwuS SBt/4xAANshNGbjtEWkHpm+3mjW7c+CR6a32ddkOmdDzRoPrCutSKEyIJ IwrrM/Qog9q92f1a7NvxN0E/WOip6d2qYJX6fg3OjZsqpKWuY+dLV2rXN w==; X-IronPort-AV: E=McAfee;i="6400,9594,10310"; a="242191140" X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="242191140" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2022 06:59:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="698190261" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.192.101]) by fmsmga001.fm.intel.com with ESMTP; 08 Apr 2022 06:59:52 -0700 Date: Fri, 8 Apr 2022 21:59:41 +0800 From: Chao Peng To: Sean Christopherson Subject: Re: [PATCH v5 07/13] KVM: Add KVM_EXIT_MEMORY_ERROR exit Message-ID: <20220408135941.GF57095@chaop.bj.intel.com> References: <20220310140911.50924-1-chao.p.peng@linux.intel.com> <20220310140911.50924-8-chao.p.peng@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Received-SPF: none client-ip=192.55.52.151; envelope-from=chao.p.peng@linux.intel.com; helo=mga17.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Chao Peng Cc: Wanpeng Li , jun.nakajima@intel.com, kvm@vger.kernel.org, david@redhat.com, qemu-devel@nongnu.org, "J . Bruce Fields" , linux-mm@kvack.org, "H . Peter Anvin" , ak@linux.intel.com, Jonathan Corbet , Joerg Roedel , x86@kernel.org, Hugh Dickins , Steven Price , Ingo Molnar , "Maciej S . Szmigiero" , Borislav Petkov , luto@kernel.org, Thomas Gleixner , Vitaly Kuznetsov , Vlastimil Babka , Jim Mattson , dave.hansen@intel.com, linux-api@vger.kernel.org, Jeff Layton , linux-kernel@vger.kernel.org, Yu Zhang , "Kirill A . Shutemov" , linux-fsdevel@vger.kernel.org, Paolo Bonzini , Andrew Morton , Vishal Annapurve , Mike Rapoport Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Mon, Mar 28, 2022 at 10:33:37PM +0000, Sean Christopherson wrote: > On Thu, Mar 10, 2022, Chao Peng wrote: > > This new KVM exit allows userspace to handle memory-related errors. It > > indicates an error happens in KVM at guest memory range [gpa, gpa+size). > > The flags includes additional information for userspace to handle the > > error. Currently bit 0 is defined as 'private memory' where '1' > > indicates error happens due to private memory access and '0' indicates > > error happens due to shared memory access. > > > > After private memory is enabled, this new exit will be used for KVM to > > exit to userspace for shared memory <-> private memory conversion in > > memory encryption usage. > > > > In such usage, typically there are two kind of memory conversions: > > - explicit conversion: happens when guest explicitly calls into KVM to > > map a range (as private or shared), KVM then exits to userspace to > > do the map/unmap operations. > > - implicit conversion: happens in KVM page fault handler. > > * if the fault is due to a private memory access then causes a > > userspace exit for a shared->private conversion request when the > > page has not been allocated in the private memory backend. > > * If the fault is due to a shared memory access then causes a > > userspace exit for a private->shared conversion request when the > > page has already been allocated in the private memory backend. > > > > Signed-off-by: Yu Zhang > > Signed-off-by: Chao Peng > > --- > > Documentation/virt/kvm/api.rst | 22 ++++++++++++++++++++++ > > include/uapi/linux/kvm.h | 9 +++++++++ > > 2 files changed, 31 insertions(+) > > > > diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst > > index f76ac598606c..bad550c2212b 100644 > > --- a/Documentation/virt/kvm/api.rst > > +++ b/Documentation/virt/kvm/api.rst > > @@ -6216,6 +6216,28 @@ array field represents return values. The userspace should update the return > > values of SBI call before resuming the VCPU. For more details on RISC-V SBI > > spec refer, https://github.com/riscv/riscv-sbi-doc. > > > > +:: > > + > > + /* KVM_EXIT_MEMORY_ERROR */ > > + struct { > > + #define KVM_MEMORY_EXIT_FLAG_PRIVATE (1 << 0) > > + __u32 flags; > > + __u32 padding; > > + __u64 gpa; > > + __u64 size; > > + } memory; > > +If exit reason is KVM_EXIT_MEMORY_ERROR then it indicates that the VCPU has > > Doh, I'm pretty sure I suggested KVM_EXIT_MEMORY_ERROR. Any objection to using > KVM_EXIT_MEMORY_FAULT instead of KVM_EXIT_MEMORY_ERROR? "ERROR" makes me think > of ECC errors, i.e. uncorrected #MC in x86 land, not more generic "faults". That > would align nicely with -EFAULT. Sure. > > > +encountered a memory error which is not handled by KVM kernel module and > > +userspace may choose to handle it. The 'flags' field indicates the memory > > +properties of the exit.