Received: by 2002:ab2:6841:0:b0:1f8:2b01:8fb7 with SMTP id l1csp1987409lqp; Wed, 15 May 2024 06:03:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWMnBETHa0p4b09B/2IjQIvNC0bXiR2QMrJhrrlm3rCBNs3zm60uc86djhwQ/vZ0FidNM+tkgAZ5I7ajLOwVsHPA3DgPgDdEgwyTPaKVQ== X-Google-Smtp-Source: AGHT+IFV8OP4NKnhynqbER7NvLvGTyd/qHP0OQ3bib6oK9ph1kkXOQsYIh3GsbwOhbx0cEmNeteU X-Received: by 2002:a05:6102:c86:b0:47c:3477:b4a1 with SMTP id ada2fe7eead31-48077e1cf92mr16998614137.15.1715778205223; Wed, 15 May 2024 06:03:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715778205; cv=pass; d=google.com; s=arc-20160816; b=Ld0TOJlfEp2OlYE/j1HSZUBhuYW3idpnTA+xBhkXOBOht5luiNBGQMUF40phVFvlL4 K4c6ambRhpXJzyVUDX4ObjyH2+zWujg4znHQFr28SMMM0AjwXQzvn39P9IykU2dRoinp qwyGv2Zin75I0B6khFn3x5r4+NJL4xdsiQUxKny6cfb9VdIdX8rrbmSImD95ugsVRdAQ eMx/znKiA4y/eWeu1Dk/jbW24Ir0Hevn8XlxRnPBbNDmlCaEr7tptzp5ktDTXVYhvvky Om6GR5p6t6g19Tunemf+vX9LZRM27OC3sWAPGo8bxZTr4ztA6VhtBXZ7XT0FytMeSZUE /tMA== 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=LVn/KH53UIW1tV24eE2TI2vH/bASdrQT5Jj1c6/w34E=; fh=dfpuzL54LAMf7GQmHoqmub+qZCPWKUPNTVFHnj8Vxqk=; b=GGyRbl9NRkM1B54/7G4432hqsoPPEIj8GFeKExsdK0MfDyRcBOVyAshw5FWvoW6sjm Z8Aa6tYZ8flDFGEaGVOvqzmfD4JZle5id9E3ByX3I61diENICKSGLL9IMOqs8EkU6DVW XI6+r9Z2glyVyjZfXVHv8BZEMs1nkZ79SOnRufJgw52OlufzjYCl3lQ5AwpVxjjk37Qt bgUzQi7P+8+H6FArWJ3ZuJT4ksKxuysR4ut6YPOa6KHqN+sC9DaBhRdK7+jLT6T5Mabz gGucxitqQyp/NgR2dNenHWoaDFlI4tmlSnIR4Sbi2OwpoRaHY5HO3Hef9ksfNx83GTOb Bjbw==; 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-179870-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179870-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ada2fe7eead31-4806cccf9bbsi2492996137.824.2024.05.15.06.03.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 06:03:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-179870-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-179870-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179870-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 4C0281C2261A for ; Wed, 15 May 2024 13:02:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 236DE86130; Wed, 15 May 2024 13:02:16 +0000 (UTC) Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [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 4D7BF84D3F; Wed, 15 May 2024 13:02:13 +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=1715778135; cv=none; b=cJq9AzcYrjgJzPIJXfOMwtIEB+p/7MzbopvApO1njFclbGycXILunTXTzHYooiLy/r02Te0GnRUf5yyWc2rteaVE+3MBKwB0QS10aYnBVHXCnA1T3bB3gl8HWDi011H7tfacMpjTiB5NTsaXRtKZiwsQbuuHBbt4tpV2QVTFAqM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715778135; c=relaxed/simple; bh=yuE0dUkKg6SEvEFuaXMjjSTzSms1xrmRs0cuseyJTws=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=C1+TDfko9FBM+DWBJGsCIHhaDOZUZdfWPZF4GYT78E9hGa/tcnuwHPie22xfqfKgxohP+IbUQJEMPzqH7dp0ob7okMjmSqpC7zfHurR9/wiTMZZ7on5GORMWRaAaloYkR8O09LOcKxY+fmKNXvlM2Q0ZvlWAEgtiRQaKmuddx2s= 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.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VfYK571Mzz4f3jdX; Wed, 15 May 2024 21:02:01 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id A2BE21A016E; Wed, 15 May 2024 21:02:10 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFLskRmALLwMg--.18738S9; Wed, 15 May 2024 21:02:10 +0800 (CST) From: libaokun@huaweicloud.com To: netfs@lists.linux.dev, dhowells@redhat.com, jlayton@kernel.org Cc: hsiangkao@linux.alibaba.com, jefflexu@linux.alibaba.com, zhujia.zj@bytedance.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, libaokun@huaweicloud.com, yangerkun@huawei.com, houtao1@huawei.com, yukuai3@huawei.com, wozizhi@huawei.com, Baokun Li Subject: [PATCH v2 5/5] cachefiles: add missing lock protection when polling Date: Wed, 15 May 2024 20:51:36 +0800 Message-Id: <20240515125136.3714580-6-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240515125136.3714580-1-libaokun@huaweicloud.com> References: <20240515125136.3714580-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:cCh0CgAX6RFLskRmALLwMg--.18738S9 X-Coremail-Antispam: 1UD129KBjvJXoW7tF4rWr4Dtr4furW3uw4rZrb_yoW8Xw4DpF WSya4Utry8ur48uF1jva4kJ34SyaykWa4DWaykXwsIvwnrXr1FqFnak3yYgrn5Jr1kJF47 tw1UKF9xA3yUA3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUm014x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWUuVWrJwAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17 CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0 I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVj vjDU0xZFpf9x0JUB89_UUUUU= 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 Signed-off-by: Baokun Li Reviewed-by: Jia Zhu Reviewed-by: Gao Xiang --- 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