Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp787131lqm; Wed, 1 May 2024 16:17:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWi4nmj+G/yZ/Hnx3HKBvyVsCB7kZlJuICYOVUPxSS6zemul1E8/8/Y7XV3oKpO6AfLJ42F4KGIbQxIA2FwdNYJjF3i61vEBtFXtSX+6Q== X-Google-Smtp-Source: AGHT+IFefcmo/zKvFT+CIlKCS7/y7JKKSMxDFTNu9J00uXv9EBGG05JMwqQS9WfMzpzJKJu0FPVS X-Received: by 2002:a17:902:ce0f:b0:1e3:e081:d29b with SMTP id k15-20020a170902ce0f00b001e3e081d29bmr5138344plg.45.1714605454398; Wed, 01 May 2024 16:17:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714605454; cv=pass; d=google.com; s=arc-20160816; b=J7+aiNC50YL8eqiu7Od/Uk7DpfoTidoE6ch2k95xRM2kHS8EH/zK0lf6Pv/+YuHHH6 u4AZ0CjGoO5fDp6XURlrkZ9mCaQ1fkQBd+csOLsldTbnIXw0eUuyuKTkB6Qhytwj6TrK UFsx0AcK5oE9kLcXKJNEPkz3J76r4La/5Skj6w3otN1bNnpuacuXsCiOpMSZ9v84kdUv LIfnPyPjDSH9C+dMph6h+o9Sx2CPuJ87Benf5zdQomfPSyvjerwNx98389VGLnxTuLpf Tei7Bpl8Ex8na7MSqIqDXa92nkmo+Q8QIJc0ngEN6XJ+Xh+E/Ev5KPungr3Hd9cPW4sM es5A== 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=rLsdIwymTCHMRiGzZhz/oYnmKJwch+ZfMdjTvC31E8w=; fh=pAW0K/jVXCnaKl+gQLWoMwZGE50xQF4hRU91KTAnqRQ=; b=NULS6MmNjX1m8CRGVnubGggJZ+L5wvBVcWEmM+WHXjXwP9eayodQmhjSnTuwfgVStH 9QZynap5a0muH3+qvKAWSlD0uf0eVs/JBKcQ4Asdl1/Y46K+XCdDcJNoR4+3BZWsu2fh qKcESZB1SsxaAtumMWEoslG2+4wQ76CrPj7GBHW9ZdsyS4L4xGEM01etoZKZrXGbCdAE LmJq7NW5DcpO/7iYuk4tO5qosKkXnCVEZBywDjNFZkDXBVqro5k/APij853A93tuh0sI BVy3nofjxotJDKXlFL+/k9sAc3Q3CIAY/vajvR4i9f2BZ9S4l/fK8wI5AneAl0JixJVB tr0Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=sNHY3byj; 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-165828-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165828-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 lv14-20020a1709032a8e00b001ec6933ee1csi3490908plb.376.2024.05.01.16.17.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 16:17:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-165828-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=sNHY3byj; 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-165828-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165828-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 61AF4285B89 for ; Wed, 1 May 2024 23:15:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7B43C168B01; Wed, 1 May 2024 23:15:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="sNHY3byj" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 4D4E54D9EF for ; Wed, 1 May 2024 23:15:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714605333; cv=none; b=ngzjkC8c3FHxiprMRA4YKLspgQA3e5H7MnXqzU1JB+J/bWGJNloZX3fjgrEgM/lffBJls83KxVGCsobO/lK1Il3UFZ8JdCtl4oZt/WY8X6el/9hgn04WQZTf5tNPDxSqr0fp6bJbzuavlqJMulkspiaun7rUclGBRkJ9RChdH8k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714605333; c=relaxed/simple; bh=3AM2EWff9SwBfyQdM1iIgurVCO8gQYGt1lNkAfst2vM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=n2DgJ0VLpff+xLOCb4v1SWTuTYJFOf1nUFTF52MzOLsXjzu3GjzuYmfUVfivAIclODP8unQPb0pu4+jeGBJkjCUouHZI3SGfc6Sqd7GijCEp7uCW8+3tSbb3ywvvXKIV5tlbxOQzCOFzF3K1snuW9mZEJPjt3+A1bSl3hzSIVmk= 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=sNHY3byj; arc=none smtp.client-ip=209.85.219.201 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-f201.google.com with SMTP id 3f1490d57ef6-dc691f1f83aso569737276.1 for ; Wed, 01 May 2024 16:15:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714605330; x=1715210130; 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=rLsdIwymTCHMRiGzZhz/oYnmKJwch+ZfMdjTvC31E8w=; b=sNHY3byjO3koyPG2YQ+HHE8hcMBqJr/Z1+sayNL28W8riMusWbo0YsEDsqm36jR9of LRoNJq4mL64tnmhAPB0Kjhi+FVUY3OGzuEEnjxL0t7kFPeZUJH5S9G5bGik9rjUVwC8Y 54IynVwEoLG7Vq1bYeLmi4Rkl2/2b/mHHeYQYuqMsw11Nq4oiLNre8zAxIvTHpC/evUz 3gv0l/z8WYSPk6lgPQvWVzly2SAj0Vut/XnG99mUJp9kwkARSHvB3JvusUKAB2EJFlkQ MV73VVKLGOspzSQpEM0/jvYXe8Ds2/BaPaQZXF5KEgZTfhWg9GhOk9ccO2OaG9cLzt8L RmTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714605330; x=1715210130; 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=rLsdIwymTCHMRiGzZhz/oYnmKJwch+ZfMdjTvC31E8w=; b=mu35wtww0JySkWlVTDzLbqLtRw/nx382Ypcigj6W3/Th+DGOpliiY/sU/1mpf5B3Xv mFOXiXtrM3gK6IEGVYyeCiKCfI2fesEMtx63jCCZ1zBzdV8Wp6PtbG3cmGf5nxro6kTy wlP4VTFP63fdgLAcZuXtZ5qtL1z+eZCYJHX9XrTPqfj0WLdXvYPwgNktnyo59EQuyj34 7abfSzWN7TgS6kUtfFuJ1EN6LpRq54Oe4WTvJxWZiChsVGwgEt8rAAnf4NVOqrZfZjJc z9TW5pp13RyS11a5qgCpxXb/wDngPGobe4mFF7iJavznzf9yzZ6D35RBxTaRhm4YC7Wu CkmA== X-Forwarded-Encrypted: i=1; AJvYcCWu1XMNUcZctAJWZZ5j33cZKbeufBBRrmJi5N6eH2GdOqu80CDLHwN9o6JRi7c7V7QWzq7rqA8eulWpg3O3vGKwfzJK3+gic2srA6Z3 X-Gm-Message-State: AOJu0Yx/bIKiooSJneCu+Lfaw1nO6Bg2xiQB9DNRNw7Y6JIDibcaUE8s gYxl5pJK3e8ScdW01Ao9SHMqQHp77cJaKXJJoAbYgaye15eqvrUG1twDTwRoTAmWu8YBHBgCM3Y JGQ== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:100a:b0:dd9:2782:d1c6 with SMTP id w10-20020a056902100a00b00dd92782d1c6mr263457ybt.1.1714605330246; Wed, 01 May 2024 16:15:30 -0700 (PDT) Date: Wed, 1 May 2024 16:15:28 -0700 In-Reply-To: <20240219074733.122080-25-weijiang.yang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240219074733.122080-1-weijiang.yang@intel.com> <20240219074733.122080-25-weijiang.yang@intel.com> Message-ID: Subject: Re: [PATCH v10 24/27] KVM: x86: Enable CET virtualization for VMX and advertise to userspace From: Sean Christopherson To: Yang Weijiang Cc: pbonzini@redhat.com, dave.hansen@intel.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, peterz@infradead.org, chao.gao@intel.com, rick.p.edgecombe@intel.com, mlevitsk@redhat.com, john.allen@amd.com Content-Type: text/plain; charset="us-ascii" On Sun, Feb 18, 2024, Yang Weijiang wrote: > @@ -696,6 +697,20 @@ void kvm_set_cpu_caps(void) > kvm_cpu_cap_set(X86_FEATURE_INTEL_STIBP); > if (boot_cpu_has(X86_FEATURE_AMD_SSBD)) > kvm_cpu_cap_set(X86_FEATURE_SPEC_CTRL_SSBD); > + /* > + * Don't use boot_cpu_has() to check availability of IBT because the > + * feature bit is cleared in boot_cpu_data when ibt=off is applied > + * in host cmdline. I'm not convinced this is a good reason to diverge from the host kernel. E.g. PCID and many other features honor the host setup, I don't see what makes IBT special. LA57 is special because it's entirely reasonable, likely even, for a host to only want to use 48-bit virtual addresses, but still want to let the guest enable LA57. > @@ -4934,6 +4935,14 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) > > vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, 0); /* 22.2.1 */ > > + if (kvm_cpu_cap_has(X86_FEATURE_SHSTK)) { > + vmcs_writel(GUEST_SSP, 0); > + vmcs_writel(GUEST_S_CET, 0); > + vmcs_writel(GUEST_INTR_SSP_TABLE, 0); > + } else if (kvm_cpu_cap_has(X86_FEATURE_IBT)) { > + vmcs_writel(GUEST_S_CET, 0); > + } Similar to my comments about MSR interception, I think it would be better to explicitly handle the "common" field. At first glance, code like the above makes it look like IBT is mutually exclusive with SHSTK, e.g. a reader that isn't looking closely could easily miss that both paths write GUEST_S_CET. if (kvm_cpu_cap_has(X86_FEATURE_SHSTK)) { vmcs_writel(GUEST_SSP, 0); vmcs_writel(GUEST_INTR_SSP_TABLE, 0); } if (kvm_cpu_cap_has(X86_FEATURE_IBT) || kvm_cpu_cap_has(X86_FEATURE_SHSTK)) vmcs_writel(GUEST_S_CET, 0);