Skip to contentSkip to conversation

Remove get_task_comm() and print task comm directly

PATCH Applied Yafang Shao 2 participants 8 messages Dec 19, 2024

Subsystems (17)
lore
Share & tools
lore
#0 lore raw

v2 cover Remove get_task_comm() and print task comm directly

Since task->comm is guaranteed to be NUL-terminated, we can print it directly without the need to copy it into a separate buffer. This simplifies the code and avoids unnecessary operations.

v1->v2:
- Don't add "%pTN" (Petr, Kalle, Borislav, Andy, Linus)

v1: https://lore.kernel.org/all/[email protected]/

Yafang Shao (5):
kernel: Remove get_task_comm() and print task comm directly
arch: Remove get_task_comm() and print task comm directly
net: Remove get_task_comm() and print task comm directly
security: Remove get_task_comm() and print task comm directly
drivers: Remove get_task_comm() and print task comm directly

 arch/arc/kernel/unaligned.c                         |  5 ++---
 arch/x86/kernel/vm86_32.c                           |  5 ++---
 drivers/accel/habanalabs/common/context.c           |  3 +--
 drivers/accel/habanalabs/common/habanalabs_ioctl.c  | 11 +++--------
 drivers/gpu/drm/i915/display/intel_display_driver.c |  6 ++----
 drivers/gpu/drm/nouveau/nouveau_chan.c              |  4 +---
 drivers/gpu/drm/nouveau/nouveau_drm.c               |  5 ++---
 drivers/tty/tty_io.c                                |  3 +--
 kernel/capability.c                                 |  8 ++------
 kernel/futex/waitwake.c                             |  3 +--
 net/wireless/wext-core.c                            |  4 +---
 security/yama/yama_lsm.c                            |  4 +---
 12 files changed, 19 insertions(+), 42 deletions(-)
Signature · 1 line
2.43.5
#1 lore raw

PATCH v2 1/5 kernel: Remove get_task_comm() and print task comm directly

Since task->comm is guaranteed to be NUL-terminated, we can print it directly without the need to copy it into a separate buffer. This simplifies the code and avoids unnecessary operations.

Cc Serge Hallyn <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Darren Hart <[email protected]>
Cc Davidlohr Bueso <[email protected]>
Cc "André Almeida" <[email protected]>
---
 kernel/capability.c     | 8 ++------
 kernel/futex/waitwake.c | 3 +--
 2 files changed, 3 insertions(+), 8 deletions(-)
kernel/capability.c +2 -6
index dac4df77e376..e089d2628c29 100644
@@ -38,10 +38,8 @@ __setup("no_file_caps", file_caps_disable);
 
 static void warn_legacy_capability_use(void)
 {
-	char name[sizeof(current->comm)];
-
 	pr_info_once("warning: `%s' uses 32-bit capabilities (legacy support in use)\n",
-		     get_task_comm(name, current));
+		     current->comm);
 }
 
 /*
@@ -62,10 +60,8 @@ static void warn_legacy_capability_use(void)
 
 static void warn_deprecated_v2(void)
 {
-	char name[sizeof(current->comm)];
-
 	pr_info_once("warning: `%s' uses deprecated v2 capabilities in a way that may be insecure\n",
-		     get_task_comm(name, current));
+		     current->comm);
 }
 
 /*
kernel/futex/waitwake.c +1 -2
index 3a10375d9521..eb86a7ade06a 100644
@@ -210,13 +210,12 @@ static int futex_atomic_op_inuser(unsigned int encoded_op, u32 __user *uaddr)
 
 	if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28)) {
 		if (oparg < 0 || oparg > 31) {
-			char comm[sizeof(current->comm)];
 			/*
 			 * kill this print and return -EINVAL when userspace
 			 * is sane again
 			 */
 			pr_info_ratelimited("futex_wake_op: %s tries to shift op by %d; fix this program\n",
-					get_task_comm(comm, current), oparg);
+					    current->comm, oparg);
 			oparg &= 31;
 		}
 		oparg = 1 << oparg;
