Received: by 10.213.65.68 with SMTP id h4csp2121721imn; Sun, 8 Apr 2018 20:14:16 -0700 (PDT) X-Google-Smtp-Source: AIpwx49rShcCc5jbLjyEOX4Zo/ckwA8OezXVl7JK5k9SCRBuXCncmqf2DUfBb+UM0Uq8XCXjuDta X-Received: by 2002:a17:902:8490:: with SMTP id c16-v6mr37333251plo.132.1523243656869; Sun, 08 Apr 2018 20:14:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243656; cv=none; d=google.com; s=arc-20160816; b=UwOaxqsOlomI3Te33luL6jhHf+6X1NLEvbCOswdNyyvi1XsjeTmsxiFLavPr5flFqE ABHwp9oZe2VDZ0lHMe81ieDFUMUziwihBUu12KufaeGNXb1/LdBGnTW1NoFMSc1EUJBW tXqpchWuk8Bahv9SHeWoaL9B8WJ42UWVVuQOeP+8VZqjSnCxC4sHoYUtDKRGeaTVg6N6 KKGt0RWrmv9OOmMjHBJ5Yz4BdN2r5fwNgCbIPjMh7rmACDrDK/ELPa2kDaULPRByRZ75 qo1y5g1BfL55U1l3ZmFQkOspJCTkAAOxH7aJHvzRmquawaVcQbPfA13WcvseWb/cXc8E gdaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=Y0Fx6Z94AbEpQ0CTuCQzCWuJYuswu/sPMv5AJ5ZUj3I=; b=hb8NceipqSNgfZ/umWhFhpY4QL3KB5FKl+qtXKijuqCiSCvzZu2k/jumVnVVw9IImx q4WanjduOcy9q5NBeKpMv3LfAtwF9tesEHdKW6nh44huhhe8r77QCEYyfoTSfDnC3HmZ YycfCUGMq/kvvbOqJbh6yV08gOnaXXJ0DPNKRhevM9YVHdVO06YbFjpORU+P5ZUl3oVz UIFOdr+Ob/VaMI5OXC29aJFcXwqtDV6EKz3hcMHd4HLL2RSWpkSeEm95UV3kK74TOOUi dEnbi9529v6GCD9sxfVSIC1tOx6gunk7YVf/KreJTXIPnxeczllBdDVjaQggY/fiou8d ippw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=dfyLSTuF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u17-v6si13730063plj.731.2018.04.08.20.13.40; Sun, 08 Apr 2018 20:14:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=dfyLSTuF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752739AbeDIDDy (ORCPT + 99 others); Sun, 8 Apr 2018 23:03:54 -0400 Received: from mail-sn1nam02on0128.outbound.protection.outlook.com ([104.47.36.128]:23328 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755094AbeDIAYx (ORCPT ); Sun, 8 Apr 2018 20:24:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=Y0Fx6Z94AbEpQ0CTuCQzCWuJYuswu/sPMv5AJ5ZUj3I=; b=dfyLSTuFIddbbmY7BN8PQwwbt1U6NmYpTZzhrxLPD0et2OoAvP1iWzqmCfi03Pyk0XlKsy5MjxDlrlcEYWf/Q+tBr1CPzcIlNU5r8P47x6OyjWV/eHfeeC01Hi1YFosXRCFcv6nE8lza3LBbVd3Yp0EpmGYMBWmKF5fKZ+mUi4E= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0983.namprd21.prod.outlook.com (52.132.133.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:24:46 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:24:46 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Jens Axboe , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 107/161] blk-mq: fix discard merge with scheduler attached Thread-Topic: [PATCH AUTOSEL for 4.14 107/161] blk-mq: fix discard merge with scheduler attached Thread-Index: AQHTz5iucpgoiJKTYEO/j2ksBcfvnA== Date: Mon, 9 Apr 2018 00:21:19 +0000 Message-ID: <20180409001936.162706-107-alexander.levin@microsoft.com> References: <20180409001936.162706-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001936.162706-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0983;7:WMYYxMCm92FpYgVv8wL0SoBHYf7xxZuaGYzj+0Mw4E3argOunxo6vmLtFQ49BnF/fkKkJWIJ4PJRzy6B9RAL69znBOwdF7PLUFNb3dL9o31WZUGOfVOI7xVz8uTf5XOrXw7ElB5Q4AVWhZvgmomWt/m0wZbvE0/j1G8j1PQJHPknKyXmpUDgyuCKdoTbvjwOU4v6jnGHMud+Ltgnc5QN+W4eZSkqC0ThgKzyGkUvr+sYhbom4VAF1E16czwUGFiG;20:LnGk/HXNQLaoLuPjbSmpoOzS8aNiDm4l3t+Jzst+qfJBi/4XRovw9hHYeyLsTgCPy1gvebTim7q0dhX99zHmJSsJ8HK0Uhr2jlGROKJg0TTBgBcy1zjqE9TI//SjhcNlpR7a7Sz/6bCUwU/BQYHnmMZscPK6UhMW10pt92j+Kek= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 7bc1d6c2-7ed1-4b9f-c57f-08d59db04c91 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0983; x-ms-traffictypediagnostic: DM5PR2101MB0983: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0983;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0983; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(39860400002)(346002)(376002)(39380400002)(366004)(199004)(189003)(478600001)(59450400001)(72206003)(10290500003)(3846002)(102836004)(6506007)(551934003)(6116002)(25786009)(6436002)(66066001)(99286004)(54906003)(86612001)(6666003)(105586002)(53936002)(76176011)(316002)(486006)(7736002)(22452003)(3660700001)(86362001)(97736004)(106356001)(575784001)(8936002)(110136005)(5660300001)(11346002)(446003)(81166006)(81156014)(2906002)(8676002)(2900100001)(1076002)(476003)(2616005)(10090500001)(6486002)(107886003)(36756003)(4326008)(2501003)(68736007)(186003)(305945005)(3280700002)(5250100002)(6512007)(26005)(14454004)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0983;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 0jCIDF6rRZ2rB+JSH/s9dwb963lMHgS87GDEAVgnY5H+Tmght0CXvAUE+MBwJ7/Pg/26KqUTg64EEI72Ouvg45juJn/ZTBgQcjcZT/6a0/EGdI9IrirHfcj1x6OfzKx5MI5zswB8qtPUeKGBc2SlgfpcUtjENn3nqegu/LIT8RkNFCN8u6buHiG1SILgdIeoVud3rntffWoIcHIwTW3+Mde5BkTZVZWkTABOTurUXcj8c4E+hrGJJU4dJlsw4XpsSdj/o6Q9El0BtKOl2p1gWlWLOyoVapnaEl9tfAkRVm+gBvm1fYtEJaQFQI3aiLiRWTgNMW0ITdxUK2a3eEyOj5S1Gb1RJ+WvmWwZXqDDx6AUJXqgI8oJQPag8Hu3+T+UKjgdYwMsKNq0IlE1qnAld6d4DBEFptW+X7Dk36qkxtw= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7bc1d6c2-7ed1-4b9f-c57f-08d59db04c91 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:21:19.9250 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0983 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jens Axboe [ Upstream commit 445251d0f4d329aa061f323546cd6388a3bb7ab5 ] I ran into an issue on my laptop that triggered a bug on the discard path: WARNING: CPU: 2 PID: 207 at drivers/nvme/host/core.c:527 nvme_setup_cmd+0x3= d3/0x430 Modules linked in: rfcomm fuse ctr ccm bnep arc4 binfmt_misc snd_hda_codec= _hdmi nls_iso8859_1 nls_cp437 vfat snd_hda_codec_conexant fat snd_hda_codec= _generic iwlmvm snd_hda_intel snd_hda_codec snd_hwdep mac80211 snd_hda_core= snd_pcm snd_seq_midi snd_seq_midi_event snd_rawmidi snd_seq x86_pkg_temp_t= hermal intel_powerclamp kvm_intel uvcvideo iwlwifi btusb snd_seq_device vid= eobuf2_vmalloc btintel videobuf2_memops kvm snd_timer videobuf2_v4l2 blueto= oth irqbypass videobuf2_core aesni_intel aes_x86_64 crypto_simd cryptd snd = glue_helper videodev cfg80211 ecdh_generic soundcore hid_generic usbhid hid= i915 psmouse e1000e ptp pps_core xhci_pci xhci_hcd intel_gtt CPU: 2 PID: 207 Comm: jbd2/nvme0n1p7- Tainted: G U 4.15.0+ #= 176 Hardware name: LENOVO 20FBCTO1WW/20FBCTO1WW, BIOS N1FET59W (1.33 ) 12/19/2= 017 RIP: 0010:nvme_setup_cmd+0x3d3/0x430 RSP: 0018:ffff880423e9f838 EFLAGS: 00010217 RAX: 0000000000000000 RBX: ffff880423e9f8c8 RCX: 0000000000010000 RDX: ffff88022b200010 RSI: 0000000000000002 RDI: 00000000327f0000 RBP: ffff880421251400 R08: ffff88022b200000 R09: 0000000000000009 R10: 0000000000000000 R11: 0000000000000000 R12: 000000000000ffff R13: ffff88042341e280 R14: 000000000000ffff R15: ffff880421251440 FS: 0000000000000000(0000) GS:ffff880441500000(0000) knlGS:00000000000000= 00 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000055b684795030 CR3: 0000000002e09006 CR4: 00000000001606e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: nvme_queue_rq+0x40/0xa00 ? __sbitmap_queue_get+0x24/0x90 ? blk_mq_get_tag+0xa3/0x250 ? wait_woken+0x80/0x80 ? blk_mq_get_driver_tag+0x97/0xf0 blk_mq_dispatch_rq_list+0x7b/0x4a0 ? deadline_remove_request+0x49/0xb0 blk_mq_do_dispatch_sched+0x4f/0xc0 blk_mq_sched_dispatch_requests+0x106/0x170 __blk_mq_run_hw_queue+0x53/0xa0 __blk_mq_delay_run_hw_queue+0x83/0xa0 blk_mq_run_hw_queue+0x6c/0xd0 blk_mq_sched_insert_request+0x96/0x140 __blk_mq_try_issue_directly+0x3d/0x190 blk_mq_try_issue_directly+0x30/0x70 blk_mq_make_request+0x1a4/0x6a0 generic_make_request+0xfd/0x2f0 ? submit_bio+0x5c/0x110 submit_bio+0x5c/0x110 ? __blkdev_issue_discard+0x152/0x200 submit_bio_wait+0x43/0x60 ext4_process_freed_data+0x1cd/0x440 ? account_page_dirtied+0xe2/0x1a0 ext4_journal_commit_callback+0x4a/0xc0 jbd2_journal_commit_transaction+0x17e2/0x19e0 ? kjournald2+0xb0/0x250 kjournald2+0xb0/0x250 ? wait_woken+0x80/0x80 ? commit_timeout+0x10/0x10 kthread+0x111/0x130 ? kthread_create_worker_on_cpu+0x50/0x50 ? do_group_exit+0x3a/0xa0 ret_from_fork+0x1f/0x30 Code: 73 89 c1 83 ce 10 c1 e1 10 09 ca 83 f8 04 0f 87 0f ff ff ff 8b 4d 20= 48 8b 7d 00 c1 e9 09 48 01 8c c7 00 08 00 00 e9 f8 fe ff ff <0f> ff 4c 89 = c7 41 bc 0a 00 00 00 e8 0d 78 d6 ff e9 a1 fc ff ff ---[ end trace 50d361cc444506c8 ]--- print_req_error: I/O error, dev nvme0n1, sector 847167488 Decoding the assembly, the request claims to have 0xffff segments, while nvme counts two. This turns out to be because we don't check for a data carrying request on the mq scheduler path, and since blk_phys_contig_segment() returns true for a non-data request, we decrement the initial segment count of 0 and end up with 0xffff in the unsigned short. There are a few issues here: 1) We should initialize the segment count for a discard to 1. 2) The discard merging is currently using the data limits for segments and sectors. Fix this up by having attempt_merge() correctly identify the request, and by initializing the segment count correctly for discards. This can only be triggered with mq-deadline on discard capable devices right now, which isn't a common configuration. Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/blk-core.c | 2 ++ block/blk-merge.c | 29 ++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index c01f4907dbbc..1feeb1a8aad9 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -3065,6 +3065,8 @@ void blk_rq_bio_prep(struct request_queue *q, struct = request *rq, { if (bio_has_data(bio)) rq->nr_phys_segments =3D bio_phys_segments(q, bio); + else if (bio_op(bio) =3D=3D REQ_OP_DISCARD) + rq->nr_phys_segments =3D 1; =20 rq->__data_len =3D bio->bi_iter.bi_size; rq->bio =3D rq->biotail =3D bio; diff --git a/block/blk-merge.c b/block/blk-merge.c index f5dedd57dff6..8d60a5bbcef9 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -551,6 +551,24 @@ static bool req_no_special_merge(struct request *req) return !q->mq_ops && req->special; } =20 +static bool req_attempt_discard_merge(struct request_queue *q, struct requ= est *req, + struct request *next) +{ + unsigned short segments =3D blk_rq_nr_discard_segments(req); + + if (segments >=3D queue_max_discard_segments(q)) + goto no_merge; + if (blk_rq_sectors(req) + bio_sectors(next->bio) > + blk_rq_get_max_sectors(req, blk_rq_pos(req))) + goto no_merge; + + req->nr_phys_segments =3D segments + blk_rq_nr_discard_segments(next); + return true; +no_merge: + req_set_nomerge(q, req); + return false; +} + static int ll_merge_requests_fn(struct request_queue *q, struct request *r= eq, struct request *next) { @@ -684,9 +702,13 @@ static struct request *attempt_merge(struct request_qu= eue *q, * If we are allowed to merge, then append bio list * from next to rq and release next. merge_requests_fn * will have updated segment counts, update sector - * counts here. + * counts here. Handle DISCARDs separately, as they + * have separate settings. */ - if (!ll_merge_requests_fn(q, req, next)) + if (req_op(req) =3D=3D REQ_OP_DISCARD) { + if (!req_attempt_discard_merge(q, req, next)) + return NULL; + } else if (!ll_merge_requests_fn(q, req, next)) return NULL; =20 /* @@ -716,7 +738,8 @@ static struct request *attempt_merge(struct request_que= ue *q, =20 req->__data_len +=3D blk_rq_bytes(next); =20 - elv_merge_requests(q, req, next); + if (req_op(req) !=3D REQ_OP_DISCARD) + elv_merge_requests(q, req, next); =20 /* * 'next' is going away, so update stats accordingly --=20 2.15.1