From: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
To: Petr Mladek <pmladek@suse.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
Pan Xinhui <xinhui@linux.vnet.ibm.com>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Jan Kara <jack@suse.com>, Tejun Heo <tj@kernel.org>,
Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
linux-kernel@vger.kernel.org,
Byungchul Park <byungchul.park@lge.com>
Subject: Re: [PATCH v11 3/3] printk: make printk.synchronous param rw
Date: Fri, 22 Apr 2016 10:28:26 +0900 [thread overview]
Message-ID: <20160422012826.GA515@swordfish> (raw)
In-Reply-To: <20160421110715.GA2749@pathway.suse.cz>
Hello,
On (04/21/16 13:07), Petr Mladek wrote:
[..]
> Please, what is the purpose of "printk_initcall_done" then? If I get
> this correctly, it will always be true when printk_sync_set() is
> called.
well, this is a bit ugly, yes. kernel_param_ops defines ->set callback
as printk_sync_set(). and this ->set callback is getting called from 2
different paths (but it's really about underlying __init_printk_kthread()).
__init_printk_kthread() can be executed from:
1) when command line is getting parsed, and we have printk.synchronous=[0|1]
[ 0.000000] Kernel command line: BOOT_IMAGE=/vmlinuz-4.6.0-rc4-next-20160421 ... printk.synchronous=0
[..]
[ 0.000000] [<ffffffff8106857b>] printk_sync_set+0x12/0x52
[ 0.000000] [<ffffffff8104d9f7>] parse_args+0x1ad/0x2bb
[ 0.000000] [<ffffffff8106a3b8>] ? vprintk_default+0x18/0x1a
[ 0.000000] [<ffffffff8188fbda>] start_kernel+0x175/0x378
[ 0.000000] [<ffffffff8188f852>] ? set_init_arg+0x55/0x55
[ 0.000000] [<ffffffff8188f28e>] x86_64_start_reservations+0x2a/0x2c
[ 0.000000] [<ffffffff8188f3c8>] x86_64_start_kernel+0x138/0x148
can't invoke __init_printk_kthread().
2) late_initcall(init_printk_kthread)
can invoke __init_printk_kthread() at this point.
2) when write to /sys/module/printk/parameters/synchronous happens from user space
[ 65.441956] [<ffffffff8106857b>] printk_sync_set+0x12/0x52
[ 65.441959] [<ffffffff8104db6a>] param_attr_store+0x65/0x8b
[ 65.441960] [<ffffffff8104cf7d>] module_attr_store+0x19/0x25
[ 65.441963] [<ffffffff811411da>] sysfs_kf_write+0x36/0x38
[ 65.441964] [<ffffffff81140657>] kernfs_fop_write+0xe8/0x12e
[ 65.441966] [<ffffffff810f2535>] __vfs_write+0x21/0xc3
[ 65.441967] [<ffffffff810f1888>] ? filp_close+0x57/0x61
[ 65.441969] [<ffffffff81064ed9>] ? percpu_down_read+0xe/0x37
[ 65.441970] [<ffffffff810f2751>] vfs_write+0xb9/0x143
[ 65.441971] [<ffffffff810f28a8>] SyS_write+0x49/0x84
[ 65.441974] [<ffffffff8144959b>] entry_SYSCALL_64_fastpath+0x13/0x8f
can invoke __init_printk_kthread().
alternatively, I had this idea to re-define ->set() callback in init_printk_kthread().
IOW, by default we use param_set_bool(), so parse_args() will not cause any
problems:
static /*** can't 'const' anymore ***/ struct kernel_param_ops param_ops_printk_sync = {
.set = param_set_bool,
.get = param_get_bool,
};
and change it to printk_sync_set() in:
static __init int init_printk_kthread(void)
{
param_ops_printk_sync.set = printk_sync_set;
return __init_printk_kthread();
}
but I think that this bool flag is simpler to understand after all.
> > sysfs knob -> __init_printk_kthread() is protected by printk_sync_lock
> > mutex, obviously there can be parallel calls from user space.
>
> I think that this could not happen. We have discussed similar problem
> with livepatching some time ago. AFAIK, writes to sysfs are
> synchronized out of box.
oh, indeed.
kernfs_fop_write(struct file *file)
{
..
mutex_lock(&((struct seq_file *)file->private_data)->mutex);
ops->write();
mutex_unlock(&((struct seq_file *)file->private_data)->mutex);
..
}
good to know! will drop the mutex and re-spin.
[..]
> Otherwise the patch looks fine. I am bit concerned because
> the synchronization between the setting and testing of
> printk_sync/printk_kthread is a bit weak. But it works
> because we always either wakeup the kthread or call
> the console directly. So, we are on the safe side.
thanks.
> PS: I am sorry for the late comment. I was not able to do so
> immediately and I wrongly marked the mail as read :-(
no prob!
-ss
next prev parent reply other threads:[~2016-04-22 1:26 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-07 17:31 [PATCH v11 0/3] printk: Make printk() completely async Sergey Senozhatsky
2016-04-07 17:31 ` [PATCH v11 1/3] " Sergey Senozhatsky
2016-04-07 17:31 ` [PATCH v11 2/3] printk: Make wake_up_klogd_work_func() async Sergey Senozhatsky
2016-04-07 17:31 ` [PATCH v11 3/3] printk: make printk.synchronous param rw Sergey Senozhatsky
2016-04-08 4:04 ` Pan Xinhui
2016-04-08 5:29 ` Sergey Senozhatsky
2016-04-08 5:44 ` Pan Xinhui
2016-04-21 11:07 ` Petr Mladek
2016-04-22 1:28 ` Sergey Senozhatsky [this message]
2016-04-22 8:41 ` Petr Mladek
2016-04-22 13:12 ` Sergey Senozhatsky
2016-04-20 15:16 ` Jan Kara
2016-04-21 2:03 ` Sergey Senozhatsky
2016-04-16 2:55 ` [PATCH v11 0/3] printk: Make printk() completely async Sergey Senozhatsky
2016-04-16 5:44 ` Joe Perches
2016-04-21 2:14 ` Sergey Senozhatsky
2016-04-21 2:17 ` Joe Perches
2016-04-21 13:19 ` Jan Kara
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160422012826.GA515@swordfish \
--to=sergey.senozhatsky.work@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=byungchul.park@lge.com \
--cc=jack@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
--cc=pmladek@suse.com \
--cc=sergey.senozhatsky@gmail.com \
--cc=tj@kernel.org \
--cc=xinhui@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox