Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2102220yba; Wed, 3 Apr 2019 01:03:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqwG88D0FuvHg7wh2EMeMq9N++Wt66R6+psG2N+UxQmEAnAea6AVg4i1DkU37K7yl3Bx28ZZ X-Received: by 2002:a62:2fc4:: with SMTP id v187mr76060895pfv.147.1554278634980; Wed, 03 Apr 2019 01:03:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554278634; cv=none; d=google.com; s=arc-20160816; b=gsYouz6AyrXrFwz7VNQWNVnZHxRZWqlkWdOa7omPGpQzWEkYFhYWhmUuU+65RScQKG /vF2idRyxCw0MUsfUQnc++DnGY6MsGGkJkcDwctzgTwivDEggSaURhLnDfMLK5h15hOc YHQrH9vyBDxHjtonDIy5c09EaoS9MmGXTSj+mIpdMFiP4shJD81KLrBRoNtsZtI+xE0d KZknLz9SlPbbA70PJRLbd5XqrGYBjoyLRoFBcd1psWveqhJgpqc4VNsJa4vqZ5ZAQ2gz un65CE1D4lCgDJ9omszd6fEJj5xS/ZxXkPQlZhKsmoGnhj5R6CITnKQxpO5qj7yHBH7u tIBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=W4sm/eXh6xPYghIEJK6s5BwcuH5zyEoSDxJLYaprRPo=; b=f9idSQp78IXHbil4QrpO5Wvd231cZAHAJd380HC/EiFSdjjCl1D6soFFJMznfWeKjt IbM17YAgBUZo8LUK2K7vt7u4eWs5f5CIehTYSNT25dktYds7zPRH00otx6WjaDovNYqu /EcEMnv+1Q15Wzpyi9/nxm8p5rK4IMJQxahTz7Uydxp4RCh5SBoN2ufBwV9+pi6jnZ33 i2eF8XavCI+kkB/SH61C0p+Vjowd88EKmAVV+6qpogn9hKQbqyZTreC2ddUHxueW6L14 NDhhoDQ2Gb4DO+VTNeRL/MMd9hvHoWpm6tubN9tJ8sRqQZjgzF43d8Gi22K3nvHZUkXn n94g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=ZA4eBlzF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cv9si13854880plb.371.2019.04.03.01.03.38; Wed, 03 Apr 2019 01:03:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=ZA4eBlzF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728847AbfDCIC3 (ORCPT + 99 others); Wed, 3 Apr 2019 04:02:29 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:48944 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726360AbfDCIC2 (ORCPT ); Wed, 3 Apr 2019 04:02:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=W4sm/eXh6xPYghIEJK6s5BwcuH5zyEoSDxJLYaprRPo=; b=ZA4eBlzFLtzPGBrcJlkRbUNjz dZJz/R2oIa428kNyZw3Fn/SVRKhPKljEXpE5nqtBW0Pm5mfTv5nv/Z/UHwbiJ7Lnm/bFgubR3EQee 0mJeCZhcI672wYzyXAzw+poPdiXVEW4TRdrreJKM0L0j7oZwTCHLqg9jvaU0xqfHvYWqwAT6n9WQG tCjcHQpaE0tQeWFLLBNwe5JVbvTI8Aw+cVUAZUbmFpBstFAOGnFj4blLCaGuGP0s8Vq9o1l/U/g13 Z4w5QkkLQD7CRTJBAbr7bfxHWo6pYMO+C9s0vSgr2HJDKQuM2bGSsPa8J+ya9PLxH0sJIFvpqumWY ugNm40FlA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBaqo-0008RK-RS; Wed, 03 Apr 2019 08:02:27 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 59557203C722D; Wed, 3 Apr 2019 10:02:25 +0200 (CEST) Date: Wed, 3 Apr 2019 10:02:25 +0200 From: Peter Zijlstra To: Josh Poimboeuf Cc: Thomas Gleixner , LKML , x86@kernel.org, Andy Lutomirski Subject: Re: [patch 15/14] x86/dumpstack/64: Speedup in_exception_stack() Message-ID: <20190403080225.GM12232@hirez.programming.kicks-ass.net> References: <20190331214020.836098943@linutronix.de> <20190331215136.039902969@linutronix.de> <20190402154329.scp7i7uqevubgwrz@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190402154329.scp7i7uqevubgwrz@treble> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 02, 2019 at 10:43:29AM -0500, Josh Poimboeuf wrote: > On Tue, Apr 02, 2019 at 12:19:46PM +0200, Thomas Gleixner wrote: > > static bool in_exception_stack(unsigned long *stack, struct stack_info *info) > > { > > - unsigned long estacks, begin, end, stk = (unsigned long)stack; > > + unsigned long begin, end, stk = (unsigned long)stack; > > + const struct estack_pages *ep; > > struct pt_regs *regs; > > unsigned int k; > > > > BUILD_BUG_ON(N_EXCEPTION_STACKS != 4); > > > > - estacks = (unsigned long)__this_cpu_read(cea_exception_stacks); > > - > > - for (k = 0; k < N_EXCEPTION_STACKS; k++) { > > - begin = estacks + layout[k].begin; > > - end = estacks + layout[k].end; > > - regs = (struct pt_regs *)end - 1; > > - > > - if (stk <= begin || stk >= end) > > - continue; > > - > > - info->type = STACK_TYPE_EXCEPTION + k; > > - info->begin = (unsigned long *)begin; > > - info->end = (unsigned long *)end; > > - info->next_sp = (unsigned long *)regs->sp; > > - > > - return true; > > - } > > - > > - return false; > > + begin = (unsigned long)__this_cpu_read(cea_exception_stacks); > > + end = begin + sizeof(struct cea_exception_stacks); > > + /* Bail if @stack is outside the exception stack area. */ > > + if (stk <= begin || stk >= end) > > + return false; > > This check is the most important piece. Exception stack dumps are quite > rare, so this ensures an early exit in most cases regardless of whether > there's a loop below. > > > + > > + /* Calc page offset from start of exception stacks */ > > + k = (stk - begin) >> PAGE_SHIFT; > > + /* Lookup the page descriptor */ > > + ep = &estack_pages[k]; > > + /* Guard page? */ > > + if (unlikely(!ep->size)) > > + return false; > > + > > + begin += (unsigned long)ep->offs; > > + end = begin + (unsigned long)ep->size; > > + regs = (struct pt_regs *)end - 1; > > + > > + info->type = ep->type; > > + info->begin = (unsigned long *)begin; > > + info->end = (unsigned long *)end; > > + info->next_sp = (unsigned long *)regs->sp; > > + return true; > > With the above "(stk <= begin || stk >= end)" check, removing the loop > becomes not all that important since exception stack dumps are quite > rare and not performance sensitive. With all the macros this code > becomes a little more obtuse, so I'm not sure whether removal of the > loop is a net positive. Are you sure; perf does a lot of stack dumps from NMI context.