From patchwork Thu Jan 5 10:18:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 39447 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp227787wrt; Thu, 5 Jan 2023 02:22:48 -0800 (PST) X-Google-Smtp-Source: AMrXdXsJemcKvQg8VvB4UbJK74y20kwXYP24dOX9ZwFtfhyeOaEUTqLmidwGF/LMaljsuKOO0a3w X-Received: by 2002:a17:902:f788:b0:192:dda4:30e2 with SMTP id q8-20020a170902f78800b00192dda430e2mr9529706pln.52.1672914168264; Thu, 05 Jan 2023 02:22:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672914168; cv=none; d=google.com; s=arc-20160816; b=kZv2RkvaY1YkaxZ6DbY2NSuyZJACiS6rEMPa9WLBDiJ/UIofFmJIzQ2XVP+/jeHqd/ OxeXX0AGZ78/tFWaIzo+3m6UyCeAsxzJsotaYXIVUQ5NkeI4CoIAwI4CVOVNZ4FUH5lz E3BOzfYxT7Wp51iKxXGHMUScpzShXSieLNC/h9Os1jc/aXLvJn6sKfSi8NJ45Ere3BiF oW9VNs7Y+zXxKjZ+fDhCMw9eE8Omkzw++ClvxeWdZ4pkwegeha2qdgl6/QEC+jlefJNE RiQqCLIZbuBzcm1bJ1uBhYgUpmupxkzrU71rBHjOh6+hyI1P5iINenP8Y1ANtKcXVZlg HmoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=NiUhznaM6wSBHvFTCRNfcVBZtE9H57LW0vfZq/kiKq4=; b=ZJ9+Or7y34DI4IRErlJFVGMZ5qME+OwsmRR8Cek9v2MwWM6y5X1uvqaYFlDyXcQEam PMJP3dAYDGc9dHwbJlRkd6HYEyNcCN28YmuUYB+dPVLlrc21PZ0Ifx1fUmpJmit+tvbM MSK8NnDlRsGo1+zvjWP6bMLOQI0wGUJFqDrq8INUDhwwyyrfaK3KFV8C2fYDOB694mDv mDC8t00zt2Ee/2x5XysaZdTpG6YsbiocLExAco4E6wPIcrHupRYnRM6k6uOZ0UYSuQpg NHhNqYI6sssc7drt0o2F+recQb1yYq6N5Ek0Xns6Qpx//H0KF0szhXV3Jse3jx0629Y+ vQGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=R0e0fs1q; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q24-20020a170902bd9800b00189c83914c7si36057006pls.89.2023.01.05.02.22.35; Thu, 05 Jan 2023 02:22:48 -0800 (PST) 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=@google.com header.s=20210112 header.b=R0e0fs1q; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232977AbjAEKVo (ORCPT + 99 others); Thu, 5 Jan 2023 05:21:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232670AbjAEKT7 (ORCPT ); Thu, 5 Jan 2023 05:19:59 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63722559F3 for ; Thu, 5 Jan 2023 02:19:30 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id n203-20020a2572d4000000b0078f09db9888so19454996ybc.18 for ; Thu, 05 Jan 2023 02:19:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=NiUhznaM6wSBHvFTCRNfcVBZtE9H57LW0vfZq/kiKq4=; b=R0e0fs1qHnnMIp3WQSIqsS/oYtW5o+Yj7Qa36R5hH23w7ZdGxSpC7WlTWoe3UlQfRD dGgTxvzDN/xImPp7YvQkVKm27XaeHjtfDYvAANhaT1tIjTWlY7bJyEtqoyb0eUUUqrU8 QXro3ShToMB2A8M5U7Ys2rZi65CcMRN/fFJOZAG6TsQBgyFYz/TZFDkv9hIUQiwwQiem r9xHbnsfSv7cyl5PTzK6aFGrR3WmNbvqetolrPlO4hROQfy+iN7qwrrmjuqcIxUxBVSJ t16F0RLTvqQFbGkRUXJ/5oh9tgpANRdg+EBmcNIs00ZH4Psbt9wmtDm5WNvKRja9aVfR jqgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NiUhznaM6wSBHvFTCRNfcVBZtE9H57LW0vfZq/kiKq4=; b=vHvJ8MyHyvWVdwTREtpZPBjHzuNKwNhQ34zN7JlxqlbvPrD4jIUqouu2ojx5WzmUoa +D2Kkm6KjwxTVkV6DamCwAaBapTu8EwFXWpIZbOXtxWxJ3hiJ3twcc955C4/3feyEkF2 hTQj8w9KOEenPDnTUNBFaLJXuGsZulvq5G4e8M1dHmHBdGcn+O07Sel1gpVPBM5nyldp 1VNeg40r14DtMKNtSsNLiTdBSyv10A49IiSeREne5+7BqMlQkcP0FGLSQZSLnEe6yeK0 54COwIknJ2enVd7aGE9YR6JLb5s2QuS4r1YtkUDof/5+oUHzEe9WUMiumXZQaZogB0ps 4m4A== X-Gm-Message-State: AFqh2kp1DtFM8qCbrHBRp9FRCqg9Dv72yk80gs2JQ/zTez60mf/Pj01m PdLETY/nAlDp+xwI+KQ0CfkmHzoi2y7Xav9d X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a25:cf02:0:b0:7b4:fa63:5519 with SMTP id f2-20020a25cf02000000b007b4fa635519mr198616ybg.270.1672913970030; Thu, 05 Jan 2023 02:19:30 -0800 (PST) Date: Thu, 5 Jan 2023 10:18:22 +0000 In-Reply-To: <20230105101844.1893104-1-jthoughton@google.com> Mime-Version: 1.0 References: <20230105101844.1893104-1-jthoughton@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230105101844.1893104-25-jthoughton@google.com> Subject: [PATCH 24/46] rmap: update hugetlb lock comment for HGM From: James Houghton To: Mike Kravetz , Muchun Song , Peter Xu Cc: David Hildenbrand , David Rientjes , Axel Rasmussen , Mina Almasry , "Zach O'Keefe" , Manish Mishra , Naoya Horiguchi , "Dr . David Alan Gilbert" , "Matthew Wilcox (Oracle)" , Vlastimil Babka , Baolin Wang , Miaohe Lin , Yang Shi , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, James Houghton X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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?1754177646784674024?= X-GMAIL-MSGID: =?utf-8?q?1754177646784674024?= The VMA lock is used to prevent high-granularity HugeTLB mappings from being collapsed while other threads are doing high-granularity page table walks. Signed-off-by: James Houghton --- include/linux/hugetlb.h | 12 ++++++++++++ mm/rmap.c | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index b7cf45535d64..daf993fdbc38 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -156,6 +156,18 @@ struct file_region { #endif }; +/* + * The HugeTLB VMA lock is used to synchronize HugeTLB page table walks. + * Right now, it is only used for VM_SHARED mappings. + * - The read lock is held when we want to stabilize mappings (prevent PMD + * unsharing or MADV_COLLAPSE for high-granularity mappings). + * - The write lock is held when we want to free mappings (PMD unsharing and + * MADV_COLLAPSE for high-granularity mappings). + * + * Note: For PMD unsharing and MADV_COLLAPSE, the i_mmap_rwsem is held for + * writing as well, so page table walkers will also be safe if they hold + * i_mmap_rwsem for at least reading. See hugetlb_walk() for more information. + */ struct hugetlb_vma_lock { struct kref refs; struct rw_semaphore rw_sema; diff --git a/mm/rmap.c b/mm/rmap.c index ff7e6c770b0a..076ea77010e5 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -47,7 +47,8 @@ * * hugetlbfs PageHuge() take locks in this order: * hugetlb_fault_mutex (hugetlbfs specific page fault mutex) - * vma_lock (hugetlb specific lock for pmd_sharing) + * vma_lock (hugetlb specific lock for pmd_sharing and high-granularity + * mapping) * mapping->i_mmap_rwsem (also used for hugetlb pmd sharing) * page->flags PG_locked (lock_page) */