public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Stephen Boyd <sboyd@kernel.org>,
	Felix.Kuehling@amd.com, Qianli Zhao <zhaoqianligood@gmail.com>,
	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
Date: Wed, 12 Aug 2020 12:27:03 +0200	[thread overview]
Message-ID: <87pn7w5fd4.fsf@nanos.tec.linutronix.de> (raw)
In-Reply-To: <159722125596.33733.17725649536425524344@swboyd.mtv.corp.google.com>

Stephen,

Stephen Boyd <sboyd@kernel.org> 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

  reply	other threads:[~2020-08-12 10:27 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-12  5:14 [RFC V2] kthread: add object debug support Qianli Zhao
2020-08-12  8:34 ` Stephen Boyd
2020-08-12 10:27   ` Thomas Gleixner [this message]
2020-08-15  8:37     ` Stephen Boyd
2020-08-16 19:38       ` Thomas Gleixner
2020-08-12 10:10 ` Thomas Gleixner
2020-08-20  6:25 ` [kthread] 2e7d8748eb: last_state.is_incomplete_run kernel test robot
2020-08-27  3:49   ` qianli zhao
2020-09-02  7:53     ` Chen, Rong A

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=87pn7w5fd4.fsf@nanos.tec.linutronix.de \
    --to=tglx@linutronix.de \
    --cc=Felix.Kuehling@amd.com \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=ben.dooks@codethink.co.uk \
    --cc=bfields@redhat.com \
    --cc=cl@rock-chips.com \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sboyd@kernel.org \
    --cc=zhaoqianli@xiaomi.com \
    --cc=zhaoqianligood@gmail.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