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 0DBE3C433EF for ; Tue, 19 Jul 2022 14:07:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 74D226B0072; Tue, 19 Jul 2022 10:07:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6FC376B0073; Tue, 19 Jul 2022 10:07:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C4226B0074; Tue, 19 Jul 2022 10:07:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4E0596B0072 for ; Tue, 19 Jul 2022 10:07:51 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2134F3245B for ; Tue, 19 Jul 2022 14:07:51 +0000 (UTC) X-FDA: 79704027942.28.55CD786 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by imf28.hostedemail.com (Postfix) with ESMTP id A18FFC009B for ; Tue, 19 Jul 2022 14:07:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658239669; x=1689775669; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=s/ctDqIUvL1W3W833+ijczZqODZpeij+xtTHe7CbsGA=; b=ck94ckMDIFOiN+PQD0hHkhxXFvkBcwdvkLsw+OWKTK+PogQsWT8SkSk4 QJ3BWyfYHyFl29rwEd8rIYRVQcAYr4StUTB8icbQC4/M5gm4EkzvVCTpI map0YNw/vBFNhAZFkh/VUc1xmsQ2kjcC+vptAfU62OBoH8TGTUMI7DGNE ASZI6mBUW/eJ1GE5EAsl0iwUDFF4JsGLb7RAlk707DKTh1Dj9a6cL+bqN 2qKmK/qFXjG+x4rwUk7mQ83xfy6ZCKBe0Yo+/VXRfBRI9jNW3xNQpT507 MapkAiwQwlsjmoBWYNbZvCi/+L0xvozkZGhM9zVNSyNSFxUpxf5qN9V6b w==; X-IronPort-AV: E=McAfee;i="6400,9594,10412"; a="284061872" X-IronPort-AV: E=Sophos;i="5.92,284,1650956400"; d="scan'208";a="284061872" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jul 2022 07:07:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,284,1650956400"; d="scan'208";a="655774698" Received: from chaop.bj.intel.com (HELO localhost) ([10.240.193.75]) by fmsmga008.fm.intel.com with ESMTP; 19 Jul 2022 07:07:38 -0700 Date: Tue, 19 Jul 2022 22:02:48 +0800 From: Chao Peng To: Sean Christopherson Cc: "Gupta, Pankaj" , 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, linux-kselftest@vger.kernel.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 , Shuah Khan , 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, Muchun Song Subject: Re: [PATCH v7 07/14] KVM: Use gfn instead of hva for mmu_notifier_retry Message-ID: <20220719140248.GA84005@chaop.bj.intel.com> Reply-To: Chao Peng References: <20220706082016.2603916-1-chao.p.peng@linux.intel.com> <20220706082016.2603916-8-chao.p.peng@linux.intel.com> <20220718132950.GA38104@chaop.bj.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=ck94ckMD; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf28.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 192.55.52.93) smtp.mailfrom=chao.p.peng@linux.intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658239670; a=rsa-sha256; cv=none; b=oj1Cu8KcUWN0bvWUKJEcoVy/CjgAM/9yL26UbnDSD3dzfpMdptyMfXr74Cum1Az5U59VTT j83qEnyx98XODse7mfK8/PuZ1yASE8YaekVe2m66+Xb6a9rPj+/XygqUAQoHFuSqr8gt7j Pcuo3ogjXoxJdzM4bgDBnC5Q4QfwMOY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658239670; 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=0F7p47kyXnAjdyPQAfoXNQ2jOoQoKa43xJFnWOJqGOA=; b=2CtmxEk9FD0MakcwoYpvifQ844FaCg7HA55Y508EvaQE/mxPuIjHYWG1K3fa6CHe6cpADa aqzfS7u6XdYevCTysQqXgqpDhiA1xsLYbeiYdTOSHP7HTzuNUNF7KSmIIVaVCbOf/JWyMI RxX+kL0SxdN22rrZp1gzMDl6/3RYwOk= X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: A18FFC009B Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=ck94ckMD; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf28.hostedemail.com: domain of chao.p.peng@linux.intel.com has no SPF policy when checking 192.55.52.93) smtp.mailfrom=chao.p.peng@linux.intel.com X-Stat-Signature: hpqu435z18khexzknbk394j1ynw88rmo X-HE-Tag: 1658239669-617414 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 Mon, Jul 18, 2022 at 03:26:34PM +0000, Sean Christopherson wrote: > On Mon, Jul 18, 2022, Chao Peng wrote: > > On Fri, Jul 15, 2022 at 01:36:15PM +0200, Gupta, Pankaj wrote: > > > > Currently in mmu_notifier validate path, hva range is recorded and then > > > > checked in the mmu_notifier_retry_hva() from page fault path. However > > > > for the to be introduced private memory, a page fault may not have a hva > > > > > > As this patch appeared in v7, just wondering did you see an actual bug > > > because of it? And not having corresponding 'hva' occurs only with private > > > memory because its not mapped to host userspace? > > > > The addressed problem is not new in this version, previous versions I > > also had code to handle it (just in different way). But the problem is: > > mmu_notifier/memfile_notifier may be in the progress of invalidating a > > pfn that obtained earlier in the page fault handler, when happens, we > > should retry the fault. In v6 I used global mmu_notifier_retry() for > > memfile_notifier but that can block unrelated mmu_notifer invalidation > > which has hva range specified. > > > > Sean gave a comment at https://lkml.org/lkml/2022/6/17/1001 to separate > > memfile_notifier from mmu_notifier but during the implementation I > > realized we actually can reuse the same code for shared and private > > memory if both using gpa range and that can simplify the code handling > > in kvm_zap_gfn_range and some other code (e.g. we don't need two > > versions for memfile_notifier/mmu_notifier). > > This should work, though I'm undecided as to whether or not it's a good idea. KVM > allows aliasing multiple gfns to a single hva, and so using the gfn could result > in a much larger range being rejected given the simplistic algorithm for handling > multiple ranges in kvm_inc_notifier_count(). But I assume such aliasing is uncommon, > so I'm not sure it's worth optimizing for. That can be a real problem for current v7 code, __kvm_handle_hva_range() loops all possible gfn_range for a given hva_range but the on_lock/on_unlock is invoked only once, this should work for hva_range, but not gfn_range since we can have multiple of them. > > > Adding gpa range for private memory invalidation also relieves the > > above blocking issue between private memory page fault and mmu_notifier.