From patchwork Fri Feb 23 20:21:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 205647 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp827453dyb; Fri, 23 Feb 2024 12:27:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU3JHPfpxs3ZjX35XJxZQXjyIPeNiKR4Ye/TwRh8d8ez5Xebejb1ZaxIYFnuNp2nOSNE4VKlJxCYNh7ZKbJfK2E5QQzyQ== X-Google-Smtp-Source: AGHT+IGPmh+LoVQlKgqhfrRj/9onGnr0pFh/jrQuIU1moa37yQbLUQvPecg25bakSSJ4N4Y9w00x X-Received: by 2002:a17:902:9f88:b0:1dc:2d4d:45b6 with SMTP id g8-20020a1709029f8800b001dc2d4d45b6mr979829plq.2.1708720052819; Fri, 23 Feb 2024 12:27:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708720052; cv=pass; d=google.com; s=arc-20160816; b=iCtKRamHssEiGCD2KAHqvv0InzSMpZ/+UyIExehXNiEZEiAPRTXpZZ0fGq+SSC6Au4 ZuK6AvspVVKAaXKHaqbqrpNB5avFA9VKB2zIhdY0C4RBU4wK3rk/VKpzPi5zqKjGm+GE UK0L8p8iwyj8vtvmbic7r2Bvh7vGbRKyTqBKgq5G+7KpVwYZI7YYW41JrZLp0khu3er0 ier0Gx2kV3zWJLbKcEA5qE/uuJttBthrFXNYv8TETmRURm8cs7HOaEmrW5zISrfTfd9R nDdFDDNWF2w8vGGJzxfnyTa6fFz60CCd92UFq9m+ho3MU0g9eR47yVZElzd2o9hGA/Sb JA5w== 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 :reply-to:dkim-signature; bh=tyPTLCifBbTehT1oMnj3LiwEaJbfgbwYwJXO5JYENtY=; fh=Z9v6x5dJyo3ljyXDCMWYdbUpFr4ZKhWBvfdTmrZyIf4=; b=smi6jQ0kWkEq3To5yVz4Rg9W9fOJKeGg9jvNF38UItj/Uxx0IooigRC6ofhbyjRhj1 iY2hUlVK3gGvewDbJecSZc46iAAVI1/cqFhld5T7+xWIj1Cs25elg/eAKo82qOOMhwsZ NWDzbagY3NZ5oI7EQAOApW9SRQ9Zf+sxqQRNe3M2LgPTOO+PQ1MXmCT52PA9hILPU9TX u3kAazOD5Qd8JCa1TLLGiXisuX0xxXYIkPnaNK70jNh2aeo9sw79C9Hxv4zZb4C9fDDf KUZkzCT47ELZD3E8GDfgRBDO8f4ffnlx7wBez2mQ4pph18DhTeCcHJ/CEvcRLzpyCpci ib4Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="s9ot/QOo"; 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-79093-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79093-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id e1-20020a17090301c100b001db2ad550d8si12753656plh.134.2024.02.23.12.27.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 12:27:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79093-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="s9ot/QOo"; 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-79093-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79093-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 21659B27019 for ; Fri, 23 Feb 2024 20:22:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F1E8214CAC6; Fri, 23 Feb 2024 20:21:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="s9ot/QOo" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 930D4146E92 for ; Fri, 23 Feb 2024 20:21:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708719671; cv=none; b=TbIHNaDb3Un+mJdehxRNp8OJ+fjvKm0n2GxXNp7Iey2FghWiGV+4YGdp7BRn1qDEfzlnjECvKVUnsmwM6/XWkd/6Jwk0mQ6cU3RQrzkr/tR8Fxyw9rPF0jimsEDsvsppjbI0Q6YzoSkGTgTJLHK7MUvyJ0P3fk2AzTNHKw7ST7A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708719671; c=relaxed/simple; bh=IrRclgLzERlFlNP3VGcOQL+Anfa9GPiQX9sm7E4iwZk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HvM2ezIPLN9eAeWbSKxiaWlJS/MiVwetMEp+6OE4Nol06ClEAU5s23J/n51De0c6LHGnWzjcslr3VFgEZ8F6uHXMbvX5d9RhWdNybiLxH2SWVTn+LminzFUCyxcF3jaYR4yIGb5l/i1o3ho+eWxXCMmGN3waDbbGnBmpWP9h798= 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=s9ot/QOo; arc=none smtp.client-ip=209.85.128.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-yw1-f201.google.com with SMTP id 00721157ae682-6047a047f58so13176047b3.3 for ; Fri, 23 Feb 2024 12:21:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708719668; x=1709324468; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=tyPTLCifBbTehT1oMnj3LiwEaJbfgbwYwJXO5JYENtY=; b=s9ot/QOoa3Gfu8c/XqMU2eC8Y8M/mOM1VmZOxKhVJ7MX7yahmorYt8RghSP+suf3pq nIaILba5/ltROBxUv/YuZTHn74xfHGScNNp18IC0sqB5XkemZ7l6oOOqlOIGiThvSmWQ w/jZvmWnQ94y6AqDtToVqLQ9hLvPtBjUoy8+iZR7WkF9QpR3fMvsJIDsXwPlhCA0Toz3 FO/XbB8cBJIHHrzNRL3PIuE8oS1SrSwGyzrdVchZPaKwJzxoyYdCTEeZUuBR5qVYsrJE MXy9/3koG4Yec2yU14jBs0U6uRUh4sFjXKLIwihqmTlboOdNNlXl4maQmbSOSZ2V6Iph PpOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708719668; x=1709324468; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=tyPTLCifBbTehT1oMnj3LiwEaJbfgbwYwJXO5JYENtY=; b=s+qU/hrex9c03Yk9rQLoIR7pZEe8LekDbO0erHjd5LNUJPqxymeTnkfO+DOUsqR80a f+6IhZRyyONIbPvwF1m5aHmE8Rp0lRHJpT040h6GzmKKvqhdHwX1o4wB0Dj3MOJR4lDZ bEiyMknixl3lNnYcNUA7ruHATdQ/711TFj8tXpJ63vq2d1+ot7HBzyF+diu3rNB0cDch BqgerfM/hW6W2+XhoSuJVtacJ9fM37R7LKo2lpqWafuOQ6Y148/a/gRj1KiUy91+Vckc GZ8WWtH5NLDx8BlAOVB3q3JLnrll8JTzWvfzHsP7yLDgrEAOvRNiLXvnR7orEeZRJgH/ PXjw== X-Forwarded-Encrypted: i=1; AJvYcCUb70+DNykgfW96ueF++MWMBo5WnERwH20jAES6vV4MVUN2/sHEGrWc7GWsUqtcy10i2dQM/9f6tl2jhbRtRiiHH+cfYjCtoeDFZ/9J X-Gm-Message-State: AOJu0Yztg4f7/S+Lc2Y8QuPMvlSYPjpXipmOQ8YWkFEHuFvZKZkv33R2 WmYQLOgMXk0LyZUdep4tD6Q6gIBa/ZPQivN9yPNLMH9GszefyvFwYgaOqgM7SZfnhQMNIP4XCuH 1ZQ== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:5189:0:b0:dc6:d3c0:ebe0 with SMTP id f131-20020a255189000000b00dc6d3c0ebe0mr239480ybb.0.1708719668602; Fri, 23 Feb 2024 12:21:08 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 23 Feb 2024 12:21:02 -0800 In-Reply-To: <20240223202104.3330974-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240223202104.3330974-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240223202104.3330974-2-seanjc@google.com> Subject: [PATCH v2 1/3] KVM: VMX: fix comment to add LBR to passthrough MSRs From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Dongli Zhang X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791722838546682434 X-GMAIL-MSGID: 1791722838546682434 From: Dongli Zhang According to the is_valid_passthrough_msr(), the LBR MSRs are also passthrough MSRs, since the commit 1b5ac3226a1a ("KVM: vmx/pmu: Pass-through LBR msrs when the guest LBR event is ACTIVE"). Signed-off-by: Dongli Zhang Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/vmx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 9239a89dea22..7470a7fb1014 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -159,7 +159,7 @@ module_param(allow_smaller_maxphyaddr, bool, S_IRUGO); /* * List of MSRs that can be directly passed to the guest. - * In addition to these x2apic and PT MSRs are handled specially. + * In addition to these x2apic, PT and LBR MSRs are handled specially. */ static u32 vmx_possible_passthrough_msrs[MAX_POSSIBLE_PASSTHROUGH_MSRS] = { MSR_IA32_SPEC_CTRL, From patchwork Fri Feb 23 20:21:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 205640 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp825534dyb; Fri, 23 Feb 2024 12:23:02 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXbNEomCdP2wHfhZWczoWjWXW8fPh2WprpEDCtJV+t4hbohn/kZl1E96CdjdiykjlFWyO/SeSSz24JDaUkhfiUQmzJXPA== X-Google-Smtp-Source: AGHT+IEC6bi2TcLbKAsYjdBoY8xEh7feNpyUooD4D9EQSyZ0vVky8+qdXBUiX6Tk+5AY/KZvQ8Kx X-Received: by 2002:a05:6214:301c:b0:68f:6f11:912b with SMTP id ke28-20020a056214301c00b0068f6f11912bmr1060861qvb.21.1708719782700; Fri, 23 Feb 2024 12:23:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708719782; cv=pass; d=google.com; s=arc-20160816; b=Q+e1yKRYg8Opjf4DSMSsRrajHbZUeQwH1xmqjUXd3nKUe89t+OHILrAuXt47t/0vyJ borEONdSWoG/xnPWfHSlMo7W6HpR6NVjujfFAOLd3SDsIV0aDAVeha/ys4wtx79aMhy+ 8Fx1y8DoI0+xNHp7YAkN0Z7sAoU2xY7MnYUXk0+4ist8IPYAPvcxTjoX+0OzWwCmvG41 ShNmLZ7RaQ9NTmfbkwzzmh5bd2GKoRA1JiUsuF0qHLi0EGGsWgTeJFkBaMq/q9312OJ1 7mWtOwQVY3O8qXSHYdox7TuWLtkSLn+kywtKpe8e92oJQXu/tAmqOmTBckgknL2MzHeQ Mrlw== 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 :reply-to:dkim-signature; bh=SJIQNAlIsKGXsg0lFIYuueKE4jyUGKIK5OKq5RD486Q=; fh=ykUnnx4BgPvNrECOOXUzwP02ZFogvNldpJeDk+ROSoU=; b=ZYCiBK0P0WbZdhyKrrn08A7R5hhUhBkEMdDgJo8y4rD/PEO4VHBYwO3Iym6YYB2f+q sJBHZSeRR2IL2sXZGUrPN0Ya9dP/2EsoO0Tu9z0d/Mo5CNzGhr7uWYQUjuCms23EJA3C Rev5IOyNEcW8IWSKdWoMZVzH1CqnaALOdKc32RZQkfiLWkjaaiebMqgQARW+HZQ7tjQ4 QgQEY3lECHarbZxnJMtRM+ULehI6n1lzMzdlQ7ZIzN/26v2BvWrv1citGutFHt173Y2B 20vDXN6D+nVxRo5lC+76nMjBUteQ9jd56O9rJvhN8dLIDPcgIWCsqKX1g42p8/LGpH+j fbdw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=HXswtQXg; 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-79094-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79094-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id pt18-20020a056214049200b0068eda269640si16445051qvb.448.2024.02.23.12.23.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 12:23:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79094-ouuuleilei=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=HXswtQXg; 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-79094-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79094-ouuuleilei=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 7DC001C23BCD for ; Fri, 23 Feb 2024 20:23:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 47CB414D45B; Fri, 23 Feb 2024 20:21:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HXswtQXg" Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.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 2D65C146E9B for ; Fri, 23 Feb 2024 20:21:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708719672; cv=none; b=gSt+9OaFhZeJ9xSzdOu4bbEf8sBePWgpM7jw8KlbN1vythBz3RV1DUVi4WCzE7fYezj+Twn4WdbfERg4Co8E36qyp1Gwp+Hh8Y1WEr6p2YLh756UaxTwXZKO4NCQRH7xNiMY5+RRD/K/Ntb3CsGihEbgXpY9Q+JbfK20eb8TWTY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708719672; c=relaxed/simple; bh=HGThLVUxXYbVSOOZxCrgBI4/8udXcy4h8pBaZ8gILd4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eZc6UJqws00m8j1YwIcJEPv9pIRHexswxhafRDZ6uWQgRx/jI8WAJJM26AaskF1G0yDfnYZb7dS5Yjh66TC5ckH+72CyCosqGGeeTie/pbs2MtmDwe4Y3BI7jdjCHarCqpZUJUdpFuH9O7lDeqaN52AZ7lUk+xR/RmILI9C87Z8= 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=HXswtQXg; arc=none smtp.client-ip=209.85.210.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-pf1-f201.google.com with SMTP id d2e1a72fcca58-6e41d856114so901790b3a.1 for ; Fri, 23 Feb 2024 12:21:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708719670; x=1709324470; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=SJIQNAlIsKGXsg0lFIYuueKE4jyUGKIK5OKq5RD486Q=; b=HXswtQXgBREBdmoKabdRaJen+fLGcnUNFTYOZR0tnm9hpXuuoYpSAZNymOK8xD+le3 jYmcz0L+2WUypcToslY5SxvCEFPysoh21Iggl0rgdd1iS6rAONBBQNNfKRMGPcIjhD6W v55MlgkPuqkZYUbiBdtto5WuB4gOjTd3i4CW2fUv65qZ8huv4XlKiYYjklgLGJDPCr4t bQN7fHpdL4qOgJL40fZxWc56rXnPp58R4DBUfPNBGb4x/epv1uIqeStMICjtB1sJeEGa mujKs29fcmSIgxmfeb8hAUBf8140LMIffBdbI7DC8AJQV8uvEihwb8ozLO3J9QzwIdB/ liiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708719670; x=1709324470; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SJIQNAlIsKGXsg0lFIYuueKE4jyUGKIK5OKq5RD486Q=; b=Q4OwBLajm/O7nnpI+5pX9pMIKTBdAJL0vAiKcegdHgB2Z4zEl4pgFiZNIUC0uWGhst 8t506CpSSHuMGfCBNHjYPcHkfRnOVhw6EUuXjG0IkQ+NbiTq4L34YGhss0fLhuqBqXPG eC/g7YgcbZ10/EUGWKUauHu0lFMxuRF7dJcCLKIwp64XwkltKDje3Gzb44PZ2K29BlmL s6Vvhbtan5BlFRvGHNLG/pi6yABeqGBtYRjRaDgryhVQ4HyCERgwPvJcIUX6grhi3Glc sN87zu3LfLLAWKSCOHE1O4XqTtS8q8ohmmCXavLCjPNckUNeLjecNXtU20d2NzjkglCX Y9IA== X-Forwarded-Encrypted: i=1; AJvYcCXRDTBwSXLHLg0DoX2zLwkRrczUhR1XVLwNNrScACg6MgZ/461IurvyVeMT7jHTBSt4Qz02wwyVGaddbbo02IKSqELE9PyXQvEWph86 X-Gm-Message-State: AOJu0Yx/ME3k+bdjVdMF8mVq0NnRgZug9PKB0eStCu7eCcUCznt3Lrif BClt2KbiCtaVNW/FPiG4HRkbrgXJbte/2KDmibiQvYgCi1xLN+Lp3yI5RppJTDlCL/reYLkjhVx Vhg== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:3cd1:b0:6e4:8aa4:387b with SMTP id ln17-20020a056a003cd100b006e48aa4387bmr67638pfb.1.1708719670527; Fri, 23 Feb 2024 12:21:10 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 23 Feb 2024 12:21:03 -0800 In-Reply-To: <20240223202104.3330974-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240223202104.3330974-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240223202104.3330974-3-seanjc@google.com> Subject: [PATCH v2 2/3] KVM: VMX: return early if msr_bitmap is not supported From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Dongli Zhang X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791722555043670160 X-GMAIL-MSGID: 1791722555043670160 From: Dongli Zhang The vmx_msr_filter_changed() may directly/indirectly calls only vmx_enable_intercept_for_msr() or vmx_disable_intercept_for_msr(). Those two functions may exit immediately if !cpu_has_vmx_msr_bitmap(). vmx_msr_filter_changed() -> vmx_disable_intercept_for_msr() -> pt_update_intercept_for_msr() -> vmx_set_intercept_for_msr() -> vmx_enable_intercept_for_msr() -> vmx_disable_intercept_for_msr() Therefore, we exit early if !cpu_has_vmx_msr_bitmap(). Signed-off-by: Dongli Zhang Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/vmx.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 7470a7fb1014..014cf47dc66b 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -4127,6 +4127,9 @@ static void vmx_msr_filter_changed(struct kvm_vcpu *vcpu) struct vcpu_vmx *vmx = to_vmx(vcpu); u32 i; + if (!cpu_has_vmx_msr_bitmap()) + return; + /* * Redo intercept permissions for MSRs that KVM is passing through to * the guest. Disabling interception will check the new MSR filter and From patchwork Fri Feb 23 20:21:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 205641 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp825672dyb; Fri, 23 Feb 2024 12:23:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWcNxefZzsCQ5DwJ4XTL7cLE+2Rrj4OkszX2DGVyOt8JHs9bhsuHto+NwWVOBBDecSdtDKl36tQ4drAviaJp7JuLrcJGw== X-Google-Smtp-Source: AGHT+IEAdz+HJv37XcuuPEiPj69tSFPpFThzBWlGOgWgPVcdh0MGcL5YRwWngGIGTIuLVAGQ0PNI X-Received: by 2002:a05:6358:2923:b0:17b:6ba0:261 with SMTP id y35-20020a056358292300b0017b6ba00261mr1142152rwb.27.1708719798157; Fri, 23 Feb 2024 12:23:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708719798; cv=pass; d=google.com; s=arc-20160816; b=De3HyGlbC/awqKlqPVhwjbaxJW3gQX4Ure/ElvuZBHaAOWSUIUe2DGbP96k+itn3+n JjJ8IzfuZOWmHqSQFWe1dTtrWQAb0NLwIJcu7Jsrf9H1zcc7mWN1dy9Vvz0yZS4ZfbYq 9tAKdlYmSMwBls9VBH5//TRRtcak7F1lzObWpPYCxJcTuhBQtdhGW/yutGlhFBCnSDMr Kxop5UsPNC9tI9JPDd6CM8F23zBnzB3f1MFhPliBU2SiYYN7gvXTv48Nz6ja9kEMtKZk 2Q7ofZhFulBL2OOtTCljTys2FR6pgOM/6XjMVZZENPbMacNgjo0PmGAKMcYDdDbcGfDE unpw== 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 :reply-to:dkim-signature; bh=4AhBqaFKsEgrMMKsPnTb4KDGMvhddDO4DQwV/SsUl6M=; fh=hjhNgp9pt9rxaKUObiJEXVeBTsHkrXcmlwzxVWEGekA=; b=rk/ftVqpntLyN48wRBv3aJOdmc9aVRC2dd/MwghscP3aLUxTAEY1l180PIj6MpfSCZ jvhiSesVk/uRVWv1opjJpxbdmWYEXm9VMm+3lhvmVnc9E1tT0/Z5OQlykLfdIw14oVfZ Ik+jNMqh9OLBOsYSyJg5rDzqyETHjc6i1ilxD8bfUe0cxx9wmG0mT8c+5cs6QvQChr1S +tnUBwNswjNiscUcOv7Rppzyr3DIuhI230kIF1fQh8SqUBAy+6QoRFOOXr8KKxTT84J1 N2kM5Hjsi8IUf6RvQxWT/1xzTXXNtUAk+Rd98azYSDFYRslQeYPxomsdG2Kyz8Cjjgx4 kyOQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=wk+bWj8T; 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-79095-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79095-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id l17-20020a05622a175100b0042e6da8dde9si397612qtk.358.2024.02.23.12.23.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 12:23:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79095-ouuuleilei=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=wk+bWj8T; 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-79095-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79095-ouuuleilei=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 DCBCF1C2410D for ; Fri, 23 Feb 2024 20:23:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B6FEC14DFE4; Fri, 23 Feb 2024 20:21:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wk+bWj8T" Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 1D94014CAB3 for ; Fri, 23 Feb 2024 20:21:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708719674; cv=none; b=ckMcehqRv7rs8Co2vjxQn+jY2PgVZHR9Hooj9Pn5eYoipAtNNVwjryniJ1mk86RbPOrTwvrVZPoxPjV8LOePlsX1hzOD2Y+uqDDQdQPKxbg3CoQ8/vzdjLSmzi8zITO4SH4fVMw0Z5mMG1VQ3Ow8IhIU41SRpa5iPWI0AfZOMHI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708719674; c=relaxed/simple; bh=+lJk5AK8dlVL05cps/qThtV9mpJgp251EZLu0QB3UtM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=iy4i8nFGow/ESP3VwB3FK2PEzVzklyN4wRpi6vcD0Yp+TLX2Maem49+nHDkE9t4QIO19n7vpC8rXVyN8g5SvRDOedc8UeWKtyK5mAsMASxWkojRf8IYSplJyc82iJ3a3zBIETex0ehqBAuHJZ2KL7YD004BaoVg9VyBYSpTBItc= 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=wk+bWj8T; arc=none smtp.client-ip=209.85.216.74 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-pj1-f74.google.com with SMTP id 98e67ed59e1d1-29a86539b3cso340640a91.0 for ; Fri, 23 Feb 2024 12:21:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708719672; x=1709324472; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=4AhBqaFKsEgrMMKsPnTb4KDGMvhddDO4DQwV/SsUl6M=; b=wk+bWj8T05NuASRY4t99y3sPoOQodcX+XY5Y/efVhoDnzqIR/gZsEv/FDad1IUMNdw TqZFbnNwa5YOi2aVNeWL/Nly6lvl8U2+QMHAyotSt6cRhSRe0HSzIWyz6GPEmCw2sqPg 5LPOUmooA8UHT5pa0Lq3csjGLkSSZocnMFOlbm3ZK3wkalpEJCo158N2xoiQcB17ChXu utjpYd4SOdO4I+TTJCCQdG4WJNPHOgxHitNsbIMv+AAjk9Kdo1GXlkK8w+JQMmQZaivR nGIj+UD5DhwNbAjMp1w72XoZLDKWudIHnhkF5qNYKEVogbsFaMiRtPivNLEltiHN6DdO Idsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708719672; x=1709324472; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4AhBqaFKsEgrMMKsPnTb4KDGMvhddDO4DQwV/SsUl6M=; b=wKNzg7dYbEZ7JdY0QSEvMu3BfN+89c1YtmfaFah36b/fNq1wjJmqvXwq4+pomzc6aH yodIPIOAhv4YWDaVNJwI2PEjM4UkP/rCQZSvxDtm8ic0BgOsH6fQvG0qxZxlpntM2PBe bR/AEAklb1QurzZbvhm/VYrUYjLwr8ABWo79ma4t9DQ4kzxV0Ag8QhXH0qhek1RwrFga SVAgbZHM+Cvwb0dW2g/Fdz+6qEoNe1hoiIoVA9q/NWvQBN61qU79l/OcZ9J7vURCVoEk 0qGm4amP3+CqtLim3otr7kvcppTb9N0B1Le0fGYxI6Nx+HhNRBXY5Chu1oGr5BcT6plY 3MQw== X-Forwarded-Encrypted: i=1; AJvYcCWq54mQUWBK947FFbm0q+p1R7G3/+tFycRSDi0/SkzpgRLBKcnmHGcWY9Lasuj7iCFAggiQNjnPlKcfMUJJmmsSpTRDUImK+7iqS1bL X-Gm-Message-State: AOJu0Yx8yBRek7NLyLxTrQ+F40dpLs1ffRGNHUE+MwuvtLVUpZ/AUtt4 f+yx8ikobseNEDrjcmMA/xBNkVXRlstoZ7FgFBjxHIdRkvLXWAufBscs28/3hg5/iT+Y9FYJABE f8w== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90b:2d89:b0:299:4395:a21c with SMTP id sj9-20020a17090b2d8900b002994395a21cmr2519pjb.7.1708719672505; Fri, 23 Feb 2024 12:21:12 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 23 Feb 2024 12:21:04 -0800 In-Reply-To: <20240223202104.3330974-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240223202104.3330974-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240223202104.3330974-4-seanjc@google.com> Subject: [PATCH v2 3/3] KVM: VMX: Combine "check" and "get" APIs for passthrough MSR lookups From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Dongli Zhang X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791722570696121395 X-GMAIL-MSGID: 1791722570696121395 Combine possible_passthrough_msr_slot() and is_valid_passthrough_msr() into a single function, vmx_get_passthrough_msr_slot(), and have the combined helper return the slot on success, using a negative value to indicate "failure". Combining the operations avoids iterating over the array of passthrough MSRs twice for relevant MSRs. Suggested-by: Dongli Zhang Signed-off-by: Sean Christopherson Reviewed-by: Dongli Zhang --- arch/x86/kvm/vmx/vmx.c | 63 +++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 38 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 014cf47dc66b..969fd3aa0da3 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -658,25 +658,14 @@ static inline bool cpu_need_virtualize_apic_accesses(struct kvm_vcpu *vcpu) return flexpriority_enabled && lapic_in_kernel(vcpu); } -static int possible_passthrough_msr_slot(u32 msr) +static int vmx_get_passthrough_msr_slot(u32 msr) { - u32 i; - - for (i = 0; i < ARRAY_SIZE(vmx_possible_passthrough_msrs); i++) - if (vmx_possible_passthrough_msrs[i] == msr) - return i; - - return -ENOENT; -} - -static bool is_valid_passthrough_msr(u32 msr) -{ - bool r; + int i; switch (msr) { case 0x800 ... 0x8ff: /* x2APIC MSRs. These are handled in vmx_update_msr_bitmap_x2apic() */ - return true; + return -ENOENT; case MSR_IA32_RTIT_STATUS: case MSR_IA32_RTIT_OUTPUT_BASE: case MSR_IA32_RTIT_OUTPUT_MASK: @@ -691,14 +680,16 @@ static bool is_valid_passthrough_msr(u32 msr) case MSR_LBR_CORE_FROM ... MSR_LBR_CORE_FROM + 8: case MSR_LBR_CORE_TO ... MSR_LBR_CORE_TO + 8: /* LBR MSRs. These are handled in vmx_update_intercept_for_lbr_msrs() */ - return true; + return -ENOENT; } - r = possible_passthrough_msr_slot(msr) != -ENOENT; - - WARN(!r, "Invalid MSR %x, please adapt vmx_possible_passthrough_msrs[]", msr); + for (i = 0; i < ARRAY_SIZE(vmx_possible_passthrough_msrs); i++) { + if (vmx_possible_passthrough_msrs[i] == msr) + return i; + } - return r; + WARN(1, "Invalid MSR %x, please adapt vmx_possible_passthrough_msrs[]", msr); + return -ENOENT; } struct vmx_uret_msr *vmx_find_uret_msr(struct vcpu_vmx *vmx, u32 msr) @@ -3954,6 +3945,7 @@ void vmx_disable_intercept_for_msr(struct kvm_vcpu *vcpu, u32 msr, int type) { struct vcpu_vmx *vmx = to_vmx(vcpu); unsigned long *msr_bitmap = vmx->vmcs01.msr_bitmap; + int idx; if (!cpu_has_vmx_msr_bitmap()) return; @@ -3963,16 +3955,13 @@ void vmx_disable_intercept_for_msr(struct kvm_vcpu *vcpu, u32 msr, int type) /* * Mark the desired intercept state in shadow bitmap, this is needed * for resync when the MSR filters change. - */ - if (is_valid_passthrough_msr(msr)) { - int idx = possible_passthrough_msr_slot(msr); - - if (idx != -ENOENT) { - if (type & MSR_TYPE_R) - clear_bit(idx, vmx->shadow_msr_intercept.read); - if (type & MSR_TYPE_W) - clear_bit(idx, vmx->shadow_msr_intercept.write); - } + */ + idx = vmx_get_passthrough_msr_slot(msr); + if (idx >= 0) { + if (type & MSR_TYPE_R) + clear_bit(idx, vmx->shadow_msr_intercept.read); + if (type & MSR_TYPE_W) + clear_bit(idx, vmx->shadow_msr_intercept.write); } if ((type & MSR_TYPE_R) && @@ -3998,6 +3987,7 @@ void vmx_enable_intercept_for_msr(struct kvm_vcpu *vcpu, u32 msr, int type) { struct vcpu_vmx *vmx = to_vmx(vcpu); unsigned long *msr_bitmap = vmx->vmcs01.msr_bitmap; + int idx; if (!cpu_has_vmx_msr_bitmap()) return; @@ -4008,15 +3998,12 @@ void vmx_enable_intercept_for_msr(struct kvm_vcpu *vcpu, u32 msr, int type) * Mark the desired intercept state in shadow bitmap, this is needed * for resync when the MSR filter changes. */ - if (is_valid_passthrough_msr(msr)) { - int idx = possible_passthrough_msr_slot(msr); - - if (idx != -ENOENT) { - if (type & MSR_TYPE_R) - set_bit(idx, vmx->shadow_msr_intercept.read); - if (type & MSR_TYPE_W) - set_bit(idx, vmx->shadow_msr_intercept.write); - } + idx = vmx_get_passthrough_msr_slot(msr); + if (idx >= 0) { + if (type & MSR_TYPE_R) + set_bit(idx, vmx->shadow_msr_intercept.read); + if (type & MSR_TYPE_W) + set_bit(idx, vmx->shadow_msr_intercept.write); } if (type & MSR_TYPE_R)