Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp823700lqb; Wed, 17 Apr 2024 11:44:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXhoftUa015En6bqC304xoAaku1QfGxoR576oBklCOd9ifVt4d/1gZOedUgiYt0uUT3QrN74xYM19yJve7Fpzoe3JQtZSLZ5IKiKwOF0Q== X-Google-Smtp-Source: AGHT+IHWrp5YR8fTd7lE6n8Tl5GbTO2x3p8JzgTsps6az7VD2BEoN9bQXZ0Ff5/GC1HsnC88aAqF X-Received: by 2002:a17:906:30d3:b0:a52:3ecb:ad83 with SMTP id b19-20020a17090630d300b00a523ecbad83mr232285ejb.38.1713379483113; Wed, 17 Apr 2024 11:44:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713379483; cv=pass; d=google.com; s=arc-20160816; b=D1AGEIrI71Hd9+Kp/BRugTCnki19I+1nr9V1Sc1NOhivGg81lO/kPgl9EpclhDTQq1 2NhnuaKD1YdNcA51NLHJZi/bJ8hRUZUcQ8qaSShYMhMPMVheoH8MI9VuPa1aQQts/eXf v2tkc00GZ2awI/8ZWdoEHzYbvsjdhahplpbmJpC+vWY6oHnDgF5iSOj7SiTOFokLSAhQ kaYacNVaqJjqNhlTzo8pbOsai8j2pgWzXKBhad49+h/xgycukIhUg9ib0Pte46hjYe8j /NQK5TNWU0FprjHnzdoEnh5vpymggfU6yD8JfdQbMLJtAl5Lijyn6Gagz5BuA6ngb389 6uzg== 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=xhLBIlsG15cumMVZLRfdHS3f5RIdwjpuCQF+VzpN5Eo=; fh=7AbxetfAwmm/hOxqZ49UZ2Pdy3AIUIDCjFpMLHqpjBs=; b=IQkQSoEZC7cRRYqd1ojHV9qP7G5UZd+KViQlX/LdxoA+ZcXwcb5M8IfY5VfE510EjQ 4yG/BE47ppyHz5EheCWX0g/4czgilUXpk6N1aYmbLG1iiGOhl26t2gLIzGavbCz9/9lN Vh6e7FtWxfKfV2omYaEf9naBSvi1jTKtgdxbQNclnZdWb4twzpfBFH8Vywug6ZFVD+mr kbb1fn5jHguYegqTWxXe1WLajjRUNSUYJPWDEWqwuTfVI8Kjbqs+d6LlDyLyE8jrgEuK C5eKtJmI8/2+r4thqTS19azkks7emBMcvGLMufYFmPxVN6D5Z8e27sY6OuS0fzl1Lh/i AFUw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lQUQj5zI; 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-149072-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149072-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id gf1-20020a170906e20100b00a43db2d8b90si7001417ejb.325.2024.04.17.11.44.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 11:44:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-149072-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lQUQj5zI; 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-149072-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149072-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 am.mirrors.kernel.org (Postfix) with ESMTPS id D13141F25110 for ; Wed, 17 Apr 2024 18:44:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1FBC91BC5C; Wed, 17 Apr 2024 18:44:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="lQUQj5zI" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 9AD5E22338; Wed, 17 Apr 2024 18:44:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713379464; cv=none; b=AO1aJUcBi4Pvvfk2fk7yhCyPRJxdwvtV97zDZu39P4glwmUMTCJUJUvTbfBFEk+kfEqdCtHyhUcH6A5+0rLO8+aPIw2sbm5wvJmpe0/3cSiniE73MDZt2mzKW7YeEQXQbtaWZawXDhox4m7iQmWDTLW1UdilqJkju4yoAYuG+HM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713379464; c=relaxed/simple; bh=/MgPf3JdMf3WsCCU3RTyq2hSaaAaGOGjKybT8hE2a0I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sGa0ChI8bzRsPaJJq4UbJeHL01jSrbflGrowoTURe24+EcjYKKtkxIlLyKv3e7URSdnxyKCkgf6p2kArQ2BMibcFYoL318pzsAxEKc8S2BFSEhSSKc1XOSw/rmVeqNyq6yUB75frR9QUqh5Hon3R8yaFCgi2sViVaFOQop3fyGA= 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=lQUQj5zI; arc=none smtp.client-ip=198.175.65.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=1713379463; x=1744915463; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=/MgPf3JdMf3WsCCU3RTyq2hSaaAaGOGjKybT8hE2a0I=; b=lQUQj5zIIGR6weey/tTW2jLddzXuGwoTJTe+mYjX6rP6idX9WEiy19ps 0M0rfhDW91jw8A+lvYVksbUUHD9iqTa9kQH0AyNoXBDYMvXvsD4b1k8NZ IFtgzHyF75cP2merojVuK28RjSGWlbpIpZDmKcUPWxYRxVzRbFMf60gTM raLyiGzqatq/u627rWLyYZxtoel/bgB5lReBOvJhd9elNIcGk+MgZxn10 II1mZM4bkA85CrWkPxhWV0Bk378vCwHdoPJlS+EM3hIgTOghuXKzixFC/ BFl080/bXyPyT46Cglr5PUrMqzJBOiXA0UNtuf07Pej3E8yFEF+y6uY0Z A==; X-CSE-ConnectionGUID: ksZfUWL5SiesRffaqWKNYw== X-CSE-MsgGUID: eMc8i/Z/RuibjJQCwTWIIw== X-IronPort-AV: E=McAfee;i="6600,9927,11046"; a="9047005" X-IronPort-AV: E=Sophos;i="6.07,209,1708416000"; d="scan'208";a="9047005" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2024 11:44:22 -0700 X-CSE-ConnectionGUID: 2uUunGCcR+SpwJWuzhuYtA== X-CSE-MsgGUID: dL8AWQALQ66oDjtbRMoRDg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,209,1708416000"; d="scan'208";a="23309529" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2024 11:44:21 -0700 Date: Wed, 17 Apr 2024 11:44:20 -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 05/10] KVM: x86/mmu: Introduce kvm_tdp_map_page() to populate guest memory Message-ID: <20240417184420.GH3039520@ls.amr.corp.intel.com> References: <9b866a0ae7147f96571c439e75429a03dcb659b6.1712785629.git.isaku.yamahata@intel.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; charset=utf-8 Content-Disposition: inline In-Reply-To: On Wed, Apr 17, 2024 at 03:04:08PM +0800, Chao Gao wrote: > On Wed, Apr 10, 2024 at 03:07:31PM -0700, isaku.yamahata@intel.com wrote: > >From: Isaku Yamahata > > > >Introduce a helper function to call the KVM fault handler. It allows a new > >ioctl to invoke the KVM fault handler to populate without seeing RET_PF_* > >enums or other KVM MMU internal definitions because RET_PF_* are internal > >to x86 KVM MMU. The implementation is restricted to two-dimensional paging > >for simplicity. The shadow paging uses GVA for faulting instead of L1 GPA. > >It makes the API difficult to use. > > > >Signed-off-by: Isaku Yamahata > >--- > >v2: > >- Make the helper function two-dimensional paging specific. (David) > >- Return error when vcpu is in guest mode. (David) > >- Rename goal_level to level in kvm_tdp_mmu_map_page(). (Sean) > >- Update return code conversion. Don't check pfn. > > RET_PF_EMULATE => EINVAL, RET_PF_CONTINUE => EIO (Sean) > >- Add WARN_ON_ONCE on RET_PF_CONTINUE and RET_PF_INVALID. (Sean) > >- Drop unnecessary EXPORT_SYMBOL_GPL(). (Sean) > >--- > > arch/x86/kvm/mmu.h | 3 +++ > > arch/x86/kvm/mmu/mmu.c | 32 ++++++++++++++++++++++++++++++++ > > 2 files changed, 35 insertions(+) > > > >diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h > >index e8b620a85627..51ff4f67e115 100644 > >--- a/arch/x86/kvm/mmu.h > >+++ b/arch/x86/kvm/mmu.h > >@@ -183,6 +183,9 @@ static inline void kvm_mmu_refresh_passthrough_bits(struct kvm_vcpu *vcpu, > > __kvm_mmu_refresh_passthrough_bits(vcpu, mmu); > > } > > > >+int kvm_tdp_map_page(struct kvm_vcpu *vcpu, gpa_t gpa, u64 error_code, > >+ u8 *level); > >+ > > /* > > * Check if a given access (described through the I/D, W/R and U/S bits of a > > * page fault error code pfec) causes a permission fault with the given PTE > >diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > >index 91dd4c44b7d8..a34f4af44cbd 100644 > >--- a/arch/x86/kvm/mmu/mmu.c > >+++ b/arch/x86/kvm/mmu/mmu.c > >@@ -4687,6 +4687,38 @@ int kvm_tdp_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) > > return direct_page_fault(vcpu, fault); > > } > > > >+int kvm_tdp_map_page(struct kvm_vcpu *vcpu, gpa_t gpa, u64 error_code, > >+ u8 *level) > >+{ > >+ int r; > >+ > >+ /* Restrict to TDP page fault. */ > > need to explain why. (just as you do in the changelog) Sure. > >+ if (vcpu->arch.mmu->page_fault != kvm_tdp_page_fault) > > page fault handlers (i.e., vcpu->arch.mmu->page_fault()) will be called > finally. why not let page fault handlers reject the request to get rid of > this ad-hoc check? We just need to plumb a flag indicating this is a > pre-population request into the handlers. I think this way is clearer. > > What do you think? __kvm_mmu_do_page_fault() doesn't check if the mmu mode is TDP or not. If we don't want to check page_fault handler, the alternative check would be if (!vcpu->arch.mmu->direct). Or we will require the caller to guarantee that MMU mode is tdp (direct or tdp_mmu). -- Isaku Yamahata