Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754990AbcDFNGX (ORCPT ); Wed, 6 Apr 2016 09:06:23 -0400 Received: from mx2.suse.de ([195.135.220.15]:53037 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751827AbcDFNGV (ORCPT ); Wed, 6 Apr 2016 09:06:21 -0400 Date: Wed, 6 Apr 2016 15:06:19 +0200 From: Petr Mladek To: Josh Poimboeuf 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: <20160406130619.GA5218@pathway.suse.cz> References: <24db5a6ae5b63dfcd2096a12d18e1399a351348e.1458933243.git.jpoimboe@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <24db5a6ae5b63dfcd2096a12d18e1399a351348e.1458933243.git.jpoimboe@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 880 Lines: 35 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); /* * 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); } Best Regards, Petr