Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1596603rwd; Wed, 31 May 2023 16:43:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4rcitYKr/NNQLX8YePaN2xMTQwXa/Tuf3XFrqFfXU0H1wIwyOjQZGtkaffe/doBU46rCsF X-Received: by 2002:a05:6808:1449:b0:39a:427a:a315 with SMTP id x9-20020a056808144900b0039a427aa315mr5931274oiv.2.1685576598233; Wed, 31 May 2023 16:43:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685576598; cv=none; d=google.com; s=arc-20160816; b=ravC2MvecCyMRYauqz5D68l4iVKALSv6v7IiW864MLivsHdVYkcgWNPMsIrVGGI4dJ 8klkIHI1gNgdIsGtBcLsXHYyUevX3EXQYt07SpO0UrAb8ReWyS9Yo9s79Y00ZIaUwcKS k9i6rgyExv0pkC/yDhKJu4Ek/NLiJfNlLxyLOtwdxm4Nx95EyKqHsP0v9qg4MtCvq2Hy CIj1uI37n9fM56ddBXPX4x7GKk7FVYkAizfdFSRYj8zS7rXfz5tGSiYFXow6HOogLHN9 TyO4/IMehYI577b6UR1+mu75W81odSblpsgVHthaSxkx9kAoycBo3h3KbUNPqojiyN3i ixNA== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:dkim-signature:date; bh=SXIoTlecMC6VxxSME1sHTXGjADcYTmN1y7mvnJvjlhM=; b=boISrj1PPbr3RAtBCZirw+Pmk7FrylfmGEA9RUe42BUX+nol2N+moS8x8BlvrheDp8 LqbvXOTKmpH9FKIJTXPbL77Q2Nl5AhHx8pUhr8K7jHpQIy89bNPj7lSAEBelnp1hriC9 IVIj+EOFDVFdRuNzh0GinBRvF2T3bYm8lPZIVndCPAu65WEzsJsO/+Pb3/V9YHUaVyTG 7AexEsr/tc9rJXgJCevidVIc6CY4sOdr33hUUJSQyZ7hBLNCrhWc7Mf8jRFEWZPbFPwZ xIsqsz4x8uWdTLLXk4h3CrRHL5JgWDFFCW2Y5qCVJLGRuvjwLzyzaDvnion4lJJbxa+m 0uJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=lyfbrHT4; 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=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h10-20020a170902748a00b001b045d65af0si790269pll.76.2023.05.31.16.43.01; Wed, 31 May 2023 16:43:18 -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=@linux.dev header.s=key1 header.b=lyfbrHT4; 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=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229874AbjEaXXJ (ORCPT + 99 others); Wed, 31 May 2023 19:23:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229941AbjEaXXI (ORCPT ); Wed, 31 May 2023 19:23:08 -0400 Received: from out-39.mta1.migadu.com (out-39.mta1.migadu.com [IPv6:2001:41d0:203:375::27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAF2612F for ; Wed, 31 May 2023 16:23:07 -0700 (PDT) Date: Wed, 31 May 2023 23:22:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1685575383; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SXIoTlecMC6VxxSME1sHTXGjADcYTmN1y7mvnJvjlhM=; b=lyfbrHT4Q4zo1L0ArqeQIdJoep5zRjHJ2OLTTh3iRuaDrDCmyrt6ZdUnmT8D0VRFrnKrfd Fay41KvYXJP8CWHfKOE6M8su7vw1n8IEhIPvIvj0EphIHYOG0Ve9WKW9yduPpl6rDOCxtx CeLsU8HW8TNpYdjp9DmTE9Euk9lTN+Y= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Yu Zhao Cc: Andrew Morton , Paolo Bonzini , Alistair Popple , Anup Patel , Ben Gardon , Borislav Petkov , Catalin Marinas , Chao Peng , Christophe Leroy , Dave Hansen , Fabiano Rosas , Gaosheng Cui , Gavin Shan , "H. Peter Anvin" , Ingo Molnar , James Morse , "Jason A. Donenfeld" , Jason Gunthorpe , Jonathan Corbet , Marc Zyngier , Masami Hiramatsu , Michael Ellerman , Michael Larabel , Mike Rapoport , Nicholas Piggin , Paul Mackerras , Peter Xu , Sean Christopherson , Steven Rostedt , Suzuki K Poulose , Thomas Gleixner , Thomas Huth , Will Deacon , Zenghui Yu , kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-trace-kernel@vger.kernel.org, x86@kernel.org, linux-mm@google.com Subject: Re: [PATCH mm-unstable v2 04/10] kvm/arm64: make stage2 page tables RCU safe Message-ID: References: <20230526234435.662652-1-yuzhao@google.com> <20230526234435.662652-5-yuzhao@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Wed, May 31, 2023 at 05:10:52PM -0600, Yu Zhao wrote: > On Wed, May 31, 2023 at 1:28 PM Oliver Upton wrote: > > On Tue, May 30, 2023 at 02:06:55PM -0600, Yu Zhao wrote: > > > On Tue, May 30, 2023 at 1:37 PM Oliver Upton wrote: > > > > As it is currently implemented, yes. But, there's potential to fast-path > > > > the implementation by checking page_count() before starting the walk. > > > > > > Do you mind posting another patch? I'd be happy to ack it, as well as > > > the one you suggested above. > > > > I'd rather not take such a patch independent of the test_clear_young > > series if you're OK with that. Do you mind implementing something > > similar to the above patch w/ the proposed optimization if you need it? > > No worries. I can take the above together with the following, which > would form a new series with its own merits, since apparently you > think the !AF case is important. Sorry if my suggestion was unclear. I thought we were talking about ->free_removed_table() being called from the stage-2 unmap path, in which case we wind up unnecessarily visiting PTEs on a table known to be empty. You could fast-path that by only initiating a walk if page_count() > 1: diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 95dae02ccc2e..766563dc465c 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -1331,7 +1331,8 @@ void kvm_pgtable_stage2_free_removed(struct kvm_pgtable_mm_ops *mm_ops, void *pg .end = kvm_granule_size(level), }; - WARN_ON(__kvm_pgtable_walk(&data, mm_ops, ptep, level + 1)); + if (mm_ops->page_count(pgtable) > 1) + WARN_ON(__kvm_pgtable_walk(&data, mm_ops, ptep, level + 1)); WARN_ON(mm_ops->page_count(pgtable) != 1); mm_ops->put_page(pgtable); A lock-free access fault walker is interesting, but in my testing it hasn't led to any significant improvements over acquiring the MMU lock for read. Because of that I hadn't bothered with posting the series upstream. -- Thanks, Oliver