From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751255AbdJCW1k (ORCPT ); Tue, 3 Oct 2017 18:27:40 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:56824 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750841AbdJCW1j (ORCPT ); Tue, 3 Oct 2017 18:27:39 -0400 Date: Tue, 3 Oct 2017 15:27:37 -0700 From: Andrew Morton To: Tim Chen Cc: Ying Huang , Wenwei Tao , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Minchan Kim , Rik van Riel , Andrea Arcangeli , Johannes Weiner , Michal Hocko , Hillf Danton Subject: Re: [PATCH 1/2] mm/swap: Fix race conditions in swap_slots cache init Message-Id: <20171003152737.c955053c04ee6ad9f70dc5eb@linux-foundation.org> In-Reply-To: <65a9d0f133f63e66bba37b53b2fd0464b7cae771.1500677066.git.tim.c.chen@linux.intel.com> References: <65a9d0f133f63e66bba37b53b2fd0464b7cae771.1500677066.git.tim.c.chen@linux.intel.com> X-Mailer: Sylpheed 3.4.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 21 Jul 2017 15:45:00 -0700 Tim Chen wrote: > Memory allocations can happen before the swap_slots cache initialization > is completed during cpu bring up. If we are low on memory, we could call > get_swap_page and access swap_slots_cache before it is fully initialized. > > Add a check in get_swap_page for initialized swap_slots_cache > to prevent this condition. Similar check already exists in > free_swap_slot. Also annotate the checks to indicate the likely > condition. > > We also added a memory barrier to make sure that the locks > initialization are done before the assignment of cache->slots > and cache->slots_ret pointers. This ensures the assumption > that it is safe to acquire the slots cache locks and use the slots > cache when the corresponding cache->slots or cache->slots_ret > pointers are non null. I guess that the user-visible effect is "crash on boot on large machine". Or something. Please don't make me guess! Which kernel version(s) do you believe need this patch, and why?