Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp5404531ybp; Tue, 8 Oct 2019 02:16:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqyZHOSuWoElIhovwHgsHF2bYY8+V6dUD/kan7JlHYgE8NppJSQHIsVh5VuJVyNxnFZgJbeC X-Received: by 2002:a17:907:4242:: with SMTP id np2mr27737954ejb.102.1570526176622; Tue, 08 Oct 2019 02:16:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570526176; cv=none; d=google.com; s=arc-20160816; b=BHWnQWfY9WfLw3Be9siw3eqydQ6mPHBgK+sQrLIsSyZXoGDgPYbiYeOk3F+2As1o08 kffGqDPl6EsX3KHDXgE5czTEqIKtdRSYJwoWLmTCjHPuAH++olJc8K/3vlwNm5oSagQl PhezwYIYxgV4YBp8bwiERaqHhmdoKaVDhquvNcZDOYjWTRuW5xTcORIhD6Tu/BjumZ4O DPR+MzZ0eVWYtEAEHhycnHMR2uPm9ihPsKxWPVnV8lOEysL/rbZmFpsfgbJ6C6ED4eb+ KyifF8c+mjLj5qlUjpDURwTC/L7XrQ55IWzbXXecSGzw467oFuFAuGgBPuLF+e8X5Bbm CraQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fTIhKKlUDhPpYjme5Tv/X2LJjSH5NTGVPpeGaklT3sU=; b=z1GVxdt9Rx6w+LC+2+y6+3/SONl5MAnTAPbacdJ0n/VXsLobiedWiFJWgRdXJMzJSY psYEQjPDcrhfVaZ/JqdM2O8B8fcVoiDdUGxkq0ZgCnQERYGTC5RJm/eFpp9SzofbJtHL XGMtAqKbG7AWeCiDfndQUOod554H1vOXLcEGm0tYXhJbkR0fQHmC4ap7TghKZ8FS0Amf sLsQ2oQCJ5GH7l7uwJyUouZbPzh6Jk0qc5pxG6PwZbPvY2I3RWlSvIggijaxLAFYuLqM Aw8Let0x2hHwC+EHhMwnj/aMaKSvoZ8FUdqeXHGkc7J8R1l3DcCgKmsOgum2k+32Cnno 0N8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@shipmail.org header.s=mail header.b=aHdlB1za; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z2si10531934edd.390.2019.10.08.02.15.51; Tue, 08 Oct 2019 02:16:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@shipmail.org header.s=mail header.b=aHdlB1za; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730199AbfJHJPe (ORCPT + 99 others); Tue, 8 Oct 2019 05:15:34 -0400 Received: from pio-pvt-msa2.bahnhof.se ([79.136.2.41]:56136 "EHLO pio-pvt-msa2.bahnhof.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730163AbfJHJPc (ORCPT ); Tue, 8 Oct 2019 05:15:32 -0400 Received: from localhost (localhost [127.0.0.1]) by pio-pvt-msa2.bahnhof.se (Postfix) with ESMTP id 365FC3F68E; Tue, 8 Oct 2019 11:15:25 +0200 (CEST) Authentication-Results: pio-pvt-msa2.bahnhof.se; dkim=pass (1024-bit key; unprotected) header.d=shipmail.org header.i=@shipmail.org header.b=aHdlB1za; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at bahnhof.se X-Spam-Flag: NO X-Spam-Score: -2.099 X-Spam-Level: X-Spam-Status: No, score=-2.099 tagged_above=-999 required=6.31 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no Received: from pio-pvt-msa2.bahnhof.se ([127.0.0.1]) by localhost (pio-pvt-msa2.bahnhof.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PK8-sFKECaEf; Tue, 8 Oct 2019 11:15:20 +0200 (CEST) Received: from mail1.shipmail.org (h-205-35.A357.priv.bahnhof.se [155.4.205.35]) (Authenticated sender: mb878879) by pio-pvt-msa2.bahnhof.se (Postfix) with ESMTPA id 0400A3F374; Tue, 8 Oct 2019 11:15:17 +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 7E8FC3605CA; Tue, 8 Oct 2019 11:15:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=shipmail.org; s=mail; t=1570526117; bh=fG/GNjL9xDuyikgbRDOUKbeudoZ9IgG6ULIdrU+mLBQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aHdlB1zax3KqHtdg+12GqQ4xe9oZhVhb/iGc5X6UYUyemkpWGmKCluj2cofgOkrXW kxRjrliinZnszyw+Eec2OClT+3OLJFNSQ8QLK9Mlwa6IBTYHo2i32L7z7Tvl5z2Eot ZrDcqiN6xpMBg0l1Z6nFYhbPQ3xjmUh5UbMINoAs= From: =?UTF-8?q?Thomas=20Hellstr=C3=B6m=20=28VMware=29?= To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: torvalds@linux-foundation.org, 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?= , "Kirill A . Shutemov" Subject: [PATCH v4 2/9] mm: pagewalk: Take the pagetable lock in walk_pte_range() Date: Tue, 8 Oct 2019 11:15:01 +0200 Message-Id: <20191008091508.2682-3-thomas_os@shipmail.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191008091508.2682-1-thomas_os@shipmail.org> References: <20191008091508.2682-1-thomas_os@shipmail.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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érôme 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..83c0b78363b4 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -10,8 +10,9 @@ static int walk_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, pte_t *pte; int err = 0; const struct mm_walk_ops *ops = walk->ops; + spinlock_t *ptl; - pte = pte_offset_map(pmd, addr); + pte = pte_offset_map_lock(walk->mm, pmd, addr, &ptl); for (;;) { err = 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 addr, unsigned long end, pte++; } - pte_unmap(pte); + pte_unmap_unlock(pte - 1, ptl); return err; } -- 2.21.0