Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1710221pxb; Mon, 13 Sep 2021 03:55:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxGL5jxhFdf4AWXWSN6yafjLe0sKbTIY7Ot3mjkJ/OenfgEE3XitytaLCXqlRthJmWm/zo X-Received: by 2002:a6b:3c16:: with SMTP id k22mr8497844iob.130.1631530506175; Mon, 13 Sep 2021 03:55:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631530506; cv=none; d=google.com; s=arc-20160816; b=0gbcB0tUkm2kSaFMrgKxm/BYnWsErUuOh4EO0YiPESTawOkKdVyxYB5uaVI8ppxHc+ 2Qpk62MYJCJxF6HxU8bP+12DTex4aCOrd85dwqP5ikXnpPcqb+Yd8mXC5rBhZ7NumER1 srzIzLFBHxQ/ED7rSCwPOQXEYR1FSCuPi/UsHO4v+WK7jEfC3ZbHFn8AnbH/+4X5vc1F 09Si8i/HNO1ITz7Xn+h8mOpPSfcbtTFKQmj2VoqyfWYrwv7mw6hkcUKjv8nLXZoi75Gv ppXPozHq78DzaEQCiEPwgeYQ1AXitmV7Oj/fA1MWozj2ZiCuSssrEvIMnn/oBWkkCB5I kgQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=aTrEWPTgm+dIL/hGTC+DhKVRcNbUKDY/ngJtAI2gUPw=; b=Zei+loXWVUlJcoXnYrq3bvKiw5CIe2cqIH9PvyIdR2EsBfKCiIxC24Y4H4apNiR/yP RIgQRUZTxy2CdA1VA3wX6J9WYaWf+EsUpDZhri/VzKPoVTnbvaJcht8VkYDBo4yjkqCP i/5B9D+OmDWsIzjdzJH4gHtWBS5jII0I9/1td/r4NnJIUg96TTba7isxX82xr3bNjB7h ar31wmt2fv7pOGLmnpOWHsNwd8VAbADA1E542935xqxyzlbY1VzAUX9pPWDWIeLgSbaA X88Ds3yBzgapkIlystm+fa88npTuOaHIfvo3kMzzUXFizcrt57Ddcmy+88V/u2ciGEL2 edfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=HLuLa0Js; 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 l15si7522226ios.94.2021.09.13.03.54.53; Mon, 13 Sep 2021 03:55:06 -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=@infradead.org header.s=desiato.20200630 header.b=HLuLa0Js; 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 S239078AbhIMK0C (ORCPT + 99 others); Mon, 13 Sep 2021 06:26:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239065AbhIMK0B (ORCPT ); Mon, 13 Sep 2021 06:26:01 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7277BC061574; Mon, 13 Sep 2021 03:24:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=aTrEWPTgm+dIL/hGTC+DhKVRcNbUKDY/ngJtAI2gUPw=; b=HLuLa0Js2fe4rdc8ZDDfvF3dq3 1VKI/tNmJlHv93Ku/PQwXaw/scNiXiGteqOOakxoEiSnqI507iMpxRkxPjmqmWNKynVHnJcQuNlTt qZgvtwSqjmHTYEin8jK1epP74aoQ4abDhWTBn7Jj3JHn9AnHNE5xGwv/7OI9rC02qUN8baaP5kl3W XbbaBsiRuTQbtbVaukpArL3JX5grPuFD2wWG2v2Q53cMjt/OfnZG+SQIbSsjGLaeAa8apMn5qgF+9 hYQpZ/0Y0uCBCkGgy4gOwAVjWueS2qCHbQKWOK3rSsFh/27VNf4O//wPN2uSLGu5DUHv8y23ZBV3y 3PPm7KsA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mPj8U-002nk6-08; Mon, 13 Sep 2021 10:24:26 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id BCE9E300047; Mon, 13 Sep 2021 12:24:24 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 9842E2098BD0E; Mon, 13 Sep 2021 12:24:24 +0200 (CEST) Date: Mon, 13 Sep 2021 12:24:24 +0200 From: Peter Zijlstra To: =?utf-8?B?546L6LSH?= 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)" Subject: Re: [RFC PATCH] perf: fix panic by mark recursion inside perf_log_throttle Message-ID: References: <20210910153839.GH4323@worktop.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.