From mboxrd@z Thu Jan 1 00:00:00 1970 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 AAD8BC4321E for ; Wed, 30 Nov 2022 15:58:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE6A06B0074; Wed, 30 Nov 2022 10:58:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E96B06B0075; Wed, 30 Nov 2022 10:58:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D38D76B0078; Wed, 30 Nov 2022 10:58:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C3C7E6B0074 for ; Wed, 30 Nov 2022 10:58:31 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8F2E51605C3 for ; Wed, 30 Nov 2022 15:58:31 +0000 (UTC) X-FDA: 80190566022.29.6E9595F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 35375180007 for ; Wed, 30 Nov 2022 15:58:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669823910; 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: in-reply-to:in-reply-to:references:references; bh=gumPfomwfQgnMEmlAyv6hxZfw1R4BzWPjEo9qytgwX0=; b=emu18ouOknB31YZ+XCw9Os5RWsB8kAygwH/kWmpk87pufkAUhJIcBZgNw3JU8FLNKkjXjC nbETsQrr7SJsAecbD+j2p1HP6niM+ZAoe065cmPeBcxYtLUErQ4C24wlgjBi22s8iZWy2+ vFjGMfeUxxLYoirTC2ByLBtvZRqbj6M= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-467-g7Ug_j_ANqeEZ7Aqd42Jig-1; Wed, 30 Nov 2022 10:58:29 -0500 X-MC-Unique: g7Ug_j_ANqeEZ7Aqd42Jig-1 Received: by mail-qt1-f200.google.com with SMTP id b20-20020ac844d4000000b003a542f9de3dso28998177qto.7 for ; Wed, 30 Nov 2022 07:58:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=gumPfomwfQgnMEmlAyv6hxZfw1R4BzWPjEo9qytgwX0=; b=2C+s/W8wtLJlu2Qxgh016pZf3IDD6kbFGJoODr689xfVDSxuQw6Eb0vbaqAemdeXQg 8e9JOyuvkmJUzwWa1dcFo/t5DLZ3WUB2tK5ymGtYw+iSJYvxB4up2eyZHYCSeOZhSwQ6 UTVZMGfNFoZORqLfhI9ZyVO5W93fCwUFQBo7VCNvD3DXFNqOr6s7NFd30YJgE72+2HgC opec6X45EIQRhl452CS86nIWuYwJYRj8qT7NUtopIWlDryh76bf4hKXBbmWFSXSeOOe7 SyFcKMoB1eYuapYiqX1hxBzh9JTmo6moxEQOo9OWF/vQ7bqpWoOC24ZErpcMpdCpOc6n zlvw== X-Gm-Message-State: ANoB5pn6f0zyseMen0MrZYGA2cl5hH51ba06M/Jv8AkPZL1zfkPiXVoV 5h31kKd7P2hoeMOgBO0g1LWrmrECYcoWq+IpXIpHvZqTOoHg2hpltgV7T8v0FQ3GtEwzUwJnbui sBPbVZarlUh4= X-Received: by 2002:ac8:44b9:0:b0:3a5:81ec:c4bf with SMTP id a25-20020ac844b9000000b003a581ecc4bfmr46559859qto.180.1669823908556; Wed, 30 Nov 2022 07:58:28 -0800 (PST) X-Google-Smtp-Source: AA0mqf6pBOYhiiE2CqRWsX8IsY49phZViulM6NbKkVUdLVuq8qQQboKpqdAL6d3q9aaQVWSWvod8Qg== X-Received: by 2002:ac8:44b9:0:b0:3a5:81ec:c4bf with SMTP id a25-20020ac844b9000000b003a581ecc4bfmr46559836qto.180.1669823908297; Wed, 30 Nov 2022 07:58:28 -0800 (PST) Received: from x1n (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id y6-20020a05620a25c600b006b9c9b7db8bsm1462092qko.82.2022.11.30.07.58.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 07:58:27 -0800 (PST) Date: Wed, 30 Nov 2022 10:58:26 -0500 From: Peter Xu To: Mike Kravetz Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, James Houghton , Jann Horn , Andrew Morton , Andrea Arcangeli , Rik van Riel , Nadav Amit , Miaohe Lin , Muchun Song , David Hildenbrand Subject: Re: [PATCH 03/10] mm/hugetlb: Document huge_pte_offset usage Message-ID: References: <20221129193526.3588187-1-peterx@redhat.com> <20221129193526.3588187-4-peterx@redhat.com> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=emu18ouO; spf=pass (imf06.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=1669823911; a=rsa-sha256; cv=none; b=Axhgv4Sq4ISIh954BvCYpn7jNFM1W97Ml5E9XZriHWIW34Zy6d2TkgzOURT+FQPE7oOwPM avF/8YgVakppMmzYTMMi0e2dCQLrv2BqnB6UxQE60ES9g8qM7ymTD08fHPsYPiXOSJGRer 72e1bNfuI7k0/aKXaeN+R8PtQYIDPHs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669823911; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gumPfomwfQgnMEmlAyv6hxZfw1R4BzWPjEo9qytgwX0=; b=iJrPBokPHXJGGiDlIq2oj4BemBJnvG26V0QpKFq5RiD8eA29F54m18Cxv2IiC9Wqcmxh/O SWJ4xGpkCnos7+dvkTtv5kkByjGzejfYd64fg9qk7mt5btfIEIXJ2S/UgyOpHBUU/aEZ4A 4wQLYQ3XwgumEwv5lkz6JnIn8kh46Fg= Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=emu18ouO; spf=pass (imf06.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 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 35375180007 X-Stat-Signature: h6eikts7k41ymyopshykbm7ang9if41z X-Rspam-User: X-HE-Tag: 1669823911-819030 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: Hi, Mike, On Tue, Nov 29, 2022 at 08:55:21PM -0800, Mike Kravetz wrote: > > + * (2) For shared mappings: pmd unsharing is possible (so the PUD-ranged > > + * pgtable page can go away from under us! It can be done by a pmd > > + * unshare with a follow up munmap() on the other process), then we > > + * need either: > > + * > > + * (2.1) hugetlb vma lock read or write held, to make sure pmd unshare > > + * won't happen upon the range (it also makes sure the pte_t we > > + * read is the right and stable one), or, > > + * > > + * (2.2) hugetlb mapping i_mmap_rwsem lock held read or write, to make > > + * sure even if unshare happened the racy unmap() will wait until > > + * i_mmap_rwsem is released. > > Is that 100% correct? IIUC, the page tables will be released via the > call to tlb_finish_mmu(). In most cases, the tlb_finish_mmu() call is > performed when holding i_mmap_rwsem. However, in the final teardown of > a hugetlb vma via __unmap_hugepage_range_final, the tlb_finish_mmu call > is done outside the i_mmap_rwsem lock. In this case, I think we are > still safe because nobody else should be walking the page table. > > I really like the documentation. However, if i_mmap_rwsem is not 100% > safe I would prefer not to document it here. I don't think anyone > relies on this do they? I think i_mmap_rwsem is 100% safe. It's not in tlb_finish_mmu(), but when freeing the pgtables we need to unlink current vma from the vma list first: free_pgtables unlink_file_vma i_mmap_lock_write tlb_finish_mmu So it's not the same logic as how the RCU lock worked, but it's actually better (even though with higher overhead) because vma unlink happens before free_pgd_range(), so the pgtable locks are not freed yet (unlike RCU). Thanks, -- Peter Xu