Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1099161lql; Tue, 12 Mar 2024 07:20:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUDr3EQPAXQOLSMGA/Xktx+VGw/7s6fzlecP3lCmp4m0bLc4k12Cj9Nsf3gV7vbD+JFTKz/OgulEB+pU+GhfBbzlF8dpRtv/KyKeadGog== X-Google-Smtp-Source: AGHT+IGGt9z6EbG/HKp9Rb7k8WdFP6hsdnW8CgsqL+0bhyIEECFnuE/bqnQDC177uK9USeNTrVsu X-Received: by 2002:a17:903:11d2:b0:1dd:be1d:4658 with SMTP id q18-20020a17090311d200b001ddbe1d4658mr435035plh.51.1710253235814; Tue, 12 Mar 2024 07:20:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710253235; cv=pass; d=google.com; s=arc-20160816; b=lHlTS3tnEK/UEZu8kDKGqBxK7hoWdcoHWEkWPs580oBCqSnD2Tj7XujYopTYWvyM7U KJw8dD5avLkdHxaHYsFRqJlYeDMHG7HdRoUAYYApsBjpNYbnk6jSEdlDbhMgwdstUs9k WARptL6l0Ivheu+8MFE/vWZxGOqjcAm/znok2SfnjiC7MZ9V+fqulYxyKrMViCV2Nxl4 yY5bKEo8jCSW82/A/01bJ8Q5/ZN5YP/eWtv3p84uoQaxcs8w/s9P9RESF0EuxNCmDRYm sE2zeactXkpB6HFW0d3AzzsZQtfNCBW3fCLsx0/sFSm8MktdlZS6wJRm/BRVTulGv4Nz Mvkg== 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=6Jjb/PAOgGaN7lAsVIUO9NyizSvHp4sC3GUTaZ0PNJs=; fh=KHaHEx0+JQ9YHzghChlp393UQkom67Wx2nOLhD9OGHY=; b=ke9RaQhyVfbViTAZP79VaHrRdbrZ7F2Bm4fZ1a8GAMmTh9ujDEH00V59WAgPRW3fij N8nSVnKY5VtjPfilJ9/E52ZEg00p5hhzAzgjBKcYPJbHHe4ED81wJabhFUgVcge+MW3D D3BVseGDCdFIojZGhqvPGgnby8yq44ej7omuOBHA1jy6Xpec7DpSZpeRGZ7+d+M6cZPg QcB07iXFie7koVMyvS+gKXKWNbMh9EAYdyBKIeXKl6iv5lDXox7XboNuPbyvUz9OAkE1 eLzLD3mW+4/lbr2CzRMipH7iY2WRDPoMNiByx+Akb5G9HRRfovwcZ0rcRraDN7WYumw3 asVw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=H0zhra1t; 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-100343-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100343-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id j7-20020a170903028700b001dda3d63b0csi3546014plr.4.2024.03.12.07.20.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 07:20:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-100343-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=H0zhra1t; 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-100343-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100343-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id DE491285AD7 for ; Tue, 12 Mar 2024 14:20:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CFAF47B3F7; Tue, 12 Mar 2024 14:20:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="H0zhra1t" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 810DD7AE51 for ; Tue, 12 Mar 2024 14:20:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710253210; cv=none; b=KXQnL6SlLGQ8dMm0obWO+FeHmN/MYe2KNdyyM3Sfnvr1Id5NuBX8OBOrZSsI2j7H6S03TJ2NGs1W624yNACRNxSEFj9yrf2eV/8TX9E7cfVWKbR2ho1uAr6IwRdukuoXTCsqBWS+VxLbzabbtmA6efS4DA1wikjZNm+vi9CoKMU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710253210; c=relaxed/simple; bh=Cyv31l3V93wJczzZuVe6h3HTL/aj20Zlxrvzm4Sh8lE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=X9y0/hEb2hlzoIesUlQqXLaQIvmRCROKj5z+PsMHGyGEageoCAYKatMQT927ix0e/YPOAK0q+FZCj0+txA1A93DVY11vBklVaLG0q5hRY73jy54lDsGQ76oP7+SGXh7GsEL3HfcYVQp+O1+ld47AVl+NGUWPaqZ6Q3oOgsMp05Q= 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=H0zhra1t; arc=none smtp.client-ip=209.85.219.201 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-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc657e9bdc4so1214890276.0 for ; Tue, 12 Mar 2024 07:20:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710253207; x=1710858007; 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=6Jjb/PAOgGaN7lAsVIUO9NyizSvHp4sC3GUTaZ0PNJs=; b=H0zhra1tbF2BHsVDBkI/e5ByzJ1FKwfcZbWw1ikPhXbAFRTByAcXlwfuKBTUfpKuGg CByuuIJnmYSODXsQSDj/P/i9r+sVyopD8lUmj1ePR5mDX5eIpY/ZB2mKnp55rjFf0wjk oVZPp+PviACFX0D75LmUIcGshgNM5+TcJcGTgUNI5mOmsu5h4/kJVMIr1yywq2GXdJRF E9yMg6dSYc+i1Qv9To6d+ZRoVT0EIHa57RdXGeJIaBAoBGQFHlWnr361WFwXF3E3DAo7 TdHkMpx4rh55d9XxCwwWnzmnNnZfmIOLZR4pqy55TIzMJAsOONvd0+7aPxTnartrDA+c GLXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710253207; x=1710858007; 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=6Jjb/PAOgGaN7lAsVIUO9NyizSvHp4sC3GUTaZ0PNJs=; b=WfsO+Zv4AwBS2Q5FGNhmx6NxRBrW/U89pA7UuZbPSiDMZ2JvOVZPsi/xRuJRsibf9W qJ6nG35hw5gHymTUre4qoaEpi456Rk85kND+UWPUAwrP9xchdcAanCr0G9LSeFe5vXNT 7H+Auj7vzjcaUVNzJuAGCunCoJWX9U3QfFsc6F506U47IkwDPIyI1br8MwVdlnN4Jmce vTMoKsspE3mKn4S6dQkjPAaly1SakoMsE0eBRvKgk1EluB986pwQGyvxqsxCMGki1udx FYMSHFhOYVmg3kOpTcJzHYh5BrjqvPQjMKSnjHkWam7DoFkePT5yn2zKQJsBcr4CrbGC VQ6Q== X-Forwarded-Encrypted: i=1; AJvYcCW5vnWR3xjQ8N4nrTHrDQmQc2gYjUX8Uqrjvs1myQEXjrrk88zvfJC5+5u1N+h5NPJViWq4iKjkP1yh5KSRHjQNep8UUd51hjD25XPF X-Gm-Message-State: AOJu0YxOvt5ANzVXO4ENuC9AzbjQE6ZlG6+Sx0wv8PufqTWoC5UtESOS UVFAVEJg8UI6lvGM8yaO6ZpYOVAV6Klx9ffvazA9/R8ukiCNR/y6uxfxOeYIXzKLIrcc7s5MjXt 22g== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:be49:0:b0:dc6:44d4:bee0 with SMTP id d9-20020a25be49000000b00dc644d4bee0mr512108ybm.7.1710253207502; Tue, 12 Mar 2024 07:20:07 -0700 (PDT) Date: Tue, 12 Mar 2024 07:20:05 -0700 In-Reply-To: <6b38d1ea3073cdda0f106313d9f0e032345b8b75.camel@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> <6b38d1ea3073cdda0f106313d9f0e032345b8b75.camel@intel.com> Message-ID: Subject: Re: [RFC PATCH 6/8] KVM: x86: Implement kvm_arch_{, pre_}vcpu_map_memory() From: Sean Christopherson To: Kai Huang Cc: Isaku Yamahata , "kvm@vger.kernel.org" , "pbonzini@redhat.com" , "federico.parola@polito.it" , "linux-kernel@vger.kernel.org" , "isaku.yamahata@gmail.com" , "michael.roth@amd.com" , "dmatlack@google.com" Content-Type: text/plain; charset="us-ascii" On Tue, Mar 12, 2024, Kai Huang wrote: > > Wait. KVM doesn't *need* to do PAGE.ADD from deep in the MMU. The only inputs to > > PAGE.ADD are the gfn, pfn, tdr (vm), and source. The S-EPT structures need to be > > pre-built, but when they are built is irrelevant, so long as they are in place > > before PAGE.ADD. > > > > Crazy idea. For TDX S-EPT, what if KVM_MAP_MEMORY does all of the SEPT.ADD stuff, > > which doesn't affect the measurement, and even fills in KVM's copy of the leaf EPTE, > > but tdx_sept_set_private_spte() doesn't do anything if the TD isn't finalized? > > > > Then KVM provides a dedicated TDX ioctl(), i.e. what is/was KVM_TDX_INIT_MEM_REGION, > > to do PAGE.ADD. KVM_TDX_INIT_MEM_REGION wouldn't need to map anything, it would > > simply need to verify that the pfn from guest_memfd() is the same as what's in > > the TDP MMU. > > One small question: > > What if the memory region passed to KVM_TDX_INIT_MEM_REGION hasn't been pre- > populated? If we want to make KVM_TDX_INIT_MEM_REGION work with these regions, > then we still need to do the real map. Or we can make KVM_TDX_INIT_MEM_REGION > return error when it finds the region hasn't been pre-populated? Return an error. I don't love the idea of bleeding so many TDX details into userspace, but I'm pretty sure that ship sailed a long, long time ago.