Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp582361rwr; Thu, 20 Apr 2023 03:46:15 -0700 (PDT) X-Google-Smtp-Source: AKy350b8WTHXCcJNpV5kXJN6ym+HLtLx2ZXXH4zKblvPKz5NdGi2UILqronN4j5PjpiHH6j+4VVv X-Received: by 2002:a05:6a20:748b:b0:f0:ac6a:a3bb with SMTP id p11-20020a056a20748b00b000f0ac6aa3bbmr2112454pzd.32.1681987575080; Thu, 20 Apr 2023 03:46:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681987575; cv=none; d=google.com; s=arc-20160816; b=ll0pTLEew0HohHX5LDYI1pmjSP7SMperA/LVVFmPsIFQtUGZADhWViTHuv6vxH7aDS Enb/EobOZez2m0U7uIS14qMeqAyMbdkFXnLf6vISiszgisHFSXR0c9vJiihOuSHhHXHT 3Cit2SZ/KTYK/9PFYWvqfUrgoXGKLSXPWmp3awjtOA/9uZ2nmRBp6zGuL11hHfHN9LFX 9IovP8VPk8aTBT9IskyWLsyw6aCa9CGfh9d5jXySo1xBojahCzAiA4LjZjxPnKOCqc/8 kyUlS3qCO171Uu/qsO5P+w8uRBwGicaCKIlyy/ZA0XeZIW8+UYvSujAPJhAgmn7wgg1P ezew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=I1WwqJbjdqbVTI8TYWB0whF/15cU3RjutF8ccNUpsmg=; b=pXN/Xjnn6MSlRBpMpBXvStyU/bP68MSQaJxItLoFHzWiFbAZfsiOKBPkalMY2mIVU4 jnJ/02tTinwgnz/XFbWI3EUWr/diOxKyrQHRGB/7bVvZ5nzzH6UuYTpW3DdDNpsZ0odC vV4PnO/7hacgWV4Q09vwicNSF7AdW98Bn28S+tWg0gquFmxboKAfr4yCuDYnNKV8XP+E 6kwrANz65txfQktQvDqwfU4Xyb5IO6zk9hGrnOPdprgJPNDXaL7YR3EqniT/Q40bknvp CH5z0lOZ09o0NkYgYF0BVUfenU5slNXrnLIPX86DFtkK/NmctfrE4UHlYdTWDZoOrfbs Hl3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=pSxQZAqn; dkim=neutral (no key) header.i=@linutronix.de header.b="r/Xalzos"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g193-20020a636bca000000b005134680e477si1457098pgc.499.2023.04.20.03.45.57; Thu, 20 Apr 2023 03:46:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=pSxQZAqn; dkim=neutral (no key) header.i=@linutronix.de header.b="r/Xalzos"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234932AbjDTKih (ORCPT + 99 others); Thu, 20 Apr 2023 06:38:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234937AbjDTKiO (ORCPT ); Thu, 20 Apr 2023 06:38:14 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA8F14C08 for ; Thu, 20 Apr 2023 03:35:33 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1681986931; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=I1WwqJbjdqbVTI8TYWB0whF/15cU3RjutF8ccNUpsmg=; b=pSxQZAqnSvsSgu+wbVW0ZoGHxgE0aUCza+aRw+bvqvk9oHwn4mqoDwGVj1LZAB7dpzMTHz bB52ANyQ8VvRmUvaQs36/tUg7lKToAX3qbxvxICNiSB77tZIJEqMg1lGHSXspTqhZdW5nN 90pApwix/qUupUwDxa3WYbqNwhFwjqZFfdceUjqC5Pi7ZskWtP9cdBEkCp4dhDdcTxN0/r P88DcdYRxyBqd9yri977YNFONa/4iOMk47cyawXGdU+ht3N8EWF0Kw2nVrvT4DHZrYPSHq /3nlJDP+9F8xGTvBO8y67EzMgvcuqEAbVLZ06uNZycPcrD4PyjR5JwPClulahg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1681986931; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=I1WwqJbjdqbVTI8TYWB0whF/15cU3RjutF8ccNUpsmg=; b=r/Xalzos+G1Ip59iGysXHnsyWVtkesjJFsFVC7yUbtZAl9aOwRLm3QvrY58tq3pcB6i324 IX3JqTqmbSusjbAQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: Re: port lock: was: Re: [PATCH printk v1 11/18] printk: nobkl: Introduce printer threads In-Reply-To: References: <20230302195618.156940-1-john.ogness@linutronix.de> <20230302195618.156940-12-john.ogness@linutronix.de> Date: Thu, 20 Apr 2023 12:39:31 +0206 Message-ID: <87zg72vo5g.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023-04-20, Petr Mladek wrote: >> OK, let's first define what the two locks are supposed to synchronize. >> My understanding is that this patchset uses them the following way: >> >> + The new lock (atomic_state) is used to serialize emiting >> messages between different write contexts. It replaces >> the functionality of console_lock. It replaces the functionality of console_lock, but operates at a finer level. It is serializing all access to the hardware registers involved in outputting. For the 8250 driver, this is the IER register. >> It is a per-console sleeping lock, allows voluntary and has >> hand-over using priorities and spinning with a timeout. It is not a sleeping lock. It is used as a trylock or spinning with timeout. It has the special feature that it can be handed over to or stolen by another context with a higher ownership priority. >> + The port_lock is used to synchronize various operations >> of the console driver/device, like probe, init, exit, >> configuration update. >> >> It is typically a per-console driver/device spin lock. >> >> >> I guess that we would want to keep both locks: I agree because the port_lock has a much larger scope and is fully preemptible under PREEMPT_RT. > I forgot to check how these two locks are supposed to be used > in write_atomic(). > > It seems that cons_atomic_flush_con() takes only the new lock > (atomic_state) and ignores the port_lock(). It should be safe > against write_kthread(). But it is not safe against other > operations with the console device that are synchronized > only by the port_lock(). Yes, it is because the console drivers will also take the atomic_state lock when needed. You can see this in the POC patch I posted [0]. For example, a new function serial8250_enter_unsafe() is used by the serial drivers to mark the beginning of an unsafe section. To use this function, the port_lock must be held. This function additionally takes the atomic_state lock. Then the driver is allowed to touch hardware registers related to outputting (IER). But typically the driver will use a new higher level function, for example serial8250_in_IER(), which will enter unsafe, read the register, and exit unsafe. This provides the necessary synchronization against write_atomic() (for the 8250 driver). Please also remember that hostile takeovers of drivers in unsafe sections are done as a last resort in panic, after all other nbcon consoles have safely flushed their buffers. So we should not spend too many brain cycles on "what if the atomic_state lock is stolen while in an unsafe section" questions. The answer is: then you are in "hope and pray" mode. John [0] https://lore.kernel.org/lkml/877cv1geo4.fsf@jogness.linutronix.de