Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2150825rdb; Mon, 9 Oct 2023 14:36:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEmSDfiCdhHn4PSSSFwvHZ7kndZ7kGh1kGtvSfrhS1eJHm7lHjKi47VlaqUN86UZMk7rYl/ X-Received: by 2002:a05:6a21:9986:b0:13c:988c:e885 with SMTP id ve6-20020a056a21998600b0013c988ce885mr15568655pzb.56.1696887398131; Mon, 09 Oct 2023 14:36:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696887398; cv=none; d=google.com; s=arc-20160816; b=rukVOuf5FbYqaPJyxFMBBu5D65iHBdu5/0E7GZMPHm7yYcTjJg1R2LaKJHGWoZ7jwD w1Ur4sbto1+bBUPB/bWC/RunHP8J+2xMdiX2F6hu/Ri6cig7m5VtuycRjoOyTkledJQ5 JuIGUtm8WRU4jlOKRspkMTy2Tvha/llPjg1eDPry9TERaSPsUOtJ0Df6UQpvsoij+9xO FdvtLJ0Pg5p84CwLD+a8WJb1Wu09Ier9MuYUOkSFDdxLQgHCsJbYdyoLy3yYmvV6qgKL d5OnOMWKALDcRMS4seSUiWcM1lAnqasuwNdM1Yg7VdIQZR09H5VVXYwRfJaMLJvbdfib vqrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:dkim-signature; bh=CeiLuszUQzm1dE5vxA8gfNKXniFYODS3y9KHytRWFpM=; fh=Utig29YSei7qdvKIJLu7W1GkDHF+gWBejU0AiRcgKSE=; b=0T4+dX8ctyMiQWXwJtTqdVxtZdfAwtbl64DCAwRo/A/0eAUoR+pI3MRlGKFvGbON34 u5lfSS8jgAWThQBuij0elB2c+lfmptK71qiC88lPl1Hr9olZvy96Sg/gVt55xbsvCCil gK39H+6gN9Oi+u+NYBKndSps6bjNKBwjRV4US/B/K8gtaK8b2FH6zor+OQ7qRwYVufuU ybja8ff/v3lNUk273Mb9mEejAcyMV9xjUvC70ovKahg62AJzUg7wJL5L2R4hzywfTyuG SFPwcxyPLUh1a8Sk6p39jZ28F+XkecBUITeIbOO5LNcLFG9HDA7HCRIt1gXkb1SWka8b R60Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=DS0pyVOS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id u11-20020a6540cb000000b00565aa20a07asi10176248pgp.683.2023.10.09.14.36.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 14:36:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=DS0pyVOS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A940580DEA40; Mon, 9 Oct 2023 14:36:36 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378699AbjJIVga (ORCPT + 99 others); Mon, 9 Oct 2023 17:36:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377177AbjJIVg3 (ORCPT ); Mon, 9 Oct 2023 17:36:29 -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 BAC539E for ; Mon, 9 Oct 2023 14:36:27 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id 98e67ed59e1d1-27911ce6206so4911241a91.0 for ; Mon, 09 Oct 2023 14:36:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696887387; x=1697492187; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=CeiLuszUQzm1dE5vxA8gfNKXniFYODS3y9KHytRWFpM=; b=DS0pyVOSgJn+2cY+lenjN3nIPtGMAAwB7k12PM5aOtfo64vgPgPjUApWcD9l54GZJo ZQsSUZREQdCs95eFYRv+CoN/tgNCrKuOEMZsk9Hx7X3b3r/R/PC/y+XIf9drXdqneDUo fiNCv7f594wHPeQ06bELorTMs1bj/H68GkKjIlJK121d33Kvjg3vQ/CmDTKkgPdqqC0Z gwXm8nMXKh4n79ciTYlf1IDYy8cbNqNYXGH8Hr/IX1rE3GWqQf190pKZzXVnk7zTC9CI MIdI0ArO5VroGsxc8bXrokQ0CcwEpGbYTBU34H7COid2q1kj4NauxUGPYi/2y2KeqaCH UK0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696887387; x=1697492187; h=content-transfer-encoding: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=CeiLuszUQzm1dE5vxA8gfNKXniFYODS3y9KHytRWFpM=; b=wXfC7hwhTc4aKISJqohqkcpH+Zw7LNeX6kW55Ut+eSMnOKfKLxUT7fKIIjaPFvO5JK qSI7L3RX0w/zgn+pj+oEjmzxi9TvqHicYWeS8ZJoVQz5eBIq5ZNvcqVXj4Oj3M9nsyNq mz1a2C9YRgX8K4qeFVM+TmB9BwUM3LC5sCOnx0Zohkaf1xQfTKW9oc9/0ws5WsEUDul/ um2TQntjPyAPlRzp4JbcduGeqtVbYxqbzvKPyD0u3vwAm99VQRlTPkn759x3HjrW21zh kv4bHeZ+zzkJBKwo9dyFTGLVoW8M2SYa5OhznJN3YFMhJDmMsOqyMMLo7JT935Sbst+P RPVg== X-Gm-Message-State: AOJu0Yy0VZDfgo4PdJdJ2vlBbDNFJm91eqCGARZXCJZWQRoMAHyPwSXA kngxdRRff5zOCfofRWscUwLEXotPcPo= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90a:a393:b0:274:90a4:f29 with SMTP id x19-20020a17090aa39300b0027490a40f29mr280600pjp.1.1696887387251; Mon, 09 Oct 2023 14:36:27 -0700 (PDT) Date: Mon, 9 Oct 2023 14:36:25 -0700 In-Reply-To: Mime-Version: 1.0 References: <20230714064656.20147-1-yan.y.zhao@intel.com> <20230714065006.20201-1-yan.y.zhao@intel.com> <553e3a0f-156b-e5d2-037b-2d9acaf52329@gmail.com> Message-ID: Subject: Re: [PATCH v4 01/12] KVM: x86/mmu: helpers to return if KVM honors guest MTRRs From: Sean Christopherson To: Like Xu Cc: Yan Zhao , pbonzini@redhat.com, chao.gao@intel.com, kai.huang@intel.com, robert.hoo.linux@gmail.com, yuan.yao@linux.intel.com, kvm list , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 09 Oct 2023 14:36:36 -0700 (PDT) On Mon, Oct 09, 2023, Sean Christopherson wrote: > On Mon, Oct 09, 2023, Sean Christopherson wrote: > > On Sat, Oct 07, 2023, Like Xu wrote: > > > On 14/7/2023 2:50=E2=80=AFpm, Yan Zhao wrote: > > > > diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h > > > > index 92d5a1924fc1..38bd449226f6 100644 > > > > --- a/arch/x86/kvm/mmu.h > > > > +++ b/arch/x86/kvm/mmu.h > > > > @@ -235,6 +235,13 @@ static inline u8 permission_fault(struct kvm_v= cpu *vcpu, struct kvm_mmu *mmu, > > > > return -(u32)fault & errcode; > > > > } > > > > +bool __kvm_mmu_honors_guest_mtrrs(struct kvm *kvm, bool vm_has_non= coherent_dma); > > > > + > > > > +static inline bool kvm_mmu_honors_guest_mtrrs(struct kvm *kvm) > > > > +{ > > > > + return __kvm_mmu_honors_guest_mtrrs(kvm, kvm_arch_has_noncoherent= _dma(kvm)); > > > > +} > > > > + > > > > void kvm_zap_gfn_range(struct kvm *kvm, gfn_t gfn_start, gfn_t gf= n_end); > > > > int kvm_arch_write_log_dirty(struct kvm_vcpu *vcpu); > > > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > > > > index 1e5db621241f..b4f89f015c37 100644 > > > > --- a/arch/x86/kvm/mmu/mmu.c > > > > +++ b/arch/x86/kvm/mmu/mmu.c > > > > @@ -4516,6 +4516,21 @@ static int kvm_tdp_mmu_page_fault(struct kvm= _vcpu *vcpu, > > > > } > > > > #endif > > > > +bool __kvm_mmu_honors_guest_mtrrs(struct kvm *kvm, bool vm_has_non= coherent_dma) > > >=20 > > > According to the motivation provided in the comment, the function wil= l no > > > longer need to be passed the parameter "struct kvm *kvm" but will rel= y on > > > the global parameters (plus vm_has_noncoherent_dma), removing "*kvm" = ? > >=20 > > Yeah, I'll fixup the commit to drop @kvm from the inner helper. Thanks= ! >=20 > Gah, and I gave more bad advice when I suggested this idea. There's no n= eed to > explicitly check tdp_enabled, as shadow_memtype_mask is set to zero if TD= P is > disabled. And that must be the case, e.g. make_spte() would generate a c= orrupt > shadow_memtype_mask were non-zero on Intel with shadow paging. >=20 > Yan, can you take a look at what I ended up with (see below) to make sure= it > looks sane/acceptable to you? >=20 > New hashes (assuming I didn't botch things and need even more fixup). Oof, today is not my day. I forgot to fix the missing "check" in the chang= elog that Yan reported. So *these* are the new hashes, barring yet another goof= on my end. [1/5] KVM: x86/mmu: Add helpers to return if KVM honors guest MTRRs https://github.com/kvm-x86/linux/commit/1affe455d66d [2/5] KVM: x86/mmu: Zap SPTEs when CR0.CD is toggled iff guest MTRRs are ho= nored https://github.com/kvm-x86/linux/commit/7a18c7c2b69a [3/5] KVM: x86/mmu: Zap SPTEs on MTRR update iff guest MTRRs are honored https://github.com/kvm-x86/linux/commit/9a3768191d95 [4/5] KVM: x86/mmu: Zap KVM TDP when noncoherent DMA assignment starts/stop= s https://github.com/kvm-x86/linux/commit/68c320298404 [5/5] KVM: VMX: drop IPAT in memtype when CD=3D1 for KVM_X86_QUIRK_CD_NW_CL= EARED https://github.com/kvm-x86/linux/commit/8925b3194512