Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp279043lqb; Tue, 16 Apr 2024 16:01:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWF1y+qpVW13ACAtoEB8bzecw8hQm9AiW1vE1yribPaHX1Azw1fIPI/40N1KAb67C0LaFgseGhp2Z+DCIsh6ID4N/8b5Lx1rGlq6TawdQ== X-Google-Smtp-Source: AGHT+IF7bdRfs5MZMKxjh4nbzmYG3TLTuoGMFvKyUSW/cG35zJ+cev4v3LolnpFty6BV9zISbyGU X-Received: by 2002:a17:90a:fa84:b0:2a4:892f:39b2 with SMTP id cu4-20020a17090afa8400b002a4892f39b2mr14282761pjb.11.1713308464146; Tue, 16 Apr 2024 16:01:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713308464; cv=pass; d=google.com; s=arc-20160816; b=XBlhOGSS04b5tNEY87s0a5nbnKRx4mEdWOfooW0gtJNvbrdzhrLrRW70aa99J5K6CN pmoJk+o0jmCN47S0FEbuk9DLhphVFAtRmjFsk8xvfXNqy/YKO2xOv/m7ThpVAAlu+jPO j+EHstbgiHvkt0IxJXIWVAlTM8F8WAEqSJkabzadnkR1ieYRQ/4a+kwECKLohBFnfUKs ecDqw+1HZYmGW90TYxi4OYCyTRCqfj+pdGkCRIhWFeOJmOMb2sFKXE0Txkhc9qXRSnth 9Quf5T+TEZ46uU2lExiic81jDnMAAnqJx//lJonu1rSyg0VoNU/5o8+xksBA7rPRBTX4 RV4Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :in-reply-to:date:dkim-signature; bh=gUTtXSCxfr7roX4tv8e3CeB2xn8HuprapDcEtfWKNTY=; fh=2rvyZTHI3U9aukTDuOXWSPCN5ew+IyhWNVGwnHXefAU=; b=eMHvY0+mJreaJc/Hx8KfesBLkx/FpM1bRfL79hD1rk8ymHkiJSRswRGN8aH3tcCdhz lUIcEb6rmiWYEQAsJji3qUxkhgn8Tk/7/3y6W+mkyKt+Nv0dNTNzLY1xMqtmBMMKW2Oz PKsMRv+wiRTSgncpzy/15tABUQ9eTDB5XC67EqdjzEdVg7inssn9WzziCCaSghioe1bc Cc+O/1STe9Z/prqyKYOpyKW0TbitCWBviEnuXeQnCX4NNi9fei8nIjk6Pi0tYG2gTHRb 8x7Di7GI5G/g2VmAw6LH4LKTFYfLhg2ZltBb720UQr9u2//l0E5TQ0au2rCDzqgk53O8 pTXg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ACTaVNrV; 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-147726-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147726-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id a22-20020a17090acb9600b0029de97229e8si165995pju.189.2024.04.16.16.01.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 16:01:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-147726-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ACTaVNrV; 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-147726-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147726-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id B8BB8B22B97 for ; Tue, 16 Apr 2024 23:01:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 353C213A400; Tue, 16 Apr 2024 23:00:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ACTaVNrV" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 E9CA284E0B for ; Tue, 16 Apr 2024 23:00:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713308449; cv=none; b=DpKt6AWG2isj6u4mI8dthpilw3fEAXrjd6XAty5e0Q4SK6IYmYwWDShWgitCsH5ucp7hd4W5iPmus+j1nFaf9XQzogr9qVi3pdEAqRN9VgQftSnEV/S+B7PXHPwZvzQMahZ8Up3Y7ulGJhrm/okd/CfCJ8NvLaSONT0U41jKhYY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713308449; c=relaxed/simple; bh=938CDYTogAtfMd1cQm26cNVOklu3dGsvJ7jgtq4RFlU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=O0MidvZW01b7Wdd98YybT1GGp1BnwVuhGLdlrhd5jQnWyoYX3ky9En9vJg4Rnl84CiDhBZgRy1O5VBVTG5eYpj6/VH3huaMXHRrhmzG4K2EjLsCCQKRIP4lk/rGQbGiKj8qdXcLDBmAaC83tAINoCFq6Ir42y6wBA9gXn09/oio= 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=ACTaVNrV; arc=none smtp.client-ip=209.85.219.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-yb1-f202.google.com with SMTP id 3f1490d57ef6-dd0ae66422fso587361276.0 for ; Tue, 16 Apr 2024 16:00:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713308447; x=1713913247; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=gUTtXSCxfr7roX4tv8e3CeB2xn8HuprapDcEtfWKNTY=; b=ACTaVNrVlaHruOYoVyqPS3OKmX7SdAPNIjoPF+QYfN+kmtAhl+hBlT7e4zhQ22ByK4 gc7cXCOGRX3c4LLz6ZslXrIci8h0wVK70MVKbDMgOiK1KPdjSlFrP7vqF6hXvuqydkEm dUfLNjzZBRr0BsjQjtWQg6mJ5aIIlAjkPPEta2xNdZFIu/cBUI4SJk6wvpsWjVqUymdA ZrUrDkEQ5k645g9AsyFSCBivs81JSA3ysv2BdZ98iO63wJ2PTLiIjmrAZvzJ5jYOrdFO nCQ0bBO0hVnCuJE3KiCCpQI4mljAY8FhPLQ1Mr7f65B7AJArDANpfoI+AFCIbLL3zmCP SLRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713308447; x=1713913247; h=content-transfer-encoding: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=gUTtXSCxfr7roX4tv8e3CeB2xn8HuprapDcEtfWKNTY=; b=IMj7bMQgOqb2dWVW0fr+5fEnSeNYhT6FSNFAneSusITWy+gzboC+jgvaXP/aDxx6SU cx+bMYK7xp5jv3D0i5XnvjA0kbVC8tH8ghomrFz1BJUx+Hf/fiNaEzKb75vDmLuR23Z3 sRbTIRW+iBqysm17lmHTwq+SCa9bEUijdoXSOylW3VKrA5O3ocGnEBgpWJ05Yf8lqqnh Td91Y/WKtJwXarCgIcx7hHsRGr1W6jgBjTxR/tVeJGcEBa3VcyGkRYoNKb3lO7YJSPBX pyAAVSTEdzcBWfy5Cbhrd7aCaW9seOFtd5lI6at3kTop+sxPcClyxrzlvO/PbQuaJ509 Npeg== X-Forwarded-Encrypted: i=1; AJvYcCUe642W/7aaj/HRd036eGjK7r9nB91FRfhxLrkh+5SOxk6mAEjE5l7GWLy+m7zmaD80lCEvoTnsyJZQW+Je+6OLrNelhHwomTcf/rXL X-Gm-Message-State: AOJu0YzvmxKwPTfEST71PLB8T5uqTR7ZZvthXz/r6tDj7QYS5yZBZM+X hJ40cPczyFbtG1MtgOu2eypH33xynhi0GL+5oE8J/MJY+Zq1ib2ZNbb1mTXUxFjhfXXnVXTjP75 Q7A== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:72c:b0:dda:c4ec:7db5 with SMTP id l12-20020a056902072c00b00ddac4ec7db5mr1295216ybt.4.1713308446874; Tue, 16 Apr 2024 16:00:46 -0700 (PDT) Date: Tue, 16 Apr 2024 16:00:45 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <2f1de1b7b6512280fae4ac05e77ced80a585971b.1712785629.git.isaku.yamahata@intel.com> <116179545fafbf39ed01e1f0f5ac76e0467fc09a.camel@intel.com> Message-ID: Subject: Re: [PATCH v2 07/10] KVM: x86: Always populate L1 GPA for KVM_MAP_MEMORY From: Sean Christopherson To: Paolo Bonzini Cc: Rick P Edgecombe , "kvm@vger.kernel.org" , Isaku Yamahata , Kai Huang , "federico.parola@polito.it" , "linux-kernel@vger.kernel.org" , "isaku.yamahata@gmail.com" , "dmatlack@google.com" , "michael.roth@amd.com" Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Tue, Apr 16, 2024, Paolo Bonzini wrote: > On Mon, Apr 15, 2024 at 11:17=E2=80=AFPM Sean Christopherson wrote: > > The first question to answer is, do we want to return an error or "sile= ntly" > > install mappings for !SMM, !guest_mode. And so this option becomes rel= evant only > > _if_ we want to unconditionally install mappings for the 'base" mode. > > > > > > - Return error on guest mode or SMM mode: Without this patch. > > > > Pros: No additional patch. > > > > Cons: Difficult to use. > > > > > > Hmm... For the non-TDX use cases this is just an optimization, right?= For TDX > > > there shouldn't be an issue. If so, maybe this last one is not so hor= rible. >=20 > It doesn't even have to be ABI that it gives an error. As you say, > this ioctl can just be advisory only for !confidential machines. Even > if it were implemented, the shadow MMU can drop roots at any moment Sure, but there's a difference between KVM _potentially_ dropping roots and guaranteed failure because userspace is trying to do something that's unsup= ported. But I think this is a non-issue, because it should really just be as simple= as: if (!mmu->pre_map_memory) return -EOPNOTSUPP; Hmm, or probably this to avoid adding an MMU hook for a single MMU flavor: if (!tdp_mmu_enabled || !mmu->root_role.direct) return -EOPNOTSUPP; > and/or kill the mapping via the shrinker. Ugh, we really need to kill that code. > That said, I can't fully shake the feeling that this ioctl should be > an error for !TDX and that TDX_INIT_MEM_REGION wasn't that bad. The > implementation was ugly but the API was fine.=20 Hmm, but IMO the implementation was ugly in no small part because of the co= ntraints put on KVM by the API. Mapping S-EPT *and* doing TDH.MEM.PAGE.ADD in the s= ame ioctl() forced KVM to operate on vcpu0, and necessitated shoving temporary = data into a per-VM structure in order to get the source contents into TDH.MEM.PA= GE.ADD. We could eliminate the vcpu0 grossness, but it would require a massive refa= ctor, which is also not a problem per se, but it's obviously not free. Eliminati= ng kvm_tdx.source_page is also doable, but it's not clear to me that end resul= t would be a net positive. If userspace pre-maps the S-EPT entries ahead of time, then KVM should have= a straight shot to PAGE.ADD, i.e. doesn't need to "pass" the source page via = a scratch field in kvm_tdx, and I think/hope would avoid the need to grab vcp= u0 in order to get at an MMU to build the S-EPT. And stating the obvious, TDX_INIT_MEM_REGION also doesn't allow pre-mapping= memory, which is generally useful, and can be especially beneficial for confidentia= l VMs (and TDX in particular) due to the added cost of a page fault VM-Exit. I'm not dead set on this generic ioctl(), but unless it ends up being a tra= in wreck for userspace, I think it will allow for cleaner and more reusable code in = KVM.