From patchwork Sun Oct 30 21:29:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13025218 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 87193FA3743 for ; Sun, 30 Oct 2022 21:29:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 209E080008; Sun, 30 Oct 2022 17:29:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 16B6580007; Sun, 30 Oct 2022 17:29:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB50C80008; Sun, 30 Oct 2022 17:29:43 -0400 (EDT) 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 C6F8080007 for ; Sun, 30 Oct 2022 17:29:43 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A1890140149 for ; Sun, 30 Oct 2022 21:29:43 +0000 (UTC) X-FDA: 80078907846.13.2D3A53E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf20.hostedemail.com (Postfix) with ESMTP id 5DC191C0008 for ; Sun, 30 Oct 2022 21:29:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667165382; 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=JcZdgMzXcUClzXwFwvMe9vX/XbvITV8H0Y6t4On5idY=; b=BvcrJES4j0nILKfC76UaCHTgFjMycDrDv6w+C8IYnKZ4GiscdDrMn5DoIPp4LnPjV269aJ TNtaj4tsazvYdg4yX38rIlXNAIFg5xuOfXWzbFpuZs0RM2StwfpUiueU6YnzgGp1V+umc9 JAUSwPK7CFfnsHuhqM2Ou+fVRTtIwmo= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-351-ADNiyPdwPfWhKDvxdv6IEg-1; Sun, 30 Oct 2022 17:29:40 -0400 X-MC-Unique: ADNiyPdwPfWhKDvxdv6IEg-1 Received: by mail-qk1-f199.google.com with SMTP id w13-20020a05620a424d00b006e833c4fb0dso7976839qko.2 for ; Sun, 30 Oct 2022 14:29:40 -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=JcZdgMzXcUClzXwFwvMe9vX/XbvITV8H0Y6t4On5idY=; b=McaIixJjc/UgV8G6e5GIW8Gn7YNg89zrZp0Odrydlw8pMOPTqWDKANlJQkCGYVk1if 7WPLR6IsODZyXEdrK2yJAerY1qquqeP0Y4otCRAbGWxMaDSfgQcIX7NJH24adcPxVBq8 B6+4AvnXg0LHcuJiR1jfL+E5CWAWGmgbB7/5A5Jfw/KGXj7o97MyVQlfHU61am8zlxGu ZzgBHiLAkU5iGUF0srgkSaXyn/+seWvldkJOGpaWVpZJT2/giHFMMm6BmH2gmcmMFH1z 2fHnaAWlrgiy+gyF8SKGE1NCDu09G1jg2r9kZWkG/+jHtrW9+9ogOhMdtFFiX2dTIVd+ HvOg== X-Gm-Message-State: ACrzQf2XVsXQmnJs+Zwprht/gqRgMyLfHDLIwsquLWWqw/oHc9E9WW5i w1hD7c7IxRGiyfyQe2ZZJTg3S+FsU8B1IqV4xAvbLXTgpps60JMTmbdGzH0ViJLS87xfAf1wH6+ KEyL3LeUCk8A= X-Received: by 2002:ad4:5c4e:0:b0:4bb:9fea:f52e with SMTP id a14-20020ad45c4e000000b004bb9feaf52emr8476673qva.51.1667165380550; Sun, 30 Oct 2022 14:29:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7ZnJZXvFuDX4rJ/LrVQdDYcAIkIRly/xQ0vtJY1Rg+h8deNRU6tueG0RHxG/wRYLRwm8iB2w== X-Received: by 2002:ad4:5c4e:0:b0:4bb:9fea:f52e with SMTP id a14-20020ad45c4e000000b004bb9feaf52emr8476659qva.51.1667165380375; Sun, 30 Oct 2022 14:29:40 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Oct 2022 14:29:39 -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 05/10] mm/hugetlb: Make walk_hugetlb_range() RCU-safe Date: Sun, 30 Oct 2022 17:29:24 -0400 Message-Id: <20221030212929.335473-6-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; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BvcrJES4; spf=pass (imf20.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=1667165383; a=rsa-sha256; cv=none; b=kKDzQ6mdN2Gv9q8TjggUZXmsYX27FmPfNbOg1lD0u/qF7ZcvprVVxzhZq1jHXai93uTquJ MsGmVnb/yLsWZJXn2mmW/ynRFO9mBayX9Lag5rqePVDNUucQ59kf3Ff99XRhDPERDiVoGP kgTXXWq3kCZQhGNow6hIqYZdqN+gbjQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667165383; 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=JcZdgMzXcUClzXwFwvMe9vX/XbvITV8H0Y6t4On5idY=; b=ghC4zPMUT1ifPZKnmS26CiIC19oYe7vpcPQsB3H1jif37S/1y88I9mJyOQAfNu4lGy8IVm C/a3BVPrKWnM6jtbXZeg6b6Dxo5krYfYdamt7VD5wE9CsNsPCBGKKGKCHZ3F+z3ErFj2q6 ZujzBF7APDixSUTR6z8APq4NVDlLV7E= X-Rspam-User: X-Rspamd-Queue-Id: 5DC191C0008 Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BvcrJES4; spf=pass (imf20.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-Stat-Signature: dfqe48ori9eyewxt7omt8coc5j855771 X-Rspamd-Server: rspam10 X-HE-Tag: 1667165383-737625 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 --- mm/pagewalk.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/pagewalk.c b/mm/pagewalk.c index 7f1c9b274906..bbc71c750576 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -302,6 +302,9 @@ static int walk_hugetlb_range(unsigned long addr, unsigned long end, const struct mm_walk_ops *ops = walk->ops; int err = 0; + /* For huge_pte_offset() */ + rcu_read_lock(); + do { next = hugetlb_entry_end(h, addr, end); pte = huge_pte_offset(walk->mm, addr & hmask, sz); @@ -315,6 +318,8 @@ static int walk_hugetlb_range(unsigned long addr, unsigned long end, break; } while (addr = next, addr != end); + rcu_read_unlock(); + return err; }