From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43FB9C43334 for ; Fri, 24 Jun 2022 09:06:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 678458E0206; Fri, 24 Jun 2022 05:06:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 626E98E0205; Fri, 24 Jun 2022 05:06:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4EEAB8E0206; Fri, 24 Jun 2022 05:06:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 3CABA8E0205 for ; Fri, 24 Jun 2022 05:06:21 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 009E820E29 for ; Fri, 24 Jun 2022 09:06:20 +0000 (UTC) X-FDA: 79612548120.15.8ACCA1A Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by imf10.hostedemail.com (Postfix) with ESMTP id BD545C0011 for ; Fri, 24 Jun 2022 09:06:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656061578; x=1687597578; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=pFiQPRhH8oZ/U60WvOqK308IWSu6PiUOr+QWUMTnIwQ=; b=IORdGZtjVSlbtQC0JEmTPxoXoVTsV2arwyzB+7Nu7UxOMd5somnwyza4 LYARNe2+iz0TMlxTIOVzrJ6EMyO/+XSH6D1PS1Z75YlhoubTIT3533fvv Gv/cOWLmgx0ZGRJ18mwzFlLpJHNJOjHZfbixveor6j9WEaon2cbw4gPbT oPeHPoPnDdxz/niBXVksoHGKNlGev9cAdxIkvC8KJqVHjtjRJHO/zPvf5 mfrBEETwWQQF6OO9heCKDqezerDFnvPyrFE4qhO9ujt9Tsz85JUqs3j6M IU/87g5W+ZVgbqk3ox1Uto1f76wNtNkuRIxL0wMMvODee+JMExJDnsTGn g==; X-IronPort-AV: E=McAfee;i="6400,9594,10387"; a="279726529" X-IronPort-AV: E=Sophos;i="5.92,218,1650956400"; d="scan'208";a="279726529" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jun 2022 02:06:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,218,1650956400"; d="scan'208";a="656571912" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.192.101]) by fmsmga004.fm.intel.com with ESMTP; 24 Jun 2022 02:06:06 -0700 Date: Fri, 24 Jun 2022 17:02:46 +0800 From: Chao Peng To: "Nikunj A. Dadhania" Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, qemu-devel@nongnu.org, Paolo Bonzini , Jonathan Corbet , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H . Peter Anvin" , Hugh Dickins , Jeff Layton , "J . Bruce Fields" , Andrew Morton , Mike Rapoport , Steven Price , "Maciej S . Szmigiero" , Vlastimil Babka , Vishal Annapurve , Yu Zhang , "Kirill A . Shutemov" , luto@kernel.org, jun.nakajima@intel.com, dave.hansen@intel.com, ak@linux.intel.com, david@redhat.com, aarcange@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, Quentin Perret , Michael Roth , mhocko@suse.com Subject: Re: [PATCH v6 6/8] KVM: Handle page fault for private memory Message-ID: <20220624090246.GA2181919@chaop.bj.intel.com> Reply-To: Chao Peng References: <20220519153713.819591-1-chao.p.peng@linux.intel.com> <20220519153713.819591-7-chao.p.peng@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656061580; a=rsa-sha256; cv=none; b=RJHS7yU5BKrRUjW/wCFzTGDKzQ+CSSIQOvUFPku5ecyXgqIBG1g+7UcpPGmDRYYOa4Wtfi NxS/PWmLDMusFHvaOAYTAlxIRMaUQppmBN5aJDKw792GbVKkE3ZBU5cfb+xUVGsD7zWpSh GxXZM14EUHC//kPS/rt6MumsW5PJcG8= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=IORdGZtj; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf10.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 192.55.52.120) smtp.mailfrom=chao.p.peng@linux.intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656061580; h=from:from:sender:reply-to: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=C1r2WCw8FmFbrj8Tu3GplHjMaXCmM0IIQnYBAn0gVGE=; b=5Vigls97QYMgtKvASvaXGD3LPikOoU+Jo+lgW1LwbLK/8GAmuI+uoo/DsHLpWbLHIOVB0f fjQcN0dotVKFAhg4dGGamJipBntrUbyCJFJA8DOp4+PaKei7eYq46ECtaFNK5qasy5T6Qd Qge0NqFo0PbllDSD0lZTd11w+BUXgS4= X-Stat-Signature: ugsgsf4qwrti9q7q587ac3mjr1adkz5j X-Rspam-User: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: BD545C0011 Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=IORdGZtj; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf10.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 192.55.52.120) smtp.mailfrom=chao.p.peng@linux.intel.com X-HE-Tag: 1656061578-88046 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Jun 24, 2022 at 09:28:23AM +0530, Nikunj A. Dadhania wrote: > On 5/19/2022 9:07 PM, Chao Peng wrote: > > A page fault can carry the information of whether the access if private > > or not for KVM_MEM_PRIVATE memslot, this can be filled by architecture > > code(like TDX code). To handle page faut for such access, KVM maps the > > page only when this private property matches host's view on this page > > which can be decided by checking whether the corresponding page is > > populated in the private fd or not. A page is considered as private when > > the page is populated in the private fd, otherwise it's shared. > > > > For a successful match, private pfn is obtained with memfile_notifier > > callbacks from private fd and shared pfn is obtained with existing > > get_user_pages. > > > > For a failed match, KVM causes a KVM_EXIT_MEMORY_FAULT exit to > > userspace. Userspace then can convert memory between private/shared from > > host's view then retry the access. > > > > Co-developed-by: Yu Zhang > > Signed-off-by: Yu Zhang > > Signed-off-by: Chao Peng > > --- > > arch/x86/kvm/mmu.h | 1 + > > arch/x86/kvm/mmu/mmu.c | 70 +++++++++++++++++++++++++++++++-- > > arch/x86/kvm/mmu/mmu_internal.h | 17 ++++++++ > > arch/x86/kvm/mmu/mmutrace.h | 1 + > > arch/x86/kvm/mmu/paging_tmpl.h | 5 ++- > > include/linux/kvm_host.h | 22 +++++++++++ > > 6 files changed, 112 insertions(+), 4 deletions(-) > > > > diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h > > index 7e258cc94152..c84835762249 100644 > > --- a/arch/x86/kvm/mmu.h > > +++ b/arch/x86/kvm/mmu.h > > @@ -176,6 +176,7 @@ struct kvm_page_fault { > > > > /* Derived from mmu and global state. */ > > const bool is_tdp; > > + const bool is_private; > > const bool nx_huge_page_workaround_enabled; > > > > /* > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > > index afe18d70ece7..e18460e0d743 100644 > > --- a/arch/x86/kvm/mmu/mmu.c > > +++ b/arch/x86/kvm/mmu/mmu.c > > @@ -2899,6 +2899,9 @@ int kvm_mmu_max_mapping_level(struct kvm *kvm, > > if (max_level == PG_LEVEL_4K) > > return PG_LEVEL_4K; > > > > + if (kvm_slot_is_private(slot)) > > + return max_level; > > Can you explain the rationale behind the above change? > AFAIU, this overrides the transparent_hugepage=never setting for both > shared and private mappings. As Sean pointed out, this should check against fault->is_private instead of the slot. For private fault, the level is retrieved and stored to fault->max_level in kvm_faultin_pfn_private() instead of here. For shared fault, it will continue to query host_level below. For private fault, the host level has already been accounted in kvm_faultin_pfn_private(). Chao > > > host_level = host_pfn_mapping_level(kvm, gfn, pfn, slot); > > return min(host_level, max_level); > > } > > Regards > Nikunj