From nobody Mon Nov 25 07:30:23 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 25210185B6E for ; Mon, 28 Oct 2024 22:05:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730153133; cv=none; b=Eo9tpOMoMmu0p1t1x8jcMjhFewNuamCiKNnC2L8qNhsRWGjxV3Tqf8BbL5zGlRjIWnlwjMrVQ5vgwyPsp2jWQtJ6icCxVNUBOHOvYeWaLgbW3UnmLSXdUdF0s3i5VTl0Psm3mNofZW0CnHyLRFI561M+VcG38e2IAtvIkGPfcKg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730153133; c=relaxed/simple; bh=b7NDcp0ZbtvVvN+n9OTWm8KVIbatbAAOOj0YER5oc7c=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ncIYf0w/8OrPlVRS9Q+HU7/K8NHECkeo+5XgjTQ9zIwtZ+F19H3eqKYmLmKOD9CsGoK34ancayawuiBYaAz75avZ0AaNrFu8tWBy3s+3vdVDcKPSdSTi3dVVskUoZ2Za8LVvBv07LadvzUsw8xdJjc47Xxo4OAE1eGTlgt/strU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=1QH1M2Xv; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1QH1M2Xv" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e3d660a1afso83135527b3.0 for ; Mon, 28 Oct 2024 15:05:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730153130; x=1730757930; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=w3ou0NFxNBMI+LK68R3aSahBHwkUL88oLn/g1FPlgGI=; b=1QH1M2XvwYrj5izJC2xtekYMt62DZ7zG56TLeFpFr+e2UGI8abFbMX2L9Jnx1vVFvR k6M7y9RPM3pGXIM5utjHALB9qanTcptdnOZ2md3wpZXuY+kxTc8ymFNzU3yJKMcvUb2W C1ExmcbWlPK5oY9E24/d/qxV6l5obOKux90exJcfkgopWqYxyos1tgYIHUK21mN0EjRp qzD8aUd9Gmu7bB7c9TBa1dnMC7nx/iuLeRgs+FL0H1mScvIBKJ0DvSRtHsemjhBU7C3J 1cBUhKju+oYaT6Ao97CpfvINrGbpqBzA+MQa5I1gnfiupx4TEA96FVMgPFVLEUC2cOJr rBaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730153130; x=1730757930; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=w3ou0NFxNBMI+LK68R3aSahBHwkUL88oLn/g1FPlgGI=; b=AWyZirXtusVaOyJ72AcfyB2MLBsyKf0uHyAycgqarnk8nkAVKxIAw8nkniOYl9lF2M lSEe2BnY5Tccn3GP0uNNZyD75r9anJTgMalWlM09V+/ubg4BSpx0FuUgFkrMMESyLbbL qFwPOWm/a8Muse1Q6E+nXE6yQLirXsf0yQKiP2hhYQCPyzN8VOZ2BGRKGk2iMQCJI3hC RRRnVptdQVCado8caK3Vip26lRBJaKyr/OzMDwX2qSQPHz+6GBeEJNOqVY9WaIhO8QOc yM+DCxG2ViPkQ7ZfUTTUUA9UELozFLLkmOGDrQMG97f1qcH7dr8qMjdllGk6hG2lNEpb HYaA== X-Forwarded-Encrypted: i=1; AJvYcCWPm5JM/EnCz2my4FWHukl3EIyAAIV3TWeu9mx1+XY3+ePcyRD5S5V3xExoSEOlt4iiVAKJWCNGI7Tx6Sw=@vger.kernel.org X-Gm-Message-State: AOJu0Yxtd9JKPjCPMMa+rJoIzeAvPJVhAVBOR8OYkddBb4UW3aDuD6Ql yAhDAtv4mKK8sZZI0S0iCMKyerATHn4rX7LhiLKTHHjIGuUACr7nDj4fsO5AEMuPO27AzbYkNtv D35z06sPevShGzs3bjOcIfA== X-Google-Smtp-Source: AGHT+IEoJvt/jAg/wrQgLrbnpd1PYPhm7g2qxg9aTFmYZoLnT+5hMX+dRMvN53ZNPQP7hmPh/zEREK2sEQRWA+pWew== X-Received: from kalesh.mtv.corp.google.com ([2a00:79e0:2e3f:8:dd17:1d2c:7822:7fdf]) (user=kaleshsingh job=sendgmr) by 2002:a05:6902:3297:b0:e2e:2e79:207c with SMTP id 3f1490d57ef6-e3087728d56mr8839276.0.1730153130042; Mon, 28 Oct 2024 15:05:30 -0700 (PDT) Date: Mon, 28 Oct 2024 14:43:57 -0700 In-Reply-To: <20241028214550.2099923-1-kaleshsingh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241028214550.2099923-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241028214550.2099923-2-kaleshsingh@google.com> Subject: [PATCH 1/3] tracing: Document tracefs gid mount option From: Kalesh Singh To: dhowells@redhat.com, rostedt@goodmis.org, mhiramat@kernel.org Cc: surenb@google.com, jyescas@google.com, kernel-team@android.com, android-mm@google.com, Kalesh Singh , Mathieu Desnoyers , Shuah Khan , Ali Zahraee , Christian Brauner , Eric Sandeen , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" [1] and [2] introduced a new gid mount options that could apply to a group to all entries in tracefs. Document this in the tracing readme. [1] https://lore.kernel.org/r/20211208075720.4855d180@gandalf.local.home/T/= #u [2] https://lore.kernel.org/r/20211207171729.2a54e1b3@gandalf.local.home/T/= #u Cc: David Howells Cc: Steven Rostedt Cc: Masami Hiramatsu Signed-off-by: Kalesh Singh --- kernel/trace/trace.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index a8f52b6527ca..2b64b3ec67d9 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -5501,6 +5501,10 @@ static const struct file_operations tracing_iter_fop= s =3D { =20 static const char readme_msg[] =3D "tracing mini-HOWTO:\n\n" + "By default tracefs removes all OTH file permission bits.\n" + "When mounting tracefs an optional group id can be specified\n" + "which adds the group to every directory and file in tracefs:\n\n" + "\t e.g. mount -t tracefs [-o [gid=3D]] nodev /sys/kernel/tracing\n\= n" "# echo 0 > tracing_on : quick way to disable tracing\n" "# echo 1 > tracing_on : quick way to re-enable tracing\n\n" " Important files:\n" --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 07:30:23 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 F01A619007E for ; Mon, 28 Oct 2024 22:05:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730153157; cv=none; b=rB/4StsP1oM9oHDn98vrTOU6dp9qDWpVhahfmcuMdh09aS5hHA0q4yRBCXNhHP/diMKR3pZ2HmjfuZ60uWsySy3zqA+8IzauDgKH9AhsP5uNtNhZcDM6+SYX+qiIkd5+4NJ7RbvKfYoCYiGr722hZzoRLTuaaCpEE7yWPs7ekEw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730153157; c=relaxed/simple; bh=EmllJLfP0nLO3+si2cN9oyclRZPtfrj39zUndlbiJNI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QlPZ/GJ9+6iUGi0vjzSmC7+B+YptEJsSBugt47U6QqeAY1a/FlM58i1fjL83EUsQBG0j3XG4+vl+Mu/bmajoQgLQKCGCOL3tc7IMOOOd+FFFBYTNM5jM+pd3N0PoFL7Ixd5H88eypC3jb8HhUnruXZI2I42Nx8sWJGW3AxF9t5M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Ltuu5R4S; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Ltuu5R4S" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e7fb84f999so71904917b3.2 for ; Mon, 28 Oct 2024 15:05:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730153154; x=1730757954; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=qgXMA3H1i71vePLOcuFKt/eJvEilt9qljsSwQxbfxX0=; b=Ltuu5R4Sbpr4ZN0M6dvdhHpnmkkwzWkiHlVA7Pp5fyxc5Sb4Gr6leJCRfD+hmxs/b8 wXhbVa2xLkkHabOg3NUhArBYu8m2njbzro09ZYiBKZDkzkw2bHoot7qwd8fAERMSYUZC BdAJZC0bF8APQqMtsDB2RnyZQ0biFTgsob9dxqdXBoJnGlctsT24Gi0rPxFNTlRIrUu2 +e08xwgDK7cITIAshELE5jofXirKU2PWi1hUZTBMszt5Lv7wKDIEoyg94XtVN/uz7Scw GAEE/P7eyZ1DbBazPcDVXnx1Suo2yWFZgWwSWMa7662SchKZxYTqVgnbfKqd3gsNHW7m GWkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730153154; x=1730757954; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qgXMA3H1i71vePLOcuFKt/eJvEilt9qljsSwQxbfxX0=; b=OjBT+2BMYEsZ3xat4ME1ZApMeKA6BBr7a0n28T7ESuneXmXAyF9gfeUmtvek6cg7w4 8XgbaAogOOimglitB8DvwXwCkbY0UllOs1TLcNXVhJsfqPbQs2Ia7QjngGXAprVaT6lq I+rU4BqMZKKSnipmiG6nRrmOfXqUN7hD9Vj5PMavDAQHsLCwIwSeLUjJZFboEjcxQ26z v3DElDhXDawbkQIlDuheWg3hdNux0pFPMPl1Vo02U16m3ERBelkGAPd3DFaIwf9fAlvR 0QvpaQ8snb6Ci/E2fGmaU1sxXoXywnrQ/TODpO/6ZBRPRHfT1HR9LcaomA/Ihr+0v0cF f9nQ== X-Forwarded-Encrypted: i=1; AJvYcCU72ZL977pv4tlL25TnGjJMXPLy/gf/rcBni7Owt1zC7df67htpEPSiAzZcuZcgYIadFr3Gb7SFeSu1ykA=@vger.kernel.org X-Gm-Message-State: AOJu0YwORdfrwgIosIQRD8eDwYSGtmorm/QgL3dklBowryybYZvFsSO6 HArArO+yTvVPBDzECcml2DEvKLO+3mxaTU3V+z47wAbZj+Ar2236gFbMmwhQ7KIX/yShabHUzMY /UizvgqJACzpaJNtBB2/NKw== X-Google-Smtp-Source: AGHT+IGF9Pi2lb2sUc0GUX/DYg5llr+NhdKdR00JACXX1x5oo3dzjoH/TRmaF857GPkgm+W8S7O8gnUmssb4hz0lRw== X-Received: from kalesh.mtv.corp.google.com ([2a00:79e0:2e3f:8:dd17:1d2c:7822:7fdf]) (user=kaleshsingh job=sendgmr) by 2002:a05:6902:1822:b0:e1c:ed3d:7bb7 with SMTP id 3f1490d57ef6-e308784a6eamr7475276.1.1730153153942; Mon, 28 Oct 2024 15:05:53 -0700 (PDT) Date: Mon, 28 Oct 2024 14:43:58 -0700 In-Reply-To: <20241028214550.2099923-1-kaleshsingh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241028214550.2099923-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241028214550.2099923-3-kaleshsingh@google.com> Subject: [PATCH 2/3] tracing/selftests: Add tracefs mount options test From: Kalesh Singh To: dhowells@redhat.com, rostedt@goodmis.org, mhiramat@kernel.org Cc: surenb@google.com, jyescas@google.com, kernel-team@android.com, android-mm@google.com, Kalesh Singh , Mathieu Desnoyers , Shuah Khan , Ali Zahraee , Eric Sandeen , Christian Brauner , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add test to check the tracefs gid mount option is applied correctly ./ftracetest test.d/00basic/mount_options.tc Use the new readme string "[gid=3D] as a requirement and also update test_ownership.tc requirements to use this. mount_options.tc will fail currently, this is fixed by the subsequent patch in this series. Cc: David Howells Cc: Steven Rostedt Cc: Masami Hiramatsu Signed-off-by: Kalesh Singh --- .../ftrace/test.d/00basic/mount_options.tc | 101 ++++++++++++++++++ .../ftrace/test.d/00basic/test_ownership.tc | 16 +-- .../testing/selftests/ftrace/test.d/functions | 25 +++++ 3 files changed, 129 insertions(+), 13 deletions(-) create mode 100644 tools/testing/selftests/ftrace/test.d/00basic/mount_opt= ions.tc diff --git a/tools/testing/selftests/ftrace/test.d/00basic/mount_options.tc= b/tools/testing/selftests/ftrace/test.d/00basic/mount_options.tc new file mode 100644 index 000000000000..b8aff85ec259 --- /dev/null +++ b/tools/testing/selftests/ftrace/test.d/00basic/mount_options.tc @@ -0,0 +1,101 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# description: Test tracefs GID mount option +# requires: "[gid=3D]":README + +fail() { + local msg=3D"$1" + + echo "FAILED: $msg" + exit_fail +} + +find_alternate_gid() { + local original_gid=3D"$1" + tac /etc/group | grep -v ":$original_gid:" | head -1 | cut -d: -f3 +} + +mount_tracefs_with_options() { + local mount_point=3D"$1" + local options=3D"$2" + + mount -t tracefs -o "$options" nodev "$mount_point" + + setup +} + +unmount_tracefs() { + local mount_point=3D"$1" + + # Need to make sure the mount isn't busy so that we can umount it + (cd $mount_point; finish_ftrace;) + + cleanup +} + +create_instance() { + local mount_point=3D"$1" + local instance=3D"$mount_point/instances/$(mktemp -u test-XXXXXX)" + + mkdir "$instance" + echo "$instance" +} + +remove_instance() { + local instance=3D"$1" + + rmdir "$instance" +} + +check_gid() { + local mount_point=3D"$1" + local expected_gid=3D"$2" + + echo "Checking permission group ..." + + cd "$mount_point" + + for file in "." "events" "events/sched" "events/sched/sched_switch" "even= ts/sched/sched_switch/enable"; do + local gid=3D`stat -c "%g" $file` + if [ "$gid" -ne "$expected_gid" ]; then + cd - # Return to the previous working direcotry (tracefs root) + fail "$(realpath $file): Expected group $expected_gid; Got group $gid" + fi + done + + cd - # Return to the previous working direcotry (tracefs root) +} + +test_gid_mount_option() { + local mount_point=3D$(get_mount_point) + local mount_options=3D$(get_mnt_options "$mount_point") + local original_group=3D$(stat -c "%g" .) + local other_group=3D$(find_alternate_gid "$original_group") + + # Set up mount options with new GID for testing + local new_options=3D`echo "$mount_options" | sed -e "s/gid=3D[0-9]*/gid= =3D$other_group/"` + if [ "$new_options" =3D "$mount_options" ]; then + new_options=3D"$mount_options,gid=3D$other_group" + mount_options=3D"$mount_options,gid=3D$original_group" + fi + + # Unmount existing tracefs instance and mount with new GID + unmount_tracefs "$mount_point" + mount_tracefs_with_options "$mount_point" "$new_options" + + check_gid "$mount_point" "$other_group" + + # Check that files created after the mount inherit the GID + local instance=3D$(create_instance "$mount_point") + check_gid "$instance" "$other_group" + remove_instance "$instance" + + # Unmount and remount with the original GID + unmount_tracefs "$mount_point" + mount_tracefs_with_options "$mount_point" "$mount_options" + check_gid "$mount_point" "$original_group" +} + +test_gid_mount_option + +exit 0 diff --git a/tools/testing/selftests/ftrace/test.d/00basic/test_ownership.t= c b/tools/testing/selftests/ftrace/test.d/00basic/test_ownership.tc index 094419e190c2..e71cc3ad0bdf 100644 --- a/tools/testing/selftests/ftrace/test.d/00basic/test_ownership.tc +++ b/tools/testing/selftests/ftrace/test.d/00basic/test_ownership.tc @@ -1,24 +1,14 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0 # description: Test file and directory ownership changes for eventfs +# requires: "[gid=3D]":README =20 original_group=3D`stat -c "%g" .` original_owner=3D`stat -c "%u" .` =20 -mount_point=3D`stat -c '%m' .` +local mount_point=3D$(get_mount_point) =20 -# If stat -c '%m' does not work (e.g. busybox) or failed, try to use the -# current working directory (which should be a tracefs) as the mount point. -if [ ! -d "$mount_point" ]; then - if mount | grep -qw $PWD ; then - mount_point=3D$PWD - else - # If PWD doesn't work, that is an environmental problem. - exit_unresolved - fi -fi - -mount_options=3D`mount | grep "$mount_point" | sed -e 's/.*(\(.*\)).*/\1/'` +mount_options=3D$(get_mnt_options "$mount_point") =20 # find another owner and group that is not the original other_group=3D`tac /etc/group | grep -v ":$original_group:" | head -1 | cu= t -d: -f3` diff --git a/tools/testing/selftests/ftrace/test.d/functions b/tools/testin= g/selftests/ftrace/test.d/functions index 779f3e62ec90..84d6a9c7ad67 100644 --- a/tools/testing/selftests/ftrace/test.d/functions +++ b/tools/testing/selftests/ftrace/test.d/functions @@ -193,3 +193,28 @@ ftrace_errlog_check() { # err-prefix command-with-erro= r-pos-by-^ command-file # " Command: " and "^\n" =3D> 13 test $(expr 13 + $pos) -eq $N } + +# Helper to get the tracefs mount point +get_mount_point() { + local mount_point=3D`stat -c '%m' .` + + # If stat -c '%m' does not work (e.g. busybox) or failed, try to use the + # current working directory (which should be a tracefs) as the mount poin= t. + if [ ! -d "$mount_point" ]; then + if mount | grep -qw "$PWD"; then + mount_point=3D$PWD + else + # If PWD doesn't work, that is an environmental problem. + exit_unresolved + fi + fi + echo "$mount_point" +} + +# Helper function to retrieve mount options for a given mount point +get_mnt_options() { + local mnt_point=3D"$1" + local opts=3D$(mount | grep -m1 "$mnt_point" | sed -e 's/.*(\(.*\)).*/\1/= ') + + echo "$opts" +} \ No newline at end of file --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 07:30:23 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 896AB1DF25A for ; Mon, 28 Oct 2024 22:06:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730153180; cv=none; b=eks+uAllqDURNSqRvPpWljgNdHqF8MC4gmZKUh4DL/4kfg3xSVnJJw2EkCik0rGIDQ9dnCSq8M3dv2ft0ZoPm339GaUQxNqfCQk7p1+DW6ayyciKqlp+yLTW5Q4fUynFEom31GaWP5lSUtASRUdYRU8mQ8YI7fXShDRpUkaAm40= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730153180; c=relaxed/simple; bh=lnNh2MyW6k3PPWKeZ3lkSphmqc6oZlzuJG2jDdoCDuc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=CJrCK75779l4a/haKizjvzjOtl88xc/2GDcT7y1gZyqfltWg8uQF1+GJtkEmUriAkDwJ0kloIC84v33gutck3UmYIaZ33rNF4Khifg42KClS+G2ucP62FxAXITRznpYBJPpTvGrSmXXcsIq9IuWbsBR1CPnfxQYOzrMEtzAcqik= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=XzAlhRyX; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="XzAlhRyX" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e32e8436adso69740287b3.0 for ; Mon, 28 Oct 2024 15:06:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730153177; x=1730757977; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=SOY2vgqJ0KtVzbKcwr3dZPfuHJS0Y1wX9dhGpLmmysU=; b=XzAlhRyXDt0IKtNwkAaZzgCReQ5z9gGMXRlpYyOcbv/yDhp601ZroIh90cW7z2oleL PnnSDR1CtNDuegX5Do3uZpJweqKdDa1pgLKYP5rYL5uT0UW9A2xi5IR6LRQteerYcjSp xarBu5PuG1rXsYEckqswbikk+Pzz/Qy5x3/N3FqN3gxEpCc6AbNJF9xmbyeo1H/opSke SpFifHzlrVSGMO3AmFWr6oldlytnMYL48QItnldGPMwGA3Y8rMtehV1l3+lpwBJ8io5q HzZO/pb2IcslBZjMLGBOhoqQzzHybdY6WY97Z0qSPjIB0SX9DMp7HCxntTQYXP4gEcSL MM1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730153177; x=1730757977; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SOY2vgqJ0KtVzbKcwr3dZPfuHJS0Y1wX9dhGpLmmysU=; b=Z8trMN3lkq5uYjjMkRUsT0o23/9G3mM+7VLMyz0gsDDtTE6riahQI/3MP+XzYU7NH9 +sRVQD6INEx7fi+YVcHzOiU4MISu7vN54O2u4O602VSqcJk6ZfJuY9RyfbDzqoprPG9T RhSl8ARV2tYcNjVBTJJpbLUEK10En2oZ6P6dXlpw2MwxXAPVpX06d4cmE5vSCWIlCPq4 wGDCQf8yBZz4c05dEakD44s1G5rageFbyDrXk3PPg2/ibsNF6P9FWBHeJjPzeZgtCBM/ eXyX2oDHKUxUEYjSGqJsCkxQBmL0twn5M8siKJcOLi585FjCnuGshJkNwRS19chuDiub wg8Q== X-Forwarded-Encrypted: i=1; AJvYcCVJBwe1Y/cbvzjGGruCzKr+usNlI7Hd94HtOr+XI1Hrlogm4Y13cwaEd3+GLFDbGK71cNvvLWSJHEYkQgM=@vger.kernel.org X-Gm-Message-State: AOJu0YxHvbXjby5rWe3hLZlsh5k3uUArfK0Hq/XnwgCn92fZKnEwoDDP XBaiMb3fRAlHNOjCNJGCWjw5qELmdK5giJPanmiQTf1U7Rs4jdqGqwhuScOBHNQtFqZtKuYyhJe i8sueRfiYaCZlrxeGEm6fsQ== X-Google-Smtp-Source: AGHT+IHJS7A7yrEb37MadLUrxRTDRexnft6XJqKZL6BE/v5PEF5d2AuI0hKlTnaiOAdoLKFKUc2XiD9OoW2teZTugQ== X-Received: from kalesh.mtv.corp.google.com ([2a00:79e0:2e3f:8:dd17:1d2c:7822:7fdf]) (user=kaleshsingh job=sendgmr) by 2002:a05:690c:9682:b0:69b:c01:82a5 with SMTP id 00721157ae682-6e9d8b89f8amr7192987b3.7.1730153177563; Mon, 28 Oct 2024 15:06:17 -0700 (PDT) Date: Mon, 28 Oct 2024 14:43:59 -0700 In-Reply-To: <20241028214550.2099923-1-kaleshsingh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241028214550.2099923-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241028214550.2099923-4-kaleshsingh@google.com> Subject: [PATCH 3/3] tracing: Fix tracefs gid mount option From: Kalesh Singh To: dhowells@redhat.com, rostedt@goodmis.org, mhiramat@kernel.org Cc: surenb@google.com, jyescas@google.com, kernel-team@android.com, android-mm@google.com, Kalesh Singh , Mathieu Desnoyers , Shuah Khan , Ali Zahraee , Eric Sandeen , Christian Brauner , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Commit 78ff64081949 ("vfs: Convert tracefs to use the new mount API") tracefs to use the new mount APIs caused mounting with the gid=3D option to not take effect. The tracefs superblock can be updated from multiple paths: - on fs_initcall() to init_trace_printk_function_export() - form a work queue to initialize eventfs tracer_init_tracefs_work_func() - fsconfig() syscall to mount of remount sysfs The tracefs super block root inode gets created early on in init_trace_printk_function_export(). With the new mount API tracefs effectively uses get_tree_single() instead of the old API mount_single(). Previously, mount_single() ensured that the options are alway applied to the superblock root inode: (1) If the root inode didn't exist, called fill_super() to create it and apply the options. (2) If the root inode exists, called reconfigure_single() which effectively called tracefs_apply_options() to parse and apply options to the subperblock's fs_info and inode and remount eventfs (if necessary) On the other hand, get_tree_single() effectively calls vfs_get_super() which: (3) If the root inode doesn't exists calls fill_super() to create it and apply the options. (4) If the root inode already exists, updates the fs_context root with the superblock's root inode. (4) above is always the case for tracefs mounts, since the super block's root inode will already be created by init_trace_printk_function_export(). This means that the gid mount option gets ignored: - Since it isn't applied to the super block's root inode, it doesn't get inherited by the children. - Since eventfs is initialized from form a separate work queue and before call to mount with the options, and it doesn't get remounted for mount. Ensure that the mount options are applied to the super block and eventfs is remounted to respect the new mount options. [1] https://lore.kernel.org/r/536e99d3-345c-448b-adee-a21389d7ab4b@redhat.c= om/ Fixes: 78ff64081949 ("vfs: Convert tracefs to use the new mount API") Cc: David Howells Cc: Steven Rostedt Cc: Masami Hiramatsu Signed-off-by: Kalesh Singh --- fs/tracefs/inode.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index 1748dff58c3b..cfc614c638da 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -392,6 +392,9 @@ static int tracefs_reconfigure(struct fs_context *fc) struct tracefs_fs_info *sb_opts =3D sb->s_fs_info; struct tracefs_fs_info *new_opts =3D fc->s_fs_info; =20 + if (!new_opts) + return 0; + sync_filesystem(sb); /* structure copy of new mount options to sb */ *sb_opts =3D *new_opts; @@ -478,14 +481,17 @@ static int tracefs_fill_super(struct super_block *sb,= struct fs_context *fc) sb->s_op =3D &tracefs_super_operations; sb->s_d_op =3D &tracefs_dentry_operations; =20 - tracefs_apply_options(sb, false); - return 0; } =20 static int tracefs_get_tree(struct fs_context *fc) { - return get_tree_single(fc, tracefs_fill_super); + int err =3D get_tree_single(fc, tracefs_fill_super); + + if (err) + return err; + + return tracefs_reconfigure(fc); } =20 static void tracefs_free_fc(struct fs_context *fc) --=20 2.47.0.163.g1226f6d8fa-goog