From patchwork Sun Oct 30 21:29:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13025215 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 B09F7ECAAA1 for ; Sun, 30 Oct 2022 21:29:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8C2EA8E0002; Sun, 30 Oct 2022 17:29:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D4BB8E0001; Sun, 30 Oct 2022 17:29:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 626EC8E0002; Sun, 30 Oct 2022 17:29:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 56C658E0001 for ; Sun, 30 Oct 2022 17:29:39 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 29F1040A3B for ; Sun, 30 Oct 2022 21:29:39 +0000 (UTC) X-FDA: 80078907678.15.157BEFD 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 BD2A71C003F for ; Sun, 30 Oct 2022 21:29:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667165377; 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=vgQM4vgy+7KnPWYFNhgrYbDAEMQY1XSSTWC+/NJ93CA=; b=UV8XJ7jsRur0UmosKLJPs7T9l0RCPY8ZAOqRC9R55yZDDpwaD0R1HxW3pSQamCEThgX1rX tMXWaGTr2Ny82NhZ87IlhgFZcsz1/G0hk4O4/QKP4/XYQwV5qAEdpGpiQJMOT65EY7Ah6m SwWF6GwuAMiehB7napb1RKxCczCgRrg= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-378-a7o_1hzGP1mVa6JVF1lfdQ-1; Sun, 30 Oct 2022 17:29:35 -0400 X-MC-Unique: a7o_1hzGP1mVa6JVF1lfdQ-1 Received: by mail-qt1-f198.google.com with SMTP id v12-20020ac8578c000000b003a50eb13e29so3372434qta.3 for ; Sun, 30 Oct 2022 14:29:35 -0700 (PDT) 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=vgQM4vgy+7KnPWYFNhgrYbDAEMQY1XSSTWC+/NJ93CA=; b=bNqxyI++YuBPUNAz/yQ7k/dbrqkan7eInk8F6HlNkAeoLBjVjp8nWPQqClTW9uEDFB ouAOnUDWooRibYlkdUIDbrq8XcfOkKmECZuWTJu63rTOU5oR3x7lmslb1LMRkMS1/Zuj DHlkCdiRDQUbRRmWGBxCwHf6oddo93oV/glm2VjPz3NbBFLCaEq8kkAJ+j0Iqwdru9x6 lGSHDYUCvHUzNOBdNZX5X7e2WbYcB1L6QGXhUsx+DhHJG+0nAY183nKzp3SpgvpmPpnA xknvQmt8B6OAVNtj0o5PdlEErCGOZDfCkkseC3Tt49FyXJyTxUeqRUaxRPKELfOlgO76 8zNw== X-Gm-Message-State: ACrzQf3BuDTw0gDtEkL4DnH1VyOR7GSRw9+V4xhrpALUld/eADcS7LyJ xzsQEkz3U9iscH2D4XljMcGTJJhpdwqSW5LWgWfPGzzW99pAcxzioNKTQtN0GuTnVHk+mfiuc21 VY9jNWodQdRg= X-Received: by 2002:a05:620a:88a:b0:6f9:c32b:5fc6 with SMTP id b10-20020a05620a088a00b006f9c32b5fc6mr7043711qka.288.1667165374687; Sun, 30 Oct 2022 14:29:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6gRJ4q4CUl52TBJKx7VsDhJCeJVh7fc6aYcv1+iKVnCNyNlKKvVpkjHmjx+cbWeRM6B/g+2w== X-Received: by 2002:a05:620a:88a:b0:6f9:c32b:5fc6 with SMTP id b10-20020a05620a088a00b006f9c32b5fc6mr7043701qka.288.1667165374468; Sun, 30 Oct 2022 14:29:34 -0700 (PDT) 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 a1-20020ac81081000000b003a4b88b886esm2654781qtj.96.2022.10.30.14.29.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Oct 2022 14:29:33 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , James Houghton , Miaohe Lin , David Hildenbrand , Muchun Song , Andrea Arcangeli , Nadav Amit , Mike Kravetz , peterx@redhat.com, Rik van Riel Subject: [PATCH RFC 01/10] mm/hugetlb: Let vma_offset_start() to return start Date: Sun, 30 Oct 2022 17:29:20 -0400 Message-Id: <20221030212929.335473-2-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221030212929.335473-1-peterx@redhat.com> References: <20221030212929.335473-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UV8XJ7js; 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=1667165377; a=rsa-sha256; cv=none; b=ijWc9WVV4RvVIpQHDIxB0p9/v58zQTaCUgEUw1lj/IjBy1/HPdrIj/Wxh0V4A4iZoBkuwA 8yMN3UGyPEq4Q2afr34g/v/JQOOf27e5G0t5wYd05GEjbRus0UxEtopWXyno9hhnFkex8Z 33/gFyqeWuiT8b9/NaOZ3/aTv7WhEpA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667165377; 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=vgQM4vgy+7KnPWYFNhgrYbDAEMQY1XSSTWC+/NJ93CA=; b=0ogtZht8chxwWsoRGAktsdRbxnH1y3pguq75cRfw7VCtnVPsEH5M3jkt1MCfAbHGIXuowU WF5S2GotlGbqfqe/omJ8ZT+WpZYLtt/LxTq8l0KkRzYnbKiCD2Lk2rDIvankSWIlkK/dfT ZzSMWBlKH3NDfy8VDkfjonVBdIL9a1I= X-Rspam-User: Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UV8XJ7js; 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 X-Rspamd-Server: rspam07 X-Stat-Signature: odxts4tuuq4tx71pyigki5ib155kabpw X-Rspamd-Queue-Id: BD2A71C003F X-HE-Tag: 1667165377-856352 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. Signed-off-by: Peter Xu Reviewed-by: Mike Kravetz --- 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 3ee84604e36d..ac3a69fe29c3 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