From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750996AbdHMG1d (ORCPT ); Sun, 13 Aug 2017 02:27:33 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:35650 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750863AbdHMG1b (ORCPT ); Sun, 13 Aug 2017 02:27:31 -0400 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Re: [PATCH 4.4 18/58] mm, mprotect: flush TLB if potentially racing with a parallel reclaim leaving stale TLB entries From: Nadav Amit In-Reply-To: <1502473549.2047.36.camel@codethink.co.uk> Date: Sat, 12 Aug 2017 23:27:23 -0700 Cc: Mel Gorman , Linux Kernel Mailing List , stable@vger.kernel.org, Andy Lutomirski , Andrew Morton , Linus Torvalds , Greg Kroah-Hartman Message-Id: References: <20170809194146.501519882@linuxfoundation.org> <20170809194147.234463750@linuxfoundation.org> <1502473549.2047.36.camel@codethink.co.uk> To: Ben Hutchings X-Mailer: Apple Mail (2.3273) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by nfs id v7D6Rb6P024401 Ben Hutchings wrote: > On Wed, 2017-08-09 at 12:41 -0700, Greg Kroah-Hartman wrote: >> 4.4-stable review patch. If anyone has any objections, please let me know. >> >> ------------------ >> >> From: Mel Gorman >> >> commit 3ea277194daaeaa84ce75180ec7c7a2075027a68 upstream. > [...] >> +/* >> + * Reclaim unmaps pages under the PTL but do not flush the TLB prior to >> + * releasing the PTL if TLB flushes are batched. It's possible for a parallel >> + * operation such as mprotect or munmap to race between reclaim unmapping >> + * the page and flushing the page. If this race occurs, it potentially allows >> + * access to data via a stale TLB entry. Tracking all mm's that have TLB >> + * batching in flight would be expensive during reclaim so instead track >> + * whether TLB batching occurred in the past and if so then do a flush here >> + * if required. This will cost one additional flush per reclaim cycle paid >> + * by the first operation at risk such as mprotect and mumap. >> + * >> + * This must be called under the PTL so that an access to tlb_flush_batched >> + * that is potentially a "reclaim vs mprotect/munmap/etc" race will synchronise >> + * via the PTL. > > What about USE_SPLIT_PTE_PTLOCKS? I don't see how you can use "the PTL" > to synchronise access to a per-mm flag. Although it is a per-mm flag, the only situations we care about it are those in which “the PTL” (i.e. the same PTL) is accessed by both the reclaimer (which batches the flushes) and mprotect/munmap/etc. Nadav