Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1691965ybt; Thu, 2 Jul 2020 11:22:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPuYRDahZEWfg1Xt5bl4H7TwmM1ReYZb1oO31iULvbDS3yRAcmC8FITCoDu6IS5f5BmHIp X-Received: by 2002:a17:906:e0c7:: with SMTP id gl7mr27075453ejb.264.1593714128842; Thu, 02 Jul 2020 11:22:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593714128; cv=none; d=google.com; s=arc-20160816; b=HHEMX1PA2sCKKoSARFL0DgtilhyU1PxUfItUxIKF7TY9RR1MYtPAZm3S3R5FZchliE Zma7U/bRCFW5zC66PIBjBn15gVLsHiUqCuDVjMFfFcH94v1f8CgLUFkHKlksDATdJfhj AiOntrc66L2KXY8yqQFESgv+AKY8Eo339Tz3/f8lN+8urubYniF2I57n616E3P/9/jH/ cDHPXOOHbK32Xxt0GODt2nYli0czaAx9+v1GdFM5rbgGu4jfQU9ksHnwnBv+opA2HBa+ 7BwslD2pbu20iLeAkxGuZCH4NWdsPCgopbGMB9EDalaI3uiH4K/O6SIn6umVXAaQQlXz vgIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=2K2Hs32m8s3R9zQsf7Qk6Prn12PHGpoBzWkvChbckxg=; b=e6JAicTDt8Xv/sjqv/XJqnzkZc9jfNn29eyCnhFSGer74vA7gfZ8lO3YKojgiALoXn pUlmBZvNBwS9aAtXG0rvCTIXtXNCgc2Tnl+Gb1HuU8YvsqaPkpGDf4Kjz1YSj2+Cv/Xp USUPnAIOdCEao0V0MC38Y2GU/0R7JXQZJkoHE7z9bF6NJ184kg0EcFQa9kbxYS7WJNXa jiJ8kISCGXFgZ8rgLutbzNoLZoqAN8QUDLyw4+U63LchX+aiXkKvgz3UQ13og74G/33p /OBEZpNHNn3cwjK8b8sZC0PPjx/POQanKg934qukz9OymNKVP8GFFPwHNQeFellsUUSG 3ReA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="K7q/s1pk"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v6si6095440eje.743.2020.07.02.11.21.44; Thu, 02 Jul 2020 11:22:08 -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=pass header.i=@kernel.org header.s=default header.b="K7q/s1pk"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727936AbgGBSVP (ORCPT + 99 others); Thu, 2 Jul 2020 14:21:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:36402 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727882AbgGBSVP (ORCPT ); Thu, 2 Jul 2020 14:21:15 -0400 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 41D58208D5 for ; Thu, 2 Jul 2020 18:21:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593714074; bh=od8CmWPiX+a0VrEI4SwvSaUzn0AzEAmUSBqAuGCGkB0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=K7q/s1pkoeNSbBojHMLagRhr4Dj/a2u38lhFSiU8fOOTJmFUme+3YyDC3GgeJJB7t zn+hUkS5pGr5NxpjBxBcf4KLVx23LDAl/xl7PWCiSKNA213QOkGHW2Hb5m6fVKbAvE HDeaH/bUqRfK6bX4FDMZs7OjFyj3yB8krr08Wiuk= Received: by mail-wr1-f49.google.com with SMTP id o11so29636165wrv.9 for ; Thu, 02 Jul 2020 11:21:14 -0700 (PDT) X-Gm-Message-State: AOAM530u6H+JwhI1lmMQzgt/pww2r0P2ZBGsVgBhP8uocUD9dvOPiPrU ACLilij8D8jVhQRW8F10A3PEjyfcJlpVLj1imp9RsA== X-Received: by 2002:adf:a111:: with SMTP id o17mr32330321wro.257.1593714072771; Thu, 02 Jul 2020 11:21:12 -0700 (PDT) MIME-Version: 1.0 References: <87imfwd5f6.fsf@nanos.tec.linutronix.de> <8DD3180E-0E69-4FD6-92C3-311AAB3F688F@amacapital.net> <87d064d13p.fsf@nanos.tec.linutronix.de> <20200702150250.GS4800@hirez.programming.kicks-ass.net> In-Reply-To: <20200702150250.GS4800@hirez.programming.kicks-ass.net> From: Andy Lutomirski Date: Thu, 2 Jul 2020 11:21:01 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Perf: WARNING: arch/x86/entry/common.c:624 idtentry_exit_cond_rcu+0x92/0xc0 To: Peter Zijlstra Cc: Naresh Kamboju , 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 2, 2020 at 8:03 AM Peter Zijlstra wrote: > > 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 I'll fold something like this into my pile of pending fixes.