Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp296312lqb; Tue, 16 Apr 2024 16:43:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXXmQRlQdvfRaa5Tgfa4XjKOIVrMyEiw/OA3Ny8tmBDPY+bp5YOUDha4DPnJSxZqv5L2xn9fu0/jw3sviwJm1lgQmL2lpwE+AEmQa4wAQ== X-Google-Smtp-Source: AGHT+IEJuNEYEc9c+OyoSMRKjJamPCLxn+2xsfLVTcwf/WX5h/9l+Zq9ITsNXE6Y5nfvGAQyRZBa X-Received: by 2002:a17:90a:fa84:b0:2a4:892f:39b2 with SMTP id cu4-20020a17090afa8400b002a4892f39b2mr14369206pjb.11.1713311028892; Tue, 16 Apr 2024 16:43:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713311028; cv=pass; d=google.com; s=arc-20160816; b=ubBCsuIpWS0tI3xn9Zi2wFjNpiGI0C9CuNkzqYcuCq8sZq5vL3Uy8WVc655I3Fcngi QFh5Ddynk3cYqxdKjhnpUIF53u9bDNYohPr/3BOOpGTmJeRFPWJSdpo+RZAV+UktkCDU LDcOmuKTOFm3bcfEpYTQboT7TUT8iTlX+Kdf8wnrJ99C7G1r6DpPEnsOkLjcPsPO8H4K Arw0SvHoBx67/D3uP4Q14udNp0/mnsrQfSugiRDqYfWSLmIWMW+z5vLvl2wBSljKlsdQ iWNthnLiWIjBHx8206RaLYTnk2rRsNLzlV+tsbMjzbi4X4l4C8R/Q0B5Z2/VNZjqYhF0 8IAg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=l4hf3gAcaV7W88KWjlYQXIMSLivDYuUGF9YQl4WGxec=; fh=7AbxetfAwmm/hOxqZ49UZ2Pdy3AIUIDCjFpMLHqpjBs=; b=a6ZpSwUU3jkTO1HS8G97D5dj2JeVx2HdBg5hsRq6xnFuvW1MQKzqhOzkA6fwbnbylL SL/WwgGcgCiKnQuq6nC2WNhcOLXAnWnqRibMX+rDvug87HoP30uJpePOrskuKbiYSVWc Ez7RgCfWTsKGHnHbCJwoEZupMEDiR0mrm7vVoOKgDzMlwH1dQIyO2Gz9jNdJgv+T8alg 3g67a+mmEaidGTnuQaw+QNDQzVjVkV3TWpcBr0LhilJUf9r8JtKjG+4PJUYg5xtDfefe 7IfFA+v+pBqi9fcQySV2fT6lAIm2U2eRrVmNTR1mNhuXEGzbbGtdN92X/qFuLIQN8Gz/ sajA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ScFb9Qhc; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-147759-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147759-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id lw12-20020a17090b180c00b002a6383593bdsi235259pjb.90.2024.04.16.16.43.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 16:43:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-147759-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ScFb9Qhc; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-147759-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147759-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 8F8D2283E13 for ; Tue, 16 Apr 2024 23:43:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3FD6313AA3B; Tue, 16 Apr 2024 23:43:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ScFb9Qhc" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) (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 1988113A415; Tue, 16 Apr 2024 23:43:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713311018; cv=none; b=TqDKpOD84vJ8KCUZxVheUPPp01K1XtiUNGBg9NreijF+zpQkpxixzzWn+HrlsyDEjNl1TjyDDES9zCyZF40VlKD7bBi7VbLX5C/5WtFja22zeW5t7zAm0NUZ/iuhk2WIE74eMHKnZjOOJt7b28UVOTAwE+l8aZJyCfdBhb75fdU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713311018; c=relaxed/simple; bh=8aUqXz+i9chtNJef9my3dWa4P1+x056EvnBQkIpWUR8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Q4ZwGzCLKjfhB6XKfNBhtcN2HXXP0NeLmbw+X+ROstlqwXqpNtPs0OIuUeAQeUNkCUPrhDOZaljF97zPR0BLRQ8AnFzBBC0pamTsqo3mylrGUZR+hX3BE7EghHPRTHBqfHy1SePXzoS8KPyN7Yf5IchiGrbKS6n8Y9yODq0ODPg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ScFb9Qhc; arc=none smtp.client-ip=192.198.163.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1713311016; x=1744847016; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=8aUqXz+i9chtNJef9my3dWa4P1+x056EvnBQkIpWUR8=; b=ScFb9QhcCypvNMmgU0lDLbqUYks3Je3MDtnw2AfMuIxOfGztcU7aJX7D H8lV6z55FNFM8yaiu0mCVq26oHSA73X8PS7TA1XT3Lx1XM35I3rBMST0d l8MJmEGqp7WDfkH+QHhqN0BdzjoPDwLNQfOeXgkzv3aQZBLHSxecwpMh1 TwnJZpVk5srGakibMsSlJ0+y1tWwgyeFfdfzbhfxYRQuZCNDtKkcf17py YLHtnN3mqxL0xiE1I3PCd3DqXFKozaRrPePv9vJvHMWu8CW4+y2iYicFz DbQFvS7M9YI+xYnOBLNI8c4EqhSLfn7tNkq/p9+pK47RB0YeX0e3HXgQb g==; X-CSE-ConnectionGUID: TdUH60YqTuKhfLP9reL6YQ== X-CSE-MsgGUID: jNx1m/9pRuqzBIlHJBLQ1g== X-IronPort-AV: E=McAfee;i="6600,9927,11046"; a="8645383" X-IronPort-AV: E=Sophos;i="6.07,207,1708416000"; d="scan'208";a="8645383" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2024 16:43:35 -0700 X-CSE-ConnectionGUID: fS8w87q+Rv2YO7ZuLxYjmw== X-CSE-MsgGUID: OGrvR6teSV+HtibVE03PkQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,207,1708416000"; d="scan'208";a="22834585" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2024 16:43:35 -0700 Date: Tue, 16 Apr 2024 16:43:34 -0700 From: Isaku Yamahata To: Chao Gao Cc: isaku.yamahata@intel.com, kvm@vger.kernel.org, isaku.yamahata@gmail.com, linux-kernel@vger.kernel.org, Sean Christopherson , Paolo Bonzini , Michael Roth , David Matlack , Federico Parola , Kai Huang , isaku.yamahata@linux.intel.com Subject: Re: [PATCH v2 03/10] KVM: x86/mmu: Extract __kvm_mmu_do_page_fault() Message-ID: <20240416234334.GA3039520@ls.amr.corp.intel.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: On Tue, Apr 16, 2024 at 04:22:35PM +0800, Chao Gao wrote: > > >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. > > This is benign. But what's the benefit of doing this? To avoid increment vcpu->stat. Because originally this was VM ioctl, I wanted to avoid touch vCPU stat. Now it's vCPU ioctl, it's fine to increment them. Probably we can drop this patch and use kvm_mmu_do_page_fault(). > > >+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,14 +318,6 @@ 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); > > } > > > >- /* > >- * 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 > >- * original fault. > >- */ > >- if (!prefetch) > >- vcpu->stat.pf_taken++; > >- > > if (IS_ENABLED(CONFIG_MITIGATION_RETPOLINE) && fault.is_tdp) > > r = kvm_tdp_page_fault(vcpu, &fault); > > else > >@@ -333,12 +325,30 @@ static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, > > > > if (r == RET_PF_EMULATE && fault.is_private) { > > kvm_mmu_prepare_memory_fault_exit(vcpu, &fault); > >- return -EFAULT; > >+ 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 > >+ * original fault. > >+ */ > >+ if (!prefetch) > >+ vcpu->stat.pf_taken++; > >+ > >+ r = __kvm_mmu_do_page_fault(vcpu, cr2_or_gpa, err, prefetch, emulation_type); > > bail out if r < 0? The following if clauses checks RET_PF_xxx > 0. -- Isaku Yamahata