Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp628761yba; Thu, 9 May 2019 03:35:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqwgxB5lQC3aOyt50AnmdCeeLcbySgau0++6y1Q4x6NcNmtZgXHX7lX1tI2PioGkkEM/IIn2 X-Received: by 2002:aa7:8212:: with SMTP id k18mr3863284pfi.50.1557398126395; Thu, 09 May 2019 03:35:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557398126; cv=none; d=google.com; s=arc-20160816; b=Xr3qrzhxJlw+0OFbQ9JBk+yEDSlK1PVhjDGrI3oIWXlC14XgNpfcha8UsCJWC8ALQo 85CElBxJldSdA38JqWvEMaLFoWdZUHMYl/Vfqld+JA2Lc15OTm4vpoOwKpXVAo2MAdmr l6iFgspu6eCevTXG+7w0txceUEuFC8FFus/YbdeLtSEeZ+Q+efzRXUUngLjj3r5kv6X5 xd7znxsrkR5d5C9WRnrUG4FZXuiJN7AYrz/kETlU16Np3xWvaxAPxZqei0Mrj7oCrkMk R2e5XL4gHgs+LPIngqfL+XM69oVtLiErOLOHQcsNHuY4zWjU+rxwO5e1H0RRA8+/28Hq 615Q== 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=oE9eCpy3F60D9DiRJkxpg5GRfRziteGWaCjBu7enldw=; b=ssUaO36eL65y/3Wbogoqv/4FUq14xk52etRnTt573eEFmS4q0TGBl995nPri0UXAfA 6+DM8/XvkdjLHyh+T9SxZ+TfZxwehA6fnqUOKRWujaBYaBdcjWR2MCZh2lorzcb75rzx TkaybG56uMGSJ3ZjVbGVP4NK0d4xcmx6USk3mt6cOeIX8sbY2P83KXCNFgA/0PDbefvZ Kbxu1+FF10rwqlAt98PYeyrcBtxPk2QoezO2TPATg5BM2QcMkOi+UTir4BxUhRTB4nhx 88Doqle2jr+JXGVUjldlmQrcGm2ehffJQHiOTcluoKLhUHlP7pFRmS2qkYv/+w0oi5QU M2vA== 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 cd3si2311868plb.98.2019.05.09.03.35.10; Thu, 09 May 2019 03:35:26 -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 S1726469AbfEIKeG convert rfc822-to-8bit (ORCPT + 99 others); Thu, 9 May 2019 06:34:06 -0400 Received: from mail.fireflyinternet.com ([109.228.58.192]:57786 "EHLO fireflyinternet.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726078AbfEIKeF (ORCPT ); Thu, 9 May 2019 06:34:05 -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 16500941-1500050 for multiple; Thu, 09 May 2019 11:33:00 +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: <20190506074553.21464-1-daniel.vetter@ffwll.ch> Cc: Petr Mladek , John Ogness , Peter Zijlstra , Daniel Vetter , Will Deacon , linux-kernel@vger.kernel.org, Steven Rostedt , Sergey Senozhatsky , Ingo Molnar , Daniel Vetter References: <20190502141643.21080-1-daniel.vetter@ffwll.ch> <20190506074553.21464-1-daniel.vetter@ffwll.ch> Message-ID: <155739797736.28545.2942646931608459049@skylake-alporthouse-com> User-Agent: alot/0.6 Subject: Re: [Intel-gfx] [PATCH] RFC: console: hack up console_lock more v2 Date: Thu, 09 May 2019 11:32:57 +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-06 08:45:53) > +/** > + * printk_safe_up - release the semaphore in console_unlock > + * @sem: the semaphore to release > + * > + * Release the semaphore. Unlike mutexes, up() may be called from any > + * context and even by tasks which have never called down(). > + * > + * NOTE: This is a special version of up() for console_unlock only. It is only > + * safe if there are no killable, interruptible or timing out down() calls. > + */ > +void printk_safe_up(struct semaphore *sem) > +{ > + unsigned long flags; > + struct semaphore_waiter *waiter = NULL; > + > + raw_spin_lock_irqsave(&sem->lock, flags); > + if (likely(list_empty(&sem->wait_list))) { > + sem->count++; > + } else { > + waiter = list_first_entry(&sem->wait_list, > + struct semaphore_waiter, list); > + list_del(&waiter->list); > + waiter->up = true; > + } > + raw_spin_unlock_irqrestore(&sem->lock, flags); > + > + if (waiter) > + wake_up_process(waiter->task); From comparing against __down_common() there's a risk here that as soon as waiter->up == true, the waiter may complete and make the onstack struct semaphore_waiter invalid. If you store waiter->task locally under the spinlock that problem is resolved. Then there is the issue of an unprotected dereference of the task in wake_up_process() -- I think you can wrap this function with rcu_read_lock() to keep that safe, and wake_up_process() should be a no-op if it races against process termination. -Chris