Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4491064ybl; Mon, 13 Jan 2020 14:50:07 -0800 (PST) X-Google-Smtp-Source: APXvYqw3T97Xii43xggKg+ro5h4AN6RHpgWTveEmUppJ/7DPXNP0CfkY60WAsTfSBcXO2rLFXpdf X-Received: by 2002:a05:6830:1e8a:: with SMTP id n10mr14571144otr.303.1578955807445; Mon, 13 Jan 2020 14:50:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578955807; cv=none; d=google.com; s=arc-20160816; b=pZ6ifzXNp2NmEDz7kNlpKft1ahDKuuR3DQZpvOTq9qd3I1DUW3izlVtCRiavHJI0eS WjK6KiQby/R6tam8Boy5GLvyOvPRCXAY+OaJo42Qwr1CRUbJJDIwg3EVFsg11Pp7heGi O9UPLZ72BlG/zWTer2Q5auez3UXxgGHrqyyAzteleoDjowX34Hu9KCGffK28Sh8If+bi pdGZ9zLATFRtGnvUvD5xdqacH6mHOX8yzWg/WKSCRrQyTOBbBMP1qU1iXatVo3c23x0X g3I3fCXGRgcm4j4M8bPy7BlFSHc/4lbS6hmGfVR39ELebgrZW8vdfTEd3CSfuTf9Rzvf raoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=4zTuXc0CKU6YrnV6uf1EmOy7Oy/UdZiLxLw4iGtjyrQ=; b=d9PqQnXkgRUEBQLVSMiTH3+XnOym4DWUdDKvzd6CndKDpAuCqTPRmsCMMf7ZrFipL1 dMZkZFUq0kp43z/kPGAIECiwjW+RPMKkg/pg7J+ZLLe1XHYXqWCYD7mqnCfNjc5zCV5L xB9ossMP4oNRb1c2kWXXCMYEbTZWwshgX64HowvFwOmWtToSZUnsVRqrwflvRcllpzan wIbJjxcmoRhvrbp6OzXg2ZbGLi3jiPpxcIBEdpczhda3RnfTmLv1aS5Kl5/eW5YQiZv2 u092E5QyvZuGXr+9Ww9R+4A3N80PgS89Wwi2cO5eD66GE/3ZKkwRe/aZjNJitQNWLjFX Zk8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=fd++jT+O; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i11si7555403otc.105.2020.01.13.14.49.54; Mon, 13 Jan 2020 14:50:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=fd++jT+O; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729044AbgAMWrQ (ORCPT + 99 others); Mon, 13 Jan 2020 17:47:16 -0500 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:16374 "EHLO hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728992AbgAMWrO (ORCPT ); Mon, 13 Jan 2020 17:47:14 -0500 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Mon, 13 Jan 2020 14:46:19 -0800 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Mon, 13 Jan 2020 14:47:13 -0800 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Mon, 13 Jan 2020 14:47:13 -0800 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 13 Jan 2020 22:47:13 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 13 Jan 2020 22:47:12 +0000 Received: from hqnvemgw03.nvidia.com (10.124.88.68) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Mon, 13 Jan 2020 22:47:11 +0000 Received: from rcampbell-dev.nvidia.com (Not Verified[10.110.48.66]) by hqnvemgw03.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Mon, 13 Jan 2020 14:47:11 -0800 From: Ralph Campbell To: , , , , CC: Jerome Glisse , John Hubbard , Christoph Hellwig , Jason Gunthorpe , "Andrew Morton" , Ben Skeggs , "Shuah Khan" , Ralph Campbell Subject: [PATCH v6 4/6] mm/mmu_notifier: add mmu_interval_notifier_find() Date: Mon, 13 Jan 2020 14:47:01 -0800 Message-ID: <20200113224703.5917-5-rcampbell@nvidia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200113224703.5917-1-rcampbell@nvidia.com> References: <20200113224703.5917-1-rcampbell@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1578955579; bh=4zTuXc0CKU6YrnV6uf1EmOy7Oy/UdZiLxLw4iGtjyrQ=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:X-NVConfidentiality: Content-Transfer-Encoding:Content-Type; b=fd++jT+OQXFtmpIHOl28C4037Q8VrPBBYOvqiQTwadzERzw4EKdg+nAz+mC4N9LM4 lrFeMU4uXG/szra8U6tiXaQkOOko/3Smh75yv6UxW9uwOV/b4PgL6zFSknd+NKIGnK 8d97NTOlQtzf2P5fjm+wao0+3Twclmttc7SipQeFpg5sZH41rmCsNqn+3bqHkY+Ncj DmlOdaMcwa+2FEjXlqYtPD1M6+db3wwZRHdWtnskgBneyaz2rDhRevnVxIG8RlZVyF qJLTpWYS+0oH8RiNBl+JJ4EEgWLrZsq5T/a8/Cb+YBbnKEErt4W9MlJNcZN/hBufig tWwfAygjWiYGw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Device drivers may or may not have a convenient range based data structure to look up and find intervals that are registered with the mmu interval notifiers. Rather than forcing drivers to duplicate the interval tree, provide an API to look up intervals that are registered and accessor functions to return the start and last address of the interval. Signed-off-by: Ralph Campbell --- include/linux/mmu_notifier.h | 15 +++++++++++++++ mm/mmu_notifier.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h index 0ce59b4f22c2..cdbbad13b278 100644 --- a/include/linux/mmu_notifier.h +++ b/include/linux/mmu_notifier.h @@ -314,6 +314,21 @@ void mmu_interval_notifier_remove(struct mmu_interval_= notifier *mni); void mmu_interval_notifier_put(struct mmu_interval_notifier *mni); void mmu_interval_notifier_update(struct mmu_interval_notifier *mni, unsigned long start, unsigned long last); +struct mmu_interval_notifier *mmu_interval_notifier_find(struct mm_struct = *mm, + const struct mmu_interval_notifier_ops *ops, + unsigned long start, unsigned long last); + +static inline unsigned long mmu_interval_notifier_start( + struct mmu_interval_notifier *mni) +{ + return mni->interval_tree.start; +} + +static inline unsigned long mmu_interval_notifier_last( + struct mmu_interval_notifier *mni) +{ + return mni->interval_tree.last; +} =20 /** * mmu_interval_set_seq - Save the invalidation sequence diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c index 47ad9cc89aab..4efecc0f13cb 100644 --- a/mm/mmu_notifier.c +++ b/mm/mmu_notifier.c @@ -1171,6 +1171,39 @@ void mmu_interval_notifier_update(struct mmu_interva= l_notifier *mni, } EXPORT_SYMBOL_GPL(mmu_interval_notifier_update); =20 +struct mmu_interval_notifier *mmu_interval_notifier_find(struct mm_struct = *mm, + const struct mmu_interval_notifier_ops *ops, + unsigned long start, unsigned long last) +{ + struct mmu_notifier_mm *mmn_mm =3D mm->mmu_notifier_mm; + struct interval_tree_node *node; + struct mmu_interval_notifier *mni; + struct mmu_interval_notifier *res =3D NULL; + + spin_lock(&mmn_mm->lock); + node =3D interval_tree_iter_first(&mmn_mm->itree, start, last); + if (node) { + mni =3D container_of(node, struct mmu_interval_notifier, + interval_tree); + while (true) { + if (mni->ops =3D=3D ops) { + res =3D mni; + break; + } + node =3D interval_tree_iter_next(&mni->interval_tree, + start, last); + if (!node) + break; + mni =3D container_of(node, struct mmu_interval_notifier, + interval_tree); + } + } + spin_unlock(&mmn_mm->lock); + + return res; +} +EXPORT_SYMBOL_GPL(mmu_interval_notifier_find); + /** * mmu_notifier_synchronize - Ensure all mmu_notifiers are freed * --=20 2.20.1