Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp8613859rwi; Tue, 25 Oct 2022 08:45:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5ncFvv3g1nja4tUvwZeUKKXD5KxKqXG7rMmL/BNrBr0W+XcKeCjfM0pWXAQpBrrw1ILAet X-Received: by 2002:a17:906:30c5:b0:782:707:9e2d with SMTP id b5-20020a17090630c500b0078207079e2dmr32246070ejb.286.1666712729428; Tue, 25 Oct 2022 08:45:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666712729; cv=none; d=google.com; s=arc-20160816; b=oZfEnr5o9WGCRGXG8XgMSm7T9Lsst6AsIhkLiJpp+zWoRkzuWfT+7ytR46Ag2HWrtP Ld+mWGRWu2OU7JhguY+8En2gOSl8nq6XhrcxdxBMlRKIY2BwHPSVVAjc9tt9rsJLuUbX sCzfTRlCoIYtGsRfD8JaB4CqQydR8sg7zZe4GNlhs/osJJhDPbslbz/XatByZRF+4mgp qG3v9Y3PLZALIbxbWQkb2cPpuQG4Ewk/NGhF2QQ2FeZ52pjkqi4oKh0MDjork44TFHQI efOCjEfVgxwUhxDHG/NmLjL6WZSaEt7krgTQEAGaHRPBZqZYTG7aWFvYngHfGnYrnXKa E6cw== 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=f0Fk+0/Amw7nskzxgUFtOOx5Md+yUa8AJYsojRyR41E=; b=Pleb8a6Ly+xxcS9ebVvM0U4mxwgY381IpXAdSj38e9UOG2KV+IijtFDks7kVAxTxrP o2wwXY8jv0PlEFA6iWTRn2TYJelPGPAnv0wf7A4z+JV8BG60cnqHTFinkNBVbZgY7KEv 4ORfEdyrhom3EvhABuboQA+U5SZt53KgFYvNoH19VHFn+dIlqOrAj82jtpmADRAaX/YV Hr3JDri97kvKk5oxq3DsUo+BSWifAuFihA9cezBgTlxyYooSQhkfbshKAuuop4+b2GkP SeNL7PuhcxZzlpnl4m0PblwLuJfej1YVhtzHf8nyuqCKugD+Ceb83je+87EHg2+MkHkK vr+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=at2Vihq0; 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=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n12-20020a05640205cc00b00461a4eb674dsi3948912edx.619.2022.10.25.08.45.02; Tue, 25 Oct 2022 08:45:29 -0700 (PDT) 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=@linaro.org header.s=google header.b=at2Vihq0; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233141AbiJYP0i (ORCPT + 99 others); Tue, 25 Oct 2022 11:26:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233002AbiJYP0d (ORCPT ); Tue, 25 Oct 2022 11:26:33 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C495C3C8DC for ; Tue, 25 Oct 2022 08:26:30 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id f9so7392404pgj.2 for ; Tue, 25 Oct 2022 08:26:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=f0Fk+0/Amw7nskzxgUFtOOx5Md+yUa8AJYsojRyR41E=; b=at2Vihq0ZysdnRIAuOMyqUBdq1/FFvX63hDc58gBWKAYTaAmkdYraFO/pRcQUDSDYE 0fkDw3uZaS0h9nyoTmESSO/FjPD1QqpECPNASv+D/6l+zaxAf+VJn/1HbEpmn5RksRqM Kzp2cehpcT91+FjF962CIIiyPLseroHnn8m58E8xAwNn8/VzQz0SjVNwnMGfPlyntwWG 1v+JEBR3ZSQGmfEMYXT1afvMpcQP3UQ/MndzyKc736Oi9OUW1NIyDDMvB7aFBM+fsgL1 HkgjZvE5tmNi+7E1mPJH+qwH0v1PNDsMYQONw16TaTIl5SmDaOKIjaZzxn0BT619gx8g +GOw== 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=f0Fk+0/Amw7nskzxgUFtOOx5Md+yUa8AJYsojRyR41E=; b=WD8qMDRWver1NdPy11WjCP0oMN7Cv8l62gvUMAsKNE1qSJpecxMTJTHIn1mGoUgppS I4kZMlsUzmVZbl/1i5xvff5A78I2D6ARmIMEwXaOVX/s4//xFaf7pjNC99RYnES0Wb/C 5NTYUgrkatpSeQ57tqjFUuBDedpNZVEvoSgnQhS7lsyboM5gV4VB+IJSSH7nJBhKq1QB fS6Df98L4tmImK6L1/0WI6atILybglo8+7qXVtWpjxZG9Jg3SuFsQJwNz2y2zWkCH4WY kBj6+MkvQfJmR0SHfyaGMWIdYJHuzJwNGGZyhqEmjCl1DlXNDksCF9miWUyYHH+l7aJO 9tsw== X-Gm-Message-State: ACrzQf1aovF3CiHF53eeFrb7gDZcJDArGQ/Y0tBu9i1APyOsoRtsoYRI BEpychmXvnwAclePGmeV+Jd1okWBSc/FJH/ZOTQ4jw== X-Received: by 2002:a63:1d5a:0:b0:46e:d157:39ef with SMTP id d26-20020a631d5a000000b0046ed15739efmr17120402pgm.231.1666711590299; Tue, 25 Oct 2022 08:26:30 -0700 (PDT) MIME-Version: 1.0 References: <20221025151344.3784230-1-chao.p.peng@linux.intel.com> <20221025151344.3784230-4-chao.p.peng@linux.intel.com> In-Reply-To: <20221025151344.3784230-4-chao.p.peng@linux.intel.com> From: Peter Maydell Date: Tue, 25 Oct 2022 16:26:18 +0100 Message-ID: Subject: Re: [PATCH v9 3/8] 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 , 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 , tabba@google.com, Michael Roth , mhocko@suse.com, Muchun Song , wei.w.wang@intel.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 On Tue, 25 Oct 2022 at 16:21, 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; > + > +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. > + What's the difference between this and a plain old MMIO exit ? Just that we can specify a wider size and some flags ? -- PMM