From patchwork Tue Nov 29 19:35:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13059086 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6013C433FE for ; Tue, 29 Nov 2022 19:35:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 560F46B0074; Tue, 29 Nov 2022 14:35:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 49B386B0075; Tue, 29 Nov 2022 14:35:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 279726B007D; Tue, 29 Nov 2022 14:35:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 19A986B0074 for ; Tue, 29 Nov 2022 14:35:38 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E757B1A0A43 for ; Tue, 29 Nov 2022 19:35:37 +0000 (UTC) X-FDA: 80187484314.07.5AE0DCF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 8833C14000B for ; Tue, 29 Nov 2022 19:35:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669750536; 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=oUaUMokAqyi3NHrr8ZrIfiPSDBorB4zEKfPSOjIyLzs=; b=J8zan7P8iEiNIQueQrmJuPqEXnfpRKcYKQ/Ifc5Qu38XF5JzKvxmibNOvQ1nbJoyFHI2wJ 6umxRkgNBEJ3gWYhSwh7EjWag3XLbhT8jj6u0VwIQdWl+YBsFr/TLeGCzKubwtjtw0+gy/ 9Z/MkbZ9ExMKYWyxY0zVP0rnXOB3Y8M= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-675-YSiOcgn5P5e60GVO5mslzQ-1; Tue, 29 Nov 2022 14:35:33 -0500 X-MC-Unique: YSiOcgn5P5e60GVO5mslzQ-1 Received: by mail-qk1-f200.google.com with SMTP id bj4-20020a05620a190400b006fc7c5d454cso16903080qkb.14 for ; Tue, 29 Nov 2022 11:35:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oUaUMokAqyi3NHrr8ZrIfiPSDBorB4zEKfPSOjIyLzs=; b=ca4aEiei/cG7z+wuWQhmEToKs7Q2q8+15/idNuUof09S+1luo14ggcZOsweRXdxZkU Nu3LTBNPMKtm2xTbwccWHJ13cIUbkzsfRVSoovFx6H0GIsEadZLzUyQqhlQqjzOZHdnb ld/RD+G36QkgjGLjFUIpY6UqvWO9bYfFcuUsqXj+f1dQGE09w3FGw9ALI4WoKX8/dP1g haNvgk3a7JycgWvKtb0HEURew0BGG7CSQOK33Ya5DCu34JpCh0eOMsfuaTrokks97Yjy hEZn/ZDvfrryyYrag00TbbdrITjDJXlinP0GTFwK17kJrmOtrRy4nVtAH0ys3+x1lUmv LWhw== X-Gm-Message-State: ANoB5pkptQFvZfpiZbPEiK/j1WW7oWKLtvlLni/Q0qBIn6y2aJfDhQWj tOG30Qb17kM7023DbDDoBQEi6KUVd72GY3bVIvUg30zOUR+VI6OAfZnRU4Yoied6bHhzVCsHyGB D3lJKOtyktZVgkZ7si5Z/hwA2P6tGOQDOTCe9xyHT8ZwkqpVdlj6RQsJ1hZ3v X-Received: by 2002:a05:620a:b83:b0:6fb:ec6:da03 with SMTP id k3-20020a05620a0b8300b006fb0ec6da03mr51132397qkh.206.1669750532253; Tue, 29 Nov 2022 11:35:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf5YA/acon+LhfHPHPKaW5yLk7KnmfoilNeObxz2Q7Ei8/I2mWOfNhuwDiUBf8dY9EaFWOGB6Q== X-Received: by 2002:a05:620a:b83:b0:6fb:ec6:da03 with SMTP id k3-20020a05620a0b8300b006fb0ec6da03mr51132361qkh.206.1669750531938; Tue, 29 Nov 2022 11:35:31 -0800 (PST) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id n1-20020a05620a294100b006fa16fe93bbsm11313013qkp.15.2022.11.29.11.35.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Nov 2022 11:35:29 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: James Houghton , Jann Horn , peterx@redhat.com, Andrew Morton , Andrea Arcangeli , Rik van Riel , Nadav Amit , Miaohe Lin , Muchun Song , Mike Kravetz , David Hildenbrand Subject: [PATCH 01/10] mm/hugetlb: Let vma_offset_start() to return start Date: Tue, 29 Nov 2022 14:35:17 -0500 Message-Id: <20221129193526.3588187-2-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221129193526.3588187-1-peterx@redhat.com> References: <20221129193526.3588187-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669750537; a=rsa-sha256; cv=none; b=reFdPtWP90woKWldxv2W14zPKvrj0v/uzYJ6Q+8aPHj1eG1VCYxoAHDmyI8MI0kzVCC1Hp gWOygxtmqabk0mg1bbvS97gIURtZWibofvUZ83i7yEYQ55E7U7MqVQsXmK5oAxuC6LOwdb OH1/1geoHdsRlLpB+yjWdMgGiYvOYLg= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=J8zan7P8; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669750537; h=from:from:sender: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:dkim-signature; bh=oUaUMokAqyi3NHrr8ZrIfiPSDBorB4zEKfPSOjIyLzs=; b=sHvvzOssrtRzdzeO3Ii7KTJpHi+OfcMKwkKBnzh44WuTGkSs/iPsHdLLrwiscFTV/4YKvQ SvP+xOJaizcOI+jpwkPvkOAvLvHdkNclsXEIRgigjsZAAoMn329ruftFGTYUB3FtiEVmj5 e24QSDDjmSD3aXoNkGVsC7H4tg7WDFg= X-Rspamd-Queue-Id: 8833C14000B Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=J8zan7P8; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: qxzcbyp4crb6p5kca86qnsp9bhei81zw X-HE-Tag: 1669750537-328043 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: Even though vma_offset_start() is named like that, it's not returning "the start address of the range" but rather the offset we should use to offset the vma->vm_start address. Make it return the real value of the start vaddr, and it also helps for all the callers because whenever the retval is used, it'll be ultimately added into the vma->vm_start anyway, so it's better. Reviewed-by: Mike Kravetz Signed-off-by: Peter Xu Reviewed-by: David Hildenbrand --- fs/hugetlbfs/inode.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 790d2727141a..fdb16246f46e 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -412,10 +412,12 @@ static bool hugetlb_vma_maps_page(struct vm_area_struct *vma, */ static unsigned long vma_offset_start(struct vm_area_struct *vma, pgoff_t start) { + unsigned long offset = 0; + if (vma->vm_pgoff < start) - return (start - vma->vm_pgoff) << PAGE_SHIFT; - else - return 0; + offset = (start - vma->vm_pgoff) << PAGE_SHIFT; + + return vma->vm_start + offset; } static unsigned long vma_offset_end(struct vm_area_struct *vma, pgoff_t end) @@ -457,7 +459,7 @@ static void hugetlb_unmap_file_folio(struct hstate *h, v_start = vma_offset_start(vma, start); v_end = vma_offset_end(vma, end); - if (!hugetlb_vma_maps_page(vma, vma->vm_start + v_start, page)) + if (!hugetlb_vma_maps_page(vma, v_start, page)) continue; if (!hugetlb_vma_trylock_write(vma)) { @@ -473,8 +475,8 @@ static void hugetlb_unmap_file_folio(struct hstate *h, break; } - unmap_hugepage_range(vma, vma->vm_start + v_start, v_end, - NULL, ZAP_FLAG_DROP_MARKER); + unmap_hugepage_range(vma, v_start, v_end, NULL, + ZAP_FLAG_DROP_MARKER); hugetlb_vma_unlock_write(vma); } @@ -507,10 +509,9 @@ static void hugetlb_unmap_file_folio(struct hstate *h, */ v_start = vma_offset_start(vma, start); v_end = vma_offset_end(vma, end); - if (hugetlb_vma_maps_page(vma, vma->vm_start + v_start, page)) - unmap_hugepage_range(vma, vma->vm_start + v_start, - v_end, NULL, - ZAP_FLAG_DROP_MARKER); + if (hugetlb_vma_maps_page(vma, v_start, page)) + unmap_hugepage_range(vma, v_start, v_end, NULL, + ZAP_FLAG_DROP_MARKER); kref_put(&vma_lock->refs, hugetlb_vma_lock_release); hugetlb_vma_unlock_write(vma); @@ -540,8 +541,7 @@ hugetlb_vmdelete_list(struct rb_root_cached *root, pgoff_t start, pgoff_t end, v_start = vma_offset_start(vma, start); v_end = vma_offset_end(vma, end); - unmap_hugepage_range(vma, vma->vm_start + v_start, v_end, - NULL, zap_flags); + unmap_hugepage_range(vma, v_start, v_end, NULL, zap_flags); /* * Note that vma lock only exists for shared/non-private