From patchwork Thu Nov 14 19:13:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joanne Koong X-Patchwork-Id: 13875573 Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) (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 9D6761AB51F for ; Thu, 14 Nov 2024 19:13:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611634; cv=none; b=RmePWbOvXfBVXJuCH5HzyKPweZBFa2O+gY/oGJ1B4HPgLbXQ/pf0QeLnK629T3KpnCqPbo4uuITGoKbs4EjZm9VRq0q+TIfgIZzv0ku93EdZLCQx/jhid/on0zERdg2BZI6NxYdwn/aGgho90hlh6cFyLRIByG79pu0OK/83hnw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611634; c=relaxed/simple; bh=XTqdpnqCQUq/lyFP7zkZinayJQkDWOixs7lnvYm0jvo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RHIU2hNED297iKehMF4/SsHXqDblnp5JrzjxZlppCltjFOIizwkTK3XqyhAFL7taG8qSe27iiPdyoaW/n5KZdmvH/vPveaqTs5TdhTThpxma++viAkDEa4xcQHVbaGpP7lBfc6rrNkecnP4tsaKJQwOcgKsSm3Fuqz3l6OnPzOM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=iPpTDb5I; arc=none smtp.client-ip=209.85.219.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iPpTDb5I" Received: by mail-yb1-f180.google.com with SMTP id 3f1490d57ef6-e38193093a7so748791276.0 for ; Thu, 14 Nov 2024 11:13:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731611631; x=1732216431; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aw6yEAfKVb/rJW5k4q7A4sTnqwnlBXS09YR6aNAi5U8=; b=iPpTDb5Ii5hTh8ZtA/Z2zvYDxU3eouIyIRExqWbBzZ5C2ykJAYqoWaUtjx16iSDMM5 24UVvosZbXV05uwk2TdU1LlteBYhz/GKN5bafj5nmMzvAJ/tfvFpcqm3DE17co5Ri+Py /7eV3x3VPmD9FAqbziR20kHQbNWL2ujaAfiRruBw0yOlCD3JUhqbKEBeQ+Y1/wfCiqUe nRatkvUq6ESqL9XMqPysWQmdrYYsp/cBGm4wDvlmal7+FvjFJU8bBGZyP4lO3LYirZR+ ipEgmjHzgJ9IJOVhwVIuxqH1zFHmE4AyhZWZjmZfiyWZ0V4RBk6vMu+c8pIOSewg/0ab VL3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731611631; x=1732216431; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aw6yEAfKVb/rJW5k4q7A4sTnqwnlBXS09YR6aNAi5U8=; b=UCiMcHKHOcSX4GUGvjGzj/skPCxX0Oe2MjBjCfat6W/0ntUFoxudbH0nVsBEmOvQ1E AOhew9X2uxUydQZ6C5ZltmJAkQZ5eAOtoKI+eo7TxroTTHYkfPy2+NDEBAwRE48z+3MB fBr0wD74rX7WoUMufFZcw6SFAAa+Nj2d9beVm7LNS4qy9R4dfSOjJ1Tm+1t3rM0CzQ/Y zUQ1gq1NTKmiEWRrqp0iXziV1DpTmVqrMCKxSF8Y+0Zk52HFobzmSI/jpWYBpi4+UdoO q5O+Kp8VufgApFSFfcUHG6vEj2u+2AeCXzeLjmw3A3lIyaynuoP0ZYA3nRnh2WnNnE5h eK2A== X-Forwarded-Encrypted: i=1; AJvYcCUgZIA9NFyy97oQf7kdCrZf5crSWFftoEHSM8lO8YUlmPTYyjYYa1/DfrIO8NhDFRPVclpNSwf27e80ayEI@vger.kernel.org X-Gm-Message-State: AOJu0YyiH7Kwl0oixoE5aEj6DLxdMF1dFtayZM66+Yi8G+MqJX0rRH5d Upo6zMix3sXLM5KZLTNgBJ6EYsBtMlxFj2i+1SLV40fubDwE8WLq X-Google-Smtp-Source: AGHT+IHfK6FdLsWwcF5qvTOk0MIcLBo07MSwwVmcfGvB9zQWa9k4bBl1UzOYK5Ajb8+/N9k12UkLRg== X-Received: by 2002:a05:6902:3402:b0:e2b:9ae5:5bf7 with SMTP id 3f1490d57ef6-e38140e52demr3261026276.19.1731611631499; Thu, 14 Nov 2024 11:13:51 -0800 (PST) Received: from localhost (fwdproxy-nha-005.fbsv.net. [2a03:2880:25ff:5::face:b00c]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e381545ae2esm467773276.38.2024.11.14.11.13.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:13:51 -0800 (PST) From: Joanne Koong To: miklos@szeredi.hu, linux-fsdevel@vger.kernel.org Cc: josef@toxicpanda.com, bernd.schubert@fastmail.fm, jefflexu@linux.alibaba.com, laoar.shao@gmail.com, kernel-team@meta.com, Bernd Schubert Subject: [PATCH RESEND v9 1/3] fs_parser: add fsparam_u16 helper Date: Thu, 14 Nov 2024 11:13:30 -0800 Message-ID: <20241114191332.669127-2-joannelkoong@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241114191332.669127-1-joannelkoong@gmail.com> References: <20241114191332.669127-1-joannelkoong@gmail.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add a fsparam helper for unsigned 16 bit values. Signed-off-by: Joanne Koong Reviewed-by: Bernd Schubert --- fs/fs_parser.c | 14 ++++++++++++++ include/linux/fs_parser.h | 9 ++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/fs/fs_parser.c b/fs/fs_parser.c index 24727ec34e5a..0e06f9618c89 100644 --- a/fs/fs_parser.c +++ b/fs/fs_parser.c @@ -210,6 +210,20 @@ int fs_param_is_bool(struct p_log *log, const struct fs_parameter_spec *p, } EXPORT_SYMBOL(fs_param_is_bool); +int fs_param_is_u16(struct p_log *log, const struct fs_parameter_spec *p, + struct fs_parameter *param, struct fs_parse_result *result) +{ + int base = (unsigned long)p->data; + if (param->type != fs_value_is_string) + return fs_param_bad_value(log, param); + if (!*param->string && (p->flags & fs_param_can_be_empty)) + return 0; + if (kstrtou16(param->string, base, &result->uint_16) < 0) + return fs_param_bad_value(log, param); + return 0; +} +EXPORT_SYMBOL(fs_param_is_u16); + int fs_param_is_u32(struct p_log *log, const struct fs_parameter_spec *p, struct fs_parameter *param, struct fs_parse_result *result) { diff --git a/include/linux/fs_parser.h b/include/linux/fs_parser.h index 6cf713a7e6c6..84acd7acef50 100644 --- a/include/linux/fs_parser.h +++ b/include/linux/fs_parser.h @@ -26,9 +26,10 @@ typedef int fs_param_type(struct p_log *, /* * The type of parameter expected. */ -fs_param_type fs_param_is_bool, fs_param_is_u32, fs_param_is_s32, fs_param_is_u64, - fs_param_is_enum, fs_param_is_string, fs_param_is_blob, fs_param_is_blockdev, - fs_param_is_path, fs_param_is_fd, fs_param_is_uid, fs_param_is_gid; +fs_param_type fs_param_is_bool, fs_param_is_u16, fs_param_is_u32, fs_param_is_s32, + fs_param_is_u64, fs_param_is_enum, fs_param_is_string, fs_param_is_blob, + fs_param_is_blockdev, fs_param_is_path, fs_param_is_fd, fs_param_is_uid, + fs_param_is_gid; /* * Specification of the type of value a parameter wants. @@ -55,6 +56,7 @@ struct fs_parse_result { union { bool boolean; /* For spec_bool */ int int_32; /* For spec_s32/spec_enum */ + u16 uint_16; /* For spec_u16{,_octal,_hex}/spec_enum */ unsigned int uint_32; /* For spec_u32{,_octal,_hex}/spec_enum */ u64 uint_64; /* For spec_u64 */ kuid_t uid; @@ -119,6 +121,7 @@ static inline bool fs_validate_description(const char *name, #define fsparam_flag_no(NAME, OPT) \ __fsparam(NULL, NAME, OPT, fs_param_neg_with_no, NULL) #define fsparam_bool(NAME, OPT) __fsparam(fs_param_is_bool, NAME, OPT, 0, NULL) +#define fsparam_u16(NAME, OPT) __fsparam(fs_param_is_u16, NAME, OPT, 0, NULL) #define fsparam_u32(NAME, OPT) __fsparam(fs_param_is_u32, NAME, OPT, 0, NULL) #define fsparam_u32oct(NAME, OPT) \ __fsparam(fs_param_is_u32, NAME, OPT, 0, (void *)8) From patchwork Thu Nov 14 19:13:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joanne Koong X-Patchwork-Id: 13875574 Received: from mail-yw1-f180.google.com (mail-yw1-f180.google.com [209.85.128.180]) (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 4C6251ABEA1 for ; Thu, 14 Nov 2024 19:13:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611636; cv=none; b=j3HZW90JW00b4MSZzY1DNXaUr81+Ihrb5CUibR/Qv6VCBkS5EGsfyqVMMrrYQkL742t3KZplxXFZtezgpZSI0fGKqjOL1DSBzsvivKpYzyTGpZYY7tf2sh5mVxpI7blrchauYftlqkOBc7pUob9ODgvHw1+lzOWELm/FSCSIYww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611636; c=relaxed/simple; bh=0SuE55RkA5E+LBqO8lUOgOZPPlh2syIt9/gaYS9uTCc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EV9d4s7QkiGQ6P7/Toy2ZQa4s+Y+9eSjphfJ/G5CUEqoaxR9DoAt8lkbidORR0wlPCnNKHordzUuLKTWHs+O1cgk0Z1/zHRBnOobTGb8Dx8Luz/HF7svdrswe/wjPxOoHTqNFtljGQ5vPoTXsVofpY0rIia4pRM23UziK41P2PA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gdvkvxMB; arc=none smtp.client-ip=209.85.128.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gdvkvxMB" Received: by mail-yw1-f180.google.com with SMTP id 00721157ae682-6ea85f7f445so10654587b3.0 for ; Thu, 14 Nov 2024 11:13:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731611633; x=1732216433; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4Zj6VQ5V5mAxCWloUS8Kj9By1xu0Ish6ebhkeGJjc8Y=; b=gdvkvxMB6wGilPUCm0FCbqW1L8ThLk6gE1rNZm7vxy1UhESrvTS9Y5oomrd3uKlgtO BvyHCaa7eCu3u5eWLi0LeSWv8ZuPRJDeMa77crpvtFxN//KI0906z1VgHnYaDJfGnXfI nJr3cIThYuaPE8HjvhcMGDJnwuU+Wy0437dCGEOIryAQcFNaXzu/2vPlwvTOJCMOF+jF d4q2ki0CJmjnPv+AM1IQlfwjEb0cqF0SjRkMa3K4RDqWpSvCYXnv0Kf1B5ExN/RlM+YR fzZjXw7gOy/w6jUT4E5QKD4aeu3/dmAhl18lcUJfmyRTY+6Hqn7RfwNLz+e6vGqUvwRU z92g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731611633; x=1732216433; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4Zj6VQ5V5mAxCWloUS8Kj9By1xu0Ish6ebhkeGJjc8Y=; b=AmS/dAecckJJpIXkHaEKsDDkwIRhnlLQSvPBevtRMmccJ/x2JiwahhFIpVLLPGHSum K8nxarFeCdKuL4Ac/1EmOLebDo3pHfWbx5megMcSYM6ozipJ89+c8BIquIHLEhfwXofA Jy7/hyy2vv4bbZg5j6WMOHfktUv/+w+yZEYJAC4fjXHrn9YVRcMGRKys1+X9GlGmgQSm COrAva5S8alrvrnDGbbVzs1/4NdftAPEiuZG1vL8ntPY3Sj/fU/6SGtL4MIZNJT2XURa R1rmmV5awUJqdp+1bBX/izYL6AaiYZHGuA7U/MfGhvN3bN4ZhsFWbEif6dlriVVpzwUy 5JuQ== X-Forwarded-Encrypted: i=1; AJvYcCWq4/rJsbgGKW9qP24qcBkySUrXeYC8ZaUMEo5WvioEJc0iDU4fSWZmyB4rCKzQqlZ7tv6UkTAtrhtM3MCD@vger.kernel.org X-Gm-Message-State: AOJu0Yz1ozIPNftMNhwe6FYGwHgGap9dgFtJ+kcLL5DjXGT7RRiEF2ai fqwntdT0n9wjtzeWHjAmFGrL0UY2eT0uGK5mnPIxrm5bwuNDdN94 X-Google-Smtp-Source: AGHT+IFBHLU86BSfd7LJgLZfK7Hn2l3e+pIEtRJv1E95vcChba7dS26qufPWYDyt70sp4IHD/yTDMg== X-Received: by 2002:a05:690c:6705:b0:6ee:5158:5909 with SMTP id 00721157ae682-6ee55a3b337mr721017b3.4.1731611633082; Thu, 14 Nov 2024 11:13:53 -0800 (PST) Received: from localhost (fwdproxy-nha-001.fbsv.net. [2a03:2880:25ff:1::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ee44412699sm3797817b3.83.2024.11.14.11.13.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:13:52 -0800 (PST) From: Joanne Koong To: miklos@szeredi.hu, linux-fsdevel@vger.kernel.org Cc: josef@toxicpanda.com, bernd.schubert@fastmail.fm, jefflexu@linux.alibaba.com, laoar.shao@gmail.com, kernel-team@meta.com, Bernd Schubert Subject: [PATCH RESEND v9 2/3] fuse: add optional kernel-enforced timeout for requests Date: Thu, 14 Nov 2024 11:13:31 -0800 Message-ID: <20241114191332.669127-3-joannelkoong@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241114191332.669127-1-joannelkoong@gmail.com> References: <20241114191332.669127-1-joannelkoong@gmail.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There are situations where fuse servers can become unresponsive or stuck, for example if the server is deadlocked. Currently, there's no good way to detect if a server is stuck and needs to be killed manually. This commit adds an option for enforcing a timeout (in minutes) for requests where if the timeout elapses without the server responding to the request, the connection will be automatically aborted. Please note that these timeouts are not 100% precise. The request may take an extra FUSE_TIMEOUT_TIMER_FREQ seconds beyond the requested max timeout due to how it's internally implemented. Signed-off-by: Joanne Koong Reviewed-by: Bernd Schubert --- fs/fuse/dev.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/fuse/fuse_i.h | 21 +++++++++++++ fs/fuse/inode.c | 21 +++++++++++++ 3 files changed, 122 insertions(+) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 29fc61a072ba..536aa4525e8f 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -45,6 +45,82 @@ static struct fuse_dev *fuse_get_dev(struct file *file) return READ_ONCE(file->private_data); } +static bool request_expired(struct fuse_conn *fc, struct fuse_req *req) +{ + return jiffies > req->create_time + fc->timeout.req_timeout; +} + +/* + * Check if any requests aren't being completed by the specified request + * timeout. To do so, we: + * - check the fiq pending list + * - check the bg queue + * - check the fpq io and processing lists + * + * To make this fast, we only check against the head request on each list since + * these are generally queued in order of creation time (eg newer requests get + * queued to the tail). We might miss a few edge cases (eg requests transitioning + * between lists, re-sent requests at the head of the pending list having a + * later creation time than other requests on that list, etc.) but that is fine + * since if the request never gets fulfilled, it will eventually be caught. + */ +void fuse_check_timeout(struct timer_list *timer) +{ + struct fuse_conn *fc = container_of(timer, struct fuse_conn, timeout.timer); + struct fuse_iqueue *fiq = &fc->iq; + struct fuse_req *req; + struct fuse_dev *fud; + struct fuse_pqueue *fpq; + bool expired = false; + int i; + + spin_lock(&fiq->lock); + req = list_first_entry_or_null(&fiq->pending, struct fuse_req, list); + if (req) + expired = request_expired(fc, req); + spin_unlock(&fiq->lock); + if (expired) + goto abort_conn; + + spin_lock(&fc->bg_lock); + req = list_first_entry_or_null(&fc->bg_queue, struct fuse_req, list); + if (req) + expired = request_expired(fc, req); + spin_unlock(&fc->bg_lock); + if (expired) + goto abort_conn; + + spin_lock(&fc->lock); + if (!fc->connected) { + spin_unlock(&fc->lock); + return; + } + list_for_each_entry(fud, &fc->devices, entry) { + fpq = &fud->pq; + spin_lock(&fpq->lock); + req = list_first_entry_or_null(&fpq->io, struct fuse_req, list); + if (req && request_expired(fc, req)) + goto fpq_abort; + + for (i = 0; i < FUSE_PQ_HASH_SIZE; i++) { + req = list_first_entry_or_null(&fpq->processing[i], struct fuse_req, list); + if (req && request_expired(fc, req)) + goto fpq_abort; + } + spin_unlock(&fpq->lock); + } + spin_unlock(&fc->lock); + + mod_timer(&fc->timeout.timer, jiffies + FUSE_TIMEOUT_TIMER_FREQ); + return; + +fpq_abort: + spin_unlock(&fpq->lock); + spin_unlock(&fc->lock); +abort_conn: + fuse_abort_conn(fc); +} + static void fuse_request_init(struct fuse_mount *fm, struct fuse_req *req) { INIT_LIST_HEAD(&req->list); @@ -53,6 +129,7 @@ static void fuse_request_init(struct fuse_mount *fm, struct fuse_req *req) refcount_set(&req->count, 1); __set_bit(FR_PENDING, &req->flags); req->fm = fm; + req->create_time = jiffies; } static struct fuse_req *fuse_request_alloc(struct fuse_mount *fm, gfp_t flags) @@ -2308,6 +2385,9 @@ void fuse_abort_conn(struct fuse_conn *fc) spin_unlock(&fc->lock); end_requests(&to_end); + + if (fc->timeout.req_timeout) + timer_delete(&fc->timeout.timer); } else { spin_unlock(&fc->lock); } diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index d35c37ccf9b5..9092201c4e0b 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -438,6 +438,9 @@ struct fuse_req { /** fuse_mount this request belongs to */ struct fuse_mount *fm; + + /** When (in jiffies) the request was created */ + unsigned long create_time; }; struct fuse_iqueue; @@ -528,6 +531,16 @@ struct fuse_pqueue { struct list_head io; }; +/* Frequency (in seconds) of request timeout checks, if opted into */ +#define FUSE_TIMEOUT_TIMER_FREQ 60 * HZ + +struct fuse_timeout { + struct timer_list timer; + + /* Request timeout (in jiffies). 0 = no timeout */ + unsigned long req_timeout; +}; + /** * Fuse device instance */ @@ -574,6 +587,8 @@ struct fuse_fs_context { enum fuse_dax_mode dax_mode; unsigned int max_read; unsigned int blksize; + /* Request timeout (in minutes). 0 = no timeout (infinite wait) */ + unsigned int req_timeout; const char *subtype; /* DAX device, may be NULL */ @@ -920,6 +935,9 @@ struct fuse_conn { /** IDR for backing files ids */ struct idr backing_files_map; #endif + + /** Only used if the connection enforces request timeouts */ + struct fuse_timeout timeout; }; /* @@ -1181,6 +1199,9 @@ void fuse_request_end(struct fuse_req *req); void fuse_abort_conn(struct fuse_conn *fc); void fuse_wait_aborted(struct fuse_conn *fc); +/* Check if any requests timed out */ +void fuse_check_timeout(struct timer_list *timer); + /** * Invalidate inode attributes */ diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index f1779ff3f8d1..ee006f09cd04 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -735,6 +735,7 @@ enum { OPT_ALLOW_OTHER, OPT_MAX_READ, OPT_BLKSIZE, + OPT_REQUEST_TIMEOUT, OPT_ERR }; @@ -749,6 +750,7 @@ static const struct fs_parameter_spec fuse_fs_parameters[] = { fsparam_u32 ("max_read", OPT_MAX_READ), fsparam_u32 ("blksize", OPT_BLKSIZE), fsparam_string ("subtype", OPT_SUBTYPE), + fsparam_u16 ("request_timeout", OPT_REQUEST_TIMEOUT), {} }; @@ -844,6 +846,10 @@ static int fuse_parse_param(struct fs_context *fsc, struct fs_parameter *param) ctx->blksize = result.uint_32; break; + case OPT_REQUEST_TIMEOUT: + ctx->req_timeout = result.uint_16; + break; + default: return -EINVAL; } @@ -973,6 +979,8 @@ void fuse_conn_put(struct fuse_conn *fc) if (IS_ENABLED(CONFIG_FUSE_DAX)) fuse_dax_conn_free(fc); + if (fc->timeout.req_timeout) + timer_shutdown_sync(&fc->timeout.timer); if (fiq->ops->release) fiq->ops->release(fiq); put_pid_ns(fc->pid_ns); @@ -1691,6 +1699,18 @@ int fuse_init_fs_context_submount(struct fs_context *fsc) } EXPORT_SYMBOL_GPL(fuse_init_fs_context_submount); +static void fuse_init_fc_timeout(struct fuse_conn *fc, struct fuse_fs_context *ctx) +{ + if (ctx->req_timeout) { + if (check_mul_overflow(ctx->req_timeout * 60, HZ, &fc->timeout.req_timeout)) + fc->timeout.req_timeout = ULONG_MAX; + timer_setup(&fc->timeout.timer, fuse_check_timeout, 0); + mod_timer(&fc->timeout.timer, jiffies + FUSE_TIMEOUT_TIMER_FREQ); + } else { + fc->timeout.req_timeout = 0; + } +} + int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx) { struct fuse_dev *fud = NULL; @@ -1753,6 +1773,7 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx) fc->destroy = ctx->destroy; fc->no_control = ctx->no_control; fc->no_force_umount = ctx->no_force_umount; + fuse_init_fc_timeout(fc, ctx); err = -ENOMEM; root = fuse_get_root_inode(sb, ctx->rootmode); From patchwork Thu Nov 14 19:13:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joanne Koong X-Patchwork-Id: 13875575 Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.171]) (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 D39B81ABEBB for ; Thu, 14 Nov 2024 19:13:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611637; cv=none; b=GK/Y49hF7KcDlo/gdl/z6FrebrLFtgK6ualaQTeyvkKA5TYEkrWf47ZadhxUG0W3xjpRrjkWb9P571WxCIRuZp0EQZ8DlJDl9N0UpTd/pOj41f/4jXIWKm6do2kzhwD2hSg9Hwnulg7QbWf/bDT0hj08jgIHi7T7rR/VrUZElTU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611637; c=relaxed/simple; bh=yGjq2THbmv9V+Y9hO2p8tlo7MFsMcJM2+0aeHs/zKWQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FhDyyN8sJoICpc0SIsCWlAdhq0cQuOP1OuQ7IPamCTLfeUksfs+845V2kLOgtES8rdbsvpBKB4IYoF06nXuKd06d2Ifw/I312Datxfv7h0cWjlFhdPRBISJ08lxyurcsGnfyO9Ch52xJukI/5SDaRU8/9F+gBqPm15+Vh1Tvsm4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=K9TE25O5; arc=none smtp.client-ip=209.85.128.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="K9TE25O5" Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-6ea7c9227bfso11514487b3.2 for ; Thu, 14 Nov 2024 11:13:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731611635; x=1732216435; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SAQF0WkcxGB4AMW/MmznpwNgMYPbmkZ5lpmeYrrfBhA=; b=K9TE25O5DEyMz5pfePhlFEo8hgvyEoSXfoabyDICyRvELSJA8pMq5Ri51HSruhi8/h kibipoj9DQ/ihUWbXn7dO7PHlOK1gCgRQDYtlC2l2KsRu6evPX/YUldKNgzYyIrm+WX8 dgwNgAtEMhb555Lt6tZmXyyAhKNtuaImp/P/9lqM+DdXMVdSD72/2cHbrHx0BKAoLqIk C9xspu0AJr574UlxX2HQEyBX70PYTmcXNwy53SeByg3diiSjv4FSdaJZh1TnerdslVqA E7Zt79zQouOsxRsgUPacPfaGkGtYz43AUw9AeywEUmBTB9dQbN8GbNhVCa8oRtCma2Kd trJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731611635; x=1732216435; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SAQF0WkcxGB4AMW/MmznpwNgMYPbmkZ5lpmeYrrfBhA=; b=ZI+cl6D8fMQPT4Q8ZnRSL+YsItX8tsl2h2TP059788Zx+kwKGTdVsFvSiiuFMQwk5f Qw1t9m2hxvVyiA/JeHVg4acaVp5ocW9NEjN5nIDlA3aU858lBNevAXzqo0fsD9nrDkno KFC56/mMV51OKz+GUJTFTVmyXzfXu7wz7FFwAzkBhcUKDoV+kg2S8olKcMlJVhqOMmlj 6oPQ1b+oWtceoXnpF9ecTinMLxjFcjl+GlEq5NK442qBk3pF5Dtlj18gu8uKI4yhgXHW LHCA1iuLVQKLicGMB0uM6/9x+f10Db+/qRAgqnsynK2jkQbsnIKVpW2h9DmDgsHtFqMf IQdA== X-Forwarded-Encrypted: i=1; AJvYcCW/d+7BhHEZL/vJdyxI2jOpQBHYl1dU4285LPPUuEL6gg977CKTLTF9djFAUb09oKSMvgyHSuO9OvrJkwOz@vger.kernel.org X-Gm-Message-State: AOJu0YwRf9y0r0IY0R71IKs/1Joo7JU/AbOsKGpPMK8jnaDlbQfEvp0q 9TltjQ4K9nFqYlM8/3ZCkdkVpwdJFw8Y4Q64ulcnewPN3Z8fZT/u X-Google-Smtp-Source: AGHT+IGiKOemj4DhFvPKGQlPs9pOnNjxhkgQPv56vNm1ewN/4uPArYUPGy8/+kQYNaPZWv8m4qrzUg== X-Received: by 2002:a05:690c:6207:b0:6ea:84e9:15fb with SMTP id 00721157ae682-6ee55c263e8mr459787b3.24.1731611634614; Thu, 14 Nov 2024 11:13:54 -0800 (PST) Received: from localhost (fwdproxy-nha-014.fbsv.net. [2a03:2880:25ff:e::face:b00c]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ee444124e2sm3783077b3.85.2024.11.14.11.13.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:13:54 -0800 (PST) From: Joanne Koong To: miklos@szeredi.hu, linux-fsdevel@vger.kernel.org Cc: josef@toxicpanda.com, bernd.schubert@fastmail.fm, jefflexu@linux.alibaba.com, laoar.shao@gmail.com, kernel-team@meta.com, Bernd Schubert Subject: [PATCH RESEND v9 3/3] fuse: add default_request_timeout and max_request_timeout sysctls Date: Thu, 14 Nov 2024 11:13:32 -0800 Message-ID: <20241114191332.669127-4-joannelkoong@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241114191332.669127-1-joannelkoong@gmail.com> References: <20241114191332.669127-1-joannelkoong@gmail.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Introduce two new sysctls, "default_request_timeout" and "max_request_timeout". These control how long (in minutes) a server can take to reply to a request. If the server does not reply by the timeout, then the connection will be aborted. "default_request_timeout" sets the default timeout if no timeout is specified by the fuse server on mount. 0 (default) indicates no default timeout should be enforced. If the server did specify a timeout, then default_request_timeout will be ignored. "max_request_timeout" sets the max amount of time the server may take to reply to a request. 0 (default) indicates no maximum timeout. If max_request_timeout is set and the fuse server attempts to set a timeout greater than max_request_timeout, the system will use max_request_timeout as the timeout. Similarly, if default_request_timeout is greater than max_request_timeout, the system will use max_request_timeout as the timeout. If the server does not request a timeout and default_request_timeout is set to 0 but max_request_timeout is set, then the timeout will be max_request_timeout. Please note that these timeouts are not 100% precise. The request may take an extra FUSE_TIMEOUT_TIMER_FREQ seconds beyond the set max timeout due to how it's internally implemented. $ sysctl -a | grep fuse.default_request_timeout fs.fuse.default_request_timeout = 0 $ echo 65536 | sudo tee /proc/sys/fs/fuse/default_request_timeout tee: /proc/sys/fs/fuse/default_request_timeout: Invalid argument $ echo 65535 | sudo tee /proc/sys/fs/fuse/default_request_timeout 65535 $ sysctl -a | grep fuse.default_request_timeout fs.fuse.default_request_timeout = 65535 $ echo 0 | sudo tee /proc/sys/fs/fuse/default_request_timeout 0 $ sysctl -a | grep fuse.default_request_timeout fs.fuse.default_request_timeout = 0 Signed-off-by: Joanne Koong Reviewed-by: Bernd Schubert --- Documentation/admin-guide/sysctl/fs.rst | 27 +++++++++++++++++++++++++ fs/fuse/fuse_i.h | 10 +++++++++ fs/fuse/inode.c | 16 +++++++++++++-- fs/fuse/sysctl.c | 20 ++++++++++++++++++ 4 files changed, 71 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/sysctl/fs.rst b/Documentation/admin-guide/sysctl/fs.rst index fa25d7e718b3..790a34291467 100644 --- a/Documentation/admin-guide/sysctl/fs.rst +++ b/Documentation/admin-guide/sysctl/fs.rst @@ -342,3 +342,30 @@ filesystems: ``/proc/sys/fs/fuse/max_pages_limit`` is a read/write file for setting/getting the maximum number of pages that can be used for servicing requests in FUSE. + +``/proc/sys/fs/fuse/default_request_timeout`` is a read/write file for +setting/getting the default timeout (in minutes) for a fuse server to +reply to a kernel-issued request in the event where the server did not +specify a timeout at mount. If the server set a timeout, +then default_request_timeout will be ignored. The default +"default_request_timeout" is set to 0. 0 indicates a no-op (eg +requests will not have a default request timeout set if no timeout was +specified by the server). + +``/proc/sys/fs/fuse/max_request_timeout`` is a read/write file for +setting/getting the maximum timeout (in minutes) for a fuse server to +reply to a kernel-issued request. A value greater than 0 automatically opts +the server into a timeout that will be at most "max_request_timeout", even if +the server did not specify a timeout and default_request_timeout is set to 0. +If max_request_timeout is greater than 0 and the server set a timeout greater +than max_request_timeout or default_request_timeout is set to a value greater +than max_request_timeout, the system will use max_request_timeout as the +timeout. 0 indicates a no-op (eg requests will not have an upper bound on the +timeout and if the server did not request a timeout and default_request_timeout +was not set, there will be no timeout). + +Please note that for the timeout options, if the server does not respond to +the request by the time the timeout elapses, then the connection to the fuse +server will be aborted. Please also note that the timeouts are not 100% +precise (eg you may set 10 minutes but the timeout may kick in after 11 +minutes). diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 9092201c4e0b..e82ddff8d752 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -46,6 +46,16 @@ /** Maximum of max_pages received in init_out */ extern unsigned int fuse_max_pages_limit; +/* + * Default timeout (in minutes) for the server to reply to a request + * before the connection is aborted, if no timeout was specified on mount. + */ +extern unsigned int fuse_default_req_timeout; +/* + * Max timeout (in minutes) for the server to reply to a request before + * the connection is aborted. + */ +extern unsigned int fuse_max_req_timeout; /** List of active connections */ extern struct list_head fuse_conn_list; diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index ee006f09cd04..1e7cc6509e42 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -36,6 +36,9 @@ DEFINE_MUTEX(fuse_mutex); static int set_global_limit(const char *val, const struct kernel_param *kp); unsigned int fuse_max_pages_limit = 256; +/* default is no timeout */ +unsigned int fuse_default_req_timeout = 0; +unsigned int fuse_max_req_timeout = 0; unsigned max_user_bgreq; module_param_call(max_user_bgreq, set_global_limit, param_get_uint, @@ -1701,8 +1704,17 @@ EXPORT_SYMBOL_GPL(fuse_init_fs_context_submount); static void fuse_init_fc_timeout(struct fuse_conn *fc, struct fuse_fs_context *ctx) { - if (ctx->req_timeout) { - if (check_mul_overflow(ctx->req_timeout * 60, HZ, &fc->timeout.req_timeout)) + unsigned int timeout = ctx->req_timeout ?: fuse_default_req_timeout; + + if (fuse_max_req_timeout) { + if (!timeout) + timeout = fuse_max_req_timeout; + else + timeout = min(timeout, fuse_max_req_timeout); + } + + if (timeout) { + if (check_mul_overflow(timeout * 60, HZ, &fc->timeout.req_timeout)) fc->timeout.req_timeout = ULONG_MAX; timer_setup(&fc->timeout.timer, fuse_check_timeout, 0); mod_timer(&fc->timeout.timer, jiffies + FUSE_TIMEOUT_TIMER_FREQ); diff --git a/fs/fuse/sysctl.c b/fs/fuse/sysctl.c index b272bb333005..6a9094e17950 100644 --- a/fs/fuse/sysctl.c +++ b/fs/fuse/sysctl.c @@ -13,6 +13,8 @@ static struct ctl_table_header *fuse_table_header; /* Bound by fuse_init_out max_pages, which is a u16 */ static unsigned int sysctl_fuse_max_pages_limit = 65535; +static unsigned int sysctl_fuse_max_req_timeout_limit = U16_MAX; + static struct ctl_table fuse_sysctl_table[] = { { .procname = "max_pages_limit", @@ -23,6 +25,24 @@ static struct ctl_table fuse_sysctl_table[] = { .extra1 = SYSCTL_ONE, .extra2 = &sysctl_fuse_max_pages_limit, }, + { + .procname = "default_request_timeout", + .data = &fuse_default_req_timeout, + .maxlen = sizeof(fuse_default_req_timeout), + .mode = 0644, + .proc_handler = proc_douintvec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = &sysctl_fuse_max_req_timeout_limit, + }, + { + .procname = "max_request_timeout", + .data = &fuse_max_req_timeout, + .maxlen = sizeof(fuse_max_req_timeout), + .mode = 0644, + .proc_handler = proc_douintvec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = &sysctl_fuse_max_req_timeout_limit, + }, }; int fuse_sysctl_register(void)