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: 13061 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1972738wru; Sun, 30 Oct 2022 14:33:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7CXx/lZ/wdiMU3+jqU/yzLBzDmDUD2YgIcGGQ8iyfenRJGJLY4i/hwYxEmGSm6OMdocKfv X-Received: by 2002:a17:902:e8cd:b0:186:9efc:6790 with SMTP id v13-20020a170902e8cd00b001869efc6790mr11035117plg.91.1667165583467; Sun, 30 Oct 2022 14:33:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667165583; cv=none; d=google.com; s=arc-20160816; b=Xp6nYKidhsV+Fro9crvur3z63Yvd5W2zo5hK8BGdSwSznmEfxxj1MmmDPmRxC93VRT +84VNyZyycc4nUIvQ5K02m1C3cwLGMO1YCzPlDvlu7snmVy3Pw5WE/H+dNkMzH8Mg+Ff vsdy8ab63kO6/jRwGTQgzDOA4bcw+qeRenAAJGmTHZZ1mBMooAitWM9527C61TrUYS1C rz5+TFn9f4Ymu+t2t4N0LII6kW51R8xOb+xFtbXbDx04EABz2GPe59ly/Xs08ILThQAl lfpu8n5otEJmBSxURE/Wlq5ZwPDtuq9WGQUDugPl8HdK+NpKGoa6aavy7HcEpTJZGS2O lNEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JcZdgMzXcUClzXwFwvMe9vX/XbvITV8H0Y6t4On5idY=; b=uO0YJtUI4EpqSyUbEVaZjAQc3DyG00zIk4c45Baqp1cLEZXg7e2ayKESSDmt2QEY4x MmbP4CntKqgWVg2++78x0y8BUrnC4ssXHnkj6jzDbIVZzWhfaW77fD0qflFg9ePK/v4s tThUFgB5ResIBslyR32LGZ8PS3t7JW8nkYXulukRBsuPBK16+JdrwN/m+fWmdrL4tP8u Zy0ZZTQi7Erah+yT5GsI8brhjmkQA8h+rdckVv8dc0ysVo9hSLPwd3sWvmIXrRfEetqU XiU8NrodY8rTa5hqBdOMmfQrjJdJVc/rUa+BWojIRlXcLuXVzNLNVvhWjWnLQ///bnPJ m6oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BvcrJES4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e14-20020aa7980e000000b00565a581ecc0si5959864pfl.11.2022.10.30.14.32.51; Sun, 30 Oct 2022 14:33:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BvcrJES4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229849AbiJ3Vbk (ORCPT + 99 others); Sun, 30 Oct 2022 17:31:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229718AbiJ3Vbb (ORCPT ); Sun, 30 Oct 2022 17:31:31 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59241A45D for ; Sun, 30 Oct 2022 14:29:43 -0700 (PDT) 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-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-363-U_Hwj77VOKiPjB-qBt7nWQ-1; Sun, 30 Oct 2022 17:29:41 -0400 X-MC-Unique: U_Hwj77VOKiPjB-qBt7nWQ-1 Received: by mail-qk1-f198.google.com with SMTP id o13-20020a05620a2a0d00b006cf9085682dso7978019qkp.7 for ; Sun, 30 Oct 2022 14:29:41 -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=wNE2bsds37kZFN/8ELmdkj1XCw4gVEtqSw5PynUFxEKuMRKOBQOzN5jxVAKpg9Ohmt +GGFs0YosZJyzhPIKYFGHbVLLFxLKSGsDODqgji78UCF0H9zw2eIIbELIClPDcXKj+J7 jHGmXa+Be1d7oQLhGjo0tUBVGLRkQVAr/EVB28cVimr+kH7aM6k/n3lyD+Nl5cPilYjg qqz38z/NGzhJ3TsRj4x8ZopsN4nUyCt3jib66k8q5jldQG5bLquY8htA/nL9w7qv9Eow LO0+a2ye4OKvu8XreLf8DzMkN9dbxB/YGzxPh8hXm0U9VlChPaqBl58FlABh0vkBJEuk e7Vw== X-Gm-Message-State: ACrzQf1TQTQAAvE0dOzp2A2eOgb2dM4EyoHZbaAm+QECb/Pc6CavpqqS 7EI/KIk4JdZHqVAZwdLADjUCpS6ZZpq6wtV2IKu+7nkOenLT3wo+ga4eTBbRVt32k2RP/2HlA+k appNSnWYmfti+io/mNR93+xR2SvhgRxDSWZSSKKLYYTOxbAJVmiFT32M26sE00iXZQDmeci2o9w == X-Received: by 2002:ad4:5c4e:0:b0:4bb:9fea:f52e with SMTP id a14-20020ad45c4e000000b004bb9feaf52emr8476681qva.51.1667165380631; Sun, 30 Oct 2022 14:29:40 -0700 (PDT) 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 Content-type: text/plain X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748149818914580191?= X-GMAIL-MSGID: =?utf-8?q?1748149818914580191?= 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; }