From mboxrd@z Thu Jan 1 00:00:00 1970 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 49AE22C11FD for ; Tue, 10 Mar 2026 18:35:47 +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=1773167748; cv=none; b=aXhul5/ns5J6/zrqIMmh1HuHljh1YhA0G7xU5R+kfFqNG8wNUNymtbtoIij6EjnN4kEoyXE7crL97oVBfCvnLnZyyGGKqEpYjrmm1Ig8R9QrNCBXUVp7+cHcEwTqqoEH9pBSU8VkEdga/ZJFJ4zy4SNdi2j0lBKbl3MFQ/1QfPA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773167748; c=relaxed/simple; bh=p07bGoSJp/3R8scxFTy3n7KW0vlkOxH9d+YGi8txE3I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=tFSc+5hoQXKPMmGH3h+NrS4ufI3pjrUYg3E8z3Li8+t+AxPBHmYb7MPotvKElfUyepghEpD66+4VCrLJo6dLk+sBMzcrsc2qzuriEIJ+c2nnjS+jveCM9gp9iY4pWNFK+Iv2RCzPsGCoETKWW1XLtQB13wz3q3GGCNQ9CpWIlFo= 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=iR1MCYRm; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="iR1MCYRm" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2ae44db60c2so98278115ad.2 for ; Tue, 10 Mar 2026 11:35:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1773167747; x=1773772547; 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=nfTR7SOyttNQka6EYoAXlvlW8tJI1oDrp8f/Qn+Tpes=; b=iR1MCYRmt4opy/KXb4T8d4LEDqKa+ROvC5C9wtRfxezUivrBnC0MkTxgt/heGcWnjk 2NIY8zm8FMRRlMdqREx5E3v3z3bX5Ib/rXDBZUeoswTPjURzMPluHpCO07YWHuxhGjHr QYxy6ySbfkNZ80ycw/F71sNsG2jVZachaSafliHJ93+3xxOmgdfEUJTLcdiTkOojXvA9 EL97EmdAs4A35e6mMQ2Q3M2zaO0hzV8UYwkv3vA+kXsgEEKOaZxVwpSZ357wEgqJCIvJ vnfSZNuwcz3n0VbuyQYXaoWWJb8UlhJ7mPPAHqFEu+sET2Idc3VkepxcCVtwjOkFxkih MwPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773167747; x=1773772547; 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=nfTR7SOyttNQka6EYoAXlvlW8tJI1oDrp8f/Qn+Tpes=; b=qWZA6XWlAZYuM2UgaqkF/eKjDB+IT+/Z4yfMJ5fiWkdOrzZA3MwhtaqVWhR2gBFHqe 3wre3OAInhHZgwFiRSsu6PvqGgYPmIuJQW9gCeHIfJ+Zy9W6kf3KpnL2P+3GsHvAMq7K alxB/EE0vDk7ZyVNU1tWhKPtP83/Q3ebnuXt3yjkxXzl9W3HI3PewF5YNRUp44Kf1o+f 4M2CAc9+yy5mJ/L0WuihjR1KkYe6iMcux3ftzrBaUNaV2oR8dfKTqqf6bOcGaq8GOQvN sb9FMW4XCk72T7JVnEO5Co1Td90uBiLbgOn7qqeIhlfEqE9pQTgNoacrT/jRQHM07lPJ 5HNA== X-Forwarded-Encrypted: i=1; AJvYcCVM8V+Kg5aVmpnu/UtlWVGTJl0g7q/q/Cm8uOGMy5MvwcgGnnTGguUE5kJmefVnqmAeiWA5oGi7IA5JwdM=@vger.kernel.org X-Gm-Message-State: AOJu0YwobMZ19iEdwRkvwfDwPo5cn2SEpSHB5dBkL07ve9xV73TVkPC+ YqqJRjlxSQNYxiS13DPnV49COQL9wO9uiJx3U3f028lamXqHN3j7apxF10jVVPJ6x8S5k2ZLFqz w1Usazg== X-Received: from plge15.prod.google.com ([2002:a17:902:cf4f:b0:2a8:71ec:6799]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1105:b0:2ae:4800:141a with SMTP id d9443c01a7336-2ae824dd98fmr167704355ad.32.1773167746578; Tue, 10 Mar 2026 11:35:46 -0700 (PDT) Date: Tue, 10 Mar 2026 11:35: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: <20260203190711.458413-1-seanjc@google.com> <20260203190711.458413-3-seanjc@google.com> <19935696-36cf-411b-af90-aabe6a98d7e7@amd.com> <947bf241-d149-4933-874a-de96aeb73dff@amd.com> Message-ID: Subject: Re: [PATCH 2/2] KVM: SVM: Set/clear CR8 write interception when AVIC is (de)activated From: Sean Christopherson To: Tom Lendacky Cc: Naveen N Rao , Srikanth Aithal , Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Jim Mattson , "Maciej S . Szmigiero" Content-Type: text/plain; charset="us-ascii" On Tue, Mar 10, 2026, Tom Lendacky wrote: > On 3/10/26 12:48, Naveen N Rao wrote: > > On Tue, Mar 10, 2026 at 12:36:09PM -0500, Tom Lendacky wrote: > >> On 3/10/26 12:17, Sean Christopherson wrote: > >>> On Tue, Mar 10, 2026, Srikanth Aithal wrote: > >>>> > >>>> Hello Sean, > >>>> > >>>> From next-20260304 onwards [1], including recent next kernel next-20260309, > >>>> booting an SEV-ES guest on AMD EPYC Turin and AMD EPYC Genoa has been > >>>> failing. However, on EPYC Milan, the SEV-ES guest boots fine. > >>> > >>> ... > >>> > >>>> Bisecting shows that this commit is the first bad one. When I revert it, I > >>>> am able to boot the SEV-ES guest successfully on both Turin and Genoa > >>>> platforms: > >>>> > >>>> e992bf67bcbab07a7f59963b2c4ed32ef65c8431 is the first bad commit > >>>> commit e992bf67bcbab07a7f59963b2c4ed32ef65c8431 > >>>> Author: Sean Christopherson > >>>> Date: Tue Feb 3 11:07:10 2026 -0800 > >>> > >>> Gah, I hate how KVM manages intercepts for SEV-ES+. Though to a large extent I > >>> blame the architecture for not simply making CR{0,4,8} intercept trap-like. > >>> Side topic, is the host actually allowed to trap CR3 writes? That seems like a > >>> huge gaping security flaw, especially for SNP+. > >>> > >>> Anyways, this should fix the immediate problem. > >>> > >>> diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c > >>> index 33172f0e986b..b6072872b785 100644 > >>> --- a/arch/x86/kvm/svm/avic.c > >>> +++ b/arch/x86/kvm/svm/avic.c > >>> @@ -237,7 +237,8 @@ static void avic_deactivate_vmcb(struct vcpu_svm *svm) > >>> vmcb->control.int_ctl &= ~(AVIC_ENABLE_MASK | X2APIC_MODE_MASK); > >>> vmcb->control.avic_physical_id &= ~AVIC_PHYSICAL_MAX_INDEX_MASK; > >>> > >>> - svm_set_intercept(svm, INTERCEPT_CR8_WRITE); > >>> + if (!sev_es_guest(svm->vcpu.kvm)) > >>> + svm_set_intercept(svm, INTERCEPT_CR8_WRITE); > >>> > >>> /* > >>> * If running nested and the guest uses its own MSR bitmap, there > >>> > >>> Argh! The more I look at this code, the more frustrated I get. The unconditional > >>> setting of TRAP_CR8_WRITE for SEV-ES+ is flawed. When AVIC is enabled, KVM doesn't > >> > >> AVIC is disabled for SEV guests (see __sev_guest_init() and the > >> kvm_set_apicv_inhibit(kvm, APICV_INHIBIT_REASON_SEV) call at the end of > >> the function). > > > > AVIC gets inhibited globally, but continues to be enabled on > > vcpu_create() opportunistically -- see kvm_create_lapic(). It only gets > > disabled later during vcpu setup via > > vcpu_reset()->svm_vcpu_reset()->init_vmcb()->avic_init_vmcb() > > I'm just saying that the unconditional trap for CR8_WRITE isn't flawed > for SEV-ES+ because AVIC can't work with SEV, so there isn't any time > that CR8 writes shouldn't be trapped. Yeah, I forgot that (obviously). But sync_cr8_to_lapic() is very broken, no? INTERCEPT_CR8_WRITE will never be set, and svm->vmcb->control.int_ctl will become stale as soon as the VMSA is live, and so in all likelihood KVM is crushing CR8 to zero for SEV-ES guests.