Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp176763lqd; Tue, 23 Apr 2024 20:44:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWXrxe8KT/sux6pTx6hnJz8I6I5kYzujOvHtaOIcye6gZHIh1vrAnLXSmmioesUUR+Niw/XF7c3jg4qlTOZWqaoyu7KP9/tHJWvu9SxUQ== X-Google-Smtp-Source: AGHT+IG0UYMuAfqJEwLAQqo89dkdco1wuX+vA6CC/wWTEY5Cd7pdpArdGoIqk1WopMi0Hw/4IJT6 X-Received: by 2002:ac8:5790:0:b0:437:9f6e:81d3 with SMTP id v16-20020ac85790000000b004379f6e81d3mr1679608qta.9.1713930280995; Tue, 23 Apr 2024 20:44:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713930280; cv=pass; d=google.com; s=arc-20160816; b=GhqsCovjBxV4wRIV8PgIrd2KHdh483MG3fa6mF1fLbnH0j/VCiD6ZW6hYdhKGbpeZv x8aXjYaOVipgVDCYkyL/nZC/MJQg6mHr9ed1yYr+RCDsw54O47bXp0lm6wVD+v6xKcl6 U17DfEqIwf1uoD1jllT5Drc3+M9yxxZByQ92iGqpIN2IJs6AIihu2Ow0jp7vWlYxxabX dgPGkePIOgAuCrTg3AJhUfJkHYhg05894UGI2y5ph610kCIJWP1+AWN0k4t0st8ySM63 FQ1owrXKXS9c9CwMESHltBG5oZD2Wl/Jy9bjhcIV15CSsF36mTZR9Z8YmY9stRVUEal9 Y1dA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=xDVxrpgUiVuwzcZrYRsVvoYqmzu9/1KTw3T93i136Pc=; fh=l3Sl0XHYLhiGtuWBEkCPVGVkEVpc/SO+Oc7rsC8ZNXY=; b=ekVFMNgWYagstqfbwtrdowhO6RDgKKGSGu5QJVyJh+afnF+QycBVQ9Gg8BNMuuU2ug FxhLMaWoYX8FVz1yAhTpdNE2+emM5MN9CPW25q1DPgyF3F7rdJ9MxON9FEX38zxw5IrV MWmRoD6E+DuuwFbaBwaIMsqZyy2v4zpOxD8fPcT3aUvLPXwZpAkASVr30P92QeIJLXPR cSm18cISpX6ZmY7Gge5FLlGMNV+xyKKbTodnsl2z6jsJqcCAkktgljeP98dPjk57/pNW WXx6duJHjZqxr516v3uCP3bg9ka/sjeGCt22sl/lb2NuSiK35poghsUgF7Uyt0ZKpkZI Fr7g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-156230-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156230-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id y16-20020a05622a165000b00434fedde9bfsi14404349qtj.781.2024.04.23.20.44.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 20:44:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-156230-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-156230-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156230-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A78661C23411 for ; Wed, 24 Apr 2024 03:44:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 76096144D21; Wed, 24 Apr 2024 03:43:31 +0000 (UTC) Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F63314265E; Wed, 24 Apr 2024 03:43:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713930210; cv=none; b=VOia3K1+qa616Ti8AxucPxl+HNXve2lIwn1QABaCPm86Mbt8LbdPWXN47OLn24vRsn0u9j+NHtWNdrd+qrH56mtItQkUN63lhivsbwvz/4ZQ+4NH4p5aLwH2jF7NUnL5B6qAmd9M4fXKvtaWYnxX3ePKVMSmLvGiJ8AKEkkS8/o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713930210; c=relaxed/simple; bh=5R4vmUl2Os6oBqdql/2NCKIR1BOUmNtB4sSAUTZoF3Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DuI2GsQwZAc1BoR6SbS0L0AgiyeudH2vECNmNC0ygcJN4Ew/I6Z7vOVSVhlGFpWuzIr0F28vwnjyw0FdFxsupSbapVnsKNBmjYfLIEmUn8EWU3DQB2PnaSAocjHfjppmfEQodoHsIWi4lYXYJrRqps1fHAfKRKS6Z3erm/NAHRE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VPPw66DqZz4f3kGH; Wed, 24 Apr 2024 11:43:18 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 6794E1A08D9; Wed, 24 Apr 2024 11:43:26 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgBHGBHafyhmuSA4Kw--.57541S9; Wed, 24 Apr 2024 11:43:26 +0800 (CST) From: libaokun@huaweicloud.com To: netfs@lists.linux.dev Cc: dhowells@redhat.com, jlayton@kernel.org, zhujia.zj@bytedance.com, jefflexu@linux.alibaba.com, linux-cachefs@redhat.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, libaokun@huaweicloud.com, Joseph Qi , Gao Xiang , Baokun Li Subject: [PATCH 5/5] cachefiles: add missing lock protection when polling Date: Wed, 24 Apr 2024 11:34:09 +0800 Message-Id: <20240424033409.2735257-6-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240424033409.2735257-1-libaokun@huaweicloud.com> References: <20240424033409.2735257-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgBHGBHafyhmuSA4Kw--.57541S9 X-Coremail-Antispam: 1UD129KBjvJXoW7tF4rWr4Dtr4furW3uw4rZrb_yoW8Wr17pF WSya4Utry8ur48uF1jva4kJ34SyayDWa4DX3ykXwsFvwnrXr1FqFnak34Ygrn5Jw1kJF42 yw1UGF9xAFWUA3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWUWVWUuwAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24lc7CjxVAKzI0EY4vE52x082I5MxAIw28IcxkI7VAKI48J MxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwV AFwI0_JrI_JrWlx4CE17CEb7AF67AKxVW8ZVWrXwCIc40Y0x0EwIxGrwCI42IY6xIIjxv2 0xvE14v26r4j6ryUMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UMIIF0xvE42xK8V AvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E 14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VUjs2-5UUUUU== X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/ From: Jingbo Xu Add missing lock protection in poll routine when iterating xarray, otherwise: Even with RCU read lock held, only the slot of the radix tree is ensured to be pinned there, while the data structure (e.g. struct cachefiles_req) stored in the slot has no such guarantee. The poll routine will iterate the radix tree and dereference cachefiles_req accordingly. Thus RCU read lock is not adequate in this case and spinlock is needed here. Fixes: b817e22b2e91 ("cachefiles: narrow the scope of triggering EPOLLIN events in ondemand mode") Signed-off-by: Jingbo Xu Reviewed-by: Joseph Qi Reviewed-by: Gao Xiang Signed-off-by: Baokun Li --- fs/cachefiles/daemon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c index 6465e2574230..73ed2323282a 100644 --- a/fs/cachefiles/daemon.c +++ b/fs/cachefiles/daemon.c @@ -365,14 +365,14 @@ static __poll_t cachefiles_daemon_poll(struct file *file, if (cachefiles_in_ondemand_mode(cache)) { if (!xa_empty(&cache->reqs)) { - rcu_read_lock(); + xas_lock(&xas); xas_for_each_marked(&xas, req, ULONG_MAX, CACHEFILES_REQ_NEW) { if (!cachefiles_ondemand_is_reopening_read(req)) { mask |= EPOLLIN; break; } } - rcu_read_unlock(); + xas_unlock(&xas); } } else { if (test_bit(CACHEFILES_STATE_CHANGED, &cache->flags)) -- 2.39.2