Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp285463lqs; Thu, 13 Jun 2024 09:57:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWRZgUGSm+n3+SLhr5f4BPdZ1rFSjGG3b/vh7H0Ma8NklVEXMXZa36/5ea9p45AKA2/8T1/0o8gSyz/6BUZ9nCrlBaacDWcML4yC/HTww== X-Google-Smtp-Source: AGHT+IFNSuSQbin2bzyQo3CimnaumDk3rTw1YPLYMnPKCEV9xTuPp1dya9rYaoEGN3aAthgkf1qD X-Received: by 2002:a05:620a:44c4:b0:795:5981:583 with SMTP id af79cd13be357-798d26a2ab5mr7695085a.67.1718297878372; Thu, 13 Jun 2024 09:57:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718297878; cv=pass; d=google.com; s=arc-20160816; b=Ttx3xKO9Id4bQFDrzlPkgqAHLSjmEFnZ/kR9VbCIQIeE4HIbLGwbq9jQPqUn80V8ND Ag4mE+oS2+BVIn9BFRnUrKklG/x5+eUKthvrqITLlG0XRnR01pcS2RksdxCQf2jAvkBP PAgRQYVITnFCtnkRgvF6l5Uag9c68za0W5CSw5/NIuXdtbpjxx8scUXRGBzZWPS9VBMX DfORew7PpYb72n3170Nu9fTdVsgtbESKifx3wc/i/1ItJH6JMH7geSWHEsC/huHU2uWG IlUcYFoe7frJ9Uou7p8cbbscrkB6eUH3TIUfrl06hp7uLeYswwDkq0Xn7yVIN+HYQmPK bgQQ== 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=4d54lSkwQxb+qpzxsG/q3gJ1Ug5mGtZ+nd2FA07+/50=; fh=uzCrZMsEnMDs/MfHVUnv96LpYzP7XoyfHkNMvKnZn4s=; b=KPWg0t0gqwuD/pL+RwpavIiU8qD3L+I0IX1LWFEVUc9/LK62DNOLjvsroPNohoqCnB HWlQZaMzcRili9zsfQhPTsxqEx4EHvlcVzX+cXVedVCIyo7NQMYn2qLm2z9jhVNkLm6R vWoKRlZW0cpOQKKu5A2lodXAut7jqxoDwstJcR7azrOI3RToTvv0/ks5X6RdVYl7TMVH JFt/AlPPz1+rFVpU2j+RnBqqzLjwyRWb5FtkGMz2e8zKgxLSq7+t1PT1L3g2e1sQZtdZ lKBMqXN1Ypi1Cxb+oBgBfp4t3cRXFs91ycbRf14iifTwNlDHcSlCSybjEbkHMASda515 sRvQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="0/fb2Y2b"; 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-213701-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213701-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-798ab9f9bcfsi170575885a.324.2024.06.13.09.57.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 09:57:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213701-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="0/fb2Y2b"; 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-213701-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213701-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D92481C24872 for ; Thu, 13 Jun 2024 16:57:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6B216149C57; Thu, 13 Jun 2024 16:57:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="0/fb2Y2b" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 3A0D217FD for ; Thu, 13 Jun 2024 16:57:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718297865; cv=none; b=WMgBwczHcwRm5TlyTiYtV8i/jxXYdvi5MV/sZugQYE4Z1m8I6nH//Zda7cAsgQLzviEid8zpOFYWn0VzCg7aDQTo6sJE4mIEOrcHBi1F0eCoQA/i20gn6Id5OyOv3y0F4x5W1BLrNd1FrhEP6r9876foTfn5B1Dz6kdDxkd2VtU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718297865; c=relaxed/simple; bh=vL3n1P+q2IBBOi6oygriT7cY6UeZAqtzHG3QyT41Bkk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=C1NXM6Ts3tXlyNPAtPcgHr4LlDLwM0XM7M7O6FnAFnBaxYjvhIOoW4p1i+wvGr43HJkRly6Bj1R11dfDjEG9tz8lxPJnXawvAXaubWZgjjeWziaD20gvrv7N5oDz9K9Kito9FsyD4kR5Luvl5FlnDlw5JLsElTomj1fznAyvHYw= 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=0/fb2Y2b; arc=none smtp.client-ip=209.85.128.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-yw1-f202.google.com with SMTP id 00721157ae682-6312dd49229so15919567b3.3 for ; Thu, 13 Jun 2024 09:57:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718297863; x=1718902663; 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=4d54lSkwQxb+qpzxsG/q3gJ1Ug5mGtZ+nd2FA07+/50=; b=0/fb2Y2bOgaCrpafZwTD9ZWi+uqEz6qzoiuoaRcMDmxKVwE7jOQIDH1lWZVxE7ZJPm Gm9K2IyGlOtkq5tbQoiZFviBLeKDX7tfLK+iWHF66m489WHVLObKNoSsFugQgVn+WpVf KG55Z9TKkQ7qfoDzjLZWAAIn8UnOpo32J234a3jV9fCh3DWBes5VwPnie0DDhdAyhouU 0fNAp2ECFb6Ws4g6MfGoGT9oSqL78qLuD/0EeprzD2l9XizwZZCUHe4xUglLSW6PYSoe d89ns3zEQZssnwOXTViWaZc1HJ2fE8XrbE2zZEjf15HjLRw2lurXChV/a21feJaHE7Lr f3AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718297863; x=1718902663; 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=4d54lSkwQxb+qpzxsG/q3gJ1Ug5mGtZ+nd2FA07+/50=; b=NEJ3RdhhXe9M72hFi0wnXFzcKwiAsMypWATxvB1OBocLPeW+Xa/Vh2bsYVH+iAXbvV RO6VQfH87QOjjcREmH3WqOog+8xeHCnOI1Kfn38FrahREquYfAqj4vR1UToPQ1pTztD6 tFtYCMwLDvf7d3seRec1P15RWMot0o4+8y2pK5xrqtVzVscGIS0O6TkfvMV9HjfI+Tub +Uaw+rDQDQAWbtsX4oW/RUk8nUBnT+c002Be43g1w4oGu0+9idV9UdVtbjNTCpAHp70w 0bBIXYVr0Lh0J5rcbglspQeVsOHMqOXhS2KuQRgxGsrkiv4Pt7K1yMTe9TWUiH0rFZyD XGdg== X-Gm-Message-State: AOJu0Yxmy+NbbP2yGBA+4LFZlxbwxXL+BDupmDCJcSWuNkmGwVkWELGE kusatuQvSNbYbyszVsCukmT6prbwGANs7Jx+2sOMN7y3wO4n8fVeq8I3bssmNpFNPnmNXKXuvmg oNg== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:690c:6706:b0:622:cd98:3b89 with SMTP id 00721157ae682-63224b005fcmr8987b3.9.1718297863344; Thu, 13 Jun 2024 09:57:43 -0700 (PDT) Date: Thu, 13 Jun 2024 09:57:41 -0700 In-Reply-To: <20240207172646.3981-13-xin3.li@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240207172646.3981-1-xin3.li@intel.com> <20240207172646.3981-13-xin3.li@intel.com> Message-ID: Subject: Re: [PATCH v2 12/25] KVM: VMX: Handle FRED event data From: Sean Christopherson To: Xin Li Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, pbonzini@redhat.com, corbet@lwn.net, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, shuah@kernel.org, vkuznets@redhat.com, peterz@infradead.org, ravi.v.shankar@intel.com, xin@zytor.com Content-Type: text/plain; charset="us-ascii" On Wed, Feb 07, 2024, Xin Li wrote: > @@ -7382,6 +7419,24 @@ static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu, > > vmx_disable_fb_clear(vmx); > > + /* > + * %cr2 needs to be saved after a VM exit and restored before a VM > + * entry in case a VM exit happens immediately after delivery of a > + * guest #PF but before guest reads %cr2. > + * > + * A FRED guest should read its #PF faulting linear address from > + * the event data field in its FRED stack frame instead of %cr2. > + * But the FRED 5.0 spec still requires a FRED CPU to update %cr2 > + * in the normal way, thus %cr2 is still updated even for a FRED > + * guest. > + * > + * Note, an NMI could interrupt KVM: > + * 1) after VM exit but before CR2 is saved. > + * 2) after CR2 is restored but before VM entry. > + * And a #PF could happen durng NMI handlng, which overwrites %cr2. > + * Thus exc_nmi() should save and restore %cr2 upon entering and > + * before leaving to make sure %cr2 not corrupted. > + */ This is 99.9% noise. What software does or does not do with respect to CR2 is completely irrelevant. The *only* thing that matters is the architectural behavior, and architecturally guest CR2 _must_ be up-to-date at all times because CR2 accesses cannot be intercepted. So, just say: /* * Note, even though FRED delivers the faulting linear address via the * event data field on the stack, CR2 is still updated. */ > if (vcpu->arch.cr2 != native_read_cr2()) > native_write_cr2(vcpu->arch.cr2); >