Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp495319lqt; Fri, 19 Apr 2024 02:00:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWccRialvUU87t8U3Sl2BIU3GXZMfh/f0e0jr2TerZW170AeChNxMkFPrDOYH7g39mkcyol+bJGNiQ+ZljOxG+Li8OQuHpPwkTd7Pyyxw== X-Google-Smtp-Source: AGHT+IF/IiRu5UsK4CWTZMLrk9Fv0KrUSbqub3i0ExnQE03wLv0AW1ivg0igU9PcL8XOuarCEvNF X-Received: by 2002:a17:902:cec8:b0:1e5:62:7ac0 with SMTP id d8-20020a170902cec800b001e500627ac0mr1975798plg.14.1713517201529; Fri, 19 Apr 2024 02:00:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713517201; cv=pass; d=google.com; s=arc-20160816; b=nu+1Yb1bUvCIgKmA5+WAf8QDa+bIH4l2GCNH+UdBuExGlUw5EcedeXn9J/xnTzPZ32 Y/mCLxK8BfAxCFM0Rcvk4qAWJjIKqW21AndHF4/J9CHtw0lVnlKdSr+jOds3uqfmibSc Vz2CmH+zIQL9oFvIcqMOt6OO2bMYnl1A8o6KIrbEtNkKIahImSAPrX3zr0J2GCY6igQr LnXu0iyXNjCHa7DEesvXRzaWWIWyyKPUjrc+FIoMHcSJT7fcbHDZF9w0xXATMTUH9JXQ abFmeO1R4MHtV/NiGb/xnbwT1gY93swUP1/XH+TxJdURbSp8zVUZib5O5eF6pcm7QxuZ HkFg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=6x7YBb66dnzoHcmKY1tLeMz57M5blqYb9nwNSC1fM+k=; fh=fhNDg/rgS8N1tOOUFS+PxlxZhbe2WE6Cy8nO5yBhacU=; b=sM5NYgks0cvmtz5N1V0Yij/Clai17GuwG0whqmaz2BEStGBXsV1roFS7nNJ6EX+HNO 9ZJV3LYnvH9RZEBMoDISYF434nxDpD3oN1myyMLDIhCUZnF3Riq9FNbba/sVZYKYfjw2 BYDKfFVAEi2oBebu2WR9wdQSTdvGrBqC0+olEhaQ24VWkYF4E1DMGhl5H2NMprAil3NO qaopKmHShWPpjAUQ5eOd2GM4s+qphFKi94uY5hmaL3rNhasqyNmxJ5rPh8WywOxGGEyi W1Cz1QfMSAbaS6JzvyXso/5Fp0xDPC+eCdCODPB9kmPB9Uxwpfz8qxDvwkXSOgLorFxP md1Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VkUZZOHb; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-151200-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151200-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 k14-20020a170902c40e00b001e84ad92f52si3007748plk.486.2024.04.19.02.00.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 02:00:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151200-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=@redhat.com header.s=mimecast20190719 header.b=VkUZZOHb; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-151200-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151200-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 C7FF0281E57 for ; Fri, 19 Apr 2024 09:00:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 598D37BB17; Fri, 19 Apr 2024 08:59:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VkUZZOHb" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAC9E7440B for ; Fri, 19 Apr 2024 08:59:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713517175; cv=none; b=C9uE3osXEmB3x14dIn91l7wm+8qgxN767HVt/bIxEHV6gTtLaUXycRh75ERCo85rBkoR5tVsrNNqK7RGzW7ph/fo7ELSQmOZOqU8SR5/2/ahoqDIgfAa1eKgrxOfPuRIVp5IIX/FlKMpV40TQiGDIwGU3CAVIehvk6Aqfp+yyr4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713517175; c=relaxed/simple; bh=MlYJpZfiuuMe5cB6DpdDfoHLrBt/ox1lOXIQJOlkpek=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NniBE2f3yy9XoMbzhZk2aIrD/lWt6rtvegkGUP1TohxCY/o/UYyC7BEDVzgoCKh1+/PZ6ap3MCAwj1u750i8B7iYePTDDbO1qYv/V1JY5+vpSsH3L+LZSvWiKcdOULCDAhHp1kyMPpRPhzh5SbDcI7Chx1KXxWT5ccP9FanSO30= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=VkUZZOHb; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713517172; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6x7YBb66dnzoHcmKY1tLeMz57M5blqYb9nwNSC1fM+k=; b=VkUZZOHbgL/6vfg4ZUsfdPK+4R1LbALHuXICDK0MY7uZg1tEgj4ufacPdPvL1ZUlPrcdky udmzmuudNP1KhRMB3FTbRgRuMZweRFLVRzHxQqk/PsIUFvmJJ/AoW/8EaItawNFoSENMpJ rhMnVCZv1P2t6KteaXF4CPwnGe0dars= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-626-Qxu4fn7EOdCxpIzEZ7KaRQ-1; Fri, 19 Apr 2024 04:59:29 -0400 X-MC-Unique: Qxu4fn7EOdCxpIzEZ7KaRQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 32F5118A2BC7; Fri, 19 Apr 2024 08:59:29 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 01EFA20368A8; Fri, 19 Apr 2024 08:59:28 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: isaku.yamahata@intel.com, xiaoyao.li@intel.com, binbin.wu@linux.intel.com, seanjc@google.com, rick.p.edgecombe@intel.com Subject: [PATCH 3/6] KVM: x86/mmu: Extract __kvm_mmu_do_page_fault() Date: Fri, 19 Apr 2024 04:59:24 -0400 Message-ID: <20240419085927.3648704-4-pbonzini@redhat.com> In-Reply-To: <20240419085927.3648704-1-pbonzini@redhat.com> References: <20240419085927.3648704-1-pbonzini@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 From: Isaku Yamahata Extract out __kvm_mmu_do_page_fault() from kvm_mmu_do_page_fault(). The inner function is to initialize struct kvm_page_fault and to call the fault handler, and the outer function handles updating stats and converting return code. KVM_PRE_FAULT_MEMORY will call the KVM page fault handler. This patch makes the emulation_type always set irrelevant to the return code. kvm_mmu_page_fault() is the only caller of kvm_mmu_do_page_fault(), and references the value only when PF_RET_EMULATE is returned. Therefore, this adjustment doesn't affect functionality. No functional change intended. Suggested-by: Sean Christopherson Signed-off-by: Isaku Yamahata Message-ID: Signed-off-by: Paolo Bonzini --- arch/x86/kvm/mmu/mmu_internal.h | 38 +++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h index e68a60974cf4..9baae6c223ee 100644 --- a/arch/x86/kvm/mmu/mmu_internal.h +++ b/arch/x86/kvm/mmu/mmu_internal.h @@ -287,8 +287,8 @@ static inline void kvm_mmu_prepare_memory_fault_exit(struct kvm_vcpu *vcpu, fault->is_private); } -static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, - u64 err, bool prefetch, int *emulation_type) +static inline int __kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, + u64 err, bool prefetch, int *emulation_type) { struct kvm_page_fault fault = { .addr = cr2_or_gpa, @@ -318,6 +318,27 @@ static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, fault.slot = kvm_vcpu_gfn_to_memslot(vcpu, fault.gfn); } + if (IS_ENABLED(CONFIG_MITIGATION_RETPOLINE) && fault.is_tdp) + r = kvm_tdp_page_fault(vcpu, &fault); + else + r = vcpu->arch.mmu->page_fault(vcpu, &fault); + + if (r == RET_PF_EMULATE && fault.is_private) { + kvm_mmu_prepare_memory_fault_exit(vcpu, &fault); + r = -EFAULT; + } + + if (fault.write_fault_to_shadow_pgtable && emulation_type) + *emulation_type |= EMULTYPE_WRITE_PF_TO_SP; + + return r; +} + +static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, + u64 err, bool prefetch, int *emulation_type) +{ + int r; + /* * Async #PF "faults", a.k.a. prefetch faults, are not faults from the * guest perspective and have already been counted at the time of the @@ -326,18 +347,7 @@ static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, if (!prefetch) vcpu->stat.pf_taken++; - if (IS_ENABLED(CONFIG_MITIGATION_RETPOLINE) && fault.is_tdp) - r = kvm_tdp_page_fault(vcpu, &fault); - else - r = vcpu->arch.mmu->page_fault(vcpu, &fault); - - if (r == RET_PF_EMULATE && fault.is_private) { - kvm_mmu_prepare_memory_fault_exit(vcpu, &fault); - return -EFAULT; - } - - if (fault.write_fault_to_shadow_pgtable && emulation_type) - *emulation_type |= EMULTYPE_WRITE_PF_TO_SP; + r = __kvm_mmu_do_page_fault(vcpu, cr2_or_gpa, err, prefetch, emulation_type); /* * Similar to above, prefetch faults aren't truly spurious, and the -- 2.43.0