From patchwork Thu Sep 28 12:39:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mimi Zohar X-Patchwork-Id: 9975915 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D9FFF60365 for ; Thu, 28 Sep 2017 12:42:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAC60295A2 for ; Thu, 28 Sep 2017 12:42:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF5BB295AB; Thu, 28 Sep 2017 12:42:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E18B295A2 for ; Thu, 28 Sep 2017 12:42:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753203AbdI1MmU (ORCPT ); Thu, 28 Sep 2017 08:42:20 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:41440 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753093AbdI1MmS (ORCPT ); Thu, 28 Sep 2017 08:42:18 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v8SCe61X114227 for ; Thu, 28 Sep 2017 08:42:18 -0400 Received: from e23smtp06.au.ibm.com (e23smtp06.au.ibm.com [202.81.31.148]) by mx0a-001b2d01.pphosted.com with ESMTP id 2d8wykbvwc-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 28 Sep 2017 08:42:17 -0400 Received: from localhost by e23smtp06.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 28 Sep 2017 22:42:15 +1000 Received: from d23relay07.au.ibm.com (202.81.31.226) by e23smtp06.au.ibm.com (202.81.31.212) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 28 Sep 2017 22:42:12 +1000 Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay07.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v8SCevRM34275536; Thu, 28 Sep 2017 22:40:57 +1000 Received: from d23av01.au.ibm.com (localhost [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v8SCevZG006819; Thu, 28 Sep 2017 22:40:58 +1000 Received: from localhost.localdomain.com ([9.80.86.128]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v8SCefS7006434; Thu, 28 Sep 2017 22:40:54 +1000 From: Mimi Zohar To: linux-security-module@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, Mimi Zohar , linux-integrity@vger.kernel.org, Christoph Hellwig , Linus Torvalds , Linux Kernel Mailing List , Jan Kara , "Theodore Ts'o" Subject: [RFC PATCH 3/3] fs: detect that the i_rwsem has already been taken exclusively Date: Thu, 28 Sep 2017 08:39:33 -0400 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506602373-4799-1-git-send-email-zohar@linux.vnet.ibm.com> References: <1506602373-4799-1-git-send-email-zohar@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17092812-0040-0000-0000-000003585AD4 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17092812-0041-0000-0000-00000CD95131 Message-Id: <1506602373-4799-4-git-send-email-zohar@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-09-28_04:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1709280189 Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Don't attempt to take the i_rwsem, if it has already been taken exclusively. Signed-off-by: Mimi Zohar --- fs/ext2/file.c | 6 ++++-- fs/ext4/file.c | 8 +++++--- fs/xfs/xfs_file.c | 10 ++++++---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/fs/ext2/file.c b/fs/ext2/file.c index 839095f66d8d..d174b2880929 100644 --- a/fs/ext2/file.c +++ b/fs/ext2/file.c @@ -38,9 +38,11 @@ static ssize_t ext2_dax_read_iter(struct kiocb *iocb, struct iov_iter *to, if (!iov_iter_count(to)) return 0; /* skip atime */ - inode_lock_shared(inode); + if (!rwf) + inode_lock_shared(inode); ret = dax_iomap_rw(iocb, to, &ext2_iomap_ops); - inode_unlock_shared(inode); + if (!rwf) + inode_unlock_shared(inode); file_accessed(iocb->ki_filp); return ret; diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 10789666725e..7d7c0e380add 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -38,7 +38,7 @@ static ssize_t ext4_dax_read_iter(struct kiocb *iocb, struct iov_iter *to, struct inode *inode = file_inode(iocb->ki_filp); ssize_t ret; - if (!inode_trylock_shared(inode)) { + if (!rwf && !inode_trylock_shared(inode)) { if (iocb->ki_flags & IOCB_NOWAIT) return -EAGAIN; inode_lock_shared(inode); @@ -48,12 +48,14 @@ static ssize_t ext4_dax_read_iter(struct kiocb *iocb, struct iov_iter *to, * change anymore */ if (!IS_DAX(inode)) { - inode_unlock_shared(inode); + if (!rwf) + inode_unlock_shared(inode); /* Fallback to buffered IO in case we cannot support DAX */ return generic_file_read_iter(iocb, to, rwf); } ret = dax_iomap_rw(iocb, to, &ext4_iomap_ops); - inode_unlock_shared(inode); + if (!rwf) + inode_unlock_shared(inode); file_accessed(iocb->ki_filp); return ret; diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index cf1ce8961601..0cffca97ed68 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -239,7 +239,7 @@ xfs_file_dax_read( if (!count) return 0; /* skip atime */ - if (!xfs_ilock_nowait(ip, XFS_IOLOCK_SHARED)) { + if (!rwf && !xfs_ilock_nowait(ip, XFS_IOLOCK_SHARED)) { if (iocb->ki_flags & IOCB_NOWAIT) return -EAGAIN; xfs_ilock(ip, XFS_IOLOCK_SHARED); @@ -247,7 +247,8 @@ xfs_file_dax_read( ret = dax_iomap_rw(iocb, to, &xfs_iomap_ops); xfs_iunlock(ip, XFS_IOLOCK_SHARED); - file_accessed(iocb->ki_filp); + if (!rwf) + file_accessed(iocb->ki_filp); return ret; } @@ -262,13 +263,14 @@ xfs_file_buffered_aio_read( trace_xfs_file_buffered_read(ip, iov_iter_count(to), iocb->ki_pos); - if (!xfs_ilock_nowait(ip, XFS_IOLOCK_SHARED)) { + if (!rwf && !xfs_ilock_nowait(ip, XFS_IOLOCK_SHARED)) { if (iocb->ki_flags & IOCB_NOWAIT) return -EAGAIN; xfs_ilock(ip, XFS_IOLOCK_SHARED); } ret = generic_file_read_iter(iocb, to, rwf); - xfs_iunlock(ip, XFS_IOLOCK_SHARED); + if (!rwf) + xfs_iunlock(ip, XFS_IOLOCK_SHARED); return ret; }