From patchwork Thu Mar 2 15:13:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 9600579 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B244960522 for ; Thu, 2 Mar 2017 15:48:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1B7A285B6 for ; Thu, 2 Mar 2017 15:48:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96802285B9; Thu, 2 Mar 2017 15:48:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B6DB7285B6 for ; Thu, 2 Mar 2017 15:48:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751229AbdCBPsX (ORCPT ); Thu, 2 Mar 2017 10:48:23 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:58497 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753217AbdCBPqv (ORCPT ); Thu, 2 Mar 2017 10:46:51 -0500 Received: from pps.filterd (m0001255.ppops.net [127.0.0.1]) by mx0b-00082601.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v22FCAjK015126; Thu, 2 Mar 2017 07:13:17 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=subject : to : references : cc : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=facebook; bh=W0o8FaSrRJfYbkvLc6RFmFO2+6ff7tLizd4WETEwEHk=; b=o8Gh+d5npPWVE4yY9qnfeRbC9Yxytd7iFhmMpGVRZDLZCzDtyUyNenodICK4YV+LNa0Q ukwfLcL6s1KM44DgLQLsgwGXRWy9Y1JitZec1qjx7EqOI6HhTxImNHw9m7TZ62cdp+RU 3rlIydUJxtbeeolqBqTkok9nBigZlmFjGYA= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0b-00082601.pphosted.com with ESMTP id 28xfhvs6cd-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 02 Mar 2017 07:13:17 -0800 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (192.168.54.28) by o365-in.thefacebook.com (192.168.16.22) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 2 Mar 2017 07:13:16 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=W0o8FaSrRJfYbkvLc6RFmFO2+6ff7tLizd4WETEwEHk=; b=YF0okChwIi818Rj2AVRABw0MmsHaIhz6qKngsWNSpjer0VNmWNJYe9vbPTaBv0LmqNRAjTckBLBIs6hTTZEjpgvgLKfBrdynzYLUgtlR65P7bTPUj7cB5WHlYxvnqpz0qrObYtwPTv5rEvMCQr724VKrda9Uv8R1qyVGGslRQos= Received: from [192.168.1.154] (216.160.245.98) by BN6PR15MB1188.namprd15.prod.outlook.com (10.172.205.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.947.12; Thu, 2 Mar 2017 15:13:14 +0000 Subject: Re: [PATCH] blk-mq-sched: don't hold queue_lock when calling exit_icq To: Paolo Valente References: <73cd0cf484e8b75a771d908c172cd3a931dc00a3.1486751329.git.osandov@fb.com> <9fe1b3a9-2a80-8891-1044-f83558e28d15@fb.com> <1720FEB5-FBBA-4EAA-8292-E820AA15389D@linaro.org> CC: Omar Sandoval , , From: Jens Axboe Message-ID: <80de4554-a14b-4ce6-7c6e-ec66f70b14b1@fb.com> Date: Thu, 2 Mar 2017 08:13:11 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: X-Originating-IP: [216.160.245.98] X-ClientProxiedBy: BN6PR10CA0001.namprd10.prod.outlook.com (10.172.16.139) To BN6PR15MB1188.namprd15.prod.outlook.com (10.172.205.142) X-MS-Office365-Filtering-Correlation-Id: 0465c547-26f8-49ef-b7a8-08d4617ea642 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:BN6PR15MB1188; X-Microsoft-Exchange-Diagnostics: 1; BN6PR15MB1188; 3:cQlrueP4Q7ugtzNUEsWUwBA5ZYKzHq/EXoZKL65QRbr5nri86XUIIyxnLPGtDLBpUHbEscaQpYBKhkzS6SOvUSiyt/28quB7GbhDUdIjEqUUZDCPfAsR96Jh7mIAowPEzg3i3s9z7dP/Bhpl+Mg5QmFjPeFtV1ErkaEczjNA5HMhvhJHu7Ob1pB9OhnjhmKvym5xSuiI+InaUCSnRAP92p8RA+p7qOOC2G525K6vfHEvCzevYoXKWxeFNi3Yrc9qlRrWjMQAgryEw65w1t6JOQ==; 25:NpKXimx2/2PmPZzuwl3lDPYtwxsvbH820JLp+Gv4Amzyvap9lE3X0SkUYwOup/yzdorjaADO8qcPyhK0BoHFO0rfY49FgiqGIFeff5F73Awp7D9n++Shn9PktaMr2oJMgRvTvkHHB3kwFbOyRU2q74pEBfzVl+1mRayBynck0K9JTeeoKy2oZkbtj+uHqq+k+ecDWHTMAAGvxA+aem26VpSQQdhacl9m8DVSap/xZ1dlFcjsnxFHibPWS16Iq+NwYB3IBCeLanIKgG1YSY6QJjNOP8FG2TgIP6rX8hv1/ZCHg3VZ1WM1bmMY8EEcBVRrlkac+sa2CNAujSoauBo5e41hwQ2wAW3FJswsbBFtY5zIwCjn6CRDrPbVPBulWjN5n57hpKep5tPR3BYGJLZvX4c1Q0vtt5Fk5/sJ57CkIAxWHQ/ulqAuMmBjB4sj2gn7 X-Microsoft-Exchange-Diagnostics: 1; BN6PR15MB1188; 31:/xAb3fl7MEgjz+S4WqAPim2nFXj0Ms/s0epBuApgTmNBdlM6eFMW0+xqQNfvEeZ6C40aKDE3TJ2jEf8M+Vsa0ELtmW6xwcZmLCxn6ioBbuZKYig9p9DW1pdZQ6dHpjXYec3vhU01P/G8DD/uJgq9H1hG1C6aKXKAR8xNXMiwstabH/j0jFu4aOfIxvcvbeGzEN3jj8Sn6lZuWrE9Sw9XiAvovV9VEIGewXgk0TMpu0CzeDSR1bZXKIYqZlJGjEtv; 20:+Gkk70yfm1Q6GbeeB+9zTpQhETeAqU5YcORhJHAl9mfSWANzL9mIfSVOqOHQ7KkkJLqf8XN92l6XSX+XlD2egiSL70Nh4X0PEQOI4HInfFdAuN8PtUbwyLpy17LCekT56HwO6hQ42MnK/5qIFAw8CY82yFWubPoAPVmRp9wv/S8IBAYzn4CPMUjNmEoCHNrheH25b2p7OskDiX6V0ikg4fWSd23jPgVOrkZbOnA4Nrkk32IWh2J8/yTsdK/T0tg4rpJhjWRLpr3EEGydKZUQVKmL5HZjhZLVe+8TovxT9IX/tALgxVZlgq4I2BoaNCxQj9V6JP1p5AceyaYWC4hPejaEBus/maaJRy+TLG6Caab/l5HzrQB158dFjdfEXlzwX/Li+BF/DvwoqYpBA3F67OvwEAI1G3+auItT+B+uPHBm2Nc50F9NkDOv5FGc8UyyJZrwH3ELEMh9dTpcjMbE4caU8TFrkjDHLzgMg+0RHuannAJO7/DgDPi3XUbOMWiy X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(67672495146484)(17755550239193); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6041248)(20161123555025)(20161123558025)(20161123564025)(20161123560025)(20161123562025)(6072148); SRVR:BN6PR15MB1188; BCL:0; PCL:0; RULEID:; SRVR:BN6PR15MB1188; X-Microsoft-Exchange-Diagnostics: 1; BN6PR15MB1188; 4:/VN1djI1q/zfOT9ufmGTeFFhQhsv3HEtpXjfqJC5l6nBQyhozGv6WmPC/h+GvDtj0rFqZ27veKjvxb+Csc3sZg9hiyEM008vkJzgzCPbX12aQMUgF5/nk71OiLIWKssNjSAcfIn4m5QOHaxhtl0cTqCRTltIgLKT3Kn95Tnkdcb8dG5swS1lXJsdb+jO88VfPtPjKhK2snoITroQlgnXDxi54JaOzz7Y0YGFByDDNRWkOkAbYSzlx4hNfFRbOY5GwUp840tXW7/ue4InC4N/WHSfhVcO3sXbVIBwBNRnSx/rMskUCcebtZD4/OurMzYSDmlzAbKnMNSZ6Xvq/eh5KGOSmkJIpsrC8/CGgkJMaHTbdzPtCII+gRKN0nERdZQxuThXsvbJ/D88rT/oSrvn99njOsoNV6e6jbtpoL3XKlS0Go5WaXm/MkLilYUlJDGy298bg0BAD+jsf+yleeMVr4nTe891Z29pJeYFPzM8pFdfRYuWwwx3t5MKQ0pfyhHy/CqG+K+hoU+kkTuq9omLY2XMdcTBYN7Ee9px/Fnm2/TkhYuKP/z+pg245xkSt4OjhGt4j7zGymN2Ql0NnhxEzG2skw9vwWUn/FxQ5kaHvM3mI3YwYcjYMBRC+S7Dkxewrhh1d1P1HGbAW8pCGOCT5/yqiYfQsfFWoZnVx4G+pTUW8K4rY6eBHMUraFqIT1yb X-Forefront-PRVS: 023495660C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(6049001)(7916002)(39450400003)(39830400002)(39410400002)(377454003)(24454002)(2906002)(31686004)(86362001)(50466002)(65806001)(230700001)(6116002)(6246003)(38730400002)(110136004)(3846002)(31696002)(66066001)(23746002)(47776003)(230783001)(54356999)(33646002)(76176999)(117156001)(50986999)(93886004)(7736002)(305945005)(189998001)(8676002)(42186005)(81166006)(4326008)(53546006)(5660300001)(92566002)(83506001)(54906002)(6666003)(6916009)(53936002)(25786008)(2950100002)(229853002)(6486002)(90366009)(36756003)(77096006); DIR:OUT; SFP:1102; SCL:1; SRVR:BN6PR15MB1188; H:[192.168.1.154]; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1; BN6PR15MB1188; 23:nifcQbrI5wpOaP0xNeju0//TxmqJB7Z9THuzO?= =?Windows-1252?Q?xKoPVsPgrHC2RI8k9UER6jPqpCiGl+Zl61eiM9qSbFDpV9UJOYnB3+yf?= =?Windows-1252?Q?s25iXPWP20JwDi4rKhOFvwnFcNSy16/D1YOIGsmTW1x7FOsCyxLyv+1P?= =?Windows-1252?Q?6vkb/sJaXchJNTZYxtw2hV0XThL4EZKzttt4wDCe9Qh8rWWQbB2kEu8E?= =?Windows-1252?Q?qbkN1O42q8EAgx6xBxm+jNm7ma7LKHUft3v+dJhg76NDqKZYcEfoaIaH?= =?Windows-1252?Q?3D6oyIebilWFwwKfPfHwTHrfn3oOzZiX5kuTDIJJ7o7z5YbDqe9ZvGGu?= =?Windows-1252?Q?r2CaVbDhOQhYe8uojfGR4o6rJluVsNtJuooos7DX8PS/nnrFVCNyyVj+?= =?Windows-1252?Q?SEw92PHgRfFIgXbMWqwlONpB0AqDoymibLJbfarN6GL5qIZLZbi5R3bm?= =?Windows-1252?Q?5ocn6Cchzq5SKxj8bCNrosHU98dTYMuIBoNV60XbHOc362Kop6Af8jqm?= =?Windows-1252?Q?iaQbpvDe98q/xJrBjPZZcfiJ2GeYDqZuLGOyhGUsYUp6rOL0kJfFIwWV?= =?Windows-1252?Q?r8w4bJBuC0/LXN8zE+SkmaGNLPXh3IjxvbwtzFIrEbZVtrN1J4rfht/u?= =?Windows-1252?Q?T3K4gY0vdOeYvhwMba6OR71onnOZL6W4EeYacPm+5U8n2rQuj8BUjD6d?= =?Windows-1252?Q?Bkzsr4HkbY8xcpDK2nqsiPgBfBJOwgbne9BSGs3XhGpBBfYdNI3ClO/V?= =?Windows-1252?Q?3eKyC7glPJHin3k2PdkuoMp3X5n4IA+GJsdVrj+S+uFkwt8eRNVWHysn?= =?Windows-1252?Q?sU+QU3LqDwJNdYIrBhENgWYQiIMaDFlMIZsk+czw7Tyh+iOPJt10/2ZK?= =?Windows-1252?Q?6NtcpMDoX72cJg6wFHFeJw1NGPbY83WN8U9QELVhWRFa8z89GTHPcQ7D?= =?Windows-1252?Q?j2yUAF6PP8NO5tgCt39RPmADLfvnCzfZlZSKIuBneNEQnIdTM0Phy0+C?= =?Windows-1252?Q?D0rMDqR/CjkL07MM7p85yBrUNS61M2eUbSvgHX5eWRDJ5IAlFoJen53S?= =?Windows-1252?Q?hAfa5OnfWQaetTWlbMme1XMeeIEy1FAW0xoFjnCFdZ+pBBhp0yHtdb9A?= =?Windows-1252?Q?5JRIp7oklAqFadzpJIGcVZBjbFL3LVqrKHw8tN7+nskMV4hUQ98bLCfo?= =?Windows-1252?Q?02R0RDXkcQgpHhIertgRzolRh9qr3Zk5Og4gVSxLL0VjwRE8AkZZ5VG5?= =?Windows-1252?Q?bwn7MEGPIIlrKG9DVB9ziCQK2IXbO9bt4afd8U4y2LKghl98ldTdpWEL?= =?Windows-1252?Q?O0RXaE7cGVba3Nai2+JeBm5vJbQ830ZzPjC02KLoNmodYinBCoGyP1A3?= =?Windows-1252?Q?6BE3dq0vAd3AnmNR+IBP5MdvWyOgMNDtA=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; BN6PR15MB1188; 6:EK3NV04ftA0VMynUhrxbHDvTR8eCJ/DlONws4Kl6iMtWeIyMJ2tya/GDU6P3EQFtvMndvddg4SfgNybWnbHgA2qb1GSmTMkVN5GZM7ifeIxMGD7dzWvvkEYaii3XGlyzNgyFYQOnjP5ilIMVWKIbOL6xqBPN4fmZBQ7Vn+zLbem2VhfBtdjQN1fqJFgNOz/Woa0SmGyy/0fxr9oAF/1ejoZKnU3MIK4lyIlbzmfR9VsoY7pSww9UkCQ1eTPpL1ZrDbOQSCW1ONpLXWQeXIBD1YI8HmJbJr8WZjO+H3PZGvP7BzWPehrzWYOFcWs8osMCuMyNqdE2cmlGy7BEEc62N4NDolpY0/yPEMJGBvyhqBUnuIMOE9iQM5F8UyHPKzn+JWG+93rYeisngrhj7r61qg==; 5:x89JNbILHDat+cwQEJZubYaGmBbcl8vLlPHl8mhNi+tpOP6YbjLKi6wnWOhh5igSnnJnqgrIyQnHkg79qFWGGQmImOmVZzQ7V7bnASBlTA8BZwZuosGm0RFNjVtQoL+zp8HyA2wpn9hURGi3bRlcvg==; 24:SYfrgvO26g9wEJIlTmxfmkKuyW6IH3J/8f5yQx1SqYQZdLMlMIoeSPw4BcpnTI1ZvQw0Al4zte0AbJx+EOfc9//GaBJVKxNrzvPgHwZ6cEA= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR15MB1188; 7:/2w5nUJEFQOB3Ld1tvUvn+Y+LNuVbjMASdQGvdQrE1IJXkqn1I70BwTHwoOl0cLezzu7vuWayWuXzGTL6dD+Hu9TGsQDjKHBHOLmfS20ksPh40S7VCz0UYqR9kcg5yQCsajDn7p0rRls3pqCRAyj1A+EMPyGWPF3pxlu9B2+EDUo4cSVkHdlrhM5poGlwGtb+Jl23VKhu9zMvsg0vVSqKPqeitHOXPLs/GEUDt02+LEr7PUjioaFSMSMG7exfGTSib46Vg7sYhb/67TXvF1nA0mjNUAPskQbcmHlBBmQkf7ohOUza8CBoI+jmfdqQOKJBcC4tDjaIOgLjMxibxntgQ==; 20:g3zJycHbRAyEDrAEzH/7gAuSJ6YG0B78d7vEtgsn90uh8MmMhWTmiYg8Ve1Iru8WtMx6DCpW4NH1zH+lZBEiVw5Vy27CdT3hD28N8L+dF7UL+G7hXTjKyMQETSpHlykNvuU2a9Sjr37ra99jBWIj+sbSuj0oXq+I7Qmm3cX9Zbs= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2017 15:13:14.4722 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR15MB1188 X-OriginatorOrg: fb.com X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-02_13:, , signatures=0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 03/02/2017 08:00 AM, Jens Axboe wrote: > On 03/02/2017 03:28 AM, Paolo Valente wrote: >> >>> Il giorno 15 feb 2017, alle ore 19:04, Jens Axboe ha scritto: >>> >>> On 02/15/2017 10:58 AM, Jens Axboe wrote: >>>> On 02/15/2017 10:24 AM, Paolo Valente wrote: >>>>> >>>>>> Il giorno 10 feb 2017, alle ore 19:32, Omar Sandoval ha scritto: >>>>>> >>>>>> From: Omar Sandoval >>>>>> >>>>>> None of the other blk-mq elevator hooks are called with this lock held. >>>>>> Additionally, it can lead to circular locking dependencies between >>>>>> queue_lock and the private scheduler lock. >>>>>> >>>>> >>>>> Hi Omar, >>>>> I'm sorry but it seems that a new potential deadlock has showed up. >>>>> See lockdep splat below. >>>>> >>>>> I've tried to think about different solutions than turning back to >>>>> deferring the body of exit_icq, but at no avail. >>>> >>>> Looks like a interaction between bfqd->lock and q->queue_lock. Since the >>>> core has no notion of you bfqd->lock, the naturally dependency here >>>> would be to nest bfqd->lock inside q->queue_lock. Is that possible for >>>> you? >>>> >>>> Looking at the code a bit, maybe it'd just be simpler to get rid of >>>> holding the queue lock for that spot. For the mq scheduler, we really >>>> don't want places where we invoke with that held already. Does the below >>>> work for you? >>> >>> Would need to remove one more lockdep assert. And only test this for >>> the mq parts, we'd need to spread a bit of love on the classic >>> scheduling icq exit path for this to work on that side. >>> >> >> >> Jens, >> here is the reply I anticipated in my previous email: after rebasing >> against master, I'm getting again the deadlock that this patch of >> yours solved (together with some changes in bfq-mq). I thought you added a >> sort of equivalent commit (now) to the mainline branch. Am I wrong? > > The patch I posted was never pulled to completion, it wasn't clear > to me if it fixed your issue or not. Maybe I missed a reply on > that? > > Let me take another stab at it today, I'll send you a version to test > on top of my for-linus branch. I took at look at my last posting, and I think it was only missing a lock grab in cfq, since we don't hold that for icq exit anymore. Paolo, it'd be great if you could verify that this works. Not for bfq-mq (we already know it does), but for CFQ. Run with lockdep enabled and see if it spits out anything. We'll hit this exit path very quickly, so the test doesn't need to be anything exhaustive. diff --git a/block/blk-ioc.c b/block/blk-ioc.c index b12f9c87b4c3..546ff8f81ede 100644 --- a/block/blk-ioc.c +++ b/block/blk-ioc.c @@ -54,7 +54,7 @@ static void ioc_exit_icq(struct io_cq *icq) icq->flags |= ICQ_EXITED; } -/* Release an icq. Called with both ioc and q locked. */ +/* Release an icq. Called with ioc locked. */ static void ioc_destroy_icq(struct io_cq *icq) { struct io_context *ioc = icq->ioc; @@ -62,7 +62,6 @@ static void ioc_destroy_icq(struct io_cq *icq) struct elevator_type *et = q->elevator->type; lockdep_assert_held(&ioc->lock); - lockdep_assert_held(q->queue_lock); radix_tree_delete(&ioc->icq_tree, icq->q->id); hlist_del_init(&icq->ioc_node); @@ -222,25 +221,34 @@ void exit_io_context(struct task_struct *task) put_io_context_active(ioc); } +static void __ioc_clear_queue(struct list_head *icq_list) +{ + while (!list_empty(icq_list)) { + struct io_cq *icq = list_entry(icq_list->next, + struct io_cq, q_node); + struct io_context *ioc = icq->ioc; + + spin_lock_irq(&ioc->lock); + ioc_destroy_icq(icq); + spin_unlock_irq(&ioc->lock); + } +} + /** * ioc_clear_queue - break any ioc association with the specified queue * @q: request_queue being cleared * - * Walk @q->icq_list and exit all io_cq's. Must be called with @q locked. + * Walk @q->icq_list and exit all io_cq's. */ void ioc_clear_queue(struct request_queue *q) { - lockdep_assert_held(q->queue_lock); + LIST_HEAD(icq_list); - while (!list_empty(&q->icq_list)) { - struct io_cq *icq = list_entry(q->icq_list.next, - struct io_cq, q_node); - struct io_context *ioc = icq->ioc; + spin_lock_irq(q->queue_lock); + list_splice_init(&q->icq_list, &icq_list); + spin_unlock_irq(q->queue_lock); - spin_lock(&ioc->lock); - ioc_destroy_icq(icq); - spin_unlock(&ioc->lock); - } + __ioc_clear_queue(&icq_list); } int create_task_io_context(struct task_struct *task, gfp_t gfp_flags, int node) diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 002af836aa87..c44b321335f3 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -815,9 +815,7 @@ static void blk_release_queue(struct kobject *kobj) blkcg_exit_queue(q); if (q->elevator) { - spin_lock_irq(q->queue_lock); ioc_clear_queue(q); - spin_unlock_irq(q->queue_lock); elevator_exit(q->elevator); } diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c index 137944777859..4a71c79de037 100644 --- a/block/cfq-iosched.c +++ b/block/cfq-iosched.c @@ -3658,6 +3658,8 @@ static void cfq_exit_icq(struct io_cq *icq) struct cfq_io_cq *cic = icq_to_cic(icq); struct cfq_data *cfqd = cic_to_cfqd(cic); + spin_lock(cfqd->queue->queue_lock); + if (cic_to_cfqq(cic, false)) { cfq_exit_cfqq(cfqd, cic_to_cfqq(cic, false)); cic_set_cfqq(cic, NULL, false); @@ -3667,6 +3669,8 @@ static void cfq_exit_icq(struct io_cq *icq) cfq_exit_cfqq(cfqd, cic_to_cfqq(cic, true)); cic_set_cfqq(cic, NULL, true); } + + spin_unlock(cfqd->queue->queue_lock); } static void cfq_init_prio_data(struct cfq_queue *cfqq, struct cfq_io_cq *cic) diff --git a/block/elevator.c b/block/elevator.c index ac1c9f481a98..01139f549b5b 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -983,9 +983,7 @@ static int elevator_switch(struct request_queue *q, struct elevator_type *new_e) if (old_registered) elv_unregister_queue(q); - spin_lock_irq(q->queue_lock); ioc_clear_queue(q); - spin_unlock_irq(q->queue_lock); } /* allocate, init and register new elevator */