Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1639850pxb; Mon, 8 Mar 2021 02:41:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJxIb6LPxV2unWj/j9MWd3H7BAokKqbmyF5vH36XiUArV27Sq6OMtVvTsD6y1PeGyA4eyO4n X-Received: by 2002:a17:907:20c7:: with SMTP id qq7mr13882920ejb.528.1615200112629; Mon, 08 Mar 2021 02:41:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615200112; cv=none; d=google.com; s=arc-20160816; b=wlvDlIDcPu2h11NRqFdogyEFaWohis/0thV5RpX2jmxKihMspjcZjaFSv5ANupLtnM yyO2W7en9PhMPE5OmOvU6fBkfS+oj+If4NhBgaJ+kpyG5M+Hwefl0Txd+Cl4h97iltmB eomzU9hpEiXnyKhK9H87GOZAo4RtFaMwxZuPgi7QzsWIdf1vlHe1TjA8diiOTJGFl9in 8kIdQuhyvTaERdR3tUVcfRORw3ZynUrgmjlSrzYars+H7buuQ6kkAg9qNROfV2ZyPkOz m8/geQ9D2urd3QSNqE0utBvTY1vN9w0hg/ghd9r40kaUBakscEiKLkOvrIuoREqFDlb/ fybA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=lC8RSggeVJrLKoeC6WOvF+7kfEeZfqXWyO0lktJOVjw=; b=AfboaTjjuLzT0EKBC5tiBqZ6woQ2o6SP7MD7wc+K0DI4sMDPYXcAhmzJLaZEmq/9ZD Vv1aqB+nOPnFW+IFFUjIJFuzwdJ9JA39UJJE3NKXKuvKH5fFne+NfVJxNOiXLXNPUVBo z45Y4fO5j3EoTy6ipiEwWQQ1hxKAxEXbRSD1RnGBZJED6QMwGudu/jK/RByw7PPZ62xn Nxe3rlO+TH9NiQs0Dr0vveXrTl+sZWrOqGvwdQA6x1r015abX1jGBeof83tByG+M7m7r 3g+bOwa3854MV449BvzneNRN4JPgJRPMAIJtBBaYPfPjbQrAW+7+u82+xNhJ7Vo0j5Fr XFKQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b5si6251999edq.537.2021.03.08.02.41.29; Mon, 08 Mar 2021 02:41:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231133AbhCHKkN (ORCPT + 99 others); Mon, 8 Mar 2021 05:40:13 -0500 Received: from frasgout.his.huawei.com ([185.176.79.56]:2649 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230495AbhCHKjx (ORCPT ); Mon, 8 Mar 2021 05:39:53 -0500 Received: from fraeml714-chm.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4DvF571Tjzz67x4Q; Mon, 8 Mar 2021 18:31:55 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml714-chm.china.huawei.com (10.206.15.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Mon, 8 Mar 2021 11:39:51 +0100 Received: from [10.210.165.214] (10.210.165.214) by lhreml724-chm.china.huawei.com (10.201.108.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Mon, 8 Mar 2021 10:39:50 +0000 Subject: Re: [RFC PATCH v3 1/3] blk-mq: Clean up references to old requests when freeing rqs To: Bart Van Assche , , , , CC: , , , , References: <1614957294-188540-1-git-send-email-john.garry@huawei.com> <1614957294-188540-2-git-send-email-john.garry@huawei.com> From: John Garry Message-ID: Date: Mon, 8 Mar 2021 10:37:51 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.1.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.210.165.214] X-ClientProxiedBy: lhreml739-chm.china.huawei.com (10.201.108.189) To lhreml724-chm.china.huawei.com (10.201.108.75) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/03/2021 18:13, Bart Van Assche wrote: > On 3/5/21 7:14 AM, John Garry wrote: >> @@ -2296,10 +2296,14 @@ void blk_mq_free_rqs(struct blk_mq_tag_set *set, struct blk_mq_tags *tags, >> >> for (i = 0; i < tags->nr_tags; i++) { >> struct request *rq = tags->static_rqs[i]; >> + int j; >> >> if (!rq) >> continue; >> set->ops->exit_request(set, rq, hctx_idx); >> + /* clean up any references which occur in @ref_tags */ >> + for (j = 0; ref_tags && j < ref_tags->nr_tags; j++) >> + cmpxchg(&ref_tags->rqs[j], rq, 0); >> tags->static_rqs[i] = NULL; >> } >> } Hi Bart, > What prevents blk_mq_tagset_busy_iter() from reading hctx->tags[...] > before the cmpxcg() call and dereferencing it after blk_mq_free_rqs() > has called __free_pages()? > So there is nothing in this patch to stop that. But it's pretty unlikely, as the window is very narrow generally between reading hctx->tags[...] and actually dereferencing it. However, something like that should be made safe in patch 2/3. Thanks, John