Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3293679rwb; Wed, 30 Nov 2022 18:51:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf4NHfHSQWeEHd7JU0dE5HGB1UmSTZhXx7FOC6mOHEsA1yrfVKOup9nkYmJcjoQILiO0v2JB X-Received: by 2002:a17:906:694a:b0:7c0:9d50:5144 with SMTP id c10-20020a170906694a00b007c09d505144mr5035915ejs.590.1669863100554; Wed, 30 Nov 2022 18:51:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669863100; cv=none; d=google.com; s=arc-20160816; b=z9kWbsry2dbe6mw4+gVnj6o3ttCMFIc2zLQt7FOYgIeeOenYK1RQgAXWeLVOT+hYE0 cUv716NicU2Gmg2UqFgLeb/ZvqLLyxduvgnLpn1q9qhN4dl2/NecVVOA0uCtAft+BFp5 Hm8NyNc/fG5VNpjNJ3SqKOOGo4jcjMKaHE8vH6FbZPzEG328gv0zCGubsY7RlYTwq8pg Qyr/ygLPJXE2vjawTJfLajyoWraNVIRE1TEiTvbKEaRNoFWecWFCAGpnjIFkff/ycoMm 6QgAImhySIu92b+DDOuglOdcRrZGRYZXxATKFgfGAtPjcmPJUKOksXgH4hYyYbMdoBtp q1zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=U5olhaZx4k6b3+abV3Jw8dLplbfFqGEBg1RhWE4A9Io=; b=TaI7/g8TeBIRMOLPJWC+JeQ8jtk7K/QOikP0O5I1kVhzzsLWPNuZu1MEFn0srqWArW oIfR2eM9HL54SefuFx8PZYnpu2toHrhHQ0cOfY1YGtrl1CVN4QWbrEW2rv0HTkg2MxFa lQ9UIa56FyGgMjbgK4hTCDnsr23be8qQYYrb5uVhwfrv0PMT68kSI4zfC72n8ucmbSO2 ll9XPQAH1KrkcjyEDEKPeEORPPP2dmhR06IxppzUwc49++cNBsesciwXpD82HChB+bAk GIq9/KfHeGbMxy1P/S++uHNm8smgorjFqmZNHn8nwR2qiXM9w5hMayuTbLZzV0xc0SYQ jFQw== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lc16-20020a170906f91000b0078266dc4b8csi2146247ejb.719.2022.11.30.18.51.21; Wed, 30 Nov 2022 18:51:40 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229662AbiLACMW (ORCPT + 82 others); Wed, 30 Nov 2022 21:12:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbiLACMV (ORCPT ); Wed, 30 Nov 2022 21:12:21 -0500 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAF6254465; Wed, 30 Nov 2022 18:12:19 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4NN02N574Rz4f3s8m; Thu, 1 Dec 2022 10:12:12 +0800 (CST) Received: from [10.174.176.73] (unknown [10.174.176.73]) by APP1 (Coremail) with SMTP id cCh0CgC3YK99DYhjepV1BQ--.2209S3; Thu, 01 Dec 2022 10:12:15 +0800 (CST) Subject: Re: [PATCH -next v2 8/9] block: fix null-pointer dereference in ioc_pd_init To: Tejun Heo , Li Nan Cc: josef@toxicpanda.com, axboe@kernel.dk, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, "yukuai (C)" References: <20221130132156.2836184-1-linan122@huawei.com> <20221130132156.2836184-9-linan122@huawei.com> From: Yu Kuai Message-ID: <9ca2b7ab-7fd3-a9a3-12a6-021a78886b54@huaweicloud.com> Date: Thu, 1 Dec 2022 10:12:13 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID: cCh0CgC3YK99DYhjepV1BQ--.2209S3 X-Coremail-Antispam: 1UD129KBjvJXoW7WF4DCFWrZw4rZr1kWF17Jrb_yoW8Ww4UpF WfWF1Yy34jqrs3t3WDAw4xAryYqrs5WF1fZ3s8A3sI9FZruw1Yq3W2kFWqgayxZrs8Zr1F qayjqw17Xry0yrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUk0b4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x 0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG 6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV Cjc4AY6r1j6r4UM4x0Y48IcVAKI48JMxk0xIA0c2IEe2xFo4CEbIxvr21l42xK82IYc2Ij 64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x 8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE 2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42 xK8VAvwI8IcIk0rVWrJr0_WFyUJwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv 6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUrR6zUUUUU X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, NICE_REPLY_A,SPF_HELO_NONE,SPF_NONE 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 Hi, ?? 2022/12/01 4:50, Tejun Heo ะด??: > On Wed, Nov 30, 2022 at 09:21:55PM +0800, Li Nan wrote: >> Remove block device when iocost is initializing may cause >> null-pointer dereference: >> >> CPU1 CPU2 >> ioc_qos_write >> blkcg_conf_open_bdev >> blkdev_get_no_open >> kobject_get_unless_zero >> blk_iocost_init >> rq_qos_add >> del_gendisk >> rq_qos_exit >> q->rq_qos = rqos->next >> //iocost is removed from q->roqs >> blkcg_activate_policy >> pd_init_fn >> ioc_pd_init >> ioc = q_to_ioc(blkg->q) >> //cant find iocost and return null >> >> Fix problem by moving rq_qos_exit() to disk_release(). ioc_qos_write() get >> bd_device.kobj in blkcg_conf_open_bdev(), so disk_release will not be >> actived until iocost initialization is complited. > > I think it'd be better to make del_gendisk wait for these in-flight > operations because this might fix the above particular issue but now all the > policies are exposed to request_queue in a state it never expected before. > > del_gendisk() is quiescing the queue around rq_qos_exit(), so maybe we can > piggyback on that and update blkcg_conf_open_bdev() to provide such > exclusion? Let del_gendisk waiting for that sounds good, but I'm litter confused how to do that. Following are what I think about: 1) By mentioning that "del_gendisk() is quiescing the queue", do you suggest to add rcu_read_lock()? This seems wrong because blk_iocost_init requires memory allocation. 2) Hold gendisk open mutex 3) Use q_usage_counter, and in the meantime, rq_qos_add() and blkcg_activate_policy() will need refactoring to factor out freeze queue. 4) Define a new metux Thanks, Kuai > > Thanks. >