Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp726577rwl; Wed, 29 Mar 2023 07:43:27 -0700 (PDT) X-Google-Smtp-Source: AK7set9sSh8j/2V7NafEcPaueasAAcB7Vly7pMobHs2M/2otgAbp9I9r5w538s0l9BqtUEYY9Spy X-Received: by 2002:a05:6a20:7a9a:b0:db:314d:c19a with SMTP id u26-20020a056a207a9a00b000db314dc19amr16645932pzh.50.1680101007459; Wed, 29 Mar 2023 07:43:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680101007; cv=none; d=google.com; s=arc-20160816; b=pJU7pIGdAePBZJ4m/UXXs3WTVH6CtPv3Y7WUv3c3A1VKKx82PTa/QK+EjvhumUUUm8 5nziB44M7IfMYlPLDa5oDQlZoXcTO0sy/pTX79rrtJNKVApA/H6fD0FxfTenhph8FcJi XW7zrt2mLNuwv6a7jnGbdDMu9RnRxycUgZgUjGNc8ChhIufq3AzYt12Wp54gKo/LRf+e Aavcqeg0ebLXwkweind5BCzckGDjoxkuCPepChDKcb1J713yFduvwRbHcWNXjSCceq1s uiwn5afBnxY5Tod+StS8lMi2KsSbZ5EmaOJwFP39AArdF3xeOQmoa5oyIorfrtm1T0mP YWoQ== 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=i8HCoWe26WB6mYdY1Qj5FxD340fO9b4OxYYITS6CTEU=; b=I8kV066PU4ilFN5Ssqdv9J/sdb2abDSnby+7lgHF2cya+4k/UOuSrKQlJhDqrQLtz9 V9cdFG1o2Xz+bQYat0BO0uP6o3l5SB7FVVx2A+O3ahjtbdwnpvPV73ZFFzf2HnBDmsU9 hKezag02LrG1oas5xjT2RBAkH7j6H0sNnagx25qNNMg0d/3zDlWlS4SK0q1YdkL9d6MU /oswfFY+gJuoYcfTRMlchxJDLSjrKbR80wzeHrj0Btnfu+Ol9M6wwp+ql2veHFs1oq6W fyYb2qYM+ELnBaoNylhZ73LQRFPni3+nWuhZmYQnGnmwyr7d8I5NIaQmmwEfELIaLVhS NyQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=h+OmzYbx; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=5YCU47N9; 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 j14-20020a056a00234e00b00622b9204356si31974172pfj.204.2023.03.29.07.43.15; Wed, 29 Mar 2023 07:43:27 -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=h+OmzYbx; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=5YCU47N9; 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 S230233AbjC2OjN (ORCPT + 99 others); Wed, 29 Mar 2023 10:39:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229942AbjC2Oi7 (ORCPT ); Wed, 29 Mar 2023 10:38:59 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8079AF0A for ; Wed, 29 Mar 2023 07:35:38 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1680100535; 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=i8HCoWe26WB6mYdY1Qj5FxD340fO9b4OxYYITS6CTEU=; b=h+OmzYbxL4GiZRmmHXw58FkZsn9ciSiEgMvKxCmb94YhWN2ftaTWv946prncpJcBkwBSNr kjIC7Kt8o/EjzSS85itVXvBMEszTvYO1sR+urk8knbLmlGf9lA2/x7D4VlpAHHNctLJ9PJ SbprbnTpEdf9W4a77pT93zK8YDO3f+z725a5s2mOpwrLF54OhdL5CvNr5M2LySOfETWZPr 9ure0+iS0ProDo8fIaUTrwMseuUJW8nP+hAoeIHWbJOM8wUtyheHScIXGpOVjy93cIReoc ake0AjHh+D+2rrEoU29vCRQG2ZsP9c5uI14ghvWtbmrZmIzh1c677NKYVGxuBA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1680100535; 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=i8HCoWe26WB6mYdY1Qj5FxD340fO9b4OxYYITS6CTEU=; b=5YCU47N9ZfouEO0MVDVgvYD0fx7wYKzk9kWmsBV/G+RmrqBCwqG7ftpo+jBPcMO0xr3cY1 /hxo+YMd4yndHiBg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: Re: buffer write race: Re: [PATCH printk v1 09/18] printk: nobkl: Add print state functions In-Reply-To: References: <20230302195618.156940-1-john.ogness@linutronix.de> <20230302195618.156940-10-john.ogness@linutronix.de> Date: Wed, 29 Mar 2023 16:39:54 +0206 Message-ID: <87edp7pqy5.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-1.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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-03-29, Petr Mladek wrote: >> +/** >> + * console_can_proceed - Check whether printing can proceed >> + * @wctxt: The write context that was handed to the write function >> + * >> + * Returns: True if the state is correct. False if a handover >> + * has been requested or if the console was taken >> + * over. >> + * >> + * Must be invoked after the record was dumped into the assigned record >> + * buffer > > The word "after" made me think about possible races when the record > buffer is being filled. The owner might loose the lock a hostile > way during this action. And we should prevent using the same buffer > when the other owner is still modifying the content. > > It should be safe when the same buffer might be used only by nested > contexts. It does not matter if the outer context finishes writing > later. The nested context should not need the buffer anymore. > > But a problem might happen when the same buffer is shared between > more non-nested contexts. One context might loose the lock a hostile way. > The other context might get the access after the hostile context > released the lock. Hostile takeovers _only occur during panic_. > NORMAL and PANIC contexts are safe. These priorities have only > one context and both have their own buffers. > > A problem might be with EMERGENCY contexts. Each CPU might have > its own EMERGENCY context. We might prevent this problem if > we do not allow to acquire the lock in EMERGENCY (and NORMAL) > context when panic() is running or after the first hostile > takeover. A hostile takeover means a CPU took ownership with PANIC priority. No CPU can steal ownership from the PANIC owner. Once the PANIC owner releases ownership, the panic message has been output to the atomic consoles. Do we really care what happens after that? John