From patchwork Sat Jun 8 00:14:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralph Campbell X-Patchwork-Id: 10982969 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2C76B3A3F for ; Sat, 8 Jun 2019 00:15:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1678E28BD9 for ; Sat, 8 Jun 2019 00:15:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A25A28BE8; Sat, 8 Jun 2019 00:15:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7913B28BDB for ; Sat, 8 Jun 2019 00:15:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 72DFF6B0279; Fri, 7 Jun 2019 20:15:07 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6DE1B6B027A; Fri, 7 Jun 2019 20:15:07 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5CDB86B027B; Fri, 7 Jun 2019 20:15:07 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f70.google.com (mail-yw1-f70.google.com [209.85.161.70]) by kanga.kvack.org (Postfix) with ESMTP id 3CCC66B0279 for ; Fri, 7 Jun 2019 20:15:07 -0400 (EDT) Received: by mail-yw1-f70.google.com with SMTP id j68so3627623ywj.4 for ; Fri, 07 Jun 2019 17:15:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding:dkim-signature; bh=jjTMN2tDk2DnfrJ4AiOM/WxsV6jt0FXZOA5qIWGi5Vo=; b=DBiub/ZjZEIxpZPFNsJ4uGblbzrw9plrR9nocQp8CY5cOLUF0YFCBuRyreyZawDzs6 1zdjHu+pcGaKrGGHCok8T23Ij6UOTfD7V/X7ZQKWuH/jqIAC5uoc2w0RKkUyK+QqualT ox4BKrbh7du3ntv2C/v+SD8Aycrjlk3E4wZKDMHQYQb4Ek0yengiWJH4R154icn323PE wJ8oaoKQUPCatNM1U6szGyEjpXr2uCq225Nm7MQ8OmRiQwHeLxM7lEequyEA6/v59WPt OfwLiWRINrIvI/EteDAoZilaVVr9TpNfo0v5utLQA+030rdFpkaV2e+YXxcx5K/fN+Cd NTXA== X-Gm-Message-State: APjAAAWlSWgmpjXkAey07oP2dbvPGu2WE7NWmAkB//n7c8ibUPn5wWDq XXz9JOKi7J79qrPxDtvKRzVfMTzwM0fmlOpP+RF5srwrd14zgl6Z0so0JrP6e2MLYRLSEDsOf2q X82CN14zmA5mlyXc4yAJBPOrSP+ZkwYayC/aHnTYmP3HWl3iGUUj9F9gGxCPWducXMw== X-Received: by 2002:a81:4f91:: with SMTP id d139mr8476351ywb.146.1559952907001; Fri, 07 Jun 2019 17:15:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqzaPz+DKZ8eJh6YmC65Z7rRA5Ri19ePoQnTrJwqkA3IgklHfjbK6vWraI5yiVpQU7ZXKd3T X-Received: by 2002:a81:4f91:: with SMTP id d139mr8476320ywb.146.1559952906239; Fri, 07 Jun 2019 17:15:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559952906; cv=none; d=google.com; s=arc-20160816; b=0/G67NIQWnTBpyWtIr1hWdosGuQyTfdWbnpoePVZ/zdt698ubM/IDRIoQa6kW5cSJd ahdTXw5d7O5TvXLrZSFci/4jwuFKRVG4vSuHMQILbmZaDcRRXX8SLRXAs5CiYZDZ3Aza E/vux2JpQ3aF68HHb1YLlDsoJpe5/n1qAJClSLt7EmqYhVDVMRHd7W+ee26qxZwGneXX 5aZwYK+20wbSnNQgBfroGx6U1w0jUFNfc8MsWvpez5edCfNGEGMmFqU6nhJT6m2e0T6u x50MZTTG2Kokr1S5lBDamNzUH2SfInHuGWFZgCBQRVqFlvgRe1EoCermkDhpgHDrh1II F4fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=dkim-signature:content-transfer-encoding:mime-version:message-id :date:subject:cc:to:from; bh=jjTMN2tDk2DnfrJ4AiOM/WxsV6jt0FXZOA5qIWGi5Vo=; b=IeQ83czUpKb+GXF9ba5CfXyM041yeVjqeNYUYH8X1LIDJB109xc7WucUjJagPHJARQ dm2bs3FBQ2wdH4XFMD5FnJVhfpijaq0LgD1ri7EHUs2m3GfL/LaHyfLQZtp835JY4e9h TQDH18xtIgKEUU46lo5QVHEJgHDshCWh8BXfyTrzMWUubwNimBg2kxxUNP5ycyrePCLg pP1ue2wxGvI0jfAUGUqgvZBohYtzhexKNJJpDhqyTRiOe0TnSMdBGR8iq4XJkoZldLy4 n9FNbBrvb13PtfioTTVPjlvxhRYQLn1y8njBIMAbFWatgVKYkp+/nlntHQj6k4gWQG9U Tn+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=SQ11Ml7m; spf=pass (google.com: domain of rcampbell@nvidia.com designates 216.228.121.143 as permitted sender) smtp.mailfrom=rcampbell@nvidia.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: from hqemgate14.nvidia.com (hqemgate14.nvidia.com. [216.228.121.143]) by mx.google.com with ESMTPS id u18si1061773ywc.70.2019.06.07.17.15.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Jun 2019 17:15:06 -0700 (PDT) Received-SPF: pass (google.com: domain of rcampbell@nvidia.com designates 216.228.121.143 as permitted sender) client-ip=216.228.121.143; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=SQ11Ml7m; spf=pass (google.com: domain of rcampbell@nvidia.com designates 216.228.121.143 as permitted sender) smtp.mailfrom=rcampbell@nvidia.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate14.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Fri, 07 Jun 2019 17:15:03 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Fri, 07 Jun 2019 17:15:05 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Fri, 07 Jun 2019 17:15:05 -0700 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL108.nvidia.com (172.18.146.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sat, 8 Jun 2019 00:14:59 +0000 Received: from hqnvemgw01.nvidia.com (172.20.150.20) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Sat, 8 Jun 2019 00:14:59 +0000 Received: from rcampbell-dev.nvidia.com (Not Verified[10.110.48.66]) by hqnvemgw01.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Fri, 07 Jun 2019 17:14:59 -0700 From: Ralph Campbell To: Jerome Glisse , John Hubbard , , Jason Gunthorpe CC: , , Andrea Arcangeli , , , Ralph Campbell Subject: [RFC] mm/hmm: pass mmu_notifier_range to sync_cpu_device_pagetables Date: Fri, 7 Jun 2019 17:14:52 -0700 Message-ID: <20190608001452.7922-1-rcampbell@nvidia.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-NVConfidentiality: public DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1559952903; bh=jjTMN2tDk2DnfrJ4AiOM/WxsV6jt0FXZOA5qIWGi5Vo=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: MIME-Version:X-NVConfidentiality:Content-Transfer-Encoding: Content-Type; b=SQ11Ml7mtU/VVPx6gJwSisurSRky6JAGtlAhDA3ya7KnsP+2Me9XdeQy0dl1/UoMN xv+0zFG5tik4y8rSVn5cofTeuqlqujlwsB//FH0By1uUSUvO7ycUIG0wW3FapovgKa 0fgRjWS1C3zMfwBfxYIDpEYpQ75A8cZp3tc7J8DR0BHNMLA2r6uHj4FFGAjh7AxA7v IWvDBx+zGF8diRe5AyZGqdAEsVBWyz3rszufqbSV5jqPmoYCAOc/vHJCe10E6K4ZkJ rsy8vxbGy5RxTm7tuWyiuduAXKyz+pNxC80+VL4H5GF4RhQPhyKDFw8nr1yhTTckBa DnZ96Pvym7CFw== 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: X-Virus-Scanned: ClamAV using ClamSMTP HMM defines its own struct hmm_update which is passed to the sync_cpu_device_pagetables() callback function. This is sufficient when the only action is to invalidate. However, a device may want to know the reason for the invalidation and be able to see the new permissions on a range, update device access rights or range statistics. Since sync_cpu_device_pagetables() can be called from try_to_unmap(), the mmap_sem may not be held and find_vma() is not safe to be called. Pass the struct mmu_notifier_range to sync_cpu_device_pagetables() to allow the full invalidation information to be used. Signed-off-by: Ralph Campbell Reviewed-by: Ira Weiny --- I'm sending this out now since we are updating many of the HMM APIs and I think it will be useful. drivers/gpu/drm/nouveau/nouveau_svm.c | 4 ++-- include/linux/hmm.h | 27 ++------------------------- mm/hmm.c | 13 ++++--------- 3 files changed, 8 insertions(+), 36 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_svm.c b/drivers/gpu/drm/nouveau/nouveau_svm.c index 8c92374afcf2..c34b98fafe2f 100644 --- a/drivers/gpu/drm/nouveau/nouveau_svm.c +++ b/drivers/gpu/drm/nouveau/nouveau_svm.c @@ -252,13 +252,13 @@ nouveau_svmm_invalidate(struct nouveau_svmm *svmm, u64 start, u64 limit) static int nouveau_svmm_sync_cpu_device_pagetables(struct hmm_mirror *mirror, - const struct hmm_update *update) + const struct mmu_notifier_range *update) { struct nouveau_svmm *svmm = container_of(mirror, typeof(*svmm), mirror); unsigned long start = update->start; unsigned long limit = update->end; - if (!update->blockable) + if (!mmu_notifier_range_blockable(update)) return -EAGAIN; SVMM_DBG(svmm, "invalidate %016lx-%016lx", start, limit); diff --git a/include/linux/hmm.h b/include/linux/hmm.h index 0fa8ea34ccef..07a2d38fde34 100644 --- a/include/linux/hmm.h +++ b/include/linux/hmm.h @@ -377,29 +377,6 @@ static inline uint64_t hmm_pfn_from_pfn(const struct hmm_range *range, struct hmm_mirror; -/* - * enum hmm_update_event - type of update - * @HMM_UPDATE_INVALIDATE: invalidate range (no indication as to why) - */ -enum hmm_update_event { - HMM_UPDATE_INVALIDATE, -}; - -/* - * struct hmm_update - HMM update information for callback - * - * @start: virtual start address of the range to update - * @end: virtual end address of the range to update - * @event: event triggering the update (what is happening) - * @blockable: can the callback block/sleep ? - */ -struct hmm_update { - unsigned long start; - unsigned long end; - enum hmm_update_event event; - bool blockable; -}; - /* * struct hmm_mirror_ops - HMM mirror device operations callback * @@ -420,7 +397,7 @@ struct hmm_mirror_ops { /* sync_cpu_device_pagetables() - synchronize page tables * * @mirror: pointer to struct hmm_mirror - * @update: update information (see struct hmm_update) + * @update: update information (see struct mmu_notifier_range) * Return: -EAGAIN if update.blockable false and callback need to * block, 0 otherwise. * @@ -434,7 +411,7 @@ struct hmm_mirror_ops { * synchronous call. */ int (*sync_cpu_device_pagetables)(struct hmm_mirror *mirror, - const struct hmm_update *update); + const struct mmu_notifier_range *update); }; /* diff --git a/mm/hmm.c b/mm/hmm.c index 9aad3550f2bb..b49a43712554 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -164,7 +164,6 @@ static int hmm_invalidate_range_start(struct mmu_notifier *mn, { struct hmm *hmm = container_of(mn, struct hmm, mmu_notifier); struct hmm_mirror *mirror; - struct hmm_update update; struct hmm_range *range; unsigned long flags; int ret = 0; @@ -173,15 +172,10 @@ static int hmm_invalidate_range_start(struct mmu_notifier *mn, if (!kref_get_unless_zero(&hmm->kref)) return 0; - update.start = nrange->start; - update.end = nrange->end; - update.event = HMM_UPDATE_INVALIDATE; - update.blockable = mmu_notifier_range_blockable(nrange); - spin_lock_irqsave(&hmm->ranges_lock, flags); hmm->notifiers++; list_for_each_entry(range, &hmm->ranges, list) { - if (update.end < range->start || update.start >= range->end) + if (nrange->end < range->start || nrange->start >= range->end) continue; range->valid = false; @@ -198,9 +192,10 @@ static int hmm_invalidate_range_start(struct mmu_notifier *mn, list_for_each_entry(mirror, &hmm->mirrors, list) { int rc; - rc = mirror->ops->sync_cpu_device_pagetables(mirror, &update); + rc = mirror->ops->sync_cpu_device_pagetables(mirror, nrange); if (rc) { - if (WARN_ON(update.blockable || rc != -EAGAIN)) + if (WARN_ON(mmu_notifier_range_blockable(nrange) || + rc != -EAGAIN)) continue; ret = -EAGAIN; break;