Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3394733rwi; Wed, 12 Oct 2022 01:02:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6UdDdYnMfcR2bcXwWHuzHqoZrkLlfXGizqDlzC2qxWB+xwsOAK1uBQ4lHVmQxAWXgL9JKM X-Received: by 2002:a17:902:b68f:b0:178:627d:b38d with SMTP id c15-20020a170902b68f00b00178627db38dmr28370592pls.87.1665561745994; Wed, 12 Oct 2022 01:02:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665561745; cv=none; d=google.com; s=arc-20160816; b=h7hQVrhUbJsdMM/vLpOUiUemjSXvQQnDPaf3M1j6zs9VBcJN5/TGwFOrOnuW81Mj8d IZ3Rr+jxBaTuO+oYnINBVcnjX2fFamETFGNVf6h/RP3mSSd+sVFJlEJa9pOcQrimh9SO WStEZ/yPCiWpLOide5+rRdool77S3nKT72tyhWolPGDBr/fc423PDzFSArl05cvSUAbO 1Yjg1dnfOHMdB7HXbe27e25qIiyILTZ1PMAp6DNUMB9zR16VnqumKatNnWYltOt8IfmB YXInJKzWbwIDKHJ7pqKtY+ZYH6+QlMxdyvcW7HYEZ+/c8vH+itWuxwfy3iJK3do8cUmJ TgcA== 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:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=yC7Qi3VsA3RqK1IG3M8jBnuhux2RI3IgJIRZ5fJlUvw=; b=gFXsowqRxhQMvFQXxGFC8TtsFOcplF8YsN+QbObqqJFSz0hN6YfbAuwPDSIqR1UZ6D MPUEkWNTcWhw5MnmOOWxVVnEKjc848Smb6oivuvpDfu8mr/WB8wQ8WbxiXWoy8TJDErS mRANeDpok4O3QE0gpb+VEg/w5HrHD6QjCVDHPgkdJQx2h5eHMql5xmvutZAXw3oljpTN 1f42jybbNJUnbQWYJfiXLeCdlTc2nxOb6SRqtVouFWVIGnUwB5ZkfVC29mOpXWOdqf7S PcbPRzJyu6Gnmmc9uW/K+ZV4eHHahe5M9cgFb5oPKyxGGZv+/jBDtulPipbqcgvYQvKA sOsg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x188-20020a6231c5000000b005635bfe397bsi8469865pfx.218.2022.10.12.01.02.11; Wed, 12 Oct 2022 01:02:25 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229821AbiJLHxX (ORCPT + 99 others); Wed, 12 Oct 2022 03:53:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229507AbiJLHxU (ORCPT ); Wed, 12 Oct 2022 03:53:20 -0400 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 150C8B1B94; Wed, 12 Oct 2022 00:53:17 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R211e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0VS-qA-q_1665561193; Received: from 30.221.128.220(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VS-qA-q_1665561193) by smtp.aliyun-inc.com; Wed, 12 Oct 2022 15:53:14 +0800 Message-ID: <28d64f00-e408-9fc2-9506-63c1d8b08b9c@linux.alibaba.com> Date: Wed, 12 Oct 2022 15:53:13 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 Subject: Re: [PATCH 3/5] cachefiles: resend an open request if the read request's object is closed Content-Language: en-US To: Jia Zhu , dhowells@redhat.com, xiang@kernel.org Cc: linux-cachefs@redhat.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com References: <20221011131552.23833-1-zhujia.zj@bytedance.com> <20221011131552.23833-4-zhujia.zj@bytedance.com> From: JeffleXu In-Reply-To: <20221011131552.23833-4-zhujia.zj@bytedance.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL 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 On 10/11/22 9:15 PM, Jia Zhu wrote: > @@ -254,12 +282,18 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, > * request distribution fair. > */ > xa_lock(&cache->reqs); > - req = xas_find_marked(&xas, UINT_MAX, CACHEFILES_REQ_NEW); > - if (!req && cache->req_id_next > 0) { > - xas_set(&xas, 0); > - req = xas_find_marked(&xas, cache->req_id_next - 1, CACHEFILES_REQ_NEW); > +retry: > + xas_for_each_marked(&xas, req, xa_max, CACHEFILES_REQ_NEW) { > + if (cachefiles_ondemand_skip_req(req)) > + continue; > + break; > } > if (!req) { > + if (cache->req_id_next > 0 && xa_max == ULONG_MAX) { > + xas_set(&xas, 0); > + xa_max = cache->req_id_next - 1; > + goto retry; > + } I would suggest abstracting the "xas_for_each_marked(..., CACHEFILES_REQ_NEW)" part into a helper function to avoid the "goto retry". > @@ -392,8 +434,16 @@ static int cachefiles_ondemand_send_req(struct cachefiles_object *object, > wake_up_all(&cache->daemon_pollwq); > wait_for_completion(&req->done); > ret = req->error; > + kfree(req); > + return ret; > out: > kfree(req); > + /* Reset the object to close state in error handling path. > + * If error occurs after creating the anonymous fd, > + * cachefiles_ondemand_fd_release() will set object to close. > + */ > + if (opcode == CACHEFILES_OP_OPEN) > + cachefiles_ondemand_set_object_close(req->object); This may cause use-after-free since @req has been freed. -- Thanks, Jingbo