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 2F3F9E6FE3B for ; Fri, 22 Sep 2023 14:30:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7D3C56B02E2; Fri, 22 Sep 2023 10:30:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 75C216B02E3; Fri, 22 Sep 2023 10:30:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D5B46B02E4; Fri, 22 Sep 2023 10:30:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 49A806B02E2 for ; Fri, 22 Sep 2023 10:30:43 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 12768A09DD for ; Fri, 22 Sep 2023 14:30:43 +0000 (UTC) X-FDA: 81264469566.29.BCF2623 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf25.hostedemail.com (Postfix) with ESMTP id 2A0FAA002D for ; Fri, 22 Sep 2023 14:30:40 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=otoi0oO8; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf25.hostedemail.com: domain of 3D6UNZQYKCL4wierngksskpi.gsqpmry1-qqozego.svk@flex--seanjc.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3D6UNZQYKCL4wierngksskpi.gsqpmry1-qqozego.svk@flex--seanjc.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695393041; 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=KA5pwz3/DRQHr6a2ee4M3bjnbEYA57TwsoBM67hI6zU=; b=FUMFMEUSoFr0o8ModZ3p6iJDIjg+A21t1t55pHlBo78bJVn5/nlFgPPwTq2zPUO94K9I9J N1wEi91yeIQrbs2sBgwILqzzDlva66kYnvKfzQ65Ke+6p+/0OuwsnxTcfMYbblpHni0Df2 pK4zc1zWsSVR0/c2pjo7bOhBJXLmGug= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=otoi0oO8; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf25.hostedemail.com: domain of 3D6UNZQYKCL4wierngksskpi.gsqpmry1-qqozego.svk@flex--seanjc.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3D6UNZQYKCL4wierngksskpi.gsqpmry1-qqozego.svk@flex--seanjc.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695393041; a=rsa-sha256; cv=none; b=UFonXcUiG7Vkd2V51UiraA4Ie7kOrl9Ar8U9dZX7llzVecEJ3+DQpLJlEaLuFpiCqgL8mA 7mcNUgTJkmfaFG7l79RrhHDmdqB218flgErovkHlUzqITCsumprLLCoJLI6xlCzt8mpnZ+ 4O6S4eWK2xuqE41UtuniQk2W7qb8oSw= Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-1c5b1e55d5eso17608015ad.3 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=kvack.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=otoi0oO8MjmYrvt3OMp1rutlDhsjfL4ywovr+0KpsF+WLml8zPpTIvrM5WTOF+KS0w YUTS7NRxwJWYoX5Te4e2PbTzpiP3l4adfJ2OZ0dL3rUHRhlzNj03698YLNo/rGgQmKUs oT4td4/dnCgeeud/dRKSGrjQI7G0qiFhl8dpSVKdytqXhE6DZzu7q9dAykieSLVbnlOk rB+yPR9w8398D33DtVvloC1zTZnp89tuqFAadr9PC6BFB8zMucn//9KFZEQS/kNYcxo9 X/JJBnoLutMdj3MfjK7djMkXGiVftBVeUTsZI4yCuKI0sqdAgtNBphacCNotbSaHM9Hu Z0Sg== 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=XNTdAjqyDyHS7l4DD0m2uhFjLEtFUqEkX0p1puB4r6VzTsB2nCRlXJKacAwR+B5Rrk CqTJzIomPyD3D+JYvFLFR0dkYR/1ZY1CXcJ2TF2EPo1unNC9xEgqYDC2zj3FzbkpgvZK uzR0dNZ09YGC/aEWWs8ETzi9Zf0F4X2cZBcNJhZ3lwPYCXj9FXYVzxKv4mX655Qbe4cr qAYBCG8aE8T+zu8gm+SZjh0PwwNai5Pe1ETOX7YeKxAw8doxfggLrwEEiUAcXP2BGovh z1fcsVgSySvXHOe6FUVdkKuHvQziODxsLB4E8QkGAkopMGLILQw8GdeDnr4qoF62jVv3 5cQQ== X-Gm-Message-State: AOJu0Yw1zD/NJsZ2lAEzwUT/XUtSpk6l9EnxsoNUtJA+13jg1IT4qC8E nSTmPKma7s4ElDKJ83MXGT0zwmkitkI= X-Google-Smtp-Source: AGHT+IE7TdAMSox3QZ9i3XY42vmW+YqwJtHLDXCrkzOQDSyIHqr/K/m4w9DaaKuedrPKXRX2zXN/sfp+lRA= 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-Rspamd-Queue-Id: 2A0FAA002D X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 1jhswm74nfnbupkxtbwxzmb7m33x4sda X-HE-Tag: 1695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8WW6DIfuc6NarfqQigWIkOPXbz7ZsjiS7ez7hgthXgeLTRQDTAVvEihLLUWxvASeb4Y/ZIExwWylnvFo1Imm8CSIQfaZDu4zxDSw0m2rqeCn7WB8ieqnQ0GYJW4HIf3UHcRm+OAi6eM14QfY5WFkBRe+47V6Sy4jLdgGV/unacksiYcjhpKQHK/y70yntqvZwg0nEahokDFNrxPKbcUS7jXck3lqoOGWA/OJCho7sOevL/KZs+6uhf73wNcXgpVaXh8gfQbrc3gRSAvwZ7Z0xuMYCZMiJAFjSO1TTUqiODFQeXLmKSvzql9A+kgxSaneqXubo9nBWkme8eONWs+mkDOCOjHLaWwx9xYPJjTsgsJ18Vb/E1FLpP50JfiM9acwPqDDRn4LKlaupZRASCdjn9At35mgDCPt5QL8oEZfyVR5o6G0eHTjfVjy+/YoFp+cM4ltAQQE1ZNKF4Os9cXE4u/NUaOyo5G6fAfn7pSIy0Pj8xY8Kf3xqPKyQB9ENYm8r0CZlsSL8h32WIECZzrdW/kAkA8zJo2trQOYDpad9LNZEAkpD0JhGCPD3rOFog/r0cxNSuV4p7BXCaYsJc73/wdEg+Se/hh/FwBwS50KELBO2im5/YqwXan0nWca+y7BndjTF/Y0O2qC3i8Zhd/FIbKQV4TUffPNEPfr8rbvpkci40XOnG9CIV 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 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 :-)