mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
To: "ceph-devel@vger.kernel.org" <ceph-devel@vger.kernel.org>,
	Xiubo Li <xiubli@redhat.com>,
	"twelho@welho.tech" <twelho@welho.tech>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"idryomov@gmail.com" <idryomov@gmail.com>
Cc: "zohar@linux.ibm.com" <zohar@linux.ibm.com>,
	"roberto.sassu@huawei.com" <roberto.sassu@huawei.com>,
	"eric.snowberg@oracle.com" <eric.snowberg@oracle.com>,
	"linux-integrity@vger.kernel.org"
	<linux-integrity@vger.kernel.org>,
	"dmitry.kasatkin@gmail.com" <dmitry.kasatkin@gmail.com>,
	"serge@hallyn.com" <serge@hallyn.com>,
	"linux-security-module@vger.kernel.org"
	<linux-security-module@vger.kernel.org>,
	"jmorris@namei.org" <jmorris@namei.org>,
	"paul@paul-moore.com" <paul@paul-moore.com>
Subject: Re:  [PATCH] fs/ceph: set superblock s_magic for IMA fsmagic matching: up to 60x speedup
Date: Thu, 29 May 2025 18:02:43 +0000	[thread overview]
Message-ID: <d3a0a5caa69d3af5c9e09d1d15979c9306e5ae8e.camel@ibm.com> (raw)
In-Reply-To: <20250529174453.293618-1-twelho@welho.tech>

On Thu, 2025-05-29 at 17:45 +0000, Dennis Marttinen wrote:
> The CephFS kernel driver forgets to set the filesystem magic signature in
> its superblock. As a result, IMA policy rules based on fsmagic matching do
> not apply as intended. This causes a major performance regression in Talos
> Linux [1] when mounting CephFS volumes, such as when deploying Rook Ceph
> [2]. Talos Linux ships a hardened kernel with the following IMA policy
> (irrelevant lines omitted):
> 
> # cat /sys/kernel/security/integrity/ima/policy
> [...]
> dont_measure fsmagic=0xc36400 # CEPH_SUPER_MAGIC
> [...]
> measure func=FILE_CHECK mask=^MAY_READ euid=0
> measure func=FILE_CHECK mask=^MAY_READ uid=0
> [...]
> 
> Currently, IMA compares 0xc36400 == 0x0 for CephFS files, resulting in all
> files opened with O_RDONLY or O_RDWR getting measured with SHA512 on every
> open(2):
> 
> # cat /data/cephfs/test-file
> # tail -1 /sys/kernel/security/integrity/ima/ascii_runtime_measurements
> 10 69990c87e8af323d47e2d6ae4... ima-ng sha512:<hash> /data/cephfs/test-file
> 
> Since O_WRONLY is rare, this results in an order of magnitude lower
> performance than expected for practically all file operations. Properly
> setting CEPH_SUPER_MAGIC in the CephFS superblock resolves the regression.
> 
> Tests performed on a 3x replicated Ceph v19.3.0 cluster across three
> i5-7200U nodes each equipped with one Micron 7400 MAX M.2 disk (BlueStore)
> and Gigabit ethernet, on Talos Linux v1.10.2:
> 
> FS-Mark 3.3
> Test: 500 Files, Empty
> Files/s > Higher Is Better
> 6.12.27-talos . 16.6  |====
> +twelho patch . 208.4 |====================================================
> 
> FS-Mark 3.3
> Test: 500 Files, 1KB Size
> Files/s > Higher Is Better
> 6.12.27-talos . 15.6  |=======
> +twelho patch . 118.6 |====================================================
> 
> FS-Mark 3.3
> Test: 500 Files, 32 Sub Dirs, 1MB Size
> Files/s > Higher Is Better
> 6.12.27-talos . 12.7 |===============
> +twelho patch . 44.7 |=====================================================
> 
> IO500 [3] 2fcd6d6 results (benchmarks within variance omitted):
> 
> > IO500 benchmark   | 6.12.27-talos  | +twelho patch  | Speedup   |
> > -------------------|----------------|----------------|-----------|
> > mdtest-easy-write | 0.018524 kIOPS | 1.135027 kIOPS | 6027.33 % |
> > mdtest-hard-write | 0.018498 kIOPS | 0.973312 kIOPS | 5161.71 % |
> > ior-easy-read     | 0.064727 GiB/s | 0.155324 GiB/s | 139.97 %  |
> > mdtest-hard-read  | 0.018246 kIOPS | 0.780800 kIOPS | 4179.29 % |
> 
> This applies outside of synthetic benchmarks as well, for example, the time
> to rsync a 55 MiB directory with ~12k of mostly small files drops from an
> unusable 10m5s to a reasonable 26s (23x the throughput).
> 
> [1]: https://www.talos.dev/  
> [2]: https://www.talos.dev/v1.10/kubernetes-guides/configuration/ceph-with-rook/  
> [3]: https://github.com/IO500/io500  
> 
> Signed-off-by: Dennis Marttinen <twelho@welho.tech>
> ---
> It took me a year to hunt this down: profiling distributed filesystems is
> non-trivial. Since the regression is associated with IMA use, I received a
> hint to CC the folks associated with IMA code. The patch targets the 6.12
> kernel series currently used by Talos Linux, but should apply on top of
> master as well. Please note that this is an independent contribution -
> I am not affiliated with any company or organization.
> 
>  fs/ceph/super.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/fs/ceph/super.c b/fs/ceph/super.c
> index 73f321b52895e..9549f97233a9e 100644
> --- a/fs/ceph/super.c
> +++ b/fs/ceph/super.c
> @@ -1217,6 +1217,7 @@ static int ceph_set_super(struct super_block *s, struct fs_context *fc)
>  	s->s_time_min = 0;
>  	s->s_time_max = U32_MAX;
>  	s->s_flags |= SB_NODIRATIME | SB_NOATIME;
> +	s->s_magic = CEPH_SUPER_MAGIC;
>  

Yeah, makes sense. Thanks a lot for the fix. It's really non-trivial issue.

Reviewed-by: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>

Thanks,
Slava.

>  	ceph_fscrypt_set_ops(s);
>  
> 
> base-commit: adc218676eef25575469234709c2d87185ca223a

  reply	other threads:[~2025-05-29 18:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-29 17:45 Dennis Marttinen
2025-05-29 18:02 ` Viacheslav Dubeyko [this message]
2025-06-01 16:03   ` Ilya Dryomov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d3a0a5caa69d3af5c9e09d1d15979c9306e5ae8e.camel@ibm.com \
    --to=slava.dubeyko@ibm.com \
    --cc=ceph-devel@vger.kernel.org \
    --cc=dmitry.kasatkin@gmail.com \
    --cc=eric.snowberg@oracle.com \
    --cc=idryomov@gmail.com \
    --cc=jmorris@namei.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=roberto.sassu@huawei.com \
    --cc=serge@hallyn.com \
    --cc=twelho@welho.tech \
    --cc=xiubli@redhat.com \
    --cc=zohar@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®