Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5178795img; Wed, 27 Mar 2019 03:46:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqxHhDhS0Vnc+PWlkzv38SVpobc5T7IEhHk/jXZ7G5AbGzkIX8fkXJf6J7rL1XJAYa4aHgkl X-Received: by 2002:a62:75d7:: with SMTP id q206mr11157099pfc.213.1553683597209; Wed, 27 Mar 2019 03:46:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553683597; cv=none; d=google.com; s=arc-20160816; b=JPnBwbveeETqywHC1T3bOewyb2zXhmt7qSavd0jipTXx6RnNZh26tih2aLgxf9t6O2 tbz/lVH3MOggNrTRIqMzg1+OTWTz4kL6tj3h73Bn9y9JQt/LpzdJgRHY0qce4mfAbgMX T1/5/pA+Ym0uyQWIWkYbEXtIe4b2G9dv89Dd/jBaNown9FiRCGUy/32LvgO4duquelUL MIn7yFtIe1xUZb3jFVLBRyHvhsE6Nj7utbIw+XWrz9HqaSeeZwLnoqdW7ToRvx+B1Ewj a6uhWKiWbIl9v1YTq36DbLKSKlVvq5rAr9p8IfKQ9Lb9fuoHCwmrS1iE+OSKrPpAYzLD hw3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :date:references:in-reply-to:message-id:cc:to:subject:from :dkim-signature:dkim-signature; bh=qZZSsnfZjwS1Mn9CA2yZlrd+GTax9gGW7CsTVUXwZqM=; b=n5DMDbROwvriHiswJWRyaT7DverLBD9xd6iz4BjkKjQWT2Yo3jr6iYk/OLpUzwzsqu erEi4KuhsHRXpkEdxk0hyHct8wfnQz3g0HqQ5yvQEo+qyDF4O1toPQ8MFwg822kRU6FF K8ios698bxTbccXe6QgI1hvI2N2ckUvHrhkcAdrqhuNBBXg0KlW26fD2x6NGZZfBlvWr b3GKluu7YiqFzGfFOhrds1BA3f0QBd/RD4N1G8JdWSFXQasLck44zPQOoaEEMHVX/Vh1 JbVEZ/sPsZmz1pB54HmeZgtf+kF5eK4oD5kDqa5hfLmF88BhL4Chhfd7hIwAQB1TKe5P U7NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nexedi.com header.s=mandrill header.b="j6/h1F6I"; dkim=pass header.i=@mandrillapp.com header.s=mandrill header.b=hqsx7tqf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i69si19556113plb.75.2019.03.27.03.46.21; Wed, 27 Mar 2019 03:46:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nexedi.com header.s=mandrill header.b="j6/h1F6I"; dkim=pass header.i=@mandrillapp.com header.s=mandrill header.b=hqsx7tqf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732969AbfC0KpT (ORCPT + 99 others); Wed, 27 Mar 2019 06:45:19 -0400 Received: from mail128-16.atl41.mandrillapp.com ([198.2.128.16]:18183 "EHLO mail128-16.atl41.mandrillapp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731668AbfC0KpT (ORCPT ); Wed, 27 Mar 2019 06:45:19 -0400 X-Greylist: delayed 903 seconds by postgrey-1.27 at vger.kernel.org; Wed, 27 Mar 2019 06:45:18 EDT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; s=mandrill; d=nexedi.com; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Date:MIME-Version:Content-Type:Content-Transfer-Encoding; i=kirr@nexedi.com; bh=qZZSsnfZjwS1Mn9CA2yZlrd+GTax9gGW7CsTVUXwZqM=; b=j6/h1F6I628yHjiRDhJmjZ3RXah6ZyeDHJzsLkaLshYAC8ohSGmEj/3h9v3HIw16JblHwOHHonb4 nuE7PeB3LQckIjsWQs0Zi2iuOF4EKi99MgfyImNBe1pGic/QlZAs2nsa8qHf6VvpjpjVwaoH24ln IEcaFu4i0nWWeMjeWLo= Received: from pmta01.mandrill.prod.atl01.rsglab.com (127.0.0.1) by mail128-16.atl41.mandrillapp.com id hjda3s1mqukt for ; Wed, 27 Mar 2019 10:15:18 +0000 (envelope-from ) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; i=@mandrillapp.com; q=dns/txt; s=mandrill; t=1553681718; h=From : Subject : To : Cc : Message-Id : In-Reply-To : References : Date : MIME-Version : Content-Type : Content-Transfer-Encoding : From : Subject : Date : X-Mandrill-User : List-Unsubscribe; bh=qZZSsnfZjwS1Mn9CA2yZlrd+GTax9gGW7CsTVUXwZqM=; b=hqsx7tqfMjrBaH7sDXqPOAz8qnVbhttufWAXFSt+bhNQFQ7X1DWk1Ucr+q1ismVn/sR1/p FX/fIziK1bpXpAdwAao9+KdMy9JWKTN+P3w5uJK6yH0p6bu0D6Gnuxf7PrT1gNBi6FnKjFyt qe7JIdptPVlYSCNh0DEOAqFKazbVI= From: Kirill Smelkov Subject: [RESEND4, PATCH 1/2] fuse: retrieve: cap requested size to negotiated max_write Received: from [87.98.221.171] by mandrillapp.com id 724e808b8ada4d2a9f13fe3df0362240; Wed, 27 Mar 2019 10:15:18 +0000 X-Mailer: git-send-email 2.21.0.392.gf8f6787159 To: Miklos Szeredi , Miklos Szeredi Cc: Han-Wen Nienhuys , Jakob Unterwurzacher , Kirill Tkhai , Andrew Morton , , , , Kirill Smelkov , Message-Id: <12f7d0d98555ee0d174d04bb47644f65c07f035a.1553680185.git.kirr@nexedi.com> In-Reply-To: References: X-Report-Abuse: Please forward a copy of this message, including all headers, to abuse@mandrill.com X-Report-Abuse: You can also report abuse here: http://mandrillapp.com/contact/abuse?id=31050260.724e808b8ada4d2a9f13fe3df0362240 X-Mandrill-User: md_31050260 Date: Wed, 27 Mar 2019 10:15:18 +0000 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org FUSE filesystem server and kernel client negotiate during initialization phase, what should be the maximum write size the client will ever issue. Correspondingly the filesystem server then queues sys_read calls to read requests with buffer capacity large enough to carry request header + that max_write bytes. A filesystem server is free to set its max_write in anywhere in the range between [1=C2=B7page, fc->max_pages=C2=B7page]. In particular go-fuse[2] sets max_write by default as 64K, wheres default fc->max_pages corresponds to 128K. Libfuse also allows users to configure max_write, but by default presets it to possible maximum. If max_write is < fc->max_pages=C2=B7page, and in NOTIFY_RETRIEVE handler w= e allow to retrieve more than max_write bytes, corresponding prepared NOTIFY_REPLY will be thrown away by fuse_dev_do_read, because the filesystem server, in full correspondence with server/client contract, will be only queuing sys_read with ~max_write buffer capacity, and fuse_dev_do_read throws away requests that cannot fit into server request buffer. In turn the filesystem server could get stuck waiting indefinitely for NOTIFY_REPLY since NOTIFY_RETRIEVE handler returned OK which is understood by clients as that NOTIFY_REPLY was queued and will be sent back. -> Cap requested size to negotiate max_write to avoid the problem. This aligns with the way NOTIFY_RETRIEVE handler works, which already unconditionally caps requested retrieve size to fuse_conn->max_pages. This way it should not hurt NOTIFY_RETRIEVE semantic if we return less data than was originally requested. Please see [1] for context where the problem of stuck filesystem was hit for real, how the situation was traced and for more involving patch that did not make it into the tree. [1] https://marc.info/?l=3Dlinux-fsdevel&m=3D155057023600853&w=3D2 [2] https://github.com/hanwen/go-fuse Signed-off-by: Kirill Smelkov Cc: Han-Wen Nienhuys Cc: Jakob Unterwurzacher Cc: # v2.6.36+ --- fs/fuse/dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 8a63e52785e9..38e94bc43053 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -1749,7 +1749,7 @@ static int fuse_retrieve(struct fuse_conn *fc, struct= inode *inode, =09offset =3D outarg->offset & ~PAGE_MASK; =09file_size =3D i_size_read(inode); -=09num =3D outarg->size; +=09num =3D min(outarg->size, fc->max_write); =09if (outarg->offset > file_size) =09=09num =3D 0; =09else if (outarg->offset + num > file_size) -- 2.21.0.392.gf8f6787159