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 X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC68CC4360C for ; Thu, 10 Oct 2019 12:43:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 989BE214E0 for ; Thu, 10 Oct 2019 12:43:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=shipmail.org header.i=@shipmail.org header.b="FrkINqaN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 989BE214E0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shipmail.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0D3716B0003; Thu, 10 Oct 2019 08:43:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 00AFF8E000B; Thu, 10 Oct 2019 08:43:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E162E6B0006; Thu, 10 Oct 2019 08:43:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0117.hostedemail.com [216.40.44.117]) by kanga.kvack.org (Postfix) with ESMTP id B41596B0003 for ; Thu, 10 Oct 2019 08:43:42 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 5AD04824CA28 for ; Thu, 10 Oct 2019 12:43:42 +0000 (UTC) X-FDA: 76027841484.09.coal70_3d692da85ca0a X-HE-Tag: coal70_3d692da85ca0a X-Filterd-Recvd-Size: 4420 Received: from ste-pvt-msa2.bahnhof.se (ste-pvt-msa2.bahnhof.se [213.80.101.71]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Thu, 10 Oct 2019 12:43:41 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by ste-pvt-msa2.bahnhof.se (Postfix) with ESMTP id 888533F9B2; Thu, 10 Oct 2019 14:43:30 +0200 (CEST) Authentication-Results: ste-pvt-msa2.bahnhof.se; dkim=pass (1024-bit key; unprotected) header.d=shipmail.org header.i=@shipmail.org header.b=FrkINqaN; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at bahnhof.se Authentication-Results: ste-ftg-msa2.bahnhof.se (amavisd-new); dkim=pass (1024-bit key) header.d=shipmail.org Received: from ste-pvt-msa2.bahnhof.se ([127.0.0.1]) by localhost (ste-ftg-msa2.bahnhof.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VWP0wce9Z00i; Thu, 10 Oct 2019 14:43:25 +0200 (CEST) Received: from mail1.shipmail.org (h-205-35.A357.priv.bahnhof.se [155.4.205.35]) (Authenticated sender: mb878879) by ste-pvt-msa2.bahnhof.se (Postfix) with ESMTPA id B7F5B3F9A5; Thu, 10 Oct 2019 14:43:23 +0200 (CEST) Received: from localhost.localdomain.localdomain (h-205-35.A357.priv.bahnhof.se [155.4.205.35]) by mail1.shipmail.org (Postfix) with ESMTPSA id 134C636105C; Thu, 10 Oct 2019 14:43:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=shipmail.org; s=mail; t=1570711403; bh=xt6K1qPexhW5+7CwvPsIafay+fRiZP0wYtH6Fh+QJgI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FrkINqaNILpNgwmduymMcYIyCzxNuqG6EjcKLmBoNqw6kDFDvAX81c2NJRYJU7f+D qr2ZwCt9VnN8ks21TbYFmP2wtdsUWhTV9kggC7iBYpWOZiAGaAnVoPQkVURZQTolmx MRRmWbGMa1SuZ0GDjlf/h2kDLEmpBj62/P0p+hrI= From: =?UTF-8?q?Thomas=20Hellstr=C3=B6m=20=28VMware=29?= To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, torvalds@linux-foundation.org, kirill@shutemov.name Cc: Thomas Hellstrom , Matthew Wilcox , Will Deacon , Peter Zijlstra , Rik van Riel , Minchan Kim , Michal Hocko , Huang Ying , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= Subject: [PATCH v5 2/8] mm: pagewalk: Take the pagetable lock in walk_pte_range() Date: Thu, 10 Oct 2019 14:43:08 +0200 Message-Id: <20191010124314.40067-3-thomas_os@shipmail.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191010124314.40067-1-thomas_os@shipmail.org> References: <20191010124314.40067-1-thomas_os@shipmail.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: From: Thomas Hellstrom Without the lock, anybody modifying a pte from within this function might have it concurrently modified by someone else. Cc: Matthew Wilcox Cc: Will Deacon Cc: Peter Zijlstra Cc: Rik van Riel Cc: Minchan Kim Cc: Michal Hocko Cc: Huang Ying Cc: J=C3=A9r=C3=B4me Glisse Cc: Kirill A. Shutemov Suggested-by: Linus Torvalds Signed-off-by: Thomas Hellstrom --- mm/pagewalk.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/pagewalk.c b/mm/pagewalk.c index d48c2a986ea3..c5fa42cab14f 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -10,8 +10,9 @@ static int walk_pte_range(pmd_t *pmd, unsigned long add= r, unsigned long end, pte_t *pte; int err =3D 0; const struct mm_walk_ops *ops =3D walk->ops; + spinlock_t *ptl; =20 - pte =3D pte_offset_map(pmd, addr); + pte =3D pte_offset_map_lock(walk->mm, pmd, addr, &ptl); for (;;) { err =3D ops->pte_entry(pte, addr, addr + PAGE_SIZE, walk); if (err) @@ -22,7 +23,7 @@ static int walk_pte_range(pmd_t *pmd, unsigned long add= r, unsigned long end, pte++; } =20 - pte_unmap(pte); + pte_unmap_unlock(pte, ptl); return err; } =20 --=20 2.21.0