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 99A24C433FE for ; Thu, 6 Jan 2022 12:36:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A4576B0078; Thu, 6 Jan 2022 07:36:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 253E16B007E; Thu, 6 Jan 2022 07:36:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 143606B0082; Thu, 6 Jan 2022 07:36:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0166.hostedemail.com [216.40.44.166]) by kanga.kvack.org (Postfix) with ESMTP id 066A26B0078 for ; Thu, 6 Jan 2022 07:36:14 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id B17988249980 for ; Thu, 6 Jan 2022 12:36:13 +0000 (UTC) X-FDA: 78999809826.27.933DB65 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by imf17.hostedemail.com (Postfix) with ESMTP id A98564000D for ; Thu, 6 Jan 2022 12:35:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641472573; x=1673008573; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=xyua25iDh4JWOKyPASiZgoHVEXaKTA4j0IhBTE9lILI=; b=DcovagNVQjvk8gor6qUhJcX2QSYBegQsK9XktF0VgH9Cm7fSmU8gh2y1 gaFRmbVP10orx63hX440GRU0eOTH3gN2AbE6sn9VFPPylGl0hfZHgHlQO 5IM/gfAdNPZTkTHwGoZ9hP0C4ZKXdY8iSZ4cTEfhKEjl0tWnIVO5ElIvN 2HeQKLmybsPMEXeUI8anLsS6IMaSW8Cf2ZMlICbOVt01EUcQW/BexI7BI OFJSm3orqdGLEfbU4LfHzUlqYZGOGmzPMimv4os7PMjA6rfmCGXB1481N PblYijXQAkQvb/hhKxCIHaBpuHGMU9fiBXby8yDMYIJWnAhNhuYtRqVt6 A==; X-IronPort-AV: E=McAfee;i="6200,9189,10217"; a="229459944" X-IronPort-AV: E=Sophos;i="5.88,267,1635231600"; d="scan'208";a="229459944" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jan 2022 04:36:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,267,1635231600"; d="scan'208";a="472880803" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.192.101]) by orsmga006.jf.intel.com with ESMTP; 06 Jan 2022 04:35:59 -0800 Date: Thu, 6 Jan 2022 20:35:25 +0800 From: Chao Peng To: Sean Christopherson Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, qemu-devel@nongnu.org, Paolo Bonzini , Jonathan Corbet , 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 , Yu Zhang , "Kirill A . Shutemov" , luto@kernel.org, john.ji@intel.com, susie.li@intel.com, jun.nakajima@intel.com, dave.hansen@intel.com, ak@linux.intel.com, david@redhat.com Subject: Re: [PATCH v3 kvm/queue 11/16] KVM: Add kvm_map_gfn_range Message-ID: <20220106123525.GA43371@chaop.bj.intel.com> Reply-To: Chao Peng References: <20211223123011.41044-1-chao.p.peng@linux.intel.com> <20211223123011.41044-12-chao.p.peng@linux.intel.com> <20211224041351.GB44042@chaop.bj.intel.com> <20211231023334.GA7255@chaop.bj.intel.com> <20220105061410.GA25283@chaop.bj.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-Stat-Signature: 3qghts7wr4jwmz9dwrtuehfiqnq13cdt X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: A98564000D Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=DcovagNV; spf=none (imf17.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 134.134.136.126) smtp.mailfrom=chao.p.peng@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com X-HE-Tag: 1641472550-638066 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 Wed, Jan 05, 2022 at 05:03:23PM +0000, Sean Christopherson wrote: > On Wed, Jan 05, 2022, Chao Peng wrote: > > On Tue, Jan 04, 2022 at 05:31:30PM +0000, Sean Christopherson wrote: > > > On Fri, Dec 31, 2021, Chao Peng wrote: > > > > On Fri, Dec 24, 2021 at 12:13:51PM +0800, Chao Peng wrote: > > > > > On Thu, Dec 23, 2021 at 06:06:19PM +0000, Sean Christopherson wrote: > > > > > > On Thu, Dec 23, 2021, Chao Peng wrote: > > > > > > > This new function establishes the mapping in KVM page tables for a > > > > > > > given gfn range. It can be used in the memory fallocate callback for > > > > > > > memfd based memory to establish the mapping for KVM secondary MMU when > > > > > > > the pages are allocated in the memory backend. > > > > > > > > > > > > NAK, under no circumstance should KVM install SPTEs in response to allocating > > > > > > memory in a file. The correct thing to do is to invalidate the gfn range > > > > > > associated with the newly mapped range, i.e. wipe out any shared SPTEs associated > > > > > > with the memslot. > > > > > > > > > > Right, thanks. > > > > > > > > BTW, I think the current fallocate() callback is just useless as long as > > > > we don't want to install KVM SPTEs in response to allocating memory in a > > > > file. The invalidation of the shared SPTEs should be notified through > > > > mmu_notifier of the shared memory backend, not memfd_notifier of the > > > > private memory backend. > > > > > > No, because the private fd is the final source of truth as to whether or not a > > > GPA is private, e.g. userspace may choose to not unmap the shared backing. > > > KVM's rule per Paolo's/this proposoal is that a GPA is private if it has a private > > > memslot and is present in the private backing store. And the other core rule is > > > that KVM must never map both the private and shared variants of a GPA into the > > > guest. > > > > That's true, but I'm wondering if zapping the shared variant can be > > handled at the time when the private one gets mapped in the KVM page > > fault. No bothering the backing store to dedicate a callback to tell > > KVM. > > Hmm, I don't think that would work for the TDP MMU due to page faults taking > mmu_lock for read. E.g. if two vCPUs concurrently fault in both the shared and > private variants, a race could exist where the private page fault sees the gfn > as private and the shared page fault sees it as shared. In that case, both faults > will install a SPTE and KVM would end up running with both variants mapped into the > guest. > > There's also a performance penalty, as KVM would need to walk the shared EPT tree > on every private page fault. Make sense. Thanks, Chao