Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp180563lqd; Tue, 23 Apr 2024 20:59:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVKwXjLWv+K7ZSV1EsPjrHrbMFLMX9oyKGVQejjFkkurVy2xnGerakFTSX9yPKUfzH2DcMs4gu+P822q7z6OZ4sdC1EHfJE/wVyRgTz8g== X-Google-Smtp-Source: AGHT+IGeQF8EkdpvIcW5G4MkFJS54wbPMHl3wE919w4R3lDg+fHbRcWk71r2nzOClOpD2AKiE4/0 X-Received: by 2002:aca:1e07:0:b0:3c5:de13:a7b9 with SMTP id m7-20020aca1e07000000b003c5de13a7b9mr1049693oic.49.1713931192466; Tue, 23 Apr 2024 20:59:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713931192; cv=pass; d=google.com; s=arc-20160816; b=IBBXG1EK9PEMn3TBBRudVH9Mc+t5JkRSmmJkY7Lz1WQ+IEmg/AoZjDPLAjFNjXgcR3 UkxQ0HT8KEPBrWLTWMm3w/FmmGFlkv2ehgiINSrVOuWF2h2uEOWHaSrqjm/ukTK5l3s5 3sgjHP3xSGSi0sA/HPem7YpVSQkfnsK4JKZ9C4smX2fQF3FNF92zyjw5xputkTPdWppz hPD856einl+hCmGuQZIC2J88K6T23/Z0mN3NB9bVRRQj41LJTpdvBssYpTU0nVadk+W4 Ec6im4numoBiiW+UdScWh20XmNxMmg+E+F1I6RmpFIwC7GtMlS2db3+/uBTk5PGsl6Kb FE0Q== 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=Q69vfAhkBAKjCTBANZKdPAfZYsiLpK8s6MbYMAewit4=; fh=WA+l4cX4YwgXxXS6mzVv2qexO7t00Rej9ENZephQ/MA=; b=rS0lDkXoIcoWMD83dsKDwUf5AUpSrEvDYttd8nnwelYnZ2tiM/ZQLHXGKjHzpPObso bIuDl/hhNrMF5rhMhgyXCFbry1v02yZVzS8jMpyFOT0h3Kbwel3cZmI8cUG9T7vbZAPK iKwEdrr/G8rNLzjrlPOr3QhxOBaS7b3OuOvG0DVTRRu6iD3EEnyTmpaWlBrCWTGIG59V MTvm5MaD0Tyv1DDB5fVf1Xwn69nLy/DKlA6H0MPLtR+BIW1uh6Z1xsOuLIhFGhF6ad7S o1d1AlyB0Bsf0y54XXdp8KAI4xsHXp7C6BsxTUYFVcC781Ql+OqFKhZTUE5YiDMACR0H Dpjw==; 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-156248-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156248-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id r28-20020a635d1c000000b005f759a077bbsi10752328pgb.490.2024.04.23.20.59.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 20:59:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-156248-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-156248-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156248-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 170CD28B98B for ; Wed, 24 Apr 2024 03:52:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 402DD148828; Wed, 24 Apr 2024 03:48:41 +0000 (UTC) Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (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 A884A145B27; Wed, 24 Apr 2024 03:48:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713930520; cv=none; b=XKG/WsH7hqqZmwDUX2WTJmogoD3Pn5B+Ew1vbaRQIVXXDOvM48mEwp7JJaUljR6h2Ozg0Eoy6H6Ix7K4uJ3skV1Enf4HQTfL8Rcg8r7yzVXOMNuxjSB+/2s1ZVflwqZEjYHaaKLawzbok4EAz6KcLmRbMeSvfqg2TqhvyxPknWM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713930520; c=relaxed/simple; bh=1pMLCwcIjyuUadKe5TjQo5EuBgcbijo1JIFavcfFCyM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MIsQTka49TKmXP7tBF3flE5wIbYs8L3i51JC1Qxk5BvnlZlJXTu6oprcoyVq6OSdumSUWl6dbTwIgpGauX+TnIVOgoqoriWGplGsKKWRBbnuOF3OaLz5zFlz+a0L9/pjDv+SCcuxFHwDumdFkwE6KESOWRtPOPUERQBEY8JbaQs= 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.51 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 dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VPQ2716x3z4f3kKx; Wed, 24 Apr 2024 11:48:31 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 028581A0175; Wed, 24 Apr 2024 11:48:36 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgCXaBELgShmKXE4Kw--.6143S16; Wed, 24 Apr 2024 11:48:35 +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-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, libaokun@huaweicloud.com, Baokun Li , Hou Tao Subject: [PATCH 12/12] cachefiles: make on-demand read killable Date: Wed, 24 Apr 2024 11:39:16 +0800 Message-Id: <20240424033916.2748488-13-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240424033916.2748488-1-libaokun@huaweicloud.com> References: <20240424033916.2748488-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:cCh0CgCXaBELgShmKXE4Kw--.6143S16 X-Coremail-Antispam: 1UD129KBjvJXoW7uFW7JryDCF4DJr4kXFy7Jrb_yoW8Wr1kpF Wava4rKrykuF4I9rn3A3W8X3ySy3ykAFnrWrySqrW3AanIqrnYvr48t3WYqF45A395WrW3 tr9YgFWxK3Wjv3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWUWVWUuwAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24lc7CjxVAKzI0EY4vE52x082I5MxAIw28IcxkI7VAKI48J MxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwV AFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv2 0xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UMIIF0xvE42xK8V AvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E 14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VUUNBMtUUUUU== X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/ From: Baokun Li Replacing wait_for_completion() with wait_for_completion_killable() in cachefiles_ondemand_send_req() allows us to kill processes that might trigger a hunk_task if the daemon is abnormal. But now only CACHEFILES_OP_READ is killable, because OP_CLOSE and OP_OPEN is initiated from kworker context and the signal is prohibited in these kworker. Note that when the req in xas changes, i.e. xas_load(&xas) != req, it means that a process will complete the current request soon, so wait again for the request to be completed. Suggested-by: Hou Tao Signed-off-by: Baokun Li --- fs/cachefiles/ondemand.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c index 673e7ad52041..b766430f4abf 100644 --- a/fs/cachefiles/ondemand.c +++ b/fs/cachefiles/ondemand.c @@ -525,8 +525,25 @@ static int cachefiles_ondemand_send_req(struct cachefiles_object *object, goto out; wake_up_all(&cache->daemon_pollwq); - wait_for_completion(&req->done); - ret = req->error; +wait: + ret = wait_for_completion_killable(&req->done); + if (!ret) { + ret = req->error; + } else { + xas_reset(&xas); + xas_lock(&xas); + if (xas_load(&xas) == req) { + xas_store(&xas, NULL); + ret = -EINTR; + } + xas_unlock(&xas); + + /* Someone will complete it soon. */ + if (ret != -EINTR) { + cpu_relax(); + goto wait; + } + } cachefiles_req_put(req); return ret; out: -- 2.39.2