Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp3180319lqo; Wed, 15 May 2024 02:01:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVb2Itiwb7CpVyE0IMyPezsvfnWiIor+9YjX6Sa6pArb5pTrPraI19k+q/LcYu/6PKElUmXzXKVG1BJrDIrMx+FSVPs72AGtZteziQDQA== X-Google-Smtp-Source: AGHT+IFQqla9eXAWaf6jtVLngihCQaho6BIFee9+qlaGRUI0Dx4fjJ+N+AXYbBJPN1vTrtmDdQfH X-Received: by 2002:a17:902:d483:b0:1eb:57cb:4c69 with SMTP id d9443c01a7336-1ef43f4d1ebmr192886815ad.45.1715763707800; Wed, 15 May 2024 02:01:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715763707; cv=pass; d=google.com; s=arc-20160816; b=ObaRqAdeDVo9BsCzd3UXSlyNwUkQZIxIRAdcdkWwpGAS3FarY4sqOj5FFYMa0b8P2E bW2IXADimV0hYi/AEXF+ABDgqMqkDHViMkNfyuaylf3CXiyQJDYkDApj8NInC04YIQEo 3DdQzfZJPPiOK4oxBjwyGWtH/RiC0ulH8hpyoz+7NH+O2lspCNSCYvY5JtMLF6TV7AU2 6ZiSCh9J/Akm2rutFTMXrpvmwftM8QmWIk/ewspW88gaKAPpfbF1Y9j52rWv5Kh5VmP8 wqTJKH2QcgXCyGsMjfImb0ezhpN1ItVnOjRyRnG3gkW9DLhluIZS/X+Qn/QNzSbsfLWw 90zw== 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=ot0iK7T3HA38guhI+OwvKXnXLUsnRwj7QBC/oYCN5/c=; fh=dfpuzL54LAMf7GQmHoqmub+qZCPWKUPNTVFHnj8Vxqk=; b=B7Jx4zirfT+RKZabyiouJOjWsXvuKdjcgxO/ApMaIISSylzUW0XBV1Bg1rhMtqOEz9 zJQi21EbdSCYzGJ95+rxBL7V/dmH/rKTJHrM71TqCYplbh3LtTW/T5Cc34TOiHU03SdE Bevl9DayAwASuW8aUAis441iGXw4HYbAVBf6ZROoP+gUnHcKfG615xCJrx+xNXGAjYR2 nmQBUhQxY0qJ0VVanKshmYyXJ+/Pfqku8HfVVdRmQusLMRfjMnqwxoC7YeTOGYg0Ky7q OEnlen1U1QHHZIuseoutl3N/Rf/bM4K6nD0p+uVRnAJUdobpBkuLMt2ErCxZd95Ml/gW mgSg==; 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-179683-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179683-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0b9d13afsi134815405ad.63.2024.05.15.02.01.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 02:01:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-179683-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; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-179683-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179683-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 2C380B23298 for ; Wed, 15 May 2024 08:59:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E895A757FD; Wed, 15 May 2024 08:56:46 +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 A5C5C5C61C; Wed, 15 May 2024 08:56:44 +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=1715763406; cv=none; b=Sg8rHDz7DTsyfcVj/NiPIkaecal34xLn13n4YafaF6a/kvIt1/uWfQMvlkBOHEJAOid/0AP+h5rLV2O2YrtLUe2ppUH434ikFjKP4mDDJ9b5883PIGC37Rgc0KGzZR+Fy/+rl5Lh75I7sLmaW5V/+OMnHGlxMAkTIwwe5bhs+vk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715763406; c=relaxed/simple; bh=G9boZV469M2gzuvk6RuMnXNIMZ3C4lSeJalJhuS4ul8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Rjh5UH1EeQltc4lQXTQdzVZHj+34DGjMP6vQ2k6dLxpVLqTzKj6Vs7LjukmZ9wCyHRD0Ohrtp9m/kfpRu0eKm4DyYRPV7ukZ7hdx1tPv99aQXcUqeatz5tRaQTQMKpH8jMQpGRDaw7kj06egkIc3++YT0yXCB1pBs9rRzMrGJL4= 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.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VfRsm3hffz4f3jXJ; Wed, 15 May 2024 16:56:28 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 2D4DC1A0FE5; Wed, 15 May 2024 16:56:37 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgDHlxC7eERm68LgMg--.42328S16; Wed, 15 May 2024 16:56:36 +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 12/12] cachefiles: make on-demand read killable Date: Wed, 15 May 2024 16:46:01 +0800 Message-Id: <20240515084601.3240503-13-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240515084601.3240503-1-libaokun@huaweicloud.com> References: <20240515084601.3240503-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:cCh0CgDHlxC7eERm68LgMg--.42328S16 X-Coremail-Antispam: 1UD129KBjvJXoW7uFW7JryDCF4DJr4kXFy7Jrb_yoW8WF45pF Waka45KFykuF4I9r93J3WUX34Sy3ykAFnrWrySqrW3AwsIqrnYvr18t3WYqF43A395WrW3 tr95KFyxK3Wjq3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWUuVWrJwAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17 CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0 I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0x vEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIev Ja73UjIFyTuYvjfUYGYpUUUUU 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 Reviewed-by: Jia Zhu --- 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 a511d0a89109..bdc2d6dbadce 100644 --- a/fs/cachefiles/ondemand.c +++ b/fs/cachefiles/ondemand.c @@ -544,8 +544,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