From patchwork Wed Jun 21 21:21:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tahsin Erdogan X-Patchwork-Id: 779167 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3wtHts4jK0z9s4q for ; Thu, 22 Jun 2017 07:30:29 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="SYYS6/r3"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752136AbdFUVV4 (ORCPT ); Wed, 21 Jun 2017 17:21:56 -0400 Received: from mail-pg0-f49.google.com ([74.125.83.49]:33627 "EHLO mail-pg0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751875AbdFUVVx (ORCPT ); Wed, 21 Jun 2017 17:21:53 -0400 Received: by mail-pg0-f49.google.com with SMTP id f127so5480749pgc.0 for ; Wed, 21 Jun 2017 14:21:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IWx4ihyzm/xpBSeRb235Z54dITymRgsazVfafXRz0Ro=; b=SYYS6/r3FswsbphvpLOjwhtX67H9pevgdtEuDw+VlkyVRXHh9SIrx17hOwtKqcqy9K TRBdU97r2REdz5FG3LDMB5daZ/pXOglUnU/7xfdXBwg1txouAhC1kMe/XTCnYVkJFjJ/ GU34bv+HqoP294EiDNZ97sZftZRXvrpvri2QXW/dBin4yCRYQy9W3dmek3J9k5UobwA7 WMSFBuCuFljMjjDTI5l82ikTSj4oPwZayCPXCTJCi71z1ZCW6ou8LNvGc/lReUBd2IVO RlXLVCEWEm+sL+acSaFDqS4RKm7m25mhLnsrZ1hJTHECJ1oDrr8v16y32dVHFiv5EjFM H16Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IWx4ihyzm/xpBSeRb235Z54dITymRgsazVfafXRz0Ro=; b=MWaWg5d44zVa42Wi66dWHCQe/qOzmENbjHuumJOJnFBVgYulKoyD87rpBsaag9dnOu 51lPjseIYeWqydwIRzaLdv0y5VLaABHrRTR2f/iQK8oFxTkOjo/WXXboigMcqHBcW3LS ldrL9D+LCI0IPeKH5URhJo6kfvlyJOW5mbLUuJCJw1tgSYths3SmYF6O0ag8XJnF+TTa 823hRyhmT2TsD5+KMaGmgHriHHQ1QwJZZAwhrCFcQ8HprH6yINLJ7PDWEEYtOZBq548Z Uw/dFnwvxq9ktsDbqo6C4BGPfNju7uZYnvEkOgnL58AvwZy/1VdBF6kU+E7d7m32Hsuh A+Cg== X-Gm-Message-State: AKS2vOy3+VW342rwRUcomN4V+wR0Hy0x09Ut4Odt09ecjDuSotuXaF6D i2H8VhCJZuhuSOzP X-Received: by 10.84.196.131 with SMTP id l3mr12539556pld.62.1498080112354; Wed, 21 Jun 2017 14:21:52 -0700 (PDT) Received: from tahsin1.svl.corp.google.com ([100.123.230.167]) by smtp.gmail.com with ESMTPSA id s64sm1829980pfd.77.2017.06.21.14.21.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Jun 2017 14:21:51 -0700 (PDT) From: Tahsin Erdogan To: Andreas Dilger , "Darrick J . Wong" , Jan Kara , Theodore Ts'o , linux-ext4@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Tahsin Erdogan Subject: [PATCH 02/32] ext4: fix lockdep warning about recursive inode locking Date: Wed, 21 Jun 2017 14:21:12 -0700 Message-Id: <20170621212142.16581-2-tahsin@google.com> X-Mailer: git-send-email 2.13.1.611.g7e3b11ae1-goog In-Reply-To: <20170621212142.16581-1-tahsin@google.com> References: <20170621212142.16581-1-tahsin@google.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Setting a large xattr value may require writing the attribute contents to an external inode. In this case we may need to lock the xattr inode along with the parent inode. This doesn't pose a deadlock risk because xattr inodes are not directly visible to the user and their access is restricted. Assign a lockdep subclass to xattr inode's lock. ============================================ WARNING: possible recursive locking detected 4.12.0-rc1+ #740 Not tainted -------------------------------------------- python/1822 is trying to acquire lock: (&sb->s_type->i_mutex_key#15){+.+...}, at: [] ext4_xattr_set_entry+0x65a/0x7b0 but task is already holding lock: (&sb->s_type->i_mutex_key#15){+.+...}, at: [] vfs_setxattr+0x57/0xb0 other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(&sb->s_type->i_mutex_key#15); lock(&sb->s_type->i_mutex_key#15); *** DEADLOCK *** May be due to missing lock nesting notation 4 locks held by python/1822: #0: (sb_writers#10){.+.+.+}, at: [] mnt_want_write+0x1f/0x50 #1: (&sb->s_type->i_mutex_key#15){+.+...}, at: [] vfs_setxattr+0x57/0xb0 #2: (jbd2_handle){.+.+..}, at: [] start_this_handle+0xf0/0x420 #3: (&ei->xattr_sem){++++..}, at: [] ext4_xattr_set_handle+0x9a/0x4f0 stack backtrace: CPU: 0 PID: 1822 Comm: python Not tainted 4.12.0-rc1+ #740 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 Call Trace: dump_stack+0x67/0x9e __lock_acquire+0x5f3/0x1750 lock_acquire+0xb5/0x1d0 down_write+0x2c/0x60 ext4_xattr_set_entry+0x65a/0x7b0 ext4_xattr_block_set+0x1b2/0x9b0 ext4_xattr_set_handle+0x322/0x4f0 ext4_xattr_set+0x144/0x1a0 ext4_xattr_user_set+0x34/0x40 __vfs_setxattr+0x66/0x80 __vfs_setxattr_noperm+0x69/0x1c0 vfs_setxattr+0xa2/0xb0 setxattr+0x12e/0x150 path_setxattr+0x87/0xb0 SyS_setxattr+0xf/0x20 entry_SYSCALL_64_fastpath+0x18/0xad Signed-off-by: Tahsin Erdogan --- fs/ext4/inode.c | 2 ++ fs/ext4/xattr.c | 8 ++++++++ fs/ext4/xattr.h | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index e5535e5b3dc5..d095bf7ad390 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -4877,6 +4877,8 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) } brelse(iloc.bh); ext4_set_inode_flags(inode); + if (ei->i_flags & EXT4_EA_INODE_FL) + ext4_xattr_inode_set_class(inode); unlock_new_inode(inode); return inode; diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index 444be5c7a1d5..26d2705950a5 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -107,6 +107,13 @@ const struct xattr_handler *ext4_xattr_handlers[] = { #define EXT4_GET_MB_CACHE(inode) (((struct ext4_sb_info *) \ inode->i_sb->s_fs_info)->s_mb_cache) +#ifdef CONFIG_LOCKDEP +void ext4_xattr_inode_set_class(struct inode *ea_inode) +{ + lockdep_set_subclass(&ea_inode->i_rwsem, 1); +} +#endif + static __le32 ext4_xattr_block_csum(struct inode *inode, sector_t block_nr, struct ext4_xattr_header *hdr) @@ -830,6 +837,7 @@ static struct inode *ext4_xattr_inode_create(handle_t *handle, ea_inode->i_op = &ext4_file_inode_operations; ea_inode->i_fop = &ext4_file_operations; ext4_set_aops(ea_inode); + ext4_xattr_inode_set_class(ea_inode); ea_inode->i_generation = inode->i_generation; EXT4_I(ea_inode)->i_flags |= EXT4_EA_INODE_FL; diff --git a/fs/ext4/xattr.h b/fs/ext4/xattr.h index 6e10ff9393d4..e8bef79bdc38 100644 --- a/fs/ext4/xattr.h +++ b/fs/ext4/xattr.h @@ -196,3 +196,9 @@ static inline int ext4_init_security(handle_t *handle, struct inode *inode, return 0; } #endif + +#ifdef CONFIG_LOCKDEP +extern void ext4_xattr_inode_set_class(struct inode *ea_inode); +#else +static inline void ext4_xattr_inode_set_class(struct inode *ea_inode) { } +#endif