Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp4125413pxb; Mon, 30 Aug 2021 19:59:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykpIkWQ01Yux/zMBIpRLtUXnQTvIRDsjqEL3dBJx1dzPe3ttOGhQY7kDfRkDsQeD5FWTgM X-Received: by 2002:a92:6a0d:: with SMTP id f13mr19767617ilc.212.1630378746655; Mon, 30 Aug 2021 19:59:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630378746; cv=none; d=google.com; s=arc-20160816; b=VctkP+TdfthU6sFQK1/XyyFTqcaXvRbP7HcgTf/Q7XqSmhhdi9MjH3CtESfWUAhE95 r7yE9U3VrHej3MB9wJnKMOLq9XO1N9eSEW4nm5EmEjYeE+DP1TBU7Bi2WWdt5n63SrGT FkjPMLBkI8x/8xOVEq9VGJ7nvlNjvoSn75nbES0T7FnyeUcD20JH3BhTF2hEsiHoK+8I nD8OAjzD2e+0EkLS8zqh+a+ZARyn3JmUcY3ax9z4EJaOzkVyxovw40BshhBROYhDX23P EDz2ddpCf0OxTS+pEVvTfXLniLoHFN8Sr8ULBcpF3GRa46Q00RXP3msKqt5PmUCujPJF +d6w== 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:date:dkim-signature; bh=AvjxB8xiv6vhyzTLX37XxNMhEu4AOfVYHWUw1RynGTs=; b=un54tw+evgY5lgpyijEcoLPAu6pGXHkEOjJfMla0/QLU39LZT4KhLyRnAFVwMFGk8W W4jfnC7bN7JW3Tu1KW8yFAN4HvYIXZ9h+pKlUgWR8mnQ+K2hSIuAwtwD14VEWoJ2o44g wPv7f/1qZF2COMB6aUNjryv2zAGxJ5+fmfRURAp4JX+Yr0/ieGm+kkDNMn5Dz7SYDjdv 3v3dqdI0biPC2cX244cQACGdKlADnlSBPCi1Fa2o+VMm+JaRbSW35BYuD+UDDOqmtJkF WB/FVUPM6YS4P1RXWTvKU8eRP4tyh62FIS3boXGeZZQekLJOxNxdA2E/RkwSnVPbG9kk Bjcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=LcDbfg8h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c18si19202949iod.38.2021.08.30.19.58.54; Mon, 30 Aug 2021 19:59:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=LcDbfg8h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239432AbhHaC4D (ORCPT + 99 others); Mon, 30 Aug 2021 22:56:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229514AbhHaC4D (ORCPT ); Mon, 30 Aug 2021 22:56:03 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA35CC061575 for ; Mon, 30 Aug 2021 19:55:08 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id u11-20020a17090adb4b00b00181668a56d6so1339899pjx.5 for ; Mon, 30 Aug 2021 19:55:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=AvjxB8xiv6vhyzTLX37XxNMhEu4AOfVYHWUw1RynGTs=; b=LcDbfg8h77pj9HiMCk164bJNj2c128WiFloKTzvlCsfV9j35JoVoN6K4+MJMAuj6ep L7VXntyWCg5GreKw4W71GiQyJXs6pMl4sKgtcnm+iUKE2LyqBn637UCJ9Tpq+vBH5dH0 LDSvFiSgUA9AjbGMP83g5dzf2ai2Owxsw5uGM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=AvjxB8xiv6vhyzTLX37XxNMhEu4AOfVYHWUw1RynGTs=; b=dQvXi3xlqPXJX280ZUNrWFHMvyzYwVKzurmWNfOOsdGIZ8Jn3AEDQYak/LSGsxxOAr An2kCXNuHkoWeVb2/ORC692flEtZD+uc029U3dt10ErUq1tt4/rHfYLnaMk1XV1ktvvl fXe+NrXshlhHIKHp7HERA+QWI4kDRVDcf2xQrjL2VLaHxk8bXsQXrUFv+VWY8qeZRxgE Sxat/f0Ik4Bm/JZNCj3flIVbsgtZKh4iDqKBA4IXa0IJgcpNFBaEvxw9x0VyxUlftfgO muNzz87SKRRin6kXfE9DHv5ZM26x3IvrxPQdgeeSivnWNZuGtxJEDdZwQxN/mWrZoQhU OKKg== X-Gm-Message-State: AOAM530TfbUSoyc6zFAo7r70cBvpnxnOkf4HynUC4xEY1ZcCo/e6PZlD PLeSqv7Qz0KbAostrUmJJ7m+6w== X-Received: by 2002:a17:902:a406:b029:12b:c50a:4289 with SMTP id p6-20020a170902a406b029012bc50a4289mr2499299plq.56.1630378508430; Mon, 30 Aug 2021 19:55:08 -0700 (PDT) Received: from google.com ([2409:10:2e40:5100:6d52:87b8:b55b:8800]) by smtp.gmail.com with ESMTPSA id j9sm18869509pgl.1.2021.08.30.19.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Aug 2021 19:55:08 -0700 (PDT) Date: Tue, 31 Aug 2021 11:55:01 +0900 From: Sergey Senozhatsky To: John Ogness Cc: Petr Mladek , Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Andrew Morton , Masahiro Yamada , Peter Zijlstra , Nick Desaulniers , Andy Shevchenko , "Paul E. McKenney" , Tetsuo Handa , Vitor Massaru Iha , Sedat Dilek , Changbin Du Subject: Re: [PATCH printk v1 07/10] console: add write_atomic interface Message-ID: References: <20210803131301.5588-1-john.ogness@linutronix.de> <20210803131301.5588-8-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210803131301.5588-8-john.ogness@linutronix.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On (21/08/03 15:18), John Ogness wrote: [..] > @@ -1993,6 +1993,16 @@ static int console_trylock_spinning(void) > bool spin = false; > unsigned long flags; > > +#ifdef CONFIG_SMP > + /* > + * CPUs holding the printk cpulock must not spin on any lock. Even > + * console_trylock() must not be called because its implementation > + * uses spinlocks. > + */ > + if (atomic_read(&printk_cpulock_owner) == smp_processor_id()) > + return 0; > +#endif > + > if (console_trylock()) > return 1; > > @@ -2719,7 +2729,17 @@ static int have_callable_console(void) > */ > static inline int can_use_console(void) > { > - return cpu_online(raw_smp_processor_id()) || have_callable_console(); > + int cpu = raw_smp_processor_id(); > +#ifdef CONFIG_SMP > + /* > + * CPUs holding the printk cpulock must not spin on any lock. > + * Allowing console usage could call into the spinlocks of the > + * various console drivers. > + */ > + if (atomic_read(&printk_cpulock_owner) == cpu) > + return 0; I guess the only reason this is done in can_use_console() is console_flush_on_panic()? Because otherwise, I think, we can move this check to vprintk_emit(). can_use_console() can be called from preemptible() context. But if it's called from preemptible() then we know that this is not printk()/NMI path (but console_device() and friends instead) and that this CPU is definitely not holding printk CPU lock. console_trylock_spinning() and console_unlock()->can_use_console() follow each other if (console_trylock_spinning()) console_unlock(); so a single `atomic_read(&printk_cpulock_owner) == cpu` can suffice. Now we get to the console_flush_on_panic(), which still calls console_unlock(), iterates over messages, but when called by the CPU that owns printk_lock, just skips all the messages. But there is no point in calling console_unlock() in such a case, we can check if we're printk_cpulock_owner and bail out if so. Or am I missing something?