Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp340235pxa; Wed, 12 Aug 2020 03:30:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSzwBu+n4zxNadtLtWdmCMDrp0ReFkzaEMuwzu9l45kJJTTKLnpvCKuAqnzLorjzscz+FZ X-Received: by 2002:a05:6402:1606:: with SMTP id f6mr29009359edv.328.1597228235982; Wed, 12 Aug 2020 03:30:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597228235; cv=none; d=google.com; s=arc-20160816; b=ybxqDhI16DO7PGmpzHtXZvmFD3x6uc9G+gM1UKKqXQukKPjZEXszkenW+0g6P9NdN8 9uU2Q8Wl0oGGNrd1m79wzh8Vb6m13iaancR/1FJ8FzQ2NJYrSnul+kQ6jDRNRYrRXaPz QpOAqsTCmTKOanB3LdbH9eEmOatdHMZqLqFO/F+0p3EKEujdalLqE6f3+EV/etZUDysh yyuxZmyVi7QWStrT3VhziNTqq314SXZNoYtfxou/K+PypZ37OLgsF250Jq7BlvGnzcTa GFxnsYbufpAAAXUunG6NoJ8xZy4qgqzCPIlJ1izV0dKhO+L4Hk8kTS/hJSBoO6yAZpyf yr4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=s5r9hWDwW99yywu0GiffCS2t4+i9DAlf4Ar8Gn4QbAU=; b=N7TxVntXdrXt+o+2cEyNDgEwrVOoTaqYcQDfVImxIJa8giftLwP5Hb0U/crYckfurY eLH5W7OhVjnzxKEwKnIEg70Jc2jO0F4s/3oRVEvkebLowgffi4oIDVusd84QwmvMuNi9 GZ5csbZaUy+BnDXVvoQIVU0VrxjUCs+ZxkcV7SEd2jj5eTe3QY+zm8a7PAa/hYuHhrPL K/D5HS2B6Y/L7jLYnnmTyr5R5zyQgOlujEVsvoHAxruA1Z1d8HBdT7l6Dhjyvt+yzhja 9+jOaQHRx5MthjKRp5u3cBd2v4T7Gl8V8jc1pzWLOLvgFax6xgNEaog9IP1sDBAUGBdy jsww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Icpguvym; dkim=neutral (no key) header.i=@linutronix.de header.b="/Va/gAmR"; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ly14si790022ejb.369.2020.08.12.03.30.11; Wed, 12 Aug 2020 03:30:35 -0700 (PDT) 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=@linutronix.de header.s=2020 header.b=Icpguvym; dkim=neutral (no key) header.i=@linutronix.de header.b="/Va/gAmR"; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727078AbgHLK1G (ORCPT + 99 others); Wed, 12 Aug 2020 06:27:06 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:51352 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726595AbgHLK1G (ORCPT ); Wed, 12 Aug 2020 06:27:06 -0400 From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1597228024; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=s5r9hWDwW99yywu0GiffCS2t4+i9DAlf4Ar8Gn4QbAU=; b=IcpguvymfkOKOvtKOyUS8vZZtHdSz4DAL7j1cYuGbJJ56NjQYaFkIacfig/QO5Q60hcOtY 1qwaZxFW536hZXFLeMqg3/sHQk9ktXj1W0V/seEnpsYJywF2YJIZZC5VGsF42c9z9lCmQR 5uiCA/qlkPprFaL9MWN3WtZqviqDCzNWFhdAtf2p1Nit5zKKLgjQgODOs3YU4BReGtuWZw mGcImTbvuzMEoDoIWT1aal/uXN+KgKFRuHi6NvOEjVeH+EvEJ0otuKBKON0EZgA+sf5yPo WQjVzcaFmz3IIoJC0CCQSHfs2zynfNQJOX4Tonf+dvre6KTEvd19Tc6iLy1VAQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1597228024; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=s5r9hWDwW99yywu0GiffCS2t4+i9DAlf4Ar8Gn4QbAU=; b=/Va/gAmRz4fluU+CTzYZf2GxYiCMrqG4tr6nbKJer5IHuNifIR+eD/Fps/W4yFJKv+TMTx AAW3RCGCTwHDt4Aw== To: Stephen Boyd , Felix.Kuehling@amd.com, Qianli Zhao , akpm@linux-foundation.org, axboe@kernel.dk Cc: john.stultz@linaro.org, ben.dooks@codethink.co.uk, bfields@redhat.com, cl@rock-chips.com, linux-kernel@vger.kernel.org, zhaoqianli@xiaomi.com Subject: Re: [RFC V2] kthread: add object debug support In-Reply-To: <159722125596.33733.17725649536425524344@swboyd.mtv.corp.google.com> References: <311159bc826dcca2848344fc277c0069cff0a164.1597207603.git.zhaoqianli@xiaomi.com> <159722125596.33733.17725649536425524344@swboyd.mtv.corp.google.com> Date: Wed, 12 Aug 2020 12:27:03 +0200 Message-ID: <87pn7w5fd4.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Stephen, Stephen Boyd writes: > Quoting Qianli Zhao (2020-08-11 22:14:14) >> +/********** kernel/kthread **********/ >> +#define KWORK_ENTRY_STATIC ((void *) 0x600 + POISON_POINTER_DELTA) > > Is this related to the debugobjects change here? It looks like another > version of list poison. Yes, it is. We use these poison entries to mark statically allocated objects. debug objects does not know about statically initialized objects up to the point where they are used (activated). That means the object state lookup will fail which causes debugobjects to complain about using an uninitialized object. But in case of static initialized ones that's a false positive. So we mark these objects in their list head (or some other appropriate place) with a poison value and in case of a failed lookup debug object does: if (descr->is_static_object && descr->is_static_object(addr)) { /* track this static object */ debug_object_init(addr, descr); debug_object_activate(addr, descr); } The object specific is_static_object() callback will then check for the magic list poison value being present: > +static bool kwork_is_static_object(void *addr) > +{ > + struct kthread_work *kwork = addr; > + > + return (kwork->node.prev == NULL && > + kwork->node.next == KWORK_ENTRY_STATIC); > +} and if so the debug object core fixes its internal state by creating a tracking object and then activating it. It's not a perfect "yes this is statically initialized" check but good enough. If you go and do: work = kzalloc(sizeof(*work); work->node.next = KWORK_ENTRY_STATIC; kthread_insert_work(worker, work); or any other variant of insanity which makes the check claim that this is statically initialized then you rightfully can keep the pieces :) >> diff --git a/kernel/kthread.c b/kernel/kthread.c >> index 132f84a..ca00bd2 100644 >> --- a/kernel/kthread.c >> +++ b/kernel/kthread.c >> @@ -698,6 +786,7 @@ int kthread_worker_fn(void *worker_ptr) >> work = list_first_entry(&worker->work_list, >> struct kthread_work, node); >> list_del_init(&work->node); >> + debug_kwork_deactivate(work); > > Shouldn't this come before the list operation so that any sort of fix > can be made before possibly corrupting a list? Yes. >> } >> worker->current_work = work; >> raw_spin_unlock_irq(&worker->lock); >> @@ -835,8 +924,11 @@ static void kthread_insert_work(struct kthread_worker *worker, >> >> list_add_tail(&work->node, pos); >> work->worker = worker; >> - if (!worker->current_work && likely(worker->task)) >> + >> + if (!worker->current_work && likely(worker->task)) { >> + debug_kwork_activate(work); You missed this one as I explained to Qianli already. It's way worse than the other two. Thanks, tglx