Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp2384623pxb; Fri, 8 Oct 2021 06:47:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqsskyaT84FTyx7S81BMP0OgXlG5i1KkqV4wocPt6g79zutiJTlEzNa8+3B71SmORENwKO X-Received: by 2002:a17:90a:e453:: with SMTP id jp19mr12423470pjb.11.1633700868826; Fri, 08 Oct 2021 06:47:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633700868; cv=none; d=google.com; s=arc-20160816; b=Z2i7SJTMrYaeJf+UNVa9LHf8jztvoeH5f159peMRGj3xKrRLF+NZIhbufn0w7twiMc azqt2Mj33PcZq6nwYYUKC4x9zr0bd06I7E7+QjBPhaEoHaKtsG3sHBQri2vq8GSmXIa7 IrjEZ/oV3141IOvTf2y4a0C0puJpFjoPwzRj/n5se5ZohUJBUALa//Z5a6CuRcm6tg99 SUHN7YJQPgnvkpInmNO5YAggVwapq+RW94NMiVHzKYRgyINurNuZFyfZpWAXa7fbfgBM 7+Yd1XrHRsHVxeE+bvA5dxlVO2gUp6808f7YKSqEl39vO7iQfKADeYW46nguK8wfYZ23 Vp8w== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=AeZfY9f2iurPW1q+xtFtNI1W2I5709CG4W+EJzRCAMU=; b=z+/Cxo+/Usn8BPr2mbOps5vliBG7nfYXHeTR2AdVrjNVSHNdRZ2WpKbnsGUOeJEt+m xDCIE7wW+weX8g13bWwW7PfcC/e3pF3q3rGVvN2mqDpV+P7tVBRb+MeeZDg30lSAz//E JqhCErlgUZRvfJJ/e5Kk9oZYEfK/GROJmv+CYPeHyDH4AywSRI5ZLD9KbkEY1f1dcVdi 4BhMeeGdtP2hNcR+g6oJLfBUVQNi21zwxverhQ/wyJt7i3bfZ4SHG12vA54fNkv2j1p8 VRK72SlVoc2ynXuWPS8Vn5BwZr6nY1uMFvrPskVtsEIgjxLX5DRMEUxWwh8ZdPZlLMPa 8ndQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=VTz07ORt; 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 w15si3043339plk.330.2021.10.08.06.47.35; Fri, 08 Oct 2021 06:47:48 -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=casper.20170209 header.b=VTz07ORt; 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 S230390AbhJHNsg (ORCPT + 99 others); Fri, 8 Oct 2021 09:48:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231303AbhJHNsf (ORCPT ); Fri, 8 Oct 2021 09:48:35 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F76CC061570 for ; Fri, 8 Oct 2021 06:46:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=AeZfY9f2iurPW1q+xtFtNI1W2I5709CG4W+EJzRCAMU=; b=VTz07ORtCuf5oVvGPCxrXR3kYL hwmjJl9K29frRONPa/BsiWpyaMYGbCj8lGBNv9ysywf1ucX6SrVnNGhrFg5RgVyv/jjMXTLyyxyzZ kTkRxUFEC8uUfV6+Gf1mdGDbFyqtbcj5Ye3WQTSWYPtT3/KG75H2K1G1sWa4KD5dG75i/LmJn68A9 PVoR2JXECqp2Xs82wX3SO2vKHVGUJuXuQzLPhyHHKCT80ivuJ3ogjnSAE/Gk9ZwP/p0NzFK2uOzRv CZvdYdIu9dBjij2sqTcNQiv+vIexJ37P+rivNIgKccf58rTbEg8az7N4FTexM+Nonna16vd1ZYVto UOYsffRw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mYqCF-003Ene-QB; Fri, 08 Oct 2021 13:46:11 +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)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 9B20530077A; Fri, 8 Oct 2021 15:45:59 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 64C3A2007A037; Fri, 8 Oct 2021 15:45:59 +0200 (CEST) Date: Fri, 8 Oct 2021 15:45:59 +0200 From: Peter Zijlstra To: Mark Rutland Cc: keescook@chromium.org, jannh@google.com, linux-kernel@vger.kernel.org, vcaputo@pengaru.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, akpm@linux-foundation.org, christian.brauner@ubuntu.com, amistry@google.com, Kenta.Tada@sony.com, legion@kernel.org, michael.weiss@aisec.fraunhofer.de, mhocko@suse.com, deller@gmx.de, zhengqi.arch@bytedance.com, me@tobin.cc, tycho@tycho.pizza, tglx@linutronix.de, bp@alien8.de, hpa@zytor.com, axboe@kernel.dk, metze@samba.org, laijs@linux.alibaba.com, luto@kernel.org, dave.hansen@linux.intel.com, ebiederm@xmission.com, ohoono.kwon@samsung.com, kaleshsingh@google.com, yifeifz2@illinois.edu, jpoimboe@redhat.com, linux-hardening@vger.kernel.org, linux-arch@vger.kernel.org, vgupta@kernel.org, linux@armlinux.org.uk, will@kernel.org, guoren@kernel.org, bcain@codeaurora.org, monstr@monstr.eu, tsbogend@alpha.franken.de, nickhu@andestech.com, jonas@southpole.se, mpe@ellerman.id.au, paul.walmsley@sifive.com, hca@linux.ibm.com, ysato@users.sourceforge.jp, davem@davemloft.net, chris@zankel.net Subject: Re: [PATCH 6/7] arch: __get_wchan || STACKTRACE_SUPPORT Message-ID: References: <20211008111527.438276127@infradead.org> <20211008111626.392918519@infradead.org> <20211008124052.GA976@C02TD0UTHF1T.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211008124052.GA976@C02TD0UTHF1T.local> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 08, 2021 at 01:40:52PM +0100, Mark Rutland wrote: > [Adding Josh, since there might be a concern here from a livepatch pov] > > > +static unsigned long __get_wchan(struct task_struct *p) > > +{ > > + unsigned long entry = 0; > > + > > + stack_trace_save_tsk(p, &entry, 1, 0); > > This assumes stack_trace_save_tsk() will skip sched functions, but I > don't think that's ever been a requirement? It's certinaly not > documented anywhere that I could find, and arm64 doesn't do so today, > and this patch causes wchan to just log `__switch_to` for everything. Confused, arm64 has arch_stack_walk() and should thus use kernel/stacktrace.c's stack_trace_consume_entry_nosched. > I realise you "fix" that for some arches in the next patch, but it's not > clear to me that's the right thing to do -- I would expect that I only actually change the behaviour on csky, both mips and nds32 have this 'savesched = (task == current)' logic which ends up being a very confusing way to write things, but for wchan we never call on current, and hence don't save the __sched functions. > stack_trace_save_tsk() *shouldn't* skip anything unless we've explicitly > told it to via skipnr, because I'd expect that It's what most archs happen to do today and is what stack_trace_save_tsk() as implemented using arch_stack_walk() does. Which is I think the closest to canonical we have. > stack_trace_save_tsk_reliable() mustn't, in case we ever need to patch > anything in the scheduler (or arch ctxsw code) with a livepatch, or if > you ever *want* to have the sched functions in a trace. > > So I have two big questions: > > 1) Where precisely should stack_trace_save_tsk() and > stack_trace_save_tsk_reliable() start from? > > 1) What should you do when you *do* want sched functions in a trace? > > We could side-step the issue here by using arch_stack_walk(), which'd > make it easy to skip sched functions in the core code. arch_stack_walk() is the modern API and should be used going forward, and I've gone with the stack_trace_save*() implementation as per that.