From patchwork Mon Oct 17 01:55:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dawei Li X-Patchwork-Id: 3173 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1227500wrs; Sun, 16 Oct 2022 19:00:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM75se/AHb7glpx5eZJ8jUI2YwNosM2K7s7v7OUaRFvKlixvNG2OXEvxQ2h4/lI1l3OssVDO X-Received: by 2002:a63:494e:0:b0:448:5163:4788 with SMTP id y14-20020a63494e000000b0044851634788mr8321891pgk.507.1665972044912; Sun, 16 Oct 2022 19:00:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1665972044; cv=pass; d=google.com; s=arc-20160816; b=Z4xSFVd8cy/TEUqH+cy1IzJBZ9LVzbkxJ2J0K/PczzBRQ1WjbthV/zNmPR1UpiBDZw e6Hh7htwp4Q+qiTgZb3XcavPjEPMH1eUwsMCS/J+ocxysCYgwWGUaFNx4fKJ1bDMG4OG oG3f5vy3y3LSqlP3LSJcrnDW/Vlyu/2eCnhZF7TjeKLz/APLT8/EM2mC65+kSDt4oAGQ wH/ke41BJccnazumsXuS/0Bkv92UHOVdJgtGiL/SaIaQ223aFtyeFGu0ykYeDFBoSflA SoSM8RQQIsrHAg25ERAfvT7WDgpUnLIiBQidOxqGiB92K2SzSSZ8nPq788LwKWUx2I+j cqOw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=PHwKV3MPuAtaesPp/cey3q6qIj5U9avWEr8Is0N01pI=; b=fxMpHmspZ5ADhD3fCKJCsB5VgH0WU8+7hyd6RMVZbJDpmX1KxyjmxnKhBHFrPGhar9 llkKKIU2CoQVcPQmzY7nguE3ZsbqPRX4E+G16AMb9py2WRzkfRVRJ3/AVPeCnlSYTY5x T/phjyYxLRE9SIhF88aTQdcpqsuKpi3minmDz+Y0ucAE1AWBU9fc10eZS0e73rPG7E/I EMi5DWLjWCK/YfKqjK4p+hQkUwvonKUS92feKNBDSxDA/m+Thr6wp1vjNxGr6lAtIScF g8YfidgS6uJpTTVqh//v7tj3aRFFxnrRAVwq4gwnb2ZQt37qnosG52bYykwlvFfdm/zn FcTw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=BGqbrwG3; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cj11-20020a056a00298b00b005567d823a2esi10212513pfb.306.2022.10.16.19.00.31; Sun, 16 Oct 2022 19:00:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=BGqbrwG3; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230035AbiJQB4L (ORCPT + 99 others); Sun, 16 Oct 2022 21:56:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229597AbiJQB4J (ORCPT ); Sun, 16 Oct 2022 21:56:09 -0400 Received: from JPN01-TYC-obe.outbound.protection.outlook.com (mail-tycjpn01olkn2031.outbound.protection.outlook.com [40.92.99.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D04034151F for ; Sun, 16 Oct 2022 18:56:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fJLcaMihQ3HQ2qLQ7H0yuDeFyg2Sjwp1TPJ9cvgT27a4YblunewmkJ+BPOtye/0AV+Q6o8/RckjVUPXDf5TiBGRzTj+Mboyqg9QLpaRKQDp9zrvCrUpY6KRsSJzxInrsTLoiuXHbYa6bW9fVMGtDMM6Pbc0L+5fLaW7M6Mli9sks+5l97M5CXnF983FOnsMmTod9DU2mHWzDAkRt2wYpGQLyjlli7sLiahOGMfMyjnpyugEgO4NnQT2++Fv/FQf5JYLRk0aE0Mq/hTsmvwWwwnZahyPqeVy+mY/qeebMPKttYOTWQN676fqZJMIMXPk2/L7WG55VF5fk/QW12EQYlQ== 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=PHwKV3MPuAtaesPp/cey3q6qIj5U9avWEr8Is0N01pI=; b=gPdpicWfscD47wjYCzusBToM6Vb5nTTKRCU+sp9/Rsql5yrwXl0DSZ08Q4zIfApbNFxOlvmbDZjSXCQ6GCc9xP7TMwKxS0QAmjLD8EB5ZMgLZ8t9AMSQwOHxMM//z1+LQESkNmldyLWvUY8vdOrqRTgeh9AZYeQ629berQnAPCIhy9LEZHQkMNGdxj1NBzoEAF0m32GnzSevICvYNajLv8lwraQomc0RZIG7QqOksMm4//EqhCdIH7KyD3ZczvbSHGLE3F0qYtgZ13aPCv5ORIGdPJyPRrFk8O7oPqEIchrff0dC7HgTWEXsQ8r7XWlXK9SuPY+ZSDDyOBw3kxwInw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PHwKV3MPuAtaesPp/cey3q6qIj5U9avWEr8Is0N01pI=; b=BGqbrwG3R9aspyCuptsY2qFpkYruVZbwxwhu1jzuxKwHI4ROh0sKyi5oHyRq0yyq97uLHHvM3V9mPuqwwqgQOYJ4N626v1Ten2RgIf6tC6lNu0G6PzVijJbgGfaPIBvJZ1EbMx1R+jQUmn08ZshI/bB+zdszNsyEKfCzVhLkmzCxGdh/oe40Lz+qdOT5fHv7nQKh4zOUke9IJIi0sjgKZDSniEB2VZVp4QNa8Iz2WXtohcBUd+A3NZHNQqTHMBgE7KOGxdeoq18z9dpVcZK8nIyhgD/UJSjXLu1uFfdmjezrwdqlXf705mhnFbdhrHh41V5R34/ajvrzZ61lcJMjxA== Received: from TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:152::9) by TYWP286MB3382.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:2dd::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.29; Mon, 17 Oct 2022 01:56:03 +0000 Received: from TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM ([fe80::4722:62da:4861:9d73]) by TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM ([fe80::4722:62da:4861:9d73%3]) with mapi id 15.20.5723.033; Mon, 17 Oct 2022 01:56:03 +0000 From: Dawei Li To: xiang@kernel.org, chao@kernel.org Cc: zhujia.zj@bytedance.com, huyue2@coolpad.com, jefflexu@linux.alibaba.com, linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org, Dawei Li Subject: [PATCH v2] erofs: protect s_inodes with s_inode_list_lock Date: Mon, 17 Oct 2022 09:55:53 +0800 Message-ID: X-Mailer: git-send-email 2.25.1 X-TMN: [N4IieOCPkr1neMxE730yOVXzDyzIztSe] X-ClientProxiedBy: TY2PR02CA0016.apcprd02.prod.outlook.com (2603:1096:404:56::28) To TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:152::9) X-Microsoft-Original-Message-ID: <20221017015553.2013074-1-set_pte_at@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYCP286MB2323:EE_|TYWP286MB3382:EE_ X-MS-Office365-Filtering-Correlation-Id: ac3220d1-ffa3-4963-7314-08daafe2bf79 X-MS-Exchange-SLBlob-MailProps: ZILSnhm0P3lt+CQaDQ/GFhL8t+j9Xd9JgD+BCv9mZ0byB3ixr8ZJVtexTl0+TBLncmHRU9oafdzwUnFoG+APEeUYttaUrgrC7RadHxfs+/ROW42M+Dw3sL/Osqa7c2vKBY7EmNBhOX3YzI1LMJrze3bUy58d/S7L2m/kH6eSIpJPXM72VXGLaRPGI4rwhSaIgwbAQ6LpzBx7/TP3R8qpVvbD7dbDp7QSKyTZpn7aHf+1qxm13PCqxlakMEY6nsfYmzX6k+lFOEli+VuEF/7+sBupIRl9rCeUSZO4ZjPVMCaRm4o9JSRltqAfB5eK4d3ix+TAkaH3uNk578pPWyl6RyKE6WPAKW3k3NoHkWHZGn6APmeKP49Z0/5lKr3ChFeU2xGu0rJq2blraOQZ6GtNbsQuexXkvBZLsnRQEYrwEtxXlscYh/OSr8v6RvKWpTfFOWt5y4vtIfQ6mEyFNy+vpqCHTbfS7KSID4D0vIO09kIDaDB7NPKoDZfKRc42wr4VacuJ+YGrz8xXRoUxSI6JxyJ4gG1BreouOQeVrZmdQlwVbfOy6V+omDL9o65L+vPKoPh/E6n2aY25O8eUPn2SRk5268Gf7Le9rXX90X9gtAr0FwXpO2wNeQmjfR1hHOXvPHqNiIEQNdD64DqzCgvaF0L/eJy52fztFI8+xT+iZsgBLM3FL7Mq19XQu75BpeeECb6NcQiZWyAxLwVk91HAzQEO2C0XG07D/VTZKPa9vUNBu8YIuS/+FhMVD7E9clqd16QLr/ta1SlS84SB1vmUqnCbKjMcQCHV X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JuK4Yw0cE9t+bgb9wzXsPYwfMSSfoxqzPW98qCKFIxJj5rsU+Pq2aPI7ToZScADbh+GvLPmTC1u8k4TpaBtbYi42R/FlDYYb4czp1CYToVLMcgJkbLDT/1BW40xkqeXuCMZkV0ltQJe2dS2XUrmDzJv52Kn/1PY4gXYfUsxzaE8rI6QLAbrR4kuAcEN0UlewyLwx6aCVeg2t7Q/4nntjDNOV9h+nVtzafGjF3PNXl5N3abfLcTkaHCsYetlin1g6T+oDvsBJQlo2bLfPHvlPkvGg7OZP6neYUQ/rKADfnnNqGTw3m0U5r5YtjLcuceju90Hx9eFekl25pHejqCcQoSxiuQ7dAmqOR2kL0rxTM+Opq1eoTLes7tRCkLL52COewnGCWkuRPFPn6v2AmzR097kSvM0jczlwNxeZetHFb+0lTptKg6Ol7ph5bSqV/jRagQm574zn3/0ziupTWzwtx2QkxSh5ucSaWSwF/qP0EJx6QlAXz5qTqZ/0TonQoY4Uwn0WfYw5EkjYgCw4VQW4Nk4ehLN/NSoSl5ciyajLHbmwFkPMlwK9J3G9aqY4TqqNsvMeS1c7HZNKG/5R9NaDCDx+aWKdO39zxTy1mSAAjzj4+WfcO5yFlkJra9KufDFoItUM/j8+BwAtYXG6JLI1jBAPOoB+Q4QjHjlLoSQWmVw= X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NuU1x2jxJCzYACTPaGO41NCW5gRZSmQxMrMBJJsp6MWWV8qvGcIaVpJ8UzrGeVQ9dcU910AuCzqeYua09+3j/D+RhvgU+hbasUcGjw8HrcaMgjUkkcPbyCSE74tehRjqS1DXsuw7tUltKWQ4c0VC9LqxEZjlxCPupU5R3A/niiZA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DudxgyBQVdtYOILHcgbH9RQncNMPtowOe38qtEsKokx+k8w== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ac3220d1-ffa3-4963-7314-08daafe2bf79 X-MS-Exchange-CrossTenant-AuthSource: TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2022 01:56:03.8879 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYWP286MB3382 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746898303216093492?= X-GMAIL-MSGID: =?utf-8?q?1746898303216093492?= s_inodes is superblock-specific resource, which should be protected by sb's specific lock s_inode_list_lock. v2: update the locking mechanisim to protect mutual-exclusive access both for s_inode_list_lock & erofs_fscache_domain_init_cookie(), as the reviewing comments from Jia Zhu. v1: https://lore.kernel.org/all/TYCP286MB23237A9993E0FFCFE5C2BDBECA269@TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM/ base-commit: 8436c4a57bd147b0bd2943ab499bb8368981b9e1 Signed-off-by: Dawei Li Reviewed-by: Jia Zhu Reviewed-by: Jingbo Xu Reviewed-by: Chao Yu --- fs/erofs/fscache.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 998cd26a1b3b..fe05bc51f9f2 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -590,14 +590,17 @@ struct erofs_fscache *erofs_domain_register_cookie(struct super_block *sb, struct super_block *psb = erofs_pseudo_mnt->mnt_sb; mutex_lock(&erofs_domain_cookies_lock); + spin_lock(&psb->s_inode_list_lock); list_for_each_entry(inode, &psb->s_inodes, i_sb_list) { ctx = inode->i_private; if (!ctx || ctx->domain != domain || strcmp(ctx->name, name)) continue; igrab(inode); + spin_unlock(&psb->s_inode_list_lock); mutex_unlock(&erofs_domain_cookies_lock); return ctx; } + spin_unlock(&psb->s_inode_list_lock); ctx = erofs_fscache_domain_init_cookie(sb, name, need_inode); mutex_unlock(&erofs_domain_cookies_lock); return ctx;