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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7B73FA3740 for ; Tue, 25 Oct 2022 15:26:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6A0FD8E0003; Tue, 25 Oct 2022 11:26:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 629958E0001; Tue, 25 Oct 2022 11:26:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4CAD78E0003; Tue, 25 Oct 2022 11:26:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 3DC338E0001 for ; Tue, 25 Oct 2022 11:26:32 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 0C0E21A0C90 for ; Tue, 25 Oct 2022 15:26:31 +0000 (UTC) X-FDA: 80059848624.20.8D50586 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf04.hostedemail.com (Postfix) with ESMTP id 6C84D40038 for ; Tue, 25 Oct 2022 15:26:31 +0000 (UTC) Received: by mail-pg1-f176.google.com with SMTP id f9so7392407pgj.2 for ; Tue, 25 Oct 2022 08:26:31 -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=jQ3KzvetJmfFUlwNXloXv52NTTq27mtQSTT7XVGTIlvvwh7zfFfRag4/tmjLtjIrWp Ki4oEfL1v36BtVgI7KmpHEoSAXrshCE9aRLSHBcDl67shAsvgg5fuzjSQMfsX0BzhOeF lslrPGfTE3w0tLKtauI8NPvSU/N+LJ7+wFLIQNuaxP+bp8KdoCrXIjQ34eUet6DkNStZ ZucB9OBz3zXu7Qbp5HbuA/7oaQSzjrS0Ovf5ZBbGv3XOM2r7DktqFX5BQ+gJ21cDqOkg X6vWTpDyb/1gy3cKn3/0hQrjZyT7FSTevTjDoHDXaQuqyi7EEe58V69KmECt+o79z/2V DIxg== X-Gm-Message-State: ACrzQf3TvgPEO3gdPp8T9RHNab/c0nLH3M6w9NBwyh99kz1hhaKpq1L0 Uu3d/GW3J3jqHhrtk+1LuAOD4nvlYFDlekfV+eBjWA== X-Google-Smtp-Source: AMsMyM7S5IISqnVExEMx/Y/NdDoxoi+mPZLZks2JQtwFF+Q9Vn8DzGWDrBRBdHkSKruNqn9cxFFTv641nHc01V+gClk= 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" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666711591; a=rsa-sha256; cv=none; b=Jxd4NGV78tU+9J79hm/J2SkvMpNZHVE7gPeqQB81RQ/+sJDmVj3Lj1skQaMo3NhZz9PvbM KCz8xQ9IsOgKaQf4AXTmnizz8P6z7lNJyNP5xqs0kuAOL3ZzcK8Orr0Bj7jgX6HniXtdUl MEp8AUj5IkjQODrV0fIgxgoHgHw0FRU= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=at2Vihq0; spf=pass (imf04.hostedemail.com: domain of peter.maydell@linaro.org designates 209.85.215.176 as permitted sender) smtp.mailfrom=peter.maydell@linaro.org; dmarc=pass (policy=none) header.from=linaro.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666711591; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=f0Fk+0/Amw7nskzxgUFtOOx5Md+yUa8AJYsojRyR41E=; b=kX4x2uguzvdPNY9cXmRDycjN6WlNPunVDbSkdA6H52ta/NsXBLt6Z11tkaHjjeOcqLeyNf 4N2bi6ITFdlv814PN3d6yYRvDacXp9u07rngeKZ10hHfyuB2tMrcWj32G+OHbFg87LvSpt +VqP7+nTk2pIgjEhPNrcsx9JRUu4OkM= X-Rspam-User: X-Rspamd-Queue-Id: 6C84D40038 Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=at2Vihq0; spf=pass (imf04.hostedemail.com: domain of peter.maydell@linaro.org designates 209.85.215.176 as permitted sender) smtp.mailfrom=peter.maydell@linaro.org; dmarc=pass (policy=none) header.from=linaro.org X-Stat-Signature: auftcdrqp4tz1kg7xkfamuoa9wc1xm5o X-Rspamd-Server: rspam03 X-HE-Tag: 1666711591-854288 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 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