Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp453960ybd; Wed, 26 Jun 2019 00:48:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqwNiu/Pc/duKU7WwPZxVAJcyfuK0sc5mxi3DRvv+gR9WteJVT82VDbdfDS6HH0yPxGnOWzv X-Received: by 2002:a63:231a:: with SMTP id j26mr1546134pgj.389.1561535304158; Wed, 26 Jun 2019 00:48:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561535304; cv=none; d=google.com; s=arc-20160816; b=LnMpC565l60c3ruBJXsY9e/DgnPtjLBc6xglpLc/zln3ciTO/vQfVjq8MhPdQLMpTt eL1Ut/YnfCIumgs1c6j9erLDzkqdjWk/OuTJQtRY4sDgPt5oOhyniU9GeR8jAAvk8tV1 d4dVjtnIvH6//N19mqp3C/F7S6BV3eaxQYFDmNCNlnf4bv/sUfUEJw5QaRN4fCvel5OR /wq/gGNABwgYOGsJpJlY5Jt91HsjESjIEsxa/Xs+sG/h/9qpWdU2tx4G6SqyYwX9w+/k lzEUzGOu8FahEuMYCYnQxy2BNyXtyy9eOy7sSQ2vqSvdlyPEDJ3laqBJd0FqGXD3f2lj b3eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=zaM2AYL2HjH1dlzMDtkTqbmgxD1sE5TrhPGXrN+wL7g=; b=ElK2CG9gRSx1lv9687hwj7+cwS8+q/A3JqJrMJRm6EJv+HqseThobvnVvGMBcgW5Gr IOx+Vi8C7YVlAlKbd9Qhh3/RVZCn5RnFvvkbSj3Do8BQt2DW6uMRdzAOgw4toJtpebM9 31oBGQpiIfhRYF4fck7QyW0hapUkATg8O/Gq2uUmekuhJz3UBhLIayFbW/4uMIAr9Hg0 E/teTCwqD6cH8V3ZtPI0pRzBfm9VG9fBBEJA4m3GOU2vSofFm7hXXG3dhx600mDLaOUj OzfAGERUE9SgtbxQvfSFHtKf7aBgNtkdur5KD18YVolaav7TG3qct0yfn7cH6x+eZxbL oouA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z14si16432480pgc.581.2019.06.26.00.48.08; Wed, 26 Jun 2019 00:48:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726956AbfFZHrW (ORCPT + 99 others); Wed, 26 Jun 2019 03:47:22 -0400 Received: from mx2.suse.de ([195.135.220.15]:49764 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726796AbfFZHrV (ORCPT ); Wed, 26 Jun 2019 03:47:21 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id A4FE3AC9B; Wed, 26 Jun 2019 07:47:20 +0000 (UTC) Date: Wed, 26 Jun 2019 09:47:18 +0200 From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , linux-kernel@vger.kernel.org, Peter Zijlstra , Steven Rostedt , Linus Torvalds , Greg Kroah-Hartman , Andrea Parri , Thomas Gleixner , Sergey Senozhatsky Subject: Re: [RFC PATCH v2 1/2] printk-rb: add a new printk ringbuffer implementation Message-ID: <20190626074718.n7fmxugeul3lyyq6@pathway.suse.cz> References: <20190618045117.GA7419@jagdpanzerIV> <87imt2bl0k.fsf@linutronix.de> <20190625064543.GA19050@jagdpanzerIV> <20190625071500.GB19050@jagdpanzerIV> <875zoujbq4.fsf@linutronix.de> <20190625090620.wufhvdxxiryumdra@pathway.suse.cz> <20190625100322.GD532@jagdpanzerIV> <87woh9hnxg.fsf@linutronix.de> <20190626020837.GA25178@jagdpanzerIV> <87mui43jgk.fsf@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87mui43jgk.fsf@linutronix.de> User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 2019-06-26 09:16:11, John Ogness wrote: > On 2019-06-26, Sergey Senozhatsky wrote: > > [..] > >> > CPU0 CPU1 > >> > printk(...) > >> > sz = vscprintf(NULL, "Comm %s\n", current->comm); > >> > ia64_mca_modify_comm() > >> > snprintf(comm, sizeof(comm), "%s %d", current->comm, previous_current->pid); > >> > memcpy(current->comm, comm, sizeof(current->comm)); > >> > if ((buf = prb_reserve(... sz))) { > >> > vscnprintf(buf, "Comm %s\n", current->comm); > >> > ^^^^^^^^^^^^^^ ->comm has changed. > >> > Nothing critical, we > >> > should not corrupt > >> > anything, but we will > >> > truncate ->comm if its > >> > new size is larger than > >> > what it used to be when > >> > we did vscprintf(NULL). > >> > prb_commit(...); > >> > } Great catch. > After we get a lockless ringbuffer that we are happy with, my next > series to integrate the buffer into printk will again use the sprint_rb > solution to avoid the issue discussed in this thread. Perhaps it would > be best to continue this discussion after I've posted that series. We should keep it in head. But I fully agree with postponing the discussion. I personally think that this is a corner case. I would start with a simple vscprintf(NULL, ...) and vscprintf(reserved_buf, ...) approach. We could always make it more complex when it causes real life problems. If the data might change under the hood then we have bigger problems. For example, there might be a race when the trailing "\0" has not been written yet. Best Regards, Petr