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 AFA59C433F5 for ; Wed, 5 Jan 2022 17:03:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D47446B0071; Wed, 5 Jan 2022 12:03:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CCFDF6B0073; Wed, 5 Jan 2022 12:03:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B4ABB6B0074; Wed, 5 Jan 2022 12:03:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0073.hostedemail.com [216.40.44.73]) by kanga.kvack.org (Postfix) with ESMTP id A3D2C6B0071 for ; Wed, 5 Jan 2022 12:03:29 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 66C7F8CA50 for ; Wed, 5 Jan 2022 17:03:29 +0000 (UTC) X-FDA: 78996854538.05.82C9FB5 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by imf19.hostedemail.com (Postfix) with ESMTP id 0C2DC1A0002 for ; Wed, 5 Jan 2022 17:03:28 +0000 (UTC) Received: by mail-pj1-f50.google.com with SMTP id l16-20020a17090a409000b001b2e9628c9cso6844277pjg.4 for ; Wed, 05 Jan 2022 09:03:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=20PcXM2SOqh0bhoeFDgkuJ5Ggj44o0SuiK3MzhyRmsU=; b=rsVhd0t9UYWasE9JkCnUdxw73v/C1RJiVYZucEuqofNaX7J+c9jjVQkj/bSH9/hzML 1AQ45ueMsGZqHhb+ONFIOTRVECck4WDJiLkhJ0dCZbZRd5F9dDTBiVu7r7REZXD9nDtu Xwabj8vwZirYN27UmfT+MFejoQWUI9qJwppOAO8SVy7LPqm06bw6Rk+FSk4JnYLfNzKN 6FSWMsczvkGo3kv1fgbZktu3eIC0s4j4r+mMRKUgyd5AhelCtF7hT13ZZzUMad8zhHYs NsjHcQfwZ6EHDGIT1RaMTzGYfSxfIcJSuUk+//z6aXiUfPd4LC0DhqXQ2LFXonhbNUZK 5pzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=20PcXM2SOqh0bhoeFDgkuJ5Ggj44o0SuiK3MzhyRmsU=; b=0Xbam6RXtYn9gR3UMQ+IrHqRJPMoDacdi5lfytXzS1JOOUfdyQvWUalOpyPEhIf4tV NVp7U9EK8laYVOMd5ddMEcYNM7U0bDnkYO6PMGaUQug6TDIjx3RpGp0Rmk7k4s3f3/Ln WBaR5bly9meCQ9ezNf123r+Mqe44TSvFlVe1J8lYgOsg3CfgBqz7IxgaNrAxBcSRQCae tUBYdI4Eq5ZpVMO3mRmEvIDIqYZB+wAROLkiXrIiD9o35uTBFswiWdTGG3QF0WQ0y4Ic MhhNSB9kBNPxim+BdcdPiu92FER9swo+O6vu241S5MKUhE02Nf0imxeuQslw8K668Ybr WryQ== X-Gm-Message-State: AOAM531TMs+IIvW+KaXv0CV7DpucaTBUSeUu/iWtHXyLmK+oFV8hHSua pC6esWC+CVkwRY4kPe9ONV1y2Q== X-Google-Smtp-Source: ABdhPJxImFHzV2wP+eap8aozdummb4OVmFsl2PXCC7t1JdswItec85C5qV0TEmNNUwSf2xDAMgaO6g== X-Received: by 2002:a17:90b:1c86:: with SMTP id oo6mr4975265pjb.165.1641402207756; Wed, 05 Jan 2022 09:03:27 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id v3sm23315094pgl.64.2022.01.05.09.03.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jan 2022 09:03:27 -0800 (PST) Date: Wed, 5 Jan 2022 17:03:23 +0000 From: Sean Christopherson To: Chao Peng 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: 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: <20220105061410.GA25283@chaop.bj.intel.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 0C2DC1A0002 X-Stat-Signature: cksd9k5oehsbds3ttf1nhkgt5yk9xyns Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=rsVhd0t9; spf=pass (imf19.hostedemail.com: domain of seanjc@google.com designates 209.85.216.50 as permitted sender) smtp.mailfrom=seanjc@google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1641402208-665100 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, 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.