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 2C4A5C433FE for ; Wed, 30 Nov 2022 10:21:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B7BFF6B0074; Wed, 30 Nov 2022 05:21:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B053D6B0075; Wed, 30 Nov 2022 05:21:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 97EDE6B0078; Wed, 30 Nov 2022 05:21:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 837E46B0074 for ; Wed, 30 Nov 2022 05:21:47 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 390281C6A06 for ; Wed, 30 Nov 2022 10:21:47 +0000 (UTC) X-FDA: 80189717454.13.2E2D8C4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf02.hostedemail.com (Postfix) with ESMTP id 3A15F80014 for ; Wed, 30 Nov 2022 10:21:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669803704; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O5ATvP26yVV+R3lUMUH5z5/Q+n5P1qd+MA+woq6nwek=; b=FSDPhOEbW7AWiLqZGblDv71nRfpqtz4siQZWWSyAcK+N0VNCFApUQJUW6uK0mNlEzwWo1W SSbZWF/HAk7u15Vw7JlYGjZSqEEa26QP/Xa8lu17/AQVqifL99cz28mUXWreQQtGD30nNY jK8o97HYMxSvW7AAE+OkuM+4NEAW8xk= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-548-uWZ-7tgNOBGNbbEpSFW0tg-1; Wed, 30 Nov 2022 05:21:43 -0500 X-MC-Unique: uWZ-7tgNOBGNbbEpSFW0tg-1 Received: by mail-wm1-f71.google.com with SMTP id bg25-20020a05600c3c9900b003cf3ed7e27bso9185018wmb.4 for ; Wed, 30 Nov 2022 02:21:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=O5ATvP26yVV+R3lUMUH5z5/Q+n5P1qd+MA+woq6nwek=; b=fC9Hg8EXU0NBO49EzhS//KBKg5oNm2YeH0Ev0PK8x/TqY9U4z2Kzj7OmTGc0wua9gY 32DYexgvKnz+37OI3/prIDvO3fKT76O7Q2yU7A0rC9xCSnsbIqbFu0QIiN2JHB5o4TGY ty0S2Bo3/e4bpAyj9bM2A95T3ZK5Rfp9fAqY5/KGsuQlTNxsjQ8n9mv6VFG5LBgF3Ap+ 81tDsnvAIseOCfn25ka7UH3LU1JFrnPa1wMN6hV4TM17wlOafSSVfjE5Ds3DWARs4uH6 9FHEk4sqfVzKJQHFE3TARLvmG5E/7cSLfQWDyp7gHGuFKcQOyeUp0h5RtW4FgocLu4a0 g/cg== X-Gm-Message-State: ANoB5pkAX5j8yf446b8GIUwh+yyezge3wnffLeVMobYD+O0o1zeDiBr1 rMGolmF6NoLymhpDcyxQifkO6dBl0HvZPKnvwKZD9L/rw/bs7k1Q5HNAERE38ZqAEqjBgm0VpZL bV3cT1Gv8Hsk= X-Received: by 2002:a5d:628b:0:b0:242:26f0:d395 with SMTP id k11-20020a5d628b000000b0024226f0d395mr3327848wru.510.1669803701962; Wed, 30 Nov 2022 02:21:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf5guwVCW+BtHzSPu91RpZEmoDYmQ1ZVTA7NZdgSktSwlLqK3Z1u1RReeCVk0cLUdT051neAXQ== X-Received: by 2002:a5d:628b:0:b0:242:26f0:d395 with SMTP id k11-20020a5d628b000000b0024226f0d395mr3327824wru.510.1669803701619; Wed, 30 Nov 2022 02:21:41 -0800 (PST) Received: from ?IPV6:2003:cb:c703:7600:a8ea:29ce:7ee3:dd41? (p200300cbc7037600a8ea29ce7ee3dd41.dip0.t-ipconnect.de. [2003:cb:c703:7600:a8ea:29ce:7ee3:dd41]) by smtp.gmail.com with ESMTPSA id m21-20020a05600c4f5500b003b4fe03c881sm5563207wmq.48.2022.11.30.02.21.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 30 Nov 2022 02:21:41 -0800 (PST) Message-ID: <9bd6e57e-2c77-33f9-f9ea-7916b20ee6a5@redhat.com> Date: Wed, 30 Nov 2022 11:21:40 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [PATCH 03/10] mm/hugetlb: Document huge_pte_offset usage To: Peter Xu , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: James Houghton , Jann Horn , Andrew Morton , Andrea Arcangeli , Rik van Riel , Nadav Amit , Miaohe Lin , Muchun Song , Mike Kravetz References: <20221129193526.3588187-1-peterx@redhat.com> <20221129193526.3588187-4-peterx@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20221129193526.3588187-4-peterx@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669803706; a=rsa-sha256; cv=none; b=yhscG/aKDNQwE6LBMkcvVOKprJ7QAm51AVFmH0wuQdwSljSMrhvYu/+lQGbJWUM4tp+FR2 sX722qL4JU1l0MZhFFsQ5kVYx13z9IqoabymQpawEA5FnIjVrOiclfQID2u5JlD8mR0/qy l07aEE25pQgtsthPQ0hZiBouDnU2TWk= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FSDPhOEb; spf=pass (imf02.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669803706; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=O5ATvP26yVV+R3lUMUH5z5/Q+n5P1qd+MA+woq6nwek=; b=JhmZftNQtCZRfK7oftikllPRg9pX8rzBnYG4Q9uP00BEubXBvBEvsioA0tZAi3Npcvg5YG MErW37lZryN1O9vr+yvVnbmGa67K6Cx+Jz3mOOG63LUHi/ilAuzJAIuxcd7XdbR4mXxzbj 9cUDIUEgsQxbdjp7AbzgENd6drnjTr8= X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3A15F80014 X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FSDPhOEb; spf=pass (imf02.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: p6iarjn9q76khnw1wzuj9pwmnpa8my3f X-HE-Tag: 1669803705-521615 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 29.11.22 20:35, 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 a generic 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. With the addition, that it's only safe to walk within VMA ranges while holding the mmap lock in read mode. It's not safe to walk outside VMA ranges. But the point is that we're walking within a known hugetlbfs VMA, I assume, just adding it for completeness :) > > But it's not true for hugetlbfs, especially shared: hugetlbfs can have its > pgtable freed by pmd unsharing, it means that even with mmap lock held for > current mm, the PMD pgtable page can still go away from under us if pmd > unsharing is possible during the walk. > > So we have two ways to make it safe even for a shared mapping: > > (1) If we're with the hugetlb vma lock held for either read/write, it's > okay because pmd unshare cannot happen at all. > > (2) If we're with the i_mmap_rwsem lock held for either read/write, it's > okay because even if pmd unshare can happen, the pgtable page cannot > be freed from under us. > > Document it. > > Signed-off-by: Peter Xu In general, I like that documentation. Let's see if we can figure out what to do with the i_mmap_rwsem. -- Thanks, David / dhildenb