Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp10502995pxu; Wed, 30 Dec 2020 04:43:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJwECHDnXamekohgUgVQbArM08oO6/wH4GIorbcOT1YCRGGS0ucSj/GJmO8+Xa8k589X0tnj X-Received: by 2002:aa7:c353:: with SMTP id j19mr50456935edr.204.1609332183558; Wed, 30 Dec 2020 04:43:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609332183; cv=none; d=google.com; s=arc-20160816; b=EaMSXuiPgzYbTfKl0XZTbZ7ee5vet7yNUpuEn0EgrEi6j2JfBNga3d8zQZq2g/znuv qUln26GKLygFzjW4n+tAbtye7WTrni5gV2GpstMVUFtg/K6gW+2RsL5XVGDWggW+shcA clKPsicrptQNj9H13+GAH4MIQa7iY6OVrj6MS3cS9qqw+dSTGxVxxIlUSz08oktgH+LV Lrzm0nmSUnlsfYF+46v8BpiCcrk04Hc3aZjfMMbQ5LbOi8VcbbS26eVtqdbukUnkb3VZ 1ro3A7/EXWI8IQX8BW9aOgPIRLcbpq/qwTLGWMZE9hvU1wDIuyKruIfnXjLr/Xt4oh+o 7NSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=q2TLR5uMWYx9Zjvtm64ODpVWFeCQN26a256zYBLajaI=; b=b6U1+nNE9dX+gnnCMl3U8mb/HOzp3v3TCiHwE6kETOWKNAiqET/t9viA3l/eK8NwXg F8rC5I+8e5moQlKHdcO+SsxXvritCYtLiR21iS1W2Bd57uK08SQsYj+X0HeKRbTmxbur A6e1nV2oZfYOkMv+R+NTd33vRTstYosveIuviwtefOoJxYJaXTVmOtAj9INR+h1qnE3i QNnH7B09ulzwsF8TLiVDnlmFhi5+0jEiJCWLliKi2umkAV+bIsE0jKFS74bMwNlGfmTZ pAFgyJZD2jAO1pZwJOJ9uBQAu07zc3NlX4ExdBdHD9gG7rLzKnbtoYaHy5tSEgYlQp6U vb1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=e6i6ZaqB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m1si21511820eje.652.2020.12.30.04.42.40; Wed, 30 Dec 2020 04:43:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=e6i6ZaqB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726716AbgL3MkY (ORCPT + 99 others); Wed, 30 Dec 2020 07:40:24 -0500 Received: from mail.zx2c4.com ([192.95.5.64]:57437 "EHLO mail.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726547AbgL3MkX (ORCPT ); Wed, 30 Dec 2020 07:40:23 -0500 Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTP id b3d86b37 for ; Wed, 30 Dec 2020 12:30:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=mime-version :references:in-reply-to:from:date:message-id:subject:to:cc :content-type; s=mail; bh=DRvKx1JOp86Sg2wzMfT7xlVo2kk=; b=e6i6Za qBKb+E/gZ567M3RGDvR/Mus8Ati8OLhKr9WOhwEbTRRqO0GgYeJyV4PO95EgdGhK ++dsI0L/etgH3d0/KzKcmourHdJfPsbVtbt1WuePU8UaR7BhWj4sJlJOjqWCNgPn Uw87nhw7xT3tHEkAPF5u/8KehaOBR2gS1PlYR4jcUz6gNZs5D/254zH2ID5QskLA HZNX+sMsMJ025q1vV36vldxorOhZ7ZWLFu4lH8N7movj7ZnCoQOT7PudiDLdgfoK Skbi0lSopVQkEmXouGs58w2RrFWD4HLpyZwZ2UUQPOJkblT4+liZpE+91BXXmTrt iPT9fj6zXnYSCJGg== Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 34f60ad0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 30 Dec 2020 12:30:14 +0000 (UTC) Received: by mail-yb1-f174.google.com with SMTP id k78so14744617ybf.12 for ; Wed, 30 Dec 2020 04:39:40 -0800 (PST) X-Gm-Message-State: AOAM533t7wtdemAPGUOvLffAqZJ+68mSEY3/OrLowL9Mhfha44Z8HF0P QjPVLSW9QxfqBwFvOPJAoah1SmVxTmKQon7fcNs= X-Received: by 2002:a25:4744:: with SMTP id u65mr81479869yba.239.1609331979967; Wed, 30 Dec 2020 04:39:39 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: "Jason A. Donenfeld" Date: Wed, 30 Dec 2020 13:39:28 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: wg-crypt-wg0 process To: Fatih USTA Cc: WireGuard mailing list , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Fatih, Thanks for the report and the detailed test case. From what I can see, this behavior presents itself both with the explicit ip link del and without. When running with debugging enabled, I can see this in dmesg: [558758.361056] wireguard: wg0: Keypair 244 destroyed for peer 21 [558758.546649] wireguard: wg0: Peer 21 (10.150.150.2:51820) destroyed [558758.563317] wireguard: wg0: Interface destroyed [558758.567803] wireguard: wg0: Keypair 243 destroyed for peer 22 [558758.733287] wireguard: wg0: Peer 22 (10.150.150.1:51820) destroyed [558758.749991] wireguard: wg0: Interface destroyed The fact that I see "Interface destroyed" for both interfaces means that wg_destruct() is being called, which includes these calls: destroy_workqueue(wg->handshake_receive_wq); destroy_workqueue(wg->handshake_send_wq); destroy_workqueue(wg->packet_crypt_wq); In doing so, the output of ps changes from: $ ps aux|grep wg0 root 200479 0.0 0.0 0 0 ? I 13:06 0:00 [kworker/0:2-wg-crypt-wg0] root 201226 0.0 0.0 0 0 ? I 13:08 0:00 [kworker/1:4-wg-crypt-wg0] root 201476 0.0 0.0 0 0 ? I< 13:11 0:00 [wg-crypt-wg0] root 201484 0.0 0.0 0 0 ? I< 13:11 0:00 [wg-crypt-wg0] to: $ ps aux|grep wg0 root 200479 0.0 0.0 0 0 ? I 13:06 0:00 [kworker/0:2-wg-crypt-wg0] root 201226 0.0 0.0 0 0 ? I 13:08 0:00 [kworker/1:4-wg-crypt-wg0] What I suspect is happening is that destroying the workqueue does not actually destroy the kthreads that they were using, so that they can be reused (and eventually relabeled) by other drivers. Looking at the stack of those indicates this is probably the case: $ cat /proc/200479/stack [<0>] worker_thread+0xba/0x3c0 [<0>] kthread+0x114/0x130 [<0>] ret_from_fork+0x1f/0x30 So it's just hanging out there idle waiting to be scheduled by something new. In fact, while I was writing this email, that worker already seems to have been reclaimed by another driver: $ cat /proc/200479/comm kworker/0:2-events Now it's called "events". This is happening because the kthread isn't actually destroyed, and task->comm is being hijacked. In proc_task_name we have: if (p->flags & PF_WQ_WORKER) wq_worker_comm(tcomm, sizeof(tcomm), p); else __get_task_comm(tcomm, sizeof(tcomm), p); That top condition holds for workqueue workers, and wq_worker_comm winds up scnprintf'ing the current worker description in there: /* * ->desc tracks information (wq name or * set_worker_desc()) for the latest execution. If * current, prepend '+', otherwise '-'. */ if (worker->desc[0] != '\0') { if (worker->current_work) scnprintf(buf + off, size - off, "+%s", worker->desc); else scnprintf(buf + off, size - off, "-%s", worker->desc); But worker->desc isn't set until process_one_work is called: /* * Record wq name for cmdline and debug reporting, may get * overridden through set_worker_desc(). */ strscpy(worker->desc, pwq->wq->name, WORKER_DESC_LEN); And it's never unset after the work is done and it's waiting idle in worker_thread for the scheduler to reschedule it and eventually call process_one_work on a new work unit. It would be easy to just null out that string after the work is done with something like: worker->current_func(work); worker->desc[0] = '\0'; But I guess this has never sufficiently bothered anyone before. I suppose I could submit a patch and see how it's received. But it also looks like the scnprintf above in wq_worker_comm distinguishes these cases anyway. If there's a + it means that the work is active and if there's a - it means that it's an old leftover thread. So maybe this is fine as-is? Jason