From patchwork Wed Sep 20 12:51:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Mladek X-Patchwork-Id: 142600 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp4420828vqi; Wed, 20 Sep 2023 13:58:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFdZgq6SZbTT2zLYLsXNctxDKQgo3ZBCEd1bEd5Axz1PuakWTNEVrEeyJE1DCFE9j98/whu X-Received: by 2002:a05:6a20:1608:b0:130:7ef2:ff21 with SMTP id l8-20020a056a20160800b001307ef2ff21mr8733283pzj.19.1695243532581; Wed, 20 Sep 2023 13:58:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695243532; cv=none; d=google.com; s=arc-20160816; b=iQhaGQZIyS1WcMJ8O4IxL6WylZKhCFO720Z93NvduBd3wWJJMvubL9KS1tySwVj1+Y Yp8YDIXO4mwyf9ETLTM8JB1XG7cjilucCH4T13pF9VA9ZQgD//0ClSaLxmrBDNDMFxrv ptFN+/4QUdszUm2G+lPv62U92E3VJnDbTlTUQvg9dUPSQ0+Yf6nt/LQdZtSpiwll6VYX h1ozYHkOyID9K+2ggwX1r6TutVlMoCCIzSG0KEg8Mtwp0oWJHBxvK7CAPEjEYkWfswLb ASYFUsrQepk1i1zC5SBl20XJ4cp1Biy8olMEUvQXUBIrjlbG3qdQmiumRVAEr5/1Ksar wyHg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=07u4Q5pAxOrutNCPHuGqm79fyJmvNY+HPmPgd0ex2so=; fh=MKXUfOjajqMxXqezc8Hjo+ZKx6BkQrUgbM0sGvVFEWA=; b=Ksf9GNZ0xsU2YynU3QybkTMYL/jEDbCPb79O8YzrVg35N+oe3MWa7h14W5/kPzQafQ 46sKhV6LEdS1FrwPVxNyU8Fyy7aKy7l6udySp8sLC8gwcewuCzeM/4nyJKQFDkPfYoBw KvFwIulPuJBb5thraCG7oyTkyN8gUZeHUh1D9i19L0dUh37UsRwnO4dH8F+ESNyd+edX Lszyysq8OkGW0Xil5sGrE3fjn/Gy6CT1/8G2nh9tn39m8R9LM8xRgtlpc/ka8Gyn/Viv lzhIwgVNNUQX69QZiy4OeRXGTYfqlBRo9f+KZjQ6VSSxvx1FBzgC2caskZCc9ku5L7Ig pFlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=FcDpi5m2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id r22-20020a638f56000000b005648d3f2031si12259459pgn.362.2023.09.20.13.58.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 13:58:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=FcDpi5m2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 60F2880BEB1E; Wed, 20 Sep 2023 05:51:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235679AbjITMvy (ORCPT + 26 others); Wed, 20 Sep 2023 08:51:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235056AbjITMvx (ORCPT ); Wed, 20 Sep 2023 08:51:53 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8131583 for ; Wed, 20 Sep 2023 05:51:47 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 427AC21BE1; Wed, 20 Sep 2023 12:51:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1695214306; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=07u4Q5pAxOrutNCPHuGqm79fyJmvNY+HPmPgd0ex2so=; b=FcDpi5m25Ust/F5P9vXeaMt5gXDitqy8owCtcQNUn3gM3H9+LJupun+aE3xkvm4IXdxEh9 cO064jkZaj6HUD2gaCckqXXLDAOLhZAGU2V7J7UfSvl3CNAwtt6iZIyWdQu3eTciynPnBH pMTa6PXNvseArhOrg3ayw1eqIIiC5I8= Received: from alley.suse.cz (pmladek.tcp.ovpn2.prg.suse.de [10.100.208.146]) by relay2.suse.de (Postfix) with ESMTP id 95AFB2C142; Wed, 20 Sep 2023 12:51:45 +0000 (UTC) From: Petr Mladek To: John Ogness , Sergey Senozhatsky , Steven Rostedt Cc: Thomas Gleixner , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH] printk/nbcon: Add assert that CPU migration is disabled when calling nbcon_context_try_acquire() Date: Wed, 20 Sep 2023 14:51:36 +0200 Message-Id: <20230920125136.15504-1-pmladek@suse.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, 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 agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 20 Sep 2023 05:51:56 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777573358517477212 X-GMAIL-MSGID: 1777591682122066089 The nbcon console is locked when the 'prio' and 'cpu' fields in console->nbcon_state stay the same. The locking algorithm would break when the locked context got migrated to another CPU. Add assert into nbcon_context_try_acquire(). It would warn when the function is called in a context where the CPU migration is possible. Signed-off-by: Petr Mladek --- I propose this patch on top of the patchset adding basic support for nbcon consoles, see https://lore.kernel.org/r/20230916192007.608398-1-john.ogness@linutronix.de Or another way, it is on top of rework/nbcon-base branch in printk/linux.git tree. --- kernel/printk/nbcon.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index b96077152f49..2c2e98d61660 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -234,6 +234,19 @@ static void nbcon_seq_try_update(struct nbcon_context *ctxt, u64 new_seq) } } +#ifdef CONFIG_PROVE_LOCKING +static inline void nbcon_assert_cpu_migration_disabled(void) +{ + WARN_ON_ONCE(IS_ENABLED(CONFIG_SMP) && + __lockdep_enabled && + this_cpu_read(hardirqs_enabled) && + preempt_count() == 0 && + !current->migration_disabled); +} +#else +#define nbcon_assert_cpu_migration(void) {} +#endif + /** * nbcon_context_try_acquire_direct - Try to acquire directly * @ctxt: The context of the caller @@ -579,6 +592,8 @@ static bool nbcon_context_try_acquire(struct nbcon_context *ctxt) struct nbcon_state cur; int err; + nbcon_assert_cpu_migration_disabled(); + nbcon_state_read(con, &cur); try_again: err = nbcon_context_try_acquire_direct(ctxt, &cur);