Received: by 2002:a05:622a:251a:b0:39a:b4a2:e86 with SMTP id cm26csp527047qtb; Wed, 19 Oct 2022 08:08:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6H0xZ94Eph4uCIhz3F1zv9f0acWD4i2aBW6v+qqLlK08nyoGmDRI1L2g5RL/H57KJ2mJQg X-Received: by 2002:a17:907:2cf1:b0:78d:cafc:caba with SMTP id hz17-20020a1709072cf100b0078dcafccabamr7254730ejc.154.1666192122503; Wed, 19 Oct 2022 08:08:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666192122; cv=none; d=google.com; s=arc-20160816; b=NjEdE+euKncTBzC+7ctp54sa4su9oF1d4u7LdWA8TSk9IUoDNF4jS3+7d/UdMmPM9p IfJ00wqfy2Cr0De2KccK3jSNHWFnUTdq3fCC0VHeGz5WrgeAXJJAIq2oNQN89X3P+M1u XiMrlX9xBVaSHAj0iZrCehfBCiCZtCvVbyosRGWqm5fhf/e92piqTVZwrQgl0/aYCkXk mp1ac6yJt/mFhsFQ7IEes2vPlkvQmggk6zgfn7PqQRJIg3OXQH4ev1bGNnr0s6KOP1vO LwqnYWe+jOOwnu60k4sYJu8InK7GsZxg419+tCe3T/BT5uopkzl0GQo6rTWFUEpwMgup iy1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=hllJr9Cenmg6tA9bg55xooViBdr/MaRQODlzmP0LypQ=; b=K1fXp3hF+w2Cfa82JRuFWScSuzP4wkh4R6j6VKkxIcDPSP6fsgQHIj6dcrkq5T0hwg Xeu2HdhGCrW4pZEGJhsOUrfoGGMvl4XyyIG++Mg49OkdgJnPnFCk6nDWzyzgXPSnDVGx FbMekW4zSgH3tL6y/CXWPrNni1P1ggdQBkDSiveqNzGLGE46RNNeXZNmOObTV6MfxEZ7 6zOj2Ya8Auy7RKFdo7Ty37+FWQz+1r1kaqcQxCdzp1DAk+YHSOdBIuYaMY6SySIYVvpZ Rd7uLYUmHcKxZOcGXS09+TMTusNO3p8POZCV0ENmt2A4Nadd67+hYr0aZly+cn89RCqZ HRww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mMoqhcUJ; dkim=neutral (no key) header.i=@linutronix.de; 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 gn22-20020a1709070d1600b007429f0c69ccsi17545763ejc.579.2022.10.19.08.08.13; Wed, 19 Oct 2022 08:08:42 -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=mMoqhcUJ; dkim=neutral (no key) header.i=@linutronix.de; 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 S231629AbiJSPDm (ORCPT + 99 others); Wed, 19 Oct 2022 11:03:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbiJSPCt (ORCPT ); Wed, 19 Oct 2022 11:02:49 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E251D17A964 for ; Wed, 19 Oct 2022 07:57:33 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191364; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hllJr9Cenmg6tA9bg55xooViBdr/MaRQODlzmP0LypQ=; b=mMoqhcUJaer0GASfzyAekKN+pSE8kqodiNK415JtDTtl/yYfijstiMQVyIVGVhbYJ7jiZy cKhgwp014bcWywD++czA8VHdfLmMfNHfT9xWvGVzDl1BSXzuTXhemseXYlrav5AHS4+h3b iXhswrgzZMfsRkUXSMPESUzJ+rSu3M7/YNj7ejdSKY5Yxhtm11uOmEXTnfiTuvJDajS8Dt gDw+WexxNI1DOGL9NoyYoTDrKUOZT02uu7KgiIO9lSmuToUrf/p0DUJZYwHx1FxGqlsn5D beK0nlWDHvmI58Iw3MyOaR7HUyvDEIWWDiLi+pCNT0K6BiV6dSSjn9hd4gaF8A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191364; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hllJr9Cenmg6tA9bg55xooViBdr/MaRQODlzmP0LypQ=; b=anaafIfR//UTCpo9Mk4ATxTaSPAW/cLDpNejXqfvkq1eS4iO6NOae6e9TO/xryKwhc8urc BQG9YbEHS5/MnBBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v2 04/38] printk: introduce console_is_enabled() wrapper Date: Wed, 19 Oct 2022 17:01:26 +0206 Message-Id: <20221019145600.1282823-5-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 After switching to SRCU for console list iteration, some readers will begin accessing console->flags as a data race. This is safe because there is at most one CPU modifying console->flags and using rmw operations. The primary reason for readers to access console->flags is to check if the console is enabled. Introduce console_is_enabled() to mark such access as a data race. Signed-off-by: John Ogness --- include/linux/console.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/linux/console.h b/include/linux/console.h index cff86cc615f8..60195cd086dc 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -172,6 +172,26 @@ extern void console_srcu_read_unlock(int cookie); extern struct hlist_head console_list; +/** + * console_is_enabled - Check if the console is enabled + * @con: struct console pointer of console to check + * + * This should be used instead of manually testing for the CON_ENABLED + * bit in the console->flags. + * + * Context: Any context. + */ +static inline bool console_is_enabled(const struct console *con) +{ + /* + * If SRCU is used, reading of console->flags can be a data + * race. However, this is safe because there is at most one + * CPU modifying console->flags and it is using only + * read-modify-write operations to do so. + */ + return (data_race(READ_ONCE(con->flags)) & CON_ENABLED); +} + /** * for_each_console_srcu() - Iterator over registered consoles * @con: struct console pointer used as loop cursor -- 2.30.2