From patchwork Fri Dec 9 17:00:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13070014 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 DF293C4332F for ; Fri, 9 Dec 2022 17:01:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 765868E0005; Fri, 9 Dec 2022 12:01:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6EECD8E0001; Fri, 9 Dec 2022 12:01:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 569448E0005; Fri, 9 Dec 2022 12:01:18 -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 4402B8E0001 for ; Fri, 9 Dec 2022 12:01:18 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 00FD51612A3 for ; Fri, 9 Dec 2022 17:01:17 +0000 (UTC) X-FDA: 80223383436.28.A9D5B94 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id B05831C0021 for ; Fri, 9 Dec 2022 17:01:14 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="h/06BBKf"; spf=pass (imf18.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670605274; 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=W6TRH+D4KiiNcSkU8trC/D1fuTVk/3U3ig0mjyWFdEw=; b=HN6JfYksooF7/+CGvjYjRVC7JNd9ohDlJipkLOd96G/uFiRiCewAAjbwFl9W1jAMVmxKKl 9t4lJsXb2UE/sONHBYZw1GGMT26ld1q/pvyS9LjGUCgATaJcP2BVfk3d7h2HmbHwM6TAbs E4x9dqUJf1vqkePW91u/h9eYc3ncNPs= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="h/06BBKf"; spf=pass (imf18.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670605274; a=rsa-sha256; cv=none; b=qiMGdAtVwz4o2RB/fR3Xoc2NPFUraCeWHzOrCT67So2dXSZx6UEP6FnCxnZr40tflMncqw Iv5pSXSQYRETRyYpE1kHrG5uZaOUmxMZX4ltvpt95tKEHUGpyPTsZBQRluXYu0hUzRoxcY ucpiADy/F5WpTfceRn5r6STzWaGZld4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670605273; 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=W6TRH+D4KiiNcSkU8trC/D1fuTVk/3U3ig0mjyWFdEw=; b=h/06BBKfpncYFUep+eykfC6o4wSh6uV5/RYQAYCRoK+5QuTH+5Ym+6RKf1/PVdLjAbEIi+ 09leC7tOsk6TxQMhahuK4W0QCnRwOFT1XBY2EIuHVHJ2+vycyqbjmKpV6BaVpXW/pCGzIx 2aSps95QA5Axn3BmejmayMvieBx6j10= Received: from mail-oa1-f70.google.com (mail-oa1-f70.google.com [209.85.160.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-542-SZ4RfORDP-GkQupA5zCNqA-1; Fri, 09 Dec 2022 12:01:12 -0500 X-MC-Unique: SZ4RfORDP-GkQupA5zCNqA-1 Received: by mail-oa1-f70.google.com with SMTP id 586e51a60fabf-1445373be54so144658fac.7 for ; Fri, 09 Dec 2022 09:01:12 -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=W6TRH+D4KiiNcSkU8trC/D1fuTVk/3U3ig0mjyWFdEw=; b=x5Up5K01f3dJwlSPPYseJe13q2Pr83+iq1+dmZOO4kjRPiHxnjrEL0lmjD9I+tX2Jk krTNxvChYM/9AVelDhPinAmV9p4+kj8OPol02NrEcXVUVtZRks1/sBLvMlru0V0ihXAH cvRfPp3FsWC9AwlioPonvyW4S9WXTQZ7mxF4SjWjHWuwwkqfLO4NyjrdKJkVAclm9QDb 61G1WqCWYPzx4PYt/bVsZfDKwYORN452vYe7Yos739FhDlap7IGS+dp6XmpoWGR8qq/F 3Xsi3cXySG9MlIqvbRIeKY+VHBe3rW3QjyKQWbBCyJPxn42nxfzi0+YsJw4Dx4gmMISZ fNLg== X-Gm-Message-State: ANoB5pnfluozeJW/hZarY3JSQIJBsccz6CHG2AWDnOUKZqjWj1QLg9we WWY5kZ9CwWPsvJ1KaqiypFEVj9ZhspnudhapqiSRne+entv8LyUWlJy0E/L0jSSlGWeoBPR15eF BuedFFfe5Pq6Z+30X4UCHxVSU2Q0Xabkgs64wN3VR6e/k7fGV+nqCuEEsTlTX X-Received: by 2002:a05:6870:ed8e:b0:144:c281:11ec with SMTP id fz14-20020a056870ed8e00b00144c28111ecmr3491126oab.38.1670605270812; Fri, 09 Dec 2022 09:01:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf6WHTJqwwVeVsgY0NWBk0jYEVKINaa6MKI3WEpB+yvuS9iLQU0VCefP3qH0KxAb0MhxkQi25w== X-Received: by 2002:a05:6870:ed8e:b0:144:c281:11ec with SMTP id fz14-20020a056870ed8e00b00144c28111ecmr3491088oab.38.1670605270459; Fri, 09 Dec 2022 09:01:10 -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 q7-20020a05620a0d8700b006cf38fd659asm178907qkl.103.2022.12.09.09.01.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Dec 2022 09:01:06 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrew Morton , Miaohe Lin , David Hildenbrand , Nadav Amit , peterx@redhat.com, Andrea Arcangeli , Jann Horn , John Hubbard , Mike Kravetz , James Houghton , Rik van Riel , Muchun Song Subject: [PATCH v3 1/9] mm/hugetlb: Let vma_offset_start() to return start Date: Fri, 9 Dec 2022 12:00:52 -0500 Message-Id: <20221209170100.973970-2-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221209170100.973970-1-peterx@redhat.com> References: <20221209170100.973970-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: B05831C0021 X-Stat-Signature: oxzsfzwkbr45ou5p6qk56npu9y7ima9p X-HE-Tag: 1670605274-933348 X-HE-Meta: U2FsdGVkX19O92BYLfcMtwUTTCJakyzUfTyqG9RtlRcxvjnjbitAEyLNgCpJCC3LsbmWDke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dDHT4OTgwyIaNqCoQqm/z9OhPSg4WByI0qUGz4TzU51VL5SDf9KFfSXkpWOvOPtcQDjftLwkIoHezROZqCQuumD0LQrqrOwI9WAcpQ= 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 Reviewed-by: David Hildenbrand Reviewed-by: John Hubbard Signed-off-by: Peter Xu --- 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