Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp743061yba; Thu, 9 May 2019 05:22:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqyUFMuCqE4pjrzmWnzJLfHOctzUJpe8p34PKP6qLHDskIoW6b3LfQVzLxqUdpOA26qMnXKF X-Received: by 2002:a17:902:e583:: with SMTP id cl3mr4645880plb.35.1557404555676; Thu, 09 May 2019 05:22:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557404555; cv=none; d=google.com; s=arc-20160816; b=sLhRCEjx7qt1Kpuw8DBMQvQOrKkzenzTlF/bz0lRq7Wp9jltT+afdeKOv+u9wVVyTc ecJs0L+Uvz9mhFgw9t4vDuMsR9s6PhLiNHoq4Yoy4GwHmwkxCTWgJJ7qVjqIS9eYagir fpwPBnorcCTgrxNlbU0GMUYKJ5q4/SeDTVWlPIaZfIMXmVHqFHoCuLRqPJbs5wUrwtu9 urAF4v5igEjWe9Gc0Wl2JHslH2pviC49aElh10OFY3SPD+YVwS3J3hOQYL/3drKH4Lbx i8tvCPs5JvAbU0CPTaOUaAPjVQkdqk8XKq5gHMchbMYn9TLpfkupBG5b+MkssZ/NvFQn nbUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:subject:user-agent:message-id :references:cc:in-reply-to:from:to:content-transfer-encoding :mime-version; bh=ANdPTBGMve87ihwV3o6dqSV3N2/z7h2on16PijjiDNY=; b=MXVtCxG4nGx8rwJMWrq/+SQd6dIaBJTHPptZeMpsEnJ/hAMNLxUzF2u1Dq/htqJIDM t622U8byZ+RKDMTLuVQuGm+Hz/awOcGG+HzXL3Mm2uFiDHfgy6CvADTzrp8YQcbGJGaH s8nzN13ZkhXpTM7nShxGtQscaLcciTO4X19mhCJXV84kCboV0s0PVbbpERe7N65oUD/z ggmo1OaJuEQj9UW4JpaunVmsJAhUQssqmvutsEyqHdqrFGQJinGZ/KwmrW1ADMt2g+p6 Oe1JlR1TZcfubi8mir2o5GFHj2RTm8K6512qcNXSAFI0PNJN5uX2hpzgfz9+UQbs0t1N OFSw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3si1872575plz.94.2019.05.09.05.22.18; Thu, 09 May 2019 05:22:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726674AbfEIMV2 convert rfc822-to-8bit (ORCPT + 99 others); Thu, 9 May 2019 08:21:28 -0400 Received: from mail.fireflyinternet.com ([109.228.58.192]:51566 "EHLO fireflyinternet.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726448AbfEIMV1 (ORCPT ); Thu, 9 May 2019 08:21:27 -0400 X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from localhost (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP (TLS) id 16502409-1500050 for multiple; Thu, 09 May 2019 13:21:24 +0100 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT To: Daniel Vetter , Intel Graphics Development From: Chris Wilson In-Reply-To: <20190509120903.28939-1-daniel.vetter@ffwll.ch> Cc: DRI Development , Daniel Vetter , Daniel Vetter , Peter Zijlstra , Ingo Molnar , Will Deacon , Petr Mladek , Sergey Senozhatsky , Steven Rostedt , John Ogness , linux-kernel@vger.kernel.org References: <20190509120903.28939-1-daniel.vetter@ffwll.ch> Message-ID: <155740448210.28545.914918106077410179@skylake-alporthouse-com> User-Agent: alot/0.6 Subject: Re: [PATCH] RFC: console: hack up console_lock more v3 Date: Thu, 09 May 2019 13:21:22 +0100 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Daniel Vetter (2019-05-09 13:09:03) > console_trylock, called from within printk, can be called from pretty > much anywhere. Including try_to_wake_up. Note that this isn't common, > usually the box is in pretty bad shape at that point already. But it > really doesn't help when then lockdep jumps in and spams the logs, > potentially obscuring the real backtrace we're really interested in. > One case I've seen (slightly simplified backtrace): > > Call Trace: > > console_trylock+0xe/0x60 > vprintk_emit+0xf1/0x320 > printk+0x4d/0x69 > __warn_printk+0x46/0x90 > native_smp_send_reschedule+0x2f/0x40 > check_preempt_curr+0x81/0xa0 > ttwu_do_wakeup+0x14/0x220 > try_to_wake_up+0x218/0x5f0 > pollwake+0x6f/0x90 > credit_entropy_bits+0x204/0x310 > add_interrupt_randomness+0x18f/0x210 > handle_irq+0x67/0x160 > do_IRQ+0x5e/0x130 > common_interrupt+0xf/0xf > > > This alone isn't a problem, but the spinlock in the semaphore is also > still held while waking up waiters (up() -> __up() -> try_to_wake_up() > callchain), which then closes the runqueue vs. semaphore.lock loop, > and upsets lockdep, which issues a circular locking splat to dmesg. > Worse it upsets developers, since we don't want to spam dmesg with > clutter when the machine is dying already. > > Fix this by creating a prinkt_safe_up() which calls wake_up_process > outside of the spinlock. This isn't correct in full generality, but > good enough for console_lock: > > - console_lock doesn't use interruptible or killable or timeout down() > calls, hence an up() is the only thing that can wake up a process. > Hence the process can't get woken and killed and reaped while we try > to wake it up too. > > - semaphore.c always updates the waiter list while under the spinlock, > so there's no other races. Specifically another process that races > with a quick console_lock/unlock while we've dropped the spinlock > already won't see our own waiter. > > Note that we only have to break the recursion for the semaphore.lock > spinlock of the console_lock. Recursion within various scheduler > related locks is already prevented by the printk_safe_enter/exit pair > in __up_console_sem(). > > Also cc'ing John Ogness since perhaps his printk rework fixes this all > properly. > > v2: Ditch attempt to fix console_trylock. > > v3: Add a comment explaining why the taks we're waking won't > disappear (Chris), and improve commit message to address review > questions. > > Signed-off-by: Daniel Vetter > Cc: Peter Zijlstra > Cc: Ingo Molnar > Cc: Will Deacon > Cc: Petr Mladek > Cc: Sergey Senozhatsky > Cc: Steven Rostedt > Cc: Daniel Vetter > Cc: John Ogness > Cc: Chris Wilson > Cc: linux-kernel@vger.kernel.org > Signed-off-by: Daniel Vetter I'm a bit nervous about that this is only safe for the precisely controlled conditions, but then again that it is called printk_safe should deter any other users. The logic checks out, and you convinced me that the dereference is protected, so Reviewed-by: Chris Wilson -Chris