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: 13059 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1972620wru; Sun, 30 Oct 2022 14:32:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5LHJokbXyXL0GT7OEC6kwvcQbLaz0dgzqudrYncyVZzFyN4wphM6/FpVwCljZ1+ww+0iz6 X-Received: by 2002:a05:6a00:1145:b0:52b:78c:fa26 with SMTP id b5-20020a056a00114500b0052b078cfa26mr10805839pfm.27.1667165559250; Sun, 30 Oct 2022 14:32:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667165559; cv=none; d=google.com; s=arc-20160816; b=ZMQs0NTMrMID4uEWdiv2acw+PpeEaPiP8aR/T0qpVYsbqu30DRzeUsumJBpK9PUBnJ E3x2JZ3K9vY62uLlQxN1yNLMCFZdh+RrVlUtoRG72Be/mV1CKvGBj7hXuWCmGRvdo7nV nBt8u6m5h5x/k2fAEPA0liKIYiQKQRUwX11uZB/cWM6QEDWS/qzj6ipEUibLOFuRzufz AYFfT0PHKWBe5mkgDssFtB4MRqy9Du0XOT7G+fPMVOlnsHjoOvB9UEMR8+X7QvbarFRg GgiBPb3qcwwNWgxcVLRcRJV5G0rSAq0t+csyN5Y9sd4Nj9MVWuzC59C/QRUEmzQMInKS OCHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vgQM4vgy+7KnPWYFNhgrYbDAEMQY1XSSTWC+/NJ93CA=; b=Fjrg2+sGdsJqicjvvy0Biyv7EqiNNFuXIcGC5GiIEUKCyJnx4J9H1ongW4t5mMXPi6 m9xQgyLQwh4y7QkZgN8MumEFwML/cj6e9bYQLhKHIA0CEUD0W2jQW4Y9PW1g1gRQo6K9 ST0jJxWQ39aM9wnnk4qm84ybeWqrmV+m+d0t5iDBIUUKlShgZwGsb+N3M/8xk3+oNLvv quPZ3tk/HlibGbbACTMmaCcd5Zz0esKWvDzn5pSxLcLruWgVLEfSId7Y/5gUl69Tpkvk 3Bd2SanlE7alTMM/A3yVMok6zGS47FnGCRu8u+MUqHwOVPX7hmN1Lu8c54y5RCP54/mv i1Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c2WcbyRM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ls14-20020a17090b350e00b00213defacf97si2069370pjb.163.2022.10.30.14.32.27; Sun, 30 Oct 2022 14:32:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c2WcbyRM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229714AbiJ3Vag (ORCPT + 99 others); Sun, 30 Oct 2022 17:30:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229651AbiJ3Vad (ORCPT ); Sun, 30 Oct 2022 17:30:33 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CE91A190 for ; Sun, 30 Oct 2022 14:29:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667165376; 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=c2WcbyRMABi8Dplc0jXgTe7OJGJJMhuRRsv0NmtP5tbNj/uSou87A6leo4xWEuva1dMBvF hitqb5MaVttgCI4BuNlhzN2uzHkVjcy73vpoullBXdWTNgCEwlxWB6D6LsgnKc2p8QQ/T1 pb5f778ffOel+kznbPTpwpEb/VoyJOc= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-75-PM-fcrfCPQ-pwSPLlw_Csw-1; Sun, 30 Oct 2022 17:29:35 -0400 X-MC-Unique: PM-fcrfCPQ-pwSPLlw_Csw-1 Received: by mail-qt1-f197.google.com with SMTP id fb5-20020a05622a480500b003a525d52abcso655048qtb.10 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=DYsghoWSS8o89aP8AF2ySpqs7uV7eTAqRh7e/eYLbSd9HEgCpkQ+9XWUaFEh6Q97qI Rev2/b6HTw9PcPgLjvGcUjohpQpBUuNCFeQ3zABsie2SdlipT+Ovwnw7iT0Jf+/qlmG2 82hx+Q32Ly8QNmjwxlLrA3J1qm5/rOBvJj31qL3XK0JJQN+ARFWfnzgYgmTM+46EQ5xi Nu9OfM1uR1PJwYbMJOZh1vQg+9M/EgbDVPXXR1SIrpC8gEdRr70nimLq6gHk1DwoCl3f UD0dxJWBVALWvwTsI1tRdlMSzK3KOvc8UznJq0rc3hCOlBNsqqLjpPBzX2QqpT3jOzgp R33Q== X-Gm-Message-State: ACrzQf3I27vqRc8mCWjOZELqEH6c2VcOKxUSVvK1rqdSTUZemGeypuZF z1rzBe8duTOfPIu1KIZq3roZUCuwLGDDc4pEV1YK/zBaTgrOPADUe62upRv5S4XB4B4FxfL+LRg EDK9vt4i9L3Vy2vtBqP7EVCzsv42BRbu7He4CSXLZTJ1XAcABIza7MqwEIG8yY6ncqsIgZAKUTQ == X-Received: by 2002:a05:620a:88a:b0:6f9:c32b:5fc6 with SMTP id b10-20020a05620a088a00b006f9c32b5fc6mr7043720qka.288.1667165374749; Sun, 30 Oct 2022 14:29:34 -0700 (PDT) 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 Content-type: text/plain X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748149793050649237?= X-GMAIL-MSGID: =?utf-8?q?1748149793050649237?= 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