Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp487370iog; Thu, 30 Jun 2022 04:52:27 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uQ6aRYvni5GB9ovzvoTEUB+I7IxozAUUZBv/JigePLNn9lOaJBuwVQyhMgc8XUFJY+6+9O X-Received: by 2002:a63:4f09:0:b0:3fd:3479:7624 with SMTP id d9-20020a634f09000000b003fd34797624mr7211240pgb.425.1656589947546; Thu, 30 Jun 2022 04:52:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656589947; cv=none; d=google.com; s=arc-20160816; b=S/hHcCVG8y80lS+vKzkZqJCCJh23bFmOaD2jiPxjPRVagOjR6BP2SIzByEtDFC/v/H 2rFKqKJ5gH8pSW4Rj0VtyE6sMAJwe67TNLr7sS1DzkqbKszNnd3bMTzh2lEApJ5u6iny rhM+0vWCmRuWdJAy45p7Hju3Ar6RMongBgtUMckUWBud8Ii/V35LBMZWhi7bc9GI4WT/ MTpmYPf8rdcQA/nzASdMuSZlggZoNJgWSC8QRwnxekg1pPOuLfSZIxOO9DfuP0zlo3eV mQZTQ72jG6DII4VX7Ahj8fP9Jav55hbBKNmU8YgBhGTf9RYhUqkXXMvFCNYyHzBsHTw7 PiYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=BbmA8cEUOB2epjM0Yh9TllodwfGQOdF7ML5kuI9IiCw=; b=vMMmMSqkmSpblzJx1g3YtzHsHNw17O7ju3irreO2T00LR7Qxq0oFeUc6yp9MFIt+vy hiZoQpQVDtEuUXmN2nMbYJhs1pb+haqkF1dUHYrrvM3E/EkGp1lKjHB1HHpBVqgHzDUW v/OU0Wp9BrVWtaHIlAmSauXWJhuSSuH9xW6y9MQlRwWD0pTaKUdIDvFa2jmc2AkBWL8s 8zM+CHyJlkdHpkjwkSh8LIDRDvRQk+bit+JMEhmtihg/pfljSR2fy2n+bNafwX/uxc/F AqVGi/sWy+DNDC3DA05k1/cgqlVhZbPMdF1VNUNIc5gceq8PtTB4byTvOif69bk29Hx0 QqDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=S1VE8R0H; 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=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p23-20020a17090adf9700b001ece6d4794fsi6348609pjv.118.2022.06.30.04.52.15; Thu, 30 Jun 2022 04:52:27 -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=@intel.com header.s=Intel header.b=S1VE8R0H; 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=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234656AbiF3Lpf (ORCPT + 99 others); Thu, 30 Jun 2022 07:45:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230350AbiF3Lpe (ORCPT ); Thu, 30 Jun 2022 07:45:34 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C11658FC0; Thu, 30 Jun 2022 04:45:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656589533; x=1688125533; h=message-id:subject:from:to:cc:date:in-reply-to: references:content-transfer-encoding:mime-version; bh=2mX4uYFYckU+u5d/5B4pwRiefLjn+1g7/6dyINaE9Kw=; b=S1VE8R0HmSx7JxfM2Z/gO2Qu7LKHrdGv39K8EPfhANpHn6LTZgB5pyof 8vIpyiSQf0DxiiThX+KE8QFMx1GMrkKZVLb1uAmKBRGrlryNs50hsoCza Kli8I6pGWxCEHQJ3eE+sZKLe96bBaaF6bla46843JzLe8NtuhozR3gol7 icnPgBqmMWyCnvF3PGNbWYpk+yDtRC/60XoHeB/Q/9qpf7gBSBb5Ar7p1 l3SJJrL5w0PWAiO1G6uwjUi3t9rGV9OtJqt/zIK889JadWB4tsEILjtMl IUsL9Un9iwQnczPaiq7COs9pDqzC9KrL1cE+Bidcxb/rILokniy8wMCn0 g==; X-IronPort-AV: E=McAfee;i="6400,9594,10393"; a="265359536" X-IronPort-AV: E=Sophos;i="5.92,234,1650956400"; d="scan'208";a="265359536" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jun 2022 04:45:33 -0700 X-IronPort-AV: E=Sophos;i="5.92,234,1650956400"; d="scan'208";a="617949573" Received: from zhihuich-mobl.amr.corp.intel.com (HELO khuang2-desk.gar.corp.intel.com) ([10.212.49.124]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jun 2022 04:45:31 -0700 Message-ID: Subject: Re: [PATCH v7 037/102] KVM: x86/mmu: Track shadow MMIO value/mask on a per-VM basis From: Kai Huang To: isaku.yamahata@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@gmail.com, Paolo Bonzini , Sean Christopherson Date: Thu, 30 Jun 2022 23:45:29 +1200 In-Reply-To: <242df8a7164b593d3702b9ba94889acd11f43cbb.1656366338.git.isaku.yamahata@intel.com> References: <242df8a7164b593d3702b9ba94889acd11f43cbb.1656366338.git.isaku.yamahata@intel.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.2 (3.44.2-1.fc36) MIME-Version: 1.0 X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE 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 Mon, 2022-06-27 at 14:53 -0700, isaku.yamahata@intel.com wrote: > From: Sean Christopherson >=20 > TDX will use a different shadow PTE entry value for MMIO from VMX.=C2=A0 = Add > members to kvm_arch and track value for MMIO per-VM instead of global > variables.=C2=A0 By using the per-VM EPT entry value for MMIO, the existi= ng VMX > logic is kept working. >=20 > In the case of VMX VM case, the EPT entry for MMIO is non-present PTE > (present bit cleared) without backing guest physical address (on EPT > violation, KVM searches backing guest memory and it finds there is no > backing guest page.) or the value to trigger EPT misconfiguration.=C2=A0 = Once > MMIO is triggered on the EPT entry, the EPT entry is updated to trigger E= PT > misconfiguration for the future MMIO on the same GPA.=C2=A0 It allows KVM= to > understand the memory access is for MMIO without searching backing guest > pages.). And then KVM parses guest instruction to figure out > address/value/width for MMIO. >=20 > In the case of the guest TD, the guest memory is protected so that VMM > can't parse guest instruction to understand the value and access width fo= r > MMIO.=C2=A0 Instead, VMM sets up (Shared) EPT to trigger #VE by clearing > the VE-suppress bit.=C2=A0 When the guest TD issues MMIO, #VE is injected= .=C2=A0 Guest VE > handler converts MMIO access into MMIO hypercall to pass > address/value/width for MMIO to VMM. (or directly paravirtualize MMIO int= o > hypercall.)=C2=A0 Then VMM can handle the MMIO hypercall without parsing = guest > instructions. This is an infrastructural patch which enables per-VM MMIO caching. Why no= t putting this patch first so you don't need to do below changes (which are introduced by your previous patches)? [...] > =C2=A0 > - if (!is_shadow_present_pte(spte) || is_mmio_spte(spte)) > + if (!is_shadow_present_pte(spte) || > + =C2=A0=C2=A0=C2=A0 is_mmio_spte(vcpu->kvm, spte)) > =C2=A0 break; > =C2=A0 >=20 [...] > @@ -1032,7 +1032,7 @@ static int FNAME(sync_page)(struct kvm_vcpu *vcpu, = struct kvm_mmu_page *sp) > =C2=A0 gfn_t gfn; > =C2=A0 > =C2=A0 if (!is_shadow_present_pte(sp->spt[i]) && > - =C2=A0=C2=A0=C2=A0 !is_mmio_spte(sp->spt[i])) > + =C2=A0=C2=A0=C2=A0 !is_mmio_spte(vcpu->kvm, sp->spt[i])) > =C2=A0 continue;