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 X-Spam-Level: X-Spam-Status: No, score=-8.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5DE2C433DF for ; Sat, 16 May 2020 00:56:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 97355207C3 for ; Sat, 16 May 2020 00:56:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="qTQeteg5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 97355207C3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2BF208E0003; Fri, 15 May 2020 20:56:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 26FBB8E0001; Fri, 15 May 2020 20:56:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 15D918E0003; Fri, 15 May 2020 20:56:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0109.hostedemail.com [216.40.44.109]) by kanga.kvack.org (Postfix) with ESMTP id F33988E0001 for ; Fri, 15 May 2020 20:56:14 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id B37D38248076 for ; Sat, 16 May 2020 00:56:14 +0000 (UTC) X-FDA: 76820765868.02.burst83_5393861d6322f X-HE-Tag: burst83_5393861d6322f X-Filterd-Recvd-Size: 4872 Received: from hqnvemgate26.nvidia.com (hqnvemgate26.nvidia.com [216.228.121.65]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Sat, 16 May 2020 00:56:14 +0000 (UTC) Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Fri, 15 May 2020 17:56:00 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Fri, 15 May 2020 17:56:12 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Fri, 15 May 2020 17:56:12 -0700 Received: from rcampbell-dev.nvidia.com (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sat, 16 May 2020 00:56:10 +0000 Subject: Re: [PATCH] mm/hmm/test: destroy xa_array instead of looping To: Jason Gunthorpe CC: , , , , "Jerome Glisse" , John Hubbard , "Christoph Hellwig" , Andrew Morton , Shuah Khan References: <20200513214507.30592-1-rcampbell@nvidia.com> <20200515231538.GD24561@mellanox.com> X-Nvconfidentiality: public From: Ralph Campbell Message-ID: Date: Fri, 15 May 2020 17:56:10 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <20200515231538.GD24561@mellanox.com> X-Originating-IP: [172.20.13.39] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1589590560; bh=NhBCoaCRWwssiHRuS3xyxevAb+KCgQoaTCdzXg1ITHY=; h=X-PGP-Universal:Subject:To:CC:References:X-Nvconfidentiality:From: Message-ID:Date:User-Agent:MIME-Version:In-Reply-To: X-Originating-IP:X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=qTQeteg5qrAId4asjZOdDSQniDmaYrOBSh/LU1Do4auOQVVwJbiU1xRCGXl1jK6ct aVjUR04LI8BA0CxVpvIdj2oyaJrKSjcgCYbXVrkOjMWpyFL0whmXJ1SSKX7PiLhKq5 MT+FL57PzrZwzQo9lTfUjVdwXqGyF5AzlZF3xzrqmR6d8J3omRLXE5ai+C6+ftyORg IDqEYISElmzyt+Y6S+bUi1zbrcFIAZC1MZD7CnKIAUSdCq2VMPP6zOi2mMngOoIitS mGvD6YUI8EZhmAOx/z/SSfrwD/SuY59oEESVjx5sSwg8zdHXlOgc7neLQ6wbbQHLhW 9Vjg/rHgCT9Cw== 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 5/15/20 4:15 PM, Jason Gunthorpe wrote: > On Wed, May 13, 2020 at 02:45:07PM -0700, Ralph Campbell wrote: >> The test driver uses an xa_array to store virtual to physical address >> translations for a simulated hardware device. The MMU notifier >> invalidation callback is used to keep the table consistent with the CPU >> page table and is frequently called only for a page or two. However, if >> the test process exits unexpectedly or is killed, the range can be >> [0..ULONG_MAX] in which case calling xa_erase() for every possible PFN >> results in CPU timeouts. Munmap() can result in a large range being >> invalidated but in that case, the xa_array is likely to contain entries >> that need to be invalidated. >> Check for [0..ULONG_MAX] explicitly and just destroy the whole table. >> >> Signed-off-by: Ralph Campbell >> >> This patch is based on Jason Gunthorpe's hmm tree and should be folded >> into the ("mm/hmm/test: add selftest driver for HMM") patch once this >> patch is reviewed, etc. >> >> lib/test_hmm.c | 6 ++++++ >> 1 file changed, 6 insertions(+) >> >> diff --git a/lib/test_hmm.c b/lib/test_hmm.c >> index 8b36c26b717b..b89852ec3c29 100644 >> +++ b/lib/test_hmm.c >> @@ -201,7 +201,13 @@ static void dmirror_do_update(struct dmirror *dmirror, unsigned long start, >> * The XArray doesn't hold references to pages since it relies on >> * the mmu notifier to clear page pointers when they become stale. >> * Therefore, it is OK to just clear the entry. >> + * However, if the entire address space is being invalidated, it >> + * takes too long to clear them one at a time so destroy the array. >> */ >> + if (start == 0 && end == ULONG_MAX) { >> + xa_destroy(&dmirror->pt); >> + return; >> + } >> for (pfn = start >> PAGE_SHIFT; pfn < (end >> PAGE_SHIFT); pfn++) >> xa_erase(&dmirror->pt, pfn); >> } > > Just use xa_for_each_range() instead of the naive loop, it already > optimizes against membership and avoids the need for the xa_destroy > hack > > Jason > For some reason I had looked at that and rejected it but of course, it works fine. :-) Thanks!