Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp19483rdb; Thu, 21 Dec 2023 01:16:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGHGI/k/wfswEk4upxvJRBDd53MDWMV7es0bgB+oN5ad6+d1iTNR/NVukxe1HCV0GeqrLcZ X-Received: by 2002:a17:907:9518:b0:a23:5814:4b76 with SMTP id ew24-20020a170907951800b00a2358144b76mr3058605ejc.35.1703150179828; Thu, 21 Dec 2023 01:16:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703150179; cv=none; d=google.com; s=arc-20160816; b=CXSkJLonWKbC0wexNd34h5ZT6Sf9hgIbMf1pW+X7NUyfsGCCXj5ib7c43xrXdaX2+d e+zAXVa5X8FGnZn5Y4lEQUzBm4lXKipZv8gCp+IkhiZQ8KrpDFTPTapdZLwUg0cTeiZy aH/U+2KA9sMxPe6BdydW93qZ+WXKYWkq+KjWay0mUN7atXt8d0GpkXkOc/LxyY5c0tQe n7k/hufTkBBA6+f1vcxsr3aJ2puiAvt0wfv+wGyeUhjb3u33IGXiOM6NJUwx0nat5+7H gPpYim7zrDMKr0IRhJ/d+ZCfdcrpL6nJf2K3yEFd6dieOEz8MvYIlyJCNJUdYqAo85A/ wCmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=AJ+4U2msN7QZ9ZpIY+THcHcxA5uA7/W3GKth94CrRwQ=; fh=uy0EBGgYIm8+MgsxUvKHUXUo3s9z4H9hdLwRv8YoeJU=; b=WpcS4xJf9neUiBvWZInLZeorT30mCY8FMln58WWH6V4MP+fWql+mn7tYiIaoebLD7R 4FKRoWm1bzT3lcpzkeWPG3mbSCnu+G+EJjpEhTowSL1ABsSN2WqXv3awL6QAxqXfm1rf lkDK04Oh1U/znmPZWp2KRaYtji/66q45LFkyAcX2xD0hWRm8GJ2jgeY4gfXCN9SxTerH veuYB0jxN2pcgBVrpzn01RUN8Px7lkA7QYLg5G+AJXEjwmrOB+r++qcImaaJs3O0smLm mAKjbHfyegshi/4Th18PeNOXYJ09fgCynKNA45LngoLhom1GGwgM0+eKDvzELLrErtRP jb4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=N1n1CC4F; spf=pass (google.com: domain of linux-kernel+bounces-8074-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8074-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 ey20-20020a1709070b9400b00a26a9c27fd0si199796ejc.140.2023.12.21.01.16.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 01:16:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-8074-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=@intel.com header.s=Intel header.b=N1n1CC4F; spf=pass (google.com: domain of linux-kernel+bounces-8074-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8074-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 92F281F213D4 for ; Thu, 21 Dec 2023 09:16:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 987DA56763; Thu, 21 Dec 2023 09:03:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="N1n1CC4F" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43F3454F88; Thu, 21 Dec 2023 09:03:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703149432; x=1734685432; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=F9opDfCZwYUSpXz1rhkoPf6Q6E9dmRJye3dTlxS+ZDs=; b=N1n1CC4F5ObPAITsmi0cegntltIVFM7nezGqCGuhZFQYXB2l9z3YddhF 5eDGToU9b38gVTTcJ87/k3a+kKv9dePa0Cwxym11Doc7MUJJlIMKK7oPH J7+K6TGPq05vpdltosm7m6Jttshbn/48D6qwtpzRt86S847yvabndtu+I z4wszExk6W1awXfRtMsAVNMadz6H1/lODSA7LVV1tWDl6bU+t6APX0036 eQINKLHWC0iws3d+mpYp1q9U48KlZXq2jj4vLIa5q5buuBb6hFs0CvDfR Jz9gVdrTlljaWJ6zWxtjtwOV8IrvO/BKei5cRvBz5ehxqAEOIX9ySlU3X w==; X-IronPort-AV: E=McAfee;i="6600,9927,10930"; a="398729672" X-IronPort-AV: E=Sophos;i="6.04,293,1695711600"; d="scan'208";a="398729672" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Dec 2023 01:03:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10930"; a="900028625" X-IronPort-AV: E=Sophos;i="6.04,293,1695711600"; d="scan'208";a="900028625" Received: from 984fee00a5ca.jf.intel.com (HELO embargo.jf.intel.com) ([10.165.9.183]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Dec 2023 01:03:11 -0800 From: Yang Weijiang To: seanjc@google.com, pbonzini@redhat.com, dave.hansen@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: peterz@infradead.org, chao.gao@intel.com, rick.p.edgecombe@intel.com, mlevitsk@redhat.com, john.allen@amd.com, weijiang.yang@intel.com Subject: [PATCH v8 19/26] KVM: x86: Use KVM-governed feature framework to track "SHSTK/IBT enabled" Date: Thu, 21 Dec 2023 09:02:32 -0500 Message-Id: <20231221140239.4349-20-weijiang.yang@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231221140239.4349-1-weijiang.yang@intel.com> References: <20231221140239.4349-1-weijiang.yang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Use the governed feature framework to track whether X86_FEATURE_SHSTK and X86_FEATURE_IBT features can be used by userspace and guest, i.e., the features can be used iff both KVM and guest CPUID can support them. TODO: remove this patch once Sean's refactor to "KVM-governed" framework is upstreamed. See the work here [*]. [*]: https://lore.kernel.org/all/20231110235528.1561679-1-seanjc@google.com/ Signed-off-by: Yang Weijiang Reviewed-by: Maxim Levitsky --- arch/x86/kvm/governed_features.h | 2 ++ arch/x86/kvm/vmx/vmx.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/arch/x86/kvm/governed_features.h b/arch/x86/kvm/governed_features.h index ad463b1ed4e4..daf0c0a3e29c 100644 --- a/arch/x86/kvm/governed_features.h +++ b/arch/x86/kvm/governed_features.h @@ -17,6 +17,8 @@ KVM_GOVERNED_X86_FEATURE(PFTHRESHOLD) KVM_GOVERNED_X86_FEATURE(VGIF) KVM_GOVERNED_X86_FEATURE(VNMI) KVM_GOVERNED_X86_FEATURE(LAM) +KVM_GOVERNED_X86_FEATURE(SHSTK) +KVM_GOVERNED_X86_FEATURE(IBT) #undef KVM_GOVERNED_X86_FEATURE #undef KVM_GOVERNED_FEATURE diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index b2f6bcf3bf9b..29a0fd3e83c5 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7764,6 +7764,8 @@ static void vmx_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_VMX); kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_LAM); + kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_SHSTK); + kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_IBT); vmx_setup_uret_msrs(vmx); -- 2.39.3