Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1125485rwd; Thu, 25 May 2023 08:18:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ47wyuQENtZFPkhGBRSkGFvjqnso2nQMiSdnQnEabNAH3iNg+q3A0HhYvIoKcNIs3gSZ7Tg X-Received: by 2002:a17:902:c945:b0:1af:eea0:4f35 with SMTP id i5-20020a170902c94500b001afeea04f35mr2515746pla.2.1685027924849; Thu, 25 May 2023 08:18:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685027924; cv=none; d=google.com; s=arc-20160816; b=vfEj6usp+EugBVz1AAwWhr3Uz2I20KKgqizfhFUxmnNbO3zw3bc2NivZbfxzYHaxtR /Nc/5FLCPAtUp7Gjrds3JOnIu+xeKmnuhFBG8pDzhD0AFfeVHcJYW09aKq4nFkJn9qUg 8ca81ofO/91++/xTJquwLOMTsJ3w1dpmahPGC3E/TZ5zCZbh4FM5+nEoVKh/Fwnyq7t8 FSVcQpdCcwkNxIe4swgsI7jI+bM82tJsitD7xI2tpePPa9Qn4sflLOfveJaZuUSK6Rcq pnTB+0FwJNxbz5evzE+LwjBgWRDeATMW139SiadjckamDGE/YRpIqjKFMkpDz3fM01A5 kaRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=2rgc5wNBzRwTZsiTn0J0WHKeSrzO5GwJcVsGE/2GYBg=; b=ANjumacq8yAP4gUXoPrEioKvzKGPaEpscE+/5vvyxqloJlyOq7QbSIxP2g2y+yGeBv IkL50bPgluPQHCA7MqXnqhRwFjMgsd57AcmTP6aeNiWDzklAS2uP5lUpLlKntqJQzLg8 e2XStXViwwFjrnkCScGEn2kz6O4h5lJUp63YLtDx+UD+1drokFsMV30+F8RqYXwWLI4l jrXyGzqaX6zoIXxSFGTiaFdyeaOMW7RBdmC9pVzXb4Vj88Z0WdrjEIEQjIWlBXFSxJmk fwFS90D+O/Z9Q135GEHifFSdGCtxuJTFHrT2jUF7V7NTLXg0S2puQqD0wn1Tt3W6y367 YRvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=AyY7s5NO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x5-20020a1709028ec500b001a699fc81e8si1686525plo.98.2023.05.25.08.18.32; Thu, 25 May 2023 08:18:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=AyY7s5NO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241262AbjEYPBD (ORCPT + 99 others); Thu, 25 May 2023 11:01:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240847AbjEYPBB (ORCPT ); Thu, 25 May 2023 11:01:01 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0A971B3 for ; Thu, 25 May 2023 08:00:59 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id 98e67ed59e1d1-25359e411ceso967003a91.2 for ; Thu, 25 May 2023 08:00:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685026859; x=1687618859; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=2rgc5wNBzRwTZsiTn0J0WHKeSrzO5GwJcVsGE/2GYBg=; b=AyY7s5NO6ZYMxx+nAp8os1iSmL+QUh0+NNNS14PW8xDvfy14jeBv20Cn+/xySm0GS+ 7JLXIMsPgorL07xkxMYRmcSAp/H90WQnq5m0O4W/mOE9Um4tYYNOk5Bgg/ZJeGjjUE0E tAU2NRyk6rNg0Sd0lXD/e5OJdMa3n3EpMDS/xks/N183FlGxRzVW1SsHC/8+k8/JX/Y1 af3OGWtTx7YIOKwNAEi/VswrUDCEvN2lluN+Bpsy/lCDUbo55Rx4891gHCjPsU2SUtSS 8uNw0kEDQBwtNMS9jtoCWLNl9mVDch8QqvuUftQh8EZpQMLUC3PrWXy31Dy4aOSm5rUq vuZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685026859; x=1687618859; 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=2rgc5wNBzRwTZsiTn0J0WHKeSrzO5GwJcVsGE/2GYBg=; b=lYxxzchpWxEKwqvWLOx+huVr3zI9gXQpYjKb+HnXhz2DJJJIWeNywjbFo3C6pvxorm lO6TCK+L4DYcrMPa6VfWKSPt7niLD3Nlwl9NR8VMKla2ifsWziPSJIH2ug4nwrj6D9LR gmC4prTFNv9DxI8Cg4opDJ1hLqzRHnBu/kVk/WuQc30rA6J3md5Mw+n/nfmF9I31HDIS T4ALvUVqjiLm7dS8D7eeDHqpfiO0lxs6puldLOdnIdgUdaJJDq9mY+0oPBP1ftNHR0SD a/yZ3jAaaBm/YxdkBfe9mrmVK9Qc7uf0/seXGcGs4K3bbRM8T6gVTYFkeJq9OQIS7G8X tfug== X-Gm-Message-State: AC+VfDwiQ5Gt13Or86NpI0Ip525ly6cevfQ2Opdbkkug36G8wXbZFLkw 2qUM/bLlWkBB0UI3ND7TL0beceJhh3I= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90a:9304:b0:250:a6c1:b843 with SMTP id p4-20020a17090a930400b00250a6c1b843mr436712pjo.9.1685026859534; Thu, 25 May 2023 08:00:59 -0700 (PDT) Date: Thu, 25 May 2023 08:00:58 -0700 In-Reply-To: <393b16f7-8359-5d77-7d5d-8942de987331@gmail.com> Mime-Version: 1.0 References: <20230509134825.1523-1-yan.y.zhao@intel.com> <20230509135300.1855-1-yan.y.zhao@intel.com> <3f09e751-33fd-7d60-78cd-6857d113e8bd@gmail.com> <393b16f7-8359-5d77-7d5d-8942de987331@gmail.com> Message-ID: Subject: Re: [PATCH v2 5/6] KVM: x86: Keep a per-VM MTRR state From: Sean Christopherson To: Robert Hoo Cc: Yan Zhao , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, pbonzini@redhat.com Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 25, 2023, Robert Hoo wrote: > On 5/23/2023 2:21 PM, Yan Zhao wrote: > IIUC, your saving comes from skips the intermediate state during boot, when > APs goes through setting MTRR, which would cause SPTE zap before your this > patch set. > > MHO was, now that your ignores other vCPU's MTRR settings (unless it is > different from BP's MTRR?), why not let each vCPU's MTRR set/update directly > set to the per-VM MTRR states (if differs from current value). It's guest > OS/BIOS's responsibility to keep the consistency anyway. And even if the > malfunction caused by the inconsistency might differ from that of native, > SDM doesn't clearly state how the malfunction should be, does it? > that's to say, anyone knows, when inconsistency happens, does it cause that > logical processor malfunction or in fact it impacts the global MTRR > settings? If the latter, I think leaving only the per-VM MTRR state aligns > with native. The MTRRs are not system wide or per-package though, they are per logical CPU. Yes, they "need" to be consistent with respect to one another, but only when the CPU is actually accessing memory. This is a big reason why trying to track MTRRs as a per-VM asset in KVM is so difficult/messy. Software doesn't rendezvous all CPUs and then do the write on just one CPU, each CPU does its own writes more or less independently. > BTW, with regard to KVM_X86_QUIRK_CD_NW_CLEARED, I see svm honors it while > vmx doesn't before it clear CR0.CD/NW. > > svm_set_cr0(): > > if (kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_CD_NW_CLEARED)) > hcr0 &= ~(X86_CR0_CD | X86_CR0_NW); > > > vmx_set_cr0(): > > hw_cr0 = (cr0 & ~KVM_VM_CR0_ALWAYS_OFF); > > Perhaps vmx side can be fixed passingly? Sadly, no. SVM and VMX manage guest memtype completely differently. VMX doesn't allow CR0.CD=1 when VMX is enabled, and so KVM needs to emulate CR0.CD via the EPT memtype.