From patchwork Sun Oct 30 21:29:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13025216 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 3B5FBC38A02 for ; Sun, 30 Oct 2022 21:29:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DF0E78E0003; Sun, 30 Oct 2022 17:29:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D7C078E0001; Sun, 30 Oct 2022 17:29:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF3338E0003; Sun, 30 Oct 2022 17:29:40 -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 B2E5F8E0001 for ; Sun, 30 Oct 2022 17:29:40 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 88777AAB0E for ; Sun, 30 Oct 2022 21:29:40 +0000 (UTC) X-FDA: 80078907720.01.323F458 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 40B2318000E for ; Sun, 30 Oct 2022 21:29:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667165379; 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=wagvClDr96VqW50v7EvOelntcB2vHhVhi8l6aUJsy+c=; b=ew7FqRFPd5YS+Gzcrzv0V/2ob8hXdbkhwRtX9iXwDsDZhDzpRGw5gWyPgGlc70jn2DpTLh AkDjTMvvnaudRq7XOVPepOcA/2C59UUpMRONz1HmS/HJevRwzwvi4iMq0m702T8ov1cFmK hSJSGDKq7NZe1G0YX5b5XAsPEqM6wko= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-151-L1B2XG7nOBucz90uH26Mdg-1; Sun, 30 Oct 2022 17:29:38 -0400 X-MC-Unique: L1B2XG7nOBucz90uH26Mdg-1 Received: by mail-qk1-f197.google.com with SMTP id bk21-20020a05620a1a1500b006be9f844c59so7999375qkb.9 for ; Sun, 30 Oct 2022 14:29:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wagvClDr96VqW50v7EvOelntcB2vHhVhi8l6aUJsy+c=; b=arxG58fNDejEYbKCBdI5OaBa3lI14WtKvnPow5RyW/EgsK/sNmE4sX4oC6R5GNUwYI CqhN5bVksWolm8UO4Jf1PnR0TRjGDLNxjHCJp7ZgGbw6deV3rJoa2YENHkS1qr26FZz3 4Rcx3H5JcgZsWAUvX1rYh5L8GzbSz9ZW+lMBHWQ+w9C6PCyBBmXm/XB96OaoHVcRfSdV 6B30f7MxRn981tIxhZdKQ8wSvsFNeRAM8vV/wyi/ROc9hcwX+qemV/u4JQMt6vZXkSf0 emBlQxWC+cIT2VG142FsW4tBGlJDyjunpm/uZbZMpG7LDQ0fCRcZsglhTYIihFy2/cL4 UF1A== X-Gm-Message-State: ACrzQf0A1nOUlAXyMgTYVo4pRdxebhOk/HN3VxXx+mpfKazQEKQ1vbfe pq92Ufz7fFpaBQ1Ln9mzLD1NV0s7TVHz3q1YoqQX/K68QxREoUpgZCCSDZNNK18s6D68ha6ce/1 Bjt13i06keeE= X-Received: by 2002:a05:620a:270e:b0:6df:7dba:f45a with SMTP id b14-20020a05620a270e00b006df7dbaf45amr6855702qkp.661.1667165377621; Sun, 30 Oct 2022 14:29:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM43y+Z2mW0srzuBvDKmocMA3VgcwsAHhf82R+MjgsQxdn6rUm6xToTQeXJSbTLNoU9IYHY77A== X-Received: by 2002:a05:620a:270e:b0:6df:7dba:f45a with SMTP id b14-20020a05620a270e00b006df7dbaf45amr6855682qkp.661.1667165377401; Sun, 30 Oct 2022 14:29:37 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id a1-20020ac81081000000b003a4b88b886esm2654781qtj.96.2022.10.30.14.29.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Oct 2022 14:29:36 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , James Houghton , Miaohe Lin , David Hildenbrand , Muchun Song , Andrea Arcangeli , Nadav Amit , Mike Kravetz , peterx@redhat.com, Rik van Riel Subject: [PATCH RFC 03/10] mm/hugetlb: Make hugetlb_vma_maps_page() RCU-safe Date: Sun, 30 Oct 2022 17:29:22 -0400 Message-Id: <20221030212929.335473-4-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221030212929.335473-1-peterx@redhat.com> References: <20221030212929.335473-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ew7FqRFP; spf=pass (imf16.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=1667165380; a=rsa-sha256; cv=none; b=khxDZvEbqyH2t3roXG1DzES06YsGEw95U3yLu3zygLFe6P40k0r9np4sY/iRWeYa7rkzI1 mtTL3cVdg0r+dIMLo4VHqN930vqxDturiCQQf1m0tkr4VVCyLPPn7/77+Fh8D5yjYLrVmW BbfCCHrbJ+VyPmXov3Z1dlp0g4HDekM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667165380; 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=wagvClDr96VqW50v7EvOelntcB2vHhVhi8l6aUJsy+c=; b=Yob0Fj7prIrgMelSa+2hB6mdyLmjDIzyrzdTD3AaLPigqbW6rA+9N6rQQW7QdZAobxuQRv TuvF70j5dD9IhLyA12J+xuXH751sv2gBrg+XLm+hyqyG5jcvYPy497eRrMXUSGnvc/Mj4e wV5x3vASzVqCTs9b7qGY5czcoA4si3E= X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ew7FqRFP; spf=pass (imf16.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: rspam07 X-Stat-Signature: 76watknc759q4subpp7fpxah8u7gouy4 X-Rspamd-Queue-Id: 40B2318000E X-HE-Tag: 1667165380-511183 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: RCU makes sure the pte_t* won't go away from under us. Please refer to the comment above huge_pte_offset() for more information. Signed-off-by: Peter Xu --- fs/hugetlbfs/inode.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index ac3a69fe29c3..b9e7825079c7 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -387,21 +387,26 @@ static bool hugetlb_vma_maps_page(struct vm_area_struct *vma, unsigned long addr, struct page *page) { pte_t *ptep, pte; + bool result = false; + + /* For huge_pte_offset() */ + rcu_read_lock(); ptep = huge_pte_offset(vma->vm_mm, addr, huge_page_size(hstate_vma(vma))); if (!ptep) - return false; + goto out; pte = huge_ptep_get(ptep); if (huge_pte_none(pte) || !pte_present(pte)) - return false; + goto out; if (pte_page(pte) == page) - return true; - - return false; + result = true; +out: + rcu_read_unlock(); + return result; } /*