From patchwork Mon Jul 17 11:52:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Maiolino X-Patchwork-Id: 13315512 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87CA9C001DC for ; Mon, 17 Jul 2023 11:52:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 27ED56B0072; Mon, 17 Jul 2023 07:52:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 22EC96B0074; Mon, 17 Jul 2023 07:52:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0F73B8D0001; Mon, 17 Jul 2023 07:52:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 00BBA6B0072 for ; Mon, 17 Jul 2023 07:52:40 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B7CD680520 for ; Mon, 17 Jul 2023 11:52:40 +0000 (UTC) X-FDA: 81020941680.10.5D160AC Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf12.hostedemail.com (Postfix) with ESMTP id 15ACA40018 for ; Mon, 17 Jul 2023 11:52:38 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=W6tB5o6m; spf=pass (imf12.hostedemail.com: domain of cem@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cem@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689594759; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=Z6DnFkgYxF84ZsaCJV7sHQtaqOKItRqfOSnl6euL8FE=; b=Agti9ZgAe8HEEmHU/0AnHN9IzKsEAvQ3zgBBqNbSZRczTsu2nj7M5hJRdoopiwXvn3Y3G8 9gydunlSO9YY6u2xhcmLxEpG7p2P0WNGXCa1mwlgzC+bLm5r3nnFXgXIeeg6c+kGQ9M192 6/xCUZGIxTGFSpvDedzpkto6qk9/rzw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689594759; a=rsa-sha256; cv=none; b=I19xjPb0iacPkCybAq+tyI/MeQvynPWAt71wvjrtraO4J149khh6TxzKGwUE385A4kKrAL Z6UDyR2Dltj8MOtsEXVRD4wZ/aXRcjxcGWLKSneIVx+eDOqXaDLdiGt+psTRFjY5vuN1du NnC+3K2gXAj1XttA4HUSBVXQFBHz+Bc= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=W6tB5o6m; spf=pass (imf12.hostedemail.com: domain of cem@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cem@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 135B46103C; Mon, 17 Jul 2023 11:52:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58E02C433C8; Mon, 17 Jul 2023 11:52:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689594757; bh=E8Rh0neNu7io2oM8L8reTqLstY9Jmi1bawVs92HmbKs=; h=From:To:Cc:Subject:Date:From; b=W6tB5o6mu21ndL7u0S3arqg7fKw/KfCWLcZ5gvytulzp1r8C/oC7b1YceYiYVt14y b/ejbV2cn+q6pzCJAFyIeqSWBeUQIcqmUTwAXX9aimMfOq6AT1QrmAd5XMMl2PxGc1 nwYPzQqXppn1GrxLNhxSsSn+hdYCekesbP0fuSoQrJw7JN3KVnpSZrWQZ787R6/WFm HZX/yTdyJ8PmL7lOQDoRe3A/3dbQIm7LMaxcTPLlCjumZx4o0vn2VzX2u6HyV2QH4I htgh6Xqoz6fQgJ+8MknVuC+0S69fa9yCeyhL+brRIcWS1wqk+R0Ddq4ukB2IECHsmU nW9m/5t4scK6Q== From: cem@kernel.org To: linux-fsdevel@vger.kernel.org Cc: jack@suse.cz, akpm@linux-foundation.org, viro@zeniv.linux.org.uk, linux-mm@kvack.org, djwong@kernel.org, hughd@google.com, brauner@kernel.org, mcgrof@kernel.org Subject: [PATCH V5 0/6] shmem: Add user and group quota support for tmpfs Date: Mon, 17 Jul 2023 13:52:07 +0200 Message-Id: <20230717115212.208651-1-cem@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspamd-Queue-Id: 15ACA40018 X-Rspam-User: X-Stat-Signature: qmuitmptweyjk8n3gntxrr3hk3z6t1kd X-Rspamd-Server: rspam03 X-HE-Tag: 1689594758-442230 X-HE-Meta: U2FsdGVkX1+rgFUK/yfl8xPlnik695Edr/pnje3VSD3B3JgMGIjUwUL7GDiD3b70iRkULQuO7/0+ricG7HM5Zhm0ZRK6YCX7B0OXinEBCM/OYn/E53Q7gSHZIVnRk6H1wCRpfBt+XLu+wW3lLcbIJ+d/P0R8G9x6rDiCbOuoLe8MbGdmitEvHv0nvyCk8lCiN1rMy7M30+J8olRdipEIM6j4EwKpY5YNAofEYVybqVJmXTFI5kw7CfHdoN2CLLfYLI3/OjuEJKJNcM+AQLSpIvIM0f8dDuGt4ZSkkhqooJ5yf2WGARvHJtJiOGF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, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Carlos Maiolino Hello folks. This updates the previous series, to improve error handling of tmpfs quota options. This new version changes only patch 5/6 "shmem: quota support", and it only adds a conditional if fc->user_ns != &init_user_ns, so there isn't much logic change on the overall patch. This has also been sync'ed to today Linus's TOT, and they should apply cleanly on top of that. Honza, the overall logic isn't changed, but since there's new code in here, I opted to remove your RwB from this patch, would you be so kind to RwB it again? Christian, could you please also review this? As before, details are within each patch. The original cover-letter follows... people have been asking for quota support in tmpfs many times in the past mostly to avoid one malicious user, or misbehaving user/program to consume all of the system memory. This has been partially solved with the size mount option, but some problems still prevail. One of the problems is the fact that /dev/shm is still generally unprotected with this and another is administration overhead of managing multiple tmpfs mounts and lack of more fine grained control. Quota support can solve all these problems in a somewhat standard way people are already familiar with from regular file systems. It can give us more fine grained control over how much memory user/groups can consume. Additionally it can also control number of inodes and with special quota mount options introduced with a second patch we can set global limits allowing us to replace the size mount option with quota entirely. Currently the standard userspace quota tools (quota, xfs_quota) are only using quotactl ioctl which is expecting a block device. I patched quota [1] and xfs_quota [2] to use quotactl_fd in case we want to run the tools on mount point directory to work nicely with tmpfs. The implementation was tested on patched version of xfstests [3]. [1] https://github.com/lczerner/quota/tree/quotactl_fd_support [2] https://github.com/lczerner/xfsprogs/tree/quotactl_fd_support [3] https://github.com/lczerner/xfstests/tree/tmpfs_quota_support Jan Kara (1): quota: Check presence of quota operation structures instead of ->quota_read and ->quota_write callbacks Lukas Czerner (5): shmem: make shmem_inode_acct_block() return error shmem: make shmem_get_inode() return ERR_PTR instead of NULL shmem: prepare shmem quota infrastructure shmem: quota support Add default quota limit mount options Documentation/filesystems/tmpfs.rst | 31 ++ fs/Kconfig | 12 + fs/quota/dquot.c | 2 +- include/linux/shmem_fs.h | 28 ++ include/uapi/linux/quota.h | 1 + mm/Makefile | 2 +- mm/shmem.c | 465 +++++++++++++++++++++------- mm/shmem_quota.c | 350 +++++++++++++++++++++ 8 files changed, 783 insertions(+), 108 deletions(-) create mode 100644 mm/shmem_quota.c Signed-off-by: Carlos Maiolino