Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp436917rdb; Thu, 8 Feb 2024 10:01:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXFFjykDWxi4ovcC1HWoh3mijit1VyTNAG/v33GRycwpufDVDmjKmvQO8JlA9W6LF+cC1sLeEn7L8of74qnvbf5OmjY+KwMKRVOmiFrXg== X-Google-Smtp-Source: AGHT+IENDwesabn0QyZ/6n95hJIel7vvYPlzqTmiP8lRcoNMP0Zn45yxEYm5K31NF4KPRD49c2mx X-Received: by 2002:a17:90a:9ed:b0:296:e1f8:ef0d with SMTP id 100-20020a17090a09ed00b00296e1f8ef0dmr5942916pjo.43.1707415280964; Thu, 08 Feb 2024 10:01:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707415280; cv=pass; d=google.com; s=arc-20160816; b=PeozPHwY+ZhZGOZ2EaWoDfTfVq77uJWjYV5WvhTjVSBlFie2nWCZVSlGyGOm3i1w1h pztLUrXrihPRhtspuIxYT47l+TsuHLDuswnzvwVi1s6OS3r0cKr+eDyqu0nrmeS4+BIF UXTpXkA62r/XioVC88w0oMZP++sOnGMyYLj5TVrll+xEM3dURDDJg01Gc8lUqAgc0K8r mWCrz8AzTaz0ZO26c2Un+pWJJv0TayJ/nFZtSfRMrXE/9gxQpxgATQRwt90/maU2wxgm xCVhHhW6o38FEQpfe5dOe6X3WkSfCxooqbIc3qOeMRVhi8Oz3cUV23DVDKWS2BZM6LfQ eOZg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=6sek37PEy2MZoPmgCe0RKHy1EATtqvffN4QHzb+4/dw=; fh=8Egu58+hRCrm/+RJLZ3DpKh2FpkPeCPYKytj04vmmDE=; b=tZg83/fKQHrESN2yI4VXzV6uNcF2VLNT80P6HK6l/YMMJLh1nps4PE1SGts3sNLC9G Ou6XTD1BvXwagaDkiU9CsBgkUj5RSitolK//2ZjRyXbgdUXCFfWi22LigCoprGMSeQv7 hGmdTKCAGB0g8Bhq6nFvnzJxABgp6635LPf8JevnuhZni+JX/F8juzLrPSYRTrRBi1+w sPmhIvYu5MywKUlZLVNGBz5xON1uhbYOafnynIveWOrhLZq/U+DpQyw2W4358N8NtnU6 bay3s4sxK/1ZSqxA5ohaysqVMCS1I06Z77skzRwPyoO3b5RtZZwf2UTmoHIGXcVpQ0hh VBIQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=a12FjRP+; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-58463-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58463-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=2; AJvYcCXKtTCWusvRUgIwOYsoSx8f7pf1rEm9Dk4le0IW1SclvV6Orz9hF3uI2VdLNeUCuQO9foquurejzrasg3VnFz/gQeW5eeeTOBccD/3E2Q== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id lm11-20020a170903298b00b001d72a09b874si92477plb.3.2024.02.08.10.01.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 10:01:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58463-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=a12FjRP+; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-58463-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58463-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 24A2CB2A5C4 for ; Thu, 8 Feb 2024 17:31:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4734B82C64; Thu, 8 Feb 2024 17:30:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="a12FjRP+" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C039080C05 for ; Thu, 8 Feb 2024 17:30:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707413450; cv=none; b=SHAuDafBqPWSa4Q10t/mnxt5fsvkDK8PPCeQdDoXSNgRIrX8BVsPeumpjXlC31bPjAFgwbRg/04mQMSzWUJvdWRK3bCFVmemMPVOSmSa0VovrxEOrC3NA5qlFmg9qxRBLO3EYIACg4G5onNPW/C5+znWD5d2Mf8GLNAp/Dqg6w4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707413450; c=relaxed/simple; bh=1IQJLk1ty4Cbv9srUf/jkoJhkkc0s4qbS6Kv1KMw1nQ=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=pSmYaplGHwKNgUDm9nwTqB3sAzDhuwy92UvjDFPfThn72Cd4E3EZai4HsfI3O6+J4dZ+jp2b80zBpBI5F7Ib6y7iYqeomU12CWitKbW4tVBX2BLQMs+4qF1rkTrmEJuRI4qrYm39XI7VToqsNtTsAs6o/tFJtJmLE7jIwaRRJ+c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=a12FjRP+; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707413447; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6sek37PEy2MZoPmgCe0RKHy1EATtqvffN4QHzb+4/dw=; b=a12FjRP+LdNnDXJCBACmwQcs59sJfRLqD3RHmG67rNOtbwCbXMvo4mLQwpDnpO09iBA6Ct eNkKCKNNXIq0D7vWXPuH0uD3N0MmIF4F525G+p7OGnfEHwsQYZpJA14A42HMGi7rxb+LD/ T5Snt7tXrm0eV9Dz9AviqPfX+PrdNo4= Received: from mail-ua1-f72.google.com (mail-ua1-f72.google.com [209.85.222.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-421-P22isv3TMESPgyBjAU3omg-1; Thu, 08 Feb 2024 12:30:46 -0500 X-MC-Unique: P22isv3TMESPgyBjAU3omg-1 Received: by mail-ua1-f72.google.com with SMTP id a1e0cc1a2514c-7d2dfa4c63dso6151241.1 for ; Thu, 08 Feb 2024 09:30:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707413445; x=1708018245; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6sek37PEy2MZoPmgCe0RKHy1EATtqvffN4QHzb+4/dw=; b=EDbG6uJ53AG+DhAs/dWFjauCrpQfLRrXTYfb6XV6AqjDL3Ff2FoMXi/+b5IcDn/3GD C288JtzaCQF0nwhlaAJbhzOGqIvAZRzw5LB8A2T2gYshYFpcjfVW4U5MQEUHl9RngAmI LIlVsxoeYsWTIrdOnibfhJYpzAAuDkTAugwdlwNNLUKXqo7FCmJHAWTVrXYjgEYA2rkn +0sK1D+vfhCYXmB5mM/JgRDHwUmj2Fd9lypgGCckhe3OTHzUxBXFhz04KH0D47AY5mrr BiUJlXu5/RSsYTVEhYIieeCAKWMTg9Ak4WaxYbiFqwif9wkigMm9l+bleOsIHUlLtASD irsQ== X-Forwarded-Encrypted: i=1; AJvYcCV2MTWrjPKqVU/7Bt8w8oh3tWtEt9SusaIEI0KzdacLoLPpuBvNGqC+cT7+y6dew7kbkCwFVI0ZxmmVo8FFm/p9+Hh3GGebXX8hUK7c X-Gm-Message-State: AOJu0YyVV/B0uH78Tp+PHnFgAneelxjaP3CHjnmEgfWXfJFtCkfjbsLo JaAfjrZJ9zCCnmGIHC28foBHOUQlNCQCr2YbdAahprUhKgFyI6r4Ea5qD5K5Ipadd0xXkMrwDHQ DUUaC1Y/UgMEQf3wTTpahfSVPIXtAZs33POo8HYkaHc6xQYoKTvpqCQlafnO8sZ92pt/r2//5Ec HWgtNv+Dr15cHzu43xjwsoKajqr7atr994/NG2 X-Received: by 2002:a05:6102:1158:b0:46d:5cb9:c3a0 with SMTP id j24-20020a056102115800b0046d5cb9c3a0mr2966153vsg.33.1707413445631; Thu, 08 Feb 2024 09:30:45 -0800 (PST) X-Received: by 2002:a05:6102:1158:b0:46d:5cb9:c3a0 with SMTP id j24-20020a056102115800b0046d5cb9c3a0mr2966099vsg.33.1707413445212; Thu, 08 Feb 2024 09:30:45 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231016115028.996656-1-michael.roth@amd.com> <20231016115028.996656-9-michael.roth@amd.com> <20240208002420.34mvemnzrwwsaesw@amd.com> In-Reply-To: From: Paolo Bonzini Date: Thu, 8 Feb 2024 18:30:31 +0100 Message-ID: Subject: Re: [PATCH RFC gmem v1 8/8] KVM: x86: Determine shared/private faults based on vm_type To: Sean Christopherson Cc: Michael Roth , kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, isaku.yamahata@intel.com, ackerleytng@google.com, vbabka@suse.cz, ashish.kalra@amd.com, nikunj.dadhania@amd.com, jroedel@suse.de, pankaj.gupta@amd.com, thomas.lendacky@amd.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Feb 8, 2024 at 6:27=E2=80=AFPM Sean Christopherson wrote: > No. KVM does not yet support SNP, so as far as KVM's ABI goes, there are= no > existing guests. Yes, I realize that I am burying my head in the sand to= some > extent, but it is simply not sustainable for KVM to keep trying to pick u= p the > pieces of poorly defined hardware specs and broken guest firmware. 101% agreed. There are cases in which we have to and should bend together backwards for guests (e.g. older Linux kernels), but not for code that---according to current practices---is chosen by the host admin. (I am of the opinion that "bring your own firmware" is the only sane way to handle attestation/measurement, but that's not how things are done currently). Paolo > > > > +static bool kvm_mmu_fault_is_private(struct kvm *kvm, gpa_t gpa, u= 64 err) > > > > +{ > > > > + bool private_fault =3D false; > > > > + > > > > + if (kvm_is_vm_type(kvm, KVM_X86_SNP_VM)) { > > > > + private_fault =3D !!(err & PFERR_GUEST_ENC_MASK); > > > > + } else if (kvm_is_vm_type(kvm, KVM_X86_SW_PROTECTED_VM)) { > > > > + /* > > > > + * This handling is for gmem self-tests and guests that t= reat > > > > + * userspace as the authority on whether a fault should b= e > > > > + * private or not. > > > > + */ > > > > + private_fault =3D kvm_mem_is_private(kvm, gpa >> PAGE_SHI= FT); > > > > + } > > > > > > This can be more simply: > > > > > > if (kvm_is_vm_type(kvm, KVM_X86_SNP_VM)) > > > return !!(err & PFERR_GUEST_ENC_MASK); > > > > > > if (kvm_is_vm_type(kvm, KVM_X86_SW_PROTECTED_VM)) > > > return kvm_mem_is_private(kvm, gpa >> PAGE_SHIFT); > > > > > > > Yes, indeed. But TDX has taken a different approach for SW_PROTECTED_VM > > case where they do this check in kvm_mmu_page_fault() and then synthesi= ze > > the PFERR_GUEST_ENC_MASK into error_code before calling > > kvm_mmu_do_page_fault(). It's not in the v18 patchset AFAICT, but it's > > in the tdx-upstream git branch that corresponds to it: > > > > https://github.com/intel/tdx/commit/3717a903ef453aa7b62e7eb65f230566b= 7f158d4 > > > > Would you prefer that SNP adopt the same approach? > > Ah, yes, 'twas my suggestion in the first place. FWIW, I was just review= ing the > literal code here and wasn't paying much attention to the content. > > https://lore.kernel.org/all/f474282d701aca7af00e4f7171445abb5e734c6f.1689= 893403.git.isaku.yamahata@intel.com >