From patchwork Wed Dec 7 20:30:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13067577 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 959BAC63705 for ; Wed, 7 Dec 2022 20:30:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E2178E0001; Wed, 7 Dec 2022 15:30:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 96B0A8E0005; Wed, 7 Dec 2022 15:30:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7BD728E0001; Wed, 7 Dec 2022 15:30:43 -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 542BD8E0005 for ; Wed, 7 Dec 2022 15:30:43 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 21C97141025 for ; Wed, 7 Dec 2022 20:30:43 +0000 (UTC) X-FDA: 80216653566.15.0381D93 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf09.hostedemail.com (Postfix) with ESMTP id A64EA140011 for ; Wed, 7 Dec 2022 20:30:42 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Jplkhv66; spf=pass (imf09.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.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=1670445042; a=rsa-sha256; cv=none; b=TOvbAjapAvrh+1TCEDiZeaySfWtUFXY81oXL00C6LilXetGVpRrUDi4du6DZ04GXDizrrl nX6nHM/81c630fquV7nndo2g01UdHAEo4mBMIyjhu7nPmiDqUFPvE3I70ln0srqXoIj8y1 NQCh55HpcdcILNj0IFzc6fPdgWfnuwk= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Jplkhv66; spf=pass (imf09.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.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=1670445042; 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=kXTqB5FubF2+0tcQcQ/EoMxi6C2oCNf5KVcHgua8JL0=; b=fJeKdzBBoOkFeCMd4XNMfGDfhte8KcxVEdcvrg2kVtcU5O71Ug8pqnvqOVUJKPoU6e/psX Jx4tt61/tqSajn0DvWm6lVjJaIUBdfuvb0cEnUYNvqNh1xpzFRt/5jZPBU1iUa87jAoa8A 1Leh1W77/u26abPtehIrjSSdCLT/nGw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670445042; 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=kXTqB5FubF2+0tcQcQ/EoMxi6C2oCNf5KVcHgua8JL0=; b=Jplkhv66+/xlI1uUbT+rjsNq/Wj8B3aGSyuMo6Raarc3s4gFkslI1whjCth46a0K57KsbJ oSk7mSfrUsEjLYRW74M8pqiimXQ2XfnFuxJzhxU7oTmXOH/3A1L2bgmv9AKNh0CGNscuR6 yWQLxzZ1pHfc/LWBwCJJg6H5YY2iaEI= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-671-iz7lCSIvPKyIjOwypYBADA-1; Wed, 07 Dec 2022 15:30:41 -0500 X-MC-Unique: iz7lCSIvPKyIjOwypYBADA-1 Received: by mail-qk1-f197.google.com with SMTP id bq13-20020a05620a468d00b006fa5a75759aso26384710qkb.13 for ; Wed, 07 Dec 2022 12:30:40 -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=kXTqB5FubF2+0tcQcQ/EoMxi6C2oCNf5KVcHgua8JL0=; b=ErCl1/6OoQAiR5wcO7raDp6ZM94gDgclopO6ibpgp43oTvjfqJjAAiUJagx5VDoF3P C5RZXZ2R032hTAlFjDUuT6gcGDQx2guv1OW6+M3wstmTUqgcNRa0ajIT7z0atidB+ekz epGBAD+zqvqyYlSGPnF+h+C8qp3w+2e+GfF+cMqeNv9wK2cnaWuTyqKBSnK6OHMmpWGq 8ybxa44p0W5tPbgxE01nBzoNXlolMlByO3TZ/abwIpztIuDMBG1Schbe7f/IIyH5LTTM l+7DpMa13RHtIrwJCgovQ+RAf0BdVJRdge7A5CWeWsaw3ZzHjNHLkRY/t4pCNncot8XH 3R1w== X-Gm-Message-State: ANoB5pmuP+mpdV7c4qn3u8IHZTqL5ylua37VbaAQ6KdpqewTkta0gVaO HvThJqrpvthFss51lt9zeY1/wELEEm5BImkymIAGrCm2TEmivAlLCuOAVTiqQWsK8CY92O0Ts8H PFhqeu1jXXItdCLjmDEnXD8opO6uxFPDwXrqK/nS62YE5eCswrwC5yOitM1kF X-Received: by 2002:ac8:4e47:0:b0:3a5:63ef:cf4e with SMTP id e7-20020ac84e47000000b003a563efcf4emr1902955qtw.16.1670445040174; Wed, 07 Dec 2022 12:30:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf6IQwsRhSSOAs+i008iOESp/4MgizW47uNvKVfGDqpV4y6exkH0YuDqLS4fPXFFuTpd369j9Q== X-Received: by 2002:ac8:4e47:0:b0:3a5:63ef:cf4e with SMTP id e7-20020ac84e47000000b003a563efcf4emr1902931qtw.16.1670445039881; Wed, 07 Dec 2022 12:30:39 -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 dc53-20020a05620a523500b006fefa5f7fcesm855594qkb.10.2022.12.07.12.30.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 12:30:37 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Muchun Song , John Hubbard , Andrea Arcangeli , James Houghton , Jann Horn , Rik van Riel , Miaohe Lin , Andrew Morton , Mike Kravetz , peterx@redhat.com, David Hildenbrand , Nadav Amit Subject: [PATCH v2 01/10] mm/hugetlb: Let vma_offset_start() to return start Date: Wed, 7 Dec 2022 15:30:25 -0500 Message-Id: <20221207203034.650899-2-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221207203034.650899-1-peterx@redhat.com> References: <20221207203034.650899-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain X-Spamd-Result: default: False [3.60 / 9.00]; BAYES_HAM(-5.50)[98.90%]; SORBS_IRL_BL(3.00)[209.85.222.197:received]; R_MISSING_CHARSET(2.50)[]; SUSPICIOUS_RECIPS(1.50)[]; SUBJECT_HAS_UNDERSCORES(1.00)[]; MID_CONTAINS_FROM(1.00)[]; RCVD_NO_TLS_LAST(0.10)[]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; PREVIOUSLY_DELIVERED(0.00)[linux-mm@kvack.org]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWELVE(0.00)[14]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_ALLOW(0.00)[redhat.com:s=mimecast20190719]; MIME_TRACE(0.00)[0:+]; TAGGED_RCPT(0.00)[]; DMARC_POLICY_ALLOW(0.00)[redhat.com,none]; TO_MATCH_ENVRCPT_SOME(0.00)[]; ARC_SIGNED(0.00)[hostedemail.com:s=arc-20220608:i=1]; DKIM_TRACE(0.00)[redhat.com:+]; R_SPF_ALLOW(0.00)[+ip4:170.10.129.0/24]; RCVD_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: A64EA140011 X-Stat-Signature: g6bqi3qpq5u48ht6imk5ksiq87qd7p5o X-HE-Tag: 1670445042-807483 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 Signed-off-by: Peter Xu Reviewed-by: John Hubbard --- 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