Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1838320rdb; Tue, 20 Feb 2024 08:23:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWW2eh4XAWYAToAHGRh3yDwjQbezfNT5sBuS5Ek7NYRbCBkVnh7A98LdOlc8jjpQOIkAd8gVBRJm4YZYYChFBSYjw4jNh/ShN/ypRBV5g== X-Google-Smtp-Source: AGHT+IGHe4inwuzXY1ntKThpDAZeVlek8DSf/6iUfXPop5SOyAL/rUpTg68fWNqhr8AVjpNahKjC X-Received: by 2002:a05:6512:1593:b0:512:c2f8:7ac1 with SMTP id bp19-20020a056512159300b00512c2f87ac1mr2054319lfb.32.1708446221315; Tue, 20 Feb 2024 08:23:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708446221; cv=pass; d=google.com; s=arc-20160816; b=Je32n0iDpYj+JKv0jioGPCOcZRaO0xvNnkEi99O3DiZ8WN7a9lqx6Zb+4BwB9nGF0M eru0EarPos9vBGJgQEEn0G/SUdih26ISKBjVPVMSLovn4z/KtbuElYUUkLzM9R1UeeWF jQhuGhQsV0rVOWQML4okkq5FgK8zVeYeCYt7btf/3R2pU0EmFjnhAPjEAZNGz2QhU60S 37EkuEndBmhC+jjsIJuOgaanMmJQT6NCiLXRBoyYQJX5DD4ICzgJSTPm094dFRtjhs+9 4sD19/m+LY0aKxI6k4H0VapOWw06TR/GCm4oV+ciIYOJ230AyGMzR3CyzWmDz9ybVd7I RV3w== 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=gaBNvIG1XlI7Rma4r4ZehqM6i4uIMsjEXoMFyCXLWog=; fh=nKDWtQB4LU/dkjw4Vi93MsLv3xD+XrpzRfp00vd/yI4=; b=jij8G5oJlg++JNv/2/Xs5eA9D5IbvuMLICFGw9h2YfgZK6FJc/gAt/V6vzWuIE5Bde rk+fMpULV7mM2lUj5BOkebd8gXKZ6G4xiivtpIZqeXQkJDSDdX6W21lMEHiOj0WcEcJy xX8bVSVQuxg0I27fkX6psJM/zDVbjZA2U/uG67yuz/fdpuNpa95a6ff51MWCT2emZYVA tMGX+RRmMu8W80pk7GpyKII698Cr5rooyJOXTZ4Qb4ymDpMi6Oxb7kdqTlCIDEwt5Qni qUFMNTD0kMHtSE+DCUivq4aydnlNLPG0RMxU+zA3fYVC6dbp1XsCf1o1K+OGHzkl0o87 sxfA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=hnH3DEK1; 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-73337-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73337-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id e23-20020a17090681d700b00a3e45a37f1bsi2911437ejx.688.2024.02.20.08.23.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 08:23:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-73337-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=hnH3DEK1; 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-73337-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-73337-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 DF4661F22234 for ; Tue, 20 Feb 2024 16:23:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5C1A579DA1; Tue, 20 Feb 2024 16:20:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="hnH3DEK1" Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.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 EFDDF79922 for ; Tue, 20 Feb 2024 16:20:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708446040; cv=none; b=sMrGffp713ovIr761dygD2zNucC0r9rNpUIe2yqYSfDfiR/uDjMDsRfFxgcC4uYzZ8iZmq70hpyT62aFdA/2whWpUVlBRUs8wvcn6nA1f2fA2ei6QVGQEqP4MT0mIYplF1SLwJL+CE+w9oxX/5EcJ8TNpArDGLkOQYw5PaldX08= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708446040; c=relaxed/simple; bh=tkQx8P4cA4yFykrMvurCrO/U9EcQdI6W6X9CrUgTWAE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KpZ+1vXdiXPM8h4ow7HNxtf5ziJoJP+78knMB/BSQU7YyhjsYEob8umRdySdQVYeXFwCgrwQRMTuJqNZHFo1VniDSij1feJk9cZIFxNFnqiiBxXdDqGefotb1qeWdqsxYbVEb46QdvqiFGXpGefzjZSXfcGg2Kf4OOB7Ojk0GL4= 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=hnH3DEK1; arc=none smtp.client-ip=209.85.214.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-pl1-f202.google.com with SMTP id d9443c01a7336-1db90f7b92bso52075275ad.0 for ; Tue, 20 Feb 2024 08:20:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708446038; x=1709050838; 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=gaBNvIG1XlI7Rma4r4ZehqM6i4uIMsjEXoMFyCXLWog=; b=hnH3DEK1TlZ9XwRPa83LdjKnfEDz6mvX3uvbNOKk5vlHxAcF/xGUsoDiW2kmphZJ8P sSzYna9rcvjRU0qhgID4aqNAZCnYGaS7rkjVN74ZngY/yBpmP8AlzeLd7pY1SaEAIjuI 9xov93twffL7EOgDT1w8w9DHfjjiuHWQ4Pq1IzsCXV8iN8Ka/2MxdYq/TUU4/r1vZktI YxIc5uaLt+QDWpwjB/5/5VM3dRkP7AL0S/Jdde+HuZFCJj/j3wJKppg6jTdT4bEzSnq1 DYB5xhRw4vik1jyn9upwPoZ/PsVFyfq+IxzVOtp7WOMrF7+wd+PDFjNftoT07ZP2HVTi Ra5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708446038; x=1709050838; 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=gaBNvIG1XlI7Rma4r4ZehqM6i4uIMsjEXoMFyCXLWog=; b=ppf/1nL9NEqdGLT7fb1nR0H8WgiqWOqAPUfZ4U0iUGt9OCTb48zJypTH0Lg4I1ZWJG Lf807nekLZWPCMDZiwCVUn6CnqwQcailQRSl2FGaoPhZbPGyFqH6cKSM8sxmL0wFeK4W XEJb/FhrFRvrHtAgwpepHzuR76IN/ZTWJqLsZ6d02MUNbH9pW35hisKTB39IMP8sCRte qP1gELx4ndJGHCHVx3NtuS6NTvmE7gEkM7Ipgfau1aWS9BgpD+ItPpuXHOtgQjc6819P DCgY0qXpEsD/kMLw+WLkzG3071kZNeSLrEV21KtZBxiOfhaZVyn1Mdt+SN6eW5g8LITJ kd9A== X-Forwarded-Encrypted: i=1; AJvYcCWlYZ/JXg0NYwsgjTx5/w7ei7SJADZhiQ+kzlRVNWRbjsXf8UDCcS5mVIB0zJgHUnMfCZg/Ma80CwWzEUZTLb/ydZJewmSvOqi4pAKj X-Gm-Message-State: AOJu0YxIRM7UoXA1hpuBK8pq9wyMEUUTSKFb4pHFwjx8KIr769luHYaR wy3q/pgVi/9EEmLlBvUyLwE/Ki82shiB+i87a/0KMqw/gD0bTXIeUqchcRT1rIFQ6ZMs3sPmvma a0Q== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:e74d:b0:1db:e494:4b51 with SMTP id p13-20020a170902e74d00b001dbe4944b51mr268101plf.4.1708446038280; Tue, 20 Feb 2024 08:20:38 -0800 (PST) Date: Tue, 20 Feb 2024 08:20:36 -0800 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231010200220.897953-1-john.allen@amd.com> <20231010200220.897953-7-john.allen@amd.com> <5e413e05de559971cdc2d1a9281a8a271590f62b.camel@redhat.com> Message-ID: Subject: Re: [PATCH 6/9] KVM: SVM: Add MSR_IA32_XSS to the GHCB for hypervisor kernel From: Sean Christopherson To: John Allen Cc: mlevitsk@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, pbonzini@redhat.com, weijiang.yang@intel.com, rick.p.edgecombe@intel.com, x86@kernel.org, thomas.lendacky@amd.com, bp@alien8.de Content-Type: text/plain; charset="us-ascii" On Thu, Feb 15, 2024, John Allen wrote: > On Tue, Nov 07, 2023 at 08:20:52PM +0200, Maxim Levitsky wrote: > > On Thu, 2023-11-02 at 16:22 -0700, Sean Christopherson wrote: > > > On Thu, Nov 02, 2023, Maxim Levitsky wrote: > > > > On Tue, 2023-10-10 at 20:02 +0000, John Allen wrote: > > > > > @@ -3032,6 +3037,9 @@ static void sev_es_init_vmcb(struct vcpu_svm *svm) > > > > > if (guest_cpuid_has(&svm->vcpu, X86_FEATURE_RDTSCP)) > > > > > svm_clr_intercept(svm, INTERCEPT_RDTSCP); > > > > > } > > > > > + > > > > > + if (kvm_caps.supported_xss) > > > > > + set_msr_interception(vcpu, svm->msrpm, MSR_IA32_XSS, 1, 1); > > > > > > > > This is not just a virtualization hole. This allows the guest to set MSR_IA32_XSS > > > > to whatever value it wants, and thus it might allow XSAVES to access some host msrs > > > > that guest must not be able to access. > > > > > > > > AMD might not yet have such msrs, but on Intel side I do see various components > > > > like 'HDC State', 'HWP state' and such. > > > > > > The approach AMD has taken with SEV-ES+ is to have ucode context switch everything > > > that the guest can access. So, in theory, if/when AMD adds more XCR0/XSS-based > > > features, that state will also be context switched. > > > > > > Don't get me wrong, I hate this with a passion, but it's not *quite* fatally unsafe, > > > just horrific. > > > > > > > I understand that this is needed so that #VC handler could read this msr, and > > > > trying to read it will cause another #VC which is probably not allowed (I > > > > don't know this detail of SEV-ES) > > > > > > > > I guess #VC handler should instead use a kernel cached value of this msr > > > > instead, or at least KVM should only allow reads and not writes to it. > > > > > > Nope, doesn't work. In addition to automatically context switching state, SEV-ES > > > also encrypts the guest state, i.e. KVM *can't* correctly virtualize XSS (or XCR0) > > > for the guest, because KVM *can't* load the guest's desired value into hardware. > > > > > > The guest can do #VMGEXIT (a.k.a. VMMCALL) all it wants to request a certain XSS > > > or XCR0, and there's not a damn thing KVM can do to service the request. > > > > > > > Ah, I understand now. Everything makes sense, and yes, this is really ugly. > > Hi Maxim and Sean, > > It looks as though there are some broad changes that will need to happen > over the long term WRT to SEV-ES/SEV-SNP. In the short term, how would > you suggest I proceed with the SVM shstk series? Can we omit the SEV-ES > changes for now with an additional patch that disallows guest shstk when > SEV-ES is enabled? Subsequently, when we have a proper solution for the > concerns discussed here, we could submit another series for SEV-ES > support. The SEV-ES mess was already addressed by commit a26b7cd22546 ("KVM: SEV: Do not intercept accesses to MSR_IA32_XSS for SEV-ES guests"). Or is there more that's needed for shadow stacks?