From patchwork Tue Jul 23 23:30:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ralph Campbell X-Patchwork-Id: 11055455 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 A72BE746 for ; Tue, 23 Jul 2019 23:30:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98F1628741 for ; Tue, 23 Jul 2019 23:30:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8CEDC28749; Tue, 23 Jul 2019 23:30:28 +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=ham 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 DB74D28741 for ; Tue, 23 Jul 2019 23:30:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CADDD6B0006; Tue, 23 Jul 2019 19:30:26 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C5E8E8E0003; Tue, 23 Jul 2019 19:30:26 -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 B27738E0002; Tue, 23 Jul 2019 19:30:26 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yb1-f200.google.com (mail-yb1-f200.google.com [209.85.219.200]) by kanga.kvack.org (Postfix) with ESMTP id 9258E6B0006 for ; Tue, 23 Jul 2019 19:30:26 -0400 (EDT) Received: by mail-yb1-f200.google.com with SMTP id f126so34260248ybg.16 for ; Tue, 23 Jul 2019 16:30:26 -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:in-reply-to :references:mime-version:content-transfer-encoding:dkim-signature; bh=vXNCPdLtOKpCMqnhnrWYHHQ4R9DMFg9c7ubyhWGAGSI=; b=FDBhXRxjvwmha4OLgxF8wQX1cAL63GMta0+csX7iLtptn0ExLjwl8iuvkL+ss6hqbe s7Ug1X4Touh9fuvSzPeA58Oh/wfFVMg4N3Jf/61ws0QRMSenEPc+rpyfo6x+Tk4vl/v9 dkfrMCdDA1DswCZJSli3Bp//93YYNZCxinG6Th/dtuYxY7oapfiWO/ZRPw32djW5wSqz CPPxJQ2cNNTI7mBUD3RAXj9evd4NsmOoJgBzsY8SUXZ598szfdrOyB67rhuIBVwUU4V0 BCHaXLqbyzg+E8wZlAE5Q/NzAGNhkBCfiaZxDRou0BJA/A4Q7Cyzy+QH3POzE3loxfb/ QEww== X-Gm-Message-State: APjAAAWSQKOHjoZCstbzryeOv5k/Mc3gcbAl2Ui7bmCrhhOCdAVGW5mn c4pdSS4IRAm0WD86IOXhmA3WzpqgxoqXVDx+QuabWer/RIsxFYOtOaymkD4AKjG8nfU0rSWURky 8/vpvotlL+DbNNuKuZmL2VBoJtWKFWqMUMl3CnR8rDEN0Hb2AoN8hm7QMT3tqfzjHAw== X-Received: by 2002:a81:f88:: with SMTP id 130mr48020007ywp.311.1563924626350; Tue, 23 Jul 2019 16:30:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqzUH/rU4ajMYAvFF5GCUVvHemitgiWHNNK063v6xylW2U9tk/1Y2eMO54ONl/gp46S+/Bbd X-Received: by 2002:a81:f88:: with SMTP id 130mr48019975ywp.311.1563924625716; Tue, 23 Jul 2019 16:30:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563924625; cv=none; d=google.com; s=arc-20160816; b=mnfk7YJVTMjSWdFYNtNWXakilg/30HqOzNUxOMTgsflKWm5RuL11mKJzmSxKDVogkr m0nWAtP8oC4oNsCIHIxt11FgTOkN3KXJ3cmrrZiTqS+7FTIb52oTD+JWQUmckEpYIO6x LN8TuEVlyVg0xPTSNfNKJ0ZPZrkMb/pYnjGPVRi5ItqsjDSH62dd/THILxTn8e7FO996 s1w+y057v2laPtS2G4FLRrlfiSMLpNYOEkbjjmgiFZIpMxNTc8IrEpIJB1XWry8ZNz40 slnF4/Cd46218alOf7cndHLAHeHQ7GGFEm6F0moC27hNrrNZkpiW5t5U9bz7MHq+mwUp 0VYw== 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:references :in-reply-to:message-id:date:subject:cc:to:from; bh=vXNCPdLtOKpCMqnhnrWYHHQ4R9DMFg9c7ubyhWGAGSI=; b=VgqCZuqtzqKeY9RkC4uRQU4uU5ddE7eE30J+NrxyAvnwgQ+HyGMxIt1CqJzLlLeBUR QGxhN1QQ+zayw77CNfYeWcpVBF3/+CG+z5ldmLb98hk02fcQkfdL3fOMi5NMJQMGRFKI S67h1iNX8dW8G+umVn+oC1sQA6Dz5evNfXWPzCutjLaeNRpJkR9QFHnYoTF0VqlTBIZd hC8kcS7MKWO9gupJYhBJWAozmuf3XlhJ+ilIeYgQGxUX/bSwdMX65KzQWdKC3nbxte4Q h6SuZYenwZla6QvDn25MhcNVNSXA8FV7Xg5qHNrCe3J1sB9ra2//yp28bybZWfPVISjr vNSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=fM855tyZ; spf=pass (google.com: domain of rcampbell@nvidia.com designates 216.228.121.65 as permitted sender) smtp.mailfrom=rcampbell@nvidia.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: from hqemgate16.nvidia.com (hqemgate16.nvidia.com. [216.228.121.65]) by mx.google.com with ESMTPS id y4si16386244ybp.210.2019.07.23.16.30.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Jul 2019 16:30:25 -0700 (PDT) Received-SPF: pass (google.com: domain of rcampbell@nvidia.com designates 216.228.121.65 as permitted sender) client-ip=216.228.121.65; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=fM855tyZ; spf=pass (google.com: domain of rcampbell@nvidia.com designates 216.228.121.65 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 hqemgate16.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 23 Jul 2019 16:30:22 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 23 Jul 2019 16:30:24 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 23 Jul 2019 16:30:24 -0700 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; Tue, 23 Jul 2019 23:30:21 +0000 Received: from hqnvemgw01.nvidia.com (172.20.150.20) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 23 Jul 2019 23:30:21 +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 ; Tue, 23 Jul 2019 16:30:21 -0700 From: Ralph Campbell To: CC: , Ralph Campbell , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , Jason Gunthorpe , Christoph Hellwig Subject: [PATCH 1/2] mm/hmm: a few more C style and comment clean ups Date: Tue, 23 Jul 2019 16:30:15 -0700 Message-ID: <20190723233016.26403-2-rcampbell@nvidia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190723233016.26403-1-rcampbell@nvidia.com> References: <20190723233016.26403-1-rcampbell@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1563924622; bh=vXNCPdLtOKpCMqnhnrWYHHQ4R9DMFg9c7ubyhWGAGSI=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:X-NVConfidentiality: Content-Type:Content-Transfer-Encoding; b=fM855tyZ1WcjIgnyEsZQy7O05+TECy5DrMYAhbx2p36jOb6O5IiErvFCE8Lfi3V8G RLKkR7eVIPK8qwtQXYw9OvS/KqkTsUX7wV7H36PbDzfFgGhMyICZWtaMoJCBxf4mJ/ qtpLJkHil520lNp2U4onHfGqewP3oynUtHuuQWeDqYnGvh+SS9rz2Fc7jEixEHxaY4 Ry9ODubJpC+UqxGV22eGSI8sYEs2SR9kkm5Jc8AaQQYyGVcWcRhT3uN/9Wy8D4pPXz jUsp5ObCYqjuFQMgsIG9zmKwJ8XI9SaD5eRZoEk51lNi5lqTgUkI35WbFckjVjIvZm pb4A5wgPe7U/g== 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 A few more comments and minor programming style clean ups. There should be no functional changes. Signed-off-by: Ralph Campbell Cc: "Jérôme Glisse" Cc: Jason Gunthorpe Cc: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- mm/hmm.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/mm/hmm.c b/mm/hmm.c index b810a4fa3de9..8271f110c243 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -32,7 +32,7 @@ static const struct mmu_notifier_ops hmm_mmu_notifier_ops; * hmm_get_or_create - register HMM against an mm (HMM internal) * * @mm: mm struct to attach to - * Returns: returns an HMM object, either by referencing the existing + * Return: an HMM object, either by referencing the existing * (per-process) object, or by creating a new one. * * This is not intended to be used directly by device drivers. If mm already @@ -323,8 +323,8 @@ static int hmm_pfns_bad(unsigned long addr, } /* - * hmm_vma_walk_hole() - handle a range lacking valid pmd or pte(s) - * @start: range virtual start address (inclusive) + * hmm_vma_walk_hole_() - handle a range lacking valid pmd or pte(s) + * @addr: range virtual start address (inclusive) * @end: range virtual end address (exclusive) * @fault: should we fault or not ? * @write_fault: write fault ? @@ -374,9 +374,9 @@ static inline void hmm_pte_need_fault(const struct hmm_vma_walk *hmm_vma_walk, /* * So we not only consider the individual per page request we also * consider the default flags requested for the range. The API can - * be use in 2 fashions. The first one where the HMM user coalesce - * multiple page fault into one request and set flags per pfns for - * of those faults. The second one where the HMM user want to pre- + * be used 2 ways. The first one where the HMM user coalesces + * multiple page faults into one request and sets flags per pfn for + * those faults. The second one where the HMM user wants to pre- * fault a range with specific flags. For the latter one it is a * waste to have the user pre-fill the pfn arrays with a default * flags value. @@ -386,7 +386,7 @@ static inline void hmm_pte_need_fault(const struct hmm_vma_walk *hmm_vma_walk, /* We aren't ask to do anything ... */ if (!(pfns & range->flags[HMM_PFN_VALID])) return; - /* If this is device memory than only fault if explicitly requested */ + /* If this is device memory then only fault if explicitly requested */ if ((cpu_flags & range->flags[HMM_PFN_DEVICE_PRIVATE])) { /* Do we fault on device memory ? */ if (pfns & range->flags[HMM_PFN_DEVICE_PRIVATE]) { @@ -500,7 +500,7 @@ static int hmm_vma_handle_pmd(struct mm_walk *walk, hmm_vma_walk->last = end; return 0; #else - /* If THP is not enabled then we should never reach that code ! */ + /* If THP is not enabled then we should never reach this code ! */ return -EINVAL; #endif } @@ -624,13 +624,12 @@ static int hmm_vma_walk_pmd(pmd_t *pmdp, pte_t *ptep; pmd_t pmd; - again: pmd = READ_ONCE(*pmdp); if (pmd_none(pmd)) return hmm_vma_walk_hole(start, end, walk); - if (pmd_huge(pmd) && (range->vma->vm_flags & VM_HUGETLB)) + if (pmd_huge(pmd) && is_vm_hugetlb_page(vma)) return hmm_pfns_bad(start, end, walk); if (thp_migration_supported() && is_pmd_migration_entry(pmd)) { @@ -655,11 +654,11 @@ static int hmm_vma_walk_pmd(pmd_t *pmdp, if (pmd_devmap(pmd) || pmd_trans_huge(pmd)) { /* - * No need to take pmd_lock here, even if some other threads + * No need to take pmd_lock here, even if some other thread * is splitting the huge pmd we will get that event through * mmu_notifier callback. * - * So just read pmd value and check again its a transparent + * So just read pmd value and check again it's a transparent * huge or device mapping one and compute corresponding pfn * values. */ @@ -673,7 +672,7 @@ static int hmm_vma_walk_pmd(pmd_t *pmdp, } /* - * We have handled all the valid case above ie either none, migration, + * We have handled all the valid cases above ie either none, migration, * huge or transparent huge. At this point either it is a valid pmd * entry pointing to pte directory or it is a bad pmd that will not * recover. @@ -793,10 +792,10 @@ static int hmm_vma_walk_hugetlb_entry(pte_t *pte, unsigned long hmask, pte_t entry; int ret = 0; - size = 1UL << huge_page_shift(h); + size = huge_page_size(h); mask = size - 1; if (range->page_shift != PAGE_SHIFT) { - /* Make sure we are looking at full page. */ + /* Make sure we are looking at a full page. */ if (start & mask) return -EINVAL; if (end < (start + size)) @@ -807,8 +806,7 @@ static int hmm_vma_walk_hugetlb_entry(pte_t *pte, unsigned long hmask, size = PAGE_SIZE; } - - ptl = huge_pte_lock(hstate_vma(walk->vma), walk->mm, pte); + ptl = huge_pte_lock(hstate_vma(vma), walk->mm, pte); entry = huge_ptep_get(pte); i = (start - range->start) >> range->page_shift; @@ -857,7 +855,7 @@ static void hmm_pfns_clear(struct hmm_range *range, * @start: start virtual address (inclusive) * @end: end virtual address (exclusive) * @page_shift: expect page shift for the range - * Returns 0 on success, -EFAULT if the address space is no longer valid + * Return: 0 on success, -EFAULT if the address space is no longer valid * * Track updates to the CPU page table see include/linux/hmm.h */ From patchwork Tue Jul 23 23:30:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ralph Campbell X-Patchwork-Id: 11055457 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 1DAE51399 for ; Tue, 23 Jul 2019 23:30:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D75628741 for ; Tue, 23 Jul 2019 23:30:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0194428749; Tue, 23 Jul 2019 23:30:30 +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=ham 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 36AEA28741 for ; Tue, 23 Jul 2019 23:30:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 46FEA8E0002; Tue, 23 Jul 2019 19:30:28 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4236E6B0008; Tue, 23 Jul 2019 19:30:28 -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 2C31D8E0002; Tue, 23 Jul 2019 19:30:28 -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 00CFD6B0007 for ; Tue, 23 Jul 2019 19:30:28 -0400 (EDT) Received: by mail-yw1-f70.google.com with SMTP id b63so33356952ywc.12 for ; Tue, 23 Jul 2019 16:30:27 -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:in-reply-to :references:mime-version:content-transfer-encoding:dkim-signature; bh=hfYQ/qkPLZjADPYtK9Vb0H/HyTmNQ/JXBO+v+y3qqYE=; b=DqcJp+GrN9SZLDigBQ+UywNMC/zOv7oMiYIxNSd7G0WraMMsGJkvUsFp5P7JTvMqDO 4SdZ1EO0nalJ8Lkz+7+CL6FmHOhLSsGtlN1VwhrnJrv0aoo6TErimaWM3sUMO1vNK/6k D1OAkn+wv7fFLlWyrOEDRUScQnaUVSqCWsCI/wTgz3741QZoB7h21GRIgY/P0/nYHWOL 0J4yKON121tLQz6cy93mA7XkJqQNd6XN47VT+jGXFO4WV+t72h/nzvIzaaasqlHQ9ncs oYRfxmEDTVW/Cf6xz52heh+tz/rMIMkYmPMs9My5Nc1bYKXmuYMJXta8aL3k7RIhJAYS +CxA== X-Gm-Message-State: APjAAAXaOcP1tgWTBTiQdyCDh+Tz+cOPw+uzbregYDSZHRkl+knLFu9T 5aXq0DZjZkjI5hk0lvoQQYiQiWw056hwX1CDDLWtOqjGUHyVOPUCnHBIzbUMUKNod1lm/f7Lu8P 74niVYYU/918Cybipbfawv6bP7BlVOqH3hDJhJQxs+QUsg7ihvZkhQYDEGTB0LwX+4g== X-Received: by 2002:a25:60d7:: with SMTP id u206mr50445969ybb.257.1563924627744; Tue, 23 Jul 2019 16:30:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqwcCjea+8zKOuXOVZT50PUJwr2qJuosTXJXRwCIJbOf2gc5Im5wa0TKKLtaFiYEHDdgVVlN X-Received: by 2002:a25:60d7:: with SMTP id u206mr50445916ybb.257.1563924626650; Tue, 23 Jul 2019 16:30:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563924626; cv=none; d=google.com; s=arc-20160816; b=tLMakoyUNZ8nRbgk+GhMVuGg3WmD6U0C6xfd8B8a+z5+jxoQlYlZHEQAMNw4h1OvhI qcWwI0P5N2HMTvaKVwOxFKapGFSr5weFlkcm3cXvNwHvuCkVpKjW7pcBHm+gXFZbKhnh y9t8h4EqpCQxeb3e1ZiPoyoMMOpXCePKA3lIb2In1gkg9pjnitmRBv1aPOiIdAOStivE QSmDkUgv4huwaKaI5I2MAkFDfTJzXKh5K3CPu7ZOi4hxgUxTOprubOrA00L8V15D3uu5 A5ENwP6Glrpp8m6JTI3KS2zZr9U9oVgIwkl94+QuUpUTsMKzbsCQhzoVZOFHlYdLrP6n 0UPA== 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:references :in-reply-to:message-id:date:subject:cc:to:from; bh=hfYQ/qkPLZjADPYtK9Vb0H/HyTmNQ/JXBO+v+y3qqYE=; b=yrR5fNIR/5cEzN1nFid5zp2mNHPZbySU/Q1jya33TvYTBU0JfD02acE7dL1HWmZU13 weze6zR9n0CcMg3WlxeYlyaEcdXHlbJJYZU3kenIqPO5RqSHnO0VA+RGZ1HgyGfqFJbz 2oPS/ePlpBzN3Py5g+IAMY9b6suzcM8dAGOQRXa3WCZjPLSrfj+bz2O3Z79V5sEO3vwp dSnIpctceBGlEeuNpU8qWrJ0N5NwXSkHek+im6xJmuW4wGoKV9UTwtbIXvpfdweXYuck 3rn5avxbfmregjBW5uBGzTKUPUciNwJzvtB7aEIfNj9Hjjr7voKpeeyMna88ls+Jw1iR JkvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=PmsQaM0N; spf=pass (google.com: domain of rcampbell@nvidia.com designates 216.228.121.64 as permitted sender) smtp.mailfrom=rcampbell@nvidia.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: from hqemgate15.nvidia.com (hqemgate15.nvidia.com. [216.228.121.64]) by mx.google.com with ESMTPS id u23si16764011ywc.376.2019.07.23.16.30.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Jul 2019 16:30:26 -0700 (PDT) Received-SPF: pass (google.com: domain of rcampbell@nvidia.com designates 216.228.121.64 as permitted sender) client-ip=216.228.121.64; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=PmsQaM0N; spf=pass (google.com: domain of rcampbell@nvidia.com designates 216.228.121.64 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 hqemgate15.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 23 Jul 2019 16:30:33 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 23 Jul 2019 16:30:25 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 23 Jul 2019 16:30:25 -0700 Received: from HQMAIL110.nvidia.com (172.18.146.15) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 23 Jul 2019 23:30:25 +0000 Received: from HQMAIL107.nvidia.com (172.20.187.13) by hqmail110.nvidia.com (172.18.146.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 23 Jul 2019 23:30:22 +0000 Received: from hqnvemgw01.nvidia.com (172.20.150.20) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 23 Jul 2019 23:30:22 +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 ; Tue, 23 Jul 2019 16:30:22 -0700 From: Ralph Campbell To: CC: , Ralph Campbell , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , Jason Gunthorpe , Christoph Hellwig Subject: [PATCH 2/2] mm/hmm: make full use of walk_page_range() Date: Tue, 23 Jul 2019 16:30:16 -0700 Message-ID: <20190723233016.26403-3-rcampbell@nvidia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190723233016.26403-1-rcampbell@nvidia.com> References: <20190723233016.26403-1-rcampbell@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1563924633; bh=hfYQ/qkPLZjADPYtK9Vb0H/HyTmNQ/JXBO+v+y3qqYE=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:X-NVConfidentiality: Content-Type:Content-Transfer-Encoding; b=PmsQaM0NskBkOCohdJNR6vE+X7fr8YGHD0BPSKxxNAJnBiGfOZ1OFbMAFpmkyrDbQ 6OIHTMYlKoxkmxvcrLuprnPuX+OrTtZO6EwF/To/OZV1rV3wuHcNktrWn7lQAoX0kK TDT/0oErWbbFW/yVSuvuDm7kbleyInsG3qcmOec9w2f8zmKcm4bEptqYbUp6Susg2x lVcD9xVRYZwVTqTDuoEaanbD0JS4BuzLOFaC1tilqfNCm3HXySfjyhl36wy27Xx+7R FtJjCAaQuNRlp0l7xWfGkzCpOQ+e0/71SddSGIEJOH8IA2PlsTQKSRco/RfdzeNzd7 s0QTQ7eJSd3jg== 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_range_snapshot() and hmm_range_fault() both call find_vma() and walk_page_range() in a loop. This is unnecessary duplication since walk_page_range() calls find_vma() in a loop already. Simplify hmm_range_snapshot() and hmm_range_fault() by defining a walk_test() callback function to filter unhandled vmas. Signed-off-by: Ralph Campbell Cc: "Jérôme Glisse" Cc: Jason Gunthorpe Cc: Christoph Hellwig --- mm/hmm.c | 197 ++++++++++++++++++++----------------------------------- 1 file changed, 70 insertions(+), 127 deletions(-) diff --git a/mm/hmm.c b/mm/hmm.c index 8271f110c243..218557451070 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -839,13 +839,40 @@ static int hmm_vma_walk_hugetlb_entry(pte_t *pte, unsigned long hmask, #endif } -static void hmm_pfns_clear(struct hmm_range *range, - uint64_t *pfns, - unsigned long addr, - unsigned long end) +static int hmm_vma_walk_test(unsigned long start, + unsigned long end, + struct mm_walk *walk) { - for (; addr < end; addr += PAGE_SIZE, pfns++) - *pfns = range->values[HMM_PFN_NONE]; + const unsigned long device_vma = VM_IO | VM_PFNMAP | VM_MIXEDMAP; + struct hmm_vma_walk *hmm_vma_walk = walk->private; + struct hmm_range *range = hmm_vma_walk->range; + struct vm_area_struct *vma = walk->vma; + + /* If range is no longer valid, force retry. */ + if (!range->valid) + return -EBUSY; + + if (vma->vm_flags & device_vma) + return -EFAULT; + + if (is_vm_hugetlb_page(vma)) { + if (huge_page_shift(hstate_vma(vma)) != range->page_shift && + range->page_shift != PAGE_SHIFT) + return -EINVAL; + } else { + if (range->page_shift != PAGE_SHIFT) + return -EINVAL; + } + + /* + * If vma does not allow read access, then assume that it does not + * allow write access, either. HMM does not support architectures + * that allow write without read. + */ + if (!(vma->vm_flags & VM_READ)) + return -EPERM; + + return 0; } /* @@ -949,65 +976,28 @@ EXPORT_SYMBOL(hmm_range_unregister); */ long hmm_range_snapshot(struct hmm_range *range) { - const unsigned long device_vma = VM_IO | VM_PFNMAP | VM_MIXEDMAP; - unsigned long start = range->start, end; - struct hmm_vma_walk hmm_vma_walk; + unsigned long start = range->start; + struct hmm_vma_walk hmm_vma_walk = {}; struct hmm *hmm = range->hmm; - struct vm_area_struct *vma; - struct mm_walk mm_walk; + struct mm_walk mm_walk = {}; + int ret; lockdep_assert_held(&hmm->mm->mmap_sem); - do { - /* If range is no longer valid force retry. */ - if (!range->valid) - return -EBUSY; - vma = find_vma(hmm->mm, start); - if (vma == NULL || (vma->vm_flags & device_vma)) - return -EFAULT; - - if (is_vm_hugetlb_page(vma)) { - if (huge_page_shift(hstate_vma(vma)) != - range->page_shift && - range->page_shift != PAGE_SHIFT) - return -EINVAL; - } else { - if (range->page_shift != PAGE_SHIFT) - return -EINVAL; - } + hmm_vma_walk.range = range; + hmm_vma_walk.last = start; + mm_walk.private = &hmm_vma_walk; - if (!(vma->vm_flags & VM_READ)) { - /* - * If vma do not allow read access, then assume that it - * does not allow write access, either. HMM does not - * support architecture that allow write without read. - */ - hmm_pfns_clear(range, range->pfns, - range->start, range->end); - return -EPERM; - } + mm_walk.mm = hmm->mm; + mm_walk.pud_entry = hmm_vma_walk_pud; + mm_walk.pmd_entry = hmm_vma_walk_pmd; + mm_walk.pte_hole = hmm_vma_walk_hole; + mm_walk.hugetlb_entry = hmm_vma_walk_hugetlb_entry; + mm_walk.test_walk = hmm_vma_walk_test; - range->vma = vma; - hmm_vma_walk.pgmap = NULL; - hmm_vma_walk.last = start; - hmm_vma_walk.fault = false; - hmm_vma_walk.range = range; - mm_walk.private = &hmm_vma_walk; - end = min(range->end, vma->vm_end); - - mm_walk.vma = vma; - mm_walk.mm = vma->vm_mm; - mm_walk.pte_entry = NULL; - mm_walk.test_walk = NULL; - mm_walk.hugetlb_entry = NULL; - mm_walk.pud_entry = hmm_vma_walk_pud; - mm_walk.pmd_entry = hmm_vma_walk_pmd; - mm_walk.pte_hole = hmm_vma_walk_hole; - mm_walk.hugetlb_entry = hmm_vma_walk_hugetlb_entry; - - walk_page_range(start, end, &mm_walk); - start = end; - } while (start < range->end); + ret = walk_page_range(start, range->end, &mm_walk); + if (ret) + return ret; return (hmm_vma_walk.last - range->start) >> PAGE_SHIFT; } @@ -1043,83 +1033,36 @@ EXPORT_SYMBOL(hmm_range_snapshot); */ long hmm_range_fault(struct hmm_range *range, bool block) { - const unsigned long device_vma = VM_IO | VM_PFNMAP | VM_MIXEDMAP; - unsigned long start = range->start, end; - struct hmm_vma_walk hmm_vma_walk; + unsigned long start = range->start; + struct hmm_vma_walk hmm_vma_walk = {}; struct hmm *hmm = range->hmm; - struct vm_area_struct *vma; - struct mm_walk mm_walk; + struct mm_walk mm_walk = {}; int ret; lockdep_assert_held(&hmm->mm->mmap_sem); - do { - /* If range is no longer valid force retry. */ - if (!range->valid) - return -EBUSY; + hmm_vma_walk.range = range; + hmm_vma_walk.last = start; + hmm_vma_walk.fault = true; + hmm_vma_walk.block = block; + mm_walk.private = &hmm_vma_walk; - vma = find_vma(hmm->mm, start); - if (vma == NULL || (vma->vm_flags & device_vma)) - return -EFAULT; - - if (is_vm_hugetlb_page(vma)) { - if (huge_page_shift(hstate_vma(vma)) != - range->page_shift && - range->page_shift != PAGE_SHIFT) - return -EINVAL; - } else { - if (range->page_shift != PAGE_SHIFT) - return -EINVAL; - } + mm_walk.mm = hmm->mm; + mm_walk.pud_entry = hmm_vma_walk_pud; + mm_walk.pmd_entry = hmm_vma_walk_pmd; + mm_walk.pte_hole = hmm_vma_walk_hole; + mm_walk.hugetlb_entry = hmm_vma_walk_hugetlb_entry; + mm_walk.test_walk = hmm_vma_walk_test; - if (!(vma->vm_flags & VM_READ)) { - /* - * If vma do not allow read access, then assume that it - * does not allow write access, either. HMM does not - * support architecture that allow write without read. - */ - hmm_pfns_clear(range, range->pfns, - range->start, range->end); - return -EPERM; - } + do { + ret = walk_page_range(start, range->end, &mm_walk); + start = hmm_vma_walk.last; - range->vma = vma; - hmm_vma_walk.pgmap = NULL; - hmm_vma_walk.last = start; - hmm_vma_walk.fault = true; - hmm_vma_walk.block = block; - hmm_vma_walk.range = range; - mm_walk.private = &hmm_vma_walk; - end = min(range->end, vma->vm_end); - - mm_walk.vma = vma; - mm_walk.mm = vma->vm_mm; - mm_walk.pte_entry = NULL; - mm_walk.test_walk = NULL; - mm_walk.hugetlb_entry = NULL; - mm_walk.pud_entry = hmm_vma_walk_pud; - mm_walk.pmd_entry = hmm_vma_walk_pmd; - mm_walk.pte_hole = hmm_vma_walk_hole; - mm_walk.hugetlb_entry = hmm_vma_walk_hugetlb_entry; - - do { - ret = walk_page_range(start, end, &mm_walk); - start = hmm_vma_walk.last; - - /* Keep trying while the range is valid. */ - } while (ret == -EBUSY && range->valid); - - if (ret) { - unsigned long i; - - i = (hmm_vma_walk.last - range->start) >> PAGE_SHIFT; - hmm_pfns_clear(range, &range->pfns[i], - hmm_vma_walk.last, range->end); - return ret; - } - start = end; + /* Keep trying while the range is valid. */ + } while (ret == -EBUSY && range->valid); - } while (start < range->end); + if (ret) + return ret; return (hmm_vma_walk.last - range->start) >> PAGE_SHIFT; }