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 EF247C433F5 for ; Tue, 4 Jan 2022 17:31:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 262CC6B0071; Tue, 4 Jan 2022 12:31:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 212C06B0072; Tue, 4 Jan 2022 12:31:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B3EE6B0073; Tue, 4 Jan 2022 12:31:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0154.hostedemail.com [216.40.44.154]) by kanga.kvack.org (Postfix) with ESMTP id F20436B0071 for ; Tue, 4 Jan 2022 12:31:35 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id A44B5181C34FB for ; Tue, 4 Jan 2022 17:31:35 +0000 (UTC) X-FDA: 78993296550.13.418DC11 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf06.hostedemail.com (Postfix) with ESMTP id 7CE60180007 for ; Tue, 4 Jan 2022 17:31:33 +0000 (UTC) Received: by mail-pj1-f44.google.com with SMTP id o63-20020a17090a0a4500b001b1c2db8145so97946pjo.5 for ; Tue, 04 Jan 2022 09:31:34 -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=rOI9lx3ly2W5g+I//wMzwDwVhtW2WkhsJvnaYL+oVaA=; b=GM1vaX8nnsQ5aen4uuxpsO114wif5ycCG9Oq+Pc5m0xedO5AWvlwlk+0nur670mGKt onzOYTKoI9ivHrmZ5omlX7G/9g8vG1Dk7BMz+AhbgZkQYjM5XKrkVKn/mua46+jhsgFl 2x7N1/izW3LtGJIoZWWYJyzycZQWJVLVQuROwTwUx6Lb7wS1WfjJ2ZYfADX8e7fCk4Gv 3x2oDnc8GvPEK74RL4V15y2/q8Wd2PT6kYpMQXV19pxe40QE3h194kOApOsI9U9v5KmD d9EPsZeQajXh15idUScX3jRX2SE0PftIP1z+OqwywcvLzNIoSgKRELKr5w7K0PR0/UYB ULOQ== 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=rOI9lx3ly2W5g+I//wMzwDwVhtW2WkhsJvnaYL+oVaA=; b=PjqBGbrzywwlgcmkvMrLu4XHhVAbbEaSSeT9HiP2pPuE5QbvJw2jXG7la8nxZs+Ayq FKKxjjSBuT24FPxgEkuWo7n2aCIBfx1bHrpZaJHXKU2EcjHIdEuEBVlWDGTKHNq9reZZ 49X4F2m3uvMSUPPAthzu7TVRPNgY5TllO25pUksocBUWWwq+M4QsCGBDviv8zzuqPXfV jqHKKwYiYEbSHkoPlbKKqyecwiEWev87wdj3mr9+R/vnH3Y5A2CmCP/RTw9hz6fVUUhQ f+FQVns/I0NDTVdr36+AOPjfC5qoK7jTDhwoBlF5hztX0a6rI2lU3IO0CNpmr7YL71qF tIdg== X-Gm-Message-State: AOAM530sJW/zqTi7651b1ytb+2XDbuS5sXkr70M0fAKh1JSHr8HhkYNL u7p6BuFPF+pHS8moUZa1RtlqWg== X-Google-Smtp-Source: ABdhPJyW9pN160gPJHaycV7mP2xi077B27olHyhgGOoe6nr/BCGbiHdtFfrcOodNTbojl/LtojMyPQ== X-Received: by 2002:a17:902:8645:b0:149:7d71:c229 with SMTP id y5-20020a170902864500b001497d71c229mr39146383plt.141.1641317493940; Tue, 04 Jan 2022 09:31:33 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id l22sm43563684pfc.167.2022.01.04.09.31.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 09:31:33 -0800 (PST) Date: Tue, 4 Jan 2022 17:31:30 +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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211231023334.GA7255@chaop.bj.intel.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 7CE60180007 X-Stat-Signature: i5xnbo19bzniig8n81irqwzaswzwnsyd Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=GM1vaX8n; spf=pass (imf06.hostedemail.com: domain of seanjc@google.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=seanjc@google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1641317493-453977 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, 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.