Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp10715334rwp; Fri, 21 Jul 2023 04:00:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlH7PqsnMtd51DsSJoOU0rTYW99fmNbGlR0Bwoy2lP8JH14Y9c967nn5VEVu3pljS18EQhZ3 X-Received: by 2002:a05:6a20:9384:b0:134:589a:c0fc with SMTP id x4-20020a056a20938400b00134589ac0fcmr1654573pzh.32.1689937235950; Fri, 21 Jul 2023 04:00:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689937235; cv=none; d=google.com; s=arc-20160816; b=AIySh0GduM8K0Mr0szTZPyA5A55MieGaM2A0CBswYs7QsivxVI9NHcm9M6m05ThuZ9 scYFXpYynCyjhKCmm8p7oowmup/Jalt5u5VKojk660VsZyI0A5Gl7MjIMEspiVUmQ8Vn DOhbJ84/ZvQB6tX1mpkYMK73ZmessYd+C0wf94r11tcRkQSBSFtql3o59+4uIXV4NtQF sbd+hC0/NbKixuyG68rhhOlbe3ncpsVIAylEtWYU1XXaMYHzuGe+WGTpsiRGJHq5yJ06 xIIU0GsvzQeFT1SB4ZptO27cq1E2pBrNjUQya7ryHz9y7FntXPWFBuGWVEhca1BBmIZN 7KXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=vVhppqqgLjbIUSHewUZbge5o+QCkgECm2Td3V9CkNsg=; fh=ArTWlW5KpGiWrk4QKe6oDxGe2eoFbp8QxjHFSilyq50=; b=uw8eERUsScVvT8E3DraMOLc52/gMWeexJTVXVVFQOMSM0mRP2/lNHWmz8lJs1nRncs 1zx6LIXM4C2kZMgLsbKumTIQ+D83Yrxki4LnnoqR6duu288HMTL/69/G+fRsKgpVkze0 47Pmrhlthk7EHHb5+bvwme8PjI4a92i+dZjZe0B2W07He7UyDfrgRYOUtMK4Jz6uf03t HiwqlmimcSCy2EWDprFb67y+J5BDmrc6TwlHXVbvxvvArDWex/m0zQsG+zUxN9f7FqKZ l5uyoa2oBPTHg1WaDTk7oXbhHD3L2oFW9k74ODTEFQmkvtKENDgCvkW+OKJJm4x2bB93 hM1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=b1gQmxJK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p21-20020a056a000b5500b0068664d7f3f2si1041942pfo.88.2023.07.21.04.00.23; Fri, 21 Jul 2023 04:00:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=b1gQmxJK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229848AbjGUKrb (ORCPT + 99 others); Fri, 21 Jul 2023 06:47:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229493AbjGUKr3 (ORCPT ); Fri, 21 Jul 2023 06:47:29 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 965AB1701; Fri, 21 Jul 2023 03:47:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689936448; x=1721472448; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=lqUeKJjFv2Sxri0zg/OC/DAKL78i5iZqhBI02xpLRko=; b=b1gQmxJK0t5qLXwInz2z1vsdJy6AAum1O7lL2lvyHs1DN9MMjcWJh3Ie XiQIolmGnSCp8dS7AHZSNibxy1hVJ/i0RigeqX+3TY4Dchg79d7tNOVZt 1zI0mxUUEvbdid5OKYkKK/OjvF3ZXRsYUUBweuFEO96HogAYXug1jV1FM yXeHCATd/WIUfaKFRwUCN6MxORHdPgsDhMt0bhcAg+lXz7IRDf3PKuGMb /1av+6I8NpXxKDEkf4L4OUG5eZRRZANszRY6PuFLljdeBGha5N7Pqp/NZ HY/81IGWCW7Y7bnlpdITKo1unVMFC5S6MTvObMTBR5MjdcpzxEDN4ncJ0 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="365884912" X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="365884912" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2023 03:47:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="724827627" X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="724827627" Received: from yilunxu-optiplex-7050.sh.intel.com (HELO localhost) ([10.239.159.165]) by orsmga002.jf.intel.com with ESMTP; 21 Jul 2023 03:47:13 -0700 Date: Fri, 21 Jul 2023 18:45:26 +0800 From: Xu Yilun To: Yan Zhao Cc: Sean Christopherson , Paolo Bonzini , Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , "Matthew Wilcox (Oracle)" , Andrew Morton , Paul Moore , James Morris , "Serge E. Hallyn" , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Chao Peng , Fuad Tabba , Jarkko Sakkinen , Yu Zhang , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , Vlastimil Babka , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" Subject: Re: [RFC PATCH v11 01/29] KVM: Wrap kvm_gfn_range.pte in a per-action union Message-ID: References: <20230718234512.1690985-1-seanjc@google.com> <20230718234512.1690985-2-seanjc@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023-07-21 at 14:26:11 +0800, Yan Zhao wrote: > On Tue, Jul 18, 2023 at 04:44:44PM -0700, Sean Christopherson wrote: > > May I know why KVM now needs to register to callback .change_pte()? I can see the original purpose is to "setting a pte in the shadow page table directly, instead of flushing the shadow page table entry and then getting vmexit to set it"[1]. IIUC, KVM is expected to directly make the new pte present for new pages in this callback, like for COW. > As also commented in kvm_mmu_notifier_change_pte(), .change_pte() must be > surrounded by .invalidate_range_{start,end}(). > > While kvm_mmu_notifier_invalidate_range_start() has called kvm_unmap_gfn_range() > to zap all leaf SPTEs, and page fault path will not install new SPTEs > successfully before kvm_mmu_notifier_invalidate_range_end(), > kvm_set_spte_gfn() should not be able to find any shadow present leaf entries to > update PFN. I also failed to figure out how the kvm_set_spte_gfn() could pass several !is_shadow_present_pte(iter.old_spte) check then write the new pte. [1] https://lore.kernel.org/all/200909222039.n8MKd4TL002696@imap1.linux-foundation.org/ Thanks, Yilun > > Or could we just delete completely > "kvm_handle_hva_range(mn, address, address + 1, pte, kvm_set_spte_gfn);" > from kvm_mmu_notifier_change_pte() ?