From patchwork Fri Nov 18 01:10:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13047534 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 173F2C43217 for ; Fri, 18 Nov 2022 01:10:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA6558E0001; Thu, 17 Nov 2022 20:10:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B372A6B0073; Thu, 17 Nov 2022 20:10:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C5EA6B0078; Thu, 17 Nov 2022 20:10:33 -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 672116B0071 for ; Thu, 17 Nov 2022 20:10:33 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 44E78140226 for ; Fri, 18 Nov 2022 01:10:33 +0000 (UTC) X-FDA: 80144782746.25.18746B1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id DCCFB40008 for ; Fri, 18 Nov 2022 01:10:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668733832; 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=NCAnpiPt+tc1mIfjedss7udThNf5UmUQ5mc3nevJ92rWnn57VteJso03Kjkc7c8exkaROa MctIKYmmTGoj4rkbK9rQ1P0BMoDpFIn03m1gl/+ab9aM6FNEFkrvcD7Z+l9j7REK5c6coo V2oflIZ3tlA7ZcSz9gjDzKngbSWoPfo= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-648-5m0aTwnaM7CJ3k1LmRqjgA-1; Thu, 17 Nov 2022 20:10:31 -0500 X-MC-Unique: 5m0aTwnaM7CJ3k1LmRqjgA-1 Received: by mail-qk1-f198.google.com with SMTP id x2-20020a05620a448200b006fa7dad5c1cso4401217qkp.10 for ; Thu, 17 Nov 2022 17:10:31 -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=GcaXjTpfvB3n7GV3cFkP8RqSltkmHnic+wzw4P+nQG5vyPwiNGvskS1R0OzcGdkr0E YzimQ22Ify6rJT//wUhOtQ/OzDOtnW/Fdg2zsH5ynclN2Ah8VIy2Ahz2bmSEOFpitpNq NC5ghj8cE8MaiNFi/d8FtnU9rrR9qJ5urxRmXM8RBN3lNrG9cn2jHKE/Y1XY1VCQUccp xIduUB/rYIPlx1Z1ownuHpB8mxyM7DQiGbn7GrC9XBtMevHBA6OqPhXim74agOEMQbjH I/CXZI1Oh7eR76cw8uhsWZo4VdYY8E2TDCaRrhxRXO091nHKnbZImz6c0okOD6BI503J kwhg== X-Gm-Message-State: ANoB5pnLVKOiJXEWUxsHqCw1hKvAgISpTMlDCg2xRySJBvEB78ZMZyj8 fH//Htj2eSa9a6CqzhaOPyufVE1jAVmhB1UNfIBY+/6l5VXiU8BNbI2oIuv26antzGUdWqEuG9S fTCc6WDIVsGE6zLUhnrlRTLmod0fkHQviwKnMN2m2nOdpsVLQFuRrfwojEAq3 X-Received: by 2002:a05:620a:d41:b0:6fa:1af0:7c2a with SMTP id o1-20020a05620a0d4100b006fa1af07c2amr4043649qkl.777.1668733830622; Thu, 17 Nov 2022 17:10:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf75PFHtqCG9q2KgS1yvrcaA+UfK7n2hAr9m/2KGhekXpy9/jpuVsMotL2vGdRkhVFniO41W+w== X-Received: by 2002:a05:620a:d41:b0:6fa:1af0:7c2a with SMTP id o1-20020a05620a0d4100b006fa1af07c2amr4043628qkl.777.1668733830341; Thu, 17 Nov 2022 17:10:30 -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 u7-20020a05620a430700b006eed75805a2sm1491342qko.126.2022.11.17.17.10.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 17:10:29 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Rik van Riel , Muchun Song , Andrew Morton , peterx@redhat.com, James Houghton , Nadav Amit , Andrea Arcangeli , David Hildenbrand , Miaohe Lin , Mike Kravetz Subject: [PATCH RFC v2 01/12] mm/hugetlb: Let vma_offset_start() to return start Date: Thu, 17 Nov 2022 20:10:14 -0500 Message-Id: <20221118011025.2178986-2-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221118011025.2178986-1-peterx@redhat.com> References: <20221118011025.2178986-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=1668733832; a=rsa-sha256; cv=none; b=aMyC5DP1jSE0wknpCNUhdrvY21STe/3b44pr4tHzbgs2pUKaV2jYjP1Tcm7RcrDIJkn1lb 5P4Bnw3gG3XUW4nQBbA0k98EDi/sa6xQJkkZUTivUC4Uig5jcA0CH67yXyCpX85QtJEC4U LBNOM64r/YnVds3zv3r1BgOWgn8ujkw= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NCAnpiPt; spf=pass (imf07.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=1668733832; 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=aJt12UWd7AGuB3K6uDKG69jhdSwGTzQyVIvg4eIzeEPQjkcgOw4tDRvyNOj0cOH7qhDMWe SjEij/pVEPLJVXvN2h/D/i+3QHcNWTQJITtKkmtpZD2t5jGXZ4xO9hvgsZs8OmSKDP6XBZ 657l+SYVorxjA92/R+PTV59d0yQZU6E= X-Stat-Signature: tn1rrn1mzh4hqk6foxhzf86ojbnpmpcu X-Rspamd-Queue-Id: DCCFB40008 Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NCAnpiPt; spf=pass (imf07.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-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1668733832-607617 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 --- 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