Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3773536pxb; Mon, 1 Feb 2021 04:30:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJyGDWXmE5micRnTDSizt71n0q1XkXeC4CkkLCJbXNkKNwnI5+PZjE5PRqLOVhMCfjQ26WqU X-Received: by 2002:a05:6402:942:: with SMTP id h2mr18633281edz.128.1612182626366; Mon, 01 Feb 2021 04:30:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612182626; cv=none; d=google.com; s=arc-20160816; b=aE8omy4XFdtAq0E8HCCeM4sGHjHgyZrh5IfJYat72v1H/LGI8yPc4fZLxL3uLfFWm8 j0VavxBsekKeuepxgDwjLWbRPUbEN5Turo1YbVbiOluWm/8YzNoUhQ1HSr7GPPtUaQPV drNWz2s5VoccREpSxGu6SkJeTxQN6aDhT0I1aT5MPSQUbQ9mFixTrgRlFysveaunWz6I QIKxosndUZnc3jx2w8pNdWU/QOwFOzQFtEL/DIffQ8HG+BdAno1HJWv0dUYfkA3rpugz xN86nyKmpfMIzjyT3cvvjsqMlAw3wWrN6ei/uQx66oPUtjX67FALjDEyf8tJ+hnaQUYn bn8g== 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=PE9JrNiPE/waS59o8i1v4gEWcbHimWae5gJXMMipSF4=; b=OmSCV5XYv8fz2cPoa1gg252urqtx1PGthBZObO2Yff1VPAijSAx7oly975J7cf/cgC hHSx+MLhfTD/ro/fY9kt5EDCv53wljC+Vx9JXt6M7AfDXt5N6N6I8h0YwMpz295uX/sm MiI51HDi5iHVehxnNWmxil6z9FATuDRE/ZMxwkSeoQHNdEt2fSqi7N/SqdWxtQlUfZQS GTexiHjpisjGtzVu7mqIPgiD4nRLOyopAnVOijrT/O1/b3O/FXLGh/GVWpSd6DJsWAKE yLXq22HYPKoP7VYoCvRwFk1u7dGjZioIMt5+ZTjaodNmSpN+LGy0L5M9v5Qy+39B7bvM YOng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b="b/z+QBJC"; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l2si11255964ede.232.2021.02.01.04.30.01; Mon, 01 Feb 2021 04:30:26 -0800 (PST) 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=@suse.com header.s=susede1 header.b="b/z+QBJC"; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229519AbhBAM1f (ORCPT + 99 others); Mon, 1 Feb 2021 07:27:35 -0500 Received: from mx2.suse.de ([195.135.220.15]:54354 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229545AbhBAM10 (ORCPT ); Mon, 1 Feb 2021 07:27:26 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1612182398; h=from:from:reply-to: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=PE9JrNiPE/waS59o8i1v4gEWcbHimWae5gJXMMipSF4=; b=b/z+QBJCHLvZ4MqEWcNfsnAUF2y+/fbIoxnYxOPxMr/8kxauEB51km9hFs5NWqWNg6bZAG GRlMgTdV2yOMh93axDQfX0THW27184QFNHY0j8s3jg78lU13WOVHGBvymgh79G8OSAbiBg yOzdvMXsZJrVmiZtaujLZCxSkIx5zw0= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id AB3E7AC45; Mon, 1 Feb 2021 12:26:38 +0000 (UTC) Date: Mon, 1 Feb 2021 13:26:38 +0100 From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: Re: [PATCH printk-rework 07/12] printk: add syslog_lock Message-ID: References: <20210126211551.26536-1-john.ogness@linutronix.de> <20210126211551.26536-8-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210126211551.26536-8-john.ogness@linutronix.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 2021-01-26 22:21:46, John Ogness wrote: > The global variables @syslog_seq, @syslog_partial, @syslog_time > and write access to @clear_seq are protected by @logbuf_lock. > Once @logbuf_lock is removed, these variables will need their > own synchronization method. Introduce @syslog_lock for this > purpose. > --- a/kernel/printk/printk.c > +++ b/kernel/printk/printk.c > @@ -390,8 +390,12 @@ DEFINE_RAW_SPINLOCK(logbuf_lock); > printk_safe_exit_irqrestore(flags); \ > } while (0) > > +/* syslog_lock protects syslog_* variables and write access to clear_seq. */ > +static DEFINE_RAW_SPINLOCK(syslog_lock); I am not expert on RT code but I think that it prefers the generic spinlocks. syslog_lock seems to be used in a normal context. IMHO, it does not need to be a raw spinlock. Note that using normal spinlock would require switching the locking order. logbuf_lock is a raw lock. Normal spinlock must not be taken under a raw spinlock. Or we could switch syslog_lock to the normal spinlock later after logbuf_lock is removed. > + > #ifdef CONFIG_PRINTK > DECLARE_WAIT_QUEUE_HEAD(log_wait); > +/* All 3 protected by @syslog_lock. */ > /* the next printk record to read by syslog(READ) or /proc/kmsg */ > static u64 syslog_seq; > static size_t syslog_partial; > @@ -1631,6 +1643,7 @@ int do_syslog(int type, char __user *buf, int len, int source) > bool clear = false; > static int saved_console_loglevel = LOGLEVEL_DEFAULT; > int error; > + u64 seq; This allows to remove definition of the same temporary variable for case SYSLOG_ACTION_SIZE_UNREAD. > > error = check_syslog_permissions(type, source); > if (error) > @@ -1648,8 +1661,14 @@ int do_syslog(int type, char __user *buf, int len, int source) > return 0; > if (!access_ok(buf, len)) > return -EFAULT; > + > + /* Get a consistent copy of @syslog_seq. */ > + raw_spin_lock_irq(&syslog_lock); > + seq = syslog_seq; > + raw_spin_unlock_irq(&syslog_lock); > + > error = wait_event_interruptible(log_wait, > - prb_read_valid(prb, syslog_seq, NULL)); > + prb_read_valid(prb, seq, NULL)); Hmm, this will not detect when syslog_seq gets cleared in parallel. I hope that nobody rely on this behavior. But who knows? A solution might be to have also syslog_seq latched. But I am not sure if it is worth it. I am for taking the risk and use the patch as it is now. Let's keep the code for now. We could always use the latched variable when anyone complains. Just keep it in mind. > if (error) > return error; > error = syslog_print(buf, len); Otherwise, the patch looks good to me. Best Regards, Petr