From patchwork Tue Nov 29 19:35: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: 13059092 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 223BCC433FE for ; Tue, 29 Nov 2022 19:35:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 560F48E0005; Tue, 29 Nov 2022 14:35:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 511BE6B0080; Tue, 29 Nov 2022 14:35:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2EEBD6B0081; Tue, 29 Nov 2022 14:35:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 1C0A26B007E for ; Tue, 29 Nov 2022 14:35:46 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id CD60FAB708 for ; Tue, 29 Nov 2022 19:35:45 +0000 (UTC) X-FDA: 80187484650.15.5383F48 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 5E3C640014 for ; Tue, 29 Nov 2022 19:35:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669750544; 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=tlgp91ck5zE/ROfq0OY9j8l1q/C3T3fwuEiiEDoRd8M=; b=PLmp9qAAVoXZ/DLCrhHauwbfIJ8eucPnqbLK/nRBJIKfSy2xRYyOfG9cpnvH4yNsOCxf60 ONlKONJCwUJht1zh2iZ82SSNfzcMDGnyIEYpeBPBqEMkp7MCCQCSIvZDQqthMmEHJpg43b 9OyN7osSfnd1FAHdBbWORvnupPB2HUQ= 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-372-hYxXIdGFNsisqjHvMTJYag-1; Tue, 29 Nov 2022 14:35:43 -0500 X-MC-Unique: hYxXIdGFNsisqjHvMTJYag-1 Received: by mail-qk1-f197.google.com with SMTP id de43-20020a05620a372b00b006fae7e5117fso30768615qkb.6 for ; Tue, 29 Nov 2022 11:35:43 -0800 (PST) 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=tlgp91ck5zE/ROfq0OY9j8l1q/C3T3fwuEiiEDoRd8M=; b=HgAM9ezP9m/1bF9tZSqTPfU+9+MN/6MA4bqHGwgxgViruFTHbmpdXZKFVMsgubrHEk y/hHGUreI/wg8fqDZQ5/xdqSkSjMRdpQ+3CQXxgteHJssuKk3tIg3+xzHef/6EqUPSr+ fqwCYK57I408Llxt5MRh3ujiPQd5ah4mF+txeo2YU2j9Bgj1cO8m6mHgDWwzv5Cdem8m O5Jd65UVFij6PLHLtNNhVaY91acdL34l98i3Ak48lHX24OFuQbwKOrPwFkkU67ZlUFtY 64aLn/XZYyzJiTWpRLXeTf9cW7/3oywD6vTs9P6xzJ1NKW9XlEB7sa9pYERJrm7Dty7S +eUg== X-Gm-Message-State: ANoB5plEp42nVpQ1p3YvoQwFg/mUrrPhvnBi/Y9KMY4OqXtSqjovJljc kPkJYC0LI/dCbETYCiiykYZjtp5rVF7sKDU29nXXBWlCDNk5oNIRwBtbgxMeMUjg8SK/gszU2tR ZeEfdmH+fwf4B1IyJ62Aa5mHuiPLtyBZyZinal8qOL4yWMxplt8wXvnlKh+Y9 X-Received: by 2002:a05:6214:3607:b0:4c6:fb3e:4993 with SMTP id nv7-20020a056214360700b004c6fb3e4993mr12852452qvb.110.1669750542569; Tue, 29 Nov 2022 11:35:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf4xmfsUZVgeiYSekMVU4CvYl69LMLxbBsqa8kFerZrz4PcOvOhvTZpsuJGzn4pvxETRAceDKA== X-Received: by 2002:a05:6214:3607:b0:4c6:fb3e:4993 with SMTP id nv7-20020a056214360700b004c6fb3e4993mr12852419qvb.110.1669750542285; Tue, 29 Nov 2022 11:35:42 -0800 (PST) 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 n1-20020a05620a294100b006fa16fe93bbsm11313013qkp.15.2022.11.29.11.35.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Nov 2022 11:35:41 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: James Houghton , Jann Horn , peterx@redhat.com, Andrew Morton , Andrea Arcangeli , Rik van Riel , Nadav Amit , Miaohe Lin , Muchun Song , Mike Kravetz , David Hildenbrand Subject: [PATCH 08/10] mm/hugetlb: Make walk_hugetlb_range() safe to pmd unshare Date: Tue, 29 Nov 2022 14:35:24 -0500 Message-Id: <20221129193526.3588187-9-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221129193526.3588187-1-peterx@redhat.com> References: <20221129193526.3588187-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669750545; a=rsa-sha256; cv=none; b=ww37ECfSUbnnr1fupMrzWqBpTeT1tUKMiUDBQ4U7sw8ZC+SK+zhAyfXvP9PLh6yOMWwsVG QeyfvM/s/GJmegiGdtbmWzWKQGZGUqdBS2G8R3RTMMSqizzH78Egs5sfbCucx9hYzT0aEw 5Z6s1/XA4yXin+ZykWEw9xex/s+X+q8= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PLmp9qAA; spf=pass (imf12.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@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=1669750545; 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=tlgp91ck5zE/ROfq0OY9j8l1q/C3T3fwuEiiEDoRd8M=; b=B/ZRh6W+AdRKSvmFhhYSf+ZfJLGVmqEEGDbE1x2KGhEU7+F0YHTx45fhUakXakfNDTsINb O/+G7BhL+QPedu+Nbmpfcd1SbjdarGMFr/x7QzUYDpXrxZi+jQBZ5iea9iGFXfy9ATSHMX lRtFtU4ZUojMEVGB7MfdJbdhR/O5VTc= X-Stat-Signature: fzmrabo9az71j8qciwyzqotq8yeduoiq X-Rspamd-Queue-Id: 5E3C640014 X-Rspam-User: Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PLmp9qAA; spf=pass (imf12.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam05 X-HE-Tag: 1669750545-290768 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: Since walk_hugetlb_range() walks the pgtable, it needs the vma lock to make sure the pgtable page will not be freed concurrently. Signed-off-by: Peter Xu Acked-by: David Hildenbrand Reviewed-by: Mike Kravetz --- mm/pagewalk.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/pagewalk.c b/mm/pagewalk.c index 7f1c9b274906..d98564a7be57 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -302,6 +302,7 @@ static int walk_hugetlb_range(unsigned long addr, unsigned long end, const struct mm_walk_ops *ops = walk->ops; int err = 0; + hugetlb_vma_lock_read(vma); do { next = hugetlb_entry_end(h, addr, end); pte = huge_pte_offset(walk->mm, addr & hmask, sz); @@ -314,6 +315,7 @@ static int walk_hugetlb_range(unsigned long addr, unsigned long end, if (err) break; } while (addr = next, addr != end); + hugetlb_vma_unlock_read(vma); return err; }