From patchwork Mon Jan 16 13:02:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangtao Li X-Patchwork-Id: 13103014 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 80235C46467 for ; Mon, 16 Jan 2023 13:02:41 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1pHP8K-0006pr-Gc; Mon, 16 Jan 2023 13:02:39 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pHP8G-0006pj-Ci for linux-f2fs-devel@lists.sourceforge.net; Mon, 16 Jan 2023 13:02:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=MIME-Version:Content-Type:Content-Transfer-Encoding :Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=f36cEWbdgA4BZW8xHZW2RLhdOIn2TffiaahwF6T7uf0=; b=EXQDaCkGjy3C4a9R5nYqojXotT nz3WpGal5ZwMvDKXtL7TGxl0xcsEUJr1dj/0U1WsSm6k80ln1Gmq0xDcrIwrzgivBYCz4pqtXPZyO R52P5RmDAemSFKX+0987TwwfXaWGZB3czpM797sMLBmS4mlYTtuMZIwhIfcVMiMrVSlo=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=f36cEWbdgA4BZW8xHZW2RLhdOIn2TffiaahwF6T7uf0=; b=h TDicuAPRtkaZNypLykWe0ZKG0h4Pf0MO9FaCMaIseMzLznpad/Cg4vqvKmm6N/9MTcf5cWJoUhFfB +D1f+2+vI4cF9GKP6IUUrioa9BVumf/lajE1p6pvBfuNEUpprnq1e4kgjp3d2uoWWMRSzEbrs2LNb i/M51pFJhcLIBM8I=; Received: from mail-tyzapc01on2118.outbound.protection.outlook.com ([40.107.117.118] helo=APC01-TYZ-obe.outbound.protection.outlook.com) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1pHP8A-0007pp-Ed for linux-f2fs-devel@lists.sourceforge.net; Mon, 16 Jan 2023 13:02:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jxa52YZVzd8e6nEEw4XMWQb8X7PTRsvPsiAM0lzs8nnLf7VsdzabwSIaqvo4Rp5wyhj3cjtyQYPHfKz+BEAa0Kqfbg1FvV8WKuZ5j7lwnQ0cMK6P8gDyay/dNSKTKfrnxn64SB8mu6QLeE/BpOwfFgH/OZgmT5eVSGSdvzvomCraWxfuuf+EmPSjg8S5cuXRNugX1IoJh7sqx6rTZr6mTSY64JPwJm01fVRdagbjoD5N/aEbsWjRBkrk9AXt17icQkGzy30syjlj5Mi7L0TzsLQb+vlH8LeDhyxb8JCpeoe0coFyJg2+/wyQms6cA4uVr+SEsDNBm0Lbq3Vv19AIvQ== 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=f36cEWbdgA4BZW8xHZW2RLhdOIn2TffiaahwF6T7uf0=; b=U5iDUuBWhad388ZIJaA2rWuIA7E4vb/Yh4OWwK3sEzPnqFW9ct79BvqgouVcOLcBRQ5ryoKJ8SXqLw+HBzU/NTgVZf2t1fjfOMARKTg70X5RRcVjPx0GjvRa2bZbfuPc5Kns2BHC7RGuOHuVji9h4ZwUkjpU3Sjz0hFHsPZ9Ca1Udd/NKuW4rI+nAwCN+M9yzhGkk6ezaMrztkBsOcxjMBZTrg4vfvsXIsbxfPdq1w/mGN8MhR7Y2hwM12b56LXPS4Pw9lKecPyvaKhOtMp2f+8cNfHi37YOTJnjZ9PDIM/wPRBWWxasBt/NXfaMAD4MeifikVOSB60REmcuvknHdw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=f36cEWbdgA4BZW8xHZW2RLhdOIn2TffiaahwF6T7uf0=; b=KqslN3L2GzsK1DASsiwCMmikUO3rt4CTeo9q2qStq62nCAcJ7bqPFDw+vTZT2oibA55ucNNm5HNabsKCWPVluYuH4szXQlF/klYcvZjz90JI5AbZ5bB9MeSj/dq4qwXQMiUElZV3jt6QTIc512+qc2wGmXyP+4gwG3QPdzzUIURPYfPW7w45ln/qSyX/QX5Q76ysVmM6WWhYaA/iUuJOTQE6LslZ8bm9soZFlLHxoNYGyvLwd9dJEwRbhQtbK9vga8L+wyhr3xGsLTOKHdGqHQI5WNVp1hAxok1H+J6TJ0Xqu2Fq+P1xIIOD3GS/mpIJ2KpaghpAZX6zsSdrOb93qg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) by SI2PR06MB4251.apcprd06.prod.outlook.com (2603:1096:4:154::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.11; Mon, 16 Jan 2023 13:02:20 +0000 Received: from SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::3e52:d08c:ecf4:d572]) by SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::3e52:d08c:ecf4:d572%5]) with mapi id 15.20.6002.012; Mon, 16 Jan 2023 13:02:20 +0000 To: jaegeuk@kernel.org, chao@kernel.org Date: Mon, 16 Jan 2023 21:02:10 +0800 Message-Id: <20230116130210.34490-1-frank.li@vivo.com> X-Mailer: git-send-email 2.35.1 X-ClientProxiedBy: SG2PR01CA0126.apcprd01.prod.exchangelabs.com (2603:1096:4:40::30) To SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEZPR06MB5269:EE_|SI2PR06MB4251:EE_ X-MS-Office365-Filtering-Correlation-Id: 8e9e0167-5ff4-428f-12d3-08daf7c1e6d5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +wFwys1nGB0/uJNLVb1dF+/ssEvXJBoHLL5p1yefpEhzgrLjaJc2xlV0LTQawfmUrYo7EHj5JV1olb3EMBNf7ZXtbDWjDjZHP9xUT8IPR/ZrVimCLWBCUK0XU00CcvYDnumULlwAJ2eGJ6NbBVku2HmmUJ3HcO/PO29sQHQTA7bsM8sFuVnkVwLH5N61v9KYvymbQnNlLtAgHD5rRlgh9/EiSLge/U230ving47+WB6otyUU7UmXnEhS5DElip7t1BB7NlsDTezFu8ED7FgHaYOdOLe4koVygdairrvRpCTX7g/eEU/y9pHA6z9AjcG8rGQhAgCfR1LLdCNU7d9yNlunrPnTr5m7N4yypIaFl5c9F9Bbdq01jX1kYt+QxX4Xx2YIdGGhPl2iEZEcRCgCvJ1596eafKxVOcbLtk4wliJbYYxwendpobBthZbUUHOAtB9AUbk9r9P0m0X2UB27y4XJsLU29GQU4kcu1KBHXdEaHjnp+4/nibvWfg/jMolKpECXMFYAk7y+tgKMQ260+AhL4Cp+uR1MmHtt3tBRp6u1dh/bJ4gnI1NPUdhF8eqel7W2FPfkO50wfxL+fYTcqNgpmsrEU7jD8EpT4dXjGwbLP4ARy9Ytqf4tbyDE7gAjha+Ffq/LwFX49DWTKvV/243wfk9mlD8I7Z1txGxk7cRug2IsfzbZMsQXxgio+o/xfa0a11/EXFx1M41pAjpJHA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SEZPR06MB5269.apcprd06.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(396003)(346002)(376002)(366004)(39860400002)(136003)(451199015)(36756003)(86362001)(6512007)(186003)(26005)(4326008)(8676002)(66556008)(41300700001)(66946007)(2616005)(66476007)(316002)(52116002)(6506007)(1076003)(478600001)(6666004)(54906003)(6486002)(2906002)(38100700002)(38350700002)(83380400001)(5660300002)(8936002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8WDTwv/bDRJWpZ4ftmkMixewUOgEcXnZSDsWf0tF7nVx3RdCHtcuYe2sQ/l4SgLEHxlrw2cJwGbO/ppU8VM782PqSN9zZL2oWkwc7CRkJ4ewcUMhLld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aR1ES8VgNncRyzCGSt7pWCjr4JbVhkXXavaeI+q6Nu3nVlOHxtw/HzJyvC7q1mZpBeomFgYGG2N7MDyFglNn/cd9BkWB2jTB93aSIuLiIaD6a8RGD30rf9hh0CaXforiqlNCmqjl15azxisAZx6H9+7ElyOQ4iXIbA0WzzlnYp4Rt43xEdcZ095eI87OwxfC5Mk6BzPPAapIXVs5CTNUCjjGBDbd4BIRBjvhE08lEhaFRivqDSsh36LMJCuK5zqTZnNEwWq022o7AMsghz7GNFb2CRZVYCxYpC0/ay/dhq2wENL16Pw/vUkrd00qskX8JbIRfVBDx9JzVpBVfCvTknFidYuAb3FDtJ7VahTQtgk7B36sK6TNCD7/e1m6i8o39SW/w+oDA3oZI/vvZRz3 X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8e9e0167-5ff4-428f-12d3-08daf7c1e6d5 X-MS-Exchange-CrossTenant-AuthSource: SEZPR06MB5269.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2023 13:02:20.2005 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Zi2jd6TjiGu9Slgm770d8hC9vHLN559HvfQcW9ENC3PNccQp6HH6/r+O4WF/OD/R/w6cxN0tF6uf4ujNFdmalA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SI2PR06MB4251 X-Headers-End: 1pHP8A-0007pp-Ed Subject: [f2fs-dev] [PATCH v2 1/2] f2fs: fix to avoid potential memory corruption in __update_iostat_latency() X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Yangtao Li via Linux-f2fs-devel From: Yangtao Li Reply-To: Yangtao Li Cc: kernel test robot , Yangtao Li , Dan Carpenter , linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net Add iotype sanity check to avoid potential memory corruption. This is to fix the compile error below: fs/f2fs/iostat.c:231 __update_iostat_latency() error: buffer overflow 'io_lat->peak_lat[type]' 3 <= 3 vim +228 fs/f2fs/iostat.c 211 static inline void __update_iostat_latency(struct bio_iostat_ctx *iostat_ctx, 212 enum iostat_lat_type type) 213 { 214 unsigned long ts_diff; 215 unsigned int page_type = iostat_ctx->type; 216 struct f2fs_sb_info *sbi = iostat_ctx->sbi; 217 struct iostat_lat_info *io_lat = sbi->iostat_io_lat; 218 unsigned long flags; 219 220 if (!sbi->iostat_enable) 221 return; 222 223 ts_diff = jiffies - iostat_ctx->submit_ts; 224 if (page_type >= META_FLUSH) ^^^^^^^^^^ 225 page_type = META; 226 227 spin_lock_irqsave(&sbi->iostat_lat_lock, flags); @228 io_lat->sum_lat[type][page_type] += ts_diff; ^^^^^^^^^ Mixup between META_FLUSH and NR_PAGE_TYPE leads to memory corruption. Fixes: a4b6817625e7 ("f2fs: introduce periodic iostat io latency traces") Reported-by: kernel test robot Reported-by: Dan Carpenter Signed-off-by: Yangtao Li --- fs/f2fs/iostat.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/iostat.c b/fs/f2fs/iostat.c index ed8176939aa5..e9a3df7ce4d9 100644 --- a/fs/f2fs/iostat.c +++ b/fs/f2fs/iostat.c @@ -223,7 +223,7 @@ static inline void __update_iostat_latency(struct bio_iostat_ctx *iostat_ctx, return; ts_diff = jiffies - iostat_ctx->submit_ts; - if (iotype >= META_FLUSH) + if (iotype == META_FLUSH) iotype = META; if (rw == 0) { @@ -235,6 +235,11 @@ static inline void __update_iostat_latency(struct bio_iostat_ctx *iostat_ctx, idx = WRITE_ASYNC_IO; } + if (iotype >= NR_PAGE_TYPE) { + f2fs_bug_on(sbi, 1); + return; + } + spin_lock_irqsave(&sbi->iostat_lat_lock, flags); io_lat->sum_lat[idx][iotype] += ts_diff; io_lat->bio_cnt[idx][iotype]++; From patchwork Mon Jan 16 13:02:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangtao Li X-Patchwork-Id: 13103015 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C295FC46467 for ; Mon, 16 Jan 2023 13:02:48 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1pHP8R-0004my-0V; Mon, 16 Jan 2023 13:02:46 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pHP8O-0004mr-QA for linux-f2fs-devel@lists.sourceforge.net; Mon, 16 Jan 2023 13:02:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=MIME-Version:Content-Type:Content-Transfer-Encoding :Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=LD/fWeUHjzYE+WRwzmlLxSCP9GEFOqaTeuks0H5w1hY=; b=MuZNLNdjnPXegnJNW5xnySsBvQ rERQ7i5LO2cMwcw7xQYQPG4NMF7n2sS2myD+bt2hc3rV2qOcFS1G3orUA+bsuTmIn559R1jYCsNkB EOjYeiSTEkd/86wQWdq5kgmFiPE0+nsxKyHKUZS5E+MIDI4e3+WQZStsdrix5w1UoZ+M=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=LD/fWeUHjzYE+WRwzmlLxSCP9GEFOqaTeuks0H5w1hY=; b=a D3D8oYewiUYVzeoFZ8GmkWPq4x1JbPR08L7PyHXtIzeFm68sZqCwOFOjX2BFzg43UhiP2goiWZcHv woTJCIClSdEy8nj/EFupTHek8qr250DTYLR9OY5xO15JLu8pTDxXCiqOD7OkrWiTLXMUb1C3ugpZg tsZuAYZhYayw6KbA=; Received: from mail-tyzapc01on2110.outbound.protection.outlook.com ([40.107.117.110] helo=APC01-TYZ-obe.outbound.protection.outlook.com) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1pHP8N-0007q6-Es for linux-f2fs-devel@lists.sourceforge.net; Mon, 16 Jan 2023 13:02:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m3q6xPiOHrqaE8vFIarW2NMhPF34LDQjYt0PP5E7frEXEuYIGGjaKQx9K0FIWWCjAjkXev2LoHsjDvykULxDv76vIc50F+a+B/H4jlDFaKqPt9Eo/2TGTFZ9w0C/JpcR0PuMZr+u6mYCnp2S7CrYbo7kRfrhq68999VmFuX/EoLXAWS3FHKjcQIXPvCTH68/6wtj5cEDbtsCtWhgpOYZ8vLFlDTjK38jQdpj5aDZfN46hI/8lNLi1ZM8N+C5bioJvtWceAeigeg1Dd/SpGirum+Xkj6ll0tFHIQAGunR+orcBZI9yWTba6AUKRpf9SeSg5k9sivCOWF8G9nvFY6UHA== 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=LD/fWeUHjzYE+WRwzmlLxSCP9GEFOqaTeuks0H5w1hY=; b=g0mOksktLBHKTQtG/ykf7H8PhbRdEwYjZROZjv62PsnVl7nRY1jzwbMwvkd4MLklZ+PJtJ+NkP5MRWcj1RTWqhHbKt0HwHTA7Bl8ai14qrDhLYHBCze9qB80fr1qJMC3SFye79tg0EFLegLEVwyJD0jehRLEGMZ0qj1FYszN/KtCzYyCex0qc/db9KkANzhT2OIx6Fj5/LlAoS7ytJnQesuQyYXba7p9IeSE/lNjJxyMYiNxUyHhksuLmpdZ9EqoaUBL8ZZvr2vh7CHUsm0H4Tr4ursmX7SvyLZibLH6uenTz1rMopj6KltsD91by6hbM1IiFmx75lcqHi+xOU3TtQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LD/fWeUHjzYE+WRwzmlLxSCP9GEFOqaTeuks0H5w1hY=; b=SM5UG69RCE4CgJoWWas4aWvOaAsq2D6NMzeszfLUHzrG/psK8O9GfrFSEjoPvVl6YEjFMLBX/8kffQ2KyO4Evrw4eWJ24OfmMvDcS2FGhqv17OWFaRClS0+PSFVjSEG79S1efaz+dHhcylNkgEA9ZVr8DE8ltDbu7qlgOEwJJma3I/AdZgV8orlsNqE0bQNOm3KJox7tnNZ2ayked0ilntFtMLAo91gwykMGu11myjotcpMZbDEX3SOMZQseJoqZpKVe/NfDuEkXsXN2oCoGyeaxS2SKDxaNIWViEN0uPvGmdP3thy/d6L3lco5W93F9TPZuCrr2qqaxfit+Y1R/fQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) by SI2PR06MB4251.apcprd06.prod.outlook.com (2603:1096:4:154::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.11; Mon, 16 Jan 2023 13:02:35 +0000 Received: from SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::3e52:d08c:ecf4:d572]) by SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::3e52:d08c:ecf4:d572%5]) with mapi id 15.20.6002.012; Mon, 16 Jan 2023 13:02:35 +0000 To: jaegeuk@kernel.org, chao@kernel.org Date: Mon, 16 Jan 2023 21:02:25 +0800 Message-Id: <20230116130225.34600-1-frank.li@vivo.com> X-Mailer: git-send-email 2.35.1 X-ClientProxiedBy: SG2P153CA0054.APCP153.PROD.OUTLOOK.COM (2603:1096:4:c6::23) To SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEZPR06MB5269:EE_|SI2PR06MB4251:EE_ X-MS-Office365-Filtering-Correlation-Id: 4ed2704a-8bcc-4fd4-f5ce-08daf7c1f02c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oRrFugrkq18RlDKdsOoLwk2VbiP3wuvW/iY+yH6C1rigEpo2754LdiKJMVCeTYWgbZP7DtjoGfVhOe2W225PinHlZHIObOmrXuvINQpSyKLDM3IAjYfQMelVkHU0MLP7DrN3GdFaF1Sk1TU9q53PMp/wSasQh7c3wg+O49NI8Gxr7RmDwLZXRwQkIhVJBRdwJAcDNm5/RYGJMe4BtZ4pb1LsS/05mXkQFA256VY05Yvto+1pnkk+NHRiiWn7HIZwgbMgInxfaNTdAT8dCQuvLMHWXqqZy/LVy/OEyBAbjmMVUqwsNLXuwh/qRvWOOeDx78AC6kRAaQu8bx+cS7rotTQEVNN/p43qiPPmk+GgFD2osj1I2HaHL9+YEwMP66qlBb4HRJgxTCaAKB2mrVhV/s8+97gmiHkUPicAsbfIYD0Fn1DaFuSy2rYNMBUx5zjsxSTmZQ+H7uProLhOC5W/iKUaoEv/M9u7qOjnOsm4wmEUZtx7TqmdrUF9+LAvq3QRtP3KfIoi564sjBsy1imggrKvrd5Y69pOmh/mw4j6Dtz60wGm2nP4wTdDwwzUGQ/i+521c8250JrAfaWtcBTPokNANRXWHMoGwGLcEw4VDCQbaKQkqJOBGLBZdvmMa03bsPFjRD4JT2USN2Yho4IoNRuZgwW5sKKQQGbl8+n1bWfX0rKkPFNieBimlbMVY7GP2Vuwi0DW5ggf9YS2t6NAwg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SEZPR06MB5269.apcprd06.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(396003)(346002)(376002)(366004)(39860400002)(136003)(451199015)(36756003)(86362001)(6512007)(186003)(26005)(4326008)(8676002)(66556008)(41300700001)(66946007)(2616005)(66476007)(316002)(52116002)(6506007)(1076003)(478600001)(6666004)(54906003)(6486002)(2906002)(38100700002)(38350700002)(83380400001)(5660300002)(8936002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: a0wnBheJLXLU7jS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JpW5npU+h5T0x6s8Yq1qOIopRsXsd4PNAk4Rl7OqnzPXDNiisqPrunitka2jc6dtQFRei5+h2v73YrtjrWh+qZRZ/WqzGlRjPW7uGpWVb7uWb1a1IPQcSQcHXzll2Qa/uE5zIrCITFkSLScjkY9hWT4Pnw75lZym7QOyWShC2TIzMPZPgAI2HJj9iNcEjv9MeHgoWZ9MYuidaF4zpUml4X/blCC+2gZlrmj8XfvhAQEiPTF4uSzRAcoIOhjMBWoYNiXJGtlFzapzyyh22qWPvOxsLdALj3yH7PqRUeyv0WKxTj43tMhiB8ueklU+x1fXpfd3cEnN/4PyfsPMXTrCDwhG6zY5xTY0lJ7zntxdPAscnfwBFNxJcWa0N665K2s68kbfHb1RzNXHkBetpF4E10y8vuje4a9ksrsNY5M0wvcJLjnBnLijMcWWPafVqeotqSQKO91xUAfhuBXI5BPqr9WVtrYvxLfw4/4pL8FkCFHDs4NpXX9z3/ X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4ed2704a-8bcc-4fd4-f5ce-08daf7c1f02c X-MS-Exchange-CrossTenant-AuthSource: SEZPR06MB5269.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2023 13:02:35.8604 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: rguwMTYMihRZq4TJukKRZAmlYzWuUACtc+DMwRmS40bP1asIz2XZ9Ws0iDv1qt8x3WeTqt0T4ju+OGF6Jq5RBg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SI2PR06MB4251 X-Headers-End: 1pHP8N-0007q6-Es Subject: [f2fs-dev] [PATCH v2 2/2] f2fs: use iostat_lat_type directly as a parameter in the iostat_update_and_unbind_ctx() X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Yangtao Li via Linux-f2fs-devel From: Yangtao Li Reply-To: Yangtao Li Cc: kernel test robot , Yangtao Li , Dan Carpenter , linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net Convert to use iostat_lat_type as parameter instead of raw number. BTW, move NUM_PREALLOC_IOSTAT_CTXS to the header file, and rename iotype to page_type to match the definition. Reported-by: kernel test robot Reported-by: Dan Carpenter Signed-off-by: Yangtao Li --- fs/f2fs/data.c | 4 ++-- fs/f2fs/iostat.c | 36 ++++++++++++------------------------ fs/f2fs/iostat.h | 19 ++++++++++--------- 3 files changed, 24 insertions(+), 35 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index c940da1c540f..6153647d93b0 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -292,7 +292,7 @@ static void f2fs_read_end_io(struct bio *bio) struct bio_post_read_ctx *ctx; bool intask = in_task(); - iostat_update_and_unbind_ctx(bio, 0); + iostat_update_and_unbind_ctx(bio, READ_IO); ctx = bio->bi_private; if (time_to_inject(sbi, FAULT_READ_IO)) @@ -330,7 +330,7 @@ static void f2fs_write_end_io(struct bio *bio) struct bio_vec *bvec; struct bvec_iter_all iter_all; - iostat_update_and_unbind_ctx(bio, 1); + iostat_update_and_unbind_ctx(bio, bio->bi_opf & REQ_SYNC ? WRITE_SYNC_IO : WRITE_ASYNC_IO); sbi = bio->bi_private; if (time_to_inject(sbi, FAULT_WRITE_IO)) diff --git a/fs/f2fs/iostat.c b/fs/f2fs/iostat.c index e9a3df7ce4d9..bc6a9c80a026 100644 --- a/fs/f2fs/iostat.c +++ b/fs/f2fs/iostat.c @@ -14,7 +14,6 @@ #include "iostat.h" #include -#define NUM_PREALLOC_IOSTAT_CTXS 128 static struct kmem_cache *bio_iostat_ctx_cache; static mempool_t *bio_iostat_ctx_pool; @@ -210,54 +209,43 @@ void f2fs_update_iostat(struct f2fs_sb_info *sbi, struct inode *inode, } static inline void __update_iostat_latency(struct bio_iostat_ctx *iostat_ctx, - int rw, bool is_sync) + enum iostat_lat_type lat_type) { unsigned long ts_diff; - unsigned int iotype = iostat_ctx->type; + unsigned int page_type = iostat_ctx->type; struct f2fs_sb_info *sbi = iostat_ctx->sbi; struct iostat_lat_info *io_lat = sbi->iostat_io_lat; - int idx; unsigned long flags; if (!sbi->iostat_enable) return; ts_diff = jiffies - iostat_ctx->submit_ts; - if (iotype == META_FLUSH) - iotype = META; - - if (rw == 0) { - idx = READ_IO; - } else { - if (is_sync) - idx = WRITE_SYNC_IO; - else - idx = WRITE_ASYNC_IO; - } + if (page_type == META_FLUSH) + page_type = META; - if (iotype >= NR_PAGE_TYPE) { + if (lat_type >= MAX_IO_TYPE || page_type >= NR_PAGE_TYPE) { f2fs_bug_on(sbi, 1); return; } spin_lock_irqsave(&sbi->iostat_lat_lock, flags); - io_lat->sum_lat[idx][iotype] += ts_diff; - io_lat->bio_cnt[idx][iotype]++; - if (ts_diff > io_lat->peak_lat[idx][iotype]) - io_lat->peak_lat[idx][iotype] = ts_diff; + io_lat->sum_lat[lat_type][page_type] += ts_diff; + io_lat->bio_cnt[lat_type][page_type]++; + if (ts_diff > io_lat->peak_lat[lat_type][page_type]) + io_lat->peak_lat[lat_type][page_type] = ts_diff; spin_unlock_irqrestore(&sbi->iostat_lat_lock, flags); } -void iostat_update_and_unbind_ctx(struct bio *bio, int rw) +void iostat_update_and_unbind_ctx(struct bio *bio, enum iostat_lat_type lat_type) { struct bio_iostat_ctx *iostat_ctx = bio->bi_private; - bool is_sync = bio->bi_opf & REQ_SYNC; - if (rw == 0) + if (lat_type == READ_IO) bio->bi_private = iostat_ctx->post_read_ctx; else bio->bi_private = iostat_ctx->sbi; - __update_iostat_latency(iostat_ctx, rw, is_sync); + __update_iostat_latency(iostat_ctx, lat_type); mempool_free(iostat_ctx, bio_iostat_ctx_pool); } diff --git a/fs/f2fs/iostat.h b/fs/f2fs/iostat.h index 2c048307b6e0..1f827a2fe6b2 100644 --- a/fs/f2fs/iostat.h +++ b/fs/f2fs/iostat.h @@ -8,20 +8,21 @@ struct bio_post_read_ctx; +enum iostat_lat_type { + READ_IO = 0, + WRITE_SYNC_IO, + WRITE_ASYNC_IO, + MAX_IO_TYPE, +}; + #ifdef CONFIG_F2FS_IOSTAT +#define NUM_PREALLOC_IOSTAT_CTXS 128 #define DEFAULT_IOSTAT_PERIOD_MS 3000 #define MIN_IOSTAT_PERIOD_MS 100 /* maximum period of iostat tracing is 1 day */ #define MAX_IOSTAT_PERIOD_MS 8640000 -enum { - READ_IO, - WRITE_SYNC_IO, - WRITE_ASYNC_IO, - MAX_IO_TYPE, -}; - struct iostat_lat_info { unsigned long sum_lat[MAX_IO_TYPE][NR_PAGE_TYPE]; /* sum of io latencies */ unsigned long peak_lat[MAX_IO_TYPE][NR_PAGE_TYPE]; /* peak io latency */ @@ -57,7 +58,7 @@ static inline struct bio_post_read_ctx *get_post_read_ctx(struct bio *bio) return iostat_ctx->post_read_ctx; } -extern void iostat_update_and_unbind_ctx(struct bio *bio, int rw); +extern void iostat_update_and_unbind_ctx(struct bio *bio, enum iostat_lat_type type); extern void iostat_alloc_and_bind_ctx(struct f2fs_sb_info *sbi, struct bio *bio, struct bio_post_read_ctx *ctx); extern int f2fs_init_iostat_processing(void); @@ -67,7 +68,7 @@ extern void f2fs_destroy_iostat(struct f2fs_sb_info *sbi); #else static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi, struct inode *inode, enum iostat_type type, unsigned long long io_bytes) {} -static inline void iostat_update_and_unbind_ctx(struct bio *bio, int rw) {} +static inline void iostat_update_and_unbind_ctx(struct bio *bio, enum iostat_lat_type type) {} static inline void iostat_alloc_and_bind_ctx(struct f2fs_sb_info *sbi, struct bio *bio, struct bio_post_read_ctx *ctx) {} static inline void iostat_update_submit_ctx(struct bio *bio,