Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7615229rwb; Tue, 6 Dec 2022 07:53:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf7QWp6ZouYpGu9Fbedg1ogR25guzpyyoZF0t30iuhy/FQnVqIFa0/NxuwIpfFvBURE2nYFy X-Received: by 2002:aa7:ce8d:0:b0:46c:e010:acb2 with SMTP id y13-20020aa7ce8d000000b0046ce010acb2mr6257601edv.415.1670342032500; Tue, 06 Dec 2022 07:53:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670342032; cv=none; d=google.com; s=arc-20160816; b=pAUL2fUhmh6nWXLxW6cJqZb8YWdTvxc8+ybV0Lha6ciCsw8y3x4HgPkFD4vqBzi9/B TzDM+geYEcGhEYwTcDwsZePne1yfUzY8bMOvauXbyfa0zfZGHygAkQvjxuvfFTF/W603 jCKifxgYIAgBjDNHk9TAWTayC5oQxBQ7P5CKX3ZG7s1JHRryKjSZwrjvgWegNjPJ1Kza Kj3mgQg6xVz+jPY0aU1F10Kazmg6k7KttHkn611XwPWKobtbGz0zoh1mPy5BIzUTLHZ5 o2wl00hcbGdG9MlycPjjqrcCygxci41UqtDuVBzCKTrDQb+1dWMM9Xre4w3UsMPMoU+3 lD0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=m1kCqWlRYfobNKnwTTmG2lD4ZIH0ubVAosfgV6W3Dk4=; b=Yfi4FTcYBFmk69oHM2M6yhJcu9MYpbIOpMbfBYwaeqVw+I2jqYr2xngDINFJNe0uE1 u5Ha72dV4yL5qMAXrH1FqiKcmtAJlF9uzZUuS7CqZjuiW+Jpo5jvKFjRyK5A7pviSKb3 nxsKGGhy72ZodKP3K8ff2/bQQBJzPDrOmX8RfeJeJXy/ZQigDrlQB980fQi3JfgdUr5M p5t+TZ5zzwU36IuQr96OcBNhA+EtVlknKqQizIDchRcSkoIyX7rDtkH2NWDV/ctSAldX eMzqwGXRTgRLeomJOeGjR4IO6YIdCYpBuQNLmnZjOZGSPrhwTRU9EWd0Q1j1KSYwRKeK ScIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=km4nt3h3; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c6-20020a056402100600b00461540620f1si1940541edu.169.2022.12.06.07.53.32; Tue, 06 Dec 2022 07:53:52 -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=@google.com header.s=20210112 header.b=km4nt3h3; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232135AbiLFPsV (ORCPT + 79 others); Tue, 6 Dec 2022 10:48:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232099AbiLFPsC (ORCPT ); Tue, 6 Dec 2022 10:48:02 -0500 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39891E086 for ; Tue, 6 Dec 2022 07:47:59 -0800 (PST) Received: by mail-lj1-x22d.google.com with SMTP id l8so17651218ljh.13 for ; Tue, 06 Dec 2022 07:47:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=m1kCqWlRYfobNKnwTTmG2lD4ZIH0ubVAosfgV6W3Dk4=; b=km4nt3h3SHb/kEB2LuEUazieUkF9KftHb5F5G6SyTF0tkPyKfN2VeOikiWxEBRycBp HsbvpDP5MQFX5lKttQgca1p57UvCAGjzgI85ey19QT3BdjKfqI9Cvl6Wv6b4IRjUUGio SNCBKhia8UVi2JEXoKNgW6LJLeJ34+7z8/13c3LqbFAKDJMO8Gy/+VyTLMrA7AhhENd1 TNOqx+MF6+0Q7sMMqfp/4fXIA6AYYQUMyiQMrZUKrOwSlFwEERF41f5MgnrniS4C+Zx7 aT0+T5Mh7IQLLskdVC1oVbKnMT2sukhYGiYH6rQJUVqDRrBUtxo2Y0A4TZ8KfOE3PyHH RKTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=m1kCqWlRYfobNKnwTTmG2lD4ZIH0ubVAosfgV6W3Dk4=; b=mrwxHqAi2rgtxeW52wI5+3LVRiHNQc97QJw1b0wyHg9IQSguRigElRswpnqfH9v19k xX6/lucf44HHErlu7KLoainuADySMsbfVvnGJ9LYk/jsEyGrcCa//Jd82xvus/oW3hUI WEmyqM+2GHNlaFQwB+cEoDJbtIjOrZHNOzkoRPZJH+IdJuMs0+PxlSbAQhbzMqLMTqKM MqD7ZlEyIbcF4xXuagNFTf4qeH0DDu+WqTuLMsi9HSxl06rLElwucYJTXIJom/psZX42 dsYTbHejFyb0CFTrwLttqsRpHV6ZJzdQ3Ey6Kn3pYulH49dQH9KGsin826ejgvhKnd1a 3VOg== X-Gm-Message-State: ANoB5pn32QzQh3c5FIFaLaydmWmaD+J01ylc3NEM1aGalxoW4S4LZQYj PxjNSQdpK1qmn5ioargA0yW/Zoa19fgVZdWkh95LcQ== X-Received: by 2002:a2e:a80d:0:b0:277:1295:31ca with SMTP id l13-20020a2ea80d000000b00277129531camr27009331ljq.280.1670341677228; Tue, 06 Dec 2022 07:47:57 -0800 (PST) MIME-Version: 1.0 References: <20221202061347.1070246-1-chao.p.peng@linux.intel.com> <20221202061347.1070246-5-chao.p.peng@linux.intel.com> In-Reply-To: <20221202061347.1070246-5-chao.p.peng@linux.intel.com> From: Fuad Tabba Date: Tue, 6 Dec 2022 15:47:20 +0000 Message-ID: Subject: Re: [PATCH v10 4/9] KVM: Add KVM_EXIT_MEMORY_FAULT exit To: Chao Peng Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, qemu-devel@nongnu.org, Paolo Bonzini , Jonathan Corbet , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Arnd Bergmann , Naoya Horiguchi , Miaohe Lin , x86@kernel.org, "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" , luto@kernel.org, jun.nakajima@intel.com, dave.hansen@intel.com, ak@linux.intel.com, david@redhat.com, aarcange@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, Quentin Perret , Michael Roth , mhocko@suse.com, wei.w.wang@intel.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 Hi, On Fri, Dec 2, 2022 at 6:19 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 > Reviewed-by: Fuad Tabba > --- > Documentation/virt/kvm/api.rst | 22 ++++++++++++++++++++++ > include/uapi/linux/kvm.h | 8 ++++++++ > 2 files changed, 30 insertions(+) > > diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst > index 99352170c130..d9edb14ce30b 100644 > --- a/Documentation/virt/kvm/api.rst > +++ b/Documentation/virt/kvm/api.rst > @@ -6634,6 +6634,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_FAULT */ > + struct { > + #define KVM_MEMORY_EXIT_FLAG_PRIVATE (1ULL << 0) > + __u64 flags; I see you've removed the padding and increased the flag size. Reviewed-by: Fuad Tabba Tested-by: Fuad Tabba Cheers, /fuad > + __u64 gpa; > + __u64 size; > + } memory; > + > +If exit reason is KVM_EXIT_MEMORY_FAULT then it indicates that the VCPU has > +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. > + > + - KVM_MEMORY_EXIT_FLAG_PRIVATE - indicates the memory error is caused by > + private memory access when the bit is set. Otherwise the memory error is > + caused by shared memory access when the bit is clear. > + > +'gpa' and 'size' indicate the memory range the error occurs at. The userspace > +may handle the error and return to KVM to retry the previous memory access. > + > :: > > /* KVM_EXIT_NOTIFY */ > diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h > index 13bff963b8b0..c7e9d375a902 100644 > --- a/include/uapi/linux/kvm.h > +++ b/include/uapi/linux/kvm.h > @@ -300,6 +300,7 @@ struct kvm_xen_exit { > #define KVM_EXIT_RISCV_SBI 35 > #define KVM_EXIT_RISCV_CSR 36 > #define KVM_EXIT_NOTIFY 37 > +#define KVM_EXIT_MEMORY_FAULT 38 > > /* For KVM_EXIT_INTERNAL_ERROR */ > /* Emulate instruction failed. */ > @@ -541,6 +542,13 @@ struct kvm_run { > #define KVM_NOTIFY_CONTEXT_INVALID (1 << 0) > __u32 flags; > } notify; > + /* KVM_EXIT_MEMORY_FAULT */ > + struct { > +#define KVM_MEMORY_EXIT_FLAG_PRIVATE (1ULL << 0) > + __u64 flags; > + __u64 gpa; > + __u64 size; > + } memory; > /* Fix the size of the union. */ > char padding[256]; > }; > -- > 2.25.1 >