From patchwork Tue Dec 5 03:08:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 13479348 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 C5E3AC4167B for ; Tue, 5 Dec 2023 03:09:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 65E506B0085; Mon, 4 Dec 2023 22:09:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 60E4A6B0087; Mon, 4 Dec 2023 22:09:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4FCF56B0089; Mon, 4 Dec 2023 22:09:09 -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 40E6E6B0085 for ; Mon, 4 Dec 2023 22:09:09 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 16ACEC0524 for ; Tue, 5 Dec 2023 03:09:09 +0000 (UTC) X-FDA: 81531283218.29.0FEC6C5 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf12.hostedemail.com (Postfix) with ESMTP id 61C1940018 for ; Tue, 5 Dec 2023 03:09:07 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=WoEr+eGx; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf12.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701745747; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=U90AZwx0u64U412UxCK0KCGmEXN+Ai+QPINiscHKrO8=; b=GQJeyc3X000r7heLB2gtyeTpNBqS2Fpq5LdRO8tA/tdxk/ssimPBYKDXalFSchA3zohu+V AtqLDHRJAckEUGP2R9KRvn69WykwH+yay3eyXscVXE9YRk24QCFiUegh8mT0X1QeZErLNt d6zA2UXiN7dgF9R+H0OfQDgjSXf4/IM= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=WoEr+eGx; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf12.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701745747; a=rsa-sha256; cv=none; b=VPcZ2zKsgxhBu+gXs4mVTVxPf9cFqoy3L2q8zSSarVDSQp+GwEjXrNF6DIz0ACx6bfZ4e3 Uy6CkrgwmAWG5dttQFi7gQJdAzM/xZpcKFBIsLFR/PU9/sHyJEdXNMBjMpDaKQPoRaTEB+ tRf/i6hhhwLsZxe6mdKjXTW+NeSxBm8= Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6cdcef787ffso5481480b3a.0 for ; Mon, 04 Dec 2023 19:09:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1701745746; x=1702350546; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=U90AZwx0u64U412UxCK0KCGmEXN+Ai+QPINiscHKrO8=; b=WoEr+eGxJJguUB2eYSILoKCU2C6yJ4nT9zB2Bmwz1guaFkYKn5MpbQNzxnHgrC13eV Dv3TiZZ6bZhatEgvq5RPO/zq1vkp0ZhNK2M185YyHVdaacgtYRyzvtWZQU3rA/dY4b6o fFaMA/P/VvIBCgVNu+ngt9caB+GLwWIKWA2kW+v7sa0m8simWBvyWSy+R3v1VB3hOsZj /7B7Y/oTdn8OVbOO/MNuZ7jP4PAD7nKyxTYWBvGGYA7V161EpfAEi+eY4aK9ckQCESNM bWFkfQ48oon+f3E0X0qk4Ffp9MZ9m0Az6nwEd9z++OlDEVe2FfXD41VU0zodwCL6leHh K1CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701745746; x=1702350546; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=U90AZwx0u64U412UxCK0KCGmEXN+Ai+QPINiscHKrO8=; b=tXPGGYa61DCMPTjDy+jYw1JS4v2cW9ULdE291kIsT/ueoVPFEJoBb6sNO+3fr6ZrtB 6HBAwj271IbDRLktjhJTqQ1AR5HNRsACkDfn9DCqedXROWDwaQBdTN6V+TyrQYRFNHtz OpeRGFwVJKKedR5fpa6DoZ73s76Wij8x91G51dKT5ku5UHRQh+NfypZJpiRrmHCbIXM+ WRZKCDDLq3GGMazuDDyOsBxy+B/mzHba5Ii3Zg2atEsl//gRhaHk9X65NXf4Ofjn+mNC HOxnQi0O7u2PyYx5mGYE5GLG/HIqZJjlZEx68IEfh3iLwCioKYnQQhHzS3emoNdSf3hZ xusg== X-Gm-Message-State: AOJu0YyaJtoBLWafBsW5pp7pfMSiZ0ZR/HNCMvUqzi+Bp/J1qnDaH1+o s4h7r+ft5ucOIGThNV4Z4lDrWg== X-Google-Smtp-Source: AGHT+IEzQfDv9VGzVKsBlFQTjRF34+fkm6hAacFqusPIW7gAuJ24V1lKK5t7tS1NNlZtGQXs4s7AkA== X-Received: by 2002:a05:6a00:6c9e:b0:6ce:5431:6e43 with SMTP id jc30-20020a056a006c9e00b006ce54316e43mr868206pfb.33.1701745745972; Mon, 04 Dec 2023 19:09:05 -0800 (PST) Received: from PXLDJ45XCM.bytedance.net ([61.213.176.12]) by smtp.gmail.com with ESMTPSA id n28-20020a056a000d5c00b006ce647b9aacsm964357pfv.130.2023.12.04.19.09.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 04 Dec 2023 19:09:05 -0800 (PST) From: Muchun Song To: mike.kravetz@oracle.com, muchun.song@linux.dev, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH] mm: hugetlb_vmemmap: move mmap lock to vmemmap_remap_range() Date: Tue, 5 Dec 2023 11:08:53 +0800 Message-Id: <20231205030853.3921-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.39.3 (Apple Git-145) MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 61C1940018 X-Stat-Signature: ece1m4zxdprt4pcksxu8dfjmesogo63s X-HE-Tag: 1701745747-22662 X-HE-Meta: U2FsdGVkX1+bPMXFd1l5eYrbo+EdiUp6oQdVPd0DcAgR/DOvthTfhLT9suNVohTsMi6xsAED+iBbgvL5q7RGwtUM+zcz0rAIbTBwhlOAZnbVRIu+RjUTZARsYtQIxmHcYOcoNVEOHld/ZwzqdtiOYFmIIx6jYNI2gm9FjnhpXppjMo+7coWs/c5LSAQNxvUk9hNaYBFwMXApTgK95fodaD9oVSPhEfIhv/r8cnR6EPf3yjRT+m50tz/yNM94HbF60hDhqHao/SBycBm3trHXxPjPeQSSizcecBApr6g/0MqSmkwJJeJTjLYOWymHAhcky5BpDsokXbsmzRM0mOsxJ5HcoViFzAFVL1qgoXeDeyKHUl/NhpsxukndANN+7UubFC8QLt31YN/msgdcEzaY1kIGo6o5Tf/g8qrMjoY1I+U/IpdTOd4vHnLixHayRBAD2bfEX+63BAfVOvUVPaknSXik2wqxHAkCDFM4UkkSnR166BbjMQxX/9VdScsLYNHKAnKq133MYh1GOxSLJC/6k7B/T8LZbuGuBoGZmtO2clTl5Vjs4GtkFcYa2dOByDhaFhSZ+wz/8yNer7wHwNqKIoutaVsFr5z/HkXYCXuxuwEL/NKxlFaiqT86oweaN//Ua/FtvOAvnnL40tBTVk+6/hSkLRzamN+QiylJarOZWz4YjVjwkND8quoPbbXVZp3qhSZj7jrIAun6nJcGzvjkjd+KUALxb16oyuuAbwmShsTA7vcQsME/MmzYseeSbeqcbhdd651BBapWJthTpCwYdaJTcXP3RDApH74Yklx8d85zui2+7YRKR0z8mqAmnBkOKsasRHHCcfuemd170/bVh4fvE9FF5kmublGXBqQdcNq4EiDUCMxlk4gZQSJV7mrEuTeqvuX2F5Hrfee4AkkoP1W5dTMhJbwRJF6/At99UGQUhIwHca6KGDOJYqfg62pw8ue1tEVrXgP7QNbzk/q /tkScwHq CHqrA9fu9y/kob0KuRaDKmvLIrM8XSAU6qRkDa++ShbzIwNDwSJh9qUO/DDuAet6o+B4pGmTijLuU9+X+IgpE0gul9H3m4Uv5c4E0Aaq4xOcsy4o5pyGUcPYCUHOBIfc9nF/bS5GNGWn9pMs2M4juyvU2vGYkoOLwX0mjCdnggpaJFuCG6S5dWUbr/6mk493Eo7iSTEzJuqdzouaeBXRk0AwOPp9A8qgdD2z+i26gIukHiixZejq3GvwcUtAFsdeWGcCg7cNGE8Vr33SE1vEqlet86+fLAi8qklmBYZ4S32TQ6jD/rijSRstBKHl/9tL5FkTg1Sznx1m0uEKza56oTGCliUaA/7rKi5I90So0sFMezt+neCqdaEZe65mDzML2RxEgKxlhvcnrFVGarZjpE18kfFa+MOTHcv+50JaOSeJiHnRThIbkDaOcf6Tcd/xivN8Zmk2ZgO8fh9A= 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: List-Subscribe: List-Unsubscribe: All the users of vmemmap_remap_range() will hold the mmap lock and release it once it returns, it is naturally to move the lock to vmemmap_remap_range() to simplify the code and the users. Signed-off-by: Muchun Song --- mm/hugetlb_vmemmap.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 54f388aa361fb..9a35b5789361f 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -163,8 +163,10 @@ static int vmemmap_remap_range(unsigned long start, unsigned long end, VM_BUG_ON(!PAGE_ALIGNED(start | end)); + mmap_read_lock(&init_mm); ret = walk_page_range_novma(&init_mm, start, end, &vmemmap_remap_ops, NULL, walk); + mmap_read_unlock(&init_mm); if (ret) return ret; @@ -282,7 +284,6 @@ static void vmemmap_restore_pte(pte_t *pte, unsigned long addr, static int vmemmap_remap_split(unsigned long start, unsigned long end, unsigned long reuse) { - int ret; struct vmemmap_remap_walk walk = { .remap_pte = NULL, .flags = VMEMMAP_SPLIT_NO_TLB_FLUSH, @@ -291,11 +292,7 @@ static int vmemmap_remap_split(unsigned long start, unsigned long end, /* See the comment in the vmemmap_remap_free(). */ BUG_ON(start - reuse != PAGE_SIZE); - mmap_read_lock(&init_mm); - ret = vmemmap_remap_range(reuse, end, &walk); - mmap_read_unlock(&init_mm); - - return ret; + return vmemmap_remap_range(reuse, end, &walk); } /** @@ -358,7 +355,6 @@ static int vmemmap_remap_free(unsigned long start, unsigned long end, */ BUG_ON(start - reuse != PAGE_SIZE); - mmap_read_lock(&init_mm); ret = vmemmap_remap_range(reuse, end, &walk); if (ret && walk.nr_walked) { end = reuse + walk.nr_walked * PAGE_SIZE; @@ -377,7 +373,6 @@ static int vmemmap_remap_free(unsigned long start, unsigned long end, vmemmap_remap_range(reuse, end, &walk); } - mmap_read_unlock(&init_mm); return ret; } @@ -434,11 +429,7 @@ static int vmemmap_remap_alloc(unsigned long start, unsigned long end, if (alloc_vmemmap_page_list(start, end, &vmemmap_pages)) return -ENOMEM; - mmap_read_lock(&init_mm); - vmemmap_remap_range(reuse, end, &walk); - mmap_read_unlock(&init_mm); - - return 0; + return vmemmap_remap_range(reuse, end, &walk); } DEFINE_STATIC_KEY_FALSE(hugetlb_optimize_vmemmap_key);