Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1819103lql; Wed, 13 Mar 2024 09:00:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWGA61ZNIRTTq5QDdrsSNsDc7gTtLuEzQvsi0QYYIKk9BA/Yoi13wHA/e0SNKW4RMvxVWcl76ybTfzgRGrcCbCsOidt+RU0qwj5e5OMUg== X-Google-Smtp-Source: AGHT+IHoZ4mjXQ5IFIXFOLQ7i/CyWCodKnrkqQlaeERv6/0kpH8IZ98hyTbm8npepob48/SCFv0c X-Received: by 2002:a05:6a20:2046:b0:1a1:4aa0:d593 with SMTP id x6-20020a056a20204600b001a14aa0d593mr8136668pzx.47.1710345632914; Wed, 13 Mar 2024 09:00:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710345632; cv=pass; d=google.com; s=arc-20160816; b=kacUD/Ry+3KoR+Vta6QyzvWoeGAzQsAACT1fAxJ208TjciaSToVWyqDFJ/BtXNeZt3 fa+/4RHetfrtrpzx6u2ogtt26Mj3lCGlDExf2OG5cr5hAFbFqtStJvho8rjUN5XHqH7Q KAgII7cDlDezJFn5zYqJwIjLG6aEuQYDTX8ZiynhbBqQR3kGT58t9zmJC6b5dFLz+CPR 4+Or/cFHgySjOVCo/jkhRPP50ckb4dHB2DwncvuZ41LF2ku4e4Gmemz9d1cKKIuEMn6s oCsI6mmp2yzgPOzfDqoZ8MzyNAGzY7BRD68vypEMjhz64I3lRPd5MmwMerWMPWBToias w0kg== 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=UTq/Gh3fb1Jc7qkNObzjz7+0X1KEbNuRRHpZgPcsL2A=; fh=xI6Jws3G/bGCyYLi2GWCcxtvcsBrlNfv+H8p/QenFr0=; b=PnxAfPFTAhAytEeVA0nrp8WKLjyGr5OAdHKUEDDyHpswYWYV8aQQTO+8d7N5h1fT22 8zyRZzNiSY8FRwr2tPo5MF9JiYpLTG3NV9Rx4BtHLjO3YbUbvWsmGqXrmB390hR/Ccki Uo9Kf9LGD45F92vtVbblcLJjT+E9wgAZMSMAXYAWuPYeq9KYBuwBtlc9Z3u+aRd+5Wpa fh8ZPzAGXH+MCHnEpw3ASDxH/PQOb+NZuGsY6p2ZY/HJ7ZDh+DGZpwP+jMJT98Hh7b3H VreZ939lPQLnhfkYJMut4esLF8lwMdNu+0qf40GXCcnI276nRI9svOVDWoqfbTO0laFG iUvQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=dzfspTi9; 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-101707-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101707-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 x6-20020a656aa6000000b005dc5576a4fasi9055541pgu.770.2024.03.13.09.00.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 09:00:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101707-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=dzfspTi9; 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-101707-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101707-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 777C32851AC for ; Wed, 13 Mar 2024 16:00:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CAD15487A7; Wed, 13 Mar 2024 16:00:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dzfspTi9" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 85DE1481BA for ; Wed, 13 Mar 2024 16:00:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710345616; cv=none; b=NjKuZNz33RM67D8P0GuNzJFXU2eoe+KbkHc6vr2YkaXBFLjXDMCQovE/B2GOKes1nPbVJNbHfcqYWgU7LW8j73mrYXzQ7lX1MRSKemJxIGDmfKjUSLua7F1zYtXHcJw9yFO1q1nwJTMaJlFuqZaaPOdC2r/wkTeW2b0buwmeKtU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710345616; c=relaxed/simple; bh=yHXtaDtNvztZB6cDPOuC8+5o2hFx6wTETY3sSzeZDMg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=RaWS/XElbVX52uxVdBfTg2vVX4g5MN1d14YxsnwSdXeCCCQuKDDm9qboJm9To7V2H8I4FPSHarJGj6XCAh+/u4/Lj7UiAq0IRqAu/2ZI4ziE5mROMMw2xGzTS9fVMebEKRiOaGXRNPMb7vXHybINPve2tXsQQcqGKF82WIIMqqM= 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=dzfspTi9; arc=none smtp.client-ip=209.85.128.202 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-f202.google.com with SMTP id 00721157ae682-60a20c33f06so18922837b3.2 for ; Wed, 13 Mar 2024 09:00:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710345613; x=1710950413; 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=UTq/Gh3fb1Jc7qkNObzjz7+0X1KEbNuRRHpZgPcsL2A=; b=dzfspTi9J6rzhowghpUwmuGLuxmeFd5PfeYmIIvvEpsGGp/eFtTrlAiZJ7f/iRsn35 nqyJ24X6KuwFLhO+l9Snu0GTB0RoMa/fHM2n/codvGHgYWHScB4pYLytEgBKE9Za9ZZU LNGoPVMIjptLnP1XV/5yCNeoYZ7y943nVuZWz8LXOHbdyMo1EJr4701B8SALvnrXJSew TSv4FetT/0Tfe4KdB1tfhDjO781axXeIUiUbX3R7j/E8Abxu+syEnjrejQ49Svx46f50 zK9X6sw3RDK1U7u5a1WQMWfSjCirEtr/RuUyClvAzMNcahD/ph12i3za2J6Fk3KC20Fd ZmHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710345613; x=1710950413; 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=UTq/Gh3fb1Jc7qkNObzjz7+0X1KEbNuRRHpZgPcsL2A=; b=Z9Cybhs6yCQuk2gjlbfYQIQa4eSWEmIlwoR55b1+bhrVPfbgjaykVO6yZ8JfcRfAiw ILnbTXLazh2zXMENXC1aju2ehZyiRcYbC8fQrShVUOFW1T6odz3TOf474VxJ78KLmWRy RWWbeS4RT2MXTX3DHQN81V9Wb2snd2ml2zVT5PHvyO2HL6Xo0Z7qxJikNopulwbZy2mT gJ9PKnR4haD1a6eQ1BMqkiVv6Rz1DYn4iSW00GBC2xPzebj9ntFXSNuTxfM0+Bu8ARft YtHpbTEghlGEUAc0ZD72WouATHBaJmWifEUekE7TyWrI3fMKvubl7gaX0c5PJ0dRWLJJ Ahcg== X-Forwarded-Encrypted: i=1; AJvYcCVTtHYKT+IIHARNF38WtmUzDcyXgV1F9r0WBR5mF8rQrBQyvaxCwVhlsM3GjYmxGHxbqIOXaSiZhgROgXJbqfZm5sIoAoqsAi3Hy3cb X-Gm-Message-State: AOJu0Yw/BN6STKrLTLwGYzV06tWLTMPBA0MOKRZ0OYDDtjbjlPIbcSwF MmeC+EWfOIPoDRXyYq7lG/2HTjyJpD4GGVuHSxYEkDj2EAHbVFjg6OMI9V6tdjKQKqFBCbnSgL7 EKw== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:690c:a02:b0:609:ecbd:27dd with SMTP id cg2-20020a05690c0a0200b00609ecbd27ddmr503567ywb.3.1710345613487; Wed, 13 Mar 2024 09:00:13 -0700 (PDT) Date: Wed, 13 Mar 2024 09:00:12 -0700 In-Reply-To: <9f820b96-0e4b-4cdc-93ff-f63aed829f0d@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-21-weijiang.yang@intel.com> <9f820b96-0e4b-4cdc-93ff-f63aed829f0d@intel.com> Message-ID: Subject: Re: [PATCH v10 20/27] KVM: VMX: Emulate read and write to CET MSRs From: Sean Christopherson To: Weijiang Yang Cc: pbonzini@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, chao.gao@intel.com, rick.p.edgecombe@intel.com, mlevitsk@redhat.com, john.allen@amd.com, Aaron Lewis , Jim Mattson , Oliver Upton , Mingwei Zhang Content-Type: text/plain; charset="us-ascii" On Wed, Mar 13, 2024, Weijiang Yang wrote: > On 3/13/2024 6:55 AM, Sean Christopherson wrote: > > PERF_CAPABILITIES has a similar, but opposite, problem where KVM returns a non-zero > > value on reads, but rejects that same non-zero value on write. PERF_CAPABILITIES > > is even more complicated because KVM stuff a non-zero value at vCPU creation, but > > that's not really relevant to this discussion, just another data point for how > > messed up this all is. > > > > Also relevant to this discussion are KVM's PV MSRs, e.g. MSR_KVM_ASYNC_PF_ACK, > > as KVM rejects attempts to write '0' if the guest doesn't support the MSR, but > > if and only userspace has enabled KVM_CAP_ENFORCE_PV_FEATURE_CPUID. > > > > Coming to the point, this mess is getting too hard to maintain, both from a code > > perspective and "what is KVM's ABI?" perspective. > > > > Rather than play whack-a-mole and inevitably end up with bugs and/or inconsistencies, > > what if we (a) return KVM_MSR_RET_INVALID when an MSR access is denied based on > > guest CPUID, > > Can we define a new return value KVM_MSR_RET_REJECTED for this case in order > to tell it from KVM_MSR_RET_INVALID which means the msr index doesn't exit? No. Well, I mean, we could, but I don't see any reason to define another return value, because the semantics further up the stack need to be identical. And unfortunately, correctly differentiating between the two scenario would require quite a bit of surgery to play nice with PMU MSRs. Hmm, I suppose we could WARN if a _completely_ unhandled MSR ends up in the msrs_to_save or emulated_msrs lists. But because of the PMU MSRs complications, this is definitely not worth doing right away, if ever. > > static bool kvm_is_msr_to_save(u32 msr_index) > > { > > unsigned int i; > > > > for (i = 0; i < num_msrs_to_save; i++) { > > if (msrs_to_save[i] == msr_index) > > return true; > > } > > Should we also check emulated_msrs list here since KVM_GET_MSR_INDEX_LIST > exposes it too? Ah, yes. I was thinking msrs_to_save was a superset, but KVM_GET_MSR_INDEX_LIST is where the lists get smushed together.