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 49AFFC433FE for ; Wed, 2 Nov 2022 20:51:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E5AAB8E0002; Wed, 2 Nov 2022 16:51:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E0AEB8E0001; Wed, 2 Nov 2022 16:51:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CAD5C8E0002; Wed, 2 Nov 2022 16:51:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B7EEE8E0001 for ; Wed, 2 Nov 2022 16:51:26 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 895C0121238 for ; Wed, 2 Nov 2022 20:51:26 +0000 (UTC) X-FDA: 80089697772.28.BCD4BD7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 2D70120004 for ; Wed, 2 Nov 2022 20:51:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667422285; 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=oR5BqgUdMPYHt7RBSvr6JxSAHZ0ghv1vkqRRC1Z5JNE=; b=NB3fWdzDoWWAaA3ejesPJB8GnaGtlp6NIB421Xitr+MV7/rD+xp3hN/LEvE7bndgfqHu92 Vn8pok2FEKrm7nHFWzfgPw2Jlm29Qkoi9cMuUvq00LcYTJXF4QOTQ6IQkafB0l3hqmX0po dy+I9L5F4kV1Ndt3UBvkrD0oJmmVH8I= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-183-qEeQW1fsMYWdkwmU8IekOg-1; Wed, 02 Nov 2022 16:51:24 -0400 X-MC-Unique: qEeQW1fsMYWdkwmU8IekOg-1 Received: by mail-qk1-f198.google.com with SMTP id o13-20020a05620a2a0d00b006cf9085682dso16243853qkp.7 for ; Wed, 02 Nov 2022 13:51:24 -0700 (PDT) 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=oR5BqgUdMPYHt7RBSvr6JxSAHZ0ghv1vkqRRC1Z5JNE=; b=qor/E/7ecEJo6U5MGWqqyVKOCJR5eld9pL4DEJaxtKsopM/gc2MBs6We9ygkYkcSC+ DaLnzzn4ioIqNewiWbouekm7WLnrx0GMHUrDTQ1NLUkvGoYyEbNOSeU/2wmWKL2FCABa u5/Yu7xVmjCPW3y2roWI86ynEgK7TAJnZ3u9WYNdvpKB3slPhPt8JVlcdOLJaOZuDV94 rSmldUcMDtqAd/ef3JKh0XfQ3AN8ljfHjpHPWX8tYpax3b7YadzlUH8COXpmD6ZowTz6 sXFDW+/XHay7b0dD1whXZSptvvxUccIrUCMbZuphDNFVyYzcEjA5p0GwK6QKWntyr03x Lk9w== X-Gm-Message-State: ACrzQf1eO1xNdKulmF5k0exLBQsqtA1hFsWMvcs1whCJqsyMkUfVN/7j uvvT52KyoKwS7Og9X2YM9tgcp41CrwLGLsZDT3GWTJEBmYHrMryQeN+XASImA9VLz242zurV6+8 UznOPmE+e0Iw= X-Received: by 2002:ac8:7493:0:b0:3a5:287b:d6c8 with SMTP id v19-20020ac87493000000b003a5287bd6c8mr13850211qtq.241.1667422283967; Wed, 02 Nov 2022 13:51:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5z0sDnzwMjh5BpqiSm0cjc6QcEARteCcLX1X6LhHxG+A3UaBmwN01/wAzwejujYQEP3qWbyQ== X-Received: by 2002:ac8:7493:0:b0:3a5:287b:d6c8 with SMTP id v19-20020ac87493000000b003a5287bd6c8mr13850185qtq.241.1667422283733; Wed, 02 Nov 2022 13:51:23 -0700 (PDT) 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 h22-20020ac85156000000b003a533886612sm3377442qtn.3.2022.11.02.13.51.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 13:51:23 -0700 (PDT) Date: Wed, 2 Nov 2022 16:51:21 -0400 From: Peter Xu To: Nadav Amit Cc: kernel list , linux-mm@kvack.org, Andrew Morton , James Houghton , Miaohe Lin , David Hildenbrand , Muchun Song , Andrea Arcangeli , Mike Kravetz , Rik van Riel Subject: Re: [PATCH RFC 02/10] mm/hugetlb: Comment huge_pte_offset() for its locking requirements Message-ID: References: <20221030212929.335473-1-peterx@redhat.com> <20221030212929.335473-3-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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667422286; a=rsa-sha256; cv=none; b=fFEu3scOwlIhuMikfkzEp/hvWlQaq1w09c33f/ip1LWLTLXs/TvS4FNbYYSSItxY8LzC+i 6y95muWkTlHO8vU54/qR7HG3w7tKhaEMVm/nhe0+NmGLN2IeV2vud+vP0TDsgOePz4N1jG 07o1Hxbam8l1cTHZmQLI4kmAOuMlUEM= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NB3fWdzD; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667422286; 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=oR5BqgUdMPYHt7RBSvr6JxSAHZ0ghv1vkqRRC1Z5JNE=; b=m/4lFcYiVgIIFL4zHUhq73jE4Z/rMZ8hc3aZD4WU6DmsDS98JgT2Bfm8GL5ZPU52IzqP+N KsbahgKUs2cd/jUpuEJjrh4s9wUlOZnnTobwJfgTaGoFJ9MFCbM4M7nnRRfhN42+zLvlG4 DO0TdgXKo+WQcLiDmjWXYjtt0k6P7kE= X-Stat-Signature: wozyif3ig45znr8h4f9rt1m1nfq915sz X-Rspamd-Queue-Id: 2D70120004 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NB3fWdzD; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com X-Rspam-User: X-Rspamd-Server: rspam07 X-HE-Tag: 1667422285-317830 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: On Mon, Oct 31, 2022 at 10:46:52PM -0700, Nadav Amit wrote: > On Oct 30, 2022, at 2:29 PM, Peter Xu wrote: > > > huge_pte_offset() is potentially a pgtable walker, looking up pte_t* for a > > hugetlb address. > > > > Normally, it's always safe to walk the pgtable as long as we're with the > > mmap lock held for either read or write, because that guarantees the > > pgtable pages will always be valid during the process. > > > > But it's not true for hugetlbfs: hugetlbfs has the pmd sharing feature, it > > means that even with mmap lock held, the PUD pgtable page can still go away > > from under us if pmd unsharing is possible during the walk. > > > > It's not always the case, e.g.: > > > > (1) If the mapping is private we're not prone to pmd sharing or > > unsharing, so it's okay. > > > > (2) If we're with the hugetlb vma lock held for either read/write, it's > > okay too because pmd unshare cannot happen at all. > > > > Document all these explicitly for huge_pte_offset(), because it's really > > not that obvious. This also tells all the callers on what it needs to > > guarantee huge_pte_offset() thread-safety. > > > > Signed-off-by: Peter Xu > > --- > > arch/arm64/mm/hugetlbpage.c | 32 ++++++++++++++++++++++++++++++++ > > Please excuse my ignorant question - is there something specific for arm64 > code here? Other archs seem to have similar code, no? Oops, sorry, I meant to add this to the version in mm/hugetlb.c. Or maybe to linux/hugetlb.h would make more sense. I should probably also mention that for any arch that does not support pmd sharing at all (afaik, any arch outside arm, x86 and riscv), the shared mapping locking rule should be the same as private. -- Peter Xu