From: akpm@linux-foundation.org Subject: [patch 046/115] mm/swap_slots.c: don't disable preemption while taking the per-CPU cache Date: Mon, 10 Jul 2017 15:49:29 -0700 Message-ID: <20170710224929.tu6g8j-V2%akpm@linux-foundation.org> Reply-To: linux-kernel@vger.kernel.org Return-path: Received: from mail.linuxfoundation.org ([140.211.169.12]:42824 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755038AbdGJWtb (ORCPT ); Mon, 10 Jul 2017 18:49:31 -0400 Sender: mm-commits-owner@vger.kernel.org List-Id: mm-commits@vger.kernel.org To: akpm@linux-foundation.org, bigeasy@linutronix.de, hughd@google.com, mhocko@suse.com, mm-commits@vger.kernel.org, tglx@linutronix.de, tim.c.chen@linux.intel.com, torvalds@linux-foundation.org, ying.huang@intel.com From: Sebastian Andrzej Siewior Subject: mm/swap_slots.c: don't disable preemption while taking the per-CPU cache get_cpu_var() disables preemption and returns the per-CPU version of the variable. Disabling preemption is useful to ensure atomic access to the variable within the critical section. In this case however, after the per-CPU version of the variable is obtained the ->free_lock is acquired. For that reason it seems the raw accessor could be used. It only seems that ->slots_ret should be retested (because with disabled preemption this variable can not be set to NULL otherwise). This popped up during PREEMPT-RT testing because it tries to take spinlocks in a preempt disabled section. In RT, spinlocks can sleep. Link: http://lkml.kernel.org/r/20170623114755.2ebxdysacvgxzott@linutronix.de Signed-off-by: Sebastian Andrzej Siewior Acked-by: Michal Hocko Cc: Tim Chen Cc: Thomas Gleixner Cc: Ying Huang Cc: Hugh Dickins Signed-off-by: Andrew Morton --- mm/swap_slots.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff -puN mm/swap_slots.c~mm-swap-dont-disable-preemption-while-taking-the-per-cpu-cache mm/swap_slots.c --- a/mm/swap_slots.c~mm-swap-dont-disable-preemption-while-taking-the-per-cpu-cache +++ a/mm/swap_slots.c @@ -273,11 +273,11 @@ int free_swap_slot(swp_entry_t entry) { struct swap_slots_cache *cache; - cache = &get_cpu_var(swp_slots); + cache = raw_cpu_ptr(&swp_slots); if (use_swap_slot_cache && cache->slots_ret) { spin_lock_irq(&cache->free_lock); /* Swap slots cache may be deactivated before acquiring lock */ - if (!use_swap_slot_cache) { + if (!use_swap_slot_cache || !cache->slots_ret) { spin_unlock_irq(&cache->free_lock); goto direct_free; } @@ -297,7 +297,6 @@ int free_swap_slot(swp_entry_t entry) direct_free: swapcache_free_entries(&entry, 1); } - put_cpu_var(swp_slots); return 0; } _