Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1549974ybt; Thu, 2 Jul 2020 08:06:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLT18JLcGXTZz08zvkDu+v/U0PORtkPa6bPmMKigKAo1Yi7e6KeIevtgmKqkhp+9USDOxg X-Received: by 2002:a17:906:3787:: with SMTP id n7mr26942057ejc.551.1593702409016; Thu, 02 Jul 2020 08:06:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593702409; cv=none; d=google.com; s=arc-20160816; b=gRLSsL1L5AyeCq2PGfJjI4V0aVctmjWhDQ3U0eEKxY58MOyGyISKp49GNhL5G33wwK kJ8h9pkh08Xd68Mtr9T8VZ9lS8ZFL3GIcUc7cOrnSObjbNrb/EdXf63QdBaRzz8g0XWx VKI7YZ5Jl3VbauzK0hXb1dXIAPJsFxnV74C6OiZkO5sZ9SCFcwGG6URoEXnJnm4aaoon XalEH8mPTN81M8Dru0pNFNb7E7ysDbbSh/HWTQJYoYaw5q/3ZAhvP8aRrqs3dLjPNnLO B2ZYv4X+/hCoZ2aqc69JMYSUnkOVfO0shlTSC8Mve5P0/eJpeOWmu91Aeo2a+1RrDo4W ctwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=9GqeEnwkAqHsgBWKwxmrirDR71p/Vge6NVyXyAYx/0E=; b=nOeG9BqyMb+4VwZN7+Uh9g+1Mjy8LUxsEp9qsLrVteC6Snu9L/uvG6zLTY9i0GraGK gzK4nWw/4NpLpnA/THivdJySCcyyIvbJzdDHTimZUWkU3S0lq+p4anUOEn+FICsdERZF 1VBOroqBq1FrbFwU0EYDqtYf0CuFuS87nqOqe37GFc5QIpQ3C3jSsuoqVk3MZq3O/eoI Wy5n6wsqjDMOPYN324MsniWhuIduzwqXqD8t0dOfiL16tKpz4zmKeRLgII9uMT9uxI8M oUGxxmxhnYy/PUqDzu1D3vECJhOepIZPyu5lQcBkU5km47Lbrr1q2ZJA4BZIFjQeWLyL v7ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=BaDVylXR; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id be28si5788470edb.373.2020.07.02.08.06.25; Thu, 02 Jul 2020 08:06:49 -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=fail header.i=@infradead.org header.s=merlin.20170209 header.b=BaDVylXR; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730073AbgGBPDT (ORCPT + 99 others); Thu, 2 Jul 2020 11:03:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726032AbgGBPDQ (ORCPT ); Thu, 2 Jul 2020 11:03:16 -0400 Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D3D4C08C5C1 for ; Thu, 2 Jul 2020 08:03:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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; bh=9GqeEnwkAqHsgBWKwxmrirDR71p/Vge6NVyXyAYx/0E=; b=BaDVylXRZL0pdJE5czcfL4wmwv qfULwWYJKq73NIrRzbGZDSvsvN2oEGD3uctDfVJefjgfIdTbEHg3NJ5LLEQO79nvIfz4DvEKRMi1p P5xjbOZ4S3teL17sTOkiJMO8ymXRRGgPHKiCmtr95vVz+J9M/6+7wUQY9XGXnQrpwidjNv6dPn8WY sIuYbZy/UYdxPeT6/COktMQ3mfxoNjHWKygiJuFotUukMiL7J5E+DpkumINLFsCOeoQaUgfEllbKk aU9xsnKo7JLNK+kEg7sCmhk3l6N188vUTpvOdeJ7g9EX4tRSaQP3Fqms5GFRWODPNtfxUfQNPF+NA 3BiVMjkg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jr0jm-0005xW-C6; Thu, 02 Jul 2020 15:02:54 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 5DFAE3013E5; Thu, 2 Jul 2020 17:02:50 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 4124925F1BEE2; Thu, 2 Jul 2020 17:02:50 +0200 (CEST) Date: Thu, 2 Jul 2020 17:02:50 +0200 From: Peter Zijlstra To: Naresh Kamboju Cc: Andy Lutomirski , Thomas Gleixner , Andy Lutomirski , open list , X86 ML , cj.chengjian@huawei.com, Arnaldo Carvalho de Melo , Ingo Molnar , "H. Peter Anvin" , Borislav Petkov , Minchan Kim , Andrew Morton , Michel Lespinasse , lkft-triage@lists.linaro.org, Dave Hansen Subject: Re: Perf: WARNING: arch/x86/entry/common.c:624 idtentry_exit_cond_rcu+0x92/0xc0 Message-ID: <20200702150250.GS4800@hirez.programming.kicks-ass.net> References: <87imfwd5f6.fsf@nanos.tec.linutronix.de> <8DD3180E-0E69-4FD6-92C3-311AAB3F688F@amacapital.net> <87d064d13p.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 02, 2020 at 07:57:54PM +0530, Naresh Kamboju wrote: > I have reported this warning on linux-next and now it is happening on > linux mainline tree. > May I know , are we missing a fix patch on linus 's tree ? > > - Naresh > --- > While running selftest x86 single_step_syscall_32 on > i386 kernel linux 5.8.0-rc3 kernel warning noticed. > > steps to reproduce: > -------------------------- > perf test > and > cd /opt/kselftests/default-in-kernel/x86 > ./single_step_syscall_32 > > crash dump, > [ 1324.774385] kselftest: Running tests in x86 > [ 1324.830187] ------------[ cut here ]------------ > [ 1324.834820] IRQs not disabled as expected > [ 1324.838838] WARNING: CPU: 2 PID: 5365 at > /usr/src/kernel/arch/x86/entry/common.c:645 > idtentry_exit_cond_rcu+0x92/0xc0 How's this? DEFINE_IDTENTRY_DEBUG() is DEFINE_IDTENTRY_RAW on x86_64 DEFINE_IDTENTRY on i386 calling exc_debug_*() from DEFINE_IDTENTRY() does a double layer of idtentry_{enter,exit}*() functions. Also, handle_debug() is still a trainwreck, we should never get to cond_local_irq_enable() when !user. Completely untested... --- arch/x86/kernel/traps.c | 49 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index b0195771c932..47d6b46e1564 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -806,8 +806,17 @@ static void handle_debug(struct pt_regs *regs, unsigned long dr6, bool user) * If DR6 is zero, no point in trying to handle it. The kernel is * not using INT1. */ - if (!user && !dr6) - return; + if (!user) { + /* + * Catch SYSENTER with TF set and clear DR_STEP. If this hit a + * watchpoint at the same time then that will still be handled. + */ + if ((dr6 & DR_STEP) && is_sysenter_singlestep(regs)) + dr6 &= ~DR_STEP; + + if (!dr6) + return; + } /* * If dr6 has no reason to give us about the origin of this trap, @@ -859,25 +868,29 @@ static void handle_debug(struct pt_regs *regs, unsigned long dr6, bool user) cond_local_irq_disable(regs); } +#ifdef CONFIG_X86_64 static __always_inline void exc_debug_kernel(struct pt_regs *regs, unsigned long dr6) { bool irq_state = idtentry_enter_nmi(regs); instrumentation_begin(); - /* - * Catch SYSENTER with TF set and clear DR_STEP. If this hit a - * watchpoint at the same time then that will still be handled. - */ - if ((dr6 & DR_STEP) && is_sysenter_singlestep(regs)) - dr6 &= ~DR_STEP; - handle_debug(regs, dr6, false); instrumentation_end(); idtentry_exit_nmi(regs, irq_state); } +/* IST stack entry */ +DEFINE_IDTENTRY_DEBUG(exc_debug) +{ + unsigned long dr6, dr7; + + debug_enter(&dr6, &dr7); + exc_debug_kernel(regs, dr6); + debug_exit(dr7); +} + static __always_inline void exc_debug_user(struct pt_regs *regs, unsigned long dr6) { @@ -890,17 +903,6 @@ static __always_inline void exc_debug_user(struct pt_regs *regs, idtentry_exit_user(regs); } -#ifdef CONFIG_X86_64 -/* IST stack entry */ -DEFINE_IDTENTRY_DEBUG(exc_debug) -{ - unsigned long dr6, dr7; - - debug_enter(&dr6, &dr7); - exc_debug_kernel(regs, dr6); - debug_exit(dr7); -} - /* User entry, runs on regular task stack */ DEFINE_IDTENTRY_DEBUG_USER(exc_debug) { @@ -917,12 +919,7 @@ DEFINE_IDTENTRY_DEBUG(exc_debug) unsigned long dr6, dr7; debug_enter(&dr6, &dr7); - - if (user_mode(regs)) - exc_debug_user(regs, dr6); - else - exc_debug_kernel(regs, dr6); - + handle_debug(regs, dr6, user_mode(regs)); debug_exit(dr7); } #endif