Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757497AbcDHFqQ (ORCPT ); Fri, 8 Apr 2016 01:46:16 -0400 Received: from e23smtp01.au.ibm.com ([202.81.31.143]:47451 "EHLO e23smtp01.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750842AbcDHFqP (ORCPT ); Fri, 8 Apr 2016 01:46:15 -0400 X-IBM-Helo: d23dlp01.au.ibm.com X-IBM-MailFrom: xinhui@linux.vnet.ibm.com X-IBM-RcptTo: linux-kernel@vger.kernel.org Message-ID: <57074552.4020506@linux.vnet.ibm.com> Date: Fri, 08 Apr 2016 13:44:50 +0800 From: Pan Xinhui User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 MIME-Version: 1.0 To: Sergey Senozhatsky CC: Sergey Senozhatsky , Andrew Morton , Jan Kara , Petr Mladek , Tejun Heo , Tetsuo Handa , linux-kernel@vger.kernel.org, Byungchul Park Subject: Re: [PATCH v11 3/3] printk: make printk.synchronous param rw References: <1460050307-3718-1-git-send-email-sergey.senozhatsky@gmail.com> <1460050307-3718-4-git-send-email-sergey.senozhatsky@gmail.com> <57072DE7.50806@linux.vnet.ibm.com> <20160408052927.GA614@swordfish> In-Reply-To: <20160408052927.GA614@swordfish> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16040805-1618-0000-0000-000045516330 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1754 Lines: 62 On 2016年04月08日 13:29, Sergey Senozhatsky wrote: > On (04/08/16 12:04), Pan Xinhui wrote: > [..] >>> +/* >>> + * Init async printk via late_initcall, after core/arch/device/etc. >>> + * initialization. >>> + */ >>> +static __init int init_printk_kthread(void) >>> +{ >>> + printk_initcall_done = true; >>> + return __init_printk_kthread(); >> hello, >> >> One confusion, Why not use a lock to protect __init_printk_kthread from parallel call? Otherwise I think there is a race. >> But for simplicity, maybe you could write codes as below. >> >> + int ret = __init_printk_kthread(); >> + printk_initcall_done = true; >> + return ret; >> >> In my opinion, using a lock is better. > > Hello, > > I though about this, but isn't late_initcall() happening before kernel > starts /sbin/init? who can race with > > late_initcall() -> init_printk_kthread() -> __init_printk_kthread()? > yep, you are right. I made a mistake. > looking at > > static int __ref kernel_init(void *unused) > { > int ret; > > kernel_init_freeable(); > /* need to finish all async __init code before freeing the memory */ > async_synchronize_full(); > free_initmem(); > .. > > if (!try_to_run_init_process("/sbin/init") || > !try_to_run_init_process("/etc/init") || > !try_to_run_init_process("/bin/init") || > !try_to_run_init_process("/bin/sh")) > return 0; > > __init (and init_printk_kthread is __init) is finished and freed by the > time kernel try_to_run_init_process. isn't it? > > good explanation. thanks > sysfs knob -> __init_printk_kthread() is protected by printk_sync_lock > mutex, obviously there can be parallel calls from user space. > > -ss >