Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp3029677rdb; Fri, 22 Sep 2023 16:12:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFdhJLJVxC+i7jyixHrP1oFAejW/MlupMXogUHFjP+eHtYR3IT5lQERta3Vnu9A5fNzx/7h X-Received: by 2002:a05:6a20:13d3:b0:155:2359:e28c with SMTP id ho19-20020a056a2013d300b001552359e28cmr944689pzc.9.1695424339399; Fri, 22 Sep 2023 16:12:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695424339; cv=none; d=google.com; s=arc-20160816; b=lRqNgfMKZXyGAdwdOvnLrgz1mkU22F3SoXbjksvXyW0gukII43P783hDfcel5iICsm KKFNx4CO5JdL9NdY/9UFbS6Bu8ILFWDR3nATRmtabFV1tohTW+XXaSqvWFMifWpQgKZQ x9Zy33DY4qqKhk3q2OqAv0oJsDAQVzM4A+3sISecYSQZB6ntUQuW35MZ8wdRKMXN8NXF rXKUa9AQWHQbexbHDl3pqu2hRv37JzcmF0phVMgXC1aLDWec0slvAGuPo5IgqPiIKJRG d0dSWxlfq4ATtKeudjw54fkmP9V0K/4mHs50T8bErvAvwtjnqARky+ytlncxMN5N4W1r oruQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=KA5pwz3/DRQHr6a2ee4M3bjnbEYA57TwsoBM67hI6zU=; fh=+GvPm/ki8yAAaqSOkWAptP3/weZWiFxCw1IGyFkLobM=; b=e6ey0XhCG4F9Wn/P/LTZyr8mV7Kt2IX6qCcqyMgJlwON5OT8JQFnsu2nYIdXRYQ0Zc jMJxJT5v4K4fYHcsxYz3v+T2RQ1q9C/04BU+VCfNmNQrEMjl9BojxFpJaU6OAah+M6fb kKk4cuwvzL/GOSxTHx2j8DSCi0LmZzCtYjnTwA0ju3/f3rG39CBY8tePeM3wTFcqGH3K uqeZNu6j4fgWICQ7KXK5J4va7SgGWgorVv1EnucoXT6kAa9DcfgvaKPAi0IiImRPNmLv E/e2hcPQ/xLkhHLu2Q185K79hfaicqk2hHUcA6cQG5Vq9EJ3oIeiEgkl8gJCD6WjODKu cilA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KasGxCGh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id s11-20020a170903200b00b001b886a0c366si4190320pla.122.2023.09.22.16.12.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 16:12:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KasGxCGh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id E691C83033A6; Fri, 22 Sep 2023 07:31:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229862AbjIVOas (ORCPT + 99 others); Fri, 22 Sep 2023 10:30:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229623AbjIVOaq (ORCPT ); Fri, 22 Sep 2023 10:30:46 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50ABF180 for ; Fri, 22 Sep 2023 07:30:40 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1c40ac5b6e7so17775045ad.0 for ; Fri, 22 Sep 2023 07:30:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695393040; x=1695997840; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=KA5pwz3/DRQHr6a2ee4M3bjnbEYA57TwsoBM67hI6zU=; b=KasGxCGhlZLETJKdrWXwCt6Sdf48q70UTGzJbwZWC64s/HsrhafPEns5rIOCSmMzCF Z5vslQF3uqwntveLyJRT9X55sm2SN9LTyROw1FjsOmgBxDplUWBzYf6ax3BA5UjL4ELb YJsPknZYvqdQlxlzPz5zEqhGnX9Tu6BG6ioY3BFN0N3mSdjWPjyuvkUiP6pxEe6NnfWJ PLkmtSJXOkV0KCojJ/JCp+rGSD8krrci1aKN7jafsYbX+RWwpM95HeeOfmLnmkf1PMs0 7NxA3aqKWL8UbhrNt+pus28C2KMT02kQ3ra3JKNW0AJ2IeAxWRuxOn4ft3DclAvaZpdM jwSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695393040; x=1695997840; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KA5pwz3/DRQHr6a2ee4M3bjnbEYA57TwsoBM67hI6zU=; b=sKnHLIADyoTBAbdtrHg/FhjcAPDriEAgiu+HYX+K+k7DLo1XJwgaxQvX/HvNboMl8a HGMypbKF5u+aYq8I7CDh7LmB+FnuHSOM69fHTYXMw7vM9axUw7+RYnPdLmdz+8M6NQF5 jns7rJ3EXDvrc+Lphuhh0baW2Xw9How3u8MRZbHd4sklE9V1hZItyh2gtR2ExZhhdLKG 0C34rmm/lRCGDoiBhG64A6rAmUMIyLAMnwxyxKqoNFVD2N0UzM+HuV3oq6A7mWr6kVe0 pJMdZ+/kiq7H1adfiWJVUX041Mvab3ltrV4TTojt2I7XqnHt0DRJIf3jC70XeFiDcfIf j8kg== X-Gm-Message-State: AOJu0Yy2J3CGXJIr5e8U1O6+zVSJDGxtAD7E84O49TqG0e2RO6gnCXWm d8sTsnYx+ybgpk1uqKbudm3CL6XC4gw= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:903:1cf:b0:1b9:df8f:888c with SMTP id e15-20020a17090301cf00b001b9df8f888cmr102903plh.8.1695393039713; Fri, 22 Sep 2023 07:30:39 -0700 (PDT) Date: Fri, 22 Sep 2023 07:30:38 -0700 In-Reply-To: <117db856-9aec-e91c-b1d4-db2b90ae563d@intel.com> Mime-Version: 1.0 References: <20230914015531.1419405-1-seanjc@google.com> <20230914015531.1419405-8-seanjc@google.com> <117db856-9aec-e91c-b1d4-db2b90ae563d@intel.com> Message-ID: Subject: Re: [RFC PATCH v12 07/33] KVM: Add KVM_EXIT_MEMORY_FAULT exit to report faults to userspace From: Sean Christopherson To: Xiaoyao Li Cc: Paolo Bonzini , Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , "Matthew Wilcox (Oracle)" , Andrew Morton , Paul Moore , James Morris , "Serge E. Hallyn" , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Chao Peng , Fuad Tabba , Jarkko Sakkinen , Anish Moorthy , Yu Zhang , Isaku Yamahata , Xu Yilun , Vlastimil Babka , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 22 Sep 2023 07:31:20 -0700 (PDT) On Fri, Sep 22, 2023, Xiaoyao Li wrote: > On 9/14/2023 9:55 AM, Sean Christopherson wrote: > > From: Chao Peng > > > > Add a new KVM exit type to allow userspace to handle memory faults that > > KVM cannot resolve, but that userspace *may* be able to handle (without > > terminating the guest). > > > > KVM will initially use KVM_EXIT_MEMORY_FAULT to report implicit > > conversions between private and shared memory. With guest private memory, > > there will be two kind of memory conversions: > > > > - explicit conversion: happens when the guest explicitly calls into KVM > > to map a range (as private or shared) > > > > - implicit conversion: happens when the guest attempts to access a gfn > > that is configured in the "wrong" state (private vs. shared) > > > > On x86 (first architecture to support guest private memory), explicit > > conversions will be reported via KVM_EXIT_HYPERCALL+KVM_HC_MAP_GPA_RANGE, > > side topic. > > Do we expect to integrate TDVMCALL(MAPGPA) of TDX into KVM_HC_MAP_GPA_RANGE? Yes, that's my expectation. > > but reporting KVM_EXIT_HYPERCALL for implicit conversions is undesriable > > as there is (obviously) no hypercall, and there is no guarantee that the > > guest actually intends to convert between private and shared, i.e. what > > KVM thinks is an implicit conversion "request" could actually be the > > result of a guest code bug. > > > > KVM_EXIT_MEMORY_FAULT will be used to report memory faults that appear to > > be implicit conversions. > > > > Place "struct memory_fault" in a second anonymous union so that filling > > memory_fault doesn't clobber state from other yet-to-be-fulfilled exits, > > and to provide additional information if KVM does NOT ultimately exit to > > userspace with KVM_EXIT_MEMORY_FAULT, e.g. if KVM suppresses (or worse, > > loses) the exit, as KVM often suppresses exits for memory failures that > > occur when accessing paravirt data structures. The initial usage for > > private memory will be all-or-nothing, but other features such as the > > proposed "userfault on missing mappings" support will use > > KVM_EXIT_MEMORY_FAULT for potentially _all_ guest memory accesses, i.e. > > will run afoul of KVM's various quirks. > > So when exit reason is KVM_EXIT_MEMORY_FAULT, how can we tell which field in > the first union is valid? > > When exit reason is not KVM_EXIT_MEMORY_FAULT, how can we know the info in > the second union run.memory is valid without a run.memory.valid field? I'll respond to this separately with a trimmed Cc list. I suspect this will be a rather lengthy conversation, and it has almost nothing to do with guest_memfd. > > +Note! KVM_EXIT_MEMORY_FAULT is unique among all KVM exit reasons in that it > > +accompanies a return code of '-1', not '0'! errno will always be set to EFAULT > > +or EHWPOISON when KVM exits with KVM_EXIT_MEMORY_FAULT, userspace should assume > > +kvm_run.exit_reason is stale/undefined for all other error numbers. > > + > > Initially, this section is the copy of struct kvm_run and had comments for > each field accordingly. Unfortunately, the consistence has not been well > maintained during the new filed being added. > > Do we expect to fix it? AFAIK, no one is working on cleaning up this section of the docs, but as always, patches are welcome :-)