From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96853C7EE2C for ; Fri, 2 Jun 2023 21:50:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236802AbjFBVuL (ORCPT ); Fri, 2 Jun 2023 17:50:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236580AbjFBVtu (ORCPT ); Fri, 2 Jun 2023 17:49:50 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFFDD1A5 for ; Fri, 2 Jun 2023 14:49:48 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5659c7dad06so39219167b3.0 for ; Fri, 02 Jun 2023 14:49:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685742588; x=1688334588; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=nefBGxsNaEMoqb2mC8n3j2OvjLQc0K598TL3kgSXzFU=; b=aurBhqbKeOJz/AyMRAeO/7yWA5uxveScJZDdPbJybfzRJXg5iNEY5FZtEV7uSUvzCU PtiChI5pW/pP6OFoY63g3yXEQyjmcXN2hwcZpKKkWFZvcEXYFOkXFWlbLPW29jRLfKQb +u4blAhi4jofaqKLqN8X27ittdB8oe0nXaYmbQjzTXdwQSFkywSd5Otp5phYr6G78xao IYKc3WsSxqVyRJZqSylJOpBqoyF0QXpgXt0GZwK98gzhGpF1vKze4/wrmShW8+ZlueOz oeZZTRIS1SIRWW60Bdq5uVIv2M4e5yHlD8HQUTXXJAj9oMGDGTniLJfqvMbpRV+8l4yD opVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685742588; x=1688334588; h=content-transfer-encoding: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=nefBGxsNaEMoqb2mC8n3j2OvjLQc0K598TL3kgSXzFU=; b=jNJQ1IgoJ0p9Fdm1KqWwV/X/hPLRZK3NdykQcriisahWaK2O10QZ5h0zC7d1gszPh1 ve93QTufErOw+84WgIbDVWqCMKkT2rdlO9yuJa9q4jJWE/PQsywU7wdfpSRKACve6LUW +irWMZtjUgyHBmIJBlOAfBsk6/H2XBhutC9j5SEMVo4YKijcxRmFU40UMSi/onqVKwhg OIHXEEZA0n8uH+nJMkmykWKPK+vD0G5F3iluh+4NcjDgCy+9lr9wLOLh+QbyDmggBFcM 50do0RjxlNElZoZ4Y2qo4JMXsfGaQUTZiDb/lYF4x9SxeDIFVj6BMKRGIwDsEovgxP0m 0jQQ== X-Gm-Message-State: AC+VfDw8mlWojl79Jo8jylXTAySpa3YkUbD2MbIy6erWyU6ulew+oJE/ BbdQyTDhsu2aUuvALfWa/7y+jKs4e9w= X-Google-Smtp-Source: ACHHUZ5egV/UIPDs3RgIUBEXXI8beMvTpFWkwRh8/lCmke0ndg+wwSUO5jvBndae09dX3oizTe2mi7Dhp9M= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:af64:0:b0:559:f161:f052 with SMTP id x36-20020a81af64000000b00559f161f052mr639983ywj.2.1685742588103; Fri, 02 Jun 2023 14:49:48 -0700 (PDT) Date: Fri, 2 Jun 2023 14:49:46 -0700 In-Reply-To: Mime-Version: 1.0 References: <20230602010550.785722-1-seanjc@google.com> Message-ID: Subject: Re: [PATCH] KVM: x86: Use cpu_feature_enabled() for PKU instead of #ifdef From: Sean Christopherson To: Jim Mattson Cc: Jon Kohler , Mingwei Zhang , Paolo Bonzini , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 02, 2023, Jim Mattson wrote: > On Fri, Jun 2, 2023 at 8:51=E2=80=AFAM Jon Kohler wrote= : > > > On Jun 1, 2023, at 9:05 PM, Sean Christopherson w= rote: > > > @@ -1032,15 +1030,13 @@ void kvm_load_host_xsave_state(struct kvm_vcp= u *vcpu) > > > if (vcpu->arch.guest_state_protected) > > > return; > > > > > > -#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS > > > - if (static_cpu_has(X86_FEATURE_PKU) && > > > + if (cpu_feature_enabled(X86_FEATURE_PKU) && > > > ((vcpu->arch.xcr0 & XFEATURE_MASK_PKRU) || > > > kvm_is_cr4_bit_set(vcpu, X86_CR4_PKE))) { > > > vcpu->arch.pkru =3D rdpkru(); > > > if (vcpu->arch.pkru !=3D vcpu->arch.host_pkru) > > > write_pkru(vcpu->arch.host_pkru); > > > } > > > -#endif /* CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS */ > > > > > > if (kvm_is_cr4_bit_set(vcpu, X86_CR4_OSXSAVE)) { > > > > > > > > > base-commit: a053a0e4a9f8c52f3acf8a9d2520c4bf39077a7e > > > -- > > > 2.41.0.rc2.161.g9c6817b8e7-goog > > > > > > > Thanks for the cleanup! > > > > Reviewed-by: Jon Kohler >=20 > +Mingwei Zhang >=20 > As we move towards enabling PKRU on the host, due to some customer > requests, I have to wonder if PKRU-disabled is the norm. >=20 > In other words, is this a likely() or unlikely() optimization? Neither? I don't see any reason to speculate on guest state. I'll bet dol= lars to donuts that adding (un)likely() is negligible in terms of performance.