Signature · 1 line
2.43.5
#2 lore raw

PATCH v2 2/5 arch: Remove get_task_comm() and print task comm directly

In reply to Yafang Shao

Since task->comm is guaranteed to be NUL-terminated, we can print it directly without the need to copy it into a separate buffer. This simplifies the code and avoids unnecessary operations.

Cc Vineet Gupta <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Dave Hansen <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/arc/kernel/unaligned.c | 5 ++---
 arch/x86/kernel/vm86_32.c   | 5 ++---
 2 files changed, 4 insertions(+), 6 deletions(-)
arch/arc/kernel/unaligned.c +2 -3
index d2f5ceaaed1b..3b2d8b1bd271 100644
@@ -200,7 +200,6 @@ int misaligned_fixup(unsigned long address, struct pt_regs *regs,
 		     struct callee_regs *cregs)
 {
 	struct disasm_state state;
-	char buf[TASK_COMM_LEN];
 
 	/* handle user mode only and only if enabled by sysadmin */
 	if (!user_mode(regs) || !unaligned_enabled)
@@ -212,11 +211,11 @@ int misaligned_fixup(unsigned long address, struct pt_regs *regs,
 			     " performance significantly\n. To enable further"
 			     " logging of such instances, please \n"
 			     " echo 0 > /proc/sys/kernel/ignore-unaligned-usertrap\n",
-			     get_task_comm(buf, current), task_pid_nr(current));
+			     current->comm, task_pid_nr(current));
 	} else {
 		/* Add rate limiting if it gets down to it */
 		pr_warn("%s(%d): unaligned access to/from 0x%lx by PC: 0x%lx\n",
-			get_task_comm(buf, current), task_pid_nr(current),
+			current->comm, task_pid_nr(current),
 			address, regs->ret);
 
 	}
arch/x86/kernel/vm86_32.c +2 -3
index e9e803a4d44c..e6cc84143f3e 100644
@@ -246,9 +246,8 @@ static long do_sys_vm86(struct vm86plus_struct __user *user_vm86, bool plus)
 
 	/* VM86_SCREEN_BITMAP had numerous bugs and appears to have no users. */
 	if (v.flags & VM86_SCREEN_BITMAP) {
-		char comm[TASK_COMM_LEN];
-
-		pr_info_once("vm86: '%s' uses VM86_SCREEN_BITMAP, which is no longer supported\n", get_task_comm(comm, current));
+		pr_info_once("vm86: '%s' uses VM86_SCREEN_BITMAP, which is no longer supported\n",
+			     current->comm);
 		return -EINVAL;
 	}
 
Signature · 1 line
2.43.5
#3 lore raw

PATCH v2 3/5 net: Remove get_task_comm() and print task comm directly

In reply to Yafang Shao

Since task->comm is guaranteed to be NUL-terminated, we can print it directly without the need to copy it into a separate buffer. This simplifies the code and avoids unnecessary operations.

---
 net/wireless/wext-core.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
net/wireless/wext-core.c +1 -3
index 3bb04b05c5ce..bea70eb6f034 100644
@@ -640,10 +640,8 @@ EXPORT_SYMBOL(wireless_send_event);
 #ifdef CONFIG_CFG80211_WEXT
 static void wireless_warn_cfg80211_wext(void)
 {
-	char name[sizeof(current->comm)];
-
 	pr_warn_once("warning: `%s' uses wireless extensions which will stop working for Wi-Fi 7 hardware; use nl80211\n",
-		     get_task_comm(name, current));
+		     current->comm);
 }
 #endif
 
Signature · 1 line
2.43.5
#4 lore raw

PATCH v2 4/5 security: Remove get_task_comm() and print task comm directly

In reply to Yafang Shao

