Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1017185rwb; Wed, 16 Nov 2022 10:44:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf41DN1N7LoylNj3JZ6kFlfUWXlS9BHH3lp0LzUPpK95SMbd531tBfb+Eu29si6KlFbnhFMx X-Received: by 2002:a05:6402:653:b0:458:7758:7ed1 with SMTP id u19-20020a056402065300b0045877587ed1mr19593017edx.315.1668624243012; Wed, 16 Nov 2022 10:44:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668624243; cv=none; d=google.com; s=arc-20160816; b=P3EjCCnVEsihbWy9NaEQEfn3F+Tuyi2lKFe1LLTwix5CRmJPb7gLKyEIix/Hu0PtRA UF/nfbEDqBY0OtdDbzDzAWrVZnsu1yC8jGoM6KtANMK6b1xaL/I/K8mssV1PqQcplgjp l06zK32aG3FEs/VITwH2qUkdn82x7NKTnPq/MZ6DgfHqAi7s4ImZEOkS5UcIya0syuDF V7aE/QcvRmZpY+Q3XZKP24zTOxaQcAL11RG7rxIcbyBW6qtn5d36RoD0IxzuESdfXeqR UinsUDnkmVPPtozlynAaDQkbJLpQRiltOyTb0l0RNBVAgna2k0TvDm8D4J3hmJcbhJBQ 5//A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:references:in-reply-to :message-id:mime-version:user-agent:feedback-id:dkim-signature; bh=b5dTEfUA5K9hb7HFOsVJe59yS6OLXbe1GvgWoyoKR/4=; b=vaQQ5AmyATBTtYdpPB3VQ5w2IWneug9nGKaha/G9FQRGnB3zToPa6HY1cNo8PafuOk xMrS8oSO8AmlsBvx01VtwXkAXlnHMPeAXlpVJPnz9V7F/QlCq2uI7kBdC6iKqKW5EUu6 ghXDJw8nOZKIBn2i9oA4ihVhE//NeHcNRepYXbaEk/ZvTSlYy9pD/ThytKJRhKfDwDrE qrtL3KlowzS0O4dPo40jxTn8N4Omq8PFROLnoFus35PaE/F1drLEhQzcY4ZLYIm/cY3H D04xMChZBqALuAcyZsvCFWSoGxMOIMfWlS/pW97nnZ+2Rx6sNZc6enYdtKkV3skzTEvB +Uxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TbmnRT02; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i36-20020a0564020f2400b00447d6f244c6si15048246eda.248.2022.11.16.10.43.41; Wed, 16 Nov 2022 10:44:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TbmnRT02; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238534AbiKPSQQ (ORCPT + 90 others); Wed, 16 Nov 2022 13:16:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233202AbiKPSQL (ORCPT ); Wed, 16 Nov 2022 13:16:11 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE75E6315C; Wed, 16 Nov 2022 10:16:10 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5831161CED; Wed, 16 Nov 2022 18:16:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B9A6C433B5; Wed, 16 Nov 2022 18:16:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668622569; bh=HzuBDu3c95vDubumkqmlUpDyU7sgxHKyh2YYcB7elbo=; h=In-Reply-To:References:Date:From:To:Cc:Subject:From; b=TbmnRT02WifHTxhTrt1S3QFCyS10+Ny8syMNvxDvCWtyKPfr7LxVjdR8fA+mn6x8K TsqHlf93e0eTek76c8sWRQJ/Q0wTsu7zLYhedhBDN+ZnKJEJv5cvOf4FfQn8h0fvl4 /jjXz3QpsD70FN6lVPept8h//e/SZAqJlXfr+BkgivEFfgUDYnlO34jr+hOieTfrxk t+EXIu5KUxj69jixwFESCcWu726SGo8juE7CfEqbzz6Pu9Xl21jTZ6gR1r4345b1eQ VwMnJ+2Is2wAe2rHopq09K1eS+AVjQRkSa87F6KrzUaYFz9TTDZmv22MRmAFfWJwzM jOh2TpPLVa4LA== Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id 6393627C0054; Wed, 16 Nov 2022 13:16:07 -0500 (EST) Received: from imap48 ([10.202.2.98]) by compute2.internal (MEProxy); Wed, 16 Nov 2022 13:16:07 -0500 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrgeeigdduuddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtsehttdertderredtnecuhfhrohhmpedftehn ugihucfnuhhtohhmihhrshhkihdfuceolhhuthhosehkvghrnhgvlhdrohhrgheqnecugg ftrfgrthhtvghrnhepgedugedtledtieduteffveevhfefheeuhfegfeduvdeltdeugeet veeliedvfeehnecuffhomhgrihhnpehgihhthhhusgdrtghomhenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrnhguhidomhgvshhmthhprghu thhhphgvrhhsohhnrghlihhthidqudduiedukeehieefvddqvdeifeduieeitdekqdhluh htoheppehkvghrnhgvlhdrohhrgheslhhinhhugidrlhhuthhordhush X-ME-Proxy: Feedback-ID: ieff94742:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 4E7E831A0063; Wed, 16 Nov 2022 13:16:05 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-1115-g8b801eadce-fm-20221102.001-g8b801ead Mime-Version: 1.0 Message-Id: <2e252f4f-7d45-42ac-a88f-fa8045fe3748@app.fastmail.com> In-Reply-To: <20221025151344.3784230-4-chao.p.peng@linux.intel.com> References: <20221025151344.3784230-1-chao.p.peng@linux.intel.com> <20221025151344.3784230-4-chao.p.peng@linux.intel.com> Date: Wed, 16 Nov 2022 10:15:44 -0800 From: "Andy Lutomirski" To: "Chao Peng" , "kvm list" , "Linux Kernel Mailing List" , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, "Linux API" , linux-doc@vger.kernel.org, qemu-devel@nongnu.org Cc: "Paolo Bonzini" , "Jonathan Corbet" , "Sean Christopherson" , "Vitaly Kuznetsov" , "Wanpeng Li" , "Jim Mattson" , "Joerg Roedel" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "the arch/x86 maintainers" , "H. Peter Anvin" , "Hugh Dickins" , "Jeff Layton" , "J . Bruce Fields" , "Andrew Morton" , "Shuah Khan" , "Mike Rapoport" , "Steven Price" , "Maciej S . Szmigiero" , "Vlastimil Babka" , "Vishal Annapurve" , "Yu Zhang" , "Kirill A. Shutemov" , "Nakajima, Jun" , "Dave Hansen" , "Andi Kleen" , "David Hildenbrand" , aarcange@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, "Quentin Perret" , "Fuad Tabba" , "Michael Roth" , "Michal Hocko" , "Muchun Song" , "Wei W Wang" Subject: Re: [PATCH v9 3/8] KVM: Add KVM_EXIT_MEMORY_FAULT exit Content-Type: text/plain X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 25, 2022, at 8:13 AM, 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. > > When private memory is enabled, this new exit will be used for KVM to > exit to userspace for shared <-> 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 perform the map/unmap operations. > - implicit conversion: happens in KVM page fault handler where KVM > exits to userspace for an implicit conversion when the page is in a > different state than requested (private or shared). > > Suggested-by: Sean Christopherson > Co-developed-by: Yu Zhang > Signed-off-by: Yu Zhang > Signed-off-by: Chao Peng > --- > Documentation/virt/kvm/api.rst | 23 +++++++++++++++++++++++ > include/uapi/linux/kvm.h | 9 +++++++++ > 2 files changed, 32 insertions(+) > > diff --git a/Documentation/virt/kvm/api.rst > b/Documentation/virt/kvm/api.rst > index f3fa75649a78..975688912b8c 100644 > --- a/Documentation/virt/kvm/api.rst > +++ b/Documentation/virt/kvm/api.rst > @@ -6537,6 +6537,29 @@ 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_FAULT */ > + struct { > + #define KVM_MEMORY_EXIT_FLAG_PRIVATE (1 << 0) > + __u32 flags; > + __u32 padding; > + __u64 gpa; > + __u64 size; > + } memory; > + Would it make sense to also have a field for the access type (read, write, execute, etc)? I realize that shared <-> private conversion doesn't strictly need this, but it seems like it could be useful for logging failures and also for avoiding a second immediate fault if the type gets converted but doesn't have the right protection yet. (Obviously, if this were changed, KVM would need the ability to report that it doesn't actually know the mode.) --Andy