Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp272231pxb; Mon, 13 Sep 2021 19:02:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8j3WDv/pX5TvcrcHA/ARr5pPVcs92vnrt2ptL0ZN+GIigsrZzL0F5vl1Yx+ZPYxU8yaBh X-Received: by 2002:a17:906:6148:: with SMTP id p8mr15791376ejl.17.1631584956146; Mon, 13 Sep 2021 19:02:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631584956; cv=none; d=google.com; s=arc-20160816; b=JF+BtjACECkFljrFHg/0GUep+UqSxxwsnyErHaf88zBK/Trb2I/8wNnCSEst0vonei unUfPsx19KKwWMfk56qhNoAW9FcOIkhO2xOYDydv7t4juFjjg13VmTB+/iHLv7gtHsBB Ssnan+AaiDOGcpAawt1xSJvGtIlsQ8q836sjkfw27s2dnOCusKG4hSwed7R83Acf6EID VjM6GuXz6oWbgLJBAVvAtZqdaY1w5cl35E3bP5USi1jLyt9Ggw4oDL3Qjq74ikrvjXs+ 9UB+bX0bR1B3T+oOoGVsabMrjAi53mcBRdaIqgueTNATLd2T64JTayORfv/LGiKTlN/T izrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=g4WTK+Yo9GwOB+tXURqkkCbkMLQ1/byGt8MnkbGlpM4=; b=WgnXxwviNjPGoOk0dN6i3COMxsQydgArAqciWZwmYmhaVff9Ll2pXKaODRuJ6k4Blg OONS6rCp+qPSzEREUcQ/v/v7ia04pVP3vXZTbudeRMIQHVwGMMyndxKUs/BlbN7XL/RJ BOdpeKvpwXb4VmscyOfz8twQHfPRlGpEeV/rJOjI43dZXTncJwA3n4MF5EnVrF8f6kMW WhEMtq9yP1oXWe4j4cr48WUbt/hS/tJkyUQklIhpyPyTkcdFco6cbQ6N5cgk1rrK36w1 vEkxmOCmaEgDLwkuaugwyFV2GXvZcSAUpxi0/eb9YKaYtq0wR5d1TS7WO3YqsVeeONwp B4YA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s27si8790169edy.251.2021.09.13.19.02.12; Mon, 13 Sep 2021 19:02:36 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231248AbhINCAE (ORCPT + 99 others); Mon, 13 Sep 2021 22:00:04 -0400 Received: from out30-45.freemail.mail.aliyun.com ([115.124.30.45]:50482 "EHLO out30-45.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229778AbhINCAE (ORCPT ); Mon, 13 Sep 2021 22:00:04 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R291e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=alimailimapcm10staff010182156082;MF=yun.wang@linux.alibaba.com;NM=1;PH=DS;RN=19;SR=0;TI=SMTPD_---0UoKP4AU_1631584724; Received: from testdeMacBook-Pro.local(mailfrom:yun.wang@linux.alibaba.com fp:SMTPD_---0UoKP4AU_1631584724) by smtp.aliyun-inc.com(127.0.0.1); Tue, 14 Sep 2021 09:58:45 +0800 Subject: Re: [RFC PATCH] perf: fix panic by mark recursion inside perf_log_throttle To: Peter Zijlstra Cc: Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , "open list:PERFORMANCE EVENTS SUBSYSTEM" , "open list:PERFORMANCE EVENTS SUBSYSTEM" , "open list:BPF (Safe dynamic programs and tools)" , "open list:BPF (Safe dynamic programs and tools)" References: <20210910153839.GH4323@worktop.programming.kicks-ass.net> From: =?UTF-8?B?546L6LSH?= Message-ID: <3fb7c51f-696b-da70-1965-1dda9910cb14@linux.alibaba.com> Date: Tue, 14 Sep 2021 09:58:44 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/9/13 下午6:24, Peter Zijlstra wrote: > On Mon, Sep 13, 2021 at 11:00:47AM +0800, 王贇 wrote: >> >> >> On 2021/9/10 下午11:38, Peter Zijlstra wrote: >>> On Thu, Sep 09, 2021 at 11:13:21AM +0800, 王贇 wrote: >>>> When running with ftrace function enabled, we observed panic >>>> as below: >>>> >>>> traps: PANIC: double fault, error_code: 0x0 >>>> [snip] >>>> RIP: 0010:perf_swevent_get_recursion_context+0x0/0x70 >>>> [snip] >>>> Call Trace: >>>> >>>> perf_trace_buf_alloc+0x26/0xd0 >>>> perf_ftrace_function_call+0x18f/0x2e0 >>>> kernelmode_fixup_or_oops+0x5/0x120 >>>> __bad_area_nosemaphore+0x1b8/0x280 >>>> do_user_addr_fault+0x410/0x920 >>>> exc_page_fault+0x92/0x300 >>>> asm_exc_page_fault+0x1e/0x30 >>>> RIP: 0010:__get_user_nocheck_8+0x6/0x13 >>>> perf_callchain_user+0x266/0x2f0 >>>> get_perf_callchain+0x194/0x210 >>>> perf_callchain+0xa3/0xc0 >>>> perf_prepare_sample+0xa5/0xa60 >>>> perf_event_output_forward+0x7b/0x1b0 >>>> __perf_event_overflow+0x67/0x120 >>>> perf_swevent_overflow+0xcb/0x110 >>>> perf_swevent_event+0xb0/0xf0 >>>> perf_tp_event+0x292/0x410 >>>> perf_trace_run_bpf_submit+0x87/0xc0 >>>> perf_trace_lock_acquire+0x12b/0x170 >>>> lock_acquire+0x1bf/0x2e0 >>>> perf_output_begin+0x70/0x4b0 >>>> perf_log_throttle+0xe2/0x1a0 >>>> perf_event_nmi_handler+0x30/0x50 >>>> nmi_handle+0xba/0x2a0 >>>> default_do_nmi+0x45/0xf0 >>>> exc_nmi+0x155/0x170 >>>> end_repeat_nmi+0x16/0x55 >>> >>> kernel/events/Makefile has: >>> >>> ifdef CONFIG_FUNCTION_TRACER >>> CFLAGS_REMOVE_core.o = $(CC_FLAGS_FTRACE) >>> endif >>> >>> Which, afaict, should avoid the above, no? >> >> I'm afraid it's not working for this case, the >> start point of tracing is at lock_acquire() which >> is not from 'kernel/events/core', the following PF >> related function are also not from 'core', prevent >> ftrace on 'core' can't prevent this from happen... > > I'm confused tho; where does the #DF come from? Because taking a #PF > from NMI should be perfectly fine. > > AFAICT that callchain is something like: > > NMI > perf_event_nmi_handler() > (part of the chain is missing here) > perf_log_throttle() > perf_output_begin() /* events/ring_buffer.c */ > rcu_read_lock() > rcu_lock_acquire() > lock_acquire() > trace_lock_acquire() --> perf_trace_foo > > ... > perf_callchain() > perf_callchain_user() > #PF (fully expected during a userspace callchain) > (some stuff, until the first __fentry) > perf_trace_function_call > perf_trace_buf_alloc() > perf_swevent_get_recursion_context() > *BOOM* > > Now, supposedly we then take another #PF from get_recursion_context() or > something, but that doesn't make sense. That should just work... > > Can you figure out what's going wrong there? going with the RIP, this > almost looks like 'swhash->recursion' goes splat, but again that makes > no sense, that's a per-cpu variable. That's true, I actually have tried several approach to avoid the issue, but it trigger panic as long as we access 'swhash->recursion', the array should be accessible but somehow broken, that's why I consider this a suspected stack overflow, since nmi repeated and trace seems very long, but just a suspect... Regards, Michael Wang >