From patchwork Fri Oct 28 00:10:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13022933 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37910FA373D for ; Fri, 28 Oct 2022 00:10:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234966AbiJ1AK3 (ORCPT ); Thu, 27 Oct 2022 20:10:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234486AbiJ1AK2 (ORCPT ); Thu, 27 Oct 2022 20:10:28 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CE84399E2; Thu, 27 Oct 2022 17:10:27 -0700 (PDT) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29RMO7DV005927; Fri, 28 Oct 2022 00:10:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=uAk8pfIJ76/2yrFkZVr67deIRBkVUSRheZsGQTQYEng=; b=XrpZhYJux/04IUQeXkCJEKXKf8oIE9hZdVf/Fmr1zNLgMVZJmDqdJka2AwoqMoI8x1nY Hk1+Fvy+WFEZuOI5ocFXzNalvjssIdidDKy22TWwja6gHt42UE8wKF+NQKOGeylW7yiR rSiFJiJzS7iCzLTm1aaJADBL+1GDnRoreivEjlcO5nanlTxxtYBsjuX+Dbgg6aSF9ZL6 DiiUE+WoXwEN6hH2A73d3oaZgoSRf22IfXX9kIlQA24awlJWvUPdxX2gaRxFUsL1g1xH /KVEOq+MyZ+bK6cmirHL+SWIZTc6i16FHQnLFbdIOqMKo9wPfFZVemXJeU0xzJcb5g+M EA== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kfax7uh77-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 28 Oct 2022 00:10:24 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 29RLoWmc006786; Fri, 28 Oct 2022 00:10:23 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2107.outbound.protection.outlook.com [104.47.70.107]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3kfaghgy1n-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 28 Oct 2022 00:10:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cKUZjYy9RtVT42VEH8FHmF/QwgABsy+t5P87O8sKrSLr2rXdhIPO0jndrP4d7hzF3nYmzM2NsQqRnmMYPeQ3myjD/4VsVxiRPNKO3KunykxKh32UU2MeQ4mfbHjrodxCIEC1amtn41LZSpUXenOmbne3cHOBNSVCfXHwjujCReSOZfk9hplHwJTjZkKjYD2GqCRB4kubtMEsE3Hkor2B3RAtLIla2BpUZOuZKpWYgtv5Y5Mq7wv/QJd13zoeLsGNNka5ru/HM9+BwZjzl8FpZwhDBxSoek5q7JDlNb8oHL18Kct+DLL7XFLFipHqd0OWR6WwmEZvbRZyyF8k8JG+GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=uAk8pfIJ76/2yrFkZVr67deIRBkVUSRheZsGQTQYEng=; b=nYvjGczqlgt87QM5ITNaEgZx6T2k2YqOH0wsXk90Xby+c4WqlxKBhYMcZY8KdR7JQE6Lcw5XRyKxFCBXKuxYDPO5scHD2OVY08iMvcGiZQTGsg/ixJI52pH0ATPPNUiU4Rhx1afTuzGEX6CrWJ4TP9DOewHBCGPwX5Oc9l/+J8ja5SScdYqUWgV0i+4Va29qeAXqXrWK3M9rQHZgC9VDIq1HFiS2zyivis3I2/PJ6dfq1Htftg6dyOvE7D9jEy1QZmRHv/mgQj4C/Dqi8a3wjdzFdSk1ounGTnS15OIM98nW6UrfKWMIMIf9AXCja14YOlv18O44N0X/4edH1G9eQg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uAk8pfIJ76/2yrFkZVr67deIRBkVUSRheZsGQTQYEng=; b=eN0AjG42t7nDVjH2rycmY9n5XfRc+l0V5CdEIwfli4u4pjM5Vv+jmvbL+Phab5b5d3iV0D2Iw309Pv/4ZKmM04Gzh0XxiVjaKdFmYTbtREIzEivWPvhXpwRm3EkjOXUeZXzhUA6MmxtiWFuVJmMhphcQefqCWQS3qtPu9od2dC4= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by BY5PR10MB4130.namprd10.prod.outlook.com (2603:10b6:a03:201::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.14; Fri, 28 Oct 2022 00:10:21 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::36b6:3767:c15f:3b24]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::36b6:3767:c15f:3b24%9]) with mapi id 15.20.5769.015; Fri, 28 Oct 2022 00:10:21 +0000 From: Stephen Brennan To: Jan Kara Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Amir Goldstein , Al Viro , Stephen Brennan Subject: [PATCH v3 1/3] fsnotify: Use d_find_any_alias to get dentry associated with inode Date: Thu, 27 Oct 2022 17:10:14 -0700 Message-Id: <20221028001016.332663-2-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221028001016.332663-1-stephen.s.brennan@oracle.com> References: <20221021010310.29521-1-stephen.s.brennan@oracle.com> <20221028001016.332663-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SA9PR10CA0005.namprd10.prod.outlook.com (2603:10b6:806:a7::10) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PR10MB4166:EE_|BY5PR10MB4130:EE_ X-MS-Office365-Filtering-Correlation-Id: 06abef69-40cc-4006-9928-08dab878cde3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hOPepynYaFh3bM3Y4zBti4imCLZ1il7c/d5YtVHXcZfsQevoeJKFAw/Q2ceYXEbu8x7kF+/LIjJ50F6O+vXl8ClQLorNwA+CLtchVQIh0MTqeOp3T5G1RDVXyW1GpL3nGheQDGVmBVBb7L3gz1yGf1YeBJbOP6Ld8RJGGSvCnSrqKulhNFTp2YQID/1iNX75eMHpxuhGP94V990/4wC39E3tsxgGKzw4ld/GptPu5/uH4yyOUY96QqCZt9WW95/iWVV34OQWs34freXnXx9BXHcmUrRNyayLZ7mISs+ADPUMbtx3DpmwxOQ9GLXD7ZiTXOUbwgGmRNdhTQVdaEZDquAQsIGKX1laSPCb9+5oTKzzEh/bfdb8m0USF8Y8p53Om6L70tkjQkOt3g46/zVZf/KPKK5JUtvg/ynsjQ2ZXoR1n8UaCypK4wzj5iTyIHeZXNxZYRHnIKZqD6RXOv7iyXv7YyPfAFaROwNSslIayOmbYb84yMBpveVdsd+4VqxVgD6ouXyeMAgnf0zPNT98HlVqR4tfrcdRnmOQcs6htu9fVLppZfCbevjtDZRdW3FGaiaqrmVvbKuK/X/8UW3Pqkn9JvObUUFJ35tSxeZ1H2Zh0pkqKHTyu89+45XbyAWCO8C+dyF9FnlJ9HxvrANxUVWcS4vGlQZ8pUbNPo7G2nQjxafUGbrR+18g2Tz3AzeWGxw8Cuzi9KMayVPx3T78LQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR10MB4166.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(366004)(376002)(346002)(39860400002)(396003)(136003)(451199015)(83380400001)(103116003)(36756003)(6486002)(107886003)(6666004)(478600001)(5660300002)(66946007)(4326008)(8676002)(66476007)(8936002)(66556008)(41300700001)(54906003)(6916009)(316002)(6506007)(1076003)(2616005)(38100700002)(186003)(6512007)(26005)(86362001)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: R4GIVdsoJcOm9zRoFzpC7Ev6D3IdrZxLwXTmfWzJ5n+zV55l8+P0RIzvTmrq7uiwXwwibbRNi1AmjNe2NK/3qoN+QRgzFoW8/uaBwUupqzY370wcpgNi2DU0YOia76GcwjHHzFuPV25f+51cYMKGSmfsLmsY9p/PAH9KhIoWCVogo/gUSVKfKN1lT0tdX8mcRTYZLepqQY1pGyh02TxEaVauTvfsiz2kF1xGbYZyWrPURWKnaFoZHk17peaU65ew7JaywI7NK/VNA2ClcyeS+km+0RCEE12HhVqY6krE2QHyW5cArnAq6XmJSo4wYb7nOzhSEfuptkaoMhB2DTO3LM/tlmEZ9M6/D8D3k5OQglfCx5gy4kCqlcK4CgTONyfoClsnJClc6il+5kyzxfZxzgzhTGLNW0zr5iByLtjASGcR1Wpq1nVl5JoCf7FIt8RFjIEdW94qykQ2BMj60Q5Zlm93R4qkC6fQfwPr5cckbDHzGhXuFb4v8B5BeqNRGb/lzsnyc1DRnzBQXPvdLKF2ilo4y42NI+NjiBHdl/KTAeeIdiqBJbYshVx9+s7AgxzkZ4X198dkJuijON6zyftwKUEf2uBVK2EhWCIvN/4uifd3HAmPopQ8hIzXSZoqO2j5/l3BMrNlGy6SsjvBV60a3Pkwim04Y0mpkWRkK4qJqIro+82hsbxtNAbgGAAjQ48ZVmFu7sRfmZnjJaUU//LFQXX3OTwB6JuWxbWHIbczpSRSqu7LdiCUtW1bRGaNjWA9KNADDFifdkEyjdhoNx1La8pKoFX+UhYup8yJPJV9alYTFgASSg/htGp19ihpjMVm+wq8x4SxCNYgjK26y0OFGauzoTg8rqAIOzFxFcZDlg0bzdGmtUmxdEf/qiDCNGvTcQ310lw3w9kJwYtJaJyAxJGKfeqaSAcZMW+nzg/GgR+KZVViYnv9EzlOw9wHxRrPTKViXyKE6gcBotr2xdUVlx5FzHY9SAZzhNrYz1Re6hjfHwrp5lNcawEoRv8SoJJqc/pQeM1bpvNyLDq653MaWQiu+hCNQsXOfXlJ5g1BUUbIbPQEhT7aCIzxplyC83KpzV0GxCkpw3t4NGTmjCRyDAz8jcGw/B1YOkQPCYzF0d6Pgt5Zt7NkOi4GpuLqdPHOIbwMk/5nLH2/WZgI6hG5ZLdpAcRVowVykfMr9/9+eIZPKSIrE36NhI4c5j0ujrg2lz3ucbvLI3d5sfi1yJS/La/DcE8UgkCHuPWBBRmdusz8B0WYSVF9hRjeShD9wHO0+yrkilZd6UIq3K74eXOs7nAneqkt16H6bM5hn/jF+dzkfMKN6e16tl+gJZAWDVbwzJ11N4OhidN09bBAE3FtE96O6iCTFgG3uO6/BtKBiyt9ls9uZ2dp4ZAg0H4QtIfHZ7R3UwriB2urIwRxqQaUNPFjJRP9UzaEGoXpdApSCqmNlxLSGxQeqWiTxOg3MzkZ5I/LVoy5907fdOzRkkPpy0lzSULHCmkmf1aK6zuIh6ZJ+5TEKq7JzN1zgaZwqGQNitIlO+aWa5Q8xzP48toqsGdcp+kD8S/QQhduduCPp8VMgcDMLysbkZyOCfwnhNO7C6KWyXFj/K1BBzfwrEN9NQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 06abef69-40cc-4006-9928-08dab878cde3 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2022 00:10:21.7271 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: e8CrQA9GjshPQSaPBSVkftVrn4LeIpERbOFOF9kiNYxMhfM6eos49UD6vPi0dFvyRDnpZawf2/oZDrtcVIv5BiPWYV3pL6omXcvfXuZSOag= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4130 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-27_07,2022-10-27_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 spamscore=0 suspectscore=0 phishscore=0 adultscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2210270138 X-Proofpoint-GUID: ANc5DvF5V0BLuRgOqDpScrOlFyCKTUPs X-Proofpoint-ORIG-GUID: ANc5DvF5V0BLuRgOqDpScrOlFyCKTUPs Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Rather than iterating over the inode's i_dentry (requiring holding the i_lock for the entire duration of the function), we know that there should be only one item in the list. Use d_find_any_alias() and no longer hold i_lock. Signed-off-by: Stephen Brennan Reviewed-by: Amir Goldstein --- Notes: Changes since v2: - Add newlines in block comment - d_find_any_alias() returns a reference, which I was leaking. Add a dput(alias) at the end. - Add Amir's R-b fs/notify/fsnotify.c | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 7974e91ffe13..7939aa911931 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -105,7 +105,7 @@ void fsnotify_sb_delete(struct super_block *sb) */ void __fsnotify_update_child_dentry_flags(struct inode *inode) { - struct dentry *alias; + struct dentry *alias, *child; int watched; if (!S_ISDIR(inode->i_mode)) @@ -114,30 +114,28 @@ void __fsnotify_update_child_dentry_flags(struct inode *inode) /* determine if the children should tell inode about their events */ watched = fsnotify_inode_watches_children(inode); - spin_lock(&inode->i_lock); - /* run all of the dentries associated with this inode. Since this is a - * directory, there damn well better only be one item on this list */ - hlist_for_each_entry(alias, &inode->i_dentry, d_u.d_alias) { - struct dentry *child; - - /* run all of the children of the original inode and fix their - * d_flags to indicate parental interest (their parent is the - * original inode) */ - spin_lock(&alias->d_lock); - list_for_each_entry(child, &alias->d_subdirs, d_child) { - if (!child->d_inode) - continue; + /* Since this is a directory, there damn well better only be one child */ + alias = d_find_any_alias(inode); - spin_lock_nested(&child->d_lock, DENTRY_D_LOCK_NESTED); - if (watched) - child->d_flags |= DCACHE_FSNOTIFY_PARENT_WATCHED; - else - child->d_flags &= ~DCACHE_FSNOTIFY_PARENT_WATCHED; - spin_unlock(&child->d_lock); - } - spin_unlock(&alias->d_lock); + /* + * run all of the children of the original inode and fix their + * d_flags to indicate parental interest (their parent is the + * original inode) + */ + spin_lock(&alias->d_lock); + list_for_each_entry(child, &alias->d_subdirs, d_child) { + if (!child->d_inode) + continue; + + spin_lock_nested(&child->d_lock, DENTRY_D_LOCK_NESTED); + if (watched) + child->d_flags |= DCACHE_FSNOTIFY_PARENT_WATCHED; + else + child->d_flags &= ~DCACHE_FSNOTIFY_PARENT_WATCHED; + spin_unlock(&child->d_lock); } - spin_unlock(&inode->i_lock); + spin_unlock(&alias->d_lock); + dput(alias); } /* Are inode/sb/mount interested in parent and name info with this event? */ From patchwork Fri Oct 28 00:10:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13022936 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B44D8FA373D for ; Fri, 28 Oct 2022 00:10:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235216AbiJ1AKu (ORCPT ); Thu, 27 Oct 2022 20:10:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234811AbiJ1AKd (ORCPT ); Thu, 27 Oct 2022 20:10:33 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92DF33ED6A; Thu, 27 Oct 2022 17:10:31 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29RMOJIh007722; Fri, 28 Oct 2022 00:10:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=pStEeV/8oUEZKkb5r4ne5L2BPTh6o3Ej2omKROBzmdw=; b=NHw+qPYqEBGI1V8ki5IX/hkJfQWp+bWiCYROGbCsBQ/P8VuZOHoJc/Zl9hzahajJN3Pv taCOXIz3XvW5HPPIreNRHK5bIyXitDQQpOA2fCgQWqoq5LlCSTL0vqMQbEnE5U5Rl33o ytB9to0SqVutM7gxLK7qElKjWVAgFtC8HYL0gnxta7RdupjB6iivDcePxw18L/K0b9eB dQnJLmr6McxNBDDD5n629rBLTOXCWUGMrdsN9wYFd5kjcfODr9t4CWqiETpI12hMFycT FQIySxuuNTyT2PMRYyWXauP8sTM+HDkRaccSRVRXE6gGdxUP7QFPlaWjlRV7SMsk+wKL 1A== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kfb0akq5v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 28 Oct 2022 00:10:27 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 29RLahii026367; Fri, 28 Oct 2022 00:10:26 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2108.outbound.protection.outlook.com [104.47.70.108]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3kfagqj1vs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 28 Oct 2022 00:10:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MLTp4PSQs5hENakqA6QSpbziD6X1ZR24T23Gwinh40QsBEBYfKMbgsRsHa73UvyLaH1Few7NCH8ywTi0qWb6Kdk1+/gCmPeHiwklwaNfhBL07hEXmJX/uHCfosdmOQf/OHf4lclDJp3Gu9lAs24bVJQS+jSG0n9bJPZ79tvAbXi932U4eEEJS0GEoUp10DDRwH7pLcuSGAUiLSkGddaJ4fIQMDwcqlxSKYKMSxSIZl2nJrpPy99qaulx/qSDSw+gfKE5IuYflqlgJe8q8olUN+2Voc8foWFZBx8oISyBP6azJKQ5mi/3zfk4AXb+yxWEEjEU9px907lDSPblsWn/PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pStEeV/8oUEZKkb5r4ne5L2BPTh6o3Ej2omKROBzmdw=; b=dHxZCxJu9yEqRDS5JGV2Klow7KpPug972CN36Ub24UVg2sqtA8lbnUA1369A5e41D4YK6qvGLMVwxvZe6E4myBm/zxObrI3iSyzN/sAOkF2+jKxnZ1fmbcnFg69bve5OeH5WCq88dadkS04cpKMedPUtb4Cqw1DQ4m/+Y75KvyJA48MD9sfSYwJ1cCAnExJxjeUx0QFk2n8uU0jM2fpeemGHtORBz2M/u0//K7+aSzmLl/FVyDJMWC+dYrx1fgGJe0ZwFwEG6vBasYgx/oCYDpbvE0iISdAnLo7GdUEEPZNDLmE1aifLCAmsVsmqMpOYsY0zV8VlovEdfUcR52O2zw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pStEeV/8oUEZKkb5r4ne5L2BPTh6o3Ej2omKROBzmdw=; b=Uv+qu7BeDo1AcyiYdzlqIn98q8xRCzjSMg1Wg0roUSfXwdPz/1Sl1DiOUVQeAMisvk8EumzI9Cx8q2cbJ7QDQwfL36oilAAyB35vM423yBJBkZnkn7GJJywYDZxdfPNawVF2iE+0bIvAtMdIRBVWvyTfwz/5nNgrOH0g1QETe+g= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by BY5PR10MB4130.namprd10.prod.outlook.com (2603:10b6:a03:201::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.14; Fri, 28 Oct 2022 00:10:24 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::36b6:3767:c15f:3b24]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::36b6:3767:c15f:3b24%9]) with mapi id 15.20.5769.015; Fri, 28 Oct 2022 00:10:24 +0000 From: Stephen Brennan To: Jan Kara Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Amir Goldstein , Al Viro , Stephen Brennan Subject: [PATCH v3 2/3] fsnotify: Protect i_fsnotify_mask and child flags with inode rwsem Date: Thu, 27 Oct 2022 17:10:15 -0700 Message-Id: <20221028001016.332663-3-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221028001016.332663-1-stephen.s.brennan@oracle.com> References: <20221021010310.29521-1-stephen.s.brennan@oracle.com> <20221028001016.332663-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SA0PR11CA0115.namprd11.prod.outlook.com (2603:10b6:806:d1::30) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PR10MB4166:EE_|BY5PR10MB4130:EE_ X-MS-Office365-Filtering-Correlation-Id: 41a810bb-b9b2-4adb-d782-08dab878cf38 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CWWF/QdFtUSJofGz+WTpc1W2ANRPeutZ6m8ZWtXArq9gw5k4RXmydKrBgW5P5N2qAH59IKp68d0D02NSujrU0Wm2MShIYbD+9gHCoRq23zTxcEFZCxXh9O5aQsVDvufErzg6XP9rNP5CP8YybBzRBE4weCyCTf4AkCgtvmWs+LsKYOIRghDMmwVlOa41ahVGXWgkSRrVN+z6NLnYo3wIK15XJMMl/NcewjJGl/M75vKZ/aSd5asd5XEjlVaBUX80byUOrc3y0MwrS+SbxdoQOkLU9R2w9t1IvrMTGnrd2CuSN4mu+h0OlzEXJ8L1M76m2Wg+sL8MkVy39aHy7AQXxmfsugo/wQeIpXPGITUrTmleFgLQHCEkQl1YJIHm/ZEZ1olyuGnnsjMuqCqdc2nJ9FvAVt5xc5h6C66b8TswivWw31+9Ul1dfyEp//W0Wp+aqnJDDRziPVJLxn79aqr3j4+entN+OiD8tuaEknkpXbJq0IZ1DygUjpytVffEKoLJlGfHOt/HcXV78DJkexYZ/QkB9Op+j16JmWFWaHQeykIeO31cj51YL64V3EJyPbQAC/j3CNSykJkWBjBIWVhYRWZnUFlob9z3w3GTSPza0OJxFLIaq16Apsb2d5schUTO4n9dq5q+9R8jmnWDbn5BxKpAstBwgyQy5rM0asokyXHWJFh3FDLkOkt4rWPv9/PuDhAzSJO+p5jcVu03AMbNWA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR10MB4166.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(366004)(376002)(346002)(39860400002)(396003)(136003)(451199015)(83380400001)(103116003)(36756003)(6486002)(107886003)(6666004)(478600001)(5660300002)(66946007)(4326008)(8676002)(66476007)(8936002)(66556008)(41300700001)(30864003)(54906003)(6916009)(316002)(6506007)(1076003)(2616005)(38100700002)(186003)(6512007)(26005)(86362001)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /eyNIyc0HzaN1lFlL7A6ZKiVqIWzyCr9lzw0F807fROfdDrQOI0S+t7VwvFHEgbAav+/OxHJ0r+9QH74f9Qh/KpGabc9LOp/F0WAWqymEIxDUgeuo41coMgVvVAnLjWPcQC9CfCEt4x46A/9A5dAy2cn9XANZlYw4dsdYw8lJdm6A671nXvcO7mYTuZraOHD12fpalRKNYyykomQ8sKkeYwizBYoGw/9wIwgvDTngMO77IuJ3VNY1moPhOPvuMD1+EJH4fPorodo4GjUQMOv9V1eqfFSwWiBBqz2HAQjfUEYfKLl1P7S/v/IbxTTpkS+BJi2i5XGLumdFXoAYI26SO02i38dUrVPVWY6kVppjcW1GQ2NPh1PMj5OyLmmuVKlKaDuEzPZzMe0P/jnANJAuF2hPEh2+r0FLnBJGAgAEoBzPrubkrvRx8/ZMZt0Bjt2Rg5ihn9q0RxHIq9TCp+xBzhmiuF6MoOPeAXXGy+AKQ7aZDiw2LHvhv2K/uKacaDZ1HFK3NwDmdZbp80QwvoFaiLtdrqzlCN03zz+LJTx8mhtZVjpVZmKM9repBo7FpD5xMFECqLAnk4efr45OZRzw5/GGt43OR1B4EFIgZdqvcYzNWtdk/bIBHocBDRTfhbMvykWh4k9UDu4wIrKo7DcMPWm2L70FHa9F8/Nf/5ACN/k5wDjRdXfDQ2IL7HTSNxDtlOb7ne0WuW18JYDD3frI6UQmz7cnmSBrIJG1UuoU5iedj5i0oNOOCD9c324L9YiowM1rEMr76ekAH814ma0RnDppv9omrhVFWxMVql5AM3yANvaoEs0NCC9dK7+1JoyWEeOmZ71E5cgKFnjibNF3dxwC1Sh0f5C3xJRMrRVCAnMcbLhI9wwMfSoySabBjHO8VZRfNgx//ZaGiqigo3tLeOOst65MXQknPPZDGQq2mT9bhMMycnPVBTrSBvbkc5sGnvaxYTsGJBC6SP1+PCxG/ENeUsvCz+qyVzn3YISRJUrL6546XS6uCcvKUMHVGkUcLMnTHzBSZIlT1kELg9lfHtQZ3r/Nd+nH1wesl+RzqkDhvWdUOeN2HMB2i3iFSuO1S0U5sl/1oxi7k8l3ZwodoaRhzFMNDS7zy71YV/cCl8Wzi+9ZPwqpfQd7m27rsbOXyv/vHQ6PSJvxNgd20koKHsiun/0eY4YOoXI+3AKXY51avS0DKmmHANXvf7hnul9Hs3tebYpsYl/KoJa7FqfP240N6UxuQAFmc2Ha+1eM2y7mIvIgtY4quwHGAPjwPfttqUfTfS+wW2auGEPC9BXK9+SR3Csdqdkk2HfZgJ/yrwz4agozDxQVcUcLehytEXImXgu8VwJrUSpQyub3isRBLePA53YnlakC8dchFZ2TauGEZGeICUtAF+jOTQNJbk9B60JeuCPY1lkr2N0YhmelwXl4jYOVt3l3yH1VnnbxC9Qp5igecp21AGNkIZasrDvo6NnusfHEcoNyL7E1E8SBxV4sHXXTvyLd1J6e08t5VhYGeubspEd9dmYPBMp+Hq1E8KnV4fJljKkcD7AG1j2NaxpFsZ9eC/qUZMo1ITyDGWet36qVSDYHWFKFZV5NNUoIECvrUD12HEAyvJowcmXqA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 41a810bb-b9b2-4adb-d782-08dab878cf38 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2022 00:10:23.9635 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: R6qgmTFtGXWWfGY4baW5Fc20K8axBrPpXvKGMgf1RcoDxPsY0nIbRhES6c0JbZC/Z1VhLBgqMt3gekevZ0xoSpHnNIcZZAkOOY5IRVp2hfQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4130 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-27_07,2022-10-27_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 mlxlogscore=999 spamscore=0 phishscore=0 bulkscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2210270138 X-Proofpoint-GUID: BJVvorZks6FPWNuJz09jMYmbuWr1H93E X-Proofpoint-ORIG-GUID: BJVvorZks6FPWNuJz09jMYmbuWr1H93E Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org When an inode is interested in events on its children, it must set DCACHE_FSNOTIFY_PARENT_WATCHED flag on all its children. Currently, when the fsnotify connector is removed and i_fsnotify_mask becomes zero, we lazily allow __fsnotify_parent() to do this the next time we see an event on a child. However, if the list of children is very long (e.g., in the millions), and lots of activity is occurring on the directory, then it's possible for many CPUs to end up blocked on the inode spinlock in __fsnotify_update_child_flags(). Each CPU will then redundantly iterate over the very long list of children. This situation can cause soft lockups. To avoid this, stop lazily updating child flags in __fsnotify_parent(). Protect the child flag update with i_rwsem held exclusive, to ensure that we only iterate over the child list when it's absolutely necessary, and even then, only once. Signed-off-by: Stephen Brennan Reviewed-by: Amir Goldstein --- Notes: v3 changes: * Moved fsnotify_update_children_dentry_flags() into fsnotify.c, declared it in the header. Made __fsnotify_update_children_dentry_flags() static since it has no external callers except fsnotify_update...(). * Use bitwise xor operator in children_need_update() * Eliminated FSNOTIFY_OBJ_FLAG_* constants, reused CONN_FLAG_* * Updated documentation of fsnotify_update_inode_conn_flags() to reflect its behavior * Renamed "flags" to "update_flags" in all its uses, so that it's a clear pattern and matches renamed fsnotify_update_object(). fs/notify/fsnotify.c | 45 ++++++++++- fs/notify/fsnotify.h | 13 +++- fs/notify/mark.c | 124 ++++++++++++++++++++----------- include/linux/fsnotify_backend.h | 1 + 4 files changed, 137 insertions(+), 46 deletions(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 7939aa911931..ccb8a3a6c522 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -103,13 +103,15 @@ void fsnotify_sb_delete(struct super_block *sb) * parent cares. Thus when an event happens on a child it can quickly tell * if there is a need to find a parent and send the event to the parent. */ -void __fsnotify_update_child_dentry_flags(struct inode *inode) +static bool __fsnotify_update_children_dentry_flags(struct inode *inode) { struct dentry *alias, *child; int watched; if (!S_ISDIR(inode->i_mode)) - return; + return false; + + lockdep_assert_held_write(&inode->i_rwsem); /* determine if the children should tell inode about their events */ watched = fsnotify_inode_watches_children(inode); @@ -136,6 +138,43 @@ void __fsnotify_update_child_dentry_flags(struct inode *inode) } spin_unlock(&alias->d_lock); dput(alias); + return watched; +} + +void fsnotify_update_children_dentry_flags(struct fsnotify_mark_connector *conn, + struct inode *inode) +{ + bool need_update; + + inode_lock(inode); + spin_lock(&conn->lock); + need_update = fsnotify_children_need_update(conn, inode); + spin_unlock(&conn->lock); + if (need_update) { + bool watched = __fsnotify_update_children_dentry_flags(inode); + + spin_lock(&conn->lock); + if (watched) + conn->flags |= FSNOTIFY_CONN_FLAG_WATCHES_CHILDREN; + else + conn->flags &= ~FSNOTIFY_CONN_FLAG_WATCHES_CHILDREN; + spin_unlock(&conn->lock); + } + inode_unlock(inode); +} + + +static void fsnotify_update_child_dentry_flags(struct inode *inode, struct dentry *dentry) +{ + /* + * Flag would be cleared soon by + * __fsnotify_update_child_dentry_flags(), but as an + * optimization, clear it now. + */ + spin_lock(&dentry->d_lock); + if (!fsnotify_inode_watches_children(inode)) + dentry->d_flags &= ~DCACHE_FSNOTIFY_PARENT_WATCHED; + spin_unlock(&dentry->d_lock); } /* Are inode/sb/mount interested in parent and name info with this event? */ @@ -206,7 +245,7 @@ int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data, p_inode = parent->d_inode; p_mask = fsnotify_inode_watches_children(p_inode); if (unlikely(parent_watched && !p_mask)) - __fsnotify_update_child_dentry_flags(p_inode); + fsnotify_update_child_dentry_flags(p_inode, dentry); /* * Include parent/name in notification either if some notification diff --git a/fs/notify/fsnotify.h b/fs/notify/fsnotify.h index fde74eb333cc..621e78a6f0fb 100644 --- a/fs/notify/fsnotify.h +++ b/fs/notify/fsnotify.h @@ -70,11 +70,22 @@ static inline void fsnotify_clear_marks_by_sb(struct super_block *sb) fsnotify_destroy_marks(&sb->s_fsnotify_marks); } +static inline bool fsnotify_children_need_update(struct fsnotify_mark_connector *conn, + struct inode *inode) +{ + bool watched, flags_set; + + watched = fsnotify_inode_watches_children(inode); + flags_set = conn->flags & FSNOTIFY_CONN_FLAG_WATCHES_CHILDREN; + return watched ^ flags_set; +} + /* * update the dentry->d_flags of all of inode's children to indicate if inode cares * about events that happen to its children. */ -extern void __fsnotify_update_child_dentry_flags(struct inode *inode); +extern void fsnotify_update_children_dentry_flags(struct fsnotify_mark_connector *conn, + struct inode *inode); extern struct kmem_cache *fsnotify_mark_connector_cachep; diff --git a/fs/notify/mark.c b/fs/notify/mark.c index c74ef947447d..8969128dacc1 100644 --- a/fs/notify/mark.c +++ b/fs/notify/mark.c @@ -123,37 +123,52 @@ static void fsnotify_get_inode_ref(struct inode *inode) } /* - * Grab or drop inode reference for the connector if needed. + * Determine the connector flags that it is necessary to update * - * When it's time to drop the reference, we only clear the HAS_IREF flag and - * return the inode object. fsnotify_drop_object() will be resonsible for doing - * iput() outside of spinlocks. This happens when last mark that wanted iref is - * detached. + * If any action needs to be taken on the connector's inode outside of a spinlock, + * we return the inode and set *update_flags accordingly. + * + * If FSNOTIFY_CONN_FLAG_HAS_IREF is set in *update_flags, then the caller needs + * to drop the last inode reference using fsnotify_put_inode_ref(). + * + * If FSNOTIFY_CONN_FLAG_WATCHES_CHILDREN is set in *update_flags, then the + * caller needs to update the children dentry flags so that their + * DCACHE_FSNOTIFY_PARENT_WATCHED flag matches the i_fsnotify_mask value, using + * fsnotify_update_children_dentry_flags(). */ -static struct inode *fsnotify_update_iref(struct fsnotify_mark_connector *conn, - bool want_iref) +static struct inode *fsnotify_update_inode_conn_flags(struct fsnotify_mark_connector *conn, + bool want_iref, int *update_flags) { bool has_iref = conn->flags & FSNOTIFY_CONN_FLAG_HAS_IREF; - struct inode *inode = NULL; + struct inode *inode = NULL, *ret = NULL; - if (conn->type != FSNOTIFY_OBJ_TYPE_INODE || - want_iref == has_iref) + if (conn->type != FSNOTIFY_OBJ_TYPE_INODE) return NULL; - if (want_iref) { - /* Pin inode if any mark wants inode refcount held */ - fsnotify_get_inode_ref(fsnotify_conn_inode(conn)); - conn->flags |= FSNOTIFY_CONN_FLAG_HAS_IREF; - } else { - /* Unpin inode after detach of last mark that wanted iref */ - inode = fsnotify_conn_inode(conn); - conn->flags &= ~FSNOTIFY_CONN_FLAG_HAS_IREF; + inode = fsnotify_conn_inode(conn); + + if (want_iref != has_iref) { + if (want_iref) { + /* Pin inode if any mark wants inode refcount held */ + fsnotify_get_inode_ref(inode); + conn->flags |= FSNOTIFY_CONN_FLAG_HAS_IREF; + } else { + /* Unpin inode after detach of last mark that wanted iref */ + conn->flags &= ~FSNOTIFY_CONN_FLAG_HAS_IREF; + ret = inode; + *update_flags |= FSNOTIFY_CONN_FLAG_HAS_IREF; + } + } + if (fsnotify_children_need_update(conn, inode)) { + ret = inode; + *update_flags |= FSNOTIFY_CONN_FLAG_WATCHES_CHILDREN; } - return inode; + return ret; } -static void *__fsnotify_recalc_mask(struct fsnotify_mark_connector *conn) +static void *__fsnotify_recalc_mask(struct fsnotify_mark_connector *conn, + int *update_flags) { u32 new_mask = 0; bool want_iref = false; @@ -173,7 +188,7 @@ static void *__fsnotify_recalc_mask(struct fsnotify_mark_connector *conn) } *fsnotify_conn_mask_p(conn) = new_mask; - return fsnotify_update_iref(conn, want_iref); + return fsnotify_update_inode_conn_flags(conn, want_iref, update_flags); } /* @@ -184,15 +199,19 @@ static void *__fsnotify_recalc_mask(struct fsnotify_mark_connector *conn) */ void fsnotify_recalc_mask(struct fsnotify_mark_connector *conn) { + struct inode *inode = NULL; + int flags = 0; + if (!conn) return; spin_lock(&conn->lock); - __fsnotify_recalc_mask(conn); + inode = __fsnotify_recalc_mask(conn, &flags); spin_unlock(&conn->lock); - if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) - __fsnotify_update_child_dentry_flags( - fsnotify_conn_inode(conn)); + + if (flags & FSNOTIFY_CONN_FLAG_WATCHES_CHILDREN) + fsnotify_update_children_dentry_flags(conn, inode); + WARN_ON_ONCE(flags & FSNOTIFY_CONN_FLAG_HAS_IREF); } /* Free all connectors queued for freeing once SRCU period ends */ @@ -240,7 +259,8 @@ static void fsnotify_put_sb_connectors(struct fsnotify_mark_connector *conn) static void *fsnotify_detach_connector_from_object( struct fsnotify_mark_connector *conn, - unsigned int *type) + unsigned int *type, + unsigned int *update_flags) { struct inode *inode = NULL; @@ -252,8 +272,10 @@ static void *fsnotify_detach_connector_from_object( inode = fsnotify_conn_inode(conn); inode->i_fsnotify_mask = 0; - /* Unpin inode when detaching from connector */ - if (!(conn->flags & FSNOTIFY_CONN_FLAG_HAS_IREF)) + *update_flags = conn->flags & + (FSNOTIFY_CONN_FLAG_HAS_IREF | + FSNOTIFY_CONN_FLAG_WATCHES_CHILDREN); + if (!*update_flags) inode = NULL; } else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) { fsnotify_conn_mount(conn)->mnt_fsnotify_mask = 0; @@ -279,15 +301,37 @@ static void fsnotify_final_mark_destroy(struct fsnotify_mark *mark) fsnotify_put_group(group); } -/* Drop object reference originally held by a connector */ -static void fsnotify_drop_object(unsigned int type, void *objp) +/* Apply the update_flags for a connector after recalculating mask */ +static void fsnotify_update_object(struct fsnotify_mark_connector *conn, + unsigned int type, void *objp, + int update_flags) { if (!objp) return; /* Currently only inode references are passed to be dropped */ if (WARN_ON_ONCE(type != FSNOTIFY_OBJ_TYPE_INODE)) return; - fsnotify_put_inode_ref(objp); + + if (update_flags & FSNOTIFY_CONN_FLAG_WATCHES_CHILDREN) + /*. + * At this point, we've already detached the connector from the + * inode. It's entirely possible that another connector has been + * attached, and that connector would assume that the children's + * flags are all clear. There are two possibilities: + * (a) The connector has not yet attached a mark that watches its + * children. In this case, we will properly clear out the flags, + * and the connector's flags will be consistent with the + * children. + * (b) The connector attaches a mark that watches its children. + * It may have even already altered i_fsnotify_mask and/or + * altered the child dentry flags. In this case, our call here + * will read the correct value of i_fsnotify_mask and apply it + * to the children, which duplicates some work, but isn't + * harmful. + */ + fsnotify_update_children_dentry_flags(conn, objp); + if (update_flags & FSNOTIFY_CONN_FLAG_HAS_IREF) + fsnotify_put_inode_ref(objp); } void fsnotify_put_mark(struct fsnotify_mark *mark) @@ -296,6 +340,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark) void *objp = NULL; unsigned int type = FSNOTIFY_OBJ_TYPE_DETACHED; bool free_conn = false; + int flags = 0; /* Catch marks that were actually never attached to object */ if (!conn) { @@ -313,16 +358,16 @@ void fsnotify_put_mark(struct fsnotify_mark *mark) hlist_del_init_rcu(&mark->obj_list); if (hlist_empty(&conn->list)) { - objp = fsnotify_detach_connector_from_object(conn, &type); + objp = fsnotify_detach_connector_from_object(conn, &type, &flags); free_conn = true; } else { - objp = __fsnotify_recalc_mask(conn); + objp = __fsnotify_recalc_mask(conn, &flags); type = conn->type; } WRITE_ONCE(mark->connector, NULL); spin_unlock(&conn->lock); - fsnotify_drop_object(type, objp); + fsnotify_update_object(conn, type, objp, flags); if (free_conn) { spin_lock(&destroy_lock); @@ -331,12 +376,6 @@ void fsnotify_put_mark(struct fsnotify_mark *mark) spin_unlock(&destroy_lock); queue_work(system_unbound_wq, &connector_reaper_work); } - /* - * Note that we didn't update flags telling whether inode cares about - * what's happening with children. We update these flags from - * __fsnotify_parent() lazily when next event happens on one of our - * children. - */ spin_lock(&destroy_lock); list_add(&mark->g_list, &destroy_list); spin_unlock(&destroy_lock); @@ -834,6 +873,7 @@ void fsnotify_destroy_marks(fsnotify_connp_t *connp) struct fsnotify_mark *mark, *old_mark = NULL; void *objp; unsigned int type; + int update_flags = 0; conn = fsnotify_grab_connector(connp); if (!conn) @@ -859,11 +899,11 @@ void fsnotify_destroy_marks(fsnotify_connp_t *connp) * mark references get dropped. It would lead to strange results such * as delaying inode deletion or blocking unmount. */ - objp = fsnotify_detach_connector_from_object(conn, &type); + objp = fsnotify_detach_connector_from_object(conn, &type, &update_flags); spin_unlock(&conn->lock); if (old_mark) fsnotify_put_mark(old_mark); - fsnotify_drop_object(type, objp); + fsnotify_update_object(conn, type, objp, update_flags); } /* diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index d7d96c806bff..7b8d1cdac0ce 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -474,6 +474,7 @@ struct fsnotify_mark_connector { unsigned short type; /* Type of object [lock] */ #define FSNOTIFY_CONN_FLAG_HAS_FSID 0x01 #define FSNOTIFY_CONN_FLAG_HAS_IREF 0x02 +#define FSNOTIFY_CONN_FLAG_WATCHES_CHILDREN 0x04 unsigned short flags; /* flags [lock] */ __kernel_fsid_t fsid; /* fsid of filesystem containing object */ union { From patchwork Fri Oct 28 00:10:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13022935 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7942BFA373D for ; Fri, 28 Oct 2022 00:10:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235457AbiJ1AKs (ORCPT ); Thu, 27 Oct 2022 20:10:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235236AbiJ1AKd (ORCPT ); Thu, 27 Oct 2022 20:10:33 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B18F3FA0C; Thu, 27 Oct 2022 17:10:32 -0700 (PDT) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29RMOQtd030564; Fri, 28 Oct 2022 00:10:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=Bs8sc4GC1kdnQEvjC1SQPPl1ML6CgN50zb3nAdCF7cI=; b=yA7ix755QgKbEYx8v9t/KESnIX7uo3OVNrwnCwU/wDOOW7VFK7WYTzjNUvIuHNxEB2FD PA//APjBmdYPyrSrHGNBxr4aTWrSp1rsezDEq+4hoNcSpED0ktg/LG2Sl36wvDYY0X0/ NzXxzkA6C91Es44qBgvlQ1aX7YP3nhSrys4ex7G+uUJ1phyc3h7pK7gappFb+9QbdC0G UevYKf28j5G7vk+t0+SfI00mXDD7DH9R1FXnK0h61pfl2QXQFNcGIjkawvh4R39zMLM/ DU6EQrTAEpg/1S/hTsMXa6Ly+CB7jrZNOPQMDK2E4fvb8GTCl3Sf4DS63NijC3Wbe0CW og== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kfahec161-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 28 Oct 2022 00:10:29 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 29RKugpf009531; Fri, 28 Oct 2022 00:10:28 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2107.outbound.protection.outlook.com [104.47.70.107]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3kfagfh6y9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 28 Oct 2022 00:10:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eCVW3eF+veYCYMNXljXmW5nwhUPf+6pEKkpt2AIgkAbBU2h2C/1z723GZ0EkL8HgRMqHm4wsJz0uNej2P9c0ApBuJaVQ3/2Gpq7PuW4vbl+bylbEGPw040uqLMrgiZfI2pwkYrPCMrBKula9qjsB5O6N5cfyGOu1f3dB94cPg3Jo7NUiIBRUP/BB3QGNkQZaIWdK+bonpSu0tKgqjYCpK+r0KcfdkguIvr6E1iV7DsBhwRFeNf4D4XLLv5Y7HYheMSqDW6DrdKZdrpwz+hRXZwepnlijPJZKh9eIHw5pyM4x7G/3Y/do2ZbRi75xEAPDZLMG335S/JvjLziUmwv+BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Bs8sc4GC1kdnQEvjC1SQPPl1ML6CgN50zb3nAdCF7cI=; b=P2+yaG/314uILHpYDN9NXZ0V0LCvcfltBp3RchPJmsnvXSldTJWfw0B+FEcRAIsOJD+7Yf34emOjWMM0Jy3aJeW1oCc5wzYunncc/qWMYi3/6BOeVdlEtNkaD9pt8ZPRozBEvfQkhuw6k4y3qZHgjP+oSd4ucTeeRsCcUN37LMmJZ3idRmC2g0ea648zybk/WxVFy6+PwG7V41LsbS88Fvzu9BGhviQvhMNKAHMkB1/EATUlKtMgS1zwWahk9FFtWJV6Y08U23CgIHZQAIPJbmrpBMH1is0XDllDbyvPuzG6lwskaFZrOG7FaAZSEqiZvlIpPL7M1erbzlO8Bl8HYw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Bs8sc4GC1kdnQEvjC1SQPPl1ML6CgN50zb3nAdCF7cI=; b=Pc+qcmI0QoZxocVTVcdrNHZ442AIsZ8QYd9ucsXphzUAmTC2oy7W6lOyzfgL9nbtYSn+VuH0kk1Q7bHC45zoG2q14+Dh8S4BJ8/T3cnLaSjdjlh9pBs1nusY/bwwYAcs30GbeaOyXFdynlLlPkulASP/TBhKD2OXVmxhTpwM7+c= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by BY5PR10MB4130.namprd10.prod.outlook.com (2603:10b6:a03:201::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.14; Fri, 28 Oct 2022 00:10:26 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::36b6:3767:c15f:3b24]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::36b6:3767:c15f:3b24%9]) with mapi id 15.20.5769.015; Fri, 28 Oct 2022 00:10:26 +0000 From: Stephen Brennan To: Jan Kara Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Amir Goldstein , Al Viro , Stephen Brennan Subject: [PATCH v3 3/3] fsnotify: allow sleepable child flag update Date: Thu, 27 Oct 2022 17:10:16 -0700 Message-Id: <20221028001016.332663-4-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221028001016.332663-1-stephen.s.brennan@oracle.com> References: <20221021010310.29521-1-stephen.s.brennan@oracle.com> <20221028001016.332663-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SJ0PR13CA0009.namprd13.prod.outlook.com (2603:10b6:a03:2c0::14) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PR10MB4166:EE_|BY5PR10MB4130:EE_ X-MS-Office365-Filtering-Correlation-Id: c3f7719e-94bb-4dfa-bcad-08dab878d094 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eWRzeQhBhkvoSMIXEywxTDcii5LwlYidq1gpDRIdjfByOj1R2BoE3L9kAH9EuXHPDPeBZRcQqWgYGXFQrm/zBtKLahYsCrMs7rGyZyXJPTx5oueR3TepykO2VcNrA3EtfxjsEeVk/afYc7+chLD+UTqvVnp1we2k0/CcroOOL1qy1jddufU3XIyTAXKQF2rSh0PbWTaKHypGQ0qkEre5MSImO5dojvuwLykEvvSNp+Kf1/0wnzPzrOYj0zrcF5ZjMf7NzEyhfHbJHaEKAvrRSkyVDf56qMeujd4fURCBSUV2cFPROWnOuCQVq+jxRSwtAzVKDmXEjxvljenCPtT5smnbPBzRCACriachY1LXBdA0iZJ44ydILCTcjkjLXgjFu1nq+9dMAvbVEizw4M3DE5wQEEkbGJWCaFIb7mZ3dwQN3yxX8g2nUzLKu2xiYuxShBXsqoGJCbVRRnGc7BbzjpZzbkkxMsdGMvbJMKHR/h7p9vQGi3uBtAb1ElCE2A5T//+1MtdwAOXAkhULuUiOVWzj/SiEBDQPWHF17QwdGABfwx3UusjugLCphAhUvE3KEnC1PXN9JwgWm9WxmkZaNsxe9OLACRwqJ5L2Lv5/gig0rnPHGHroYgnZ+GOuBmJXiHVg125L3OPcg2Z/NdlO0IDyx5l49R9GK2xS9vFhMEw1i0BdQUhA+a2rPqNhWO9bnrscRBJHoDSjpD10/VOurQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR10MB4166.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(366004)(376002)(346002)(39860400002)(396003)(136003)(451199015)(83380400001)(103116003)(36756003)(6486002)(107886003)(6666004)(478600001)(5660300002)(66946007)(4326008)(8676002)(66476007)(8936002)(66556008)(41300700001)(54906003)(6916009)(316002)(6506007)(1076003)(2616005)(38100700002)(186003)(6512007)(26005)(86362001)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bIdq1f3V9ig0Yn9HH1aenPrjNuRF8YuvILfUPkIF+d9phnMeNiBwZskwYvJSBQHept4aEZuLrgjp5g5ZQasogopTbeUKketmwu0FrYkFAJX2f1ZVhlBMXPwJrAWJKlRxW3WLgD3tRHyjcXz3fkxParroKw++JT2Iok11+VO7/tprrOOX0hOBCzIwj+vhWAqHK78g29PnBw2LVaq4f5L9kA0rCRNNlriREAN83E/CZnzNmKhBuwsJwOMpXKJt0XjZutVtdyNJJOZwtWwPlgMcz/PTtLp3BnJVcHeThjJaZs4w9UhFV9Dd9C6Xf49J3IM8MDi9Gmg4NhdIIGoUYt0RffQ4rkKo/qqAzC4zYK6+cXw9mJh/Ruthj3bSeQsf/DoT1LO56ZCh6CyBLntTRP+iXGYJB6ZFrHsDczyzjTKb56s0ZAK8xv0f+nxLyxVx5Lt6EoLI0X/KyS7SzuSd5zh+2mdE58P0QtC8nHrFPUBYbY502BSxRHMK2ZCV0+EaSP2s7nkmy0YSkawyiR+jo1Ek/DFvD4oJur2Wlm+kYlj1O11OAWPsN1DyQcGm56l8yfD6y2orhcYrakuj288ctxQiqAajxu8Ore62GBJ38+eRajsbGcyiDCLO5r33JtHkX+OJguCMM1T1IL7wvwPnW6LboUYCJLiZy7P6OKhjz8IEqdvTtgIYVGxuTxFRzaLZEqm1eWEAT7FYOn6K76zPNw10oF7dAHESrG+TwNhYvAtEZ0kujbMCwHSdVKaUnicP0Mwr3mNDE8McQotDnF/Rru4Tlzn4V3/wmc8DBD2FFOoBVzk0QomAMJp5qf8eiYvyTATJD5mKm2SYWIIjNdNWxCnWvo0sBpnIs24zaa6gWeHn2WY7OV7FxS1TKgUoDUwPBUTFZS9XnvKSLRijVtm4AI9edr8Z92H7uu3ex6h4O+FaJDrnU7hsi/djnfTxgNiTNoecEpwOlR7OSU6aSYu3FCHNYxGcE0hfoHCq8fo8z5t7Zi7hahLYAyKFKqQ4hPQEz6nLXGQAr42CXOR5sN8dhhzey0WnLTh6v4eJMzrsBQjxG2+w5J1gvHGYqnjxFAbZDPoapoesGmVFCZbW1oOrK9K5AHRxyc9rMSxVNpU48PaD5aFFQ3BFbY2w/SBHmsE7tr+q6z4hlHnKqX9S9vR6jjin/+BLy79nnTtpbRUmjL7W8o/NnyYZeKFfivcD19+INyfw7LsuBxONFtb7IQZ5bzth8Hz0ELX4A1fkbDWEUiyYzsIqU+NVa8GW/boncN5Cbs6nGoEMHKIsIumWJv5NcyiKZIsdtOwppx1sa3cdGWv5ivINHtxaY3KdX50bHc/Q4yI2x/v59k/ZG21LVa1TM0P6F7huE2CPda36fMfaoVfQHjm0MKXsRPVan1km3h7HkhrBn3Ot117EUslv6P7Gnh0YSapWHiPixlq/vkOy3HpztzwRXiOEuz/CULlbkTZKplkczaY+p4V8xuVMtEDmOMFG1K0/jeQZHbJiQWpUIaf0tGjHoqC5/Voi1QJ+T4bfxyWpZMdP/VzMMy+cYNGZfjM8wxSgSqA67QB2+Sd5qgt6OcsXI+2GvugXLQxT0P+VRTIARjRM+EYrhQ1kjVnQ+OTlrQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c3f7719e-94bb-4dfa-bcad-08dab878d094 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2022 00:10:26.2903 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 0vcpEOhcbzXykz1naLG50HEHOyXLfv7SVMKlgOmU0l8gDPhG+u8fQfdZMSEt8ri4BBz46Gxaln6dpMjwg0dDo0xPQ/2dL6Jm+pclvKzISqU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4130 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-27_07,2022-10-27_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 spamscore=0 phishscore=0 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2210270138 X-Proofpoint-GUID: AV33PWdkUCZRRun01IvCxU5IVK3chsLM X-Proofpoint-ORIG-GUID: AV33PWdkUCZRRun01IvCxU5IVK3chsLM Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org With very large d_subdirs lists, iteration can take a long time. Since iteration needs to hold parent->d_lock, this can trigger soft lockups. It would be best to make this iteration sleepable. Since we have the inode locked exclusive, we can drop the parent->d_lock and sleep, holding a reference to a child dentry, and continue iteration once we wake. Signed-off-by: Stephen Brennan Reviewed-by: Amir Goldstein --- Notes: v3: - removed if statements around dput() v2: - added a check for child->d_parent != alias and retry logic fs/notify/fsnotify.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index ccb8a3a6c522..34e5d18235a7 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -102,10 +102,12 @@ void fsnotify_sb_delete(struct super_block *sb) * on a child we run all of our children and set a dentry flag saying that the * parent cares. Thus when an event happens on a child it can quickly tell * if there is a need to find a parent and send the event to the parent. + * + * Context: inode locked exclusive */ static bool __fsnotify_update_children_dentry_flags(struct inode *inode) { - struct dentry *alias, *child; + struct dentry *child, *alias, *last_ref = NULL; int watched; if (!S_ISDIR(inode->i_mode)) @@ -120,12 +122,37 @@ static bool __fsnotify_update_children_dentry_flags(struct inode *inode) alias = d_find_any_alias(inode); /* - * run all of the children of the original inode and fix their - * d_flags to indicate parental interest (their parent is the - * original inode) + * These lists can get very long, so we may need to sleep during + * iteration. Normally this would be impossible without a cursor, + * but since we have the inode locked exclusive, we're guaranteed + * that the directory won't be modified, so whichever dentry we + * pick to sleep on won't get moved. So, start a manual iteration + * over d_subdirs which will allow us to sleep. */ spin_lock(&alias->d_lock); +retry: list_for_each_entry(child, &alias->d_subdirs, d_child) { + if (need_resched()) { + /* + * We need to hold a reference while we sleep. But when + * we wake, dput() could free the dentry, invalidating + * the list pointers. We can't look at the list pointers + * until we re-lock the parent, and we can't dput() once + * we have the parent locked. So the solution is to hold + * onto our reference and free it the *next* time we drop + * alias->d_lock: either at the end of the function, or + * at the time of the next sleep. + */ + dget(child); + spin_unlock(&alias->d_lock); + dput(last_ref); + last_ref = child; + cond_resched(); + spin_lock(&alias->d_lock); + if (child->d_parent != alias) + goto retry; + } + if (!child->d_inode) continue; @@ -137,6 +164,7 @@ static bool __fsnotify_update_children_dentry_flags(struct inode *inode) spin_unlock(&child->d_lock); } spin_unlock(&alias->d_lock); + dput(last_ref); dput(alias); return watched; }