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: =?utf-8?b?5p2O5oms6Z+s?= X-Patchwork-Id: 44126 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1182627wrn; Mon, 16 Jan 2023 05:10:00 -0800 (PST) X-Google-Smtp-Source: AMrXdXsSr3zzg7e/WnhRy+Eh4J6gLjiL3zB3M7bmu8ej1ZQGhHAXDTohKX3kdSvFF0vr00huZM0u X-Received: by 2002:aa7:d7d9:0:b0:478:5688:7c9f with SMTP id e25-20020aa7d7d9000000b0047856887c9fmr8933332eds.29.1673874600107; Mon, 16 Jan 2023 05:10:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1673874600; cv=pass; d=google.com; s=arc-20160816; b=umDPdErx8p2zE0vRpVhG9btl3xkv0Y8MlN/6u1QyJtMZwjOPP6158bbtr41uMd8tyJ 1mowZW1glEJqb2K/+qYgku6+1Bwvcv5AoDN6/gKVyFWvrYqduGiWsPeOAeNQHf3OLsVe ptyHXDrdrZ2tl76WwcQvZd6RWKaT21hbpb3jRVdAdiDD3i18z45FFpDVbDrgpB/lQBfG 117MAW1lTdglMGqX9aDUpgKEtW2AN9R9jvuYxWeCBOJsqk/ZT/+4rMPHG5rE2Asqqyxk unjyxIMr6eFC/DdfQN7prdDEGz9CZeMkv+i9xr1xjALMvA82dNi8n+dep1M2U5n5IcBT JRjw== 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=f36cEWbdgA4BZW8xHZW2RLhdOIn2TffiaahwF6T7uf0=; b=aVsJFewn9ARDh0IyDNQYGqhSanxzeFcT1GiF0wouLxfkIxgepFR9qQjUIMEGx+cY94 I8SU+Kn5JLFHet3yOP+R+ZAXtpCrip5UGYSc+Ijm+eUNwU7teaZrXH+uhUqKnj7cVa6J LsjIT9h2QIlC73/NQ2LaPlJzzU427ylBrW4+Fko/rDsfKZVODmtgrHLPcI6CzBXyvZxC 3Ne48BaIO1sbAW4WWtzXkR0RROJGLjr5Pp9PiiDdusW3aeinxitzfpOCv3duunmx9fjt ZlmqsuvaFGwKtjNhiRrp9Ju8oFJlS3y7bZYQ/6boXXIsrl68QKgLCqNtHAZZrJ9Eme+5 okrg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=KqslN3L2; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p11-20020a056402500b00b004948ab74664si30137233eda.106.2023.01.16.05.09.36; Mon, 16 Jan 2023 05:10:00 -0800 (PST) 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=@vivo.com header.s=selector2 header.b=KqslN3L2; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231322AbjAPNE3 (ORCPT + 99 others); Mon, 16 Jan 2023 08:04:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231216AbjAPNDJ (ORCPT ); Mon, 16 Jan 2023 08:03:09 -0500 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2105.outbound.protection.outlook.com [40.107.117.105]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25F24468D for ; Mon, 16 Jan 2023 05:02:26 -0800 (PST) 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 From: Yangtao Li To: jaegeuk@kernel.org, chao@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Yangtao Li , kernel test robot , Dan Carpenter Subject: [PATCH v2 1/2] f2fs: fix to avoid potential memory corruption in __update_iostat_latency() 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/ppU8VM782PqSN9zZL2oWkwc7CRkJ4ewcUMhLldbpySZgKYe9Xh+2J1YPpe0VGCcQzbFAFLKIFB7LkfB4o1S1x2SYTcEdfbh9nJdIEgALJopFYfsNJvuc1RSbQiX/k7cZ1+LIibDGro6lly5VRnRDzWp9G9/rENt0juW1aKv6T7FnNDr3ql/HdiQW8vJUy+QaEykbC9S6Rr/Yp3R3mXZKHDQvyrBdMpcJYYRn/i2bFQ9RjV1fwd71Q3WQodDi0/yftmB0OgaRC96GQcO5OeskmApAjs9H8M9evVc7NqriM8H68y1Wk0wjA3x3t90CRNttGjgRR/dy66EqiD2dAz1b+ALRvYdcdqESltG/0+/eEr72wzXlRMwFeLe3TPfFyg/QJeT4g/BnM8yed+/4QsNATceIaSpHNH5ld5fYXU6XwIrlndsG61EW7kcwI+YbCzwOeMHIHG4+W/86nVbi944DuEnfQRHpKdkR0cv8si91BkqiNCq02Wn82F087wkUTT5j37H0H1qQ2ms9CeaUa4EGSO6yWs6Q/HxwNNclqoFNhH8DC8/vweYUjDpYDjyc4G/9LCl9Kc0vtw4m1KbN/Ky6vHmRa+iH4vJCOvvYbZ5pU3P7PvgsitpvcdtNdVmZF4DdwtMM28ZQ4WKg/i7/MBsH7YnVVSWfZgrVgqz4ElCL/oyTQGLgVH72BrkDGBQphoiXdJ3a3w1K0hKDEhKw0SOwYaWR07bKf9U5fJ6wUFAKQD6VccGjLE+kKLuYrhTXknRoiHDyINri6DB0IMg9PB5lBTqPUkpWP+gc8RVfh3fap9alykK5kxP7URizQBzgJQwNR9+6cRSPRUhUShXDmJas8o4iILpjvLM4M9qQAQ5iA+j2oMDVchUhii1H+omQZQJan2v1ytwAJe0R/4lyvKU/g4xb1WhdoMW+VNmWdHV4El0PvaKkdDNWvax+dERqn6AeU3/LBfIo5tNKnySN3mAhpxA1kgvMndlmA8ohPu8iEPvntNI5T4HIC2YHBqM0qEgrDVca+FMAqcfUJH1qsCdWSha7CEXracZSsngC4DqQ6nnG+nh5H9yMdIwEHhUxKfmuO6UlPI0lQn5c0rR3inuyivJVolTFC8QaR1ES8VgNncRyzCGSt7pWCjr4JbVhkXXavaeI+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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,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?1755184733004930433?= X-GMAIL-MSGID: =?utf-8?q?1755184733004930433?= 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: =?utf-8?b?5p2O5oms6Z+s?= X-Patchwork-Id: 44127 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1182700wrn; Mon, 16 Jan 2023 05:10:06 -0800 (PST) X-Google-Smtp-Source: AMrXdXsG9fjcvhD7DjPCgOqiVy/0z1zU1d3pS8mAv/kKpJSxItF6BR/viVJ8kx+xnf4yO92uikUV X-Received: by 2002:a17:906:3bcb:b0:86e:3531:555f with SMTP id v11-20020a1709063bcb00b0086e3531555fmr6349681ejf.32.1673874606520; Mon, 16 Jan 2023 05:10:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1673874606; cv=pass; d=google.com; s=arc-20160816; b=TbZWePKE4tIfGZa+RAZ9EplHo/3xedfuQunvQbtolZ3jcYfm+biMSqLti5D//Ectv8 i27fl8ur7S9kr1OA/wdQyk6wFDeSLAOFHe3Y80+fCtaM07notTcBreQRAsf4qgUsivJG /ESjmsZBthokKNBmrXBe+4sG9//jAdnhJfxP743dPtzWjqkVdgmAXkT0PABcJtW3w2AO KKBOUJmh+rBDdRZR8CHcAPscqP5K0cxb+go3YlV84zWy1jjIgZUlHPobv0UyKHdX4MZZ 5oa4s4VlPALbK6JIgJ18AatVIZBzjH6WMR5hWF5L1kvnZEZRM0S0TqWLwyaA/Z833h2N omwA== 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=LD/fWeUHjzYE+WRwzmlLxSCP9GEFOqaTeuks0H5w1hY=; b=vnJi1uPtNdHk3zLVfjt8AiBny+OjFzYHZG7bxOr/L59XugrY5B7GSt9KVVYXB2pcON G84N00Bn/i6Vt1yvJ0EfwVc7Hdd0vXdf0XfuVcJ43T0pd4/TdxYqmqbRlcBwPlEC6wKp jwl/kyiQFU2ZLeD2jVUY3CucwHJggg/SiFQ0UJKJfNYj9YoP7hvt7NQH8cJfDilUip8C hCf7J6ItFJ5I2rESkz3yGydP54EDqXEGrRWyOgR+Ptc6TMzh6GF5Py9AycCDs83URNYc eV1LzNQwy2hcsYFHGQVasoE4ztqk9vUTrnT9OhZSILdNvmvVFHLGoRNHMgRQQNhNPakE OhGg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=SM5UG69R; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dm3-20020a170907948300b007c157940720si28635062ejc.440.2023.01.16.05.09.43; Mon, 16 Jan 2023 05:10:06 -0800 (PST) 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=@vivo.com header.s=selector2 header.b=SM5UG69R; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231187AbjAPNEg (ORCPT + 99 others); Mon, 16 Jan 2023 08:04:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231410AbjAPNDS (ORCPT ); Mon, 16 Jan 2023 08:03:18 -0500 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2128.outbound.protection.outlook.com [40.107.117.128]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18DD71204F for ; Mon, 16 Jan 2023 05:02:38 -0800 (PST) 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 From: Yangtao Li To: jaegeuk@kernel.org, chao@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Yangtao Li , kernel test robot , Dan Carpenter Subject: [PATCH v2 2/2] f2fs: use iostat_lat_type directly as a parameter in the iostat_update_and_unbind_ctx() 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: a0wnBheJLXLU7jSjhnX9nbTHEEbLPiqEGUhcPj4YRHyYtDA1skEh3Ybb+qRzJQl08jRsL2bWXEakp63L7PlvHH31er3CO8aLN09cDwBTvPz0HWV5//4FF4egLACuCKRYfB6eBO9MHUdUdc80RYv6AM3caoWMbwpbRozOIE34JuB1ef0+I65sXWerhu0mC5rQXU+zu4zgaGpTkzV/EMAKUOmA19to6ZmpFclLTsLo4zrO/5lKyKTSfTfHpWviF4J+K9syAORIqHsinkjbTkD+i8l/bsC22D48uESOJBgjrBSy5BHIAi5VwuzQZzd9Um+mNtbCOrcadXLfoMAnyn14NIlAxCp9laHcFmcosPImVpZXw566vx45kQKk5in4uc/k6fJLgi1t5C4Cw/SN5vNcUcDH2X8ZGvKrnMZEkjnb1vIGIVnWHcw2mTwEXOjI9TULpXe70x1RJSsYt9CKsk7uVXqT8Tk/SdPWkwP03h4OmWHCPpn8o7MR/SnMBFt4dpGmZqmAS5J3kHheHxkUs6r9MJydL62ibho8faQ5tYWei7xwJK26l8kKCYppSyMTkVCgFNnXHRUG+oQTQazmu8ukmj2QIgjBDXmxCiiIILnZpWzxYuOOPPnWU3/HNMC/kEj2C5i/Qc9tEAAt641oPzAYQwfGxjWXk5svhZoUb2nuZlIpfknpcoCzz6eBzR/ig5VteHka8hPabEGVvLGSMxvM9P1x6NcQk6wWr9Sce4OlkQqx/T9B9y2Mo5Xlq5uP270rZBaLHpbYq4Xh0i/nlTJ/D2ONO6/lJdvWKFmVfkBH/5q4m5VPijNk4N19/P6EPQo4elORLErDEQ0ANgPZUIoZcwgS3X7rOtKBVEyX805enmlyUcguh2Iyx/THXs+fyQ0ww9rZ9A8FZ02vTRJUYzUv+3h1t42EwE3aHqye5k+ZhRJtkbE7/hqgw3rpRB9W6ujXJHIds95y3X2Ng2pUnTA6YTom7yR/30NN/H0fLjawvm+rklXUvI29BgG8XBKi4hjcxEF6kYz4sF62LDxAH0BFYLiQrtm3YXpx2ktoQb9PqibGk3wEdSPsE4Hvi+cEA+Wbc/rsaVq9/bJpW5npU+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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,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?1755184739257769502?= X-GMAIL-MSGID: =?utf-8?q?1755184739257769502?= 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,