Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752808AbbHURp1 (ORCPT ); Fri, 21 Aug 2015 13:45:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34965 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751402AbbHURpV (ORCPT ); Fri, 21 Aug 2015 13:45:21 -0400 Date: Fri, 21 Aug 2015 19:42:55 +0200 From: Oleg Nesterov To: Paul McKenney Cc: Ingo Molnar , Linus Torvalds , Peter Zijlstra , Tejun Heo , linux-kernel@vger.kernel.org Subject: [PATCH v2 5/8] percpu-rwsem: make percpu_free_rwsem() after kzalloc() safe Message-ID: <20150821174255.GA17903@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150821174230.GA17867@redhat.com> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1359 Lines: 39 This is the temporary ugly hack which will be reverted later. We only need it to ensure that the next patch will not break "change sb_writers to use percpu_rw_semaphore" patches routed via VFS tree. alloc_super()->destroy_super() error path assumes that it is safe to call percpu_free_rwsem() after kzalloc() without percpu_init_rwsem(), let's not dissapoint it. Signed-off-by: Oleg Nesterov --- kernel/locking/percpu-rwsem.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/kernel/locking/percpu-rwsem.c b/kernel/locking/percpu-rwsem.c index f325672..3bb2dc9 100644 --- a/kernel/locking/percpu-rwsem.c +++ b/kernel/locking/percpu-rwsem.c @@ -25,6 +25,13 @@ int __percpu_init_rwsem(struct percpu_rw_semaphore *brw, void percpu_free_rwsem(struct percpu_rw_semaphore *brw) { + /* + * XXX: temporary kludge. The error path in alloc_super() + * assumes that percpu_free_rwsem() is safe after kzalloc(). + */ + if (!brw->fast_read_ctr) + return; + free_percpu(brw->fast_read_ctr); brw->fast_read_ctr = NULL; /* catch use after free bugs */ } -- 1.5.5.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/