Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1306000lqd; Thu, 25 Apr 2024 11:18:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXjYBbvilrSwetMnYI32tPQsV2o04fkctjRFJUEV9G0qFLDDuMeWqGHU8aaPFr1mEVIQ8eyPvIPZHU6JsSBEYYBgwI1POG3i9etUni+9A== X-Google-Smtp-Source: AGHT+IGHKM8989itbznn0VVNCjJ90r3AtZqTfafSjfbiWTvlwpp47Jg3THTsp0Tm/ZyMIfGsBwQL X-Received: by 2002:a05:6a20:918b:b0:1ab:82fe:9285 with SMTP id v11-20020a056a20918b00b001ab82fe9285mr517674pzd.58.1714069083543; Thu, 25 Apr 2024 11:18:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714069083; cv=pass; d=google.com; s=arc-20160816; b=0jAmynQ7OyzwVOLyAgLKd5hnPYJXXhWS/4AOsOwenD5fdCwPp4onWZbP1FXwYj1nMP /M2icW1cvN00H+HLtNcogZHZQJm2Gj/pNOF1M+IzjK5I1ZBQkvBA1grqDY1WdIWycHuv lmTuNyXl1JpQL+YpChDVTH3uWVHZIrY7devAPasFjogYooEK8nPNLIF0fSckhOxhar3v 96GPrVR4biFGbBNnXXlFNrgRoPd/UnrBHhu5qhIDv0QjKRc7XXcDqiSrEq5jl5wCJ0LC 7bGgnuHsxVNeCdevP5ZFmLFqM3qi40iynZJwldtovaNydGyPpG3yKK+RbI3CaZGvFRMP NMrg== 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=7x2xDm7ORIVYu8+DJIH/haFx3NIITex91VRf9yc3OHU=; fh=uM4rbDr2Wy+UTLCX5m4XR87Cn4smLp+ju5AYRzvHiJM=; b=mfHZePHayRu0KoGuaKCY4oNWaDZPOwng+9E54Do3v0BGrsnQlsnJsgPSqciuC65+R2 w4ARxH29189R4hWc4nu8w/4/WM8vg2L/jSm+MsixsscMg3k2id0VD74q4nWXIAVzh/66 aKettdnrdAz/xGJ9Y/w+AKlQSqPE2KkrX0kx8GYmbYRacpS/ULwlOWaKmbXJi+8l9sv4 BCuT4axVPnDD/fGPc1EJZECRYtFgGAbbj7VBx+9139Xhr9YW/bqjq57VcAvTDbWH4q0O vIiapvA6HO3jWR0yyBmxgrlhrqjlmtgv80q5C8VpKUqzzZDzpDU/+THp++aAaGWyplP6 twxg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=f6jRa0OD; 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-159009-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159009-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. [139.178.88.99]) by mx.google.com with ESMTPS id f5-20020a056a0022c500b006ed1a98ce70si14103773pfj.19.2024.04.25.11.18.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 11:18:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-159009-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=f6jRa0OD; 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-159009-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159009-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 407CF282DD9 for ; Thu, 25 Apr 2024 18:17:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5F158156F26; Thu, 25 Apr 2024 18:14:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="f6jRa0OD" 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 39C02150990 for ; Thu, 25 Apr 2024 18:14:48 +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=1714068889; cv=none; b=JsO4X7RNYutxhp8vcxBAqqdFufcrDj5sTQ/8YYxMgKfgSiK5syBSOH7r6Vc8xv48Rw/JMV99Xi768Ha6X2kCowkCZ+t12ZpdfgfQO9Nr/qXdLkBHgOvS8F0IQAE8+uMNeEnlnK6OBDH02EsAkwVW01IluZzJWG0nRzBCK2wUVqs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714068889; c=relaxed/simple; bh=h3nH2RXwDRleABI7UvTpJNwiSjFJO/iubybYunLFYQY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=M5xB7pIkVNNr+fuOSDnv4X7FGFhvpshf35sf7lPZirrO7XiaRV55FXEXR/+9f9/NWY7/sFzkpiswKqIdAnVfccqGy7c2ueSWvIUvQ09vro67UXUmLnrWBo/BgIPJAL0+HpmHPlRzP8+3jiod9c10E0KXuVA5C/gt9W8Fgs97D0M= 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=f6jRa0OD; 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-6150e36ca0dso23829217b3.1 for ; Thu, 25 Apr 2024 11:14:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714068887; x=1714673687; 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=7x2xDm7ORIVYu8+DJIH/haFx3NIITex91VRf9yc3OHU=; b=f6jRa0ODT67ORWX27GVK/+mTZ31jdHbXp/6k3hpIfU/jHbO8lCsZAAGv8q6TDhrwnt iGlQdIiqywZdu8dD5gZSdyqYjXuGKkJhCy5DuFfcf8ZCG3gNuSJpTz6a5SZGZIJUrLnB XUHPvzcNBNIqNru0lO1hPsf02GKQrU7y9s4eXm7swjbYswE+UOp5jWWTtBkFRulndO7f F5hQbSwxevLP4xxsPF3U1N35v9yyPGyHDL0IU5+3p2BZdthJ7ZDDTaH7MMkg6SgQ81Xf 9jqp3FZQo43e5Je8X6t32xRuPg1MSz9Qm/vgRi2EECB1PUJ/TzJA58TdDk0ONWNB2Scm g8Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714068887; x=1714673687; 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=7x2xDm7ORIVYu8+DJIH/haFx3NIITex91VRf9yc3OHU=; b=Cy082AkguOVPdJjxeeip4K7FNo6LTuSRGoyEG2sHA6UTuBU8bZDvUpKbLP/b8zjG7f sp/uek9dRL89kbCW2iRDQnXh666uK+rOcCNyU1/9xH1DKlvwpTk3a82fUf9Gww6DwD0R INP+ySUsABhztJN7rhC17NTIgRAUtMiSKfpxUzQbQpdPRHlpOoF1YxfetyfkcCj3s3yg HOIkZEZG5oU4c2cO4k17J3itGHzj+D6Od0KGVlfAaVs6clXeWvRhPRh/WvLvnrL/kOT+ J7+hPrenXuL57fMn+Tvc0w86BBVyNT1Hv0oOHzklE99/KgYc3Z8MQ4PKZQL+TyPSbTkK xnKQ== X-Forwarded-Encrypted: i=1; AJvYcCXclZMwCOfmvfeo4E014G5beWW27xo1Dnk/FSyX96yJcrFd0qTe+vtQyxULyLlo8wQHlRrA9jZyFs4Km/qxFp69DP5VSP+k0mKdT9b0 X-Gm-Message-State: AOJu0YxpjEgR9gBpFoVQJQshWrwT2H/mNlVr+j8McrC1RsLG81wUYUIb Ag2WV0rrsFoBkWk9KOd9Oji5cKJwglAa6ff52V1nR0hIzHJ0AAv3wimf0/7K4SuDq704IMYoHZ8 39Q== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:a106:0:b0:61a:d016:60ff with SMTP id y6-20020a81a106000000b0061ad01660ffmr36102ywg.2.1714068887134; Thu, 25 Apr 2024 11:14:47 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 25 Apr 2024 11:14:22 -0700 In-Reply-To: <20240425181422.3250947-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: <20240425181422.3250947-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Message-ID: <20240425181422.3250947-11-seanjc@google.com> Subject: [PATCH 10/10] KVM: x86: Suppress userspace access failures on unsupported, "emulated" MSRs From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Tom Lendacky , Weijiang Yang Content-Type: text/plain; charset="UTF-8" Extend KVM's suppression of userspace MSR access failures to MSRs that KVM reports as emulated, but are ultimately unsupported, e.g. if the VMX MSRs are emulated by KVM, but are unsupported given the vCPU model. Suggested-by: Weijiang Yang Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 4c91189342ff..14cfa25ef0e7 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -491,7 +491,7 @@ static bool kvm_is_immutable_feature_msr(u32 msr) return false; } -static bool kvm_is_msr_to_save(u32 msr_index) +static bool kvm_is_advertised_msr(u32 msr_index) { unsigned int i; @@ -500,6 +500,11 @@ static bool kvm_is_msr_to_save(u32 msr_index) return true; } + for (i = 0; i < num_emulated_msrs; i++) { + if (emulated_msrs[i] == msr_index) + return true; + } + return false; } @@ -529,11 +534,11 @@ static __always_inline int kvm_do_msr_access(struct kvm_vcpu *vcpu, u32 msr, /* * Userspace is allowed to read MSRs, and write '0' to MSRs, that KVM - * reports as to-be-saved, even if an MSR isn't fully supported. + * advertises to userspace, even if an MSR isn't fully supported. * Simply check that @data is '0', which covers both the write '0' case * and all reads (in which case @data is zeroed on failure; see above). */ - if (host_initiated && !*data && kvm_is_msr_to_save(msr)) + if (host_initiated && !*data && kvm_is_advertised_msr(msr)) return 0; if (!ignore_msrs) { -- 2.44.0.769.g3c40516874-goog