Since task->comm is guaranteed to be NUL-terminated, we can print it directly without the need to copy it into a separate buffer. This simplifies the code and avoids unnecessary operations.

---
 security/yama/yama_lsm.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
security/yama/yama_lsm.c +1 -3
index e1a5e13ea269..1a2d02fee09b 100644
@@ -76,7 +76,6 @@ static void report_access(const char *access, struct task_struct *target,
 				struct task_struct *agent)
 {
 	struct access_report_info *info;
-	char agent_comm[sizeof(agent->comm)];
 
 	assert_spin_locked(&target->alloc_lock); /* for target->comm */
 
@@ -86,8 +85,7 @@ static void report_access(const char *access, struct task_struct *target,
 		 */
 		pr_notice_ratelimited(
 		    "ptrace %s of \"%s\"[%d] was attempted by \"%s\"[%d]\n",
-		    access, target->comm, target->pid,
-		    get_task_comm(agent_comm, agent), agent->pid);
+		    access, target->comm, target->pid, agent->comm, agent->pid);
 		return;
 	}
 
Signature · 1 line
2.43.5
#5 lore raw

PATCH v2 5/5 drivers: Remove get_task_comm() and print task comm directly

In reply to Yafang Shao

Since task->comm is guaranteed to be NUL-terminated, we can print it directly without the need to copy it into a separate buffer. This simplifies the code and avoids unnecessary operations.

Cc Oded Gabbay <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Rodrigo Vivi <[email protected]>
Cc Joonas Lahtinen <[email protected]>
Cc Tvrtko Ursulin <[email protected]>
Cc David Airlie <[email protected]>
Cc Simona Vetter <[email protected]>
Cc Karol Herbst <[email protected]>
Cc Lyude Paul <[email protected]>
Cc Danilo Krummrich <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>
---
 drivers/accel/habanalabs/common/context.c           |  3 +--
 drivers/accel/habanalabs/common/habanalabs_ioctl.c  | 11 +++--------
 drivers/gpu/drm/i915/display/intel_display_driver.c |  6 ++----
 drivers/gpu/drm/nouveau/nouveau_chan.c              |  4 +---
 drivers/gpu/drm/nouveau/nouveau_drm.c               |  5 ++---
 drivers/tty/tty_io.c                                |  3 +--
 6 files changed, 10 insertions(+), 22 deletions(-)
drivers/accel/habanalabs/common/context.c +1 -2
index b83141f58319..9f212b17611a 100644
@@ -199,7 +199,6 @@ int hl_ctx_create(struct hl_device *hdev, struct hl_fpriv *hpriv)
 
 int hl_ctx_init(struct hl_device *hdev, struct hl_ctx *ctx, bool is_kernel_ctx)
 {
-	char task_comm[TASK_COMM_LEN];
 	int rc = 0, i;
 
 	ctx->hdev = hdev;
@@ -272,7 +271,7 @@ int hl_ctx_init(struct hl_device *hdev, struct hl_ctx *ctx, bool is_kernel_ctx)
 		mutex_init(&ctx->ts_reg_lock);
 
 		dev_dbg(hdev->dev, "create user context, comm=\"%s\", asid=%u\n",
-			get_task_comm(task_comm, current), ctx->asid);
+			current->comm, ctx->asid);
 	}
 
 	return 0;
drivers/accel/habanalabs/common/habanalabs_ioctl.c +3 -8
index 1dd6e23172ca..8729a0c57d78 100644
@@ -1279,13 +1279,10 @@ static long _hl_ioctl(struct hl_fpriv *hpriv, unsigned int cmd, unsigned long ar
 		retcode = -EFAULT;
 
 out_err:
-	if (retcode) {
-		char task_comm[TASK_COMM_LEN];
-
+	if (retcode)
 		dev_dbg_ratelimited(dev,
 				"error in ioctl: pid=%d, comm=\"%s\", cmd=%#010x, nr=%#04x\n",
-				task_pid_nr(current), get_task_comm(task_comm, current), cmd, nr);
-	}
+				task_pid_nr(current), current->comm, cmd, nr);
 
 	if (kdata != stack_kdata)
 		kfree(kdata);
