Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp3025627lqz; Wed, 3 Apr 2024 16:15:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVoavB3IF8KjXhaXH0Rt8asQ4CKUGnM91y3I/XkU9n6l4pV/TC8afWfzgOzL3rnXv/659pW1cLzBhLas6mewfzjZKlCXLfQO93uHx4K0w== X-Google-Smtp-Source: AGHT+IGDcjsrNcPzGJEYpFaO2ofU+pBlrGEzG0qLZcswwsz/aeJwptVG+AUSEQIxNLotwQ7nskhi X-Received: by 2002:a17:906:70d5:b0:a4e:a7a:84e0 with SMTP id g21-20020a17090670d500b00a4e0a7a84e0mr405853ejk.34.1712186146046; Wed, 03 Apr 2024 16:15:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712186146; cv=pass; d=google.com; s=arc-20160816; b=bDLhIIg428O67jkFzas06sEhgI7gQPUFZRbi03nCajoXy1sGNCtrIZ/y+1z1aFLuVx eku60UPHrSxseFym9pxMkwiNH+cAGvcC3In6Hj3hS4FcM3RZe/rHbyvQ1vv+MbXDXz+B 48IL37B6xyb4pY3CJVUNPZ3GcDwSMooyOj2OpiBOs42Qme2K4Wl+rvINr456vPv+ZQQl nVW1970MsLaGcxc49y5L27DLMaYDGcCSUBeqnSMh/xG24LJsvbxYCwvktZiboIRlgVMC ByMNjcQWh+g5lMo5mjegX9Yt2Ek7Y8B5r6y3phs0JwxvLpl7r7oE42KSLhebvTdcT0Fj fx4A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=IB8YIURPP9Hr/QwsBdTaRFjE5dnhh/l5+FEwiaO3zio=; fh=0TQGQsy8rSYY0nPKfY7VDGOkHerIc/MarzQkmozOqs8=; b=Ap4Y8zlz2NUxMr9JJHywjI/UCexFle4x8dj8ZIAxWUApBFN9Fla348ZMI5KQBB5bgj VMMbmg5PTe3x3V99iZTRqVh/P/8ps8TRKz0IoeTx2sNFcfuKfAkadiwK01xYJgQO0pa0 1DVL4W+VAdOnNHGBXTBwFxgi+zrNack6HHDAjsYkSCiO79Nn6f47N2guW1BxSKY/ME/G IpKc+B5B/1fFYcfHqyR0I0P0KdDZgw3XS1nMuDnRzacg66QZN9CncrQnL3fN43N0Bfmj B3xTFss6ZpoUeaAoSRByuxmdpSdMa+MioPp6kAa0uRE2IQBxvP3wSjDVwIctv8cWwAGJ W30g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=F3wfA4fc; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-130714-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130714-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id do22-20020a170906c11600b00a4e58b44024si4675287ejc.461.2024.04.03.16.15.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 16:15:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-130714-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=F3wfA4fc; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-130714-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130714-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 98D761F25D8B for ; Wed, 3 Apr 2024 23:15:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 207A4156C44; Wed, 3 Apr 2024 23:15:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="F3wfA4fc" Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3CBF15696C for ; Wed, 3 Apr 2024 23:15:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712186137; cv=none; b=lW3LMmq/Z13rmdZg7smoj9x1h9TJ9dHvxpqHGVRXuIW4A4PqaWv4dQNulpFb0cijreyrwVw6noETmHc6M+JUny3+eQjE6CLi4oNTFs7lf2ViQ72v2lezifZslfqzPvcqg0yBohhw28nz16u4iAa5shdPGTv84kYdO+i8oCDVCzg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712186137; c=relaxed/simple; bh=qNXU/bUrc0L/NLVUkTSuOdRJ6SCODkDxrzDMtdi4DyU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=obxtzL8YbTogziYaOus/gMGdJSl5GFkrOKO9l72LwheT9F4qP4jdQjJZAws7Bp5/uP3zmLuNeRQSqkYEW1v5275KgEDLOAVCM5h2RUlYwlhFyPobbSdD59Jr2ZdCndhgOVXZPuKl/hyFBpq8SqZx5/kFTzJek97jJysxtinG1bI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=F3wfA4fc; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-6ea80a33cf6so286151b3a.1 for ; Wed, 03 Apr 2024 16:15:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712186135; x=1712790935; 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=IB8YIURPP9Hr/QwsBdTaRFjE5dnhh/l5+FEwiaO3zio=; b=F3wfA4fcW6LlM2GZ0QNMjYGd334clyCfrnaotPL9u2ZjLof3IAresrrIy6Jv6XMOF3 aW5eWsdY4OLCzwT4ws+TuJYtMQTr5LcbUlTah41IlbyHAZgdEon9GvtjQ6agQuLwRJLs Wvif4H0aI4zA9o6kz8bla1ayvQKk4JmvqDWisboVsGx0up6B7wLqDlXXCDMADxG6CPU5 SuMBHMYsoz7UY86IHFSpXDQs7NYdJ43tt5oK3hwgck7vCEnbTnkWHD9fToiuUR7Y6Uk5 Q0+v85xkmGJBttyunJGWMInLwmDttvfhClucW8NBe1jKof+ZTsCZLo4LNBeyjLOXw2iq s1hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712186135; x=1712790935; 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=IB8YIURPP9Hr/QwsBdTaRFjE5dnhh/l5+FEwiaO3zio=; b=d3qc6eyLGlF3BTOhkONTM85gt+vWC6c7Np6CPAOlHkL0W0spHSjIby60HoQkBuCE0v KIUA+JEpQk0pZ9gDqjrO1YshvT/UY4pFXybLC4PawuJYSLGoRdN2jG+O0OiegCxZcAJr dCuZ0PcO4wwwHUa4h0d9pZViZh8wUeHE8vzZI7kxQjPd6chd9vnREe2tr0zv4yaO7zyz Yl/FU0oafy5cbC47HE1mdBuXiOY4MH0gZ2q3mIOeCdvT/5wriuw28lIjhcajEAIcsRXC eVr59SXFohIMb2IA1Fps4AsJmGHPpjCikYfVPZblXvg51MODx1mviC4PfmXESVVBf0Ff nfOw== X-Forwarded-Encrypted: i=1; AJvYcCV81PlrJ2+EvfQMdPmpFdiXbp7I0e7F7k6nsHW1KI6BDXPjTUX7bOpLEK9eaiQBwU6poR4gM0c2E443J4AhQubJ2gIaeneyXbRifPVu X-Gm-Message-State: AOJu0YwaHdHzJ2uk5qdRebpE2xLZI/RjyPrl2r+llp/1oWdyHjG4bn2H j1tnsllxdA86tEE8K3D0StgEUf/O6KgCITeGlBgCCTqXp1ife+NHFG0GMW9/8JWIis/Uhua5IkX Llg== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:983:b0:6ea:f815:a428 with SMTP id u3-20020a056a00098300b006eaf815a428mr66918pfg.1.1712186135077; Wed, 03 Apr 2024 16:15:35 -0700 (PDT) Date: Wed, 3 Apr 2024 16:15:33 -0700 In-Reply-To: <20240319162602.GF1645738@ls.amr.corp.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <66a957f4ec4a8591d2ff2550686e361ec648b308.1709288671.git.isaku.yamahata@intel.com> <20240307015151.GF368614@ls.amr.corp.intel.com> <20240319162602.GF1645738@ls.amr.corp.intel.com> Message-ID: Subject: Re: [RFC PATCH 6/8] KVM: x86: Implement kvm_arch_{, pre_}vcpu_map_memory() From: Sean Christopherson To: Isaku Yamahata Cc: David Matlack , kvm@vger.kernel.org, isaku.yamahata@gmail.com, linux-kernel@vger.kernel.org, Paolo Bonzini , Michael Roth , Federico Parola Content-Type: text/plain; charset="us-ascii" On Tue, Mar 19, 2024, Isaku Yamahata wrote: > On Wed, Mar 06, 2024 at 05:51:51PM -0800, > > Yes. We'd like to map exact gpa range for SNP or TDX case. We don't want to map > > zero at around range. For SNP or TDX, we map page to GPA, it's one time > > operation. It updates measurement. > > > > Say, we'd like to populate GPA1 and GPA2 with initial guest memory image. And > > they are within same 2M range. Map GPA1 first. If GPA2 is also mapped with zero > > with 2M page, the following mapping of GPA2 fails. Even if mapping of GPA2 > > succeeds, measurement may be updated when mapping GPA1. > > > > It's user space VMM responsibility to map GPA range only once at most for SNP or > > TDX. Is this too strict requirement for default VM use case to mitigate KVM > > page fault at guest boot up? If so, what about a flag like EXACT_MAPPING or > > something? > > I'm thinking as follows. What do you think? > > - Allow mapping larger than requested with gmem_max_level hook: I don't see any reason to allow userspace to request a mapping level. If the prefetch is defined to have read fault semantics, KVM has all the wiggle room it needs to do the optimal/sane thing, without having to worry reconcile userspace's desired mapping level. > Depend on the following patch. [1] > The gmem_max_level hook allows vendor-backend to determine max level. > By default (for default VM or sw-protected), it allows KVM_MAX_HUGEPAGE_LEVEL > mapping. TDX allows only 4KB mapping. > > [1] https://lore.kernel.org/kvm/20231230172351.574091-31-michael.roth@amd.com/ > [PATCH v11 30/35] KVM: x86: Add gmem hook for determining max NPT mapping level > > - Pure mapping without coco operation: > As Sean suggested at [2], make KVM_MAP_MEMORY pure mapping without coco > operation. In the case of TDX, the API doesn't issue TDX specific operation > like TDH.PAGE.ADD() and TDH.EXTEND.MR(). We need TDX specific API. > > [2] https://lore.kernel.org/kvm/Ze-XW-EbT9vXaagC@google.com/ > > - KVM_MAP_MEMORY on already mapped area potentially with large page: > It succeeds. Not error. It doesn't care whether the GPA is backed by large > page or not. Because the use case is pre-population before guest running, it > doesn't matter if the given GPA was mapped or not, and what large page level > it backs. > > Do you want error like -EEXIST? No error. As above, I think the ioctl() should behave like a read fault, i.e. be an expensive nop if there's nothing to be done. For VMA-based memory, userspace can operate on the userspace address. E.g. if userspace wants to break CoW, it can do that by writing from userspace. And if userspace wants to "request" a certain mapping level, it can do that by MADV_*. For guest_memfd, there are no protections (everything is RWX, for now), and when hugepage support comes along, userspace can simply manipulate the guest_memfd instance as needed.