Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756297AbcDGOeH (ORCPT ); Thu, 7 Apr 2016 10:34:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11089 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751670AbcDGOeF (ORCPT ); Thu, 7 Apr 2016 10:34:05 -0400 Date: Thu, 7 Apr 2016 09:34:03 -0500 From: Josh Poimboeuf To: Petr Mladek Cc: Jiri Kosina , Jessica Yu , Miroslav Benes , linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Vojtech Pavlik Subject: Re: [RFC PATCH v1.9 05/14] sched: horrible way to detect whether a task has been preempted Message-ID: <20160407143403.6f7wvjvh2r43e4la@treble.redhat.com> References: <24db5a6ae5b63dfcd2096a12d18e1399a351348e.1458933243.git.jpoimboe@redhat.com> <20160406130619.GA5218@pathway.suse.cz> <20160406163356.hba6jzkloaukknn4@treble.redhat.com> <20160407094700.GA27670@pathway.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20160407094700.GA27670@pathway.suse.cz> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1886 Lines: 55 On Thu, Apr 07, 2016 at 11:47:00AM +0200, Petr Mladek wrote: > On Wed 2016-04-06 11:33:56, Josh Poimboeuf wrote: > > On Wed, Apr 06, 2016 at 03:06:19PM +0200, Petr Mladek wrote: > > > On Fri 2016-03-25 14:34:52, Josh Poimboeuf wrote: > > > > This is a horrible way to detect whether a task has been preempted. > > > > Come up with something better: task flag? or is there already an > > > > existing mechanism? > > > > > > What about using kallsyms_lookup_size_offset() to check the address. > > > It is more heavyweight but less hacky. The following code seems > > > to work for me: > > > > > > bool in_preempt_schedule_irq(unsigned long addr) > > > { > > > static unsigned long size; > > > > > > if (unlikely(!size)) { > > > int ret; > > > > > > ret = kallsyms_lookup_size_offset( > > > (unsigned long)preempt_schedule_irq, > > > size, NULL); > ^^^^ > It works even better with &size ;-) > > > > > > > /* > > > * Warn when the function is used without kallsyms or > > > * when it is unable to locate preempt_schedule_irq(). > > > * Be conservative and always return true in this case. > > > */ > > > if (WARN_ON(!ret)) > > > size = -1L; > > > } > > > > > > return (addr - (unsigned long)preempt_schedule_irq <= size); > > > } > > > > Yeah, that would definitely be better. Though still somewhat hacky. > > Yeah. Well this is the same approach that we use to check if a patched > function is on the stack. Oh, I agree that it's a good way to check if preempt_schedule_irq() is on the stack. I'm just not convinced that's the cleanest way to ask "has this task been preempted". > We could even move this check into the livepatch code but then > print_context_stack_reliable() will not always give reliable results. Why would moving the check to the livepatch code affect the reliability of print_context_stack_reliable()? -- Josh