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=-8.1 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_SANE_1 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 76AB1C47404 for ; Wed, 9 Oct 2019 15:14:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 375202053B for ; Wed, 9 Oct 2019 15:14:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="b1sQezSL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 375202053B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D23188E0006; Wed, 9 Oct 2019 11:14:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CD3A38E0003; Wed, 9 Oct 2019 11:14:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B9AC48E0006; Wed, 9 Oct 2019 11:14:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0021.hostedemail.com [216.40.44.21]) by kanga.kvack.org (Postfix) with ESMTP id 93E318E0003 for ; Wed, 9 Oct 2019 11:14:03 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id 3546252AE for ; Wed, 9 Oct 2019 15:14:03 +0000 (UTC) X-FDA: 76024591566.06.sail64_6317c3a33708 X-HE-Tag: sail64_6317c3a33708 X-Filterd-Recvd-Size: 5467 Received: from mail-lj1-f195.google.com (mail-lj1-f195.google.com [209.85.208.195]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Wed, 9 Oct 2019 15:14:02 +0000 (UTC) Received: by mail-lj1-f195.google.com with SMTP id m13so2853081ljj.11 for ; Wed, 09 Oct 2019 08:14:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=i5+F8lTtk0Euakn/RjiS7V/Gyf5iIdmbIbnkhbAYeuk=; b=b1sQezSLJ2RpHRT6G4RPpFNQ9QPWcbccuCz+q+XxR+aRGGya3h3HiebQHOKMqCV8Av KRFMjlIEMpRE8zpXTYAcDUO682DRTfznIM86/Wf8Lw7JuirqVcfggs2x1V7D1HCHAgVg tgBj2YXSfG9eaGuA9qsTLKLFP+ONR6Y6GScGSWQYnLYb/2mkSRN1lzgpRB9tPKcG+Rnr ONJbPZZTUQQ1xOjbyvYsrZVwp8vMAxcscwQ1/XgDbpIbpQaMKwOlhtUkvJPpQF6mq3VT L2ja+Bf3HNQzKolLib9YqCey4AvVnpMQOseDvlBIh+St5bVyQP59B+lfLVzIh4843QK/ 7BTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=i5+F8lTtk0Euakn/RjiS7V/Gyf5iIdmbIbnkhbAYeuk=; b=lI7vzVVbLKTrHUNI2HBMYZBQC2OVmox/jQAnJ0TcNW9E7AxaYcwybX1eaw6zZf90lh t5U6/y7bQoOgWyXku9oK/+Li8z6GRdcHCa6muJ36ZvhK5ATFjJOAJzB3LE5OZXZIHI85 PP2B0dTXt/xWQgX68gXnH5RKiVmMg8AOJ0k9U+Us5BSTt0VtsT5PVoN7JGWXcofZzmkv Tc2pMUqX+WHw9vgaTXk/qD2eBF1kokEYxVDzlWHS0Zf03DbnpaEpYf/+8ad7HqI2qI+2 XqcG/hGuUyzLpDoOe5jf6b6bA6Queh07iUJTwbZk/34j/An2euDo5BXg3ZUCy6nbfmGl 8yFA== X-Gm-Message-State: APjAAAVIlza+8lFMjvDi1gQS3elXIOcIR41Df9Uj/2eM2UCmSfrOhT/x 3W3Pan2O3fokPXn7/wO2QInMeA== X-Google-Smtp-Source: APXvYqzonBoG6yUhGVsnPYjcbe2zvWGkU0ePqWPljYB4I3KPXOX9/PxY9scZ4tjLKi0uvWWGIqsxiA== X-Received: by 2002:a2e:750c:: with SMTP id q12mr2662432ljc.138.1570634040984; Wed, 09 Oct 2019 08:14:00 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id w27sm525557ljd.55.2019.10.09.08.14.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2019 08:14:00 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id 7BDF8102BFA; Wed, 9 Oct 2019 18:14:00 +0300 (+03) Date: Wed, 9 Oct 2019 18:14:00 +0300 From: "Kirill A. Shutemov" To: Thomas =?utf-8?Q?Hellstr=C3=B6m_=28VMware=29?= Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, torvalds@linux-foundation.org, Thomas Hellstrom , Matthew Wilcox , Will Deacon , Peter Zijlstra , Rik van Riel , Minchan Kim , Michal Hocko , Huang Ying , =?utf-8?B?SsOpcsO0bWU=?= Glisse Subject: Re: [PATCH v4 2/9] mm: pagewalk: Take the pagetable lock in walk_pte_range() Message-ID: <20191009151400.bserdtpoczmawqn5@box> References: <20191008091508.2682-1-thomas_os@shipmail.org> <20191008091508.2682-3-thomas_os@shipmail.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <20191008091508.2682-3-thomas_os@shipmail.org> User-Agent: NeoMutt/20180716 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: On Tue, Oct 08, 2019 at 11:15:01AM +0200, Thomas Hellstr=F6m (VMware) wro= te: > From: Thomas Hellstrom >=20 > Without the lock, anybody modifying a pte from within this function mig= ht > have it concurrently modified by someone else. >=20 > Cc: Matthew Wilcox > Cc: Will Deacon > Cc: Peter Zijlstra > Cc: Rik van Riel > Cc: Minchan Kim > Cc: Michal Hocko > Cc: Huang Ying > Cc: J=E9r=F4me 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(-) >=20 > 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 a= ddr, 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 a= ddr, unsigned long end, > pte++; > } > =20 > - pte_unmap(pte); > + pte_unmap_unlock(pte - 1, ptl); NAK. If ->pte_entry() fails on the first entry of the page table, pte - 1 will point out side the page table. And the '- 1' is totally unnecessary as we break the loop before pte++ on the last iteration. --=20 Kirill A. Shutemov