Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp284419lqs; Thu, 13 Jun 2024 09:56:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUwmq0TXhFvaVVgqrKPHNdbqhZWTDrRxiVI/WBIWfXDNDuF8eujLInd4lgyjKa+IGhlfcN5LXxxUKe7p6i3wgRt/Hjp+R5iX1BYb/26Bw== X-Google-Smtp-Source: AGHT+IGTnQxFmkk5OLUZCStxtOwvmAIaukyHBVqqyYBx9EZEYyiF41QdwhyzJMIzAB88BosJrFgO X-Received: by 2002:a05:6a20:7485:b0:1b8:b517:9c0a with SMTP id adf61e73a8af0-1bae7d9b825mr520392637.5.1718297761504; Thu, 13 Jun 2024 09:56:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718297761; cv=pass; d=google.com; s=arc-20160816; b=jffnsNqNdEwRsmqpvxyXg6JXcwX/buwZwjqRjTbtdoLw+4f79L8/78n1t04QXUiz2G 0y71LQQa1xZI5nxDZfxkp/xYv/nrpRolDpU0G/ZwNavbWh7WJT5cJBNwC5qz12pjS9xv AYtqJajVLmMZ7bOP4yeiEuxqb1vnZeD0PEKCw807us1wbvTmqPfapnDfkFqG+0ZNvlbd GmhdvoX5W7Q8nYVV27Q3JNDdCU7cLm4/qfwvkMoewlwMWIchnzyXhAvC6Od0u2EIIC98 hgk4AojiMCg56x3gp10qKlb/PaIDtOMWVetJOQddgSUSgWiGrJz/cWfN0yKknbeEeF1Q A3vA== 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=f9CYt9bUQNxiXkzpZqytzyg53ZWv58TJdgtMwrRPm6U=; fh=uzCrZMsEnMDs/MfHVUnv96LpYzP7XoyfHkNMvKnZn4s=; b=HXfULFlqOAjGBqT35bFOeUjMiJm+VYXqS5wrYjsqT/ZbXOcmkVPXKZ+Z19ooDbbLND G7MZv8bNvDLhYuc2LC0w/CaPx3e4LI9t/xCBbJEmvUpUdq2Ndrn/Hn5V2JNR9eoiAqdN VDn9ry/HAuch6w/rEkOkBHt4NExAKa/xsp2XP36J6QwW46vv13jiQ8sBn6wWbH/Hr7W4 gXw+5SdyEn6WThCLm6dbEMigF8La0l3+2r6wY7uSbVCkrOuvh+Bhaedc/CMP8po2niQB sjzmx0Qgb577FujCpvm+qygho0deU6pHFyJFHtHlSlQ3CO+EFZNjKdp80LxZjkC3q7Ai PwAw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=lPSXC9he; 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-213697-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213697-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6fede81ffa9si1607598a12.194.2024.06.13.09.56.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 09:56:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213697-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=lPSXC9he; 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-213697-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213697-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 71FB928662D for ; Thu, 13 Jun 2024 16:56:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CD4C914A089; Thu, 13 Jun 2024 16:55:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="lPSXC9he" 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 DA94D26AF0 for ; Thu, 13 Jun 2024 16:55:41 +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=1718297744; cv=none; b=HNWQ4vCjEoI3UjX/FvZ/BvEhxvOO2BH7Ty/CSHE0KJJLTSST488/i8x1KaqETdLWJPMv10F4xa2pCYuvypNYTf2WRHm8FOOtCY6Ivv6nsVU1EpBPsi8T2uiAIPzVbea65b4Ekm6JA4akPlxUpNnkGyH+i7whWYEOVtHxGgMuEDs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718297744; c=relaxed/simple; bh=JBcO41UleHNq3lhHasPs977C4yzTa+av52awcjkovk0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=pjMnFZf228kcvm1NcXmL7qLoYy1HBV6+dlXEJRBhG228pNmn4haV43JsJx7+YDkxXP6kdWR5dlQW7Rgpv8Iamnw86bV4csj7lKOowh8BzLhz+wloZoutrca8OhKQoabMFwNyY3yHqSaCIeJjg7TauBBa8CFaEODu/u9s55zfCGI= 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=lPSXC9he; 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-dfefc2c8569so2389813276.3 for ; Thu, 13 Jun 2024 09:55:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718297741; x=1718902541; 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=f9CYt9bUQNxiXkzpZqytzyg53ZWv58TJdgtMwrRPm6U=; b=lPSXC9heprNeF8vL2j4xpLJh3aiTpXy9XicaYRrOPgkQlY8jqYcB26meROjBBxof19 aKypBhw7bwuWFGZP5z3t/bWSVqHFDQHwXTVXEZRvdMU8mkGtXPIjG4r/NNYSsOp8Hqj2 oIrIEZMQ4d2UfQ5Rgperkj9Zb9KmyDQ33LAsFYNunEI0P3ZqpWfKtx1hKOFfe7zdyUgx Dw45r6nR9vOREuYDYzDAxYchjT/tKPWhUwLk89rmY2MDGcCg/mPG+jeo8z3ncHn5DQhS tZAgHZUL8/PpBWlGwB+2X2ePpqD86UTrpYVE/lVKZr8ZY8ORn783y2l4M79pozTSrQ00 34IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718297741; x=1718902541; 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=f9CYt9bUQNxiXkzpZqytzyg53ZWv58TJdgtMwrRPm6U=; b=Z5RKLec/ryRFIIqkD+5RBfS1eMlpLYnHTyzlWf4ZyXZjWabNoMRgBACNp5mSufv6oo k4jsoPycJoxJeVghPHN0zachxahJLTJ8pIBGmnFLXJXdsEO98LsuzH32qJ2kA8gk6v4j ZrhFmk4mDvtHEFxuSJkGyBM7NM2WqFIsJ8AWV4FjwoyEn+gNS3di6t9Tc1c5fUAB4o4/ 4ghUYGFt2GBm+wyibI/sCwJrta8BrOVigdVMRUwFKA581QHDrLZaMlzaUzDcKlcyObGp PPTXM4xMuvLMSgl+GahedjDBjoHECmgerN4eXjni4q8O0duPBPRUl9mkBr6voj6lCTCC pgGQ== X-Gm-Message-State: AOJu0Yx2hi3A3dVEYeTY3oFRvDSA0otugJs04l6GG8qmROCU5sNAY0ni d6tRQUnZObtNqFJLp7qImPuTiBaL48P6puCQrWii4rLNHEB3m7uikMIO/In6/tseeIm5WzZUYkg tmw== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:100f:b0:dfd:d6ec:4e3b with SMTP id 3f1490d57ef6-dff15399367mr1866276.7.1718297740902; Thu, 13 Jun 2024 09:55:40 -0700 (PDT) Date: Thu, 13 Jun 2024 09:55:39 -0700 In-Reply-To: <20240207172646.3981-12-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-12-xin3.li@intel.com> Message-ID: Subject: Re: [PATCH v2 11/25] KVM: x86: Add kvm_is_fred_enabled() 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: > Add kvm_is_fred_enabled() to get if FRED is enabled on a vCPU. > > Signed-off-by: Xin Li > Tested-by: Shan Kang > --- > > Change since v1: > * Explain why it is ok to only check CR4.FRED (Chao Gao). > --- > arch/x86/kvm/kvm_cache_regs.h | 17 +++++++++++++++++ > 1 file changed, 17 insertions(+) > > diff --git a/arch/x86/kvm/kvm_cache_regs.h b/arch/x86/kvm/kvm_cache_regs.h > index 75eae9c4998a..1d431c703fdf 100644 > --- a/arch/x86/kvm/kvm_cache_regs.h > +++ b/arch/x86/kvm/kvm_cache_regs.h > @@ -187,6 +187,23 @@ static __always_inline bool kvm_is_cr4_bit_set(struct kvm_vcpu *vcpu, > return !!kvm_read_cr4_bits(vcpu, cr4_bit); > } > > +/* > + * It's enough to check just CR4.FRED (X86_CR4_FRED) to tell if > + * a vCPU is running with FRED enabled, because: > + * 1) CR4.FRED can be set to 1 only _after_ IA32_EFER.LMA = 1. > + * 2) To leave IA-32e mode, CR4.FRED must be cleared first. > + * > + * More details at FRED Spec 6.0 Section 4.2 Enabling in CR4. Please don't reference specific sections/tables/fields in comments. They always become stale. And the code+comments always reflect the current state, i.e. don't need to worry about spec revisions and whatnot. If there is a spec change, then there darn well needs to be a way for software to differentiate old vs. new, at which point there will be accompanying code to capture the difference. Even in changelogs, references specific specs by section number is usually discouraged. Again, it shouldn't matter if its FRED spec 6.0 vs. spec 5.0, because if there is a difference between those two, then the code better be different too. Instead, for the changelog, if it's really necessary/helpful, reference the section by name and/or keyword, as those are much less likely to become stale. > + */ > +static __always_inline bool kvm_is_fred_enabled(struct kvm_vcpu *vcpu) This doesn't need to be __always_inline, it's not used from a noinstr section. kvm_is_cr4_bit_set() is __always_inline so that @cr4_bit is guaranteed to be a compile-time constant, otherwise the BUILD_BUG_ON() would fail.