Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1056952ybp; Wed, 9 Oct 2019 08:14:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqyqrLOIwb/psvJbXTnVYNXGZK0TmegcNSHBxcrdsbomxwm0cRsOjsV6rQoWcqfIaByvQksk X-Received: by 2002:a05:6402:13c9:: with SMTP id a9mr3384448edx.141.1570634080844; Wed, 09 Oct 2019 08:14:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570634080; cv=none; d=google.com; s=arc-20160816; b=H23Q310U38QC5fX/SBVHKi6mlEysD1ZVfKeXvVm/Jn4UCEKcfPBQj9TFwoVEFfy+Dk OjHcDW3WJnH4rLH46BkPsR3AyCMCrrhhb5EcX/w4xppSXXvaxdmFuz7ENz7N7eSojeFo LaDLOnF7gspSaUJruknqohPMiVH8yVrOBHQoY0peiWUTSZOMVGrMI3P90afYLoXiECQo Z0D/14QS66HQYSIful3g5jPmbk/dBIKsUxVWMa/g1uKWlW5ANTPqKLTKY5Lul4LHNtea cLQ3m+mXEYYqsY4M/a+j6Ut0o6ohhiMwLxLUywzGTLuvxlF+WjVGC0J0te9yjPyeI7wU BDtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=i5+F8lTtk0Euakn/RjiS7V/Gyf5iIdmbIbnkhbAYeuk=; b=RqyCGohQWanzIZC8I7Mx0jhefkeeZgtz+ETWomgqQhB2rcfF4x1EvAQa4UFuGEOSns WtU4Pyu8dxo3QNQRRPApni41Jpj+X6Q0ksNWuGs1V3O2cfPJJtjS0x3A6gHxroaN/TNu mfthuzhOcpu5DYCUEHlxoctsuK2VJwhrbv3exZrapH60igApMOMkB32RApXlR8t09+60 svGVIIAEUda2pqtKu+5/mCtMilNpq9u8J648iL+WevJtVHlwG+9J7kjB6GHA+7VPzbaY UKVOc05RuJ7zRxw3GjZGkW0Og9P/RP2eAWx3QQOQ5AOkGyZRlmBTPHKLyyQiBvSMAysD 4qZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=b1sQezSL; 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 x15si1569146eda.53.2019.10.09.08.14.16; Wed, 09 Oct 2019 08:14:40 -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=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=b1sQezSL; 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 S1731451AbfJIPOE (ORCPT + 99 others); Wed, 9 Oct 2019 11:14:04 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:35161 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727920AbfJIPOE (ORCPT ); Wed, 9 Oct 2019 11:14:04 -0400 Received: by mail-lj1-f194.google.com with SMTP id m7so2918978lji.2 for ; Wed, 09 Oct 2019 08:14:01 -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=SPJDzYGZ9zagAEmXWUkO21MaUUAhd2jtw/JbDWDaLVdDStt07X11Be456YZNPiNsPz CaHRIx8b6kv0al+/VfkMA7FPj0HBIyjcmLz9p8NxfChSimFgSfsoSiogCTJHmLSMBpFq PqEWZSTdxnBQZKCGs6ucuKTb5j/aizDE/o9nhH+CFz+JNGpGRGPCVJMBvkyfWoGwqbbk Zr4S7zCuNBeahb8K8uHkSsVtad7aTCVhXdGut76R7vv713fl/sXHwTgt/FStd0cSDEBd 6yS6uQPr59vqFgPGvYN8zYD+7nx7f9K2O+Vib3idgNXGNVfVzKtFpL82rhpd/KRhGa2I GtRA== X-Gm-Message-State: APjAAAUka5zmqF9a+3wzOgbwyHIl4ngcovfmFiokWImueEVDP31KBBL3 KoerRtY8fxWNn45GD7q+27n2Yg== 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 Content-Transfer-Encoding: 8bit In-Reply-To: <20191008091508.2682-3-thomas_os@shipmail.org> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 08, 2019 at 11:15:01AM +0200, Thomas Hellstr?m (VMware) wrote: > 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); 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. -- Kirill A. Shutemov