@@ -1308,11 +1305,9 @@ long hl_ioctl_control(struct file *filep, unsigned int cmd, unsigned long arg)
 	if (nr == _IOC_NR(DRM_IOCTL_HL_INFO)) {
 		ioctl = &hl_ioctls_control[nr - HL_COMMAND_START];
 	} else {
-		char task_comm[TASK_COMM_LEN];
-
 		dev_dbg_ratelimited(hdev->dev_ctrl,
 				"invalid ioctl: pid=%d, comm=\"%s\", cmd=%#010x, nr=%#04x\n",
-				task_pid_nr(current), get_task_comm(task_comm, current), cmd, nr);
+				task_pid_nr(current), current->comm, cmd, nr);
 		return -ENOTTY;
 	}
 
drivers/gpu/drm/i915/display/intel_display_driver.c +2 -4
index 56b78cf6b854..62596424a9aa 100644
@@ -391,7 +391,6 @@ void intel_display_driver_resume_access(struct drm_i915_private *i915)
  */
 bool intel_display_driver_check_access(struct drm_i915_private *i915)
 {
-	char comm[TASK_COMM_LEN];
 	char current_task[TASK_COMM_LEN + 16];
 	char allowed_task[TASK_COMM_LEN + 16] = "none";
 
@@ -400,12 +399,11 @@ bool intel_display_driver_check_access(struct drm_i915_private *i915)
 		return true;
 
 	snprintf(current_task, sizeof(current_task), "%s[%d]",
-		 get_task_comm(comm, current),
-		 task_pid_vnr(current));
+		 current->comm, task_pid_vnr(current));
 
 	if (i915->display.access.allowed_task)
 		snprintf(allowed_task, sizeof(allowed_task), "%s[%d]",
-			 get_task_comm(comm, i915->display.access.allowed_task),
+			 i915->display.access.allowed_task->comm,
 			 task_pid_vnr(i915->display.access.allowed_task));
 
 	drm_dbg_kms(&i915->drm,
drivers/gpu/drm/nouveau/nouveau_chan.c +1 -3
index 2cb2e5675807..cd659b9fd1d9 100644
@@ -279,7 +279,6 @@ nouveau_channel_ctor(struct nouveau_cli *cli, bool priv, u64 runm,
 	const u64 plength = 0x10000;
 	const u64 ioffset = plength;
 	const u64 ilength = 0x02000;
-	char name[TASK_COMM_LEN];
 	int cid, ret;
 	u64 size;
 
@@ -338,8 +337,7 @@ nouveau_channel_ctor(struct nouveau_cli *cli, bool priv, u64 runm,
 		chan->userd = &chan->user;
 	}
 
-	get_task_comm(name, current);
-	snprintf(args.name, sizeof(args.name), "%s[%d]", name, task_pid_nr(current));
+	snprintf(args.name, sizeof(args.name), "%s[%d]", current->comm, task_pid_nr(current));
 
 	ret = nvif_object_ctor(&device->object, "abi16ChanUser", 0, hosts[cid].oclass,
 			       &args, sizeof(args), &chan->user);
drivers/gpu/drm/nouveau/nouveau_drm.c +2 -3
index 107f63f08bd9..ea7206484d22 100644
@@ -1159,7 +1159,7 @@ nouveau_drm_open(struct drm_device *dev, struct drm_file *fpriv)
 {
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct nouveau_cli *cli;
-	char name[32], tmpname[TASK_COMM_LEN];
+	char name[32];
 	int ret;
 
 	/* need to bring up power immediately if opening device */
@@ -1169,10 +1169,9 @@ nouveau_drm_open(struct drm_device *dev, struct drm_file *fpriv)
 		return ret;
 	}
 
-	get_task_comm(tmpname, current);
 	rcu_read_lock();
 	snprintf(name, sizeof(name), "%s[%d]",
-		 tmpname, pid_nr(rcu_dereference(fpriv->pid)));
+		 current->comm, pid_nr(rcu_dereference(fpriv->pid)));
 	rcu_read_unlock();
 
 	if (!(cli = kzalloc(sizeof(*cli), GFP_KERNEL))) {
drivers/tty/tty_io.c +1 -2
index 9771072da177..102e31f62f76 100644
@@ -2622,14 +2622,13 @@ static int tty_tiocgicount(struct tty_struct *tty, void __user *arg)
 
 static int tty_set_serial(struct tty_struct *tty, struct serial_struct *ss)
 {
-	char comm[TASK_COMM_LEN];
 	int flags;
 
 	flags = ss->flags & ASYNC_DEPRECATED;
 
 	if (flags)
 		pr_warn_ratelimited("%s: '%s' is using deprecated serial flags (with no effect): %.8x\n",
-				__func__, get_task_comm(comm, current), flags);
+				__func__, current->comm, flags);
 
 	if (!tty->ops->set_serial)
 		return -ENOTTY;
Signature · 1 line
2.43.5
#6 lore raw

✗ Fi.CI.BUILD: failure for Remove get_task_comm() and print task comm directly

In reply to Yafang Shao
== Series Details ==

== Series Details ==

Series: Remove get_task_comm() and print task comm directly
URL : https://patchwork.freedesktop.org/series/142837/
State : failure

== Summary ==

Error: patch https://patchwork.freedesktop.org/api/1.0/series/142837/revisions/1/mbox/ not applied
Applying: kernel: Remove get_task_comm() and print task comm directly
Applying: arch: Remove get_task_comm() and print task comm directly
Applying: net: Remove get_task_comm() and print task comm directly
Applying: security: Remove get_task_comm() and print task comm directly
Applying: drivers: Remove get_task_comm() and print task comm directly
Using index info to reconstruct a base tree...
M drivers/gpu/drm/i915/display/intel_display_driver.c
M drivers/gpu/drm/nouveau/nouveau_drm.c
M drivers/tty/tty_io.c
Falling back to patching base and 3-way merge...
Auto-merging drivers/tty/tty_io.c
Auto-merging drivers/gpu/drm/nouveau/nouveau_drm.c
Auto-merging drivers/gpu/drm/i915/display/intel_display_driver.c
CONFLICT (content): Merge conflict in drivers/gpu/drm/i915/display/intel_display_driver.c
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0005 drivers: Remove get_task_comm() and print task comm directly When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Build failed, no error log produced

#7 lore raw

✗ CI.Patch_applied: failure for Remove get_task_comm() and print task comm directly

In reply to Yafang Shao
== Series Details ==

== Series Details ==

Series: Remove get_task_comm() and print task comm directly
URL : https://patchwork.freedesktop.org/series/142835/
State : failure

== Summary ==

=== Applying kernel patches on branch 'drm-tip' with base: ===
Base commit: a5b4c40929f3 drm-tip: 2024y-12m-19d-15h-56m-38s UTC integration manifest === git am output follows ===
error: patch failed: drivers/gpu/drm/i915/display/intel_display_driver.c:391
error: drivers/gpu/drm/i915/display/intel_display_driver.c: patch does not apply
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Applying: kernel: Remove get_task_comm() and print task comm directly
Applying: arch: Remove get_task_comm() and print task comm directly
Applying: net: Remove get_task_comm() and print task comm directly
Applying: security: Remove get_task_comm() and print task comm directly
Applying: drivers: Remove get_task_comm() and print task comm directly Patch failed at 0005 drivers: Remove get_task_comm() and print task comm directly When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".