Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp212005lqd; Tue, 23 Apr 2024 22:47:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVSoADjLWsd+0XUiTVC7HnJI87XpnM455seKzY9t+gUa0B9o3qt46Mj2hgb1UU592v6YuxfcUrAXPYRn+fGY1Olr79dL5nWeDrOOjw8+Q== X-Google-Smtp-Source: AGHT+IFxso4I2Vt1ekeOhYvxL1GCKGX96yoAAJ5zimkZaBVSPs7X9lomg97ZEJuuHViYGpLzS2zH X-Received: by 2002:a05:6a00:2296:b0:6f0:be31:8577 with SMTP id f22-20020a056a00229600b006f0be318577mr1732564pfe.22.1713937652726; Tue, 23 Apr 2024 22:47:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713937652; cv=pass; d=google.com; s=arc-20160816; b=Kg3/8TnMsVmLEpylwq1A6Nez9W7BfAqz8wu4tBMk/MTWW0ga+XYCQ2o1GwUs70VrUY WNe8Iu1Gmwfd1IZdyJhFtlkab54RdEryl/s+5iAmerSzyPkK9yIiCQ1IxRYoDSrmUbUL N/YNQIsw4QmzomXHsFyAQe6GlUa6ikcyOkahzADGi14m0Misg4zBu0mpHtrxkJW0eHnU fhSjd9/wYHJ6/B5rhu24gcIoadPcqwM980vRlmN9q5++9cPib7Vlp/sI2Vki6F9uYV99 sL2l2h2sNtHWGnzyvXorHSvjG9UxIHxjTcv62u+uDUQPfcZm91h1rp2ZsemCpm7XMXsQ WHdQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=oav/nBjbNQkJSHj491t5Rtmwwi8lc2zcpFduDWDdqHo=; fh=YcSK41utwLGVTtfFrWf6CAH7E00ao4eI1HDWbwIcfCU=; b=0tcZoGPJoesxKOgZUrwdg6I7K/liwYiis388ob5eqbMERqo2yQrvCZ+RWaIg6oZmEA jFFk1OP11c4q/FBQS0bXLWLP0Roi/iZaAELb1N6d1rLNFRFVjvhqokQlkskL8iXDvVq5 9M2pkS441k9DLbaz+0BlchJVT0/bwXxHez6TKVy7RrS+1vc8g6yV/HJ/aTX5iaqQsdQ2 AYmL1QuvtKRbWmgemc21EiCGR/oq8lvIYp8gu2H82072Yf+w8Nf6B88qORYXJReezuW4 8C1CAvV+FBij9iT0CurdkxL885kYQfAptkWgweJdx4YnULv+lFry/VDqcDULGISnv+zc umgA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=HLrEp3zX; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-156329-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156329-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id f15-20020a056a00228f00b006eaa98c88c3si10938923pfe.161.2024.04.23.22.47.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 22:47:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-156329-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=HLrEp3zX; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-156329-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156329-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 117A5B22E0E for ; Wed, 24 Apr 2024 05:47:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4DB6C156888; Wed, 24 Apr 2024 05:46:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="HLrEp3zX" Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 176F2156876 for ; Wed, 24 Apr 2024 05:46:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713937618; cv=none; b=cl1mEUWsmguPErPtZ9ZT5OG8CMmAfZNBVopRO4tw3u00WoieXesl48zVbnKU6G8lVbrfRlphijO66E7E3fD/mXEuZfwk+6yrS2Yf9SBsSSEmxEPpnKrfudZfmGN5SJht5ZEsimcvXhQpX9xiDxvbFXOJU6qtvjChOGzWmdrP/gU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713937618; c=relaxed/simple; bh=CF+ts3A4hUIMuGaFQFIzKuPMzImW0nVYFO6/BZ05kUs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=VPmrShXjo+9l1eUhaRa660uyDg4og1mu2lyWOPM6XX2rI4Cj146TubHOTTMrZOhlm/GzvFVppD3bscvHiz2V9FWi4DNJW8EMTdgoW/j0mkCT47dGNI3EhihYaHqeGFxqLgvcL0gJ/7d9uIsibLHrb+2Zc4OhmtYOeDyCdRKAdrM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=HLrEp3zX; arc=none smtp.client-ip=209.85.167.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Received: by mail-oi1-f174.google.com with SMTP id 5614622812f47-3c74a75d9adso2859896b6e.0 for ; Tue, 23 Apr 2024 22:46:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1713937615; x=1714542415; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=oav/nBjbNQkJSHj491t5Rtmwwi8lc2zcpFduDWDdqHo=; b=HLrEp3zXElsNeQq5ghg+IbasyFUOY45JCFvnv8QXVgdKv7Uw064/zhoP7EkxwZd3cB 3vStyImj8UcsrgCirsRHfA1KwMU02SRFfkei+kbZV4mXigck8n4yxUZIsXDV53baxfmH +cxlMjHNEvDlGN/DJh2MqZU/qyucQazE5ULCU9SH9+VkH1iiuhMXbiFKJeZ8KwYnBL1Y bNdWl1mNSphqNJKn7HVmCQO6AM7R4tOyoHya0iQdphoibzsej9U2w5Ej0VKLkWNVirrN kJIZUCrvWi7Bb3z9Pbc8Kw7wkNoeFbgLkhdCHBWYsKpNpuC/fNQsVk7mSWdOxUDfemXx tm9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713937615; x=1714542415; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=oav/nBjbNQkJSHj491t5Rtmwwi8lc2zcpFduDWDdqHo=; b=sg+kFPMkEYmYlSGddjufyFNrbbDxisyK9T9po0Tv7NcroBiTd3LLsjl8Np7Y7v5pZM Qfkjz5pugkWdTmsuYMKOOu4glpCoj6mL+ZZ5GyT/+E/inhtQAEiVkOEz7H7ilfQnNQGj kinebJVfOuJUlk3R6Xfw6o3wIRni9aK4vveRymUZnWeMSF2lMLhrXnJS2ximHIjf/wzo cUhP/fi9D8G3UrM1sHCteII+JWDZNVybbF+qNF0QJkcKHfNFyqhzSpA/aLUFRwuBJU9+ ks2s8lxNrt3EkIz1348FYg+Tgxul1QBQtvTTH/zdi/l5Pjdfs6u4sObglYNNDO2quuDf fuzg== X-Forwarded-Encrypted: i=1; AJvYcCXLOiwxTc6myTiO4KYnCJ0O82A5oZsfD4s3CRBlWs7GEocvi/jLd2XAT9gI3irgGwLhfkxXELfq5Sx2cIfRRGzL3jr6XrS1SCw+v/qC X-Gm-Message-State: AOJu0YwxCJh2Q/AS8gk/e9FkztPp9f//57KXsKdxf+9tkKIRH3ReYO5r GsCVee+eS6Wr6Psm7tJn9Tqyc/MKTKH+HpzlWMfoLwM/ue7wbsQgCxdZu3dleUg= X-Received: by 2002:a05:6808:170e:b0:3c6:6e1:b166 with SMTP id bc14-20020a056808170e00b003c606e1b166mr1792336oib.28.1713937615179; Tue, 23 Apr 2024 22:46:55 -0700 (PDT) Received: from [10.3.132.118] ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id j9-20020a056a00130900b006eae2d9298esm10560634pfu.194.2024.04.23.22.46.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Apr 2024 22:46:54 -0700 (PDT) Message-ID: Date: Wed, 24 Apr 2024 13:46:47 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 5/5] cachefiles: add missing lock protection when polling To: libaokun@huaweicloud.com, netfs@lists.linux.dev Cc: dhowells@redhat.com, jlayton@kernel.org, jefflexu@linux.alibaba.com, linux-cachefs@redhat.com, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Joseph Qi , Gao Xiang , Baokun Li References: <20240424033409.2735257-1-libaokun@huaweicloud.com> <20240424033409.2735257-6-libaokun@huaweicloud.com> From: Jia Zhu In-Reply-To: <20240424033409.2735257-6-libaokun@huaweicloud.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 在 2024/4/24 11:34, libaokun@huaweicloud.com 写道: > 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 Thanks for catching this. Reviewed-by: Jia Zhu > --- > 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))