Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp84733rwb; Thu, 27 Jul 2023 09:40:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlELJLXPU/OFirpASOFc0wdkjUW8zi9tuVMHDiDZFxFw5xiyCbTSUkdJ47BcHmihoOeH2zJH X-Received: by 2002:a17:906:5a4a:b0:992:9d41:875b with SMTP id my10-20020a1709065a4a00b009929d41875bmr2317221ejc.32.1690476014853; Thu, 27 Jul 2023 09:40:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690476014; cv=none; d=google.com; s=arc-20160816; b=P8/+SVNgHYNAyNVybsv2xKnfN31Vqf0nACwjagYD3R3gtKJb3OcsW94nb3STBrmFOy JN1b/QQUJCGv4DqtXLr77qTWPPzAcxKP8M/zbcnVagbEhgPdC7jBIiuw4Dx5xkxLSM3A jE1jJHsppZAYaaPg0zQgCDXLfNKj9p3M5iGd/UNfyxE58hvmrfzUH1jdQXOQ08ZQ3h2+ rUaMGt+eOfydgNtrF9xYtbC2YYyUKJzBhkVOE2op+9xlpODVvQlKmO7L6DQJKK+K9ry8 qLTfrWbL9ABILgG3iEOROlG6tPd/7zZdoHbG3YnC6pGz43Z/2ON2q9WeECZ36fW6Xj1/ 4u1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature :dkim-signature:date; bh=JmZUY5HL7mxzNObUMoolfY4LWdTMi99W9UaFt95hWy0=; fh=ced17T6XrR0Qe/NQQ8TNcQUWNygkhUzVRnZWqmAjm2w=; b=ViIqlPcSLXnhpR+NDSkVmwXzg5XUhGYPr63UdfP8+Mjcewq4ws05sS8fYRG6eCkhky OfkC/iq3vew1tA2MMG2xCDmMx6yALhRQvaGZnE4vgjPpesUpycEcbm8bcx06vQ4BTh7r YDq10IvCkw3XSCaER9ZdBKrx3yunBGqgdWtO9G8JsE769OmGsejMNAAfGF5+G28b9fjb 8dfNrLW2SzZ5U+OujE7ow+vYr+XYIEJ/4HhZ7R8PXAq+LxPKq8Be1gjY6J2VBNCtW0te IS9YIC/QQXii/RAFDRhpcHzXIppGZHSoOcCf01QHH+859W1P8/l8/YfADvfU+gjBM/MG d6NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=pE+oxar1; dkim=neutral (no key) header.i=@linutronix.de header.b=4fLVNyMm; 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 p14-20020a1709061b4e00b00993166137f5si547724ejg.140.2023.07.27.09.39.50; Thu, 27 Jul 2023 09:40:14 -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=pE+oxar1; dkim=neutral (no key) header.i=@linutronix.de header.b=4fLVNyMm; 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 S234480AbjG0PKu (ORCPT + 99 others); Thu, 27 Jul 2023 11:10:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234481AbjG0PKo (ORCPT ); Thu, 27 Jul 2023 11:10:44 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB5E630EA for ; Thu, 27 Jul 2023 08:10:38 -0700 (PDT) Date: Thu, 27 Jul 2023 17:10:29 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690470636; 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=JmZUY5HL7mxzNObUMoolfY4LWdTMi99W9UaFt95hWy0=; b=pE+oxar15oNKB0QzXGcEcfcCK04CDhxmdAeQyEJP1CewY5ty+ViRtoMT6xbK7rmp1IoVvg RRSPLn/CXhWJb+kNiCQWV944mTvO7c5H28A/AJRUeB+Z4C/0yQ6dQd8MqdpDOIp09btLhc Ou6NF4uVBI6a+XiI8mGlAfN3hgAthyzETbHU79ZLWOgwRxJX+YTS3/YEfQjUTy4eRjWboq uqq1FDWTK2DMp8WXq1ploJbvv43mQFWiqdSVmwQZVr6Z8uQ96qvKfTR28tU6h7RVV/muPv 8hg34Ojr2Rt+3/SfrQCgmR5MNUCtXTX3d8BjYG0hqnnS1LW+zM0bnfPnHlNfYw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690470636; 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=JmZUY5HL7mxzNObUMoolfY4LWdTMi99W9UaFt95hWy0=; b=4fLVNyMmc+WQaVm3LN6OQZfOh2EoLerlauWoEk9JsijohOijLEVpDQ/IXFTXihIZ/gyk5I Pii9C6TPD1GRZdDA== From: Sebastian Andrzej Siewior To: Tetsuo Handa Cc: Petr Mladek , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Luis Claudio R. Goncalves" , Andrew Morton , Boqun Feng , Ingo Molnar , John Ogness , Mel Gorman , Michal Hocko , Peter Zijlstra , Thomas Gleixner , Waiman Long , Will Deacon Subject: Re: [PATCH v2 1/2] seqlock: Do the lockdep annotation before locking in do_write_seqcount_begin_nested() Message-ID: <20230727151029.e_M9bi8N@linutronix.de> References: <20230623171232.892937-1-bigeasy@linutronix.de> <20230623171232.892937-2-bigeasy@linutronix.de> <20230626081254.XmorFrhs@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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-06-28 21:14:16 [+0900], Tetsuo Handa wrote: > > Anyway, please do not do this change only because of printk(). > > IMHO, the current ordering is more logical and the printk() problem > > should be solved another way. > > Then, since [PATCH 1/2] cannot be applied, [PATCH 2/2] is automatically > rejected. My understanding is that this patch gets applied and your objection will be noted. > I found > > /* > * Locking a pcp requires a PCP lookup followed by a spinlock. To avoid > * a migration causing the wrong PCP to be locked and remote memory being > * potentially allocated, pin the task to the CPU for the lookup+lock. > * preempt_disable is used on !RT because it is faster than migrate_disable. > * migrate_disable is used on RT because otherwise RT spinlock usage is > * interfered with and a high priority task cannot preempt the allocator. > */ > #ifndef CONFIG_PREEMPT_RT > #define pcpu_task_pin() preempt_disable() > #define pcpu_task_unpin() preempt_enable() > #else > #define pcpu_task_pin() migrate_disable() > #define pcpu_task_unpin() migrate_enable() > #endif > > in mm/page_alloc.c . Thus, I think that calling migrate_disable() if CONFIG_PREEMPT_RT=y > and calling local_irq_save() if CONFIG_PREEMPT_RT=n (i.e. Alternative 3) will work. > > But thinking again, since CONFIG_PREEMPT_RT=y uses special printk() approach where messages > are printed from a dedicated kernel thread, do we need to call printk_deferred_enter() if > CONFIG_PREEMPT_RT=y ? That is, isn't the fix as straightforward as below? That below will cause a splat with CONFIG_PROVE_RAW_LOCK_NESTING. That is because seqlock_t::lock is acquired without disabling interrupts. Additionally it is a bad example because the seqcount API is bypassed due to printk's limitations and the problems, that are caused on PREEMPT_RT, are "ifdefed away". None of this is documented/ explained. Let me summarize your remaining problem: - With (and only with) CONFIG_PROVE_LOCKING there can be a printk splat caused by a lock validation error noticed by lockdep during write_sequnlock_irqrestore(). - This can deadlock if there is a printing output on the tty which is using the same console as printk and memory hotplug is active at the same time. That is because the tty layer acquires the same lock as printk's console during memory allocation (of the tty layer). Now: - before this deadlocks (with CONFIG_PROVE_LOCKING) chances are high that a splat is seen first. - printk is reworked and the printk output should either happen from a dedicated thread or directly via a different console driver which is not using uart_port::lock. Thus avoiding the deadlock. Sebastian