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: 173711 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3185145vqy; Mon, 4 Dec 2023 19:09:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IHUDQrMnxIncAR6Ar3g4EY5gPP79wwV0IpKQpjnVmPzxCJyI5pG0mT+hsq6e7VQQSLm/WB8 X-Received: by 2002:a17:90b:38cc:b0:286:b8eb:d286 with SMTP id nn12-20020a17090b38cc00b00286b8ebd286mr619267pjb.52.1701745778555; Mon, 04 Dec 2023 19:09:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701745778; cv=none; d=google.com; s=arc-20160816; b=OrPti+IwGjTUIaDougsETkxyhlhbLRuQoyreY/WwRwkd/Cr44HO7FEB1yvtxUOy23p Gi7E501oSRhHZ6NpnVUvnTt+8+4L3zqcQbAn4S8MT0bcuU6DtV7JyNaLE+zQe5pB3I5y vN/JQCpcpqZxwJ55y9+D8xTjR6kDULKlFN9v2XKlT0aFsz1wlMs3HCACed1sl5a2LWGP CM6raDieO5paeX2FbpeppzkIH+LvZ85eOgRTZZjRvtniyxJR5ttB4gPU91krEghHQnEW HiMF1qd0LVpk23H7/xjaP6eKUnCYxrKgLDt3sqfPv/OhgpMdXtXz20GX+BF6dnuvLVfw jgBg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=U90AZwx0u64U412UxCK0KCGmEXN+Ai+QPINiscHKrO8=; fh=UHevQD8g/ASKsyBf3gegCtnBBR+hA6VRMUG2agRDexA=; b=WP9Xz7avabVSCFP5yLKdj/ALa0+ehtMPQaGy89FOEf90ib5N527tpgftazj/Xdu1DW 3F17ePd7bPUXCkNpHjHGxJpt/+YxM1pCKyNX+ShqmWhxj4oBphaUmCbYSx66YZ/suJ6A eMzLRpsz45EEKAzUVrMW5MhTcf8z+09rEiczhZzCDN++8eGGTbBp9YZ3g+e5ooXgUkgU Wie/brzepMl9Uvd+By460OdPMT+jAtwXKS+mnfVU6ZTEeWEpJ2VSmLGtuIFXjbCUcR7M XMXjwRAeTOChqWTh6vhKQa44u5fefYCHQO8Ln411REP/weuDgO7t1CKiueTSaBc0CqzM gY5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b="F/LnkcUO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id n1-20020a170902d2c100b001d0c1281f07si915810plc.205.2023.12.04.19.09.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 19:09:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b="F/LnkcUO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 8B3BF805A890; Mon, 4 Dec 2023 19:09:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344139AbjLEDJZ (ORCPT + 99 others); Mon, 4 Dec 2023 22:09:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343930AbjLEDJY (ORCPT ); Mon, 4 Dec 2023 22:09:24 -0500 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A728BF for ; Mon, 4 Dec 2023 19:09:06 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6ce52d796d2so1516747b3a.3 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=vger.kernel.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=F/LnkcUODZuPVx4oUDtMsx+BhTZnmphfyXDjI2rmBu+lndSwI+2+utjib2vBq8IRZP 4FeBOYHpL1JaV1b0PCcZDxFe3wDWpZd2aTX923EMY2bpWwpxMEEOAs+7y3I5T+tTKzvj 7+xUCuRcY86engvAx5oJtDiws6oA0P27JMoCirV5IH6II1ZZ1ZY2EDA/rg22JvXN8fNp Ct4IiLT82L5OEePLjWhCssMGumCi0CS4LqENVacEfi0pxTVbljM+Bor+6GL4JIObrkcG HJuso3oclgWCPlrhQXEdXmUxdlFpqTdeyMuzObmExbb6JEIlytToYNzWJO7WVKSlG3Ns rqhA== 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=Ex3aq+aeIve5tcy7wU5WJM/PJA5ORdhv+sRKYOu866vjNqUWvz5FheocqScr7KCkbU EfBT1MMOBplM/d4MZJR+I2GB/yUfSeZhP9Pl9W6OjIcL1E6LW8c1YDu16pDAoS1kqIYh ztnsKT96hFrn5C+BtCndP+wuvUyz2GGhUb8YuU5lMS0HhYfpcFIpcgDi7xzUbnUN96ux 9GRyMFerph9UZL0kzxBEmdLwLL2A9jZB94WwuOCkPirP4fEctnj4OwsWgWjP6w24hE+L A8A5URtGLmSDyyX7mLJPVPqz9b1gujpKIcE9Y+A3bUgiMRNzNa+jtu9x1qbkoGu/Ri5o LV2Q== X-Gm-Message-State: AOJu0YwErgyFUnGNdxXopJPS9aF4IQxPTA5piBqOMzbpXX0vA3dpT9tE WhTaj0i1sBAdv49i+xhP7VJM5g== 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-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 04 Dec 2023 19:09:34 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784409781479543259 X-GMAIL-MSGID: 1784409781479543259 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);