From patchwork Thu Jun 6 16:12:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ofir Gal X-Patchwork-Id: 13688755 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2104.outbound.protection.outlook.com [40.107.7.104]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C19FD947A; Thu, 6 Jun 2024 16:12:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.7.104 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717690357; cv=fail; b=mzhQGYBtr+eBM0bW1Xsij+XEsr2HVttYsMUE8c04WB8hSfXDoRr7gk4kBQQjAO75EaNxAUcyqd4/xk2NbBKxOJb5J4f2o/7q+TlNH9MDTUXsZZbAl38iUsIh+xHMYqGPlk6gAm7cjzPnflrDN3ACP/9tjE/G7vYCZU+IBsY7p08= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717690357; c=relaxed/simple; bh=HCroDG5itaNt1moOR85LhTsQHE1o7zA0xUTZBHyhrEs=; h=From:To:Cc:Subject:Date:Message-ID:Content-Type:MIME-Version; b=tGNcaRMEAxFY6yoGNd1f6JRsSqt8sad6SK1ZmOF/BZz7YeL0EajMlAlKESrorcvCR95zwdeSCygmDjMQcbyFI5zDwmRp2Gh0J+anibpetrEZy62DcFqzxmX/EqBqAsQGGYCmjWk0/U1TXZ/Wg7qX8M3qMJ+41wgcp1S5q3fcaZ0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=volumez.com; spf=pass smtp.mailfrom=volumez.com; dkim=pass (2048-bit key) header.d=storingio.onmicrosoft.com header.i=@storingio.onmicrosoft.com header.b=abEI+9vx; arc=fail smtp.client-ip=40.107.7.104 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=volumez.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=volumez.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=storingio.onmicrosoft.com header.i=@storingio.onmicrosoft.com header.b="abEI+9vx" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FKWXPxuKiVfNGkpgyQKWSDOruvn0lKqQTSTnsrJ0vGsPDTZbsX/AiH6aukepDb4Jns/plF7Os+kQZSNDGy0tKNDJrAqr0iC0AKXmCveVN3rZuzOJSnmQYLIfST9njLDgRVBLlSoXJgHE05PGrsc0CilPWD3v5D3Rthz7R7BE+wlWZlpYi/dLWUO8ZbZwefX3kdgnb6x03apPoDuz7y6h4Wt64tfVZT0eEDwgeQ9RnHUqQM+tLU4Cp9TNTCMWRWCBC6nRigH54NvPcKZc/qBC5Qf0nDL94AJKBzYX5gZ7tMvR5ijHn6cUcxFPNdq37EUP1mY8rT2LX8Qgc9kGgjGDqw== 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=uFIG2PIf+zrG95p1W83U82nH4ppR/MDBZY9tN1VXlNs=; b=XRgsZB6X92DF7WPTJgR/M8xeIZwqA8Bx8f3nLK0Q45EVaeyQ6nL0AfUJeG2Ebwy+ZYnSQZ2NkFVYa0DtY1HaEM7H16R/tjriiQUnTlXFRkhyXfJKOH0yGw/xxG4pfy19sReyvEzXsYTxEo7M/GR2xtmpY00fIJO7mFGs8qnupU8au08lLFhtAjPzVgJKwpgH6WwVwSfqnqHZBAo8L8jR6oU/sJe44AIn7NjwTwfGNYPbfwcotBV4j9exYkwhZmrxHitvi38/tN4P0Ab/MIv8fwf8EMck1XCDpzPxO3CR2Y/LhTxoQKAxU5eAflIqpMT0NlzLOUdtekQ2CCF5LlF+/g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=volumez.com; dmarc=pass action=none header.from=volumez.com; dkim=pass header.d=volumez.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=storingio.onmicrosoft.com; s=selector1-storingio-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uFIG2PIf+zrG95p1W83U82nH4ppR/MDBZY9tN1VXlNs=; b=abEI+9vxzlifdvI8uoiOaRjbu/eFRGyN2vZoVC12zx4vdFEtprSey01YfXy9yoJR2AlhXlbQXiobtYEc7Z53TCSN4XyQbGJX1Mwsc1My1y+4WxIUWD43JSm7OfmR6jMPMzRPQJx02rq7RceTnuqMe+ykuapJAae7826d0vVhPMcROMYfQz0mIDtKJXuFymB0g6hqmB3q4WhuRIEW6B188b012s4niiyxonOd3dyhOxnORsjwHW3JZy2nSMbTmbM4bdipQ+hoDnAryi6JGFgDpcCSAWUKRHHnd/6NQrDLS+y1Cr7v2aRJsdn6QiSLUHQ+9JkouFnReJV71dKxFORvaQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=volumez.com; Received: from AM0PR04MB5107.eurprd04.prod.outlook.com (2603:10a6:208:cb::11) by AS8PR04MB7815.eurprd04.prod.outlook.com (2603:10a6:20b:28a::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.33; Thu, 6 Jun 2024 16:12:31 +0000 Received: from AM0PR04MB5107.eurprd04.prod.outlook.com ([fe80::de53:c058:7ef:21fb]) by AM0PR04MB5107.eurprd04.prod.outlook.com ([fe80::de53:c058:7ef:21fb%4]) with mapi id 15.20.7633.021; Thu, 6 Jun 2024 16:12:31 +0000 From: Ofir Gal To: davem@davemloft.net, linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, netdev@vger.kernel.org, ceph-devel@vger.kernel.org Cc: dhowells@redhat.com, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, kbusch@kernel.org, axboe@kernel.dk, hch@lst.de, sagi@grimberg.me, philipp.reisner@linbit.com, lars.ellenberg@linbit.com, christoph.boehmwalder@linbit.com, idryomov@gmail.com, xiubli@redhat.com Subject: [PATCH v3 0/4] bugfix: Introduce sendpages_ok() to check sendpage_ok() on contiguous pages Date: Thu, 6 Jun 2024 19:12:12 +0300 Message-ID: <20240606161219.2745817-1-ofir.gal@volumez.com> X-Mailer: git-send-email 2.45.1 X-ClientProxiedBy: TL0P290CA0009.ISRP290.PROD.OUTLOOK.COM (2603:1096:950:5::6) To AM0PR04MB5107.eurprd04.prod.outlook.com (2603:10a6:208:cb::11) Precedence: bulk X-Mailing-List: ceph-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB5107:EE_|AS8PR04MB7815:EE_ X-MS-Office365-Filtering-Correlation-Id: d5b66dfa-8c9a-46cf-5f3c-08dc864377f9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|376005|1800799015|52116005|366007|38350700005; X-Microsoft-Antispam-Message-Info: =?utf-8?q?53eyUaySW/dMRLMNFrppQsJncPQD4/R?= =?utf-8?q?uzPxvO0Z74JrEkIjBa+hIkVAuu7yXeTW4TPoapC4JHwm1Pkdk4C5X5tBZXbQrys3F?= =?utf-8?q?XQGy97sB6Yt+Ud+xwgkN47csnnim61juZIGdPUxfN1u90Ww1qDP5ZPH9gdQ2ft42J?= =?utf-8?q?9o0hdSGvwvGzoaQFPfSiUIAF/1KaITSM/aU12Ort/s7Q86A+WoeSvDe4ljhnRZxCk?= =?utf-8?q?PFvHgYbK9HhLV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+RzsBSUSJCj3Y6I4OCj9kgIKRXlER8hBegt9Q5zTJKiJeWBU?= =?utf-8?q?mHnVM4WlBzvCWlOX4Dkal5kz+qRTUxCbR31V+ES+PIbT60lIutM1vTtn3jx/0p+71?= =?utf-8?q?xHifJegc8qlO0mwZCPk2Iq8YPJ2JNRuQik27Dos9xPZtNE7w1KY3pqmslMDvjNjdc?= =?utf-8?q?DJLs9r8z2X96XX4eSiVGGR1NA4zFiOQFEt/YQeVZjdsZtHCC07TN2uLY=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB5107.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(7416005)(376005)(1800799015)(52116005)(366007)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?nZFZSy3sWtI4B+PXNl63/37JUcEx?= =?utf-8?q?4GiNbys7XvTbF5KdzWWfWiZf7Fnd1t/CLDkDnig22/IpEwKEh/f1tSjZzfSGEasTJ?= =?utf-8?q?/2/LZb7PZdm+/fG1ZBUn2fsZ5721NFVf1LT/IzM0Q67oZPVfZCCHV+qJ5dweVFQmx?= =?utf-8?q?M12UNkvJ1XfDLK0BKkNT4cGpk26vXQIJeKsZd8Q0GaQ9owh4HF5+7B3APz0mNsT2W?= =?utf-8?q?zYqkfXHP2idzSIzcJBsg5A+hwnUqJc3ZrMjp5kW+Vpz4dJ/GPOmqycZ8pjS801Klc?= =?utf-8?q?P2FdGGLENA0pAqPh3lMg6pZE55n5lZTtzbNovAQzoXRrz8GwHOLcqID2NmQxdnITh?= =?utf-8?q?9EotUGOGShDH72kZbju0KHSVS73igHgoQK0X/gWbZHP+r1edPuDl7Zta7/e2FxscD?= =?utf-8?q?1gUYYpGInnsnk1vnIS0CR4bIGuIsjsy1MGYMAQvBlOxSQJaFjDnZ4+zFy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8?q?ADekqhKygbTlX0lXr3ujAQKJoRdrYX3AdMFcPGQzC+EVNITMT+6obpWt2E8Cck6b4?= =?utf-8?q?8lWu0EtspxqOx0pDaKZ3jU8VQ9zbKwnre8uHkcIf2vzQMdyDn3i8CuomYlA38fAFn?= =?utf-8?q?+kK5w4h/ce2aubLUYGrzitnnMNQfyDvAADtVZu8RUwDR7A5PHpVrglVhtxc3OBMFn?= =?utf-8?q?TORPkHyuW9Db?= X-OriginatorOrg: volumez.com X-MS-Exchange-CrossTenant-Network-Message-Id: d5b66dfa-8c9a-46cf-5f3c-08dc864377f9 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5107.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2024 16:12:31.5450 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b1841924-914b-4377-bb23-9f1fac784a1d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /L1tenLMGjnGtRlyogkI7rZ2pbMsA5DpGSubu0MwPymAZMhZxzYa34gDylYgYdr8OFvWRCB83IkM1FikHaMUnA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7815 skb_splice_from_iter() warns on !sendpage_ok() which results in nvme-tcp data transfer failure. This warning leads to hanging IO. nvme-tcp using sendpage_ok() to check the first page of an iterator in order to disable MSG_SPLICE_PAGES. The iterator can represent a list of contiguous pages. When MSG_SPLICE_PAGES is enabled skb_splice_from_iter() is being used, it requires all pages in the iterator to be sendable. skb_splice_from_iter() checks each page with sendpage_ok(). nvme_tcp_try_send_data() might allow MSG_SPLICE_PAGES when the first page is sendable, but the next one are not. skb_splice_from_iter() will attempt to send all the pages in the iterator. When reaching an unsendable page the IO will hang. The patch introduces a helper sendpages_ok(), it returns true if all the continuous pages are sendable. Drivers who want to send contiguous pages with MSG_SPLICE_PAGES may use this helper to check whether the page list is OK. If the helper does not return true, the driver should remove MSG_SPLICE_PAGES flag. The root cause of the bug is a bug in md-bitmap, it sends a pages that wasn't allocated for the bitmap. This cause the IO to be a mixture of slab and non slab pages. As Christoph Hellwig said in the v2, the issue can occur in similar cases due to IO merges. The bug is reproducible, in order to reproduce we need nvme-over-tcp controllers with optimal IO size bigger than PAGE_SIZE. Creating a raid with bitmap over those devices reproduces the bug. In order to simulate large optimal IO size you can use dm-stripe with a single device. Script to reproduce the issue on top of brd devices using dm-stripe is attached below (will be added as blktest). I have added 3 prints to test my theory. One in nvme_tcp_try_send_data() and two others in skb_splice_from_iter() the first before sendpage_ok() and the second on !sendpage_ok(), after the warning. ... nvme_tcp: sendpage_ok, page: 0x654eccd7 (pfn: 120755), len: 262144, offset: 0 skbuff: before sendpage_ok - i: 0. page: 0x654eccd7 (pfn: 120755) skbuff: before sendpage_ok - i: 1. page: 0x1666a4da (pfn: 120756) skbuff: before sendpage_ok - i: 2. page: 0x54f9f140 (pfn: 120757) WARNING: at net/core/skbuff.c:6848 skb_splice_from_iter+0x142/0x450 skbuff: !sendpage_ok - page: 0x54f9f140 (pfn: 120757). is_slab: 1, page_count: 1 ... stack trace: ... WARNING: at net/core/skbuff.c:6848 skb_splice_from_iter+0x141/0x450 Workqueue: nvme_tcp_wq nvme_tcp_io_work Call Trace: ? show_regs+0x6a/0x80 ? skb_splice_from_iter+0x141/0x450 ? __warn+0x8d/0x130 ? skb_splice_from_iter+0x141/0x450 ? report_bug+0x18c/0x1a0 ? handle_bug+0x40/0x70 ? exc_invalid_op+0x19/0x70 ? asm_exc_invalid_op+0x1b/0x20 ? skb_splice_from_iter+0x141/0x450 tcp_sendmsg_locked+0x39e/0xee0 ? _prb_read_valid+0x216/0x290 tcp_sendmsg+0x2d/0x50 inet_sendmsg+0x43/0x80 sock_sendmsg+0x102/0x130 ? vprintk_default+0x1d/0x30 ? vprintk+0x3c/0x70 ? _printk+0x58/0x80 nvme_tcp_try_send_data+0x17d/0x530 nvme_tcp_try_send+0x1b7/0x300 nvme_tcp_io_work+0x3c/0xc0 process_one_work+0x22e/0x420 worker_thread+0x50/0x3f0 ? __pfx_worker_thread+0x10/0x10 kthread+0xd6/0x100 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x3c/0x60 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1b/0x30 ... --- Changelog: v3, removed the ROUND_DIV_UP as sagi suggested. add reviewed tags from Christoph Hellwig, Hannes Reinecke and Christoph Böhmwalder. Add explanation to the root cause issue in the cover letter. v2, fix typo in patch subject Ofir Gal (4): net: introduce helper sendpages_ok() nvme-tcp: use sendpages_ok() instead of sendpage_ok() drbd: use sendpages_ok() instead of sendpage_ok() libceph: use sendpages_ok() instead of sendpage_ok() drivers/block/drbd/drbd_main.c | 2 +- drivers/nvme/host/tcp.c | 2 +- include/linux/net.h | 22 ++++++++++++++++++++++ net/ceph/messenger_v1.c | 2 +- net/ceph/messenger_v2.c | 2 +- 5 files changed, 26 insertions(+), 4 deletions(-) reproduce.sh | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100755 reproduce.sh diff --git a/reproduce.sh b/reproduce.sh new file mode 100755 index 000000000..8ae226b18 --- /dev/null +++ b/reproduce.sh @@ -0,0 +1,114 @@ +#!/usr/bin/env sh +# SPDX-License-Identifier: MIT + +set -e + +load_modules() { + modprobe nvme + modprobe nvme-tcp + modprobe nvmet + modprobe nvmet-tcp +} + +setup_ns() { + local dev=$1 + local num=$2 + local port=$3 + ls $dev > /dev/null + + mkdir -p /sys/kernel/config/nvmet/subsystems/$num + cd /sys/kernel/config/nvmet/subsystems/$num + echo 1 > attr_allow_any_host + + mkdir -p namespaces/$num + cd namespaces/$num/ + echo $dev > device_path + echo 1 > enable + + ln -s /sys/kernel/config/nvmet/subsystems/$num \ + /sys/kernel/config/nvmet/ports/$port/subsystems/ +} + +setup_port() { + local num=$1 + + mkdir -p /sys/kernel/config/nvmet/ports/$num + cd /sys/kernel/config/nvmet/ports/$num + echo "127.0.0.1" > addr_traddr + echo tcp > addr_trtype + echo 8009 > addr_trsvcid + echo ipv4 > addr_adrfam +} + +setup_big_opt_io() { + local dev=$1 + local name=$2 + + # Change optimal IO size by creating dm stripe + dmsetup create $name --table \ + "0 `blockdev --getsz $dev` striped 1 512 $dev 0" +} + +setup_targets() { + # Setup ram devices instead of using real nvme devices + modprobe brd rd_size=1048576 rd_nr=2 # 1GiB + + setup_big_opt_io /dev/ram0 ram0_big_opt_io + setup_big_opt_io /dev/ram1 ram1_big_opt_io + + setup_port 1 + setup_ns /dev/mapper/ram0_big_opt_io 1 1 + setup_ns /dev/mapper/ram1_big_opt_io 2 1 +} + +setup_initiators() { + nvme connect -t tcp -n 1 -a 127.0.0.1 -s 8009 + nvme connect -t tcp -n 2 -a 127.0.0.1 -s 8009 +} + +reproduce_warn() { + local devs=$@ + + # Hangs here + mdadm --create /dev/md/test_md --level=1 --bitmap=internal \ + --bitmap-chunk=1024K --assume-clean --run --raid-devices=2 $devs +} + +echo "################################### + +The script creates 2 nvme initiators in order to reproduce the bug. +The script doesn't know which controllers it created, choose the new nvme +controllers when asked. + +################################### + +Press enter to continue. +" + +read tmp + +echo "# Creating 2 nvme controllers for the reproduction. current nvme devices:" +lsblk -s | grep nvme || true +echo "--------------------------------- +" + +load_modules +setup_targets +setup_initiators + +sleep 0.1 # Wait for the new nvme ctrls to show up + +echo "# Created 2 nvme devices. nvme devices list:" + +lsblk -s | grep nvme +echo "--------------------------------- +" + +echo "# Insert the new nvme devices as separated lines. both should be with size of 1G" +read dev1 +read dev2 + +ls /dev/$dev1 > /dev/null +ls /dev/$dev2 > /dev/null + +reproduce_warn /dev/$dev1 /dev/$dev2