Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3461661imw; Mon, 18 Jul 2022 08:29:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sibKENs0L4XSv7O3LN/VoyRbqt4SZElMmdLYqLlY1nEL6Xo0o+RwbydKOM1qCzjIRoitTr X-Received: by 2002:a05:6402:5409:b0:42a:a643:4eb8 with SMTP id ev9-20020a056402540900b0042aa6434eb8mr37650498edb.71.1658158185371; Mon, 18 Jul 2022 08:29:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658158185; cv=none; d=google.com; s=arc-20160816; b=fRCjibEXET8LHl2XCQ0QBkkQ+4ZfRWyHa/HpMpMsJQwb0T45S8EP00xJz1dg9KeHHY pMdI8ZGb7byf1hX9JBrUdU3CpRCD120JqxuIcEYzds1sHPYHkL8eMBdcZkKTuSRU/RKr rxPjrWp5X4jBY2W4zUQx2Tzy49vEfzW9Wrm58cJ4e3HhpKD/UySYqWRdzVBoFqBSoIyT CPyHNsHrsdDdNE4p+3o3xoVYBbOiqingLxDdiAKASk7ii24Cy3kI2pjAPINGntXSTHXI BcQZDcc9w2SvBnOwx4uKqhnBeX1lubHeUXLvinTEvkzSuGQSQpkgNMc2KkZpnCNm6i41 Zy5A== 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=Yt9oE0kz3TmH5FGxe6pEDCKgvRvBbOAA/ay7EMCbyEc=; b=SdElyGYM90Qt240TJuV7kissYSt/VGis1aZIoA+MXUp8uRj4Tt4NUWJZBKgUCyzI68 yi2cQj0zH4Y0VxNOuY6qsjLUi1DWFMWeQI4rALTwQ/RqWwsJz/QmuIcEZjXpj5dzhvKq snmLFwykQpve67DKmfsYgpWt/OUxCwZ8TtuTU4+86yasyvbFnN9axrSq6QKUNbnRGcfC R/FT0SlMzb7U4je+FDmf23P0fmIaSJcXkNk20eNemjBO0jNVQiVQBgUtLG685SwYTwFx xwJVW6CJFBvc9gmrlnZpxBnHI+xRDR2oa50BTrsqIOZOCdUxM0Q1JuZh1d352SORBeW3 YteQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Uff3ivfi; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sg15-20020a170907a40f00b0072b6e6512e5si19087149ejc.490.2022.07.18.08.29.20; Mon, 18 Jul 2022 08:29:45 -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=@google.com header.s=20210112 header.b=Uff3ivfi; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235414AbiGRP0q (ORCPT + 99 others); Mon, 18 Jul 2022 11:26:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235428AbiGRP0n (ORCPT ); Mon, 18 Jul 2022 11:26:43 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 850F429800 for ; Mon, 18 Jul 2022 08:26:39 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id s18-20020a17090aa11200b001f1e9e2438cso146613pjp.2 for ; Mon, 18 Jul 2022 08:26:39 -0700 (PDT) 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=Yt9oE0kz3TmH5FGxe6pEDCKgvRvBbOAA/ay7EMCbyEc=; b=Uff3ivfihawnDb3MVf5QlQ2jPMMai38C6bP4DepEErQNRp/Kc0gYVje6cUTN3mqgBa 8e/i6cCNzLQRIo6XA6wMXV8Z208mTTLPAFevNS72jjatByWcRHbhRuXNC/PzoiNVlj0A G9sTexZ1nkBq8bHjUgqFI7BC1X8Fl1pf5ZeLZgS5QdWIqKzWIGGLSvIy/UwP2bykPTMR S0KDUdaMZvJIWXXz6SkPgu1okTxSS3xRe0n7hIARn0g4omp+/4Oqj1iwRKhLmSvwxOC1 gHiiZYsDVdI0DS6/yoOU3d2IjW3kS0u9umKDtPmgnjR6gLoFlRAZm1r5c55NFjc5PcWF DbCw== 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=Yt9oE0kz3TmH5FGxe6pEDCKgvRvBbOAA/ay7EMCbyEc=; b=M0x/CDrKQSf5rtx0Pf/j7MTWbcgQ/c6Y7mPqMX0U9astsppNhfXIxkWN6i43oqmyBT INgOPO7C0SQBJNLoOZSHH+UbJQiTogT13GRIgSEE2s24qZ0XDE42QexwpW7n0TVtuL9L lBCHI9UfUKNvaszdbvKRXI4vN0p3NNudDArOAXslvPE6NgqOueGqJoJXnvIwRnkhjBQm x5tlrEMODcidm3E4Q5fBR9L/rMQkmI/vU89U5sNERd146X3Sd3J8Co96qhJCtsfiB4qp JiIfq9xxkCh235rizXkk/RyGLCbMY0E5QMKkMf6qDoli/g3puQBELx/CatNAXwxjOY7G KL5g== X-Gm-Message-State: AJIora92K1SNtqoI+ET6fgc1Z/XY0NB5+8YEQdoruoD4lG8UoxZ9lLwk HCp0NQNlxOzYxAUOpib3Ctld6g== X-Received: by 2002:a17:903:1208:b0:16b:81f6:e992 with SMTP id l8-20020a170903120800b0016b81f6e992mr29233754plh.55.1658157998529; Mon, 18 Jul 2022 08:26:38 -0700 (PDT) Received: from google.com (123.65.230.35.bc.googleusercontent.com. [35.230.65.123]) by smtp.gmail.com with ESMTPSA id h14-20020a63e14e000000b004161b3c3388sm8342392pgk.26.2022.07.18.08.26.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jul 2022 08:26:38 -0700 (PDT) Date: Mon, 18 Jul 2022 15:26:34 +0000 From: Sean Christopherson To: Chao Peng 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: 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: <20220718132950.GA38104@chaop.bj.intel.com> X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 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. > Adding gpa range for private memory invalidation also relieves the > above blocking issue between private memory page fault and mmu_notifier.