From patchwork Sat Dec 2 09:31:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhao X-Patchwork-Id: 172790 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1677436vqy; Sat, 2 Dec 2023 02:00:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IGiAjJ+1+rP1ukLHW2M34HnDT/yGbIJFeF+1GXCq/wi8Iql/b8UzTqGW2uX7xoPb7RH87/m X-Received: by 2002:a17:903:1207:b0:1cc:548d:4252 with SMTP id l7-20020a170903120700b001cc548d4252mr1005149plh.57.1701511242742; Sat, 02 Dec 2023 02:00:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701511242; cv=none; d=google.com; s=arc-20160816; b=AVo0PQWMINd7TGv1lHyVzbtF93Ez06QLG9HhTaBi5A13IXdDwx/X0bSKr9pJUjgqH+ ETvmB/xEWPuta1no3MMDyS76Ufxd/aRaZZjSQaQMgkn7l7oIb80vLXOaUWg4YxGzztV/ su2++i3dWratJTaB7soExoPqCmygAdZoZG8xjsHk1bK5tIpQyF+VzLbiwXHQRjDy0LkO 2yi0bu6Et+uDOcA5kKslQwE+y6fFG4yV4F1Kdo7jWyYc09eDXILRGZr1/kUCSuuozQ1n UwwDQX9T+Ll0WNBBOlmbutMe53PDxzZq0RBQHKL+P84t5YODSQGvq8y9h6wvliyOSi+j 8yLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=cyxLWAeUsqI9AaD+RKOM301WBzLWJojjypMxjSJGbT4=; fh=+WI4m5k3dRLR+dR3neThuZkNBTzIm/a8HgtddERL9fA=; b=gz7y2qgDnbQ/NaN/RgpdHm6goD8KIVM4rXW3U9+fVI0cNrhTkdFNSB8AwBb7UvFqhX /se7MDx4RYyuEFeobJEnlnNQiMJPeSSRAhuHX9Tm292CI3tM/iV1eqfSlcTxKjc5/woo zeIn0kE+ufwOsB5lYYcJVhpYv/b6Rx+SnVv7RFGrHlb8xt2VV4JcVPGsZhy7I1wRfl62 DhF8PoYc1OmVsQINBDd4NF11+JFrJYW/TVg4o1IMU4nOFUymqilOPzm/w5HxuUpLd/LC ylGc/kDe6OyW1Z7hGW9NameMCNGXsTFysBC/y9+NHER7Pc3Sm4LID7f/b9NFfWxIXagI NO+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dj8DtcpB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id d11-20020a170902c18b00b001d07ae424a0si226071pld.63.2023.12.02.02.00.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 02:00:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dj8DtcpB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 751DF8081F47; Sat, 2 Dec 2023 02:00:30 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232359AbjLBKAP (ORCPT + 99 others); Sat, 2 Dec 2023 05:00:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbjLBKAN (ORCPT ); Sat, 2 Dec 2023 05:00:13 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FC88181; Sat, 2 Dec 2023 02:00:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701511219; x=1733047219; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=eyjI0l/aTUHZutjS+4cOREv8PCxRPavsmMsLSGZ4+qo=; b=dj8DtcpBbcGAiquQ0YiOO6uWvzXx0YTekQcnBA3k2WO38fOf0k6OetBs xFqcd4ypxBpub92LO0CGqnqqTwtUfEJ7RLFHJ9CT/gBbF9wrbCGOP0NJo dr4P8YyUHdYPpoEev9HxMtXL8bDxn2l3FC70VTHmztcVRmOwzlWDZ6cpa Xn8Og5K0O1I9H9EiEqo39rkkRBHdhcNgTqlZNhIH/l09lJcdXLCelHBBJ 1wZ5vL/cwKqCnQLgiIi1D7LI2hwC7U6Aik/Um0dTcR3DStiNiRkm0+Ql2 nsz9GLrCI0CLES6+/v4fGDSdUpVtSqVOwir8dV/iSmg06qmzlhi3T5GiF A==; X-IronPort-AV: E=McAfee;i="6600,9927,10911"; a="396395293" X-IronPort-AV: E=Sophos;i="6.04,245,1695711600"; d="scan'208";a="396395293" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2023 02:00:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10911"; a="799015506" X-IronPort-AV: E=Sophos;i="6.04,245,1695711600"; d="scan'208";a="799015506" Received: from yzhao56-desk.sh.intel.com ([10.239.159.62]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2023 02:00:15 -0800 From: Yan Zhao To: iommu@lists.linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: alex.williamson@redhat.com, jgg@nvidia.com, pbonzini@redhat.com, seanjc@google.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, kevin.tian@intel.com, baolu.lu@linux.intel.com, dwmw2@infradead.org, yi.l.liu@intel.com, Yan Zhao Subject: [RFC PATCH 32/42] KVM: x86/mmu: add extra param "kvm" to make_mmio_spte() Date: Sat, 2 Dec 2023 17:31:19 +0800 Message-Id: <20231202093119.15407-1-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231202091211.13376-1-yan.y.zhao@intel.com> References: <20231202091211.13376-1-yan.y.zhao@intel.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Sat, 02 Dec 2023 02:00:30 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784163852384606029 X-GMAIL-MSGID: 1784163852384606029 Add an extra param "kvm" to make_mmio_spte() to allow param "vcpu" to be NULL in future to allow generating mmio spte in non-vcpu context. When "vcpu" is NULL, kvm_memslots() rather than kvm_vcpu_memslots() is called to get memslots pointer, so MMIO SPTEs are not allowed to be generated for SMM mode in non-vCPU context. This is a preparation patch for later KVM MMU to export TDP. Note: actually, if the exported TDP is mapped in non-vCPU context, it will not reach make_mmio_spte() due to earlier failure in kvm_handle_noslot_fault(). make_mmio_spte() is modified in this patch to avoid the check of "vcpu" in the caller. Signed-off-by: Yan Zhao --- arch/x86/kvm/mmu/mmu.c | 2 +- arch/x86/kvm/mmu/spte.c | 5 +++-- arch/x86/kvm/mmu/spte.h | 2 +- arch/x86/kvm/mmu/tdp_mmu.c | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index df5651ea99139..e4cae4ff20770 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -296,7 +296,7 @@ static void kvm_flush_remote_tlbs_sptep(struct kvm *kvm, u64 *sptep) static void mark_mmio_spte(struct kvm_vcpu *vcpu, u64 *sptep, u64 gfn, unsigned int access) { - u64 spte = make_mmio_spte(vcpu, gfn, access); + u64 spte = make_mmio_spte(vcpu->kvm, vcpu, gfn, access); trace_mark_mmio_spte(sptep, gfn, spte); mmu_spte_set(sptep, spte); diff --git a/arch/x86/kvm/mmu/spte.c b/arch/x86/kvm/mmu/spte.c index 9060a56e45569..daeab3b9eee1e 100644 --- a/arch/x86/kvm/mmu/spte.c +++ b/arch/x86/kvm/mmu/spte.c @@ -71,9 +71,10 @@ static u64 generation_mmio_spte_mask(u64 gen) return mask; } -u64 make_mmio_spte(struct kvm_vcpu *vcpu, u64 gfn, unsigned int access) +u64 make_mmio_spte(struct kvm *kvm, struct kvm_vcpu *vcpu, u64 gfn, unsigned int access) { - u64 gen = kvm_vcpu_memslots(vcpu)->generation & MMIO_SPTE_GEN_MASK; + struct kvm_memslots *memslots = vcpu ? kvm_vcpu_memslots(vcpu) : kvm_memslots(kvm); + u64 gen = memslots->generation & MMIO_SPTE_GEN_MASK; u64 spte = generation_mmio_spte_mask(gen); u64 gpa = gfn << PAGE_SHIFT; diff --git a/arch/x86/kvm/mmu/spte.h b/arch/x86/kvm/mmu/spte.h index 8f747268a4874..4ad19c469bd73 100644 --- a/arch/x86/kvm/mmu/spte.h +++ b/arch/x86/kvm/mmu/spte.h @@ -539,7 +539,7 @@ bool make_spte(struct kvm_vcpu *vcpu, u64 make_huge_page_split_spte(struct kvm *kvm, u64 huge_spte, union kvm_mmu_page_role role, int index); u64 make_nonleaf_spte(u64 *child_pt, bool ad_disabled); -u64 make_mmio_spte(struct kvm_vcpu *vcpu, u64 gfn, unsigned int access); +u64 make_mmio_spte(struct kvm *kvm, struct kvm_vcpu *vcpu, u64 gfn, unsigned int access); u64 mark_spte_for_access_track(u64 spte); /* Restore an acc-track PTE back to a regular PTE */ diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 5d76d4849e8aa..892cf1f5b57a8 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -962,7 +962,7 @@ static int tdp_mmu_map_handle_target_level(struct kvm_vcpu *vcpu, return RET_PF_RETRY; if (unlikely(!fault->slot)) - new_spte = make_mmio_spte(vcpu, iter->gfn, ACC_ALL); + new_spte = make_mmio_spte(vcpu->kvm, vcpu, iter->gfn, ACC_ALL); else wrprot = make_spte(vcpu, &vcpu->arch.mmu->common, sp, fault->slot, ACC_ALL, iter->gfn, fault->pfn, iter->old_spte,